From bfd48084c134c00d9242ca81731adc6fa063ff27 Mon Sep 17 00:00:00 2001 From: Anna Clemens Date: Sat, 5 Feb 2022 19:36:56 -0500 Subject: [PATCH] feat: add japanese system fonts --- ChatTwo/PluginUi.cs | 6 ++---- ChatTwo/Ui/Fonts.cs | 35 +++++++++++++++++++++++--------- ChatTwo/Ui/SettingsTabs/Fonts.cs | 22 ++++++++++---------- 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/ChatTwo/PluginUi.cs b/ChatTwo/PluginUi.cs index dc13fca..401c2d5 100755 --- a/ChatTwo/PluginUi.cs +++ b/ChatTwo/PluginUi.cs @@ -168,11 +168,9 @@ internal sealed class PluginUi : IDisposable { null ); } + } else { + jpFontData = Fonts.GetFont(this.Plugin.Config.JapaneseFont, false); } - // else { - // jpFontData = Fonts.GetFont(this.Plugin.Config.JapaneseFont, false, CharacterSet.SHIFTJIS_CHARSET); - // PluginLog.Log($"data.Regular.Length: {jpFontData?.Regular.Length}"); - // } if (jpFontData == null) { this.Plugin.Config.JapaneseFont = Fonts.JapaneseFonts[0].Item1; diff --git a/ChatTwo/Ui/Fonts.cs b/ChatTwo/Ui/Fonts.cs index 1ca5419..bdbd670 100755 --- a/ChatTwo/Ui/Fonts.cs +++ b/ChatTwo/Ui/Fonts.cs @@ -45,7 +45,7 @@ internal static class Fonts { var anyItalic = false; for (var j = 0; j < family.FontCount; j++) { using var font = family.GetFont(j); - if (font.Style is not (FontStyle.Italic or FontStyle.Oblique)) { + if (font.IsSymbolFont || font.Style is not (FontStyle.Italic or FontStyle.Oblique)) { continue; } @@ -67,16 +67,31 @@ internal static class Fonts { internal static List GetJpFonts() { var fonts = new List(); - // using var g = Graphics.FromImage(new Bitmap(1, 1)); - // foreach (var (lpelfe, _, fontType) in Gdi32.EnumFontFamiliesEx(g.GetHdc(), CharacterSet.SHIFTJIS_CHARSET)) { - // var name = lpelfe.elfEnumLogfontEx.elfLogFont.lfFaceName; - // if (name.StartsWith("@")) { - // continue; - // } - // - // fonts.Add(name); - // } + using var factory = new Factory(); + using var collection = factory.GetSystemFontCollection(false); + for (var i = 0; i < collection.FontFamilyCount; i++) { + using var family = collection.GetFontFamily(i); + var probablyJp = false; + for (var j = 0; j < family.FontCount; j++) { + using var font = family.GetFont(j); + if (!font.HasCharacter('日') || font.IsSymbolFont) { + continue; + } + + probablyJp = true; + break; + } + + if (!probablyJp) { + continue; + } + + var name = family.FamilyNames.GetString(0); + fonts.Add(name); + } + + fonts.Sort(); return fonts; } diff --git a/ChatTwo/Ui/SettingsTabs/Fonts.cs b/ChatTwo/Ui/SettingsTabs/Fonts.cs index 48067c8..22194f6 100755 --- a/ChatTwo/Ui/SettingsTabs/Fonts.cs +++ b/ChatTwo/Ui/SettingsTabs/Fonts.cs @@ -69,17 +69,17 @@ public class Fonts : ISettingsTab { } } - // ImGui.Separator(); - // - // foreach (var family in this.JpFonts) { - // if (ImGui.Selectable(family, this.Mutable.JapaneseFont == family)) { - // this.Mutable.JapaneseFont = family; - // } - // - // if (ImGui.IsWindowAppearing() && this.Mutable.JapaneseFont == family) { - // ImGui.SetScrollHereY(0.5f); - // } - // } + ImGui.Separator(); + + foreach (var family in this.JpFonts) { + if (ImGui.Selectable(family, this.Mutable.JapaneseFont == family)) { + this.Mutable.JapaneseFont = family; + } + + if (ImGui.IsWindowAppearing() && this.Mutable.JapaneseFont == family) { + ImGui.SetScrollHereY(0.5f); + } + } ImGui.EndCombo(); }