DOCX import: avoid duplicated bookmarks in copied header/footer text
commit3ec224dcb15e0e663ba85077b8ea0e632f8f03f8
authorMiklos Vajna <vmiklos@collabora.com>
Thu, 8 Sep 2022 14:41:46 +0000 (8 16:41 +0200)
committerMiklos Vajna <vmiklos@collabora.com>
Thu, 8 Sep 2022 15:46:05 +0000 (8 17:46 +0200)
treec48bb91a9a4d8b94893095b48436c403a98f60a5
parent845fa950ac635ea57dd860fb96fadcfb75e97f2b
DOCX import: avoid duplicated bookmarks in copied header/footer text

In case a DOCX document has 2 sections and the 2nd section has a linked
header, writerfilter/ copies the header text from the 1st page style to
the 2nd page style. This leads to duplicated bookmarks in the doc model,
which causes an unexpected increase in bookmark count on export.

This went wrong with 8885bdf2f564bb7b56181c50baf39ff99d551ec9
(tdf#128106 sw: copy bookmarks at start if whole node is copied,
2021-08-27), previously at least bookmarks at the start of the header
were not duplicated, though that was also inconsistent, since other
bookmarks were still duplicated. Interestingly the DOC import doesn't
have this problem, because it first copies header text and only later
imports the bookmarks.

Fix the problem by introducing a new SwCopyFlags::SkipBookmarks flag,
add UNO API to set this from writerfilter/ code and skip copying
bookmarks (but not other marks) in sw::CopyBookmarks() accordingly.
Copying other marks is still needed, because e.g. fieldmarks have a mark
and a field, and it would be inconsistent to copy the field, but not the
mark.

Note that the text is still duplicated in header/footer, linked
header/footer is a missing feature on the Writer side.

Change-Id: I40e18f231ef2c0d91ae9582621684ef5b6284904
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139697
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
sw/inc/IDocumentContentOperations.hxx
sw/qa/core/doc/data/copy-flag-skip-bookmarks.docx [new file with mode: 0644]
sw/qa/core/doc/doc.cxx
sw/source/core/doc/DocumentContentOperationsManager.cxx
sw/source/core/doc/docdesc.cxx
sw/source/core/doc/docfmt.cxx
sw/source/core/inc/DocumentContentOperationsManager.hxx
sw/source/core/unocore/unotext.cxx
writerfilter/source/dmapper/PropertyMap.cxx