feat: add support for lots of different glyph ranges

This commit is contained in:
Anna 2022-06-01 17:14:32 -04:00
parent bae9ce458a
commit b3ae2dbc1a
3 changed files with 54 additions and 6 deletions

View File

@ -3,6 +3,7 @@ using ChatTwo.Resources;
using ChatTwo.Ui; using ChatTwo.Ui;
using Dalamud.Configuration; using Dalamud.Configuration;
using Dalamud.Logging; using Dalamud.Logging;
using ImGuiNET;
namespace ChatTwo; namespace ChatTwo;
@ -36,7 +37,7 @@ internal class Configuration : IPluginConfiguration {
public bool SortAutoTranslate; public bool SortAutoTranslate;
public bool FontsEnabled = true; public bool FontsEnabled = true;
public bool EnableChineseRange; public ExtraGlyphRanges ExtraGlyphRanges = 0;
public float FontSize = 17f; public float FontSize = 17f;
public float JapaneseFontSize = 17f; public float JapaneseFontSize = 17f;
public float SymbolsFontSize = 17f; public float SymbolsFontSize = 17f;
@ -71,7 +72,7 @@ internal class Configuration : IPluginConfiguration {
this.SharedMode = other.SharedMode; this.SharedMode = other.SharedMode;
this.SortAutoTranslate = other.SortAutoTranslate; this.SortAutoTranslate = other.SortAutoTranslate;
this.FontsEnabled = other.FontsEnabled; this.FontsEnabled = other.FontsEnabled;
this.EnableChineseRange = other.EnableChineseRange; this.ExtraGlyphRanges = other.ExtraGlyphRanges;
this.FontSize = other.FontSize; this.FontSize = other.FontSize;
this.JapaneseFontSize = other.JapaneseFontSize; this.JapaneseFontSize = other.JapaneseFontSize;
this.SymbolsFontSize = other.SymbolsFontSize; this.SymbolsFontSize = other.SymbolsFontSize;
@ -306,3 +307,39 @@ internal static class LanguageOverrideExt {
_ => throw new ArgumentOutOfRangeException(nameof(mode), mode, null), _ => throw new ArgumentOutOfRangeException(nameof(mode), mode, null),
}; };
} }
[Serializable]
[Flags]
internal enum ExtraGlyphRanges {
ChineseFull = 1 << 0,
ChineseSimplifiedCommon = 1 << 1,
Cyrillic = 1 << 2,
Japanese = 1 << 3,
Korean = 1 << 4,
Thai = 1 << 5,
Vietnamese = 1 << 6,
}
internal static class ExtraGlyphRangesExt {
internal static string Name(this ExtraGlyphRanges ranges) => ranges switch {
ExtraGlyphRanges.ChineseFull => "Chinese (full)",
ExtraGlyphRanges.ChineseSimplifiedCommon => "Chinese (common simplified)",
ExtraGlyphRanges.Cyrillic => "Cyrillic",
ExtraGlyphRanges.Japanese => "Japanese",
ExtraGlyphRanges.Korean => "Korean",
ExtraGlyphRanges.Thai => "Thai",
ExtraGlyphRanges.Vietnamese => "Vietnamese",
_ => throw new ArgumentOutOfRangeException(nameof(ranges), ranges, null),
};
internal static IntPtr Range(this ExtraGlyphRanges ranges) => ranges switch {
ExtraGlyphRanges.ChineseFull => ImGui.GetIO().Fonts.GetGlyphRangesChineseFull(),
ExtraGlyphRanges.ChineseSimplifiedCommon => ImGui.GetIO().Fonts.GetGlyphRangesChineseSimplifiedCommon(),
ExtraGlyphRanges.Cyrillic => ImGui.GetIO().Fonts.GetGlyphRangesCyrillic(),
ExtraGlyphRanges.Japanese => ImGui.GetIO().Fonts.GetGlyphRangesJapanese(),
ExtraGlyphRanges.Korean => ImGui.GetIO().Fonts.GetGlyphRangesKorean(),
ExtraGlyphRanges.Thai => ImGui.GetIO().Fonts.GetGlyphRangesThai(),
ExtraGlyphRanges.Vietnamese => ImGui.GetIO().Fonts.GetGlyphRangesVietnamese(),
_ => throw new ArgumentOutOfRangeException(nameof(ranges), ranges, null),
};
}

View File

@ -116,8 +116,10 @@ internal sealed class PluginUi : IDisposable {
ImGui.GetIO().Fonts.GetGlyphRangesDefault(), ImGui.GetIO().Fonts.GetGlyphRangesDefault(),
}; };
if (this.Plugin.Config.EnableChineseRange) { foreach (var extraRange in Enum.GetValues<ExtraGlyphRanges>()) {
ranges.Add(ImGui.GetIO().Fonts.GetGlyphRangesChineseFull()); if (this.Plugin.Config.ExtraGlyphRanges.HasFlag(extraRange)) {
ranges.Add(extraRange.Range());
}
} }
BuildRange(out this._ranges, null, ranges.ToArray()); BuildRange(out this._ranges, null, ranges.ToArray());

View File

@ -91,8 +91,17 @@ 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();
ImGui.Checkbox(Language.Options_EnableChineseRange_Name, ref this.Mutable.EnableChineseRange); if (ImGui.CollapsingHeader("Extra font glyphs")) {
ImGuiUtil.HelpText(Language.Options_EnableChineseRange_Description); ImGuiUtil.HelpText("Extra glyphs can be added to {0}'s font global font by enabling the checkboxes below. This will likely require increasing Dalamud's font atlas size.");
var range = (int) this.Mutable.ExtraGlyphRanges;
foreach (var extra in Enum.GetValues<ExtraGlyphRanges>()) {
ImGui.CheckboxFlags(extra.Name(), ref range, (int) extra);
}
this.Mutable.ExtraGlyphRanges = (ExtraGlyphRanges) range;
}
ImGui.Spacing(); ImGui.Spacing();
} }