Make italic font chooseable

This commit is contained in:
Infi
2024-07-25 15:19:08 +02:00
parent 9c86ee788f
commit 41c59f6aa0
6 changed files with 90 additions and 22 deletions
+10 -1
View File
@@ -85,7 +85,8 @@ internal class Configuration : IPluginConfiguration
public float SymbolsFontSizeV2 = 12.75f; public float SymbolsFontSizeV2 = 12.75f;
public SingleFontSpec GlobalFontV2 = new() public SingleFontSpec GlobalFontV2 = new()
{ {
FontId = new DalamudAssetFontAndFamilyId(DalamudAsset.NotoSansKrRegular), // dalamud only ships KR as regular, which chat2 used previously for global fonts // dalamud only ships KR as regular, which chat2 used previously for global fonts
FontId = new DalamudAssetFontAndFamilyId(DalamudAsset.NotoSansKrRegular),
SizePt = 12.75f, SizePt = 12.75f,
}; };
public SingleFontSpec JapaneseFontV2 = new() public SingleFontSpec JapaneseFontV2 = new()
@@ -93,6 +94,12 @@ internal class Configuration : IPluginConfiguration
FontId = new DalamudAssetFontAndFamilyId(DalamudAsset.NotoSansJpMedium), FontId = new DalamudAssetFontAndFamilyId(DalamudAsset.NotoSansJpMedium),
SizePt = 12.75f, SizePt = 12.75f,
}; };
public bool ItalicEnabled = false;
public SingleFontSpec ItalicFontV2 = new()
{
FontId = new DalamudAssetFontAndFamilyId(DalamudAsset.NotoSansKrRegular),
SizePt = 12.75f,
};
// TODO Remove after 24.08 // TODO Remove after 24.08
public float FontSize = 17f; public float FontSize = 17f;
@@ -159,10 +166,12 @@ internal class Configuration : IPluginConfiguration
ShowEmotes = other.ShowEmotes; ShowEmotes = other.ShowEmotes;
BlockedEmotes = other.BlockedEmotes; BlockedEmotes = other.BlockedEmotes;
FontsEnabled = other.FontsEnabled; FontsEnabled = other.FontsEnabled;
ItalicEnabled = other.ItalicEnabled;
ExtraGlyphRanges = other.ExtraGlyphRanges; ExtraGlyphRanges = other.ExtraGlyphRanges;
FontSizeV2 = other.FontSizeV2; FontSizeV2 = other.FontSizeV2;
GlobalFontV2 = other.GlobalFontV2; GlobalFontV2 = other.GlobalFontV2;
JapaneseFontV2 = other.JapaneseFontV2; JapaneseFontV2 = other.JapaneseFontV2;
ItalicFontV2 = other.ItalicFontV2;
SymbolsFontSizeV2 = other.SymbolsFontSizeV2; SymbolsFontSizeV2 = other.SymbolsFontSizeV2;
TooltipOffset = other.TooltipOffset; TooltipOffset = other.TooltipOffset;
WindowAlpha = other.WindowAlpha; WindowAlpha = other.WindowAlpha;
+22 -18
View File
@@ -130,27 +130,31 @@ public class FontManager
} }
)); ));
// load italic version if it exists, else default to regular if (Plugin.Config.ItalicEnabled)
ItalicFont = Plugin.Interface.UiBuilder.FontAtlas.NewDelegateFontHandle( {
e => e.OnPreBuild( ItalicFont = Plugin.Interface.UiBuilder.FontAtlas.NewDelegateFontHandle(
tk => e => e.OnPreBuild(
{ tk =>
var italicVersion = Plugin.Config.GlobalFontV2.FontId.Family.Fonts.FirstOrDefault(f => f.EnglishName.Contains("Italic")); {
var config = new SafeFontConfig {SizePt = Plugin.Config.GlobalFontV2.SizePt, GlyphRanges = Ranges};
config.MergeFont = Plugin.Config.ItalicFontV2.FontId.AddToBuildToolkit(tk, config);
var config = new SafeFontConfig {SizePt = Plugin.Config.GlobalFontV2.SizePt, GlyphRanges = Ranges}; config.SizePt = Plugin.Config.JapaneseFontV2.SizePt;
config.MergeFont = italicVersion?.AddToBuildToolkit(tk, config) ?? Plugin.Config.GlobalFontV2.FontId.AddToBuildToolkit(tk, config); config.GlyphRanges = JpRange;
Plugin.Config.JapaneseFontV2.FontId.AddToBuildToolkit(tk, config);
config.SizePt = Plugin.Config.JapaneseFontV2.SizePt; config.SizePt = Plugin.Config.SymbolsFontSizeV2;
config.GlyphRanges = JpRange; config.GlyphRanges = SymRange;
Plugin.Config.JapaneseFontV2.FontId.AddToBuildToolkit(tk, config); tk.AddFontFromMemory(GameSymFont, config, "ChatTwo2 Sym Font");
config.SizePt = Plugin.Config.SymbolsFontSizeV2; tk.Font = config.MergeFont;
config.GlyphRanges = SymRange; }
tk.AddFontFromMemory(GameSymFont, config, "ChatTwo2 Sym Font"); ));
}
tk.Font = config.MergeFont; else
} {
)); ItalicFont = null;
}
} }
public static float SizeInPt(float px) => (float) (px * 3.0 / 4.0); public static float SizeInPt(float px) => (float) (px * 3.0 / 4.0);
+27
View File
@@ -2615,6 +2615,33 @@ namespace ChatTwo.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to If enabled, uses the italic font in {0}, else it will use the ingame italic font..
/// </summary>
internal static string Options_Italic_Description {
get {
return ResourceManager.GetString("Options_Italic_Description", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Use italic font.
/// </summary>
internal static string Options_ItalicEnabled {
get {
return ResourceManager.GetString("Options_ItalicEnabled", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Italic font.
/// </summary>
internal static string Options_ItalicFont_Name {
get {
return ResourceManager.GetString("Options_ItalicFont_Name", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to The font {0} will use to display Japanese text.. /// Looks up a localized string similar to The font {0} will use to display Japanese text..
/// </summary> /// </summary>
+9
View File
@@ -340,6 +340,12 @@
<data name="Options_JapaneseFont_Description"> <data name="Options_JapaneseFont_Description">
<value>The font {0} will use to display Japanese text.</value> <value>The font {0} will use to display Japanese text.</value>
</data> </data>
<data name="Options_ItalicFont_Name">
<value>Italic font</value>
</data>
<data name="Options_Italic_Description">
<value>If enabled, uses the italic font in {0}, else it will use the ingame italic font.</value>
</data>
<data name="Options_Tabs_ChannelTypes_Special"> <data name="Options_Tabs_ChannelTypes_Special">
<value>Special</value> <value>Special</value>
</data> </data>
@@ -523,6 +529,9 @@
<data name="Options_FontsEnabled"> <data name="Options_FontsEnabled">
<value>Enable custom fonts</value> <value>Enable custom fonts</value>
</data> </data>
<data name="Options_ItalicEnabled">
<value>Use italic font</value>
</data>
<data name="AutoTranslate_Search_Hint"> <data name="AutoTranslate_Search_Hint">
<value>Search Auto Translate...</value> <value>Search Auto Translate...</value>
</data> </data>
+15 -2
View File
@@ -31,7 +31,7 @@ public class Fonts : ISettingsTab
} }
else else
{ {
var globalChooser = ImGuiUtil.FontChooser(Language.Options_Font_Name, Mutable.GlobalFontV2); var globalChooser = ImGuiUtil.FontChooser(Language.Options_Font_Name, Mutable.GlobalFontV2, false, ref _);
globalChooser?.ResultTask.ContinueWith(r => globalChooser?.ResultTask.ContinueWith(r =>
{ {
if (r.IsCompletedSuccessfully) if (r.IsCompletedSuccessfully)
@@ -47,7 +47,7 @@ public class Fonts : ISettingsTab
ImGui.Spacing(); ImGui.Spacing();
// LocaleNames being null means it is likely a game font which all support JP symbols // LocaleNames being null means it is likely a game font which all support JP symbols
var japaneseChooser = ImGuiUtil.FontChooser(Language.Options_JapaneseFont_Name, Mutable.JapaneseFontV2, id => !id.LocaleNames?.ContainsKey("ja-jp") ?? false, "いろはにほへと ちりぬるを"); var japaneseChooser = ImGuiUtil.FontChooser(Language.Options_JapaneseFont_Name, Mutable.JapaneseFontV2, false, ref _, id => !id.LocaleNames?.ContainsKey("ja-jp") ?? false, "いろはにほへと ちりぬるを");
japaneseChooser?.ResultTask.ContinueWith(r => japaneseChooser?.ResultTask.ContinueWith(r =>
{ {
if (r.IsCompletedSuccessfully) if (r.IsCompletedSuccessfully)
@@ -61,6 +61,19 @@ public class Fonts : ISettingsTab
ImGuiUtil.HelpText(string.Format(Language.Options_JapaneseFont_Description, Plugin.PluginName)); ImGuiUtil.HelpText(string.Format(Language.Options_JapaneseFont_Description, Plugin.PluginName));
ImGui.Spacing(); ImGui.Spacing();
var italicChooser = ImGuiUtil.FontChooser(Language.Options_ItalicFont_Name, Mutable.ItalicFontV2, true, ref Mutable.ItalicEnabled);
italicChooser?.ResultTask.ContinueWith(r =>
{
if (r.IsCompletedSuccessfully)
Mutable.ItalicFontV2 = r.Result;
});
ImGui.SameLine();
if (ImGui.Button("Reset##italic"))
Mutable.ItalicFontV2 = new SingleFontSpec{ FontId = new DalamudAssetFontAndFamilyId(DalamudAsset.NotoSansKrRegular), SizePt = 12.75f };
ImGuiUtil.HelpText(string.Format(Language.Options_Italic_Description, Plugin.PluginName));
ImGui.Spacing();
if (ImGui.CollapsingHeader(Language.Options_ExtraGlyphs_Name)) if (ImGui.CollapsingHeader(Language.Options_ExtraGlyphs_Name))
{ {
ImGuiUtil.HelpText(string.Format(Language.Options_ExtraGlyphs_Description, Plugin.PluginName)); ImGuiUtil.HelpText(string.Format(Language.Options_ExtraGlyphs_Description, Plugin.PluginName));
+7 -1
View File
@@ -268,11 +268,17 @@ internal static class ImGuiUtil
return r; return r;
} }
public static SingleFontChooserDialog? FontChooser(string label, SingleFontSpec font, Predicate<IFontFamilyId>? exclusion = null, string? preview = null) public static SingleFontChooserDialog? FontChooser(string label, SingleFontSpec font, bool checkbox, ref bool checkboxValue, Predicate<IFontFamilyId>? exclusion = null, string? preview = null)
{ {
using var id = ImRaii.PushId(label); using var id = ImRaii.PushId(label);
ImGui.TextUnformatted(label); ImGui.TextUnformatted(label);
if (checkbox)
{
ImGui.Checkbox("##enabled", ref checkboxValue);
ImGui.SameLine();
}
var fontFamily = font.FontId.Family.EnglishName; var fontFamily = font.FontId.Family.EnglishName;
var fontStyle = font.FontId.EnglishName; var fontStyle = font.FontId.EnglishName;
fontStyle = fontStyle.Equals(fontFamily) ? "" : $" - {fontStyle}"; fontStyle = fontStyle.Equals(fontFamily) ? "" : $" - {fontStyle}";