mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Don't oversample fonts, and use geta mark to indicate unavailable glyph
(cherry picked from commit e22b168c53)
This commit is contained in:
parent
b2ff63a4cc
commit
1f20b3c35a
2 changed files with 63 additions and 31 deletions
|
|
@ -284,39 +284,49 @@ namespace Dalamud.Interface.GameFonts
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void BuildFonts()
|
public void BuildFonts()
|
||||||
{
|
{
|
||||||
var io = ImGui.GetIO();
|
unsafe
|
||||||
io.Fonts.TexDesiredWidth = 4096;
|
|
||||||
|
|
||||||
this.glyphRectIds.Clear();
|
|
||||||
this.fonts.Clear();
|
|
||||||
|
|
||||||
foreach (var style in this.fontUseCounter.Keys)
|
|
||||||
{
|
{
|
||||||
var rectIds = this.glyphRectIds[style] = new();
|
ImFontConfigPtr fontConfig = ImGuiNative.ImFontConfig_ImFontConfig();
|
||||||
|
fontConfig.OversampleH = 1;
|
||||||
|
fontConfig.OversampleV = 1;
|
||||||
|
fontConfig.PixelSnapH = true;
|
||||||
|
|
||||||
var fdt = this.fdts[(int)style.FamilyAndSize];
|
var io = ImGui.GetIO();
|
||||||
if (fdt == null)
|
io.Fonts.TexDesiredWidth = 4096;
|
||||||
continue;
|
|
||||||
|
|
||||||
var font = io.Fonts.AddFontDefault();
|
this.glyphRectIds.Clear();
|
||||||
this.fonts[style] = font;
|
this.fonts.Clear();
|
||||||
foreach (var glyph in fdt.Glyphs)
|
|
||||||
|
foreach (var style in this.fontUseCounter.Keys)
|
||||||
{
|
{
|
||||||
var c = glyph.Char;
|
var rectIds = this.glyphRectIds[style] = new();
|
||||||
if (c < 32 || c >= 0xFFFF)
|
|
||||||
|
var fdt = this.fdts[(int)style.FamilyAndSize];
|
||||||
|
if (fdt == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var widthAdjustment = style.CalculateWidthAdjustment(fdt, glyph);
|
var font = io.Fonts.AddFontDefault(fontConfig);
|
||||||
rectIds[c] = Tuple.Create(
|
this.fonts[style] = font;
|
||||||
io.Fonts.AddCustomRectFontGlyph(
|
foreach (var glyph in fdt.Glyphs)
|
||||||
font,
|
{
|
||||||
c,
|
var c = glyph.Char;
|
||||||
glyph.BoundingWidth + widthAdjustment + 1,
|
if (c < 32 || c >= 0xFFFF)
|
||||||
glyph.BoundingHeight + 1,
|
continue;
|
||||||
glyph.AdvanceWidth,
|
|
||||||
new Vector2(0, glyph.CurrentOffsetY)),
|
var widthAdjustment = style.CalculateWidthAdjustment(fdt, glyph);
|
||||||
glyph);
|
rectIds[c] = Tuple.Create(
|
||||||
|
io.Fonts.AddCustomRectFontGlyph(
|
||||||
|
font,
|
||||||
|
c,
|
||||||
|
glyph.BoundingWidth + widthAdjustment + 1,
|
||||||
|
glyph.BoundingHeight + 1,
|
||||||
|
glyph.AdvanceWidth,
|
||||||
|
new Vector2(0, glyph.CurrentOffsetY)),
|
||||||
|
glyph);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fontConfig.Destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,8 @@ namespace Dalamud.Interface.Internal
|
||||||
{
|
{
|
||||||
private const float DefaultFontSizePt = 12.0f;
|
private const float DefaultFontSizePt = 12.0f;
|
||||||
private const float DefaultFontSizePx = DefaultFontSizePt * 4.0f / 3.0f;
|
private const float DefaultFontSizePx = DefaultFontSizePt * 4.0f / 3.0f;
|
||||||
|
private const ushort Fallback1Codepoint = 0x3013; // Geta mark; FFXIV uses this to indicate that a glyph is missing.
|
||||||
|
private const ushort Fallback2Codepoint = '-'; // FFXIV uses dash if Geta mark is unavailable.
|
||||||
|
|
||||||
private readonly string rtssPath;
|
private readonly string rtssPath;
|
||||||
|
|
||||||
|
|
@ -603,6 +605,11 @@ namespace Dalamud.Interface.Internal
|
||||||
this.fontBuildSignal.Reset();
|
this.fontBuildSignal.Reset();
|
||||||
ioFonts.Clear();
|
ioFonts.Clear();
|
||||||
|
|
||||||
|
ImFontConfigPtr fontConfig = ImGuiNative.ImFontConfig_ImFontConfig();
|
||||||
|
fontConfig.OversampleH = 1;
|
||||||
|
fontConfig.OversampleV = 1;
|
||||||
|
fontConfig.PixelSnapH = true;
|
||||||
|
|
||||||
var fontPathJp = Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "NotoSansCJKjp-Medium.otf");
|
var fontPathJp = Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "NotoSansCJKjp-Medium.otf");
|
||||||
if (!File.Exists(fontPathJp))
|
if (!File.Exists(fontPathJp))
|
||||||
ShowFontError(fontPathJp);
|
ShowFontError(fontPathJp);
|
||||||
|
|
@ -610,7 +617,7 @@ namespace Dalamud.Interface.Internal
|
||||||
// Default font
|
// Default font
|
||||||
{
|
{
|
||||||
var japaneseRangeHandle = GCHandle.Alloc(GlyphRangesJapanese.GlyphRanges, GCHandleType.Pinned);
|
var japaneseRangeHandle = GCHandle.Alloc(GlyphRangesJapanese.GlyphRanges, GCHandleType.Pinned);
|
||||||
DefaultFont = ioFonts.AddFontFromFileTTF(fontPathJp, (DefaultFontSizePx + 1) * fontScale, null, japaneseRangeHandle.AddrOfPinnedObject());
|
DefaultFont = ioFonts.AddFontFromFileTTF(fontPathJp, (DefaultFontSizePx + 1) * fontScale, fontConfig, japaneseRangeHandle.AddrOfPinnedObject());
|
||||||
japaneseRangeHandle.Free();
|
japaneseRangeHandle.Free();
|
||||||
fontsToUnscale.Add(DefaultFont);
|
fontsToUnscale.Add(DefaultFont);
|
||||||
}
|
}
|
||||||
|
|
@ -622,7 +629,7 @@ namespace Dalamud.Interface.Internal
|
||||||
ShowFontError(fontPathIcon);
|
ShowFontError(fontPathIcon);
|
||||||
|
|
||||||
var iconRangeHandle = GCHandle.Alloc(new ushort[] { 0xE000, 0xF8FF, 0, }, GCHandleType.Pinned);
|
var iconRangeHandle = GCHandle.Alloc(new ushort[] { 0xE000, 0xF8FF, 0, }, GCHandleType.Pinned);
|
||||||
IconFont = ioFonts.AddFontFromFileTTF(fontPathIcon, DefaultFontSizePx * fontScale, null, iconRangeHandle.AddrOfPinnedObject());
|
IconFont = ioFonts.AddFontFromFileTTF(fontPathIcon, DefaultFontSizePx * fontScale, fontConfig, iconRangeHandle.AddrOfPinnedObject());
|
||||||
iconRangeHandle.Free();
|
iconRangeHandle.Free();
|
||||||
fontsToUnscale.Add(IconFont);
|
fontsToUnscale.Add(IconFont);
|
||||||
}
|
}
|
||||||
|
|
@ -632,7 +639,7 @@ namespace Dalamud.Interface.Internal
|
||||||
var fontPathMono = Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "Inconsolata-Regular.ttf");
|
var fontPathMono = Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "Inconsolata-Regular.ttf");
|
||||||
if (!File.Exists(fontPathMono))
|
if (!File.Exists(fontPathMono))
|
||||||
ShowFontError(fontPathMono);
|
ShowFontError(fontPathMono);
|
||||||
MonoFont = ioFonts.AddFontFromFileTTF(fontPathMono, DefaultFontSizePx * fontScale);
|
MonoFont = ioFonts.AddFontFromFileTTF(fontPathMono, DefaultFontSizePx * fontScale, fontConfig);
|
||||||
fontsToUnscale.Add(MonoFont);
|
fontsToUnscale.Add(MonoFont);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -649,6 +656,9 @@ namespace Dalamud.Interface.Internal
|
||||||
foreach (var (fontSize, requests) in extraFontRequests)
|
foreach (var (fontSize, requests) in extraFontRequests)
|
||||||
{
|
{
|
||||||
List<Tuple<ushort, ushort>> codepointRanges = new();
|
List<Tuple<ushort, ushort>> codepointRanges = new();
|
||||||
|
codepointRanges.Add(Tuple.Create(Fallback1Codepoint, Fallback1Codepoint));
|
||||||
|
codepointRanges.Add(Tuple.Create(Fallback2Codepoint, Fallback2Codepoint));
|
||||||
|
|
||||||
foreach (var request in requests)
|
foreach (var request in requests)
|
||||||
{
|
{
|
||||||
foreach (var range in request.CodepointRanges)
|
foreach (var range in request.CodepointRanges)
|
||||||
|
|
@ -674,7 +684,7 @@ namespace Dalamud.Interface.Internal
|
||||||
flattenedRanges.Add(0);
|
flattenedRanges.Add(0);
|
||||||
|
|
||||||
var rangeHandle = GCHandle.Alloc(flattenedRanges.ToArray(), GCHandleType.Pinned);
|
var rangeHandle = GCHandle.Alloc(flattenedRanges.ToArray(), GCHandleType.Pinned);
|
||||||
var sizedFont = ioFonts.AddFontFromFileTTF(fontPathJp, fontSize * fontScale, null, rangeHandle.AddrOfPinnedObject());
|
var sizedFont = ioFonts.AddFontFromFileTTF(fontPathJp, fontSize * fontScale, fontConfig, rangeHandle.AddrOfPinnedObject());
|
||||||
rangeHandle.Free();
|
rangeHandle.Free();
|
||||||
|
|
||||||
fontsToUnscale.Add(sizedFont);
|
fontsToUnscale.Add(sizedFont);
|
||||||
|
|
@ -713,7 +723,12 @@ namespace Dalamud.Interface.Internal
|
||||||
|
|
||||||
foreach (var font in fontsToUnscale)
|
foreach (var font in fontsToUnscale)
|
||||||
{
|
{
|
||||||
if (font.NativePtr == MonoFont.NativePtr || font.NativePtr == IconFont.NativePtr)
|
// Leave IconFont alone.
|
||||||
|
if (font.NativePtr == IconFont.NativePtr)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// MonoFont will be filled later from DefaultFont.
|
||||||
|
if (font.NativePtr == MonoFont.NativePtr)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (this.overwriteAllNotoGlyphsWithAxis)
|
if (this.overwriteAllNotoGlyphsWithAxis)
|
||||||
|
|
@ -722,11 +737,17 @@ namespace Dalamud.Interface.Internal
|
||||||
GameFontManager.CopyGlyphsAcrossFonts(this.axisFontHandle?.ImFont, font, false, false, 0xE020, 0xE0DB);
|
GameFontManager.CopyGlyphsAcrossFonts(this.axisFontHandle?.ImFont, font, false, false, 0xE020, 0xE0DB);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fill missing glyphs in DefaultFont from Axis
|
||||||
|
GameFontManager.CopyGlyphsAcrossFonts(this.axisFontHandle?.ImFont, DefaultFont, true, false);
|
||||||
|
|
||||||
// Fill missing glyphs in MonoFont from DefaultFont
|
// Fill missing glyphs in MonoFont from DefaultFont
|
||||||
GameFontManager.CopyGlyphsAcrossFonts(DefaultFont, MonoFont, true, false);
|
GameFontManager.CopyGlyphsAcrossFonts(DefaultFont, MonoFont, true, false);
|
||||||
|
|
||||||
foreach (var font in fontsToUnscale)
|
foreach (var font in fontsToUnscale)
|
||||||
|
{
|
||||||
|
font.FallbackChar = Fallback1Codepoint;
|
||||||
font.BuildLookupTable();
|
font.BuildLookupTable();
|
||||||
|
}
|
||||||
|
|
||||||
Log.Verbose("[FONT] Invoke OnAfterBuildFonts");
|
Log.Verbose("[FONT] Invoke OnAfterBuildFonts");
|
||||||
this.AfterBuildFonts?.Invoke();
|
this.AfterBuildFonts?.Invoke();
|
||||||
|
|
@ -734,6 +755,7 @@ namespace Dalamud.Interface.Internal
|
||||||
|
|
||||||
Log.Verbose("[FONT] Fonts built!");
|
Log.Verbose("[FONT] Fonts built!");
|
||||||
|
|
||||||
|
fontConfig.Destroy();
|
||||||
this.fontBuildSignal.Set();
|
this.fontBuildSignal.Set();
|
||||||
|
|
||||||
this.FontsReady = true;
|
this.FontsReady = true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue