Fulfill BuildLookupTable preconditions (#1507)

This commit is contained in:
srkizer 2023-10-29 19:38:31 +09:00 committed by GitHub
parent e5e9622974
commit f60e7b7a86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 3 deletions

View file

@ -169,7 +169,7 @@ internal class GameFontManager : IServiceType
}
if (rebuildLookupTable && fontPtr.Glyphs.Size > 0)
fontPtr.BuildLookupTable();
fontPtr.BuildLookupTableNonstandard();
}
/// <summary>

View file

@ -1028,7 +1028,7 @@ internal class InterfaceManager : IDisposable, IServiceType
if (font.FindGlyphNoFallback(Fallback1Codepoint).NativePtr != null)
font.FallbackChar = Fallback1Codepoint;
font.BuildLookupTable();
font.BuildLookupTableNonstandard();
}
Log.Verbose("[FONT] Invoke OnAfterBuildFonts");

View file

@ -240,7 +240,25 @@ public static class ImGuiHelpers
}
if (rebuildLookupTable && target.Value!.Glyphs.Size > 0)
target.Value!.BuildLookupTable();
target.Value!.BuildLookupTableNonstandard();
}
/// <summary>
/// Call ImFont::BuildLookupTable, after attempting to fulfill some preconditions.
/// </summary>
/// <param name="font">The font.</param>
public static unsafe void BuildLookupTableNonstandard(this ImFontPtr font)
{
// ImGui resolves ' ' with FindGlyph, which uses FallbackGlyph.
// FallbackGlyph is resolved after resolving ' '.
// On the first call of BuildLookupTable, called from BuildFonts, FallbackGlyph is set to null,
// making FindGlyph return nullptr.
// On our secondary calls of BuildLookupTable, FallbackGlyph is set to some value that is not null,
// making ImGui attempt to treat whatever was there as a ' '.
// This may cause random glyphs to be sized randomly, if not an access violation exception.
font.NativePtr->FallbackGlyph = null;
font.BuildLookupTable();
}
/// <summary>