diff options
author | Giuseppe D'Angelo <[email protected]> | 2024-05-16 21:32:31 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <[email protected]> | 2024-05-29 09:43:18 +0200 |
commit | 0dca6c40e1a66170b68941bc152aec3f29f4fd99 (patch) | |
tree | d02dfb6295b8599038c7fcbb87f8cf75695ad863 | |
parent | 2f9c72028d2481f587f378a256654d0a362e3d44 (diff) |
PDF: use a map, not a hash, to write the dest roots name tree
A PDF name tree is sorted, so just use a sorted data structure for that.
This simplifies the code.
This work has been kindly sponsored by the QGIS project
(https://qgis.org/).
Change-Id: Ib08b14aaf79c9180319efe7fefa9e797a4364d54
Reviewed-by: Albert Astals Cid <[email protected]>
-rw-r--r-- | src/gui/painting/qpdf.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp index 31e8bbdc128..716cf35ee6d 100644 --- a/src/gui/painting/qpdf.cpp +++ b/src/gui/painting/qpdf.cpp @@ -23,6 +23,8 @@ #include <qtimezone.h> #include <quuid.h> +#include <map> + #ifndef QT_NO_COMPRESS #include <zlib.h> #endif @@ -1857,7 +1859,7 @@ void QPdfEnginePrivate::writeDestsRoot() if (destCache.isEmpty()) return; - QHash<QString, int> destObjects; + std::map<QString, int> destObjects; QByteArray xs, ys; for (const DestInfo &destInfo : std::as_const(destCache)) { int destObj = addXrefEntry(-1); @@ -1865,21 +1867,19 @@ void QPdfEnginePrivate::writeDestsRoot() ys.setNum(static_cast<double>(destInfo.coords.y()), 'f'); xprintf("[%d 0 R /XYZ %s %s 0]\n", destInfo.pageObj, xs.constData(), ys.constData()); xprintf("endobj\n"); - destObjects.insert(destInfo.anchor, destObj); + destObjects.insert_or_assign(destInfo.anchor, destObj); } // names destsRoot = addXrefEntry(-1); - QStringList anchors = destObjects.keys(); - anchors.sort(); xprintf("<<\n/Limits ["); - printString(anchors.constFirst()); + printString(destObjects.begin()->first); xprintf(" "); - printString(anchors.constLast()); + printString(destObjects.rbegin()->first); xprintf("]\n/Names [\n"); - for (const QString &anchor : std::as_const(anchors)) { + for (const auto &[anchor, destObject] : destObjects) { printString(anchor); - xprintf(" %d 0 R\n", destObjects[anchor]); + xprintf(" %d 0 R\n", destObject); } xprintf("]\n>>\n" "endobj\n"); |