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 <justin_luth@sil.org>
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 0000000..53c7076
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf134951_duplicates.odt
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
index c272a58..ee98219 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
@@ -16,6 +16,7 @@
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/drawing/FillStyle.hpp>
#include <com/sun/star/text/XEndnotesSupplier.hpp>
#include <com/sun/star/text/XFootnotesSupplier.hpp>
#include <com/sun/star/text/XTextViewCursorSupplier.hpp>
#include <com/sun/star/text/XTextTable.hpp>
@@ -146,6 +147,14 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf134619_numberingProps, "tdf134619_num
CPPUNIT_ASSERT_EQUAL(72.f, getProperty<float>(xStyle, "CharHeight"));
}
DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf134951_duplicates, "tdf134951_duplicates.odt")
{
uno::Reference<text::XEndnotesSupplier> xEndnotesSupplier(mxComponent, uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(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 404db9c..98ba668 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<SwXTextDocument *>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx
index 729c8dc..5f96377 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 66c4573..1c4c3e9 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);