From 2bfddaae168bfacfd29a46d74a728aff96c4cfbc Mon Sep 17 00:00:00 2001 From: Soreepeong Date: Sun, 10 Dec 2023 21:21:14 +0900 Subject: [PATCH] Add minimum range rebuild test --- .../Widgets/GamePrebakedFontsTestWidget.cs | 57 ++++++++++++++----- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/Dalamud/Interface/Internal/Windows/Data/Widgets/GamePrebakedFontsTestWidget.cs b/Dalamud/Interface/Internal/Windows/Data/Widgets/GamePrebakedFontsTestWidget.cs index 12749114b..dba293e8b 100644 --- a/Dalamud/Interface/Internal/Windows/Data/Widgets/GamePrebakedFontsTestWidget.cs +++ b/Dalamud/Interface/Internal/Windows/Data/Widgets/GamePrebakedFontsTestWidget.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; +using System.Text; using Dalamud.Interface.GameFonts; using Dalamud.Interface.ManagedFontAtlas; @@ -24,6 +25,7 @@ internal class GamePrebakedFontsTestWidget : IDataWindowWidget, IDisposable private bool useWordWrap; private bool useItalic; private bool useBold; + private bool useMinimumBuild; /// public string[]? CommandShortcuts { get; init; } @@ -80,6 +82,17 @@ internal class GamePrebakedFontsTestWidget : IDataWindowWidget, IDisposable this.ClearAtlas(); } } + + ImGui.SameLine(); + fixed (byte* labelPtr = "Minimum Range"u8) + { + var v = (byte)(this.useMinimumBuild ? 1 : 0); + if (ImGuiNative.igCheckbox(labelPtr, &v) != 0) + { + this.useMinimumBuild = v != 0; + this.ClearAtlas(); + } + } ImGui.SameLine(); if (ImGui.Button("Reset Text") || this.testStringBuffer.IsDisposed) @@ -90,21 +103,6 @@ internal class GamePrebakedFontsTestWidget : IDataWindowWidget, IDisposable minCapacity: 1024); } - this.privateAtlas ??= - Service.Get().CreateFontAtlas( - nameof(GamePrebakedFontsTestWidget), - FontAtlasAutoRebuildMode.Async, - this.useGlobalScale); - this.fontHandles ??= - Enum.GetValues() - .Where(x => x.GetAttribute() is not null) - .Select(x => new GameFontStyle(x) { Italic = this.useItalic, Bold = this.useBold }) - .GroupBy(x => x.Family) - .ToImmutableDictionary( - x => x.Key, - x => x.Select(y => (y, new Lazy(() => this.privateAtlas.NewGameFontHandle(y)))) - .ToArray()); - fixed (byte* labelPtr = "Test Input"u8) { if (ImGuiNative.igInputTextMultiline( @@ -124,9 +122,38 @@ internal class GamePrebakedFontsTestWidget : IDataWindowWidget, IDisposable this.testStringBuffer.LengthUnsafe = len; this.testStringBuffer.StorageSpan[len] = default; } + + if (this.useMinimumBuild) + _ = this.privateAtlas?.BuildFontsAsync(); } } + this.privateAtlas ??= + Service.Get().CreateFontAtlas( + nameof(GamePrebakedFontsTestWidget), + FontAtlasAutoRebuildMode.Async, + this.useGlobalScale); + this.fontHandles ??= + Enum.GetValues() + .Where(x => x.GetAttribute() is not null) + .Select(x => new GameFontStyle(x) { Italic = this.useItalic, Bold = this.useBold }) + .GroupBy(x => x.Family) + .ToImmutableDictionary( + x => x.Key, + x => x.Select( + y => (y, new Lazy( + () => this.useMinimumBuild + ? this.privateAtlas.NewDelegateFontHandle( + e => + e.OnPreBuild( + tk => tk.AddGameGlyphs( + y, + Encoding.UTF8.GetString( + this.testStringBuffer.DataSpan).ToGlyphRange(), + default))) + : this.privateAtlas.NewGameFontHandle(y)))) + .ToArray()); + var offsetX = ImGui.CalcTextSize("99.9pt").X + (ImGui.GetStyle().FramePadding.X * 2); foreach (var (family, items) in this.fontHandles) {