include/oox/export/drawingml.hxx | 2 +- oox/source/export/drawingml.cxx | 13 +++++++------ sw/qa/extras/ooxmlexport/data/embedded_images.odt |binary sw/qa/extras/ooxmlexport/ooxmlexport16.cxx | 20 ++++++++++++++++++++ 4 files changed, 28 insertions(+), 7 deletions(-)
New commits: commit 6a39bc2668e8f0f8f953ee5f605083eb182db970 Author: Tünde Tóth <toth.tu...@nisz.hu> AuthorDate: Mon Nov 21 11:30:16 2022 +0100 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Fri Nov 25 12:01:15 2022 +0100 tdf#152153 DOCX export: fix lost images at embedded documents Handling of image counter was incorrect if the document contains embedded documents, overwriting images with the other ones. See also commit cf2dc247ff5f726238856e9b46a4926a30430e14 "DOCX export: image deduplication and clean up" and commit 3f6df3835fec71ea61894f9a3bbfe5e4a06a5495 "DOCX export: fix image counters for multiple documents". Change-Id: I3ce3e370f96fa8b9feca3bc73f06ddca933215d4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143036 Tested-by: László Németh <nem...@numbertext.org> Reviewed-by: László Németh <nem...@numbertext.org> (cherry picked from commit 55b1d635350cb76ee3e19e90c938eedd38ac3342) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143256 Reviewed-by: Michael Stahl <michael.st...@allotropia.de> Tested-by: Jenkins diff --git a/include/oox/export/drawingml.hxx b/include/oox/export/drawingml.hxx index 674457b3c6e4..9f28a5891306 100644 --- a/include/oox/export/drawingml.hxx +++ b/include/oox/export/drawingml.hxx @@ -142,7 +142,7 @@ class OOX_DLLPUBLIC DrawingML { private: - static int mnImageCounter; + static std::stack<sal_Int32> mnImageCounter; static int mnWdpImageCounter; static std::map<OUString, OUString> maWdpCache; static sal_Int32 mnDrawingMLCount; diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index 5df185983ea8..ea44c4237ff0 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -234,7 +234,7 @@ void WriteGradientPath(const awt::Gradient& rGradient, const FSHelperPtr& pFS, c } // not thread safe -int DrawingML::mnImageCounter = 1; +std::stack<sal_Int32> DrawingML::mnImageCounter; int DrawingML::mnWdpImageCounter = 1; std::map<OUString, OUString> DrawingML::maWdpCache; sal_Int32 DrawingML::mnDrawingMLCount = 0; @@ -267,7 +267,6 @@ sal_Int16 DrawingML::GetScriptType(const OUString& rStr) void DrawingML::ResetCounters() { - mnImageCounter = 1; mnWdpImageCounter = 1; maWdpCache.clear(); } @@ -280,11 +279,13 @@ void DrawingML::ResetMlCounters() void DrawingML::PushExportGraphics() { + mnImageCounter.push(1); maExportGraphics.emplace(); } void DrawingML::PopExportGraphics() { + mnImageCounter.pop(); maExportGraphics.pop(); } @@ -1393,7 +1394,7 @@ OUString DrawingML::WriteImage( const Graphic& rGraphic , bool bRelPathToMedia ) Reference<XOutputStream> xOutStream = mpFB->openFragmentStream( OUStringBuffer() .appendAscii(GetComponentDir()) - .append("/media/image" + OUString::number(mnImageCounter)) + .append("/media/image" + OUString::number(mnImageCounter.top())) .appendAscii(pExtension) .makeStringAndClear(), sMediaType); @@ -1409,7 +1410,7 @@ OUString DrawingML::WriteImage( const Graphic& rGraphic , bool bRelPathToMedia ) sPath = OUStringBuffer() .appendAscii(sRelationCompPrefix.getStr()) .appendAscii(sRelPathToMedia.getStr()) - .append(static_cast<sal_Int32>(mnImageCounter++)) + .append(static_cast<sal_Int32>(mnImageCounter.top()++)) .appendAscii(pExtension) .makeStringAndClear(); @@ -1488,7 +1489,7 @@ void DrawingML::WriteMediaNonVisualProperties(const css::uno::Reference<css::dra Reference<XOutputStream> xOutStream = mpFB->openFragmentStream(OUStringBuffer() .appendAscii(GetComponentDir()) .append("/media/media" + - OUString::number(mnImageCounter) + + OUString::number(mnImageCounter.top()) + aExtension) .makeStringAndClear(), aMimeType); @@ -1500,7 +1501,7 @@ void DrawingML::WriteMediaNonVisualProperties(const css::uno::Reference<css::dra // create the relation OUString aPath = OUStringBuffer().appendAscii(GetRelationCompPrefix()) - .append("media/media" + OUString::number(mnImageCounter++) + aExtension) + .append("media/media" + OUString::number(mnImageCounter.top()++) + aExtension) .makeStringAndClear(); aVideoFileRelId = mpFB->addRelation(mpFS->getOutputStream(), oox::getRelationship(eMediaType), aPath); aMediaRelId = mpFB->addRelation(mpFS->getOutputStream(), oox::getRelationship(Relationship::MEDIA), aPath); diff --git a/sw/qa/extras/ooxmlexport/data/embedded_images.odt b/sw/qa/extras/ooxmlexport/data/embedded_images.odt new file mode 100644 index 000000000000..26166fac349b Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/embedded_images.odt differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx index 6de87f58ced9..2f958b641ed5 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx @@ -1000,6 +1000,26 @@ DECLARE_OOXMLEXPORT_TEST(testTdf143726, "Simple-TOC.odt") assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='ContentsHeading']/w:name", "val", "TOC Heading"); } +CPPUNIT_TEST_FIXTURE(Test, testTdf152153) +{ + loadAndReload("embedded_images.odt"); + + uno::Reference<packages::zip::XZipFileAccess2> xNameAccess + = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory), + maTempFile.GetURL()); + const uno::Sequence<OUString> aNames(xNameAccess->getElementNames()); + int nImageFiles = 0; + for (const auto& rElementName : aNames) + if (rElementName.startsWith("word/media/image")) + nImageFiles++; + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 4 + // - Actual : 3 + // i.e. the once embedded picture wouldn't have been saved. + CPPUNIT_ASSERT_EQUAL(4, nImageFiles); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */