summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2018-05-02 17:22:30 +0200
committerCaolán McNamara <caolanm@redhat.com>2018-05-04 17:27:31 +0200
commite0ae55f7cefe74039f8ade1696d1861e90d73c04 (patch)
treea3a2218925b03b3a8aab2daf3e0e098d939a0425
parent46b49b0f3f539d9a8645c6447a8c4b2e0b463cac (diff)
tdf#109143 PDF export: don't reuse compressed bitmaps for cropped images
PDF wants to loose the pixels masked out by cropping, so the "reuse original compressed image" optimization should not be used in that case. (cherry picked from commit be3ef7b0e5e51c1d97309ce3b6d5cac1fbd025d0) Conflicts: vcl/source/gdi/pdfextoutdevdata.cxx Change-Id: Ifdf2cc4ff6bff0ed456a2159395314817c1cf417 Reviewed-on: https://gerrit.libreoffice.org/53772 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--include/vcl/pdfextoutdevdata.hxx4
-rw-r--r--vcl/qa/cppunit/pdfexport/data/tdf109143.odtbin0 -> 68155 bytes
-rw-r--r--vcl/qa/cppunit/pdfexport/pdfexport.cxx42
-rw-r--r--vcl/source/gdi/pdfextoutdevdata.cxx12
4 files changed, 54 insertions, 4 deletions
diff --git a/include/vcl/pdfextoutdevdata.hxx b/include/vcl/pdfextoutdevdata.hxx
index 6dc5165d99a5..22079323580c 100644
--- a/include/vcl/pdfextoutdevdata.hxx
+++ b/include/vcl/pdfextoutdevdata.hxx
@@ -180,7 +180,9 @@ public:
const tools::Rectangle& rVisibleOutputRect );
/// Detect if stream is compressed enough to avoid de-compress / scale & re-compress
- bool HasAdequateCompression( const Graphic &rGraphic ) const;
+ bool HasAdequateCompression( const Graphic &rGraphic,
+ const tools::Rectangle &rOutputRect,
+ const tools::Rectangle &rVisibleOutputRect ) const;
//--->i56629
/** Create a new named destination to be used in a link to this document from another PDF document
diff --git a/vcl/qa/cppunit/pdfexport/data/tdf109143.odt b/vcl/qa/cppunit/pdfexport/data/tdf109143.odt
new file mode 100644
index 000000000000..7d9afa3789e5
--- /dev/null
+++ b/vcl/qa/cppunit/pdfexport/data/tdf109143.odt
Binary files differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index ba8df2f1a616..c6de4b344503 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -80,6 +80,7 @@ public:
void testTdf115117_2a();
#endif
#endif
+ void testTdf109143();
CPPUNIT_TEST_SUITE(PdfExportTest);
#if HAVE_FEATURE_PDFIUM
@@ -104,6 +105,7 @@ public:
CPPUNIT_TEST(testTdf115117_2a);
#endif
#endif
+ CPPUNIT_TEST(testTdf109143);
CPPUNIT_TEST_SUITE_END();
};
@@ -427,6 +429,46 @@ void PdfExportTest::testTdf106206()
CPPUNIT_ASSERT(bool(it == pEnd));
}
+void PdfExportTest::testTdf109143()
+{
+ // Import the bugdoc and export as PDF.
+ OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf109143.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");
+ xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
+
+ // Parse the export result.
+ vcl::filter::PDFDocument aDocument;
+ SvFileStream aStream(aTempFile.GetURL(), StreamMode::READ);
+ CPPUNIT_ASSERT(aDocument.Read(aStream));
+
+ // The document has one page.
+ std::vector<vcl::filter::PDFObjectElement*> aPages = aDocument.GetPages();
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aPages.size());
+
+ // Get access to the only image on the only page.
+ vcl::filter::PDFObjectElement* pResources = aPages[0]->LookupObject("Resources");
+ CPPUNIT_ASSERT(pResources);
+ auto pXObjects = dynamic_cast<vcl::filter::PDFDictionaryElement*>(pResources->Lookup("XObject"));
+ CPPUNIT_ASSERT(pXObjects);
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pXObjects->GetItems().size());
+ vcl::filter::PDFObjectElement* pXObject = pXObjects->LookupObject(pXObjects->GetItems().begin()->first);
+ CPPUNIT_ASSERT(pXObject);
+
+ // Make sure it's re-compressed.
+ auto pLength = dynamic_cast<vcl::filter::PDFNumberElement*>(pXObject->Lookup("Length"));
+ int nLength = pLength->GetValue();
+ // This failed: cropped TIFF-in-JPEG wasn't re-compressed, so crop was
+ // lost. Size was 59416, now is 11827.
+ CPPUNIT_ASSERT(nLength < 50000);
+}
+
void PdfExportTest::testTdf106972()
{
// Import the bugdoc and export as PDF.
diff --git a/vcl/source/gdi/pdfextoutdevdata.cxx b/vcl/source/gdi/pdfextoutdevdata.cxx
index 8974c6f5a645..71ef583cda58 100644
--- a/vcl/source/gdi/pdfextoutdevdata.cxx
+++ b/vcl/source/gdi/pdfextoutdevdata.cxx
@@ -404,13 +404,13 @@ bool PageSyncData::PlaySyncPageAct( PDFWriter& rWriter, sal_uInt32& rCurGDIMtfAc
GfxLinkType eType = rGraphic.GetLink().GetType();
if ( eType == GfxLinkType::NativeJpg )
{
- mbGroupIgnoreGDIMtfActions = rOutDevData.HasAdequateCompression(rGraphic);
+ mbGroupIgnoreGDIMtfActions = rOutDevData.HasAdequateCompression(rGraphic, mParaRects[0], mParaRects[1]);
if ( !mbGroupIgnoreGDIMtfActions )
mCurrentGraphic = rGraphic;
}
else if ( eType == GfxLinkType::NativePng || eType == GfxLinkType::NativePdf )
{
- if ( eType == GfxLinkType::NativePdf || rOutDevData.HasAdequateCompression(rGraphic) )
+ if ( eType == GfxLinkType::NativePdf || rOutDevData.HasAdequateCompression(rGraphic, mParaRects[0], mParaRects[1]) )
mCurrentGraphic = rGraphic;
}
}
@@ -797,13 +797,19 @@ void PDFExtOutDevData::EndGroup( const Graphic& rGraphic,
}
// Avoids expensive de-compression and re-compression of large images.
-bool PDFExtOutDevData::HasAdequateCompression( const Graphic &rGraphic ) const
+bool PDFExtOutDevData::HasAdequateCompression( const Graphic &rGraphic,
+ const tools::Rectangle & rOutputRect,
+ const tools::Rectangle & rVisibleOutputRect ) const
{
assert(rGraphic.IsLink() &&
(rGraphic.GetLink().GetType() == GfxLinkType::NativeJpg ||
rGraphic.GetLink().GetType() == GfxLinkType::NativePng ||
rGraphic.GetLink().GetType() == GfxLinkType::NativePdf));
+ if (rOutputRect != rVisibleOutputRect)
+ // rOutputRect is the crop rectangle, re-compress cropped image.
+ return false;
+
if (rGraphic.GetLink().GetDataSize() == 0)
return false;