sw/qa/extras/odfexport/odfexport2.cxx | 21 +++++++++++++++++++++ sw/source/core/docnode/section.cxx | 13 +++++++++++++ 2 files changed, 34 insertions(+)
New commits: commit 47d596688f2dcdf67fab24e58d92f823e69c0c35 Author: László Németh <nem...@numbertext.org> AuthorDate: Thu Jan 23 12:58:15 2025 +0100 Commit: László Németh <nem...@numbertext.org> CommitDate: Thu Jan 23 17:30:57 2025 +0100 tdf#121119 master docs at-page anchor: fix runtime duplicated images Asking for "All" update of the master document resulted duplicated objects anchored at page, loading the subdocuments again, which contained the images originally. Follow-up to commit 2f135fa82c5d78ddafc14f38c0ee33358075b266 "tdf#121119 master docs at-page anchor: fix missing images" and commit fb4197ed81765e122b862471e184fcade4a2b524 "tdf#121119 master docs at-page anchor: fix duplicated images". Change-Id: I4c76c325963cd740906045653fc90055ce1840c6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180628 Reviewed-by: László Németh <nem...@numbertext.org> Tested-by: Jenkins diff --git a/sw/qa/extras/odfexport/odfexport2.cxx b/sw/qa/extras/odfexport/odfexport2.cxx index 70e8e9bfa70d..39659ff96ef0 100644 --- a/sw/qa/extras/odfexport/odfexport2.cxx +++ b/sw/qa/extras/odfexport/odfexport2.cxx @@ -1788,6 +1788,27 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf121119) CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xIndexAccess2->getCount()); } +CPPUNIT_TEST_FIXTURE(Test, testTdf121119_runtime_update) +{ + 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); + // double update of the links + 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); + + // This was 8 (duplicated images anchored at page) + CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xIndexAccess->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 2858aa8e799f..383a2ef33ebf 100644 --- a/sw/source/core/docnode/section.cxx +++ b/sw/source/core/docnode/section.cxx @@ -1264,6 +1264,19 @@ static void lcl_UpdateLinksInSect( const SwBaseLink& rUpdLnk, SwSectionNode& rSe } else if( pSrcDoc != pDoc ) { + // before update, remove obsolete page-anchored flys from the target master document + auto pFormats = pDoc->GetSpzFrameFormats(); + for( sal_uInt16 nCnt = pFormats->size(); nCnt; ) + { + SwFrameFormat* pFormat = (*pFormats)[ --nCnt ]; + SwFormatAnchor aAnchor( pFormat->GetAnchor() ); + if ( RndStdIds::FLY_AT_PAGE == aAnchor.GetAnchorId() && + pFormat->GetName().indexOf(sFileName) > -1 ) + { + pDoc->getIDocumentLayoutAccess().DelLayoutFormat( pFormat ); + } + } + // store page count of the source document to calculate // the physical page number of the objects anchored at page const SwDocStat& rDStat = pSrcDoc->getIDocumentStatistics().GetDocStat();