MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / ImFontAtlasBuildWithStbTruetype

Function ImFontAtlasBuildWithStbTruetype

KBotExt/imgui/imgui_draw.cpp:2391–2643  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2389}
2390
2391static bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
2392{
2393 IM_ASSERT(atlas->ConfigData.Size > 0);
2394
2395 ImFontAtlasBuildInit(atlas);
2396
2397 // Clear atlas
2398 atlas->TexID = (ImTextureID)NULL;
2399 atlas->TexWidth = atlas->TexHeight = 0;
2400 atlas->TexUvScale = ImVec2(0.0f, 0.0f);
2401 atlas->TexUvWhitePixel = ImVec2(0.0f, 0.0f);
2402 atlas->ClearTexData();
2403
2404 // Temporary storage for building
2405 ImVector<ImFontBuildSrcData> src_tmp_array;
2406 ImVector<ImFontBuildDstData> dst_tmp_array;
2407 src_tmp_array.resize(atlas->ConfigData.Size);
2408 dst_tmp_array.resize(atlas->Fonts.Size);
2409 memset(src_tmp_array.Data, 0, (size_t)src_tmp_array.size_in_bytes());
2410 memset(dst_tmp_array.Data, 0, (size_t)dst_tmp_array.size_in_bytes());
2411
2412 // 1. Initialize font loading structure, check font data validity
2413 for (int src_i = 0; src_i < atlas->ConfigData.Size; src_i++)
2414 {
2415 ImFontBuildSrcData& src_tmp = src_tmp_array[src_i];
2416 ImFontConfig& cfg = atlas->ConfigData[src_i];
2417 IM_ASSERT(cfg.DstFont && (!cfg.DstFont->IsLoaded() || cfg.DstFont->ContainerAtlas == atlas));
2418
2419 // Find index from cfg.DstFont (we allow the user to set cfg.DstFont. Also it makes casual debugging nicer than when storing indices)
2420 src_tmp.DstIndex = -1;
2421 for (int output_i = 0; output_i < atlas->Fonts.Size && src_tmp.DstIndex == -1; output_i++)
2422 if (cfg.DstFont == atlas->Fonts[output_i])
2423 src_tmp.DstIndex = output_i;
2424 if (src_tmp.DstIndex == -1)
2425 {
2426 IM_ASSERT(src_tmp.DstIndex != -1); // cfg.DstFont not pointing within atlas->Fonts[] array?
2427 return false;
2428 }
2429 // Initialize helper structure for font loading and verify that the TTF/OTF data is correct
2430 const int font_offset = stbtt_GetFontOffsetForIndex((unsigned char*)cfg.FontData, cfg.FontNo);
2431 IM_ASSERT(font_offset >= 0 && "FontData is incorrect, or FontNo cannot be found.");
2432 if (!stbtt_InitFont(&src_tmp.FontInfo, (unsigned char*)cfg.FontData, font_offset))
2433 return false;
2434
2435 // Measure highest codepoints
2436 ImFontBuildDstData& dst_tmp = dst_tmp_array[src_tmp.DstIndex];
2437 src_tmp.SrcRanges = cfg.GlyphRanges ? cfg.GlyphRanges : atlas->GetGlyphRangesDefault();
2438 for (const ImWchar* src_range = src_tmp.SrcRanges; src_range[0] && src_range[1]; src_range += 2)
2439 {
2440 // Check for valid range. This may also help detect *some* dangling pointers, because a common
2441 // user error is to setup ImFontConfig::GlyphRanges with a pointer to data that isn't persistent.
2442 IM_ASSERT(src_range[0] <= src_range[1]);
2443 src_tmp.GlyphsHighest = ImMax(src_tmp.GlyphsHighest, (int)src_range[1]);
2444 }
2445 dst_tmp.SrcCount++;
2446 dst_tmp.GlyphsHighest = ImMax(dst_tmp.GlyphsHighest, src_tmp.GlyphsHighest);
2447 }
2448

Callers

nothing calls this directly

Calls 15

ImFontAtlasBuildInitFunction · 0.85
ImVec2Function · 0.85
ImMaxFunction · 0.85
stbrp_pack_rectsFunction · 0.85
ImUpperPowerOfTwoFunction · 0.85
ImFloorFunction · 0.85
ImFontAtlasBuildFinishFunction · 0.85

Tested by

no test coverage detected