diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2022-11-25 15:20:48 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2022-11-25 16:54:30 +0100 |
commit | ec345c02d8fa5a7c7d4ea4ad08ae7be5303d9b20 (patch) | |
tree | 4dd95d5b760239bd06332dfd72bbda0bb652d664 /sw | |
parent | 75eb99cec153e720407b44c376285a0c543018b2 (diff) |
tdf#152200: Make sure to not write objects into field character runs
Similar how it's done for preceding objects immediately after calculating
'ofs', we also need to make sure to create a separate run for the objects
that may be anchored after the last character; otherwise, the field that
was just processed (and is waiting in the attributes) would be put out of
place, inside an inner run (e.g., in a text box inside the object).
Change-Id: I2702693595acf4befdbd25ef07a9f7c444926aab
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143297
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/tdf152200-field+textbox.docx | bin | 0 -> 15009 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport18.cxx | 25 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtw8nds.cxx | 8 |
3 files changed, 33 insertions, 0 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/tdf152200-field+textbox.docx b/sw/qa/extras/ooxmlexport/data/tdf152200-field+textbox.docx Binary files differnew file mode 100644 index 000000000000..606d1346a27a --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/tdf152200-field+textbox.docx diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx index 04c775fa8fcb..8e2732faead8 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx @@ -187,6 +187,31 @@ CPPUNIT_TEST_FIXTURE(Test, testImageCropping) CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aGraphicCropStruct.Bottom); } +CPPUNIT_TEST_FIXTURE(Test, testTdf152200) +{ + // Given a document with a fly anchored after a FORMTEXT in the end of the paragraph: + createSwDoc("tdf152200-field+textbox.docx"); + + // When exporting that back to DOCX: + save("Office Open XML Text"); + + // Then make sure that fldChar with type 'end' goes prior to the at-char anchored fly. + xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); + const int nRunsBeforeFldCharEnd = countXPathNodes(pXmlDoc, "//w:fldChar[@w:fldCharType='end']/preceding::w:r"); + CPPUNIT_ASSERT(nRunsBeforeFldCharEnd); + const int nRunsBeforeAlternateContent = countXPathNodes(pXmlDoc, "//mc:AlternateContent/preceding::w:r"); + CPPUNIT_ASSERT(nRunsBeforeAlternateContent); + // Without the accompanying fix in place, this test would have failed with: + // - Expected greater than: 6 + // - Actual : 5 + CPPUNIT_ASSERT_GREATER(nRunsBeforeFldCharEnd, nRunsBeforeAlternateContent); + // Make sure we only have one paragraph in body, and only three field characters overal, + // located directly in runs of this paragraph + assertXPath(pXmlDoc, "/w:document/w:body/w:p"); + assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/w:fldChar", 3); + assertXPath(pXmlDoc, "//w:fldChar", 3); // no field characters elsewhere +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx index a173a2014c4b..115a009bde79 100644 --- a/sw/source/filter/ww8/wrtw8nds.cxx +++ b/sw/source/filter/ww8/wrtw8nds.cxx @@ -2640,6 +2640,14 @@ void MSWordExportBase::OutputTextNode( SwTextNode& rNode ) bPostponeWritingText = false ; AttrOutput().RunText( aSnippet, eChrSet ); } + + if (ofs == 1 && nNextAttr == nEnd) + { + // tdf#152200: There could be flys anchored after the last position; make sure + // to provide a separate run after field character to write them + AttrOutput().EndRun(&rNode, nCurrentPos, -1, nNextAttr == nEnd); + AttrOutput().StartRun(pRedlineData, nCurrentPos, bSingleEmptyRun); + } } if ( aAttrIter.IsDropCap( nNextAttr ) ) |