include/oox/export/drawingml.hxx                    |    5 +--
 oox/source/export/drawingml.cxx                     |   31 +++++++++++---------
 sd/source/filter/eppt/pptx-epptooxml.cxx            |    1 
 sw/qa/extras/ooxmlexport/data/artistic_effects.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport16.cxx          |   20 ++++++++++++
 sw/source/filter/ww8/docxexport.cxx                 |    1 
 6 files changed, 40 insertions(+), 18 deletions(-)

New commits:
commit 01246f06cfeeb6a1070e82351e2559def4f5d820
Author:     Tünde Tóth <toth.tu...@nisz.hu>
AuthorDate: Thu Nov 24 15:30:37 2022 +0100
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Tue Nov 29 17:37:28 2022 +0100

    tdf#152152 DOCX export: fix lost WDP images in artistic effects
    
    Handling of WDP image counter was incorrect if the
    document contains embedded documents, overwriting
    WDP images with the other ones.
    
    See also commit 55b1d635350cb76ee3e19e90c938eedd38ac3342
    "tdf#152153 DOCX export: fix lost images at embedded documents"
    and commit cf2dc247ff5f726238856e9b46a4926a30430e14
    "DOCX export: image deduplication and clean up"
    and commit b5f6a5cfc517ecd8aa6ba96471d854b07b92ebaa
    "ooxml: Do not repeat wdp files in artistic effects".
    
    Change-Id: Ia26784519f6d514ee8c90c7a91a367feeba140b5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143235
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/include/oox/export/drawingml.hxx b/include/oox/export/drawingml.hxx
index 543fb072921f..eb0fea23b95c 100644
--- a/include/oox/export/drawingml.hxx
+++ b/include/oox/export/drawingml.hxx
@@ -144,8 +144,8 @@ class OOX_DLLPUBLIC DrawingML
 
 private:
     static std::stack<sal_Int32> mnImageCounter;
-    static int mnWdpImageCounter;
-    static std::map<OUString, OUString> maWdpCache;
+    static std::stack<sal_Int32> mnWdpImageCounter;
+    static std::stack<std::map<OUString, OUString>> maWdpCache;
     static sal_Int32 mnDrawingMLCount;
     static sal_Int32 mnVmlCount;
     static std::stack<std::unordered_map<BitmapChecksum, OUString>> 
maExportGraphics;
@@ -348,7 +348,6 @@ public:
     static bool IsGroupShape( const css::uno::Reference< css::drawing::XShape 
>& rXShape );
     sal_Int32 getBulletMarginIndentation (const css::uno::Reference< 
css::beans::XPropertySet >& rXPropSet,sal_Int16 nLevel, std::u16string_view 
propName);
 
-    static void ResetCounters();
     static void ResetMlCounters();
 
     static void PushExportGraphics();
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index 1da6391412fc..3418a125fac5 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -237,8 +237,8 @@ void WriteGradientPath(const awt::Gradient& rGradient, 
const FSHelperPtr& pFS, c
 
 // not thread safe
 std::stack<sal_Int32> DrawingML::mnImageCounter;
-int DrawingML::mnWdpImageCounter = 1;
-std::map<OUString, OUString> DrawingML::maWdpCache;
+std::stack<sal_Int32> DrawingML::mnWdpImageCounter;
+std::stack<std::map<OUString, OUString>> DrawingML::maWdpCache;
 sal_Int32 DrawingML::mnDrawingMLCount = 0;
 sal_Int32 DrawingML::mnVmlCount = 0;
 std::stack<std::unordered_map<BitmapChecksum, OUString>> 
DrawingML::maExportGraphics;
@@ -267,12 +267,6 @@ sal_Int16 DrawingML::GetScriptType(const OUString& rStr)
     return css::i18n::ScriptType::LATIN;
 }
 
-void DrawingML::ResetCounters()
-{
-    mnWdpImageCounter = 1;
-    maWdpCache.clear();
-}
-
 void DrawingML::ResetMlCounters()
 {
     mnDrawingMLCount = 0;
@@ -283,12 +277,18 @@ void DrawingML::PushExportGraphics()
 {
     mnImageCounter.push(1);
     maExportGraphics.emplace();
+
+    mnWdpImageCounter.push(1);
+    maWdpCache.emplace();
 }
 
 void DrawingML::PopExportGraphics()
 {
     mnImageCounter.pop();
     maExportGraphics.pop();
+
+    mnWdpImageCounter.pop();
+    maWdpCache.pop();
 }
 
 bool DrawingML::GetProperty( const Reference< XPropertySet >& rXPropertySet, 
const OUString& aName )
@@ -5864,11 +5864,14 @@ void DrawingML::WriteArtisticEffect( const Reference< 
XPropertySet >& rXPropSet
 
 OString DrawingML::WriteWdpPicture( const OUString& rFileId, const Sequence< 
sal_Int8 >& rPictureData )
 {
-    std::map<OUString, OUString>::iterator aCachedItem = maWdpCache.find( 
rFileId );
-    if( aCachedItem != maWdpCache.end() )
-        return OUStringToOString( aCachedItem->second, RTL_TEXTENCODING_UTF8 );
+    if (!maWdpCache.empty())
+    {
+        std::map<OUString, OUString>::iterator aCachedItem = 
maWdpCache.top().find(rFileId);
+        if (aCachedItem != maWdpCache.top().end())
+            return OUStringToOString(aCachedItem->second, 
RTL_TEXTENCODING_UTF8);
+    }
 
-    OUString sFileName = "media/hdphoto" + OUString::number( 
mnWdpImageCounter++ ) + ".wdp";
+    OUString sFileName = "media/hdphoto" + OUString::number( 
mnWdpImageCounter.top()++ ) + ".wdp";
     Reference< XOutputStream > xOutStream = mpFB->openFragmentStream( 
OUStringBuffer()
                                                                       
.appendAscii( GetComponentDir() )
                                                                       .append( 
"/" + sFileName )
@@ -5884,7 +5887,9 @@ OString DrawingML::WriteWdpPicture( const OUString& 
rFileId, const Sequence< sal
                              .appendAscii( GetRelationCompPrefix() )
                              .append( sFileName ) );
 
-    maWdpCache[rFileId] = sId;
+    if (!maWdpCache.empty())
+        maWdpCache.top()[rFileId] = sId;
+
     return OUStringToOString( sId, RTL_TEXTENCODING_UTF8 );
 }
 
diff --git a/sd/source/filter/eppt/pptx-epptooxml.cxx 
b/sd/source/filter/eppt/pptx-epptooxml.cxx
index b31ea7de9824..a9edd475aeff 100644
--- a/sd/source/filter/eppt/pptx-epptooxml.cxx
+++ b/sd/source/filter/eppt/pptx-epptooxml.cxx
@@ -428,7 +428,6 @@ bool PowerPointExport::importDocument() noexcept
 
 bool PowerPointExport::exportDocument()
 {
-    DrawingML::ResetCounters();
     DrawingML::PushExportGraphics();
     maShapeMap.clear();
 
diff --git a/sw/qa/extras/ooxmlexport/data/artistic_effects.docx 
b/sw/qa/extras/ooxmlexport/data/artistic_effects.docx
new file mode 100644
index 000000000000..7bfb4b9d1449
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/artistic_effects.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
index 22c411d28a5a..d631c783b1a9 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
@@ -1030,6 +1030,26 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf152153)
     CPPUNIT_ASSERT_EQUAL(4, nImageFiles);
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testTdf152152)
+{
+    loadAndReload("artistic_effects.docx");
+
+    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/hdphoto"))
+            nImageFiles++;
+
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 2
+    // - Actual  : 1
+    // i.e. the once WDP picture wouldn't have been saved.
+    CPPUNIT_ASSERT_EQUAL(2, nImageFiles);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/docxexport.cxx 
b/sw/source/filter/ww8/docxexport.cxx
index 7b00df3b65ac..97875b28817d 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -527,7 +527,6 @@ ErrCode DocxExport::ExportDocument_Impl()
     m_pSections.reset(new MSWordSections( *this ));
 
     // Make sure images are counted from one, even when exporting multiple 
documents.
-    oox::drawingml::DrawingML::ResetCounters();
     oox::drawingml::DrawingML::PushExportGraphics();
 
     WriteMainText();

Reply via email to