sw/qa/extras/odfexport/data/DUMMY2.odt    |binary
 sw/qa/extras/odfexport/data/DUMMY2B.odt   |binary
 sw/qa/extras/odfexport/data/tdf121119.odm |binary
 sw/qa/extras/odfexport/odfexport2.cxx     |   35 ++++++++++++++++++++++++++++++
 sw/source/core/docnode/section.cxx        |    4 +++
 xmloff/source/text/txtparae.cxx           |   15 ++++++++++++
 6 files changed, 54 insertions(+)

New commits:
commit fb4197ed81765e122b862471e184fcade4a2b524
Author:     László Németh <[email protected]>
AuthorDate: Thu Jan 23 12:08:04 2025 +0100
Commit:     László Németh <[email protected]>
CommitDate: Thu Jan 23 17:29:39 2025 +0100

    tdf#121119 master docs at-page anchor: fix duplicated images
    
    Skip saving images anchored at page in the master document,
    if they are imported from subdocuments to avoid their duplication
    during the round-trip/update of the linked subdocuments.
    
    Follow-up to commit 2f135fa82c5d78ddafc14f38c0ee33358075b266
    "tdf#121119 master docs at-page anchor: fix missing images".
    
    Change-Id: I731026bee01576fe66c9d677b53c7f85a53230fa
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180627
    Tested-by: Jenkins
    Reviewed-by: László Németh <[email protected]>

diff --git a/sw/qa/extras/odfexport/data/DUMMY2.odt 
b/sw/qa/extras/odfexport/data/DUMMY2.odt
new file mode 100644
index 000000000000..9e616cc80767
Binary files /dev/null and b/sw/qa/extras/odfexport/data/DUMMY2.odt differ
diff --git a/sw/qa/extras/odfexport/data/DUMMY2B.odt 
b/sw/qa/extras/odfexport/data/DUMMY2B.odt
new file mode 100644
index 000000000000..92d6c15c51f1
Binary files /dev/null and b/sw/qa/extras/odfexport/data/DUMMY2B.odt differ
diff --git a/sw/qa/extras/odfexport/data/tdf121119.odm 
b/sw/qa/extras/odfexport/data/tdf121119.odm
new file mode 100644
index 000000000000..ea7784a20058
Binary files /dev/null and b/sw/qa/extras/odfexport/data/tdf121119.odm differ
diff --git a/sw/qa/extras/odfexport/odfexport2.cxx 
b/sw/qa/extras/odfexport/odfexport2.cxx
index 2dcac38ae108..70e8e9bfa70d 100644
--- a/sw/qa/extras/odfexport/odfexport2.cxx
+++ b/sw/qa/extras/odfexport/odfexport2.cxx
@@ -42,6 +42,8 @@
 #include <unotxdoc.hxx>
 #include <docsh.hxx>
 #include <IDocumentFieldsAccess.hxx>
+#include <IDocumentLinksAdministration.hxx>
+#include <sfx2/linkmgr.hxx>
 
 namespace
 {
@@ -1753,6 +1755,39 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf159027)
     CPPUNIT_ASSERT_EQUAL(u"6"_ustr, xCellE9->getString());
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testTdf121119)
+{
+    createSwGlobalDoc("tdf121119.odm");
+    SwDoc* pDoc = getSwDoc();
+    CPPUNIT_ASSERT_EQUAL(
+        size_t(2), 
pDoc->getIDocumentLinksAdministration().GetLinkManager().GetLinks().size());
+    
pDoc->getIDocumentLinksAdministration().GetLinkManager().UpdateAllLinks(false, 
false, nullptr,
+                                                                            
u""_ustr);
+
+    uno::Reference<text::XTextGraphicObjectsSupplier> 
xTextGraphicObjectsSupplier(mxComponent,
+                                                                               
   uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> xIndexAccess(
+        xTextGraphicObjectsSupplier->getGraphicObjects(), uno::UNO_QUERY);
+
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xIndexAccess->getCount());
+
+    saveAndReload(u"writerglobal8_writer"_ustr);
+    pDoc = getSwDoc();
+
+    CPPUNIT_ASSERT_EQUAL(
+        size_t(2), 
pDoc->getIDocumentLinksAdministration().GetLinkManager().GetLinks().size());
+    
pDoc->getIDocumentLinksAdministration().GetLinkManager().UpdateAllLinks(false, 
false, nullptr,
+                                                                            
u""_ustr);
+
+    uno::Reference<text::XTextGraphicObjectsSupplier> 
xTextGraphicObjectsSupplier2(mxComponent,
+                                                                               
   uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> xIndexAccess2(
+        xTextGraphicObjectsSupplier2->getGraphicObjects(), uno::UNO_QUERY);
+
+    // This was 8 (duplicated images anchored at page)
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xIndexAccess2->getCount());
+}
+
 CPPUNIT_TEST_FIXTURE(Test, testTdf163703)
 {
     // Given a document with italics autostyle in a comment
diff --git a/sw/source/core/docnode/section.cxx 
b/sw/source/core/docnode/section.cxx
index 0ef7e5705c6e..2858aa8e799f 100644
--- a/sw/source/core/docnode/section.cxx
+++ b/sw/source/core/docnode/section.cxx
@@ -1274,6 +1274,10 @@ static void lcl_UpdateLinksInSect( const SwBaseLink& 
rUpdLnk, SwSectionNode& rSe
                     sal_uInt32 nPrevPages = 0;
                     for( sw::SpzFrameFormat* pCpyFormat: *pSrcFormats)
                     {
+                        // add file name of the source document to the name of 
the copied object
+                        // Note: used for the recognition of the copied 
objects anchored at page
+                        pCpyFormat->SetFormatName( pCpyFormat->GetName() + " 
(" + sFileName + ")" );
+
                         SwFormatAnchor aAnchor( pCpyFormat->GetAnchor() );
                         if ( RndStdIds::FLY_AT_PAGE == aAnchor.GetAnchorId() )
                         {
diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx
index 1df1e2dc0d78..86c4ecb0eab9 100644
--- a/xmloff/source/text/txtparae.cxx
+++ b/xmloff/source/text/txtparae.cxx
@@ -3339,6 +3339,21 @@ void XMLTextParagraphExport::_exportTextGraphic(
         const Reference < XPropertySet > & rPropSet,
         const Reference < XPropertySetInfo > & rPropSetInfo )
 {
+    // skip objects anchored at page in master documents,
+    // if they are imported from the subdocuments
+    TextContentAnchorType eAnchor;
+    rPropSet->getPropertyValue(u"AnchorType"_ustr) >>= eAnchor;
+    if( TextContentAnchorType_AT_PAGE == eAnchor )
+    {
+        Reference<XServiceInfo> xServiceInfo(GetExport().GetModel(), 
UNO_QUERY);
+        if( 
xServiceInfo->supportsService(u"com.sun.star.text.GlobalDocument"_ustr) )
+        {
+            Reference<XNamed> xNamed( rPropSet, UNO_QUERY );
+            if( xNamed.is() && xNamed->getName().indexOf(" (file://") > -1 )
+                return;
+        }
+    }
+
     OUString sStyle;
     if( rPropSetInfo->hasPropertyByName( gsFrameStyleName ) )
     {

Reply via email to