diff --git a/Dalamud/Interface/GameFonts/GameFontManager.cs b/Dalamud/Interface/GameFonts/GameFontManager.cs
index ad0e47273..3a1ab737e 100644
--- a/Dalamud/Interface/GameFonts/GameFontManager.cs
+++ b/Dalamud/Interface/GameFonts/GameFontManager.cs
@@ -171,6 +171,42 @@ internal class GameFontManager : IServiceType
fontPtr.BuildLookupTable();
}
+ ///
+ /// Create a glyph range for use with ImGui AddFont.
+ ///
+ /// Font family and size.
+ /// Merge two ranges into one if distance is below the value specified in this parameter.
+ /// Glyph ranges.
+ public GCHandle ToGlyphRanges(GameFontFamilyAndSize family, int mergeDistance = 8)
+ {
+ var fdt = this.fdts[(int)family]!;
+ var ranges = new List(fdt.Glyphs.Count)
+ {
+ checked((ushort)fdt.Glyphs[0].CharInt),
+ checked((ushort)fdt.Glyphs[0].CharInt),
+ };
+
+ foreach (var glyph in fdt.Glyphs.Skip(1))
+ {
+ var c32 = glyph.CharInt;
+ if (c32 >= 0x10000)
+ break;
+
+ var c16 = unchecked((ushort)c32);
+ if (ranges[^1] + mergeDistance >= c16 && c16 > ranges[^1])
+ {
+ ranges[^1] = c16;
+ }
+ else if (ranges[^1] + 1 < c16)
+ {
+ ranges.Add(c16);
+ ranges.Add(c16);
+ }
+ }
+
+ return GCHandle.Alloc(ranges.ToArray(), GCHandleType.Pinned);
+ }
+
///
/// Creates a new GameFontHandle, and increases internal font reference counter, and if it's first time use, then the font will be loaded on next font building process.
///
diff --git a/Dalamud/Interface/Internal/InterfaceManager.cs b/Dalamud/Interface/Internal/InterfaceManager.cs
index f46c7272d..1e1c25324 100644
--- a/Dalamud/Interface/Internal/InterfaceManager.cs
+++ b/Dalamud/Interface/Internal/InterfaceManager.cs
@@ -790,10 +790,10 @@ internal class InterfaceManager : IDisposable, IServiceType
}
else
{
- var japaneseRangeHandle = GCHandle.Alloc(GlyphRangesJapanese.GlyphRanges, GCHandleType.Pinned);
- garbageList.Add(japaneseRangeHandle);
+ var rangeHandle = gameFontManager.ToGlyphRanges(GameFontFamilyAndSize.Axis12);
+ garbageList.Add(rangeHandle);
- fontConfig.GlyphRanges = japaneseRangeHandle.AddrOfPinnedObject();
+ fontConfig.GlyphRanges = rangeHandle.AddrOfPinnedObject();
fontConfig.PixelSnapH = true;
DefaultFont = ioFonts.AddFontFromFileTTF(fontPathJp, fontConfig.SizePixels, fontConfig);
this.loadedFontInfo[DefaultFont] = fontInfo;
@@ -850,22 +850,19 @@ internal class InterfaceManager : IDisposable, IServiceType
foreach (var (fontSize, requests) in extraFontRequests)
{
- List> codepointRanges = new();
- codepointRanges.Add(Tuple.Create(Fallback1Codepoint, Fallback1Codepoint));
- codepointRanges.Add(Tuple.Create(Fallback2Codepoint, Fallback2Codepoint));
-
- // ImGui default ellipsis characters
- codepointRanges.Add(Tuple.Create(0x2026, 0x2026));
- codepointRanges.Add(Tuple.Create(0x0085, 0x0085));
+ List<(ushort, ushort)> codepointRanges = new(4 + requests.Sum(x => x.CodepointRanges.Count))
+ {
+ new(Fallback1Codepoint, Fallback1Codepoint),
+ new(Fallback2Codepoint, Fallback2Codepoint),
+ // ImGui default ellipsis characters
+ new(0x2026, 0x2026),
+ new(0x0085, 0x0085),
+ };
foreach (var request in requests)
- {
- foreach (var range in request.CodepointRanges)
- codepointRanges.Add(range);
- }
-
- codepointRanges.Sort((x, y) => (x.Item1 == y.Item1 ? (x.Item2 < y.Item2 ? -1 : (x.Item2 == y.Item2 ? 0 : 1)) : (x.Item1 < y.Item1 ? -1 : 1)));
+ codepointRanges.AddRange(request.CodepointRanges.Select(x => (From: x.Item1, To: x.Item2)));
+ codepointRanges.Sort();
List flattenedRanges = new();
foreach (var range in codepointRanges)
{