mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-08-02 05:12:02 +00:00
[client] font: skip stb-incompatible UI font faces
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user