[poppler] goo/GooString.h poppler/GlobalParams.cc poppler/GlobalParamsWin.cc
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Apr 22 11:57:04 UTC 2022
goo/GooString.h | 5 +++++
poppler/GlobalParams.cc | 2 +-
poppler/GlobalParamsWin.cc | 39 +++++++++++++++++----------------------
3 files changed, 23 insertions(+), 23 deletions(-)
New commits:
commit 8ed7d5633db76df10ef340edc31f1cc868e3ab02
Author: Albert Astals Cid <aacid at kde.org>
Date: Fri Apr 22 13:47:18 2022 +0200
Rework GetWindowsFontDir
diff --git a/goo/GooString.h b/goo/GooString.h
index 86af849e..4535f7a6 100644
--- a/goo/GooString.h
+++ b/goo/GooString.h
@@ -204,6 +204,11 @@ public:
static_cast<std::string &>(*this).insert(i, *str);
return this;
}
+ GooString *insert(int i, const std::string &str)
+ {
+ static_cast<std::string &>(*this).insert(i, str);
+ return this;
+ }
GooString *insert(int i, const char *str)
{
static_cast<std::string &>(*this).insert(i, str);
diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc
index 28a1e146..a7e7fed4 100644
--- a/poppler/GlobalParams.cc
+++ b/poppler/GlobalParams.cc
@@ -257,7 +257,7 @@ public:
const std::vector<SysFontInfo *> &getFonts() const { return fonts; }
#ifdef _WIN32
- void scanWindowsFonts(GooString *winFontDir);
+ void scanWindowsFonts(const std::string &winFontDir);
#endif
#ifdef WITH_FONTCONFIGURATION_FONTCONFIG
void addFcFont(SysFontInfo *si) { fonts.push_back(si); }
diff --git a/poppler/GlobalParamsWin.cc b/poppler/GlobalParamsWin.cc
index 63ee229b..a22bbf79 100644
--- a/poppler/GlobalParamsWin.cc
+++ b/poppler/GlobalParamsWin.cc
@@ -158,51 +158,48 @@ static const struct
{ "ArialUnicode", nullptr, "arialuni.ttf", true },
{} };
-#define FONTS_SUBDIR "\\fonts"
-
-static void GetWindowsFontDir(char *winFontDir, int cbWinFontDirLen)
+static std::string GetWindowsFontDir()
{
- BOOL(__stdcall * SHGetSpecialFolderPathFunc)(HWND hwndOwner, LPSTR lpszPath, int nFolder, BOOL fCreate);
- HRESULT(__stdcall * SHGetFolderPathFunc)(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPSTR pszPath);
+ char winFontDir[MAX_PATH];
+ winFontDir[0] = '\0';
// SHGetSpecialFolderPath isn't available in older versions of shell32.dll (Win95 and
// WinNT4), so do a dynamic load of ANSI versions.
- winFontDir[0] = '\0';
-
HMODULE hLib = LoadLibraryA("shell32.dll");
if (hLib) {
- SHGetFolderPathFunc = (HRESULT(__stdcall *)(HWND, int, HANDLE, DWORD, LPSTR))GetProcAddress(hLib, "SHGetFolderPathA");
+ auto SHGetFolderPathFunc = reinterpret_cast<HRESULT(__stdcall *)(HWND, int, HANDLE, DWORD, LPSTR)>(GetProcAddress(hLib, "SHGetFolderPathA"));
if (SHGetFolderPathFunc)
(*SHGetFolderPathFunc)(nullptr, CSIDL_FONTS, nullptr, SHGFP_TYPE_CURRENT, winFontDir);
if (!winFontDir[0]) {
// Try an older function
- SHGetSpecialFolderPathFunc = (BOOL(__stdcall *)(HWND, LPSTR, int, BOOL))GetProcAddress(hLib, "SHGetSpecialFolderPathA");
+ auto SHGetSpecialFolderPathFunc = reinterpret_cast<BOOL(__stdcall *)(HWND, LPSTR, int, BOOL)>(GetProcAddress(hLib, "SHGetSpecialFolderPathA"));
if (SHGetSpecialFolderPathFunc)
(*SHGetSpecialFolderPathFunc)(nullptr, winFontDir, CSIDL_FONTS, FALSE);
}
FreeLibrary(hLib);
}
if (winFontDir[0])
- return;
+ return winFontDir;
// Try older DLL
hLib = LoadLibraryA("SHFolder.dll");
if (hLib) {
- SHGetFolderPathFunc = (HRESULT(__stdcall *)(HWND, int, HANDLE, DWORD, LPSTR))GetProcAddress(hLib, "SHGetFolderPathA");
+ auto SHGetFolderPathFunc = reinterpret_cast<HRESULT(__stdcall *)(HWND, int, HANDLE, DWORD, LPSTR)>(GetProcAddress(hLib, "SHGetFolderPathA"));
if (SHGetFolderPathFunc)
(*SHGetFolderPathFunc)(nullptr, CSIDL_FONTS, nullptr, SHGFP_TYPE_CURRENT, winFontDir);
FreeLibrary(hLib);
}
if (winFontDir[0])
- return;
+ return winFontDir;
// Everything else failed so the standard fonts directory.
- GetWindowsDirectoryA(winFontDir, cbWinFontDirLen);
+ GetWindowsDirectoryA(winFontDir, MAX_PATH);
if (winFontDir[0]) {
- strncat(winFontDir, FONTS_SUBDIR, cbWinFontDirLen);
- winFontDir[cbWinFontDirLen - 1] = 0;
+ return std::string(winFontDir) + "\\fonts";
}
+
+ return {};
}
static bool FileExists(const char *path)
@@ -215,7 +212,7 @@ static bool FileExists(const char *path)
return false;
}
-void SysFontList::scanWindowsFonts(GooString *winFontDir)
+void SysFontList::scanWindowsFonts(const std::string &winFontDir)
{
OSVERSIONINFO version;
const char *path;
@@ -374,8 +371,7 @@ void GlobalParams::setupBaseFonts(const char *dir)
return;
baseFontsInitialized = true;
- char winFontDir[MAX_PATH];
- GetWindowsFontDir(winFontDir, sizeof(winFontDir));
+ const std::string winFontDir = GetWindowsFontDir();
for (int i = 0; displayFontTab[i].name; ++i) {
if (fontFiles.count(displayFontTab[i].name) > 0)
@@ -392,7 +388,7 @@ void GlobalParams::setupBaseFonts(const char *dir)
delete fontPath;
}
- if (winFontDir[0] && displayFontTab[i].ttFileName) {
+ if (!winFontDir.empty() && displayFontTab[i].ttFileName) {
GooString *fontPath = appendToPath(new GooString(winFontDir), displayFontTab[i].ttFileName);
if (FileExists(fontPath->c_str()) || FileExists(replaceSuffix(fontPath, ".ttc", ".ttf")->c_str())) {
addFontFile(fontName, fontPath);
@@ -406,9 +402,8 @@ void GlobalParams::setupBaseFonts(const char *dir)
delete fontName;
}
}
- if (winFontDir[0]) {
- GooString gooWinFontsDir(winFontDir);
- sysFonts->scanWindowsFonts(&gooWinFontsDir);
+ if (!winFontDir.empty()) {
+ sysFonts->scanWindowsFonts(winFontDir);
}
fileName = new GooString(dataRoot);
More information about the poppler
mailing list