diff --git a/Dalamud/DalamudAsset.cs b/Dalamud/DalamudAsset.cs index 27771116e..49fee005f 100644 --- a/Dalamud/DalamudAsset.cs +++ b/Dalamud/DalamudAsset.cs @@ -1,4 +1,4 @@ -using Dalamud.Storage.Assets; +using Dalamud.Storage.Assets; using TerraFX.Interop.DirectX; @@ -128,17 +128,17 @@ public enum DalamudAsset /// : Noto Sans CJK JP Medium. /// [DalamudAsset(DalamudAssetPurpose.Font)] - [DalamudAssetPath("UIRes", "NotoSansCJKjp-Regular.otf")] - [DalamudAssetPath("UIRes", "NotoSansCJKjp-Medium.otf")] - NotoSansJpMedium = 2000, + //[DalamudAssetPath("UIRes", "NotoSansCJKjp-Regular.otf")] + [DalamudAssetPath("UIRes", "NotoSansCJK-Medium.ttc")] + NotoSansCJKMedium = 2000, /// /// : Noto Sans CJK KR Regular. /// [DalamudAsset(DalamudAssetPurpose.Font)] - [DalamudAssetPath("UIRes", "NotoSansCJKkr-Regular.otf")] - [DalamudAssetPath("UIRes", "NotoSansKR-Regular.otf")] - NotoSansKrRegular = 2001, + //[DalamudAssetPath("UIRes", "NotoSansCJKkr-Regular.otf")] + [DalamudAssetPath("UIRes", "NotoSansCJK-Regular.ttc")] + NotoSansCJKRegular = 2001, /// /// : Inconsolata Regular. diff --git a/Dalamud/Interface/FontIdentifier/IFontFamilyId.cs b/Dalamud/Interface/FontIdentifier/IFontFamilyId.cs index 991716f74..163d7e905 100644 --- a/Dalamud/Interface/FontIdentifier/IFontFamilyId.cs +++ b/Dalamud/Interface/FontIdentifier/IFontFamilyId.cs @@ -38,7 +38,8 @@ public interface IFontFamilyId : IObjectWithLocalizableName public static List ListDalamudFonts() => new() { - new DalamudAssetFontAndFamilyId(DalamudAsset.NotoSansJpMedium), + new DalamudAssetFontAndFamilyId(DalamudAsset.NotoSansCJKMedium), + new DalamudAssetFontAndFamilyId(DalamudAsset.NotoSansCJKRegular), new DalamudAssetFontAndFamilyId(DalamudAsset.InconsolataRegular), new DalamudAssetFontAndFamilyId(DalamudAsset.FontAwesomeFreeSolid), }; diff --git a/Dalamud/Interface/FontIdentifier/IFontSpec.cs b/Dalamud/Interface/FontIdentifier/IFontSpec.cs index c597ed4dd..8c7b94a9c 100644 --- a/Dalamud/Interface/FontIdentifier/IFontSpec.cs +++ b/Dalamud/Interface/FontIdentifier/IFontSpec.cs @@ -24,6 +24,11 @@ public interface IFontSpec /// float LineHeightPx { get; } + /// + /// Gets the font no. + /// + int FontNo { get; } + /// /// Creates a font handle corresponding to this font specification. /// diff --git a/Dalamud/Interface/FontIdentifier/SingleFontSpec.cs b/Dalamud/Interface/FontIdentifier/SingleFontSpec.cs index 070b1c1e1..96b566dfe 100644 --- a/Dalamud/Interface/FontIdentifier/SingleFontSpec.cs +++ b/Dalamud/Interface/FontIdentifier/SingleFontSpec.cs @@ -65,6 +65,12 @@ public record SingleFontSpec : IFontSpec [JsonProperty] public ushort[]? GlyphRanges { get; init; } + /// + /// Gets the font no. + /// + [JsonProperty] + public int FontNo { get; init; } + /// public string ToLocalizedString(string localeCode) { @@ -99,6 +105,7 @@ public record SingleFontSpec : IFontSpec tk, new() { + FontNo = this.FontNo, SizePx = this.SizePx, GlyphRanges = this.GlyphRanges, MergeFont = mergeFont, diff --git a/Dalamud/Interface/ImGuiFontChooserDialog/SingleFontChooserDialog.cs b/Dalamud/Interface/ImGuiFontChooserDialog/SingleFontChooserDialog.cs index 6a381f5b2..cc22f358a 100644 --- a/Dalamud/Interface/ImGuiFontChooserDialog/SingleFontChooserDialog.cs +++ b/Dalamud/Interface/ImGuiFontChooserDialog/SingleFontChooserDialog.cs @@ -128,7 +128,7 @@ public sealed class SingleFontChooserDialog : IDisposable this.popupImGuiName = $"{this.title}##{nameof(SingleFontChooserDialog)}[{this.counter}]"; this.atlas = newAsyncAtlas; this.selectedFont = new() { FontId = DalamudDefaultFontAndFamilyId.Instance }; - Encoding.UTF8.GetBytes("Font preview.\n0123456789!", this.fontPreviewText); + Encoding.UTF8.GetBytes("Font preview.\n0123456789!\n遍角次亮采之门,门上插刀、直字拐弯、天上平板、船顶漏雨。\n다람쥐 헌 쳇바퀴에 타고파", this.fontPreviewText); } /// Called when the selected font spec has changed. @@ -891,7 +891,21 @@ public sealed class SingleFontChooserDialog : IDisposable this.selectedFontWeight = font.Weight; this.selectedFontStretch = font.Stretch; this.selectedFontStyle = font.Style; - this.selectedFont = this.selectedFont with { FontId = font }; + int fontNo = 0; + if (family is DalamudAssetFontAndFamilyId { Asset: DalamudAsset.NotoSansCJKRegular or DalamudAsset.NotoSansCJKMedium }) + { + var dalamudConfiguration = Service.Get(); + fontNo = dalamudConfiguration.EffectiveLanguage switch + { + "jp" => 0, + "tw" => 1, + "zh" => 2, + "ko" => 3, + _ => 0, + }; + } + + this.selectedFont = this.selectedFont with { FontId = font, FontNo = fontNo }; } return changed; diff --git a/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.BuildToolkit.cs b/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.BuildToolkit.cs index 2a93cf093..58c2c953d 100644 --- a/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.BuildToolkit.cs +++ b/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.BuildToolkit.cs @@ -371,10 +371,7 @@ internal sealed partial class FontAtlasFactory return this.factory.AddFont( this, asset, - fontConfig with - { - FontNo = 0, - }); + fontConfig); } } @@ -562,32 +559,39 @@ internal sealed partial class FontAtlasFactory return; var dalamudConfiguration = Service.Get(); - if (dalamudConfiguration.EffectiveLanguage == "ko" - || Service.GetNullable()?.EncounteredHangul is true) + var ime = Service.GetNullable(); + + string langTag = null; + // fontNo: 0 = japanese, 1 = traditional chinese, 2 = simplified chinese, 3 = korean + int fontNo = 0; + + if (dalamudConfiguration.EffectiveLanguage == "tw") { - this.AddDalamudAssetFont( - DalamudAsset.NotoSansKrRegular, - fontConfig with - { - MergeFont = targetFont, - GlyphRanges = default(FluentGlyphRangeBuilder).WithLanguage("ko-kr").BuildExact(), - }); + langTag = "zh-hant"; + fontNo = 1; + } + else if (dalamudConfiguration.EffectiveLanguage == "zh" || ime?.EncounteredHan is true) + { + langTag = "zh-hans"; + fontNo = 2; + } + else if (dalamudConfiguration.EffectiveLanguage == "ko" || ime?.EncounteredHangul is true) + { + langTag = "ko-kr"; + fontNo = 3; } - if (Service.Get().EffectiveLanguage == "tw") + Log.Debug($"Loading extra glyphs for language tag '{langTag}' (font no {fontNo})"); + if (langTag != null) { - this.AttachWindowsDefaultFont(CultureInfo.GetCultureInfo("zh-hant"), fontConfig with - { - GlyphRanges = default(FluentGlyphRangeBuilder).WithLanguage("zh-hant").BuildExact(), - }); - } - else if (Service.Get().EffectiveLanguage == "zh" - || Service.GetNullable()?.EncounteredHan is true) - { - this.AttachWindowsDefaultFont(CultureInfo.GetCultureInfo("zh-hans"), fontConfig with - { - GlyphRanges = default(FluentGlyphRangeBuilder).WithLanguage("zh-hans").BuildExact(), - }); + this.AddDalamudAssetFont( + DalamudAsset.NotoSansCJKRegular, + fontConfig with + { + FontNo = fontNo, + MergeFont = targetFont, + GlyphRanges = default(FluentGlyphRangeBuilder).WithLanguage(langTag).BuildExact(), + }); } } @@ -629,7 +633,7 @@ internal sealed partial class FontAtlasFactory if (this.data.ConfigData.Length == 0) { this.AddDalamudAssetFont( - DalamudAsset.NotoSansJpMedium, + DalamudAsset.NotoSansCJKRegular, new() { GlyphRanges = new ushort[] { ' ', ' ', '\0' }, SizePx = 1 }); } diff --git a/Dalamud/Interface/ManagedFontAtlas/Internals/GamePrebakedFontHandle.cs b/Dalamud/Interface/ManagedFontAtlas/Internals/GamePrebakedFontHandle.cs index f6904db7c..8bd3212dd 100644 --- a/Dalamud/Interface/ManagedFontAtlas/Internals/GamePrebakedFontHandle.cs +++ b/Dalamud/Interface/ManagedFontAtlas/Internals/GamePrebakedFontHandle.cs @@ -412,14 +412,14 @@ internal class GamePrebakedFontHandle : FontHandle private ImFontPtr CreateTemplateFont(IFontAtlasBuildToolkitPreBuild toolkitPreBuild, float sizePx) { var font = toolkitPreBuild.AddDalamudAssetFont( - DalamudAsset.NotoSansJpMedium, + DalamudAsset.NotoSansCJKMedium, new() { GlyphRanges = new ushort[] { ' ', ' ', '\0' }, SizePx = sizePx, }); this.templatedFonts.Add(font); - return font; + return font; } private unsafe void PatchFontMetricsIfNecessary(GameFontStyle style, ImFontPtr font, float atlasScale)