From 90d9818f9418c4ca1f998e5b7619eaf80095e4a5 Mon Sep 17 00:00:00 2001 From: Anna Date: Tue, 8 Feb 2022 18:04:42 -0500 Subject: [PATCH] fix: include more glyphs in jp font --- ChatTwo/PluginUi.cs | 50 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/ChatTwo/PluginUi.cs b/ChatTwo/PluginUi.cs index 9428949..c0e9426 100755 --- a/ChatTwo/PluginUi.cs +++ b/ChatTwo/PluginUi.cs @@ -38,11 +38,7 @@ internal sealed class PluginUi : IDisposable { private (GCHandle, int) _gameSymFont; private readonly ImVector _ranges; - - private GCHandle _jpRange = GCHandle.Alloc( - GlyphRangesJapanese.GlyphRanges, - GCHandleType.Pinned - ); + private readonly ImVector _jpRange; private GCHandle _symRange = GCHandle.Alloc( new ushort[] { @@ -74,11 +70,42 @@ internal sealed class PluginUi : IDisposable { MergeMode = true, }; - var builder = new ImFontGlyphRangesBuilderPtr(ImGuiNative.ImFontGlyphRangesBuilder_ImFontGlyphRangesBuilder()); - builder.AddRanges(ImGui.GetIO().Fonts.GetGlyphRangesDefault()); - builder.AddText("←→↑↓《》■※☀★★☆♥♡ヅツッシ☀☁☂℃℉°♀♂♠♣♦♣♧®©™€$£♯♭♪✓√◎◆◇♦■□〇●△▽▼▲‹›≤≥<«“”─\~Œœ"); - builder.BuildRanges(out this._ranges); + void BuildRange(out ImVector result, IReadOnlyList? chars, params IntPtr[] ranges) { + var builder = new ImFontGlyphRangesBuilderPtr(ImGuiNative.ImFontGlyphRangesBuilder_ImFontGlyphRangesBuilder()); + // text + foreach (var range in ranges) { + builder.AddRanges(range); + } + // chars + if (chars != null) { + for (var i = 0; i < chars.Count; i += 2) { + if (chars[i] == 0) { + break; + } + + for (var j = (uint) chars[i]; j <= chars[i + 1]; j++) { + builder.AddChar((ushort) j); + } + } + } + + // various symbols + builder.AddText("←→↑↓《》■※☀★★☆♥♡ヅツッシ☀☁☂℃℉°♀♂♠♣♦♣♧®©™€$£♯♭♪✓√◎◆◇♦■□〇●△▽▼▲‹›≤≥<«“”─\~Œœ"); + + // "Enclosed Alphanumerics" (partial) https://www.compart.com/en/unicode/block/U+2460 + for (var i = 0x2460; i <= 0x24B5; i++) { + builder.AddChar((char) i); + } + + builder.AddChar('⓪'); + + builder.BuildRanges(out result); + builder.Destroy(); + } + + BuildRange(out this._ranges, null, ImGui.GetIO().Fonts.GetGlyphRangesDefault()); + BuildRange(out this._jpRange, GlyphRangesJapanese.GlyphRanges); this.SetUpUserFonts(); var gameSym = File.ReadAllBytes(Path.Combine(this.Plugin.Interface.DalamudAssetDirectory.FullName, "UIRes", "gamesym.ttf")); @@ -109,7 +136,6 @@ internal sealed class PluginUi : IDisposable { this._italicFont.Item1.Free(); this._gameSymFont.Item1.Free(); this._symRange.Free(); - this._jpRange.Free(); this._fontCfg.Destroy(); this._fontCfgMerge.Destroy(); } @@ -242,7 +268,7 @@ internal sealed class PluginUi : IDisposable { this._jpFont.Item2, this.Plugin.Config.JapaneseFontSize, this._fontCfgMerge, - this._jpRange.AddrOfPinnedObject() + this._jpRange.Data ); ImGui.GetIO().Fonts.AddFontFromMemoryTTF( @@ -267,7 +293,7 @@ internal sealed class PluginUi : IDisposable { this._jpFont.Item2, this.Plugin.Config.JapaneseFontSize, this._fontCfgMerge, - this._jpRange.AddrOfPinnedObject() + this._jpRange.Data ); ImGui.GetIO().Fonts.AddFontFromMemoryTTF(