Fonts: ImFontFlags: ImFontFlags_NoLoadGlyphs + add ImFontFlags_LockBakedSizes

This commit is contained in:
ocornut
2025-02-06 11:57:30 +01:00
parent 8a8d8a7b38
commit dc1320df64
3 changed files with 30 additions and 9 deletions

View File

@@ -2647,7 +2647,7 @@ void ImFontAtlas::ClearInputData()
font->Sources = NULL;
font->SourcesCount = 0;
}
font->LockDisableLoading = true;
font->Flags |= ImFontFlags_NoLoadGlyphs;
}
Sources.clear();
}
@@ -3688,8 +3688,11 @@ void ImFontAtlasBuildDiscardBakes(ImFontAtlas* atlas, int unused_frames)
for (int baked_n = 0; baked_n < builder->BakedPool.Size; baked_n++)
{
ImFontBaked* baked = &builder->BakedPool[baked_n];
if (baked->LastUsedFrame + unused_frames <= atlas->Builder->FrameCount && !baked->WantDestroy)
ImFontAtlasBuildDiscardFontBaked(atlas, baked->ContainerFont, baked);
if (baked->LastUsedFrame + unused_frames > atlas->Builder->FrameCount)
continue;
if (baked->WantDestroy || (baked->ContainerFont->Flags & ImFontFlags_LockBakedSizes))
continue;
ImFontAtlasBuildDiscardFontBaked(atlas, baked->ContainerFont, baked);
}
}
@@ -3816,7 +3819,8 @@ void ImFontAtlasBuildRepackTexture(ImFontAtlas* atlas, int w, int h)
//ImFontAtlasDebugWriteTexToDisk(old_tex, "Before Pack");
// Repack, lose discarded rectangle, copy pixels
// FIXME-NEWATLAS-V2: Repacking in batch would be beneficial to packing heuristic.
// FIXME-NEWATLAS: This is unstable because packing order is based on RectsIndex
// FIXME-NEWATLAS-V2: Repacking in batch would be beneficial to packing heuristic, and fix stability.
// FIXME-NEWATLAS-TESTS: Test calling RepackTexture with size too small to fits existing rects.
ImFontAtlasPackInit(atlas);
ImVector<ImFontAtlasRect> old_rects;
@@ -4172,7 +4176,7 @@ ImFontGlyph* ImFontBaked::BuildLoadGlyph(ImWchar codepoint)
ImFont* font = ContainerFont;
ImFontBaked* baked = this;
ImFontAtlas* atlas = font->ContainerAtlas;
if (font->LockDisableLoading || atlas->Locked)
if (atlas->Locked || (font->Flags & ImFontFlags_NoLoadGlyphs))
return NULL;
//char utf8_buf[5];
@@ -5008,6 +5012,13 @@ ImFontBaked* ImFont::GetFontBaked(float size)
return baked;
}
// FIXME-BAKED: If loading is locked, find closest match
if (Flags & ImFontFlags_LockBakedSizes)
{
IM_ASSERT(LastBaked);
return LastBaked;
}
// FIXME-BAKED: If atlas is locked, find closest match
if (atlas->Locked)
IM_ASSERT(!atlas->Locked && "Cannot use dynamic font size with a locked ImFontAtlas!"); // Locked because rendering backend does not support ImGuiBackendFlags_RendererHasTextures!