From 015c313c5ebad2cfe70cdac42afa1f833ccb6f1c Mon Sep 17 00:00:00 2001 From: Soreepeong Date: Sun, 10 Dec 2023 22:02:33 +0900 Subject: [PATCH] Move UseAxis/Override to FAF --- Dalamud/Interface/Internal/DalamudIme.cs | 7 ++-- .../Interface/Internal/InterfaceManager.cs | 10 ------ .../Windows/Settings/SettingsWindow.cs | 6 ++-- .../Windows/Settings/Tabs/SettingsTabLook.cs | 6 ++-- .../FontAtlasFactory.BuildToolkit.cs | 36 +++++++++++++++++-- .../Internals/FontAtlasFactory.cs | 11 ++++++ Dalamud/Interface/Utility/ImGuiHelpers.cs | 18 +++++----- 7 files changed, 64 insertions(+), 30 deletions(-) diff --git a/Dalamud/Interface/Internal/DalamudIme.cs b/Dalamud/Interface/Internal/DalamudIme.cs index e030b4e50..28a9075bd 100644 --- a/Dalamud/Interface/Internal/DalamudIme.cs +++ b/Dalamud/Interface/Internal/DalamudIme.cs @@ -11,6 +11,7 @@ using System.Text.Unicode; using Dalamud.Game.Text; using Dalamud.Hooking.WndProcHook; using Dalamud.Interface.GameFonts; +using Dalamud.Interface.ManagedFontAtlas.Internals; using Dalamud.Interface.Utility; using ImGuiNET; @@ -196,9 +197,9 @@ internal sealed unsafe class DalamudIme : IDisposable, IServiceType { if (HanRange.Any(x => x.FirstCodePoint <= chr && chr < x.FirstCodePoint + x.Length)) { - if (Service.Get() - .GetFdtReader(GameFontFamilyAndSize.Axis12) - ?.FindGlyph(chr) is null) + if (Service.Get() + ?.GetFdtReader(GameFontFamilyAndSize.Axis12) + .FindGlyph(chr) is null) { if (!this.EncounteredHan) { diff --git a/Dalamud/Interface/Internal/InterfaceManager.cs b/Dalamud/Interface/Internal/InterfaceManager.cs index d252321db..3e004727a 100644 --- a/Dalamud/Interface/Internal/InterfaceManager.cs +++ b/Dalamud/Interface/Internal/InterfaceManager.cs @@ -189,16 +189,6 @@ internal class InterfaceManager : IDisposable, IServiceType /// public bool IsDispatchingEvents { get; set; } = true; - /// - /// Gets or sets a value indicating whether to override configuration for UseAxis. - /// - public bool? UseAxisOverride { get; set; } = null; - - /// - /// Gets a value indicating whether to use AXIS fonts. - /// - public bool UseAxis => this.UseAxisOverride ?? Service.Get().UseAxisFontsFromGame; - /// /// Gets a value indicating the native handle of the game main window. /// diff --git a/Dalamud/Interface/Internal/Windows/Settings/SettingsWindow.cs b/Dalamud/Interface/Internal/Windows/Settings/SettingsWindow.cs index 20ffc781c..027e1a571 100644 --- a/Dalamud/Interface/Internal/Windows/Settings/SettingsWindow.cs +++ b/Dalamud/Interface/Internal/Windows/Settings/SettingsWindow.cs @@ -5,6 +5,7 @@ using CheapLoc; using Dalamud.Configuration.Internal; using Dalamud.Interface.Colors; using Dalamud.Interface.Internal.Windows.Settings.Tabs; +using Dalamud.Interface.ManagedFontAtlas.Internals; using Dalamud.Interface.Utility; using Dalamud.Interface.Utility.Raii; using Dalamud.Interface.Windowing; @@ -65,11 +66,12 @@ internal class SettingsWindow : Window { var configuration = Service.Get(); var interfaceManager = Service.Get(); + var fontAtlasFactory = Service.Get(); - var rebuildFont = interfaceManager.UseAxis != configuration.UseAxisFontsFromGame; + var rebuildFont = fontAtlasFactory.UseAxis != configuration.UseAxisFontsFromGame; ImGui.GetIO().FontGlobalScale = configuration.GlobalUiScale; - interfaceManager.UseAxisOverride = null; + fontAtlasFactory.UseAxisOverride = null; if (rebuildFont) interfaceManager.RebuildFonts(); diff --git a/Dalamud/Interface/Internal/Windows/Settings/Tabs/SettingsTabLook.cs b/Dalamud/Interface/Internal/Windows/Settings/Tabs/SettingsTabLook.cs index 35f307655..5293e13c4 100644 --- a/Dalamud/Interface/Internal/Windows/Settings/Tabs/SettingsTabLook.cs +++ b/Dalamud/Interface/Internal/Windows/Settings/Tabs/SettingsTabLook.cs @@ -8,6 +8,7 @@ using Dalamud.Configuration.Internal; using Dalamud.Interface.Colors; using Dalamud.Interface.Internal.Windows.PluginInstaller; using Dalamud.Interface.Internal.Windows.Settings.Widgets; +using Dalamud.Interface.ManagedFontAtlas.Internals; using Dalamud.Interface.Utility; using Dalamud.Utility; using ImGuiNET; @@ -41,9 +42,8 @@ public class SettingsTabLook : SettingsTab (v, c) => c.UseAxisFontsFromGame = v, v => { - var im = Service.Get(); - im.UseAxisOverride = v; - im.RebuildFonts(); + Service.Get().UseAxisOverride = v; + Service.Get().RebuildFonts(); }), new GapSettingsEntry(5, true), diff --git a/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.BuildToolkit.cs b/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.BuildToolkit.cs index fdef499dd..e73ea7548 100644 --- a/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.BuildToolkit.cs +++ b/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.BuildToolkit.cs @@ -114,7 +114,7 @@ internal sealed partial class FontAtlasFactory return fontPtr; } - /// + /// public bool IsGlobalScaleIgnored(ImFontPtr fontPtr) => this.GlobalScaleExclusions.Contains(fontPtr); @@ -275,7 +275,7 @@ internal sealed partial class FontAtlasFactory { ImFontPtr font; glyphRanges ??= this.factory.DefaultGlyphRanges; - if (Service.Get().UseAxis) + if (this.factory.UseAxis) { font = this.AddGameGlyphs(new(GameFontFamily.Axis, sizePx), glyphRanges, default); } @@ -360,7 +360,8 @@ internal sealed partial class FontAtlasFactory public void AttachExtraGlyphsForDalamudLanguage(in SafeFontConfig fontConfig) { var dalamudConfiguration = Service.Get(); - if (dalamudConfiguration.EffectiveLanguage == "ko") + if (dalamudConfiguration.EffectiveLanguage == "ko" + || Service.GetNullable()?.EncounteredHangul is true) { this.AddDalamudAssetFont( DalamudAsset.NotoSansKrRegular, @@ -374,6 +375,35 @@ internal sealed partial class FontAtlasFactory UnicodeRanges.HangulJamoExtendedB), }); } + + var windowsDir = Environment.GetFolderPath(Environment.SpecialFolder.Windows); + var fontPathChs = Path.Combine(windowsDir, "Fonts", "msyh.ttc"); + if (!File.Exists(fontPathChs)) + fontPathChs = null; + + var fontPathCht = Path.Combine(windowsDir, "Fonts", "msjh.ttc"); + if (!File.Exists(fontPathCht)) + fontPathCht = null; + + if (fontPathCht != null && Service.Get().EffectiveLanguage == "tw") + { + this.AddFontFromFile(fontPathCht, fontConfig with + { + GlyphRanges = ImGuiHelpers.CreateImGuiRangesFrom( + UnicodeRanges.CjkUnifiedIdeographs, + UnicodeRanges.CjkUnifiedIdeographsExtensionA), + }); + } + else if (fontPathChs != null && (Service.Get().EffectiveLanguage == "zh" + || Service.GetNullable()?.EncounteredHan is true)) + { + this.AddFontFromFile(fontPathChs, fontConfig with + { + GlyphRanges = ImGuiHelpers.CreateImGuiRangesFrom( + UnicodeRanges.CjkUnifiedIdeographs, + UnicodeRanges.CjkUnifiedIdeographsExtensionA), + }); + } } public void PreBuildSubstances() diff --git a/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.cs b/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.cs index fc199ef5a..358ccd845 100644 --- a/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.cs +++ b/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using Dalamud.Configuration.Internal; using Dalamud.Data; using Dalamud.Game; using Dalamud.Interface.GameFonts; @@ -106,6 +107,16 @@ internal sealed partial class FontAtlasFactory }); } + /// + /// Gets or sets a value indicating whether to override configuration for UseAxis. + /// + public bool? UseAxisOverride { get; set; } = null; + + /// + /// Gets a value indicating whether to use AXIS fonts. + /// + public bool UseAxis => this.UseAxisOverride ?? Service.Get().UseAxisFontsFromGame; + /// /// Gets the service instance of . /// diff --git a/Dalamud/Interface/Utility/ImGuiHelpers.cs b/Dalamud/Interface/Utility/ImGuiHelpers.cs index 8ba103593..e3b0ff8d1 100644 --- a/Dalamud/Interface/Utility/ImGuiHelpers.cs +++ b/Dalamud/Interface/Utility/ImGuiHelpers.cs @@ -548,6 +548,15 @@ public static class ImGuiHelpers /// The pointer. /// Whether it is empty. public static unsafe bool IsNull(this ImFontAtlasPtr ptr) => ptr.NativePtr == null; + + /// + /// If is default, then returns . + /// + /// The self. + /// The other. + /// if it is not default; otherwise, . + public static unsafe ImFontPtr OrElse(this ImFontPtr self, ImFontPtr other) => + self.NativePtr is null ? other : self; /// /// Finds the corresponding ImGui viewport ID for the given window handle. @@ -569,15 +578,6 @@ public static class ImGuiHelpers return -1; } - /// - /// If is default, then returns . - /// - /// The self. - /// The other. - /// if it is not default; otherwise, . - public static unsafe ImFontPtr OrElse(this ImFontPtr self, ImFontPtr other) => - self.NativePtr is null ? other : self; - /// /// Attempts to validate that is valid. ///