diff options
author | Oliver Sander <oliver.sander@tu-dresden.de> | 2023-03-29 12:31:18 +0200 |
---|---|---|
committer | Oliver Sander <oliver.sander@tu-dresden.de> | 2023-03-29 12:31:18 +0200 |
commit | 23994cf44ac8a11b0dfbf159df669bbe1ac78dc3 (patch) | |
tree | 8727f3278bbe9a8c56008793ce73ead1be45db94 | |
parent | 09aed1a65e703ec419980506d12578ca4149f58d (diff) |
Use std::vector for the fontIDs array
This makes the code safer and easier to read.
-rw-r--r-- | poppler/PSOutputDev.cc | 24 | ||||
-rw-r--r-- | poppler/PSOutputDev.h | 6 |
2 files changed, 8 insertions, 22 deletions
diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc index cdabc251..23e3dcf0 100644 --- a/poppler/PSOutputDev.cc +++ b/poppler/PSOutputDev.cc @@ -35,7 +35,7 @@ // Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de> // Copyright (C) 2018 Philipp Knechtges <philipp-dev@knechtges.com> // Copyright (C) 2019, 2021 Christian Persch <chpe@src.gnome.org> -// Copyright (C) 2019, 2021, 2022 Oliver Sander <oliver.sander@tu-dresden.de> +// Copyright (C) 2019, 2021-2023 Oliver Sander <oliver.sander@tu-dresden.de> // Copyright (C) 2020, 2021 Philipp Knechtges <philipp-dev@knechtges.com> // Copyright (C) 2021 Hubert Figuiere <hub@figuiere.net> // @@ -1092,7 +1092,6 @@ PSOutputDev::PSOutputDev(const char *fileName, PDFDoc *docA, char *psTitleA, con customCodeCbk = customCodeCbkA; customCodeCbkData = customCodeCbkDataA; - fontIDs = nullptr; t1FontNames = nullptr; font8Info = nullptr; font16Enc = nullptr; @@ -1151,7 +1150,6 @@ PSOutputDev::PSOutputDev(int fdA, PDFDoc *docA, char *psTitleA, const std::vecto customCodeCbk = customCodeCbkA; customCodeCbkData = customCodeCbkDataA; - fontIDs = nullptr; t1FontNames = nullptr; font8Info = nullptr; font16Enc = nullptr; @@ -1191,7 +1189,6 @@ PSOutputDev::PSOutputDev(FoFiOutputFunc outputFuncA, void *outputStreamA, char * customCodeCbk = customCodeCbkA; customCodeCbkData = customCodeCbkDataA; - fontIDs = nullptr; t1FontNames = nullptr; font8Info = nullptr; font16Enc = nullptr; @@ -1407,9 +1404,8 @@ void PSOutputDev::postInit() } // initialize fontIDs, fontFileIDs, and fontFileNames lists - fontIDSize = 64; - fontIDLen = 0; - fontIDs = (Ref *)gmallocn(fontIDSize, sizeof(Ref)); + fontIDs.reserve(64); + fontIDs.resize(0); for (i = 0; i < 14; ++i) { fontNames.emplace(psBase14SubstFonts[i].psName); } @@ -1550,9 +1546,6 @@ PSOutputDev::~PSOutputDev() if (embFontList) { delete embFontList; } - if (fontIDs) { - gfree(fontIDs); - } if (t1FontNames) { for (i = 0; i < t1FontNameLen; ++i) { delete t1FontNames[i].psName; @@ -1963,18 +1956,13 @@ void PSOutputDev::setupFont(GfxFont *font, Dict *parentResDict) int i, j; // check if font is already set up - for (i = 0; i < fontIDLen; ++i) { - if (fontIDs[i] == *font->getID()) { + for (Ref fontID : fontIDs) { + if (fontID == *font->getID()) { return; } } - // add entry to fontIDs list - if (fontIDLen >= fontIDSize) { - fontIDSize += 64; - fontIDs = (Ref *)greallocn(fontIDs, fontIDSize, sizeof(Ref)); - } - fontIDs[fontIDLen++] = *font->getID(); + fontIDs.push_back(*font->getID()); psName = nullptr; xs = ys = 1; diff --git a/poppler/PSOutputDev.h b/poppler/PSOutputDev.h index 76d72396..dad0a384 100644 --- a/poppler/PSOutputDev.h +++ b/poppler/PSOutputDev.h @@ -27,7 +27,7 @@ // Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich // Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de> // Copyright (C) 2018, 2020 Philipp Knechtges <philipp-dev@knechtges.com> -// Copyright (C) 2019 Oliver Sander <oliver.sander@tu-dresden.de> +// Copyright (C) 2019, 2023 Oliver Sander <oliver.sander@tu-dresden.de> // Copyright (C) 2021 Hubert Figuiere <hub@figuiere.net> // Copyright (C) 2021 Christian Persch <chpe@src.gnome.org> // @@ -447,9 +447,7 @@ private: PDFDoc *doc; XRef *xref; // the xref table for this PDF file - Ref *fontIDs; // list of object IDs of all used fonts - int fontIDLen; // number of entries in fontIDs array - int fontIDSize; // size of fontIDs array + std::vector<Ref> fontIDs; // list of object IDs of all used fonts std::set<int> resourceIDs; // list of object IDs of objects containing Resources we've already set up std::unordered_set<std::string> fontNames; // all used font names std::unordered_map<std::string, int> perFontMaxValidGlyph; // max valid glyph of each font |