[client] font: skip stb-incompatible UI font faces

This commit is contained in:
Geoffrey McRae
2026-07-31 13:25:00 +10:00
parent b421eca5d9
commit 66547fc090
4 changed files with 177 additions and 3 deletions

View File

@@ -20,6 +20,7 @@
#include "util.h"
#include "main.h"
#include "font.h"
#include "common/debug.h"
#include "common/stringutils.h"
@@ -105,6 +106,7 @@ static bool uiFontAddFace(const FcPattern * pattern, FcCharSet ** remainingPtr)
FcChar8 * file;
FcCharSet * charset;
FcBool outline = FcTrue;
int index = 0;
if (FcPatternGetString(pattern, FC_FILE, 0, &file) != FcResultMatch ||
FcPatternGetCharSet(pattern, FC_CHARSET, 0, &charset) != FcResultMatch)
@@ -114,6 +116,9 @@ static bool uiFontAddFace(const FcPattern * pattern, FcCharSet ** remainingPtr)
!outline)
return true;
if (FcPatternGetInteger(pattern, FC_INDEX, 0, &index) == FcResultMatch)
index &= 0xFFFF;
FcCharSet * covered = FcCharSetIntersect(remaining, charset);
if (!covered)
return false;
@@ -124,6 +129,27 @@ static bool uiFontAddFace(const FcPattern * pattern, FcCharSet ** remainingPtr)
return true;
}
size_t fontDataSize;
void * fontData = igImFileLoadToMemory(
(const char *)file, "rb", &fontDataSize, 0);
if (!fontData)
{
DEBUG_WARN("Failed to read UI font face: %s", file);
FcCharSetDestroy(covered);
return true;
}
const bool compatible = font_isStbTruetypeCompatible(
fontData, fontDataSize, index);
igMemFree(fontData);
if (!compatible)
{
DEBUG_WARN("Skipping stb-incompatible UI font face: %s (index %d)",
file, index);
FcCharSetDestroy(covered);
return true;
}
struct UIFontFace * faces = realloc(UIFontFaces,
sizeof(*UIFontFaces) * (UIFontFaceCount + 1));
if (!faces)
@@ -144,9 +170,7 @@ static bool uiFontAddFace(const FcPattern * pattern, FcCharSet ** remainingPtr)
return false;
}
int index = 0;
if (FcPatternGetInteger(pattern, FC_INDEX, 0, &index) == FcResultMatch)
face->index = index & 0xFFFF;
face->index = index;
++UIFontFaceCount;