mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 12:32:20 +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;
|
||||
|
||||
|
|
|
@ -119,7 +119,7 @@ namespace IDE
|
|||
public class IDEApp : BFApp
|
||||
{
|
||||
public static String sRTVersionStr = "042";
|
||||
public const String cVersion = "0.42.4";
|
||||
public const String cVersion = "0.42.5";
|
||||
|
||||
#if BF_PLATFORM_WINDOWS
|
||||
public static readonly String sPlatform64Name = "Win64";
|
||||
|
@ -10634,6 +10634,8 @@ namespace IDE
|
|||
#endif
|
||||
}
|
||||
|
||||
Font.AddFontFailEntry("Segoe UI", scope String()..AppendF("{}fonts/NotoSans-Regular.ttf", mInstallDir));
|
||||
|
||||
DarkTheme aTheme = new DarkTheme();
|
||||
aTheme.Init();
|
||||
ThemeFactory.mDefault = aTheme;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue