@@ -2654,14 +2654,11 @@ void ImFontAtlas::CompactCache()
2654
2654
void ImFontAtlas::ClearInputData ()
2655
2655
{
2656
2656
IM_ASSERT (!Locked && " Cannot modify a locked ImFontAtlas!" );
2657
+
2658
+ for (ImFont* font : Fonts)
2659
+ ImFontAtlasBuildDestroyFontOutput (this , font);
2657
2660
for (ImFontConfig& font_cfg : Sources)
2658
- {
2659
- const ImFontLoader* loader = font_cfg.FontLoader ? font_cfg.FontLoader : FontLoader;
2660
- if (loader && loader->FontSrcDestroy != NULL )
2661
- loader->FontSrcDestroy (this , &font_cfg);
2662
2661
ImFontAtlasBuildDestroyFontSourceData (this , &font_cfg);
2663
- }
2664
-
2665
2662
for (ImFont* font : Fonts)
2666
2663
{
2667
2664
// When clearing this we lose access to the font name and other information used to build the font.
@@ -3203,15 +3200,9 @@ void ImFontAtlas::RemoveFont(ImFont* font)
3203
3200
IM_ASSERT (!Locked && " Cannot modify a locked ImFontAtlas!" );
3204
3201
font->ClearOutputData ();
3205
3202
3203
+ ImFontAtlasBuildDestroyFontOutput (this , font);
3206
3204
for (int src_n = 0 ; src_n < font->SourcesCount ; src_n++)
3207
- {
3208
- ImFontConfig* src = (ImFontConfig*)(void *)&font->Sources [src_n];
3209
- const ImFontLoader* loader = src->FontLoader ? src->FontLoader : FontLoader;
3210
- if (loader && loader->FontSrcDestroy != NULL )
3211
- loader->FontSrcDestroy (this , src);
3212
- if (src->FontData != NULL && src->FontDataOwnedByAtlas )
3213
- IM_FREE (src->FontData );
3214
- }
3205
+ ImFontAtlasBuildDestroyFontSourceData (this , &font->Sources [src_n]);
3215
3206
3216
3207
bool removed = Fonts.find_erase (font);
3217
3208
IM_ASSERT (removed);
@@ -3384,13 +3375,20 @@ void ImFontAtlasBuildSetupFontLoader(ImFontAtlas* atlas, const ImFontLoader* fon
3384
3375
3385
3376
// Note that texture size estimate is likely incorrect in this situation, as FreeType backend doesn't use oversampling.
3386
3377
ImVec2i new_tex_size = ImFontAtlasBuildGetTextureSizeEstimate (atlas);
3387
- ImFontAtlasBuildDestroy (atlas);
3378
+
3379
+ for (ImFont* font : atlas->Fonts )
3380
+ ImFontAtlasBuildDestroyFontOutput (atlas, font);
3381
+ if (atlas->Builder && atlas->FontLoader && atlas->FontLoader ->LoaderShutdown )
3382
+ atlas->FontLoader ->LoaderShutdown (atlas);
3388
3383
3389
3384
atlas->FontLoader = font_loader;
3390
3385
atlas->FontLoaderName = font_loader ? font_loader->Name : " NULL" ;
3386
+ IM_ASSERT (atlas->FontLoaderData == NULL );
3391
3387
3392
- ImFontAtlasBuildAddTexture (atlas, new_tex_size.x , new_tex_size.y );
3393
- ImFontAtlasBuildInit (atlas);
3388
+ if (atlas->Builder && atlas->FontLoader && atlas->FontLoader ->LoaderInit )
3389
+ atlas->FontLoader ->LoaderInit (atlas);
3390
+ for (ImFont* font : atlas->Fonts )
3391
+ ImFontAtlasBuildInitFontOutput (atlas, font);
3394
3392
}
3395
3393
3396
3394
// Preload all glyph ranges for legacy backends.
@@ -3568,18 +3566,31 @@ static void ImFontAtlasBuildUpdateLinesTexData(ImFontAtlas* atlas, bool add_and_
3568
3566
3569
3567
// -----------------------------------------------------------------------------------------------------------------------------
3570
3568
3571
- void ImFontAtlasBuildReloadAll (ImFontAtlas* atlas)
3569
+ bool ImFontAtlasBuildInitFontOutput (ImFontAtlas* atlas, ImFont* font )
3572
3570
{
3573
- const ImFontLoader* main_loader = atlas->FontLoader ;
3574
- ImFontAtlasBuildSetupFontLoader (atlas, NULL );
3575
- ImFontAtlasBuildSetupFontLoader (atlas, main_loader);
3571
+ bool ret = true ;
3572
+ for (int src_n = 0 ; src_n < font->SourcesCount ; src_n++)
3573
+ {
3574
+ ImFontConfig* src = &font->Sources [src_n];
3575
+ const ImFontLoader* loader = src->FontLoader ? src->FontLoader : atlas->FontLoader ;
3576
+ if (loader && loader->FontSrcInit != NULL && !loader->FontSrcInit (atlas, src))
3577
+ ret = false ;
3578
+ }
3579
+ IM_ASSERT (ret); // Unclear how to react to this meaningfully. Assume that result will be same as initial AddFont() call.
3580
+ return ret;
3576
3581
}
3577
3582
3578
- void ImFontAtlasBuildReloadFont (ImFontAtlas* atlas, ImFontConfig* src)
3583
+ // Keep source/input FontData
3584
+ void ImFontAtlasBuildDestroyFontOutput (ImFontAtlas* atlas, ImFont* font)
3579
3585
{
3580
- // FIXME-NEWATLAS: rebuild single font not supported yet.
3581
- IM_UNUSED (src);
3582
- ImFontAtlasBuildReloadAll (atlas);
3586
+ font->ClearOutputData ();
3587
+ for (int src_n = 0 ; src_n < font->SourcesCount ; src_n++)
3588
+ {
3589
+ ImFontConfig* src = &font->Sources [src_n];
3590
+ const ImFontLoader* loader = src->FontLoader ? src->FontLoader : atlas->FontLoader ;
3591
+ if (loader && loader->FontSrcDestroy != NULL )
3592
+ loader->FontSrcDestroy (atlas, src);
3593
+ }
3583
3594
}
3584
3595
3585
3596
// -----------------------------------------------------------------------------------------------------------------------------
@@ -4154,13 +4165,8 @@ void ImFontAtlasBuildInit(ImFontAtlas* atlas)
4154
4165
#else
4155
4166
IM_ASSERT (0 ); // Invalid Build function
4156
4167
#endif
4157
- return ; // ImFontAtlasBuildSetupFontLoader() automatically call ImFontAtlasBuildInit()
4158
4168
}
4159
4169
4160
- IM_ASSERT (atlas->FontLoaderData == NULL );
4161
- if (atlas->FontLoader ->LoaderInit )
4162
- atlas->FontLoader ->LoaderInit (atlas);
4163
-
4164
4170
// Create initial texture size
4165
4171
if (atlas->TexData == NULL || atlas->TexData ->Pixels == NULL )
4166
4172
ImFontAtlasBuildAddTexture (atlas, ImUpperPowerOfTwo (atlas->TexMinWidth ), ImUpperPowerOfTwo (atlas->TexMinHeight ));
@@ -4171,6 +4177,8 @@ void ImFontAtlasBuildInit(ImFontAtlas* atlas)
4171
4177
{
4172
4178
IM_ASSERT (atlas->Builder == NULL );
4173
4179
builder = atlas->Builder = IM_NEW (ImFontAtlasBuilder)();
4180
+ if (atlas->FontLoader ->LoaderInit )
4181
+ atlas->FontLoader ->LoaderInit (atlas);
4174
4182
}
4175
4183
4176
4184
ImFontAtlasBuildUpdateRendererHasTexturesFromContext (atlas);
@@ -4199,13 +4207,7 @@ void ImFontAtlasBuildInit(ImFontAtlas* atlas)
4199
4207
void ImFontAtlasBuildDestroy (ImFontAtlas* atlas)
4200
4208
{
4201
4209
for (ImFont* font : atlas->Fonts )
4202
- font->ClearOutputData ();
4203
- for (ImFontConfig& font_cfg : atlas->Sources )
4204
- {
4205
- const ImFontLoader* loader = font_cfg.FontLoader ? font_cfg.FontLoader : atlas->FontLoader ;
4206
- if (loader && loader->FontSrcDestroy != NULL )
4207
- loader->FontSrcDestroy (atlas, &font_cfg);
4208
- }
4210
+ ImFontAtlasBuildDestroyFontOutput (atlas, font);
4209
4211
if (atlas->Builder && atlas->FontLoader && atlas->FontLoader ->LoaderShutdown )
4210
4212
{
4211
4213
atlas->FontLoader ->LoaderShutdown (atlas);
0 commit comments