[poppler] glib/poppler-structure-element.cc poppler/FontInfo.cc poppler/GfxFont.cc poppler/GfxFont.h poppler/GlobalParams.cc poppler/GlobalParamsWin.cc poppler/PSOutputDev.cc poppler/TextOutputDev.cc utils/HtmlFonts.cc

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Mar 30 16:53:22 UTC 2022


 glib/poppler-structure-element.cc |   10 +++--
 poppler/FontInfo.cc               |    8 +---
 poppler/GfxFont.cc                |   70 +++++++++++++++++---------------------
 poppler/GfxFont.h                 |   10 ++---
 poppler/GlobalParams.cc           |   20 +++++-----
 poppler/GlobalParamsWin.cc        |    6 +--
 poppler/PSOutputDev.cc            |   12 +++---
 poppler/TextOutputDev.cc          |    2 -
 utils/HtmlFonts.cc                |    6 +--
 9 files changed, 70 insertions(+), 74 deletions(-)

New commits:
commit 404edfd151b814c7c4e771eda5826e65ee7c5f84
Author: Albert Astals Cid <aacid at kde.org>
Date:   Sun Mar 27 22:37:15 2022 +0200

    Change GfxFont name into an optional std::string

diff --git a/glib/poppler-structure-element.cc b/glib/poppler-structure-element.cc
index 8b5e37c7..600fe956 100644
--- a/glib/poppler-structure-element.cc
+++ b/glib/poppler-structure-element.cc
@@ -794,11 +794,15 @@ static PopplerTextSpan *text_span_poppler_text_span(const TextSpan &span)
         // GfxFont sometimes does not have a family name but there
         // is always a font name that can be used as fallback.
         const GooString *font_name = span.getFont()->getFamily();
-        if (font_name == nullptr) {
-            font_name = span.getFont()->getName();
+        if (font_name) {
+            new_span->font_name = _poppler_goo_string_to_utf8(font_name);
+        } else if (span.getFont()->getName()) {
+            const GooString aux(*span.getFont()->getName());
+            new_span->font_name = _poppler_goo_string_to_utf8(&aux);
+        } else {
+            new_span->font_name = nullptr;
         }
 
-        new_span->font_name = _poppler_goo_string_to_utf8(font_name);
         if (span.getFont()->isFixedWidth()) {
             new_span->flags |= POPPLER_TEXT_SPAN_FIXED_WIDTH;
         }
diff --git a/poppler/FontInfo.cc b/poppler/FontInfo.cc
index 4381509c..23425f61 100644
--- a/poppler/FontInfo.cc
+++ b/poppler/FontInfo.cc
@@ -162,14 +162,12 @@ void FontInfoScanner::scanFonts(XRef *xrefA, Dict *resDict, std::vector<FontInfo
 
 FontInfo::FontInfo(GfxFont *font, XRef *xref)
 {
-    const GooString *origName;
-
     fontRef = *font->getID();
 
     // font name
-    origName = font->getName();
-    if (origName != nullptr) {
-        name = font->getName()->toStr();
+    const std::optional<std::string> &origName = font->getName();
+    if (origName) {
+        name = *font->getName();
     }
 
     // font type
diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc
index 16a62c43..b0d0d610 100644
--- a/poppler/GfxFont.cc
+++ b/poppler/GfxFont.cc
@@ -199,15 +199,14 @@ const GooString *GfxFontLoc::pathAsGooString() const
 
 std::unique_ptr<GfxFont> GfxFont::makeFont(XRef *xref, const char *tagA, Ref idA, Dict *fontDict)
 {
-    GooString *nameA;
+    std::optional<std::string> name;
     Ref embFontIDA;
     GfxFontType typeA;
 
     // get base font name
-    nameA = nullptr;
     Object obj1 = fontDict->lookup("BaseFont");
     if (obj1.isName()) {
-        nameA = new GooString(obj1.getName());
+        name = obj1.getName();
     }
 
     // get embedded font ID and font type
@@ -216,18 +215,17 @@ std::unique_ptr<GfxFont> GfxFont::makeFont(XRef *xref, const char *tagA, Ref idA
     // create the font object
     GfxFont *font;
     if (typeA < fontCIDType0) {
-        font = new Gfx8BitFont(xref, tagA, idA, nameA, typeA, embFontIDA, fontDict);
+        font = new Gfx8BitFont(xref, tagA, idA, std::move(name), typeA, embFontIDA, fontDict);
     } else {
-        font = new GfxCIDFont(xref, tagA, idA, nameA, typeA, embFontIDA, fontDict);
+        font = new GfxCIDFont(xref, tagA, idA, std::move(name), typeA, embFontIDA, fontDict);
     }
 
     return std::unique_ptr<GfxFont>(font);
 }
 
-GfxFont::GfxFont(const char *tagA, Ref idA, const GooString *nameA, GfxFontType typeA, Ref embFontIDA) : tag(tagA), id(idA), type(typeA)
+GfxFont::GfxFont(const char *tagA, Ref idA, std::optional<std::string> &&nameA, GfxFontType typeA, Ref embFontIDA) : tag(tagA), id(idA), name(std::move(nameA)), type(typeA)
 {
     ok = false;
-    name = nameA;
     embFontID = embFontIDA;
     embFontName = nullptr;
     family = nullptr;
@@ -239,9 +237,6 @@ GfxFont::GfxFont(const char *tagA, Ref idA, const GooString *nameA, GfxFontType
 GfxFont::~GfxFont()
 {
     delete family;
-    if (name) {
-        delete name;
-    }
     if (embFontName) {
         delete embFontName;
     }
@@ -250,13 +245,13 @@ GfxFont::~GfxFont()
 bool GfxFont::isSubset() const
 {
     if (name) {
-        int i;
-        for (i = 0; i < name->getLength(); ++i) {
-            if (name->getChar(i) < 'A' || name->getChar(i) > 'Z') {
+        unsigned int i;
+        for (i = 0; i < name->size(); ++i) {
+            if ((*name)[i] < 'A' || (*name)[i] > 'Z') {
                 break;
             }
         }
-        return i == 6 && name->getLength() > 7 && name->getChar(6) == '+';
+        return i == 6 && name->size() > 7 && (*name)[6] == '+';
     }
     return false;
 }
@@ -268,10 +263,10 @@ std::string GfxFont::getNameWithoutSubsetTag() const
     }
 
     if (!isSubset()) {
-        return name->toStr();
+        return *name;
     }
 
-    return name->toStr().substr(7);
+    return name->substr(7);
 }
 
 // This function extracts three pieces of information:
@@ -672,7 +667,7 @@ std::optional<GfxFontLoc> GfxFont::locateFont(XRef *xref, PSOutputDev *ps)
         GfxFontLoc fontLoc;
         fontLoc.locType = gfxFontLocResident;
         fontLoc.fontType = fontType1;
-        fontLoc.setPath(name->copy());
+        fontLoc.path = *name;
         return std::move(fontLoc); // std::move only required to please g++-7
     }
 
@@ -686,7 +681,7 @@ std::optional<GfxFontLoc> GfxFont::locateFont(XRef *xref, PSOutputDev *ps)
     }
 
     //----- external font file (fontFile, fontDir)
-    if (name && (path = globalParams->findFontFile(name->toStr()))) {
+    if (name && (path = globalParams->findFontFile(*name))) {
         if (std::optional<GfxFontLoc> fontLoc = getExternalFont(path, isCIDFont())) {
             return fontLoc;
         }
@@ -760,7 +755,7 @@ std::optional<GfxFontLoc> GfxFont::locateFont(XRef *xref, PSOutputDev *ps)
             if (path) {
                 if (std::optional<GfxFontLoc> fontLoc = getExternalFont(path, false)) {
                     error(errSyntaxWarning, -1, "Substituting font '{0:s}' for '{1:s}'", base14SubstFonts[substIdx], name ? name->c_str() : "");
-                    name = new GooString(base14SubstFonts[substIdx]);
+                    name = base14SubstFonts[substIdx];
                     fontLoc->substIdx = substIdx;
                     return fontLoc;
                 }
@@ -947,9 +942,8 @@ static bool testForNumericNames(Dict *fontDict, bool hex)
     return numeric;
 }
 
-Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA, GfxFontType typeA, Ref embFontIDA, Dict *fontDict) : GfxFont(tagA, idA, nameA, typeA, embFontIDA)
+Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, std::optional<std::string> &&nameA, GfxFontType typeA, Ref embFontIDA, Dict *fontDict) : GfxFont(tagA, idA, std::move(nameA), typeA, embFontIDA)
 {
-    GooString *name2;
     const BuiltinFont *builtinFont;
     const char **baseEnc;
     bool baseEncFromFontFile;
@@ -965,7 +959,7 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA
     int firstChar, lastChar;
     unsigned short w;
     Object obj1;
-    int n, i, a, b, m;
+    int n, a, b, m;
 
     ctu = nullptr;
 
@@ -973,11 +967,11 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA
     // names
     base14 = nullptr;
     if (name) {
-        name2 = name->copy();
-        i = 0;
-        while (i < name2->getLength()) {
-            if (name2->getChar(i) == ' ') {
-                name2->del(i);
+        std::string name2 = *name;
+        size_t i = 0;
+        while (i < name2.size()) {
+            if (name2[i] == ' ') {
+                name2.erase(i, 1);
             } else {
                 ++i;
             }
@@ -987,16 +981,15 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA
         // invariant: base14FontMap[a].altName <= name2 < base14FontMap[b].altName
         while (b - a > 1) {
             m = (a + b) / 2;
-            if (name2->cmp(base14FontMap[m].altName) >= 0) {
+            if (name2.compare(base14FontMap[m].altName) >= 0) {
                 a = m;
             } else {
                 b = m;
             }
         }
-        if (!name2->cmp(base14FontMap[a].altName)) {
+        if (name2 == base14FontMap[a].altName) {
             base14 = &base14FontMap[a];
         }
-        delete name2;
     }
 
     // is it a built-in font?
@@ -1043,7 +1036,7 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA
     fontMat[1] = fontMat[2] = fontMat[4] = fontMat[5] = 0;
     obj1 = fontDict->lookup("FontMatrix");
     if (obj1.isArray()) {
-        for (i = 0; i < 6 && i < obj1.arrayGetLength(); ++i) {
+        for (int i = 0; i < 6 && i < obj1.arrayGetLength(); ++i) {
             Object obj2 = obj1.arrayGet(i);
             if (obj2.isNum()) {
                 fontMat[i] = obj2.getNum();
@@ -1055,7 +1048,7 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA
     if (type == fontType3) {
         obj1 = fontDict->lookup("FontBBox");
         if (obj1.isArray()) {
-            for (i = 0; i < 4 && i < obj1.arrayGetLength(); ++i) {
+            for (int i = 0; i < 4 && i < obj1.arrayGetLength(); ++i) {
                 Object obj2 = obj1.arrayGet(i);
                 if (obj2.isNum()) {
                     fontBBox[i] = obj2.getNum();
@@ -1186,7 +1179,7 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA
     }
 
     // copy the base encoding
-    for (i = 0; i < 256; ++i) {
+    for (int i = 0; i < 256; ++i) {
         enc[i] = (char *)baseEnc[i];
         if ((encFree[i] = baseEncFromFontFile) && enc[i]) {
             enc[i] = copyString(baseEnc[i]);
@@ -1198,7 +1191,7 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA
     // the accents in the encoding), so we fill in any gaps from
     // StandardEncoding
     if (type == fontType1C && embFontID != Ref::INVALID() && baseEncFromFontFile) {
-        for (i = 0; i < 256; ++i) {
+        for (int i = 0; i < 256; ++i) {
             if (!enc[i] && standardEncoding[i]) {
                 enc[i] = (char *)standardEncoding[i];
                 encFree[i] = false;
@@ -1213,7 +1206,7 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA
             encodingName = "Custom";
             hasEncoding = true;
             int code = 0;
-            for (i = 0; i < obj2.arrayGetLength(); ++i) {
+            for (int i = 0; i < obj2.arrayGetLength(); ++i) {
                 Object obj3 = obj2.arrayGet(i);
                 if (obj3.isInt()) {
                     code = obj3.getInt();
@@ -1239,7 +1232,7 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA
 
     // pass 1: use the name-to-Unicode mapping table
     missing = hex = false;
-    bool isZapfDingbats = name && name->endsWith("ZapfDingbats");
+    bool isZapfDingbats = name && GooString::endsWith(*name, "ZapfDingbats");
     for (int code = 0; code < 256; ++code) {
         if ((charName = enc[code])) {
             if (isZapfDingbats) {
@@ -1372,6 +1365,7 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA
         // this is technically an error -- the Widths entry is required
         // for all but the Base-14 fonts -- but certain PDF generators
         // apparently don't include widths for Arial and TimesNewRoman
+        int i;
         if (isFixedWidth()) {
             i = 0;
         } else if (isSerif()) {
@@ -1713,7 +1707,7 @@ struct cmpWidthExcepVFunctor
     bool operator()(const GfxFontCIDWidthExcepV &w1, const GfxFontCIDWidthExcepV &w2) { return w1.first < w2.first; }
 };
 
-GfxCIDFont::GfxCIDFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA, GfxFontType typeA, Ref embFontIDA, Dict *fontDict) : GfxFont(tagA, idA, nameA, typeA, embFontIDA)
+GfxCIDFont::GfxCIDFont(XRef *xref, const char *tagA, Ref idA, std::optional<std::string> &&nameA, GfxFontType typeA, Ref embFontIDA, Dict *fontDict) : GfxFont(tagA, idA, std::move(nameA), typeA, embFontIDA)
 {
     Dict *desFontDict;
     Object desFontDictObj;
@@ -2225,7 +2219,7 @@ int *GfxCIDFont::getCodeToGIDMap(FoFiTrueType *ff, int *codeToGIDLen)
         ff->setupGSUB(lp->scriptTag, lp->languageTag);
     } else {
         if (getCollection()->cmp("Adobe-Identity") == 0) {
-            error(errSyntaxError, -1, "non-embedded font using identity encoding: {0:t}", getName());
+            error(errSyntaxError, -1, "non-embedded font using identity encoding: {0:s}", name ? name->c_str() : "(null)");
         } else {
             error(errSyntaxError, -1, "Unknown character collection {0:t}\n", getCollection());
         }
diff --git a/poppler/GfxFont.h b/poppler/GfxFont.h
index 61aa09ae..7c955e3c 100644
--- a/poppler/GfxFont.h
+++ b/poppler/GfxFont.h
@@ -216,7 +216,7 @@ public:
 
     // Get the original font name (ignornig any munging that might have
     // been done to map to a canonical Base-14 font name).
-    const GooString *getName() const { return name; }
+    const std::optional<std::string> &getName() const { return name; }
 
     bool isSubset() const;
 
@@ -301,7 +301,7 @@ public:
     static const char *getAlternateName(const char *name);
 
 protected:
-    GfxFont(const char *tagA, Ref idA, const GooString *nameA, GfxFontType typeA, Ref embFontIDA);
+    GfxFont(const char *tagA, Ref idA, std::optional<std::string> &&nameA, GfxFontType typeA, Ref embFontIDA);
 
     static GfxFontType getFontType(XRef *xref, Dict *fontDict, Ref *embID);
     void readFontDescriptor(XRef *xref, Dict *fontDict);
@@ -310,7 +310,7 @@ protected:
 
     const std::string tag; // PDF font tag
     const Ref id; // reference (used as unique ID)
-    const GooString *name; // font name
+    std::optional<std::string> name; // font name
     GooString *family; // font family
     Stretch stretch; // font stretch
     Weight weight; // font weight
@@ -335,7 +335,7 @@ protected:
 class POPPLER_PRIVATE_EXPORT Gfx8BitFont : public GfxFont
 {
 public:
-    Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA, GfxFontType typeA, Ref embFontIDA, Dict *fontDict);
+    Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, std::optional<std::string> &&nameA, GfxFontType typeA, Ref embFontIDA, Dict *fontDict);
 
     int getNextChar(const char *s, int len, CharCode *code, Unicode const **u, int *uLen, double *dx, double *dy, double *ox, double *oy) const override;
 
@@ -395,7 +395,7 @@ private:
 class POPPLER_PRIVATE_EXPORT GfxCIDFont : public GfxFont
 {
 public:
-    GfxCIDFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA, GfxFontType typeA, Ref embFontIDA, Dict *fontDict);
+    GfxCIDFont(XRef *xref, const char *tagA, Ref idA, std::optional<std::string> &&nameA, GfxFontType typeA, Ref embFontIDA, Dict *fontDict);
 
     bool isCIDFont() const override { return true; }
 
diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc
index 36caf37a..f70870ac 100644
--- a/poppler/GlobalParams.cc
+++ b/poppler/GlobalParams.cc
@@ -250,7 +250,7 @@ public:
     ~SysFontList();
     SysFontList(const SysFontList &) = delete;
     SysFontList &operator=(const SysFontList &) = delete;
-    const SysFontInfo *find(const GooString *name, bool isFixedWidth, bool exact);
+    const SysFontInfo *find(const std::string &name, bool isFixedWidth, bool exact);
 
 #ifdef _WIN32
     void scanWindowsFonts(GooString *winFontDir);
@@ -275,13 +275,13 @@ SysFontList::~SysFontList()
     }
 }
 
-const SysFontInfo *SysFontList::find(const GooString *name, bool fixedWidth, bool exact)
+const SysFontInfo *SysFontList::find(const std::string &name, bool fixedWidth, bool exact)
 {
     GooString *name2;
     bool bold, italic, oblique;
     int n;
 
-    name2 = name->copy();
+    name2 = new GooString(name);
 
     // remove space, comma, dash chars
     {
@@ -909,7 +909,7 @@ GooString *GlobalParams::findSystemFontFile(const GfxFont *font, SysFontType *ty
     const SysFontInfo *fi = nullptr;
     FcPattern *p = nullptr;
     GooString *path = nullptr;
-    const GooString *fontName = font->getName();
+    const std::optional<std::string> &fontName = font->getName();
     GooString substituteName;
     if (!fontName) {
         return nullptr;
@@ -917,7 +917,7 @@ GooString *GlobalParams::findSystemFontFile(const GfxFont *font, SysFontType *ty
 
     globalParamsLocker();
 
-    if ((fi = sysFonts->find(fontName, font->isFixedWidth(), true))) {
+    if ((fi = sysFonts->find(*fontName, font->isFixedWidth(), true))) {
         path = fi->path->copy();
         *type = fi->type;
         *fontNum = fi->fontNum;
@@ -1010,7 +1010,7 @@ GooString *GlobalParams::findSystemFontFile(const GfxFont *font, SysFontType *ty
                     *fontNum = 0;
                     *type = (!strncasecmp(ext, ".ttc", 4)) ? sysFontTTC : sysFontTTF;
                     FcPatternGetInteger(set->fonts[i], FC_INDEX, 0, fontNum);
-                    SysFontInfo *sfi = new SysFontInfo(fontName->copy(), bold, italic, oblique, font->isFixedWidth(), new GooString((char *)s), *type, *fontNum, substituteName.copy());
+                    SysFontInfo *sfi = new SysFontInfo(new GooString(*fontName), bold, italic, oblique, font->isFixedWidth(), new GooString((char *)s), *type, *fontNum, substituteName.copy());
                     sysFonts->addFcFont(sfi);
                     fi = sfi;
                     path = new GooString((char *)s);
@@ -1033,7 +1033,7 @@ GooString *GlobalParams::findSystemFontFile(const GfxFont *font, SysFontType *ty
                     *fontNum = 0;
                     *type = (!strncasecmp(ext, ".pfa", 4)) ? sysFontPFA : sysFontPFB;
                     FcPatternGetInteger(set->fonts[i], FC_INDEX, 0, fontNum);
-                    SysFontInfo *sfi = new SysFontInfo(fontName->copy(), bold, italic, oblique, font->isFixedWidth(), new GooString((char *)s), *type, *fontNum, substituteName.copy());
+                    SysFontInfo *sfi = new SysFontInfo(new GooString(*fontName), bold, italic, oblique, font->isFixedWidth(), new GooString((char *)s), *type, *fontNum, substituteName.copy());
                     sysFonts->addFcFont(sfi);
                     fi = sfi;
                     path = new GooString((char *)s);
@@ -1052,7 +1052,7 @@ GooString *GlobalParams::findSystemFontFile(const GfxFont *font, SysFontType *ty
         }
         FcFontSetDestroy(set);
     }
-    if (path == nullptr && (fi = sysFonts->find(fontName, font->isFixedWidth(), false))) {
+    if (path == nullptr && (fi = sysFonts->find(*fontName, font->isFixedWidth(), false))) {
         path = fi->path->copy();
         *type = fi->type;
         *fontNum = fi->fontNum;
@@ -1149,13 +1149,13 @@ GooString *GlobalParams::findSystemFontFile(const GfxFont *font, SysFontType *ty
     const SysFontInfo *fi;
     GooString *path;
 
-    const GooString *fontName = font->getName();
+    const std::optional<std::string> &fontName = font->getName();
     if (!fontName)
         return nullptr;
 
     path = nullptr;
     globalParamsLocker();
-    if ((fi = sysFonts->find(fontName, font->isFixedWidth(), false))) {
+    if ((fi = sysFonts->find(*fontName, font->isFixedWidth(), false))) {
         path = fi->path->copy();
         *type = fi->type;
         *fontNum = fi->fontNum;
diff --git a/poppler/GlobalParamsWin.cc b/poppler/GlobalParamsWin.cc
index f686cb62..bd453862 100644
--- a/poppler/GlobalParamsWin.cc
+++ b/poppler/GlobalParamsWin.cc
@@ -500,7 +500,7 @@ GooString *GlobalParams::findSystemFontFile(const GfxFont *font, SysFontType *ty
 {
     const SysFontInfo *fi;
     GooString *path = nullptr;
-    const GooString *fontName = font->getName();
+    const std::optional<std::string> &fontName = font->getName();
     if (!fontName)
         return nullptr;
     const std::scoped_lock locker(mutex);
@@ -510,7 +510,7 @@ GooString *GlobalParams::findSystemFontFile(const GfxFont *font, SysFontType *ty
     // In the system using FontConfig, findSystemFontFile() uses
     // base14Name only for the creation of query pattern.
 
-    if ((fi = sysFonts->find(fontName, false, false))) {
+    if ((fi = sysFonts->find(*fontName, false, false))) {
         path = fi->path->copy();
         *type = fi->type;
         *fontNum = fi->fontNum;
@@ -518,7 +518,7 @@ GooString *GlobalParams::findSystemFontFile(const GfxFont *font, SysFontType *ty
             substituteFontName->Set(fi->substituteName->c_str());
     } else {
         GooString *substFontName = new GooString(findSubstituteName(font, fontFiles, substFiles, fontName->c_str()));
-        error(errSyntaxError, -1, "Couldn't find a font for '{0:t}', subst is '{1:t}'", fontName, substFontName);
+        error(errSyntaxError, -1, "Couldn't find a font for '{0:s}', subst is '{1:t}'", fontName->c_str(), substFontName);
         const auto fontFile = fontFiles.find(substFontName->toStr());
         if (fontFile != fontFiles.end()) {
             path = new GooString(fontFile->second.c_str());
diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index 7bfb2a00..111b4728 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -2511,7 +2511,7 @@ void PSOutputDev::setupExternalTrueTypeFont(GfxFont *font, const GooString *file
 void PSOutputDev::updateFontMaxValidGlyph(GfxFont *font, int maxValidGlyph)
 {
     if (maxValidGlyph >= 0 && font->getName()) {
-        auto &fontMaxValidGlyph = perFontMaxValidGlyph[font->getName()->toStr()];
+        auto &fontMaxValidGlyph = perFontMaxValidGlyph[*font->getName()];
         if (fontMaxValidGlyph < maxValidGlyph) {
             fontMaxValidGlyph = maxValidGlyph;
         }
@@ -2789,8 +2789,8 @@ GooString *PSOutputDev::makePSFontName(GfxFont *font, const Ref *id)
         }
         delete psName;
     }
-    if ((s = font->getName())) {
-        psName = filterPSName(s->toStr());
+    if (font->getName()) {
+        psName = filterPSName(*font->getName());
         if (fontNames.emplace(psName->toStr()).second) {
             return psName;
         }
@@ -2801,8 +2801,8 @@ GooString *PSOutputDev::makePSFontName(GfxFont *font, const Ref *id)
         s = filterPSName(s->toStr());
         psName->append('_')->append(s);
         delete s;
-    } else if ((s = font->getName())) {
-        s = filterPSName(s->toStr());
+    } else if (font->getName()) {
+        s = filterPSName(*font->getName());
         psName->append('_')->append(s);
         delete s;
     }
@@ -5045,7 +5045,7 @@ void PSOutputDev::drawString(GfxState *state, const GooString *s)
     if (!(font = state->getFont())) {
         return;
     }
-    maxGlyphInt = (font->getName() ? perFontMaxValidGlyph[font->getName()->toStr()] : 0);
+    maxGlyphInt = (font->getName() ? perFontMaxValidGlyph[*font->getName()] : 0);
     if (maxGlyphInt < 0) {
         maxGlyphInt = 0;
     }
diff --git a/poppler/TextOutputDev.cc b/poppler/TextOutputDev.cc
index 9e838650..439143c7 100644
--- a/poppler/TextOutputDev.cc
+++ b/poppler/TextOutputDev.cc
@@ -365,7 +365,7 @@ TextFontInfo::TextFontInfo(const GfxState *state)
 {
     gfxFont = state->getFont();
 #ifdef TEXTOUT_WORD_LIST
-    fontName = (gfxFont && gfxFont->getName()) ? gfxFont->getName()->copy() : nullptr;
+    fontName = (gfxFont && gfxFont->getName()) ? new GooString(*gfxFont->getName()) : nullptr;
     flags = gfxFont ? gfxFont->getFlags() : 0;
 #endif
 }
diff --git a/utils/HtmlFonts.cc b/utils/HtmlFonts.cc
index 7ee459d0..ca7d4a49 100644
--- a/utils/HtmlFonts.cc
+++ b/utils/HtmlFonts.cc
@@ -142,10 +142,10 @@ HtmlFont::HtmlFont(const GfxFont &font, int _size, GfxRGB rgb, double opacity)
         italic = true;
     }
 
-    if (const GooString *fontname = font.getName()) {
-        FontName = new GooString(fontname);
+    if (const std::optional<std::string> &fontname = font.getName()) {
+        FontName = new GooString(*fontname);
 
-        GooString fontnameLower(fontname);
+        GooString fontnameLower(*fontname);
         fontnameLower.lowerCase();
 
         if (!bold && strstr(fontnameLower.c_str(), "bold")) {


More information about the poppler mailing list