From deb892628a1501527c8c41b85a65282df95b81b1 Mon Sep 17 00:00:00 2001 From: Justin Luth Date: Thu, 15 Apr 2021 14:55:56 +0200 Subject: tdf#134951 docxexport: stop duplicating stuff in postponed text Certain attributes like comments, fields, and footnotes should not be duplicated when a character run is split by the bPostponeWritingText hack. Only DOCX PostponesWritingText. The comment-with-range is still not perfect, but at least it is not fully duplicated. Best would be to just get rid of the hack? A few more items suggested themselves as belonging to this list, but I don't really know what they are, and no instances of them in this position were found in the existing unit tests. So I just left them as a commented possibility. Change-Id: I950c4250b5f7ed62d63eeff71cabaa10b67dca5f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114148 Tested-by: Jenkins Reviewed-by: Justin Luth --- sw/qa/extras/ooxmlexport/data/tdf134951_duplicates.odt | Bin 0 -> 59225 bytes sw/qa/extras/ooxmlexport/ooxmlexport16.cxx | 9 +++++++++ sw/qa/extras/ooxmlexport/ooxmlexport5.cxx | 4 ++++ sw/source/filter/ww8/wrtw8nds.cxx | 11 +++++++++-- sw/source/filter/ww8/wrtww8.hxx | 2 +- 5 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 sw/qa/extras/ooxmlexport/data/tdf134951_duplicates.odt (limited to 'sw') diff --git a/sw/qa/extras/ooxmlexport/data/tdf134951_duplicates.odt b/sw/qa/extras/ooxmlexport/data/tdf134951_duplicates.odt new file mode 100644 index 000000000000..53c7076b3eeb Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf134951_duplicates.odt differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx index c272a5878ff6..ee982194ff19 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -146,6 +147,14 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf134619_numberingProps, "tdf134619_num CPPUNIT_ASSERT_EQUAL(72.f, getProperty(xStyle, "CharHeight")); } +DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf134951_duplicates, "tdf134951_duplicates.odt") +{ + uno::Reference xEndnotesSupplier(mxComponent, uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(static_cast(1), xEndnotesSupplier->getEndnotes()->getCount()); + + getParagraph(5, "Duplicate fields: 1"); +} + DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf135773_numberingShading, "tdf135774_numberingShading.docx") { // This test uses preTest to export CharBackground as Highlight instead of the 7.0 default of Shading. diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx index 404db9c59ef9..98ba668c7231 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx @@ -131,6 +131,10 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testfdo79008, "fdo79008.docx") */ parseExport("word/document.xml"); + // tdf#134951: there is only one comment + xmlDocUniquePtr pXmlSettings = parseExport("word/comments.xml"); + assertXPath(pXmlSettings, "/w:comments/w:comment", 1); + // Read-only is set, but it is not enforced, so it should be off... SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); CPPUNIT_ASSERT(pTextDoc); diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx index 729c8dc0db97..5f96377e7d2c 100644 --- a/sw/source/filter/ww8/wrtw8nds.cxx +++ b/sw/source/filter/ww8/wrtw8nds.cxx @@ -395,7 +395,7 @@ sal_Int32 SwWW8AttrIter::SearchNext( sal_Int32 nStartPos ) return nMinPos; } -void SwWW8AttrIter::OutAttr( sal_Int32 nSwPos, bool bWriteCombChars) +void SwWW8AttrIter::OutAttr(sal_Int32 nSwPos, bool bWriteCombChars, bool bPostponeSingleUse) { m_rExport.AttrOutput().RTLAndCJKState( mbCharIsRTL, GetScript() ); @@ -460,6 +460,13 @@ void SwWW8AttrIter::OutAttr( sal_Int32 nSwPos, bool bWriteCombChars) nWhichId = aIter.NextWhich(); } } + else if (bPostponeSingleUse && + (nWhich == RES_TXTATR_FTN || nWhich == RES_TXTATR_ANNOTATION || nWhich == RES_TXTATR_FIELD)) + { + // Do not duplicate these multiple times when the character run is split. + // Skip this time - it will be attempted later. + // ?? also RES_TXTATR_REFMARK: RES_TXTATR_TOXMARK: RES_TXTATR_META: RES_TXTATR_METAFIELD: ?? + } else aRangeItems[nWhich] = (&(pHt->GetAttr())); } @@ -2613,7 +2620,7 @@ void MSWordExportBase::OutputTextNode( SwTextNode& rNode ) // Output the character attributes // #i51277# do this before writing flys at end of paragraph AttrOutput().StartRunProperties(); - aAttrIter.OutAttr( nCurrentPos, false ); + aAttrIter.OutAttr(nCurrentPos, false, bPostponeWritingText); AttrOutput().EndRunProperties( pRedlineData ); } diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx index 66c4573dc96a..1c4c3e936d82 100644 --- a/sw/source/filter/ww8/wrtww8.hxx +++ b/sw/source/filter/ww8/wrtww8.hxx @@ -1538,7 +1538,7 @@ public: void NextPos() { if ( nCurrentSwPos < SAL_MAX_INT32 ) nCurrentSwPos = SearchNext( nCurrentSwPos + 1 ); } - void OutAttr( sal_Int32 nSwPos, bool bWriteCombinedChars ); + void OutAttr(sal_Int32 nSwPos, bool bWriteCombinedChars, bool bPostponeSingleUse = false); virtual const SfxPoolItem* HasTextItem( sal_uInt16 nWhich ) const override; virtual const SfxPoolItem& GetItem( sal_uInt16 nWhich ) const override; int OutAttrWithRange(const SwTextNode& rNode, sal_Int32 nPos); -- cgit