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-05 10:21:52 +0200
commiteaafd7378bd3a06d2d99360667858a3b6106d0de (patch)
tree94e8b7094293dfdcdff13163ea795bc0e08c831c /vcl
parent0ce45bf39c53a953c9f84635699ee116f1cbb5a3 (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/source/gdi/pdfwriter_impl.cxx vcl/source/gdi/pdfwriter_impl.hxx Change-Id: I8ee159f2571f4070aded85388792a215de86f7ff
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 48f12080f74b..28b0b693e426 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -138,6 +138,7 @@ public:
void testTocLink();
void testPdfImageResourceInlineXObjectRef();
void testLinkWrongPage();
+ void testLargePage();
CPPUNIT_TEST_SUITE(PdfExportTest);
CPPUNIT_TEST(testTdf106059);
@@ -176,6 +177,7 @@ public:
CPPUNIT_TEST(testTocLink);
CPPUNIT_TEST(testPdfImageResourceInlineXObjectRef);
CPPUNIT_TEST(testLinkWrongPage);
+ CPPUNIT_TEST(testLargePage);
CPPUNIT_TEST_SUITE_END();
};
@@ -1895,6 +1897,28 @@ void PdfExportTest::testLinkWrongPage()
CPPUNIT_ASSERT(!HasLinksOnPage(pPdfPage2));
}
+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);
+}
+
void PdfExportTest::testPdfImageResourceInlineXObjectRef()
{
// Create an empty document.
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index a2a3f5ca9a5b..27f5042e5f1c 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -735,6 +735,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()
@@ -816,10 +817,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 )
{
@@ -1284,6 +1290,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)
@@ -1768,6 +1786,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
@@ -4564,6 +4590,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;
@@ -4574,17 +4601,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 (const auto & page : m_aPages)
{
diff --git a/vcl/source/gdi/pdfwriter_impl.hxx b/vcl/source/gdi/pdfwriter_impl.hxx
index 7e07d9e0d472..8c88ed6fb172 100644
--- a/vcl/source/gdi/pdfwriter_impl.hxx
+++ b/vcl/source/gdi/pdfwriter_impl.hxx
@@ -117,6 +117,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;
@@ -168,7 +173,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;