Fix CreateImGuiRangesFrom to omit null char (#1709)

* Fix CreateImGuiRangesFrom to omit null char

UnicodeRanges.BasicLatin is [0, 127], but ImGui stops reading the glyph
range list on encountering a zero. Fixed that by ensuring that 0 never
appears in the glyph range list.

* Make problems explicit

---------

Co-authored-by: goat <16760685+goaaats@users.noreply.github.com>
This commit is contained in:
srkizer 2024-03-17 01:02:36 +09:00 committed by GitHub
parent 87b9edb448
commit e52c2755cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 51 additions and 9 deletions

View file

@ -35,6 +35,9 @@ internal sealed partial class FontAtlasFactory
/// </summary>
public const string EllipsisCodepoints = "\u2026\u0085";
/// <summary>Marker for tasks on whether it's being called inside a font build cycle.</summary>
public static readonly AsyncLocal<bool> IsBuildInProgressForTask = new();
/// <summary>
/// If set, disables concurrent font build operation.
/// </summary>
@ -427,11 +430,28 @@ internal sealed partial class FontAtlasFactory
}
/// <inheritdoc/>
public IFontHandle NewGameFontHandle(GameFontStyle style) => this.gameFontHandleManager.NewFontHandle(style);
public IFontHandle NewGameFontHandle(GameFontStyle style)
{
if (IsBuildInProgressForTask.Value)
{
throw new InvalidOperationException(
$"{nameof(this.NewGameFontHandle)} may not be called during {nameof(this.BuildStepChange)}, the callback of {nameof(this.NewDelegateFontHandle)}, {nameof(UiBuilder.BuildFonts)} or {nameof(UiBuilder.AfterBuildFonts)}.");
}
return this.gameFontHandleManager.NewFontHandle(style);
}
/// <inheritdoc/>
public IFontHandle NewDelegateFontHandle(FontAtlasBuildStepDelegate buildStepDelegate) =>
this.delegateFontHandleManager.NewFontHandle(buildStepDelegate);
public IFontHandle NewDelegateFontHandle(FontAtlasBuildStepDelegate buildStepDelegate)
{
if (IsBuildInProgressForTask.Value)
{
throw new InvalidOperationException(
$"{nameof(this.NewDelegateFontHandle)} may not be called during {nameof(this.BuildStepChange)} or the callback of {nameof(this.NewDelegateFontHandle)}, {nameof(UiBuilder.BuildFonts)} or {nameof(UiBuilder.AfterBuildFonts)}.");
}
return this.delegateFontHandleManager.NewFontHandle(buildStepDelegate);
}
/// <inheritdoc/>
public void BuildFontsOnNextFrame()
@ -630,6 +650,8 @@ internal sealed partial class FontAtlasFactory
FontAtlasBuiltData? res = null;
nint atlasPtr = 0;
BuildToolkit? toolkit = null;
IsBuildInProgressForTask.Value = true;
try
{
res = new(this, scale);
@ -754,6 +776,7 @@ internal sealed partial class FontAtlasFactory
// ReSharper disable once ConstantConditionalAccessQualifier
toolkit?.Dispose();
this.buildQueued = false;
IsBuildInProgressForTask.Value = false;
}
unsafe bool ValidateMergeFontReferences(ImFontPtr replacementDstFont)