From aea8043bc5f5187498fa450505d6de9d6986e2a6 Mon Sep 17 00:00:00 2001 From: Tünde Tóth Date: Tue, 22 Mar 2022 09:47:57 +0100 Subject: tdf#74670 tdf#91286 PPTX XLSX export: save image once MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Impress and Calc used to dump the same image file as many times as it was featured in the document, resulting redundant, sometimes huge documents. Note: using only checksum to recognize image duplication is a regression, because checksum collision results image loss. This is a very unlikely event, and the following commits have got the same problem. The solution is comparing the images with the same checksum byte for byte. See also commit b484e9814c66d8d51cea974390963a6944bc9d73 "tdf#83227 oox: reuse RelId in DML/VML export for the same graphic" and commit 797fef38612fb2fd62d1f6591619b9361e526bca "tdf#118535 DOCX export: save header image once". Change-Id: I9f233d521941381746634cf4f9b5991da0dadda9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131928 Tested-by: László Németh Reviewed-by: László Németh --- sd/qa/unit/data/odp/tdf74670.odp | Bin 0 -> 11786 bytes sd/qa/unit/export-tests-ooxml3.cxx | 26 ++++++++++++++++++++++++++ sd/source/filter/eppt/pptx-epptooxml.cxx | 2 ++ 3 files changed, 28 insertions(+) create mode 100644 sd/qa/unit/data/odp/tdf74670.odp (limited to 'sd') diff --git a/sd/qa/unit/data/odp/tdf74670.odp b/sd/qa/unit/data/odp/tdf74670.odp new file mode 100644 index 000000000000..98e223eb0725 Binary files /dev/null and b/sd/qa/unit/data/odp/tdf74670.odp differ diff --git a/sd/qa/unit/export-tests-ooxml3.cxx b/sd/qa/unit/export-tests-ooxml3.cxx index 776d436b7edf..3f4bec336ef1 100644 --- a/sd/qa/unit/export-tests-ooxml3.cxx +++ b/sd/qa/unit/export-tests-ooxml3.cxx @@ -106,6 +106,7 @@ public: void testTdf147121(); void testTdf140912_PicturePlaceholder(); void testEnhancedPathViewBox(); + void testTdf74670(); CPPUNIT_TEST_SUITE(SdOOXMLExportTest3); @@ -182,6 +183,7 @@ public: CPPUNIT_TEST(testTdf147121); CPPUNIT_TEST(testTdf140912_PicturePlaceholder); CPPUNIT_TEST(testEnhancedPathViewBox); + CPPUNIT_TEST(testTdf74670); CPPUNIT_TEST_SUITE_END(); virtual void registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) override @@ -1893,6 +1895,30 @@ void SdOOXMLExportTest3::testEnhancedPathViewBox() CPPUNIT_ASSERT_EQUAL(sal_Int32(2045), aBoundRectangle.Width); } +void SdOOXMLExportTest3::testTdf74670() +{ + ::sd::DrawDocShellRef xDocShRef + = loadURL(m_directories.getURLFromSrc(u"/sd/qa/unit/data/odp/tdf74670.odp"), ODP); + utl::TempFile tmpfile; + xDocShRef = saveAndReload(xDocShRef.get(), PPTX, &tmpfile); + xDocShRef->DoClose(); + + uno::Reference xNameAccess + = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory), + tmpfile.GetURL()); + const uno::Sequence aNames(xNameAccess->getElementNames()); + int nImageFiles = 0; + for (const auto& rElementName : aNames) + if (rElementName.startsWith("ppt/media/image")) + nImageFiles++; + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 2 + // i.e. the embedded picture would have been saved twice. + CPPUNIT_ASSERT_EQUAL(1, nImageFiles); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SdOOXMLExportTest3); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sd/source/filter/eppt/pptx-epptooxml.cxx b/sd/source/filter/eppt/pptx-epptooxml.cxx index 07be6521d678..8823cbd00d53 100644 --- a/sd/source/filter/eppt/pptx-epptooxml.cxx +++ b/sd/source/filter/eppt/pptx-epptooxml.cxx @@ -428,6 +428,7 @@ bool PowerPointExport::importDocument() noexcept bool PowerPointExport::exportDocument() { DrawingML::ResetCounters(); + DrawingML::PushExportGraphics(); maShapeMap.clear(); mXModel = getModel(); @@ -504,6 +505,7 @@ bool PowerPointExport::exportDocument() commitStorage(); + DrawingML::PopExportGraphics(); maShapeMap.clear(); maAuthors.clear(); maRelId.clear(); -- cgit