Fix fallback font not working correctly (#839)

* Fix GetGameFontHandle calls during BuildFonts

* Add option to draw ImGui test windows in Monospace font

* Add warning if first font is not the default font as we would like it

* Add better description for Font Resolution Level

* Fix scaling when using Korean fonts with AXIS on
This commit is contained in:
kizer 2022-05-13 17:13:49 +09:00 committed by GitHub
parent cadcddf7b1
commit e1df496e2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 15 deletions

View file

@ -39,7 +39,7 @@ namespace Dalamud.Interface.GameFonts
private readonly Dictionary<GameFontStyle, int> fontUseCounter = new();
private readonly Dictionary<GameFontStyle, Dictionary<char, Tuple<int, FdtReader.FontTableEntry>>> glyphRectIds = new();
private bool isBetweenBuildFontsAndAfterBuildFonts = false;
private bool isBetweenBuildFontsAndRightAfterImGuiIoFontsBuild = false;
private bool isBuildingAsFallbackFontMode = false;
/// <summary>
@ -174,7 +174,7 @@ namespace Dalamud.Interface.GameFonts
needRebuild = !this.fonts.ContainsKey(style);
if (needRebuild)
{
if (Service<InterfaceManager>.Get().IsBuildingFontsBeforeAtlasBuild && this.isBetweenBuildFontsAndAfterBuildFonts)
if (Service<InterfaceManager>.Get().IsBuildingFontsBeforeAtlasBuild && this.isBetweenBuildFontsAndRightAfterImGuiIoFontsBuild)
{
Log.Information("[GameFontManager] NewFontRef: Building {0} right now, as it is called while BuildFonts is already in progress yet atlas build has not been called yet.", style.ToString());
this.EnsureFont(style);
@ -246,7 +246,7 @@ namespace Dalamud.Interface.GameFonts
public void BuildFonts(bool forceMinSize)
{
this.isBuildingAsFallbackFontMode = forceMinSize;
this.isBetweenBuildFontsAndAfterBuildFonts = true;
this.isBetweenBuildFontsAndRightAfterImGuiIoFontsBuild = true;
this.glyphRectIds.Clear();
this.fonts.Clear();
@ -255,6 +255,21 @@ namespace Dalamud.Interface.GameFonts
this.EnsureFont(style);
}
/// <summary>
/// Record that ImGui.GetIO().Fonts.Build() has been called.
/// </summary>
public void AfterIoFontsBuild()
{
this.isBetweenBuildFontsAndRightAfterImGuiIoFontsBuild = false;
}
/// <summary>
/// Checks whether GameFontMamager owns an ImFont.
/// </summary>
/// <param name="fontPtr">ImFontPtr to check.</param>
/// <returns>Whether it owns.</returns>
public bool OwnsFont(ImFontPtr fontPtr) => this.fonts.ContainsValue(fontPtr);
/// <summary>
/// Post-build fonts before plugins do something more. To be called from InterfaceManager.
/// </summary>
@ -270,6 +285,9 @@ namespace Dalamud.Interface.GameFonts
var fdt = this.fdts[(int)(this.isBuildingAsFallbackFontMode ? style.FamilyWithMinimumSize : style.FamilyAndSize)];
var scale = style.SizePt / fdt.FontHeader.Size;
var fontPtr = font.NativePtr;
Log.Verbose("[GameFontManager] AfterBuildFonts: Scaling {0} from {1}pt to {2}pt (scale: {3})", style.ToString(), fdt.FontHeader.Size, style.SizePt, scale);
fontPtr->FontSize = fdt.FontHeader.Size * 4 / 3;
if (fontPtr->ConfigData != null)
fontPtr->ConfigData->SizePixels = fontPtr->FontSize;
@ -364,12 +382,8 @@ namespace Dalamud.Interface.GameFonts
}
}
ImGuiHelpers.CopyGlyphsAcrossFonts(InterfaceManager.DefaultFont, font, true, false);
UnscaleFont(font, 1 / scale, false);
font.BuildLookupTable();
}
this.isBetweenBuildFontsAndAfterBuildFonts = false;
}
/// <summary>