From 26199bd53fbe7a0d5b00f8586e66d6702e324e5e Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Fri, 5 May 2023 00:29:40 +0200 Subject: Look for fonts in both windows font dir and poppler fonts dir --- poppler/GlobalParamsWin.cc | 201 +++++++++++++++++++++++---------------------- 1 file changed, 104 insertions(+), 97 deletions(-) diff --git a/poppler/GlobalParamsWin.cc b/poppler/GlobalParamsWin.cc index 2e676bc2..268dd340 100644 --- a/poppler/GlobalParamsWin.cc +++ b/poppler/GlobalParamsWin.cc @@ -61,99 +61,98 @@ description for all fonts available in Windows. That's how MuPDF works. static const struct { const char *name; - const char *t1FileName; - const char *ttFileName; + const std::vector fileNames; bool warnIfMissing; -} displayFontTab[] = { { "Courier", "n022003l.pfb", "cour.ttf", true }, - { "Courier-Bold", "n022004l.pfb", "courbd.ttf", true }, - { "Courier-BoldOblique", "n022024l.pfb", "courbi.ttf", true }, - { "Courier-Oblique", "n022023l.pfb", "couri.ttf", true }, - { "Helvetica", "n019003l.pfb", "arial.ttf", true }, - { "Helvetica-Bold", "n019004l.pfb", "arialbd.ttf", true }, - { "Helvetica-BoldOblique", "n019024l.pfb", "arialbi.ttf", true }, - { "Helvetica-Oblique", "n019023l.pfb", "ariali.ttf", true }, +} displayFontTab[] = { { "Courier", { "n022003l.pfb", "cour.ttf" }, true }, + { "Courier-Bold", { "n022004l.pfb", "courbd.ttf" }, true }, + { "Courier-BoldOblique", { "n022024l.pfb", "courbi.ttf" }, true }, + { "Courier-Oblique", { "n022023l.pfb", "couri.ttf" }, true }, + { "Helvetica", { "n019003l.pfb", "arial.ttf" }, true }, + { "Helvetica-Bold", { "n019004l.pfb", "arialbd.ttf" }, true }, + { "Helvetica-BoldOblique", { "n019024l.pfb", "arialbi.ttf" }, true }, + { "Helvetica-Oblique", { "n019023l.pfb", "ariali.ttf" }, true }, // TODO: not sure if "symbol.ttf" is right - { "Symbol", "s050000l.pfb", "symbol.ttf", true }, - { "Times-Bold", "n021004l.pfb", "timesbd.ttf", true }, - { "Times-BoldItalic", "n021024l.pfb", "timesbi.ttf", true }, - { "Times-Italic", "n021023l.pfb", "timesi.ttf", true }, - { "Times-Roman", "n021003l.pfb", "times.ttf", true }, + { "Symbol", { "s050000l.pfb", "symbol.ttf" }, true }, + { "Times-Bold", { "n021004l.pfb", "timesbd.ttf" }, true }, + { "Times-BoldItalic", { "n021024l.pfb", "timesbi.ttf" }, true }, + { "Times-Italic", { "n021023l.pfb", "timesi.ttf" }, true }, + { "Times-Roman", { "n021003l.pfb", "times.ttf" }, true }, // TODO: not sure if "wingding.ttf" is right - { "ZapfDingbats", "d050000l.pfb", "wingding.ttf", true }, + { "ZapfDingbats", { "d050000l.pfb", "wingding.ttf" }, true }, // those seem to be frequently accessed by PDF files and I kind of guess // which font file do the refer to - { "Palatino", nullptr, "pala.ttf", true }, - { "Palatino-Roman", nullptr, "pala.ttf", true }, - { "Palatino-Bold", nullptr, "palab.ttf", true }, - { "Palatino-Italic", nullptr, "palai.ttf", true }, - { "Palatino,Italic", nullptr, "palai.ttf", true }, - { "Palatino-BoldItalic", nullptr, "palabi.ttf", true }, - - { "ArialBlack", nullptr, "arialbd.ttf", true }, - - { "ArialNarrow", nullptr, "arialn.ttf", true }, - { "ArialNarrow,Bold", nullptr, "arialnb.ttf", true }, - { "ArialNarrow,Italic", nullptr, "arialni.ttf", true }, - { "ArialNarrow,BoldItalic", nullptr, "arialnbi.ttf", true }, - { "ArialNarrow-Bold", nullptr, "arialnb.ttf", true }, - { "ArialNarrow-Italic", nullptr, "arialni.ttf", true }, - { "ArialNarrow-BoldItalic", nullptr, "arialnbi.ttf", true }, - - { "HelveticaNarrow", nullptr, "arialn.ttf", true }, - { "HelveticaNarrow,Bold", nullptr, "arialnb.ttf", true }, - { "HelveticaNarrow,Italic", nullptr, "arialni.ttf", true }, - { "HelveticaNarrow,BoldItalic", nullptr, "arialnbi.ttf", true }, - { "HelveticaNarrow-Bold", nullptr, "arialnb.ttf", true }, - { "HelveticaNarrow-Italic", nullptr, "arialni.ttf", true }, - { "HelveticaNarrow-BoldItalic", nullptr, "arialnbi.ttf", true }, - - { "BookAntiqua", nullptr, "bkant.ttf", true }, - { "BookAntiqua,Bold", nullptr, "bkant.ttf", true }, - { "BookAntiqua,Italic", nullptr, "bkant.ttf", true }, - { "BookAntiqua,BoldItalic", nullptr, "bkant.ttf", true }, - { "BookAntiqua-Bold", nullptr, "bkant.ttf", true }, - { "BookAntiqua-Italic", nullptr, "bkant.ttf", true }, - { "BookAntiqua-BoldItalic", nullptr, "bkant.ttf", true }, - - { "Verdana", nullptr, "verdana.ttf", true }, - { "Verdana,Bold", nullptr, "verdanab.ttf", true }, - { "Verdana,Italic", nullptr, "verdanai.ttf", true }, - { "Verdana,BoldItalic", nullptr, "verdanaz.ttf", true }, - { "Verdana-Bold", nullptr, "verdanab.ttf", true }, - { "Verdana-Italic", nullptr, "verdanai.ttf", true }, - { "Verdana-BoldItalic", nullptr, "verdanaz.ttf", true }, - - { "Tahoma", nullptr, "tahoma.ttf", true }, - { "Tahoma,Bold", nullptr, "tahomabd.ttf", true }, - { "Tahoma,Italic", nullptr, "tahoma.ttf", true }, - { "Tahoma,BoldItalic", nullptr, "tahomabd.ttf", true }, - { "Tahoma-Bold", nullptr, "tahomabd.ttf", true }, - { "Tahoma-Italic", nullptr, "tahoma.ttf", true }, - { "Tahoma-BoldItalic", nullptr, "tahomabd.ttf", true }, - - { "CCRIKH+Verdana", nullptr, "verdana.ttf", true }, - { "CCRIKH+Verdana,Bold", nullptr, "verdanab.ttf", true }, - { "CCRIKH+Verdana,Italic", nullptr, "verdanai.ttf", true }, - { "CCRIKH+Verdana,BoldItalic", nullptr, "verdanaz.ttf", true }, - { "CCRIKH+Verdana-Bold", nullptr, "verdanab.ttf", true }, - { "CCRIKH+Verdana-Italic", nullptr, "verdanai.ttf", true }, - { "CCRIKH+Verdana-BoldItalic", nullptr, "verdanaz.ttf", true }, - - { "Georgia", nullptr, "georgia.ttf", true }, - { "Georgia,Bold", nullptr, "georgiab.ttf", true }, - { "Georgia,Italic", nullptr, "georgiai.ttf", true }, - { "Georgia,BoldItalic", nullptr, "georgiaz.ttf", true }, - { "Georgia-Bold", nullptr, "georgiab.ttf", true }, - { "Georgia-Italic", nullptr, "georgiai.ttf", true }, - { "Georgia-BoldItalic", nullptr, "georgiaz.ttf", true }, + { "Palatino", { "pala.ttf" }, true }, + { "Palatino-Roman", { "pala.ttf" }, true }, + { "Palatino-Bold", { "palab.ttf" }, true }, + { "Palatino-Italic", { "palai.ttf" }, true }, + { "Palatino,Italic", { "palai.ttf" }, true }, + { "Palatino-BoldItalic", { "palabi.ttf" }, true }, + + { "ArialBlack", { "arialbd.ttf" }, true }, + + { "ArialNarrow", { "arialn.ttf" }, true }, + { "ArialNarrow,Bold", { "arialnb.ttf" }, true }, + { "ArialNarrow,Italic", { "arialni.ttf" }, true }, + { "ArialNarrow,BoldItalic", { "arialnbi.ttf" }, true }, + { "ArialNarrow-Bold", { "arialnb.ttf" }, true }, + { "ArialNarrow-Italic", { "arialni.ttf" }, true }, + { "ArialNarrow-BoldItalic", { "arialnbi.ttf" }, true }, + + { "HelveticaNarrow", { "arialn.ttf" }, true }, + { "HelveticaNarrow,Bold", { "arialnb.ttf" }, true }, + { "HelveticaNarrow,Italic", { "arialni.ttf" }, true }, + { "HelveticaNarrow,BoldItalic", { "arialnbi.ttf" }, true }, + { "HelveticaNarrow-Bold", { "arialnb.ttf" }, true }, + { "HelveticaNarrow-Italic", { "arialni.ttf" }, true }, + { "HelveticaNarrow-BoldItalic", { "arialnbi.ttf" }, true }, + + { "BookAntiqua", { "bkant.ttf" }, true }, + { "BookAntiqua,Bold", { "bkant.ttf" }, true }, + { "BookAntiqua,Italic", { "bkant.ttf" }, true }, + { "BookAntiqua,BoldItalic", { "bkant.ttf" }, true }, + { "BookAntiqua-Bold", { "bkant.ttf" }, true }, + { "BookAntiqua-Italic", { "bkant.ttf" }, true }, + { "BookAntiqua-BoldItalic", { "bkant.ttf" }, true }, + + { "Verdana", { "verdana.ttf" }, true }, + { "Verdana,Bold", { "verdanab.ttf" }, true }, + { "Verdana,Italic", { "verdanai.ttf" }, true }, + { "Verdana,BoldItalic", { "verdanaz.ttf" }, true }, + { "Verdana-Bold", { "verdanab.ttf" }, true }, + { "Verdana-Italic", { "verdanai.ttf" }, true }, + { "Verdana-BoldItalic", { "verdanaz.ttf" }, true }, + + { "Tahoma", { "tahoma.ttf" }, true }, + { "Tahoma,Bold", { "tahomabd.ttf" }, true }, + { "Tahoma,Italic", { "tahoma.ttf" }, true }, + { "Tahoma,BoldItalic", { "tahomabd.ttf" }, true }, + { "Tahoma-Bold", { "tahomabd.ttf" }, true }, + { "Tahoma-Italic", { "tahoma.ttf" }, true }, + { "Tahoma-BoldItalic", { "tahomabd.ttf" }, true }, + + { "CCRIKH+Verdana", { "verdana.ttf" }, true }, + { "CCRIKH+Verdana,Bold", { "verdanab.ttf" }, true }, + { "CCRIKH+Verdana,Italic", { "verdanai.ttf" }, true }, + { "CCRIKH+Verdana,BoldItalic", { "verdanaz.ttf" }, true }, + { "CCRIKH+Verdana-Bold", { "verdanab.ttf" }, true }, + { "CCRIKH+Verdana-Italic", { "verdanai.ttf" }, true }, + { "CCRIKH+Verdana-BoldItalic", { "verdanaz.ttf" }, true }, + + { "Georgia", { "georgia.ttf" }, true }, + { "Georgia,Bold", { "georgiab.ttf" }, true }, + { "Georgia,Italic", { "georgiai.ttf" }, true }, + { "Georgia,BoldItalic", { "georgiaz.ttf" }, true }, + { "Georgia-Bold", { "georgiab.ttf" }, true }, + { "Georgia-Italic", { "georgiai.ttf" }, true }, + { "Georgia-BoldItalic", { "georgiaz.ttf" }, true }, // fallback for Adobe CID fonts: - { "MingLiU", nullptr, "mingliu.ttf", false }, - { "SimSun", nullptr, "simsun.ttf", false }, - { "MS-Mincho", nullptr, "msmincho.ttf", false }, - { "Batang", nullptr, "batang.ttf", false }, - { "ArialUnicode", nullptr, "arialuni.ttf", true }, + { "MingLiU", { "mingliu.ttf" }, false }, + { "SimSun", { "simsun.ttf" }, false }, + { "MS-Mincho", { "msmincho.ttf" }, false }, + { "Batang", { "batang.ttf" }, false }, + { "ArialUnicode", { "arialuni.ttf" }, true }, {} }; static std::string GetWindowsFontDir() @@ -342,29 +341,37 @@ void GlobalParams::setupBaseFonts(const char *dir) const std::string winFontDir = GetWindowsFontDir(); + std::vector fontDirs; + if (dir) { + fontDirs.emplace_back(dir); + } + if (!winFontDir.empty()) { + fontDirs.emplace_back(winFontDir); + } + for (int i = 0; displayFontTab[i].name; ++i) { if (fontFiles.count(displayFontTab[i].name) > 0) continue; const GooString fontName = GooString(displayFontTab[i].name); - if (dir && displayFontTab[i].t1FileName) { - const std::unique_ptr fontPath(appendToPath(new GooString(dir), displayFontTab[i].t1FileName)); - if (FileExists(fontPath->c_str()) || FileExists(replaceSuffix(fontPath.get(), ".pfb", ".pfa")->c_str())) { - addFontFile(fontName.toStr(), fontPath->toStr()); - continue; + bool fontFound = false; + for (const std::string &fontDir : fontDirs) { + for (const std::string &fileName : displayFontTab[i].fileNames) { + const std::unique_ptr fontPath(appendToPath(new GooString(fontDir), fileName.c_str())); + if (FileExists(fontPath->c_str()) || FileExists(replaceSuffix(fontPath.get(), ".pfb", ".pfa")->c_str()) || FileExists(replaceSuffix(fontPath.get(), ".ttc", ".ttf")->c_str())) { + addFontFile(fontName.toStr(), fontPath->toStr()); + fontFound = true; + break; + } } - } - if (!winFontDir.empty() && displayFontTab[i].ttFileName) { - const std::unique_ptr fontPath(appendToPath(new GooString(winFontDir), displayFontTab[i].ttFileName)); - if (FileExists(fontPath->c_str()) || FileExists(replaceSuffix(fontPath.get(), ".ttc", ".ttf")->c_str())) { - addFontFile(fontName.toStr(), fontPath->toStr()); - continue; + if (fontFound) { + break; } } - if (displayFontTab[i].warnIfMissing) { + if (!fontFound && displayFontTab[i].warnIfMissing) { error(errSyntaxError, -1, "No display font for '{0:s}'", displayFontTab[i].name); } } -- cgit v1.2.3