This commit is contained in:
Loskh 2025-12-12 09:12:18 +00:00 committed by GitHub
commit 224dd3b5e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 70 additions and 39 deletions

View file

@ -1,4 +1,4 @@
using Dalamud.Storage.Assets; using Dalamud.Storage.Assets;
using TerraFX.Interop.DirectX; using TerraFX.Interop.DirectX;
@ -128,17 +128,17 @@ public enum DalamudAsset
/// <see cref="DalamudAssetPurpose.Font"/>: Noto Sans CJK JP Medium. /// <see cref="DalamudAssetPurpose.Font"/>: Noto Sans CJK JP Medium.
/// </summary> /// </summary>
[DalamudAsset(DalamudAssetPurpose.Font)] [DalamudAsset(DalamudAssetPurpose.Font)]
[DalamudAssetPath("UIRes", "NotoSansCJKjp-Regular.otf")] //[DalamudAssetPath("UIRes", "NotoSansCJKjp-Regular.otf")]
[DalamudAssetPath("UIRes", "NotoSansCJKjp-Medium.otf")] [DalamudAssetPath("UIRes", "NotoSansCJK-Medium.ttc")]
NotoSansJpMedium = 2000, NotoSansCJKMedium = 2000,
/// <summary> /// <summary>
/// <see cref="DalamudAssetPurpose.Font"/>: Noto Sans CJK KR Regular. /// <see cref="DalamudAssetPurpose.Font"/>: Noto Sans CJK KR Regular.
/// </summary> /// </summary>
[DalamudAsset(DalamudAssetPurpose.Font)] [DalamudAsset(DalamudAssetPurpose.Font)]
[DalamudAssetPath("UIRes", "NotoSansCJKkr-Regular.otf")] //[DalamudAssetPath("UIRes", "NotoSansCJKkr-Regular.otf")]
[DalamudAssetPath("UIRes", "NotoSansKR-Regular.otf")] [DalamudAssetPath("UIRes", "NotoSansCJK-Regular.ttc")]
NotoSansKrRegular = 2001, NotoSansCJKRegular = 2001,
/// <summary> /// <summary>
/// <see cref="DalamudAssetPurpose.Font"/>: Inconsolata Regular. /// <see cref="DalamudAssetPurpose.Font"/>: Inconsolata Regular.

View file

@ -38,7 +38,8 @@ public interface IFontFamilyId : IObjectWithLocalizableName
public static List<IFontFamilyId> ListDalamudFonts() => public static List<IFontFamilyId> ListDalamudFonts() =>
new() new()
{ {
new DalamudAssetFontAndFamilyId(DalamudAsset.NotoSansJpMedium), new DalamudAssetFontAndFamilyId(DalamudAsset.NotoSansCJKMedium),
new DalamudAssetFontAndFamilyId(DalamudAsset.NotoSansCJKRegular),
new DalamudAssetFontAndFamilyId(DalamudAsset.InconsolataRegular), new DalamudAssetFontAndFamilyId(DalamudAsset.InconsolataRegular),
new DalamudAssetFontAndFamilyId(DalamudAsset.FontAwesomeFreeSolid), new DalamudAssetFontAndFamilyId(DalamudAsset.FontAwesomeFreeSolid),
}; };

View file

@ -24,6 +24,11 @@ public interface IFontSpec
/// </summary> /// </summary>
float LineHeightPx { get; } float LineHeightPx { get; }
/// <summary>
/// Gets the font no.
/// </summary>
int FontNo { get; }
/// <summary> /// <summary>
/// Creates a font handle corresponding to this font specification. /// Creates a font handle corresponding to this font specification.
/// </summary> /// </summary>

View file

@ -65,6 +65,12 @@ public record SingleFontSpec : IFontSpec
[JsonProperty] [JsonProperty]
public ushort[]? GlyphRanges { get; init; } public ushort[]? GlyphRanges { get; init; }
/// <summary>
/// Gets the font no.
/// </summary>
[JsonProperty]
public int FontNo { get; init; }
/// <inheritdoc/> /// <inheritdoc/>
public string ToLocalizedString(string localeCode) public string ToLocalizedString(string localeCode)
{ {
@ -99,6 +105,7 @@ public record SingleFontSpec : IFontSpec
tk, tk,
new() new()
{ {
FontNo = this.FontNo,
SizePx = this.SizePx, SizePx = this.SizePx,
GlyphRanges = this.GlyphRanges, GlyphRanges = this.GlyphRanges,
MergeFont = mergeFont, MergeFont = mergeFont,

View file

@ -128,7 +128,7 @@ public sealed class SingleFontChooserDialog : IDisposable
this.popupImGuiName = $"{this.title}##{nameof(SingleFontChooserDialog)}[{this.counter}]"; this.popupImGuiName = $"{this.title}##{nameof(SingleFontChooserDialog)}[{this.counter}]";
this.atlas = newAsyncAtlas; this.atlas = newAsyncAtlas;
this.selectedFont = new() { FontId = DalamudDefaultFontAndFamilyId.Instance }; this.selectedFont = new() { FontId = DalamudDefaultFontAndFamilyId.Instance };
Encoding.UTF8.GetBytes("Font preview.\n0123456789!", this.fontPreviewText); Encoding.UTF8.GetBytes("Font preview.\n0123456789!\n遍角次亮采之门门上插刀、直字拐弯、天上平板、船顶漏雨。\n다람쥐 헌 쳇바퀴에 타고파", this.fontPreviewText);
} }
/// <summary>Called when the selected font spec has changed.</summary> /// <summary>Called when the selected font spec has changed.</summary>
@ -891,7 +891,21 @@ public sealed class SingleFontChooserDialog : IDisposable
this.selectedFontWeight = font.Weight; this.selectedFontWeight = font.Weight;
this.selectedFontStretch = font.Stretch; this.selectedFontStretch = font.Stretch;
this.selectedFontStyle = font.Style; 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<DalamudConfiguration>.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; return changed;

View file

@ -371,10 +371,7 @@ internal sealed partial class FontAtlasFactory
return this.factory.AddFont( return this.factory.AddFont(
this, this,
asset, asset,
fontConfig with fontConfig);
{
FontNo = 0,
});
} }
} }
@ -562,31 +559,38 @@ internal sealed partial class FontAtlasFactory
return; return;
var dalamudConfiguration = Service<DalamudConfiguration>.Get(); var dalamudConfiguration = Service<DalamudConfiguration>.Get();
if (dalamudConfiguration.EffectiveLanguage == "ko" var ime = Service<DalamudIme>.GetNullable();
|| Service<DalamudIme>.GetNullable()?.EncounteredHangul is true)
string langTag = null;
// fontNo: 0 = japanese, 1 = traditional chinese, 2 = simplified chinese, 3 = korean
int fontNo = 0;
if (dalamudConfiguration.EffectiveLanguage == "tw")
{ {
this.AddDalamudAssetFont( langTag = "zh-hant";
DalamudAsset.NotoSansKrRegular, fontNo = 1;
fontConfig with }
else if (dalamudConfiguration.EffectiveLanguage == "zh" || ime?.EncounteredHan is true)
{ {
MergeFont = targetFont, langTag = "zh-hans";
GlyphRanges = default(FluentGlyphRangeBuilder).WithLanguage("ko-kr").BuildExact(), fontNo = 2;
}); }
else if (dalamudConfiguration.EffectiveLanguage == "ko" || ime?.EncounteredHangul is true)
{
langTag = "ko-kr";
fontNo = 3;
} }
if (Service<DalamudConfiguration>.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 this.AddDalamudAssetFont(
DalamudAsset.NotoSansCJKRegular,
fontConfig with
{ {
GlyphRanges = default(FluentGlyphRangeBuilder).WithLanguage("zh-hant").BuildExact(), FontNo = fontNo,
}); MergeFont = targetFont,
} GlyphRanges = default(FluentGlyphRangeBuilder).WithLanguage(langTag).BuildExact(),
else if (Service<DalamudConfiguration>.Get().EffectiveLanguage == "zh"
|| Service<DalamudIme>.GetNullable()?.EncounteredHan is true)
{
this.AttachWindowsDefaultFont(CultureInfo.GetCultureInfo("zh-hans"), fontConfig with
{
GlyphRanges = default(FluentGlyphRangeBuilder).WithLanguage("zh-hans").BuildExact(),
}); });
} }
} }
@ -629,7 +633,7 @@ internal sealed partial class FontAtlasFactory
if (this.data.ConfigData.Length == 0) if (this.data.ConfigData.Length == 0)
{ {
this.AddDalamudAssetFont( this.AddDalamudAssetFont(
DalamudAsset.NotoSansJpMedium, DalamudAsset.NotoSansCJKRegular,
new() { GlyphRanges = new ushort[] { ' ', ' ', '\0' }, SizePx = 1 }); new() { GlyphRanges = new ushort[] { ' ', ' ', '\0' }, SizePx = 1 });
} }

View file

@ -412,7 +412,7 @@ internal class GamePrebakedFontHandle : FontHandle
private ImFontPtr CreateTemplateFont(IFontAtlasBuildToolkitPreBuild toolkitPreBuild, float sizePx) private ImFontPtr CreateTemplateFont(IFontAtlasBuildToolkitPreBuild toolkitPreBuild, float sizePx)
{ {
var font = toolkitPreBuild.AddDalamudAssetFont( var font = toolkitPreBuild.AddDalamudAssetFont(
DalamudAsset.NotoSansJpMedium, DalamudAsset.NotoSansCJKMedium,
new() new()
{ {
GlyphRanges = new ushort[] { ' ', ' ', '\0' }, GlyphRanges = new ushort[] { ' ', ' ', '\0' },