mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
feat: Refactor CJK font resources into a TTC collection and add support for multi-language switching.
This commit is contained in:
parent
a39763f161
commit
e6a9dcd740
7 changed files with 70 additions and 39 deletions
|
|
@ -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.
|
||||||
|
|
|
||||||
|
|
@ -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),
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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>
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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' },
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue