@@ -1034,7 +1034,7 @@ void ImDrawData::ScaleClipRects(const ImVec2& scale)
1034
1034
}
1035
1035
1036
1036
// -----------------------------------------------------------------------------
1037
- // ImFontAtlas
1037
+ // ImFontConfig
1038
1038
// -----------------------------------------------------------------------------
1039
1039
1040
1040
ImFontConfig::ImFontConfig ()
@@ -1055,6 +1055,10 @@ ImFontConfig::ImFontConfig()
1055
1055
memset (Name, 0 , sizeof (Name));
1056
1056
}
1057
1057
1058
+ // -----------------------------------------------------------------------------
1059
+ // ImFontAtlas
1060
+ // -----------------------------------------------------------------------------
1061
+
1058
1062
ImFontAtlas::ImFontAtlas ()
1059
1063
{
1060
1064
TexID = NULL ;
@@ -1282,40 +1286,19 @@ bool ImFontAtlas::Build()
1282
1286
TexUvWhitePixel = ImVec2 (0 , 0 );
1283
1287
ClearTexData ();
1284
1288
1285
- struct ImFontTempBuildData
1286
- {
1287
- stbtt_fontinfo FontInfo;
1288
- stbrp_rect* Rects;
1289
- stbtt_pack_range* Ranges;
1290
- int RangesCount;
1291
- };
1292
- ImFontTempBuildData* tmp_array = (ImFontTempBuildData*)ImGui::MemAlloc ((size_t )ConfigData.Size * sizeof (ImFontTempBuildData));
1293
-
1294
- // Initialize font information early (so we can error without any cleanup) + count glyphs
1289
+ // Count glyphs/ranges
1295
1290
int total_glyph_count = 0 ;
1296
1291
int total_glyph_range_count = 0 ;
1297
1292
for (int input_i = 0 ; input_i < ConfigData.Size ; input_i++)
1298
1293
{
1299
1294
ImFontConfig& cfg = ConfigData[input_i];
1300
- ImFontTempBuildData& tmp = tmp_array[input_i];
1301
-
1302
- IM_ASSERT (cfg.DstFont && (!cfg.DstFont ->IsLoaded () || cfg.DstFont ->ContainerAtlas == this ));
1303
- const int font_offset = stbtt_GetFontOffsetForIndex ((unsigned char *)cfg.FontData , cfg.FontNo );
1304
- IM_ASSERT (font_offset >= 0 );
1305
- if (!stbtt_InitFont (&tmp.FontInfo , (unsigned char *)cfg.FontData , font_offset))
1306
- return false ;
1307
-
1308
- // Count glyphs
1309
1295
if (!cfg.GlyphRanges )
1310
1296
cfg.GlyphRanges = GetGlyphRangesDefault ();
1311
- for (const ImWchar* in_range = cfg.GlyphRanges ; in_range[0 ] && in_range[1 ]; in_range += 2 )
1312
- {
1297
+ for (const ImWchar* in_range = cfg.GlyphRanges ; in_range[0 ] && in_range[1 ]; in_range += 2 , total_glyph_range_count++)
1313
1298
total_glyph_count += (in_range[1 ] - in_range[0 ]) + 1 ;
1314
- total_glyph_range_count++;
1315
- }
1316
1299
}
1317
1300
1318
- // Start packing. We need a known width for the skyline algorithm. Using a cheap heuristic here to decide of width. User can override TexDesiredWidth and TexGlyphPadding if they wish.
1301
+ // Start packing. We need a known width for the skyline algorithm. Using a dumb heuristic here to decide of width. User can override TexDesiredWidth and TexGlyphPadding if they wish.
1319
1302
// After packing is done, width shouldn't matter much, but some API/GPU have texture size limitations and increasing width can decrease height.
1320
1303
TexWidth = (TexDesiredWidth > 0 ) ? TexDesiredWidth : (total_glyph_count > 4000 ) ? 4096 : (total_glyph_count > 2000 ) ? 2048 : (total_glyph_count > 1000 ) ? 1024 : 512 ;
1321
1304
TexHeight = 0 ;
@@ -1332,6 +1315,26 @@ bool ImFontAtlas::Build()
1332
1315
if (extra_rects[i].was_packed )
1333
1316
TexHeight = ImMax (TexHeight, extra_rects[i].y + extra_rects[i].h );
1334
1317
1318
+ // Initialize font information (so we can error without any cleanup)
1319
+ struct ImFontTempBuildData
1320
+ {
1321
+ stbtt_fontinfo FontInfo;
1322
+ stbrp_rect* Rects;
1323
+ stbtt_pack_range* Ranges;
1324
+ int RangesCount;
1325
+ };
1326
+ ImFontTempBuildData* tmp_array = (ImFontTempBuildData*)ImGui::MemAlloc ((size_t )ConfigData.Size * sizeof (ImFontTempBuildData));
1327
+ for (int input_i = 0 ; input_i < ConfigData.Size ; input_i++)
1328
+ {
1329
+ ImFontConfig& cfg = ConfigData[input_i];
1330
+ ImFontTempBuildData& tmp = tmp_array[input_i];
1331
+ IM_ASSERT (cfg.DstFont && (!cfg.DstFont ->IsLoaded () || cfg.DstFont ->ContainerAtlas == this ));
1332
+ const int font_offset = stbtt_GetFontOffsetForIndex ((unsigned char *)cfg.FontData , cfg.FontNo );
1333
+ IM_ASSERT (font_offset >= 0 );
1334
+ if (!stbtt_InitFont (&tmp.FontInfo , (unsigned char *)cfg.FontData , font_offset))
1335
+ return false ;
1336
+ }
1337
+
1335
1338
// Allocate packing character data and flag packed characters buffer as non-packed (x0=y0=x1=y1=0)
1336
1339
int buf_packedchars_n = 0 , buf_rects_n = 0 , buf_ranges_n = 0 ;
1337
1340
stbtt_packedchar* buf_packedchars = (stbtt_packedchar*)ImGui::MemAlloc (total_glyph_count * sizeof (stbtt_packedchar));
@@ -1350,11 +1353,8 @@ bool ImFontAtlas::Build()
1350
1353
// Setup ranges
1351
1354
int glyph_count = 0 ;
1352
1355
int glyph_ranges_count = 0 ;
1353
- for (const ImWchar* in_range = cfg.GlyphRanges ; in_range[0 ] && in_range[1 ]; in_range += 2 )
1354
- {
1356
+ for (const ImWchar* in_range = cfg.GlyphRanges ; in_range[0 ] && in_range[1 ]; in_range += 2 , glyph_ranges_count++)
1355
1357
glyph_count += (in_range[1 ] - in_range[0 ]) + 1 ;
1356
- glyph_ranges_count++;
1357
- }
1358
1358
tmp.Ranges = buf_ranges + buf_ranges_n;
1359
1359
tmp.RangesCount = glyph_ranges_count;
1360
1360
buf_ranges_n += glyph_ranges_count;
@@ -1392,7 +1392,7 @@ bool ImFontAtlas::Build()
1392
1392
spc.pixels = TexPixelsAlpha8;
1393
1393
spc.height = TexHeight;
1394
1394
1395
- // Second pass: render characters
1395
+ // Second pass: render font characters
1396
1396
for (int input_i = 0 ; input_i < ConfigData.Size ; input_i++)
1397
1397
{
1398
1398
ImFontConfig& cfg = ConfigData[input_i];
0 commit comments