mirror of
https://github.com/beefytech/Beef.git
synced 2025-07-04 23:36:00 +02:00
Added font failovers for missing fonts
This commit is contained in:
parent
33286fb804
commit
1010e8ac83
2 changed files with 44 additions and 5 deletions
|
@ -54,6 +54,7 @@ namespace Beefy.gfx
|
|||
static extern int32 FTFont_GetKerning(FTFont* font, int32 char8CodeA, int32 char8CodeB);
|
||||
|
||||
static Dictionary<String, String> sFontNameMap ~ DeleteDictionaryAndKeysAndItems!(_);
|
||||
static Dictionary<String, String> sFontFailMap ~ DeleteDictionaryAndKeysAndItems!(_);
|
||||
static Monitor sMonitor = new .() ~ delete _;
|
||||
|
||||
struct FTFont
|
||||
|
@ -205,6 +206,29 @@ namespace Beefy.gfx
|
|||
}
|
||||
}
|
||||
|
||||
public static void AddFontFailEntry(StringView mapFrom, StringView mapTo)
|
||||
{
|
||||
using (sMonitor.Enter())
|
||||
{
|
||||
if (sFontFailMap == null)
|
||||
sFontFailMap = new .();
|
||||
|
||||
String str = new String(mapFrom);
|
||||
str.ToUpper();
|
||||
bool added = sFontFailMap.TryAdd(str, var keyPtr, var valuePtr);
|
||||
if (added)
|
||||
{
|
||||
*keyPtr = str;
|
||||
*valuePtr = new String(mapTo);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete str;
|
||||
(*valuePtr).Set(mapTo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose(bool cacheRetain)
|
||||
{
|
||||
if (mFTFont != null)
|
||||
|
@ -336,13 +360,23 @@ namespace Beefy.gfx
|
|||
String pathStr;
|
||||
if (sFontNameMap.TryGetValue(lookupStr, out pathStr))
|
||||
{
|
||||
char8[256] windowsDir;
|
||||
Windows.GetWindowsDirectoryA(&windowsDir, 256);
|
||||
path.Append(&windowsDir);
|
||||
path.Append(@"\Fonts\");
|
||||
if (!pathStr.Contains(':'))
|
||||
{
|
||||
char8[256] windowsDir;
|
||||
Windows.GetWindowsDirectoryA(&windowsDir, 256);
|
||||
path.Append(&windowsDir);
|
||||
path.Append(@"\Fonts\");
|
||||
}
|
||||
|
||||
path.Append(pathStr);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if ((sFontFailMap != null) && (sFontFailMap.TryGetValue(lookupStr, out pathStr)))
|
||||
{
|
||||
path.Append(pathStr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -358,6 +392,9 @@ namespace Beefy.gfx
|
|||
float usePointSize = pointSize;
|
||||
mPath = new String();
|
||||
GetFontPath(fontName, mPath);
|
||||
|
||||
Console.WriteLine("Font loading {} from {}", fontName, mPath);
|
||||
|
||||
if (mPath.IsEmpty)
|
||||
return false;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue