[poppler] poppler/FontInfo.cc poppler/GfxFont.cc poppler/GfxFont.h poppler/GlobalParams.cc poppler/GlobalParams.h

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu May 4 17:27:25 UTC 2023


 poppler/FontInfo.cc     |    8 +++-----
 poppler/GfxFont.cc      |    6 +++---
 poppler/GfxFont.h       |    3 ++-
 poppler/GlobalParams.cc |    8 ++++----
 poppler/GlobalParams.h  |    2 +-
 5 files changed, 13 insertions(+), 14 deletions(-)

New commits:
commit 1e4488b2b44a56b35dee8e0bf9e33453523eb2ed
Author: Albert Astals Cid <aacid at kde.org>
Date:   Thu May 4 00:21:46 2023 +0200

    FontInfo: Make it return proper information about font substitution
    
    GfxFont::locateFont is what the output devices use, which is more
    complex than just findSystemFontFile so use that

diff --git a/poppler/FontInfo.cc b/poppler/FontInfo.cc
index 309ec6d3..0be38923 100644
--- a/poppler/FontInfo.cc
+++ b/poppler/FontInfo.cc
@@ -181,12 +181,10 @@ FontInfo::FontInfo(GfxFont *font, XRef *xref)
     }
 
     if (!emb) {
-        SysFontType dummy;
-        int dummy2;
         GooString substituteNameAux;
-        std::unique_ptr<GooString> tmpFile(globalParams->findSystemFontFile(font, &dummy, &dummy2, &substituteNameAux));
-        if (tmpFile) {
-            file = tmpFile->toStr();
+        const std::optional<GfxFontLoc> fontLoc = font->locateFont(xref, nullptr, &substituteNameAux);
+        if (fontLoc && fontLoc->locType == gfxFontLocExternal) {
+            file = fontLoc->path;
         }
         if (substituteNameAux.getLength() > 0) {
             substituteName = substituteNameAux.toStr();
diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc
index 41170fd7..954fb8b3 100644
--- a/poppler/GfxFont.cc
+++ b/poppler/GfxFont.cc
@@ -608,7 +608,7 @@ CharCodeToUnicode *GfxFont::readToUnicodeCMap(Dict *fontDict, int nBits, CharCod
     return ctu;
 }
 
-std::optional<GfxFontLoc> GfxFont::locateFont(XRef *xref, PSOutputDev *ps)
+std::optional<GfxFontLoc> GfxFont::locateFont(XRef *xref, PSOutputDev *ps, GooString *substituteFontName)
 {
     SysFontType sysFontType;
     GooString *path, *base14Name;
@@ -690,7 +690,7 @@ std::optional<GfxFontLoc> GfxFont::locateFont(XRef *xref, PSOutputDev *ps)
     //----- external font file for Base-14 font
     if (!ps && !isCIDFont() && ((Gfx8BitFont *)this)->base14) {
         base14Name = new GooString(((Gfx8BitFont *)this)->base14->base14Name);
-        if ((path = globalParams->findBase14FontFile(base14Name, this))) {
+        if ((path = globalParams->findBase14FontFile(base14Name, this, substituteFontName))) {
             if (std::optional<GfxFontLoc> fontLoc = getExternalFont(path, false)) {
                 delete base14Name;
                 return fontLoc;
@@ -700,7 +700,7 @@ std::optional<GfxFontLoc> GfxFont::locateFont(XRef *xref, PSOutputDev *ps)
     }
 
     //----- system font
-    if ((path = globalParams->findSystemFontFile(this, &sysFontType, &fontNum))) {
+    if ((path = globalParams->findSystemFontFile(this, &sysFontType, &fontNum, substituteFontName))) {
         if (isCIDFont()) {
             if (sysFontType == sysFontTTF || sysFontType == sysFontTTC) {
                 GfxFontLoc fontLoc;
diff --git a/poppler/GfxFont.h b/poppler/GfxFont.h
index 7c955e3c..fbc08de1 100644
--- a/poppler/GfxFont.h
+++ b/poppler/GfxFont.h
@@ -276,7 +276,8 @@ public:
 
     // 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.
-    std::optional<GfxFontLoc> locateFont(XRef *xref, PSOutputDev *ps);
+    // substituteFontName is passed down to the GlobalParams::findSystemFontFile/findBase14FontFile call
+    std::optional<GfxFontLoc> locateFont(XRef *xref, PSOutputDev *ps, GooString *substituteFontName = nullptr);
 
     // Read an external or embedded font file into a buffer.
     std::optional<std::vector<unsigned char>> readEmbFontFile(XRef *xref);
diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc
index 2b899c92..6fc3fef4 100644
--- a/poppler/GlobalParams.cc
+++ b/poppler/GlobalParams.cc
@@ -935,12 +935,12 @@ static bool supportedFontForEmbedding(Unicode uChar, const char *filepath, int f
 // not needed for fontconfig
 void GlobalParams::setupBaseFonts(const char *) { }
 
-GooString *GlobalParams::findBase14FontFile(const GooString *base14Name, const GfxFont *font)
+GooString *GlobalParams::findBase14FontFile(const GooString *base14Name, const GfxFont *font, GooString *substituteFontName)
 {
     SysFontType type;
     int fontNum;
 
-    return findSystemFontFile(font, &type, &fontNum, nullptr, base14Name);
+    return findSystemFontFile(font, &type, &fontNum, substituteFontName, base14Name);
 }
 
 GooString *GlobalParams::findSystemFontFile(const GfxFont *font, SysFontType *type, int *fontNum, GooString *substituteFontName, const GooString *base14Name)
@@ -1178,7 +1178,7 @@ UCharFontSearchResult GlobalParams::findSystemFontFileForUChar(Unicode uChar, co
 #elif defined(WITH_FONTCONFIGURATION_WIN32)
 #    include "GlobalParamsWin.cc"
 
-GooString *GlobalParams::findBase14FontFile(const GooString *base14Name, const GfxFont *font)
+GooString *GlobalParams::findBase14FontFile(const GooString *base14Name, const GfxFont *font, GooString * /*substituteFontName*/)
 {
     return findFontFile(base14Name->toStr());
 }
@@ -1197,7 +1197,7 @@ UCharFontSearchResult GlobalParams::findSystemFontFileForUChar(Unicode uChar, co
     return {};
 }
 
-GooString *GlobalParams::findBase14FontFile(const GooString *base14Name, const GfxFont *font)
+GooString *GlobalParams::findBase14FontFile(const GooString *base14Name, const GfxFont *font, GooString * /*substituteFontName*/)
 {
     return findFontFile(base14Name->toStr());
 }
diff --git a/poppler/GlobalParams.h b/poppler/GlobalParams.h
index 30b86ee1..7cdd3718 100644
--- a/poppler/GlobalParams.h
+++ b/poppler/GlobalParams.h
@@ -135,7 +135,7 @@ public:
     FILE *findCMapFile(const GooString *collection, const GooString *cMapName);
     FILE *findToUnicodeFile(const GooString *name);
     GooString *findFontFile(const std::string &fontName);
-    GooString *findBase14FontFile(const GooString *base14Name, const GfxFont *font);
+    GooString *findBase14FontFile(const GooString *base14Name, const GfxFont *font, GooString *substituteFontName = nullptr);
     GooString *findSystemFontFile(const GfxFont *font, SysFontType *type, int *fontNum, GooString *substituteFontName = nullptr, const GooString *base14Name = nullptr);
     FamilyStyleFontSearchResult findSystemFontFileForFamilyAndStyle(const std::string &fontFamily, const std::string &fontStyle, const std::vector<std::string> &filesToIgnore = {});
     UCharFontSearchResult findSystemFontFileForUChar(Unicode uChar, const GfxFont &fontToEmulate);


More information about the poppler mailing list