Skip to content

Commit 33e5db4

Browse files
committed
WIP - Fonts: tidying up.
1 parent 9088339 commit 33e5db4

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

imgui_draw.cpp

+9-13
Original file line numberDiff line numberDiff line change
@@ -2659,17 +2659,14 @@ void ImFontAtlas::ClearInputData()
26592659
const ImFontLoader* loader = font_cfg.FontLoader ? font_cfg.FontLoader : FontLoader;
26602660
if (loader && loader->FontSrcDestroy != NULL)
26612661
loader->FontSrcDestroy(this, &font_cfg);
2662-
ImFontAtlasBuildDiscardFontSource(this, &font_cfg);
2662+
ImFontAtlasBuildDestroyFontSourceData(this, &font_cfg);
26632663
}
26642664

2665-
// When clearing this we lose access to the font name and other information used to build the font.
26662665
for (ImFont* font : Fonts)
26672666
{
2668-
if (font->Sources >= Sources.Data && font->Sources < Sources.Data + Sources.Size)
2669-
{
2670-
font->Sources = NULL;
2671-
font->SourcesCount = 0;
2672-
}
2667+
// When clearing this we lose access to the font name and other information used to build the font.
2668+
font->Sources = NULL;
2669+
font->SourcesCount = 0;
26732670
font->Flags |= ImFontFlags_NoLoadGlyphs;
26742671
}
26752672
Sources.clear();
@@ -2984,14 +2981,14 @@ bool ImFontAtlas::Build()
29842981
}
29852982
#endif // #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
29862983

2987-
void ImFontAtlasBuildDiscardFontSource(ImFontAtlas* atlas, ImFontConfig* src)
2984+
void ImFontAtlasBuildDestroyFontSourceData(ImFontAtlas* atlas, ImFontConfig* src)
29882985
{
29892986
IM_UNUSED(atlas);
29902987
if (src->FontDataOwnedByAtlas)
29912988
IM_FREE(src->FontData);
2989+
src->FontData = NULL;
29922990
if (src->GlyphExcludeRanges)
29932991
IM_FREE((void*)src->GlyphExcludeRanges);
2994-
src->FontData = NULL;
29952992
src->GlyphExcludeRanges = NULL;
29962993
}
29972994

@@ -3054,7 +3051,7 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg)
30543051
if (!ImFontAtlasBuildAddFont(this, &new_font_cfg))
30553052
{
30563053
// Rollback (this is a fragile/rarely exercised code-path. TestSuite's "misc_atlas_add_invalid_font" aim to test this)
3057-
ImFontAtlasBuildDiscardFontSource(this, &new_font_cfg);
3054+
ImFontAtlasBuildDestroyFontSourceData(this, &new_font_cfg);
30583055
Sources.pop_back();
30593056
if (!font_cfg->MergeMode)
30603057
{
@@ -3599,9 +3596,8 @@ bool ImFontAtlasBuildAddFont(ImFontAtlas* atlas, ImFontConfig* src)
35993596
}
36003597

36013598
const ImFontLoader* loader = src->FontLoader ? src->FontLoader : atlas->FontLoader;
3602-
if (loader->FontSrcInit != NULL)
3603-
if (!loader->FontSrcInit(atlas, src))
3604-
return false;
3599+
if (loader->FontSrcInit != NULL && !loader->FontSrcInit(atlas, src))
3600+
return false;
36053601

36063602
atlas->TexIsBuilt = false; // For legacy backends
36073603
ImFontAtlasBuildSetupFontSpecialGlyphs(atlas, font, src);

imgui_internal.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -4062,20 +4062,20 @@ IMGUI_API void ImFontAtlasBuildGrowTexture(ImFontAtlas* atlas, int
40624062
IMGUI_API void ImFontAtlasBuildCompactTexture(ImFontAtlas* atlas);
40634063
IMGUI_API ImVec2i ImFontAtlasBuildGetTextureSizeEstimate(ImFontAtlas* atlas);
40644064

4065+
IMGUI_API bool ImFontAtlasBuildAddFont(ImFontAtlas* atlas, ImFontConfig* src);
4066+
IMGUI_API void ImFontAtlasBuildSetupFontSpecialGlyphs(ImFontAtlas* atlas, ImFont* font, ImFontConfig* src);
4067+
IMGUI_API void ImFontAtlasBuildPreloadAllGlyphRanges(ImFontAtlas* atlas); // Legacy
4068+
IMGUI_API void ImFontAtlasBuildGetOversampleFactors(ImFontConfig* src, float size, int* out_oversample_h, int* out_oversample_v);
4069+
IMGUI_API void ImFontAtlasBuildDestroyFontSourceData(ImFontAtlas* atlas, ImFontConfig* src);
40654070
IMGUI_API void ImFontAtlasBuildReloadAll(ImFontAtlas* atlas); // Reinit/rebuild, notably if font loader params have changed.
40664071
IMGUI_API void ImFontAtlasBuildReloadFont(ImFontAtlas* atlas, ImFontConfig* src); // Reinit/rebuild, notably if font loader params have changed.
40674072

4068-
IMGUI_API bool ImFontAtlasBuildAddFont(ImFontAtlas* atlas, ImFontConfig* src);
4069-
IMGUI_API void ImFontAtlasBuildSetupFontSpecialGlyphs(ImFontAtlas* atlas, ImFont* font, ImFontConfig* src);
4070-
IMGUI_API void ImFontAtlasBuildDiscardBakes(ImFontAtlas* atlas, int unused_frames);
4071-
IMGUI_API void ImFontAtlasBuildDiscardFontBakes(ImFontAtlas* atlas, ImFont* font);
4072-
IMGUI_API void ImFontAtlasBuildDiscardFontSource(ImFontAtlas* atlas, ImFontConfig* src);
40734073
IMGUI_API ImFontBaked* ImFontAtlasBuildAddFontBaked(ImFontAtlas* atlas, ImFont* font, float font_size, ImGuiID baked_id);
40744074
IMGUI_API ImFontBaked* ImFontAtlasBuildGetClosestFontBakedMatch(ImFontAtlas* atlas, ImFont* font, float font_size);
4075+
IMGUI_API void ImFontAtlasBuildDiscardBakes(ImFontAtlas* atlas, int unused_frames);
4076+
IMGUI_API void ImFontAtlasBuildDiscardFontBakes(ImFontAtlas* atlas, ImFont* font);
40754077
IMGUI_API void ImFontAtlasBuildDiscardFontBaked(ImFontAtlas* atlas, ImFont* font, ImFontBaked* baked);
40764078
IMGUI_API void ImFontAtlasBuildDiscardFontBakedGlyph(ImFontAtlas* atlas, ImFont* font, ImFontBaked* baked, ImFontGlyph* glyph);
4077-
IMGUI_API void ImFontAtlasBuildPreloadAllGlyphRanges(ImFontAtlas* atlas); // Legacy
4078-
IMGUI_API void ImFontAtlasBuildGetOversampleFactors(ImFontConfig* src, float size, int* out_oversample_h, int* out_oversample_v);
40794079

40804080
IMGUI_API ImFontGlyph* ImFontAtlasBakedAddFontGlyph(ImFontAtlas* atlas, ImFontBaked* baked, ImFontConfig* src, const ImFontGlyph* in_glyph);
40814081
IMGUI_API void ImFontAtlasBakedSetFontGlyphBitmap(ImFontAtlas* atlas, ImFontBaked* baked, ImFontConfig* src, ImFontGlyph* glyph, ImTextureRect* r, const unsigned char* src_pixels, ImTextureFormat src_fmt, int src_pitch);

0 commit comments

Comments
 (0)