summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-04-16 18:13:01 +0200
committerMiklos Vajna <vmiklos@collabora.com>2020-05-06 09:10:14 +0200
commit6cba0e8728dd709c0170fd22fc9b251bdd4994f0 (patch)
treefbc3fe2bd58c1d04145c3ccbc231f5c96238fbb1 /vcl
parenta8c8192e3f4ef922465f0f1462fa4e1cd3fe2c8d (diff)
PDF export: fix handling of page sizes larger than 508 cm
The value of these coordinates are not allowed to be larger than 14 400, and Adobe Reader complains about them. Use UserUnit to declare in case we won't work with points anymore, but with a larger unit. This will mean UserUnit=2 in practice, since e.g. Draw has is page size limited to 600x600cm, so larger values won't happen, at least not for now. (cherry picked from commit 4830592b780833cf5eee2aef30bc9c5d444dfb24) Conflicts: vcl/qa/cppunit/pdfexport/pdfexport.cxx vcl/source/gdi/pdfwriter_impl.cxx vcl/source/gdi/pdfwriter_impl.hxx Change-Id: I8ee159f2571f4070aded85388792a215de86f7ff Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93502 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/qa/cppunit/pdfexport/data/6m-wide.odgbin0 -> 9146 bytes
-rw-r--r--vcl/qa/cppunit/pdfexport/pdfexport.cxx24
-rw-r--r--vcl/source/gdi/pdfwriter_impl.cxx51
-rw-r--r--vcl/source/gdi/pdfwriter_impl.hxx7
4 files changed, 75 insertions, 7 deletions
diff --git a/vcl/qa/cppunit/pdfexport/data/6m-wide.odg b/vcl/qa/cppunit/pdfexport/data/6m-wide.odg
new file mode 100644
index 000000000000..49fb9bfff92e
--- /dev/null
+++ b/vcl/qa/cppunit/pdfexport/data/6m-wide.odg
Binary files differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 03f412016f6e..fbc1f9be4160 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -129,6 +129,7 @@ public:
void testTdf115262();
void testTdf121962();
void testTdf121615();
+ void testLargePage();
CPPUNIT_TEST_SUITE(PdfExportTest);
CPPUNIT_TEST(testTdf106059);
@@ -164,6 +165,7 @@ public:
CPPUNIT_TEST(testTdf115262);
CPPUNIT_TEST(testTdf121962);
CPPUNIT_TEST(testTdf121615);
+ CPPUNIT_TEST(testLargePage);
CPPUNIT_TEST_SUITE_END();
};
@@ -1728,6 +1730,28 @@ void PdfExportTest::testTdf121615()
CPPUNIT_ASSERT_EQUAL( COL_BLACK, aBitmap.GetPixelColor( 199, 299 ));
}
+void PdfExportTest::testLargePage()
+{
+ // Import the bugdoc and export as PDF.
+ OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "6m-wide.odg";
+ utl::MediaDescriptor aMediaDescriptor;
+ aMediaDescriptor["FilterName"] <<= OUString("draw_pdf_Export");
+ DocumentHolder pPdfDocument = exportAndParse(aURL, aMediaDescriptor);
+
+ // The document has 1 page.
+ CPPUNIT_ASSERT_EQUAL(1, FPDF_GetPageCount(pPdfDocument.get()));
+
+ // Check the value (not the unit) of the page size.
+ double fWidth = 0;
+ double fHeight = 0;
+ FPDF_GetPageSizeByIndex(pPdfDocument.get(), 0, &fWidth, &fHeight);
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 8503.94
+ // - Actual : 17007.875
+ // i.e. the value for 600 cm was larger than the 14 400 limit set in the spec.
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(8503.94, fWidth, 0.01);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(PdfExportTest);
}
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index c5d0e441254d..bf44533afcb2 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -1132,6 +1132,7 @@ PDFWriterImpl::PDFPage::PDFPage( PDFWriterImpl* pWriter, double nPageWidth, doub
{
// object ref must be only ever updated in emit()
m_nPageObject = m_pWriter->createObject();
+ m_nUserUnit = std::ceil(std::max(nPageWidth, nPageHeight) / 14400.0);
}
PDFWriterImpl::PDFPage::~PDFPage()
@@ -1213,10 +1214,15 @@ bool PDFWriterImpl::PDFPage::emit(sal_Int32 nParentObject )
if( m_nPageWidth && m_nPageHeight )
{
aLine.append( "/MediaBox[0 0 " );
- aLine.append( m_nPageWidth );
+ aLine.append(m_nPageWidth / m_nUserUnit);
aLine.append( ' ' );
- aLine.append( m_nPageHeight );
+ aLine.append(m_nPageHeight / m_nUserUnit);
aLine.append( "]" );
+ if (m_nUserUnit > 1)
+ {
+ aLine.append("\n/UserUnit ");
+ aLine.append(m_nUserUnit);
+ }
}
switch( m_eOrientation )
{
@@ -1681,6 +1687,18 @@ void PDFWriterImpl::PDFPage::appendWaveLine( sal_Int32 nWidth, sal_Int32 nY, sal
rBuffer.append( "S\n" );
}
+double PDFWriterImpl::PDFPage::getHeight() const
+{
+ double fRet = m_nPageHeight ? m_nPageHeight : PDFWriterImpl::g_nInheritedPageHeight;
+
+ if (m_nUserUnit > 1)
+ {
+ fRet /= m_nUserUnit;
+ }
+
+ return fRet;
+}
+
PDFWriterImpl::PDFWriterImpl( const PDFWriter::PDFWriterContext& rContext,
const css::uno::Reference< css::beans::XMaterialHolder >& xEnc,
PDFWriter& i_rOuterFace)
@@ -2170,6 +2188,14 @@ void PDFWriterImpl::newPage( double nPageWidth, double nPageHeight, PDFWriter::O
endPage();
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)));
+ }
+
m_aPages.back().beginStream();
// setup global graphics state
@@ -4941,6 +4967,7 @@ bool PDFWriterImpl::emitCatalog()
sal_Int32 nMediaBoxWidth = 0;
sal_Int32 nMediaBoxHeight = 0;
+ sal_Int32 nUserUnit = 1;
if( m_aPages.empty() ) // sanity check, this should not happen
{
nMediaBoxWidth = g_nInheritedPageWidth;
@@ -4951,17 +4978,29 @@ bool PDFWriterImpl::emitCatalog()
for (auto const& page : m_aPages)
{
if( page.m_nPageWidth > nMediaBoxWidth )
+ {
nMediaBoxWidth = page.m_nPageWidth;
+ nUserUnit = page.m_nUserUnit;
+ }
if( page.m_nPageHeight > nMediaBoxHeight )
+ {
nMediaBoxHeight = page.m_nPageHeight;
+ nUserUnit = page.m_nUserUnit;
+ }
}
}
aLine.append( "/MediaBox[ 0 0 " );
- aLine.append( nMediaBoxWidth );
+ aLine.append(nMediaBoxWidth / nUserUnit);
aLine.append( ' ' );
- aLine.append( nMediaBoxHeight );
- aLine.append( " ]\n"
- "/Kids[ " );
+ aLine.append(nMediaBoxHeight / nUserUnit);
+ aLine.append(" ]\n");
+ if (nUserUnit > 1)
+ {
+ aLine.append("/UserUnit ");
+ aLine.append(nUserUnit);
+ aLine.append("\n");
+ }
+ aLine.append("/Kids[ ");
unsigned int i = 0;
for (auto & page : m_aPages)
{
diff --git a/vcl/source/gdi/pdfwriter_impl.hxx b/vcl/source/gdi/pdfwriter_impl.hxx
index 98d2f8812059..5afb1826ccb8 100644
--- a/vcl/source/gdi/pdfwriter_impl.hxx
+++ b/vcl/source/gdi/pdfwriter_impl.hxx
@@ -118,6 +118,11 @@ public:
VclPtr<PDFWriterImpl> m_pWriter;
double const m_nPageWidth; // in inch/72
double const m_nPageHeight; // in inch/72
+ /**
+ * A positive number that gives the size of default user space units, in multiples of points.
+ * Typically 1, larger if page size is > 508 cm.
+ */
+ sal_Int32 m_nUserUnit;
PDFWriter::Orientation const m_eOrientation;
sal_Int32 m_nPageObject;
std::vector<sal_Int32> m_aStreamObjects;
@@ -169,7 +174,7 @@ public:
// appends a horizontal waveline with vertical offset (helper for drawWaveLine)
void appendWaveLine( sal_Int32 nLength, sal_Int32 nYOffset, sal_Int32 nDelta, OStringBuffer& rBuffer ) const;
- double getHeight() const { return m_nPageHeight ? m_nPageHeight : PDFWriterImpl::g_nInheritedPageHeight; }
+ double getHeight() const;
};
friend struct PDFPage;