diff options
author | László Németh <nemeth@numbertext.org> | 2022-07-29 17:06:22 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2022-07-31 23:15:42 +0200 |
commit | 64ac089ad5464c832592e050f5d51a136f533f21 (patch) | |
tree | 4b2152c42db3ef73e741a5830a0997f6218811d8 | |
parent | 3ccbfaaf95005a34ca64ad250463ef5ce8842f43 (diff) |
tdf#150166 DOCX export: fix broken file with tracked ToC moving
It seems, bookmark export always resulted unpaired bookmark
elements around ToC sections without causing any interoperability
problem, but replacing bookmark elements with moveRange (where
needed) releaved the problem, resulting a file format issue in MSO.
Skip export the unpaired moveRangeEnd elements until there is a
better solution, i.e. exporting moveRangeStart elements also in
paragraph-end positions before TOC sections.
Note: for back-porting this is the best, i.e. simple enough to be
stable and to get a quick review.
Regression from commit 9e1e88ad5cf2dc0e9b188c60930445652a6c7519
"tdf#145720 DOCX export: fix loss of tracked moving".
Change-Id: I93de467b6a43b2dd3fa97defaef47993969bb7ff
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137623
Tested-by: Jenkins
Reviewed-by: László Németh <nemeth@numbertext.org>
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/tdf150166.docx | bin | 0 -> 15751 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport12.cxx | 12 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 16 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.hxx | 3 |
4 files changed, 27 insertions, 4 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/tdf150166.docx b/sw/qa/extras/ooxmlexport/data/tdf150166.docx Binary files differnew file mode 100644 index 000000000000..f802ac611e1c --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/tdf150166.docx diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx index 7719bfe65631..fe4b830b5680 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx @@ -1238,6 +1238,18 @@ DECLARE_OOXMLEXPORT_TEST(testTdf145720, "tdf104797.docx") } } +DECLARE_OOXMLEXPORT_TEST(testTdf150166, "tdf150166.docx") +{ + // check moveFromRangeStart/End and moveToRangeStart/End (to keep tracked text moving) + xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); + if (mbExported) + { + assertXPath(pXmlDoc, "//w:moveFromRangeStart", 0); + // This was 2 (missing RangeStart elements, but bad unpaired RangeEnds) + assertXPath(pXmlDoc, "//w:moveFromRangeEnd", 0); + } +} + DECLARE_OOXMLEXPORT_TEST(testTdf143510, "TC-table-DnD-move.docx") { // check moveFromRangeStart/End and moveToRangeStart/End for tracked table move by drag & drop diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 9bf73a95ff9a..29896af60270 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -1965,14 +1965,22 @@ void DocxAttributeOutput::DoWriteMoveRangeTagStart(const OString & bookmarkName, pAttributeList->add(FSNS(XML_w, XML_date ), DateTimeToOString( aDateTime )); pAttributeList->add(FSNS(XML_w, XML_name), bookmarkName); m_pSerializer->singleElementNS( XML_w, bFrom ? XML_moveFromRangeStart : XML_moveToRangeStart, pAttributeList ); + + // tdf#150166 avoid of unpaired moveRangeEnd at moved ToC + m_rSavedBookmarksIds.insert(m_nNextBookmarkId); } void DocxAttributeOutput::DoWriteMoveRangeTagEnd(sal_Int32 const nId, bool bFrom) { - m_pSerializer->singleElementNS(XML_w, bFrom - ? XML_moveFromRangeEnd - : XML_moveToRangeEnd, - FSNS(XML_w, XML_id), OString::number(nId)); + if ( m_rSavedBookmarksIds.count(nId) ) + { + m_pSerializer->singleElementNS(XML_w, bFrom + ? XML_moveFromRangeEnd + : XML_moveToRangeEnd, + FSNS(XML_w, XML_id), OString::number(nId)); + + m_rSavedBookmarksIds.erase(nId); + } } void DocxAttributeOutput::DoWriteBookmarkStartIfExist(sal_Int32 nRunPos) diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx index c25c4ad1225a..9788ec1b4374 100644 --- a/sw/source/filter/ww8/docxattributeoutput.hxx +++ b/sw/source/filter/ww8/docxattributeoutput.hxx @@ -872,6 +872,9 @@ private: /// Name of the last opened bookmark. OString m_sLastOpenedBookmark; + /// Set of ids of the saved bookmarks (used only for moveRange, yet) + std::unordered_set<sal_Int32> m_rSavedBookmarksIds; + /// Maps of the annotation marks ids std::map<OString, sal_Int32> m_rOpenedAnnotationMarksIds; |