[poppler] poppler/GlobalParams.cc poppler/GlobalParamsWin.cc

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Dec 1 18:31:24 UTC 2021


 poppler/GlobalParams.cc    |   50 ++++++++++++++++++++++++++++++++++-----------
 poppler/GlobalParamsWin.cc |    4 +--
 2 files changed, 40 insertions(+), 14 deletions(-)

New commits:
commit e9f634e789e52f4027f54165af0dea856e0dadac
Author: sunderme <sunderme at gmx.de>
Date:   Wed Dec 1 18:31:22 2021 +0000

    allow local (relative to dll) fonts dir on windows

diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc
index 63b679db..b6e5bd20 100644
--- a/poppler/GlobalParams.cc
+++ b/poppler/GlobalParams.cc
@@ -120,18 +120,14 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
 }
 }
 
-static const char *get_poppler_datadir(void)
+static void get_poppler_localdir(char *retval, const char *suffix)
 {
-    static char retval[MAX_PATH];
-    static int beenhere = 0;
-
     unsigned char *p;
 
-    if (beenhere)
-        return retval;
-
-    if (!GetModuleFileNameA(hmodule, (CHAR *)retval, sizeof(retval) - 20))
-        return POPPLER_DATADIR;
+    if (!GetModuleFileNameA(hmodule, (CHAR *)retval, sizeof(retval) - 20)) {
+        strcpy(retval, POPPLER_DATADIR);
+        return;
+    }
 
     p = _mbsrchr((unsigned char *)retval, '\\');
     *p = '\0';
@@ -140,9 +136,20 @@ static const char *get_poppler_datadir(void)
         if (stricmp((const char *)(p + 1), "bin") == 0)
             *p = '\0';
     }
-    strcat(retval, "\\share\\poppler");
+    strcat(retval, suffix);
+}
 
-    beenhere = 1;
+static const char *get_poppler_datadir(void)
+{
+    static char retval[MAX_PATH];
+    static bool beenhere = false;
+
+    if (beenhere)
+        return retval;
+
+    get_poppler_localdir(retval, "\\share\\poppler");
+
+    beenhere = true;
 
     return retval;
 }
@@ -150,6 +157,25 @@ static const char *get_poppler_datadir(void)
 #    undef POPPLER_DATADIR
 #    define POPPLER_DATADIR get_poppler_datadir()
 
+static const char *get_poppler_fontsdir(void)
+{
+    static char retval[MAX_PATH];
+    static bool beenhere = false;
+
+    if (beenhere)
+        return retval;
+
+    get_poppler_localdir(retval, "\\share\\fonts");
+
+    beenhere = true;
+
+    return retval;
+}
+#    undef POPPLER_FONTSDIR
+#    define POPPLER_FONTSDIR get_poppler_fontsdir()
+
+#else
+#    define POPPLER_FONTSDIR nullptr
 #endif
 
 //------------------------------------------------------------------------
@@ -836,7 +862,7 @@ GooString *GlobalParams::findFontFile(const GooString *fontName)
 {
     GooString *path = nullptr;
 
-    setupBaseFonts(nullptr);
+    setupBaseFonts(POPPLER_FONTSDIR);
     globalParamsLocker();
     const auto fontFile = fontFiles.find(fontName->toStr());
     if (fontFile != fontFiles.end()) {
diff --git a/poppler/GlobalParamsWin.cc b/poppler/GlobalParamsWin.cc
index 13e98b25..8bfc98bb 100644
--- a/poppler/GlobalParamsWin.cc
+++ b/poppler/GlobalParamsWin.cc
@@ -382,7 +382,7 @@ void GlobalParams::setupBaseFonts(const char *dir)
 
         GooString *fontName = new GooString(displayFontTab[i].name);
 
-        if (dir) {
+        if (dir && displayFontTab[i].t1FileName) {
             GooString *fontPath = appendToPath(new GooString(dir), displayFontTab[i].t1FileName);
             if (FileExists(fontPath->c_str()) || FileExists(replaceSuffix(fontPath, ".pfb", ".pfa")->c_str())) {
                 addFontFile(fontName, fontPath);
@@ -504,7 +504,7 @@ GooString *GlobalParams::findSystemFontFile(const GfxFont *font, SysFontType *ty
     if (!fontName)
         return nullptr;
     std::unique_lock<std::recursive_mutex> locker(mutex);
-    setupBaseFonts(nullptr);
+    setupBaseFonts(POPPLER_FONTSDIR);
 
     // TODO: base14Name should be changed?
     // In the system using FontConfig, findSystemFontFile() uses


More information about the poppler mailing list