Always keep all AXIS fonts in memory

(cherry picked from commit f5c75e4cd5)
This commit is contained in:
Soreepeong 2022-03-07 14:41:55 +09:00
parent cbc0896fad
commit 267a4b0047
2 changed files with 32 additions and 16 deletions

View file

@ -64,7 +64,7 @@ namespace Dalamud.Interface.Internal
private readonly SwapChainVtableResolver address;
private RawDX11Scene? scene;
private GameFontHandle? axisFontHandle;
private GameFontHandle[] axisFontHandles;
private bool overwriteAllNotoGlyphsWithAxis;
// can't access imgui IO before first present call
@ -353,16 +353,17 @@ namespace Dalamud.Interface.Internal
/// <returns>Requets handle.</returns>
public SpecialGlyphRequest NewFontSizeRef(float size, List<Tuple<ushort, ushort>> ranges)
{
var allContained = true;
var allContained = false;
var fonts = ImGui.GetIO().Fonts.Fonts;
ImFontPtr foundFont = null;
unsafe
{
for (int i = 0, i_ = fonts.Size; allContained && i < i_; i++)
for (int i = 0, i_ = fonts.Size; i < i_; i++)
{
if (!this.glyphRequests.Any(x => x.FontInternal.NativePtr == fonts[i].NativePtr))
continue;
allContained = true;
foreach (var range in ranges)
{
if (!allContained)
@ -418,12 +419,16 @@ namespace Dalamud.Interface.Internal
var configuration = Service<DalamudConfiguration>.Get();
this.overwriteAllNotoGlyphsWithAxis = configuration.UseAxisFontsFromGame;
var currentFamilyAndSize = GameFontStyle.GetRecommendedFamilyAndSize(GameFontFamily.Axis, this.axisFontHandle?.Style.Size ?? 0f);
var expectedFamilyAndSize = GameFontStyle.GetRecommendedFamilyAndSize(GameFontFamily.Axis, DefaultFontSizePt * ImGui.GetIO().FontGlobalScale);
if (currentFamilyAndSize != expectedFamilyAndSize)
if (this.axisFontHandles == null)
{
this.axisFontHandle?.Dispose();
this.axisFontHandle = Service<GameFontManager>.Get().NewFontRef(new(expectedFamilyAndSize));
this.axisFontHandles = new GameFontHandle[]
{
Service<GameFontManager>.Get().NewFontRef(new(GameFontFamilyAndSize.Axis96)),
Service<GameFontManager>.Get().NewFontRef(new(GameFontFamilyAndSize.Axis12)),
Service<GameFontManager>.Get().NewFontRef(new(GameFontFamilyAndSize.Axis14)),
Service<GameFontManager>.Get().NewFontRef(new(GameFontFamilyAndSize.Axis18)),
Service<GameFontManager>.Get().NewFontRef(new(GameFontFamilyAndSize.Axis36)),
};
}
}
@ -736,14 +741,24 @@ namespace Dalamud.Interface.Internal
if (font.NativePtr == MonoFont.NativePtr)
continue;
if (this.overwriteAllNotoGlyphsWithAxis)
GameFontManager.CopyGlyphsAcrossFonts(this.axisFontHandle?.ImFont, font, false, false);
var axisFont = this.axisFontHandles[^1];
for (var i = this.axisFontHandles.Length - 2; i >= 0; i--)
{
if (this.axisFontHandles[i].Style.Size >= (font.FontSize - 1) * fontScale * 3 / 4)
axisFont = this.axisFontHandles[i];
else
GameFontManager.CopyGlyphsAcrossFonts(this.axisFontHandle?.ImFont, font, false, false, 0xE020, 0xE0DB);
break;
}
if (this.overwriteAllNotoGlyphsWithAxis)
GameFontManager.CopyGlyphsAcrossFonts(axisFont.ImFont, font, false, false);
else
GameFontManager.CopyGlyphsAcrossFonts(axisFont.ImFont, font, false, false, 0xE020, 0xE0DB);
// Fill missing glyphs in DefaultFont from Axis
GameFontManager.CopyGlyphsAcrossFonts(this.axisFontHandle?.ImFont, DefaultFont, true, false);
if (font.NativePtr == DefaultFont.NativePtr)
GameFontManager.CopyGlyphsAcrossFonts(axisFont.ImFont, DefaultFont, true, false);
}
// Fill missing glyphs in MonoFont from DefaultFont
GameFontManager.CopyGlyphsAcrossFonts(DefaultFont, MonoFont, true, false);

View file

@ -245,6 +245,7 @@ namespace Dalamud.Interface.Internal.Windows
this.specialGlyphRequests[entry.Name] = fontHandle = Service<InterfaceManager>.Get().NewFontSizeRef(TargetFontSizePx, entry.Name);
ImGui.PushFont(fontHandle.Font);
ImGui.SetWindowFontScale(TargetFontSizePx / fontHandle.Size);
var scale = ImGui.GetIO().FontGlobalScale;