b
This commit is contained in:
+20
-4
@@ -21,7 +21,7 @@ public static class FontFind
|
||||
{
|
||||
extension(ImGuiIOPtr io)
|
||||
{
|
||||
public unsafe ImFontPtr AddFont(string fontPath)
|
||||
public unsafe ImFontPtr AddFont(string fontPath, bool merge = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -29,13 +29,14 @@ public static class FontFind
|
||||
FileInfo info = new FileInfo(fontPath);
|
||||
if (!info.Exists || info.Length <= 0) return null;
|
||||
|
||||
FontMetrics metrics = ReadFontMetrics(fontPath);
|
||||
FontMetrics metrics = ReadFontMetricsSafe(fontPath);
|
||||
float size = GetRecommendedPixelSize(metrics);
|
||||
|
||||
ImFontConfigPtr config = ImGui.ImFontConfig();
|
||||
config.FontLoaderFlags |= (uint)ImGuiFreeTypeLoaderFlags.LoadColor;
|
||||
config.FontLoaderFlags |= (uint)ImGuiFreeTypeLoaderFlags.LoadColor | (uint)ImGuiFreeTypeLoaderFlags.Bitmap;
|
||||
config.MergeMode = merge;
|
||||
ImFontPtr font = io.Fonts.AddFontFromFileTTF(fontPath, size, config);
|
||||
Program.Logger.Log("Added font: " + Path.GetFileName(fontPath));
|
||||
Program.Logger.Log($"{(merge ? "Merged" : "Added")} font: " + Path.GetFileName(fontPath));
|
||||
return font;
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -71,6 +72,21 @@ public static class FontFind
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
|
||||
public static FontMetrics ReadFontMetricsSafe(string fontPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
return ReadFontMetrics(fontPath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Font parsing failed: " + fontPath);
|
||||
Console.WriteLine(ex.ToString());
|
||||
|
||||
return new FontMetrics();
|
||||
}
|
||||
}
|
||||
|
||||
public static FontMetrics ReadFontMetrics(string fontPath)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user