summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2023-03-20 17:27:32 +0100
committerAndras Timar <andras.timar@collabora.com>2023-04-02 23:38:11 +0200
commita324581efffc2fce3e2a2615c76bd7cff4bae62d (patch)
tree98f283e2c557a67bf4ec4b97890def615afb780b /writerfilter
parentc9dea9b2bd1da85cd64021a1d0e1299896f4e4fa (diff)
tdf#153255 DOCX import: fix footnote order
Simple unit test for tdf#152203 allowed to create bad ordering algorithm by accident without noticing the problem, which caused problem for most of the DOCX files, where serialization in footnotes.xml doesn't follow the order of the footnotes. Regression from commit 9b39ce0e66acfe812e1d50e530dc2ccdef3e1357 "tdf#76260 DOCX import: fix slow footnote import". Follow-up to commit 09ae3c01940bbc25ffde51963683b04e3cb4bb6a "tdf#152203 DOCX import: fix mixed footnotes/endnotes". Change-Id: I0628d96e3b8ad4df38d26e9288b47d39b958c441 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149176 Tested-by: Jenkins Reviewed-by: László Németh <nemeth@numbertext.org> (cherry picked from commit 93a20c1d9c2f379906970bbe8a15905fc1a328bc) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149242 Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.cxx14
1 files changed, 11 insertions, 3 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 833f36798534..d386e4e2e7c9 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -3729,15 +3729,23 @@ void DomainMapper_Impl::RemoveTemporaryFootOrEndnotes()
static void lcl_convertToNoteIndices(std::deque<sal_Int32>& rNoteIds, sal_Int32& rFirstNoteIndex)
{
- // convert arbitrary footnote identifiers to 0, 1, 2...
- // indices, keeping their possible random order
+ // rNoteIds contains XML footnote identifiers in the loaded order of the footnotes
+ // (the same order as in footnotes.xml), i.e. it maps temporary footnote positions to the
+ // identifiers. For example: Ids[0] = 100; Ids[1] = -1, Ids[2] = 5.
+ // To copy the footnotes in their final place, create an array, which map the (normalized)
+ // footnote identifiers to the temporary footnote positions. Using the previous example,
+ // Pos[0] = 1; Pos[1] = 2; Pos[2] = 0 (where [0], [1], [2] are the normalized
+ // -1, 5 and 100 identifiers).
std::deque<sal_Int32> aSortedIds = rNoteIds;
std::sort(aSortedIds.begin(), aSortedIds.end());
std::map<sal_Int32, size_t> aMapIds;
+ // normalize footnote identifiers to 0, 1, 2 ...
for (size_t i = 0; i < aSortedIds.size(); ++i)
aMapIds[aSortedIds[i]] = i;
+ // reusing rNoteIds, create the Pos array to map normalized identifiers to the loaded positions
+ std::deque<sal_Int32> aOrigNoteIds = rNoteIds;
for (size_t i = 0; i < rNoteIds.size(); ++i)
- rNoteIds[i] = aMapIds[rNoteIds[i]];
+ rNoteIds[aMapIds[aOrigNoteIds[i]]] = i;
rFirstNoteIndex = rNoteIds.front();
rNoteIds.pop_front();
}