poppler/PSOutputDev.cc | 24 ++++++------------------ poppler/PSOutputDev.h | 6 ++---- 2 files changed, 8 insertions(+), 22 deletions(-)
New commits: commit 23994cf44ac8a11b0dfbf159df669bbe1ac78dc3 Author: Oliver Sander <[email protected]> Date: Wed Mar 29 12:31:18 2023 +0200 Use std::vector for the fontIDs array This makes the code safer and easier to read. 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 <[email protected]> // Copyright (C) 2018 Philipp Knechtges <[email protected]> // Copyright (C) 2019, 2021 Christian Persch <[email protected]> -// Copyright (C) 2019, 2021, 2022 Oliver Sander <[email protected]> +// Copyright (C) 2019, 2021-2023 Oliver Sander <[email protected]> // Copyright (C) 2020, 2021 Philipp Knechtges <[email protected]> // Copyright (C) 2021 Hubert Figuiere <[email protected]> // @@ -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, <[email protected]>. Work sponsored by the LiMux project of the city of Munich // Copyright (C) 2018 Adam Reichold <[email protected]> // Copyright (C) 2018, 2020 Philipp Knechtges <[email protected]> -// Copyright (C) 2019 Oliver Sander <[email protected]> +// Copyright (C) 2019, 2023 Oliver Sander <[email protected]> // Copyright (C) 2021 Hubert Figuiere <[email protected]> // Copyright (C) 2021 Christian Persch <[email protected]> // @@ -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
