vcl/qa/cppunit/pdfexport/data/wide_page1.fodt |   40 ++++++++++++++++++
 vcl/qa/cppunit/pdfexport/pdfexport.cxx        |   56 ++++++++++++++++++++++++++
 vcl/source/gdi/pdfwriter_impl.cxx             |    8 ---
 3 files changed, 98 insertions(+), 6 deletions(-)

New commits:
commit e80e2a8dbed8a6cea71eca333564a9fa75b5cfbc
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Fri Jul 28 17:55:17 2023 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sun Jul 30 20:08:04 2023 +0200

    tdf#156528: Fix handling PDF page scaling factor after large pages
    
    The map mode wasn't set when current page's user unit was 1, which meant
    that it used the unchanged value from the previous page, where it could
    be different.
    
    Change-Id: Id1f1515dceac25cddc12081a86fabf8b32d633f0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155025
    Tested-by: Mike Kaganski <mike.kagan...@collabora.com>
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/vcl/qa/cppunit/pdfexport/data/wide_page1.fodt 
b/vcl/qa/cppunit/pdfexport/data/wide_page1.fodt
new file mode 100644
index 000000000000..9e7390a8e22a
--- /dev/null
+++ b/vcl/qa/cppunit/pdfexport/data/wide_page1.fodt
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<office:document 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:ooo="http://openoffice.org/2004/office"; 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" 
xmlns:dc="http://purl.org/dc/elements/1.1/"; 
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:rpt="http://openoffice.org/2005/report"; 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" 
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
xmlns:ooow="http://openoffice.org/200
 4/writer" xmlns:oooc="http://openoffice.org/2004/calc"; 
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
xmlns:xforms="http://www.w3.org/2002/xforms"; 
xmlns:tableooo="http://openoffice.org/2009/table"; 
xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0"
 xmlns:drawooo="http://openoffice.org/2010/draw"; 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
 xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" 
xmlns:math="http://www.w3.org/1998/Math/MathML"; 
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" 
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" 
xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"
 xmlns:dom="http://www.w3.org/2001/xml-events"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:xhtml="http://www.w3.org/1999/xhtml"; 
xmlns:grddl="http://www.w3.org/2003/g/data-view#"; xmlns
 :css3t="http://www.w3.org/TR/css3-text/"; 
xmlns:officeooo="http://openoffice.org/2009/office"; office:version="1.3" 
office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:styles>
+ </office:styles>
+ <office:automatic-styles>
+  <style:style style:name="P1" style:family="paragraph" 
style:master-page-name="very_5f_wide"/>
+  <style:style style:name="P2" style:family="paragraph" 
style:master-page-name="Standard">
+   <style:paragraph-properties fo:break-before="page"/>
+  </style:style>
+  <style:style style:name="gr1" style:family="graphic">
+   <style:graphic-properties draw:fill="none" 
draw:textarea-horizontal-align="justify" draw:textarea-vertical-align="middle" 
draw:auto-grow-height="false" fo:min-height="257mm" fo:min-width="170mm" 
loext:decorative="false" style:run-through="foreground" 
style:wrap="run-through" style:number-wrapped-paragraphs="no-limit" 
style:vertical-pos="from-top" style:vertical-rel="page-content" 
style:horizontal-pos="from-left" style:horizontal-rel="page-content"/>
+  </style:style>
+  <style:style style:name="gr2" style:family="graphic">
+   <style:graphic-properties draw:fill="none" 
draw:textarea-horizontal-align="justify" draw:textarea-vertical-align="middle" 
draw:auto-grow-height="false" fo:min-height="170mm" fo:min-width="5060mm" 
loext:decorative="false" style:run-through="foreground" 
style:wrap="run-through" style:number-wrapped-paragraphs="no-limit" 
style:vertical-pos="from-top" style:vertical-rel="page-content" 
style:horizontal-pos="from-left" style:horizontal-rel="page-content"/>
+  </style:style>
+  <style:page-layout style:name="pm1">
+   <style:page-layout-properties fo:page-width="210mm" fo:page-height="297mm" 
style:print-orientation="portrait" fo:margin-top="20mm" fo:margin-bottom="20mm" 
fo:margin-left="20mm" fo:margin-right="20mm"/>
+  </style:page-layout>
+  <style:page-layout style:name="pm2">
+   <style:page-layout-properties fo:page-width="5100mm" fo:page-height="210mm" 
style:print-orientation="landscape" fo:margin-top="20mm" 
fo:margin-bottom="20mm" fo:margin-left="20mm" fo:margin-right="20mm"/>
+  </style:page-layout>
+ </office:automatic-styles>
+ <office:master-styles>
+  <style:master-page style:name="Standard" style:page-layout-name="pm1"/>
+  <style:master-page style:name="very_5f_wide" style:display-name="very_wide" 
style:page-layout-name="pm2"/>
+ </office:master-styles>
+ <office:body>
+  <office:text>
+   <text:p text:style-name="P1"><draw:custom-shape 
text:anchor-type="paragraph" draw:z-index="0" draw:name="Shape 1" 
draw:style-name="gr2" svg:width="5060mm" svg:height="170mm" svg:x="0mm" 
svg:y="0mm">
+     <text:p/>
+     <draw:enhanced-geometry svg:viewBox="0 0 21600 21600" 
draw:type="rectangle" draw:enhanced-path="M 0 0 L 21600 0 21600 21600 0 21600 0 
0 Z N"/>
+    </draw:custom-shape></text:p>
+   <text:p text:style-name="P2"><draw:custom-shape 
text:anchor-type="paragraph" draw:z-index="1" draw:name="Shape 2" 
draw:style-name="gr1" svg:width="170mm" svg:height="257mm" svg:x="0mm" 
svg:y="0mm">
+     <text:p/>
+     <draw:enhanced-geometry svg:viewBox="0 0 21600 21600" 
draw:type="rectangle" draw:enhanced-path="M 0 0 L 21600 0 21600 21600 0 21600 0 
0 Z N"/>
+    </draw:custom-shape></text:p>
+  </office:text>
+ </office:body>
+</office:document>
\ No newline at end of file
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index aaf3998eb99a..2ac143029c07 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -5423,6 +5423,62 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf48707_2)
     }
 }
 
+CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf156528)
+{
+    aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
+    saveAsPDF(u"wide_page1.fodt");
+    std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport();
+
+    // The document has two pages
+    CPPUNIT_ASSERT_EQUAL(2, pPdfDocument->getPageCount());
+
+    // 1st page (5100 mm width x 210 mm high, UserUnit = 2)
+    auto pPdfPage = pPdfDocument->openPage(0);
+    CPPUNIT_ASSERT(pPdfPage);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(o3tl::convert(5100.0 / 2, o3tl::Length::mm, 
o3tl::Length::pt),
+                                 pPdfPage->getWidth(), 1);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(o3tl::convert(210.0 / 2, o3tl::Length::mm, 
o3tl::Length::pt),
+                                 pPdfPage->getHeight(), 1);
+
+    // 1 object (rectangle 5060 mm width x 170 mm high, UserUnit = 2)
+    CPPUNIT_ASSERT_EQUAL(1, pPdfPage->getObjectCount());
+    auto pRect = pPdfPage->getObject(0);
+    CPPUNIT_ASSERT(pRect);
+    CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFPageObjectType::Path, pRect->getType());
+    auto bounds = pRect->getBounds();
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(o3tl::convert(5060.0 / 2, o3tl::Length::mm, 
o3tl::Length::pt),
+                                 bounds.getWidth(), 1);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(o3tl::convert(170.0 / 2, o3tl::Length::mm, 
o3tl::Length::pt),
+                                 bounds.getHeight(), 1);
+
+    // 2nd page (210 mm width x 297 mm high, UserUnit = 1)
+    pPdfPage = pPdfDocument->openPage(1);
+    CPPUNIT_ASSERT(pPdfPage);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(o3tl::convert(210.0, o3tl::Length::mm, 
o3tl::Length::pt),
+                                 pPdfPage->getWidth(), 1);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(o3tl::convert(297.0, o3tl::Length::mm, 
o3tl::Length::pt),
+                                 pPdfPage->getHeight(), 1);
+
+    // 1 object (rectangle 170 mm width x 257 mm high, UserUnit = 1)
+    CPPUNIT_ASSERT_EQUAL(1, pPdfPage->getObjectCount());
+    pRect = pPdfPage->getObject(0);
+    CPPUNIT_ASSERT(pRect);
+    CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFPageObjectType::Path, pRect->getType());
+    bounds = pRect->getBounds();
+    // Without the fix, this would fail with
+    // - Expected: 481.889763779528
+    // - Actual  : 241.925001144409
+    // - Delta   : 1
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(o3tl::convert(170.0, o3tl::Length::mm, 
o3tl::Length::pt),
+                                 bounds.getWidth(), 1);
+    //
+    // - Expected: 728.503937007874
+    // - Actual  : 365.25
+    // - Delta   : 1
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(o3tl::convert(257.0, o3tl::Length::mm, 
o3tl::Length::pt),
+                                 bounds.getHeight(), 1);
+}
+
 } // end anonymous namespace
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index e63ae76b8a8d..24e87ead042e 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -1680,12 +1680,8 @@ void PDFWriterImpl::newPage( double nPageWidth, double 
nPageHeight, PDFWriter::O
     m_nCurrentPage = m_aPages.size();
     m_aPages.emplace_back(this, nPageWidth, nPageHeight, eOrientation );
 
-    sal_Int32 nUserUnit = m_aPages.back().m_nUserUnit;
-    if (nUserUnit > 1)
-    {
-        m_aMapMode = MapMode(MapUnit::MapPoint, Point(), Fraction(nUserUnit, 
pointToPixel(1)),
-                             Fraction(nUserUnit, pointToPixel(1)));
-    }
+    const Fraction frac(m_aPages.back().m_nUserUnit, pointToPixel(1));
+    m_aMapMode = MapMode(MapUnit::MapPoint, Point(), frac, frac);
 
     m_aPages.back().beginStream();
 

Reply via email to