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,6 +10353,11 @@ public int fonsAddFont (FONScontext* stash, const(char)[] name, const(char)[] pa
// if loading failed, try fontconfig (if fontconfig is available)
static if (NanoVegaHasFontConfig) {
if (res == FONS_INVALID && fontconfigAvailable) {
// idiotic fontconfig NEVER fails; let's skip it if `path` looks like a path
bool ok = true;
if (path.length > 4 && (path[$-4..$] == ".ttf" || path[$-4..$] == ".ttc")) ok = false;
if (ok) { foreach (immutable char ch; path) if (ch == '/') { ok = false; break; } }
if (ok) {
import std.internal.cstring : tempCString;
FcPattern* pat = FcNameParse(path.tempCString);
if (pat !is null) {
@ -10376,6 +10381,7 @@ public int fonsAddFont (FONScontext* stash, const(char)[] name, const(char)[] pa
}
}
}
}
return res;
}