[poppler] 2 commits - poppler/GfxFont.cc poppler/GfxFont.h

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Mar 8 13:15:24 UTC 2022


 poppler/GfxFont.cc |   27 ++++++++++-----------------
 poppler/GfxFont.h  |   11 +++++------
 2 files changed, 15 insertions(+), 23 deletions(-)

New commits:
commit 3ecb7663c5f787c4ef877d8e0884036e4fb236f2
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date:   Tue Mar 8 10:02:42 2022 +0100

    Store GfxFontDict::fonts in a std::vector

diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc
index f0c4b28c..62b7429d 100644
--- a/poppler/GfxFont.cc
+++ b/poppler/GfxFont.cc
@@ -2353,12 +2353,10 @@ double GfxCIDFont::getWidth(char *s, int len) const
 
 GfxFontDict::GfxFontDict(XRef *xref, Ref *fontDictRef, Dict *fontDict)
 {
-    int i;
     Ref r;
 
-    numFonts = fontDict->getLength();
-    fonts = (GfxFont **)gmallocn(numFonts, sizeof(GfxFont *));
-    for (i = 0; i < numFonts; ++i) {
+    fonts.resize(fontDict->getLength());
+    for (std::size_t i = 0; i < fonts.size(); ++i) {
         const Object &obj1 = fontDict->getValNF(i);
         Object obj2 = obj1.fetch(xref);
         if (obj2.isDict()) {
@@ -2393,23 +2391,18 @@ GfxFontDict::GfxFontDict(XRef *xref, Ref *fontDictRef, Dict *fontDict)
 
 GfxFontDict::~GfxFontDict()
 {
-    int i;
-
-    for (i = 0; i < numFonts; ++i) {
-        if (fonts[i]) {
-            fonts[i]->decRefCnt();
+    for (auto &font : fonts) {
+        if (font) {
+            font->decRefCnt();
         }
     }
-    gfree(fonts);
 }
 
 GfxFont *GfxFontDict::lookup(const char *tag) const
 {
-    int i;
-
-    for (i = 0; i < numFonts; ++i) {
-        if (fonts[i] && fonts[i]->matches(tag)) {
-            return fonts[i];
+    for (const auto &font : fonts) {
+        if (font && font->matches(tag)) {
+            return font;
         }
     }
     return nullptr;
diff --git a/poppler/GfxFont.h b/poppler/GfxFont.h
index f824e13d..c88de3c6 100644
--- a/poppler/GfxFont.h
+++ b/poppler/GfxFont.h
@@ -464,15 +464,14 @@ public:
     GfxFont *lookup(const char *tag) const;
 
     // Iterative access.
-    int getNumFonts() const { return numFonts; }
+    int getNumFonts() const { return fonts.size(); }
     GfxFont *getFont(int i) const { return fonts[i]; }
 
 private:
     int hashFontObject(Object *obj);
     void hashFontObject1(const Object *obj, FNVHash *h);
 
-    GfxFont **fonts; // list of fonts
-    int numFonts; // number of fonts
+    std::vector<GfxFont *> fonts;
 };
 
 #endif
commit 34ecd262997ebe6a9eb3b1abdf38d76428a23adf
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date:   Tue Mar 8 09:51:03 2022 +0100

    Make method getWMode const

diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc
index bd30e892..f0c4b28c 100644
--- a/poppler/GfxFont.cc
+++ b/poppler/GfxFont.cc
@@ -35,7 +35,7 @@
 // Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info at kdab.com>. Work sponsored by the LiMux project of the city of Munich
 // Copyright (C) 2018 Adam Reichold <adam.reichold at t-online.de>
 // Copyright (C) 2019 LE GARREC Vincent <legarrec.vincent at gmail.com>
-// Copyright (C) 2021 Oliver Sander <oliver.sander at tu-dresden.de>
+// Copyright (C) 2021, 2022 Oliver Sander <oliver.sander at tu-dresden.de>
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -2061,7 +2061,7 @@ int GfxCIDFont::getNextChar(const char *s, int len, CharCode *code, Unicode cons
     return n;
 }
 
-int GfxCIDFont::getWMode()
+int GfxCIDFont::getWMode() const
 {
     return cMap ? cMap->getWMode() : 0;
 }
diff --git a/poppler/GfxFont.h b/poppler/GfxFont.h
index 6cb3514b..f824e13d 100644
--- a/poppler/GfxFont.h
+++ b/poppler/GfxFont.h
@@ -24,7 +24,7 @@
 // Copyright (C) 2015, 2018 Jason Crain <jason at aquaticape.us>
 // Copyright (C) 2015 Thomas Freitag <Thomas.Freitag at alfa.de>
 // Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info at kdab.com>. Work sponsored by the LiMux project of the city of Munich
-// Copyright (C) 2021 Oliver Sander <oliver.sander at tu-dresden.de>
+// Copyright (C) 2021, 2022 Oliver Sander <oliver.sander at tu-dresden.de>
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -274,7 +274,7 @@ public:
     double getDescent() const { return descent; }
 
     // Return the writing mode (0=horizontal, 1=vertical).
-    virtual int getWMode() { return 0; }
+    virtual int getWMode() const { return 0; }
 
     // Locate the font file for this font.  If <ps> is not null, includes PS
     // printer-resident fonts.  Returns std::optional without a value on failure.
@@ -410,7 +410,7 @@ public:
     int getNextChar(const char *s, int len, CharCode *code, Unicode const **u, int *uLen, double *dx, double *dy, double *ox, double *oy) const override;
 
     // Return the writing mode (0=horizontal, 1=vertical).
-    int getWMode() override;
+    int getWMode() const override;
 
     // Return the Unicode map.
     const CharCodeToUnicode *getToUnicode() const override;


More information about the poppler mailing list