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