feat: add japanese system fonts

This commit is contained in:
Anna 2022-02-05 19:36:56 -05:00
parent 2ef42aa211
commit b8d4f67f27
3 changed files with 38 additions and 25 deletions

View File

@ -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;

View File

@ -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<string> GetJpFonts() {
var fonts = new List<string>();
// 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;
}

View File

@ -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();
}