nanovega: made fontconfig less aggressive

This commit is contained in:
Ketmar Dark 2018-03-17 15:22:08 +02:00 committed by Adam D. Ruppe
parent 819c3fdf90
commit a055c35e9a
1 changed files with 22 additions and 16 deletions

View File

@ -10353,22 +10353,28 @@ public int fonsAddFont (FONScontext* stash, const(char)[] name, const(char)[] pa
// if loading failed, try fontconfig (if fontconfig is available) // if loading failed, try fontconfig (if fontconfig is available)
static if (NanoVegaHasFontConfig) { static if (NanoVegaHasFontConfig) {
if (res == FONS_INVALID && fontconfigAvailable) { if (res == FONS_INVALID && fontconfigAvailable) {
import std.internal.cstring : tempCString; // idiotic fontconfig NEVER fails; let's skip it if `path` looks like a path
FcPattern* pat = FcNameParse(path.tempCString); bool ok = true;
if (pat !is null) { if (path.length > 4 && (path[$-4..$] == ".ttf" || path[$-4..$] == ".ttc")) ok = false;
scope(exit) FcPatternDestroy(pat); if (ok) { foreach (immutable char ch; path) if (ch == '/') { ok = false; break; } }
if (FcConfigSubstitute(null, pat, FcMatchPattern)) { if (ok) {
FcDefaultSubstitute(pat); import std.internal.cstring : tempCString;
// find the font FcPattern* pat = FcNameParse(path.tempCString);
FcResult result; if (pat !is null) {
FcPattern* font = FcFontMatch(null, pat, &result); scope(exit) FcPatternDestroy(pat);
if (font !is null) { if (FcConfigSubstitute(null, pat, FcMatchPattern)) {
scope(exit) FcPatternDestroy(font); FcDefaultSubstitute(pat);
char* file = null; // find the font
if (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) { FcResult result;
if (file !is null && file[0]) { FcPattern* font = FcFontMatch(null, pat, &result);
import core.stdc.string : strlen; if (font !is null) {
res = loadFontFile(file[0..strlen(file)]); scope(exit) FcPatternDestroy(font);
char* file = null;
if (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
if (file !is null && file[0]) {
import core.stdc.string : strlen;
res = loadFontFile(file[0..strlen(file)]);
}
} }
} }
} }