diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-05-16 09:46:36 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-05-17 08:46:01 +0200 |
commit | 9fd6b6b1f5b83d923a47252b744358721761d9cf (patch) | |
tree | 873ebeb86597be94648003be0f9fabdea91b5903 | |
parent | 2e3f5a1e2aad2ff9866d7a782a04bec7c29c0e43 (diff) |
tdf#105954 PDF export, ReduceImageResolution: fix re-compressing large images
Expensive re-compress is not pointless when the user opts in to reduce
resolution.
Change-Id: I1e04c6d4f0d95d41808ef885082239645401b2e2
Reviewed-on: https://gerrit.libreoffice.org/54384
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
-rw-r--r-- | vcl/qa/cppunit/pdfexport/data/tdf105954.odt | bin | 0 -> 74147 bytes | |||
-rw-r--r-- | vcl/qa/cppunit/pdfexport/pdfexport.cxx | 47 | ||||
-rw-r--r-- | vcl/source/gdi/pdfextoutdevdata.cxx | 5 |
3 files changed, 52 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/pdfexport/data/tdf105954.odt b/vcl/qa/cppunit/pdfexport/data/tdf105954.odt Binary files differnew file mode 100644 index 000000000000..ba5c96de68bd --- /dev/null +++ b/vcl/qa/cppunit/pdfexport/data/tdf105954.odt diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx index 320c1653af9a..585b968d76d2 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -85,6 +85,7 @@ public: void testTdf66597_3(); #endif void testTdf109143(); + void testTdf105954(); #endif CPPUNIT_TEST_SUITE(PdfExportTest); @@ -113,6 +114,7 @@ public: CPPUNIT_TEST(testTdf66597_3); #endif CPPUNIT_TEST(testTdf109143); + CPPUNIT_TEST(testTdf105954); #endif CPPUNIT_TEST_SUITE_END(); }; @@ -1296,6 +1298,51 @@ void PdfExportTest::testTdf66597_3() } } #endif + +void PdfExportTest::testTdf105954() +{ + // Import the bugdoc and export as PDF. + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf105954.odt"; + mxComponent = loadFromDesktop(aURL); + CPPUNIT_ASSERT(mxComponent.is()); + + uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export"); + uno::Sequence<beans::PropertyValue> aFilterData(comphelper::InitPropertySequence( + { { "ReduceImageResolution", uno::Any(true) }, + { "MaxImageResolution", uno::Any(static_cast<sal_Int32>(300)) } })); + aMediaDescriptor["FilterData"] <<= aFilterData; + xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + + // Parse the export result with pdfium. + SvFileStream aFile(aTempFile.GetURL(), StreamMode::READ); + SvMemoryStream aMemory; + aMemory.WriteStream(aFile); + mpPdfDocument + = FPDF_LoadMemDocument(aMemory.GetData(), aMemory.GetSize(), /*password=*/nullptr); + CPPUNIT_ASSERT(mpPdfDocument); + + // The document has one page. + CPPUNIT_ASSERT_EQUAL(1, FPDF_GetPageCount(mpPdfDocument)); + mpPdfPage = FPDF_LoadPage(mpPdfDocument, /*page_index=*/0); + CPPUNIT_ASSERT(mpPdfPage); + + // There is a single image on the page. + int nPageObjectCount = FPDFPage_CountObjects(mpPdfPage); + CPPUNIT_ASSERT_EQUAL(1, nPageObjectCount); + + // Check width of the image. + FPDF_PAGEOBJECT pPageObject = FPDFPage_GetObject(mpPdfPage, /*index=*/0); + FPDF_IMAGEOBJ_METADATA aMeta; + CPPUNIT_ASSERT(FPDFImageObj_GetImageMetadata(pPageObject, mpPdfPage, &aMeta)); + // This was 2000, i.e. the 'reduce to 300 DPI' request was ignored. + // This is now around 238 (228 on macOS). + CPPUNIT_ASSERT_LESS(static_cast<unsigned int>(250), aMeta.width); +} + #endif CPPUNIT_TEST_SUITE_REGISTRATION(PdfExportTest); diff --git a/vcl/source/gdi/pdfextoutdevdata.cxx b/vcl/source/gdi/pdfextoutdevdata.cxx index 2a7e7b1f0774..a36a056ddfd2 100644 --- a/vcl/source/gdi/pdfextoutdevdata.cxx +++ b/vcl/source/gdi/pdfextoutdevdata.cxx @@ -812,6 +812,11 @@ bool PDFExtOutDevData::HasAdequateCompression( const Graphic &rGraphic, // rOutputRect is the crop rectangle, re-compress cropped image. return false; + if (mbReduceImageResolution) + // Reducing resolution was requested, implies that re-compressing is + // wanted. + return false; + if (rGraphic.GetGfxLink().GetDataSize() == 0) return false; |