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

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sun Nov 15 11:02:39 UTC 2020


 poppler/FontInfo.cc     |   11 +----------
 poppler/GfxFont.cc      |   27 +++++++++++++++++++++++++++
 poppler/GfxFont.h       |    5 +++++
 poppler/GlobalParams.cc |    2 +-
 4 files changed, 34 insertions(+), 11 deletions(-)

New commits:
commit 0986483fbd49b7bdf5f2e45bb03a7ebe6d3b8e65
Author: Albert Astals Cid <aacid at kde.org>
Date:   Mon Nov 9 01:20:18 2020 +0100

    Use the font name without subset tag when querying for a system font
    
    i.e. if the font name is DDPJAD+Times-Roman look for a replacement of Times-Roman
    
    Fixes issue #972

diff --git a/poppler/FontInfo.cc b/poppler/FontInfo.cc
index 48da3dbd..54ee0b73 100644
--- a/poppler/FontInfo.cc
+++ b/poppler/FontInfo.cc
@@ -205,16 +205,7 @@ FontInfo::FontInfo(GfxFont *font, XRef *xref)
 
     // check for a font subset name: capital letters followed by a '+'
     // sign
-    subset = false;
-    if (name) {
-        int i;
-        for (i = 0; i < name->getLength(); ++i) {
-            if (name->getChar(i) < 'A' || name->getChar(i) > 'Z') {
-                break;
-            }
-        }
-        subset = i > 0 && i < name->getLength() && name->getChar(i) == '+';
-    }
+    subset = font->isSubset();
 }
 
 FontInfo::FontInfo(const FontInfo &f)
diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc
index e6b3cfda..2560a2db 100644
--- a/poppler/GfxFont.cc
+++ b/poppler/GfxFont.cc
@@ -262,6 +262,33 @@ void GfxFont::decRefCnt()
         delete this;
 }
 
+bool GfxFont::isSubset() const
+{
+    if (name) {
+        int i;
+        for (i = 0; i < name->getLength(); ++i) {
+            if (name->getChar(i) < 'A' || name->getChar(i) > 'Z') {
+                break;
+            }
+        }
+        return i == 6 && name->getLength() > 7 && name->getChar(6) == '+';
+    }
+    return false;
+}
+
+std::string GfxFont::getNameWithoutSubsetTag() const
+{
+    if (!name) {
+        return {};
+    }
+
+    if (!isSubset()) {
+        return name->toStr();
+    }
+
+    return name->toStr().substr(7);
+}
+
 // This function extracts three pieces of information:
 // 1. the "expected" font type, i.e., the font type implied by
 //    Font.Subtype, DescendantFont.Subtype, and
diff --git a/poppler/GfxFont.h b/poppler/GfxFont.h
index 0b64615b..ddbade7f 100644
--- a/poppler/GfxFont.h
+++ b/poppler/GfxFont.h
@@ -212,6 +212,11 @@ public:
     // been done to map to a canonical Base-14 font name).
     const GooString *getName() const { return name; }
 
+    bool isSubset() const;
+
+    // Returns the original font name without the subset tag (if it has one)
+    std::string getNameWithoutSubsetTag() const;
+
     // Get font type.
     GfxFontType getType() const { return type; }
     virtual bool isCIDFont() const { return false; }
diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc
index 93024cc7..5d1ef225 100644
--- a/poppler/GlobalParams.cc
+++ b/poppler/GlobalParams.cc
@@ -701,7 +701,7 @@ static FcPattern *buildFcPattern(const GfxFont *font, const GooString *base14Nam
     FcPattern *p;
 
     // this is all heuristics will be overwritten if font had proper info
-    char *fontName = strdup(((base14Name == nullptr) ? font->getName() : base14Name)->c_str());
+    char *fontName = strdup(((base14Name == nullptr) ? font->getNameWithoutSubsetTag() : base14Name->toStr()).c_str());
 
     const char *modifiers = strchr(fontName, ',');
     if (modifiers == nullptr)


More information about the poppler mailing list