summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2023-03-20 17:27:32 +0100
committerCaolán McNamara <caolanm@redhat.com>2023-03-24 10:19:20 +0000
commit0a74936870937b64ef841d5ae78ac3bea876f16d (patch)
tree17ebccaf579442582ca10b79e1d253125de1c4af /writerfilter
parent69ca62c2fa66263f0239709446ea0b43fd9daa3d (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/+/149299 Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org> Reviewed-by: Michael Stahl <michael.stahl@allotropia.de> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
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 e9fda3f50101..449c75e9b8ce 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -3716,15 +3716,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();
}