Merge pull request #772 from Soreepeong/feature/nicer-fonts

This commit is contained in:
goaaats 2022-03-08 19:02:25 +01:00 committed by GitHub
commit ba165f09bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -611,7 +611,12 @@ namespace Dalamud.Interface.Internal
ioFonts.Clear();
ioFonts.TexDesiredWidth = 4096;
ImFontConfigPtr fontConfig = ImGuiNative.ImFontConfig_ImFontConfig();
ImFontConfigPtr fontConfig = null;
List<GCHandle> garbageList = new();
try
{
fontConfig = ImGuiNative.ImFontConfig_ImFontConfig();
fontConfig.OversampleH = 1;
fontConfig.OversampleV = 1;
fontConfig.PixelSnapH = true;
@ -623,8 +628,9 @@ namespace Dalamud.Interface.Internal
// Default font
{
var japaneseRangeHandle = GCHandle.Alloc(GlyphRangesJapanese.GlyphRanges, GCHandleType.Pinned);
garbageList.Add(japaneseRangeHandle);
DefaultFont = ioFonts.AddFontFromFileTTF(fontPathJp, (DefaultFontSizePx + 1) * fontScale, fontConfig, japaneseRangeHandle.AddrOfPinnedObject());
japaneseRangeHandle.Free();
fontsToUnscale.Add(DefaultFont);
}
@ -635,8 +641,9 @@ namespace Dalamud.Interface.Internal
ShowFontError(fontPathIcon);
var iconRangeHandle = GCHandle.Alloc(new ushort[] { 0xE000, 0xF8FF, 0, }, GCHandleType.Pinned);
garbageList.Add(iconRangeHandle);
IconFont = ioFonts.AddFontFromFileTTF(fontPathIcon, DefaultFontSizePx * fontScale, fontConfig, iconRangeHandle.AddrOfPinnedObject());
iconRangeHandle.Free();
fontsToUnscale.Add(IconFont);
}
@ -694,9 +701,9 @@ namespace Dalamud.Interface.Internal
flattenedRanges.Add(0);
var rangeHandle = GCHandle.Alloc(flattenedRanges.ToArray(), GCHandleType.Pinned);
var sizedFont = ioFonts.AddFontFromFileTTF(fontPathJp, fontSize * fontScale, fontConfig, rangeHandle.AddrOfPinnedObject());
rangeHandle.Free();
garbageList.Add(rangeHandle);
var sizedFont = ioFonts.AddFontFromFileTTF(fontPathJp, fontSize * fontScale, fontConfig, rangeHandle.AddrOfPinnedObject());
fontsToUnscale.Add(sizedFont);
foreach (var request in requests)
@ -775,11 +782,19 @@ namespace Dalamud.Interface.Internal
Log.Verbose("[FONT] Fonts built!");
fontConfig.Destroy();
this.fontBuildSignal.Set();
this.FontsReady = true;
}
finally
{
if (fontConfig.NativePtr != null)
fontConfig.Destroy();
foreach (var garbage in garbageList)
garbage.Free();
}
}
private void Disable()
{