@@ -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);
@@ -3382,15 +3373,19 @@ void ImFontAtlasBuildSetupFontLoader(ImFontAtlas* atlas, const ImFontLoader* fon
3382
3373
return ;
3383
3374
IM_ASSERT (!atlas->Locked && " Cannot modify a locked ImFontAtlas!" );
3384
3375
3385
- // Note that texture size estimate is likely incorrect in this situation, as FreeType backend doesn't use oversampling.
3386
- ImVec2i new_tex_size = ImFontAtlasBuildGetTextureSizeEstimate (atlas);
3387
- ImFontAtlasBuildDestroy (atlas);
3376
+ for (ImFont* font : atlas->Fonts )
3377
+ ImFontAtlasBuildDestroyFontOutput (atlas, font);
3378
+ if (atlas->Builder && atlas->FontLoader && atlas->FontLoader ->LoaderShutdown )
3379
+ atlas->FontLoader ->LoaderShutdown (atlas);
3388
3380
3389
3381
atlas->FontLoader = font_loader;
3390
3382
atlas->FontLoaderName = font_loader ? font_loader->Name : " NULL" ;
3383
+ IM_ASSERT (atlas->FontLoaderData == NULL );
3391
3384
3392
- ImFontAtlasBuildAddTexture (atlas, new_tex_size.x , new_tex_size.y );
3393
- 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);
3394
3389
}
3395
3390
3396
3391
// Preload all glyph ranges for legacy backends.
@@ -3568,18 +3563,31 @@ static void ImFontAtlasBuildUpdateLinesTexData(ImFontAtlas* atlas, bool add_and_
3568
3563
3569
3564
// -----------------------------------------------------------------------------------------------------------------------------
3570
3565
3571
- void ImFontAtlasBuildReloadAll (ImFontAtlas* atlas)
3566
+ bool ImFontAtlasBuildInitFontOutput (ImFontAtlas* atlas, ImFont* font )
3572
3567
{
3573
- const ImFontLoader* main_loader = atlas->FontLoader ;
3574
- ImFontAtlasBuildSetupFontLoader (atlas, NULL );
3575
- 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;
3576
3578
}
3577
3579
3578
- void ImFontAtlasBuildReloadFont (ImFontAtlas* atlas, ImFontConfig* src)
3580
+ // Keep source/input FontData
3581
+ void ImFontAtlasBuildDestroyFontOutput (ImFontAtlas* atlas, ImFont* font)
3579
3582
{
3580
- // FIXME-NEWATLAS: rebuild single font not supported yet.
3581
- IM_UNUSED (src);
3582
- 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
+ }
3583
3591
}
3584
3592
3585
3593
// -----------------------------------------------------------------------------------------------------------------------------
@@ -4154,13 +4162,8 @@ void ImFontAtlasBuildInit(ImFontAtlas* atlas)
4154
4162
#else
4155
4163
IM_ASSERT (0 ); // Invalid Build function
4156
4164
#endif
4157
- return ; // ImFontAtlasBuildSetupFontLoader() automatically call ImFontAtlasBuildInit()
4158
4165
}
4159
4166
4160
- IM_ASSERT (atlas->FontLoaderData == NULL );
4161
- if (atlas->FontLoader ->LoaderInit )
4162
- atlas->FontLoader ->LoaderInit (atlas);
4163
-
4164
4167
// Create initial texture size
4165
4168
if (atlas->TexData == NULL || atlas->TexData ->Pixels == NULL )
4166
4169
ImFontAtlasBuildAddTexture (atlas, ImUpperPowerOfTwo (atlas->TexMinWidth ), ImUpperPowerOfTwo (atlas->TexMinHeight ));
@@ -4171,6 +4174,8 @@ void ImFontAtlasBuildInit(ImFontAtlas* atlas)
4171
4174
{
4172
4175
IM_ASSERT (atlas->Builder == NULL );
4173
4176
builder = atlas->Builder = IM_NEW (ImFontAtlasBuilder)();
4177
+ if (atlas->FontLoader ->LoaderInit )
4178
+ atlas->FontLoader ->LoaderInit (atlas);
4174
4179
}
4175
4180
4176
4181
ImFontAtlasBuildUpdateRendererHasTexturesFromContext (atlas);
@@ -4199,13 +4204,7 @@ void ImFontAtlasBuildInit(ImFontAtlas* atlas)
4199
4204
void ImFontAtlasBuildDestroy (ImFontAtlas* atlas)
4200
4205
{
4201
4206
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
- }
4207
+ ImFontAtlasBuildDestroyFontOutput (atlas, font);
4209
4208
if (atlas->Builder && atlas->FontLoader && atlas->FontLoader ->LoaderShutdown )
4210
4209
{
4211
4210
atlas->FontLoader ->LoaderShutdown (atlas);
0 commit comments