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

Function ImFontAtlasBuildWithFreeTypeEx

KBotExt/imgui/imgui_freetype.cpp:399–717  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

397};
398
399bool ImFontAtlasBuildWithFreeTypeEx(FT_Library ft_library, ImFontAtlas* atlas, unsigned int extra_flags)
400{
401 IM_ASSERT(atlas->ConfigData.Size > 0);
402
403 ImFontAtlasBuildInit(atlas);
404
405 // Clear atlas
406 atlas->TexID = (ImTextureID)NULL;
407 atlas->TexWidth = atlas->TexHeight = 0;
408 atlas->TexUvScale = ImVec2(0.0f, 0.0f);
409 atlas->TexUvWhitePixel = ImVec2(0.0f, 0.0f);
410 atlas->ClearTexData();
411
412 // Temporary storage for building
413 bool src_load_color = false;
414 ImVector<ImFontBuildSrcDataFT> src_tmp_array;
415 ImVector<ImFontBuildDstDataFT> dst_tmp_array;
416 src_tmp_array.resize(atlas->ConfigData.Size);
417 dst_tmp_array.resize(atlas->Fonts.Size);
418 memset((void*)src_tmp_array.Data, 0, (size_t)src_tmp_array.size_in_bytes());
419 memset((void*)dst_tmp_array.Data, 0, (size_t)dst_tmp_array.size_in_bytes());
420
421 // 1. Initialize font loading structure, check font data validity
422 for (int src_i = 0; src_i < atlas->ConfigData.Size; src_i++)
423 {
424 ImFontBuildSrcDataFT& src_tmp = src_tmp_array[src_i];
425 ImFontConfig& cfg = atlas->ConfigData[src_i];
426 FreeTypeFont& font_face = src_tmp.Font;
427 IM_ASSERT(cfg.DstFont && (!cfg.DstFont->IsLoaded() || cfg.DstFont->ContainerAtlas == atlas));
428
429 // Find index from cfg.DstFont (we allow the user to set cfg.DstFont. Also it makes casual debugging nicer than when storing indices)
430 src_tmp.DstIndex = -1;
431 for (int output_i = 0; output_i < atlas->Fonts.Size && src_tmp.DstIndex == -1; output_i++)
432 if (cfg.DstFont == atlas->Fonts[output_i])
433 src_tmp.DstIndex = output_i;
434 IM_ASSERT(src_tmp.DstIndex != -1); // cfg.DstFont not pointing within atlas->Fonts[] array?
435 if (src_tmp.DstIndex == -1)
436 return false;
437
438 // Load font
439 if (!font_face.InitFont(ft_library, cfg, extra_flags))
440 return false;
441
442 // Measure highest codepoints
443 src_load_color |= (cfg.FontBuilderFlags & ImGuiFreeTypeBuilderFlags_LoadColor) != 0;
444 ImFontBuildDstDataFT& dst_tmp = dst_tmp_array[src_tmp.DstIndex];
445 src_tmp.SrcRanges = cfg.GlyphRanges ? cfg.GlyphRanges : atlas->GetGlyphRangesDefault();
446 for (const ImWchar* src_range = src_tmp.SrcRanges; src_range[0] && src_range[1]; src_range += 2)
447 {
448 // Check for valid range. This may also help detect *some* dangling pointers, because a common
449 // user error is to setup ImFontConfig::GlyphRanges with a pointer to data that isn't persistent.
450 IM_ASSERT(src_range[0] <= src_range[1]);
451 src_tmp.GlyphsHighest = ImMax(src_tmp.GlyphsHighest, (int)src_range[1]);
452 }
453 dst_tmp.SrcCount++;
454 dst_tmp.GlyphsHighest = ImMax(dst_tmp.GlyphsHighest, src_tmp.GlyphsHighest);
455 }
456

Callers 1

Calls 15

ImFontAtlasBuildInitFunction · 0.85
ImVec2Function · 0.85
ImMaxFunction · 0.85
stbrp_init_targetFunction · 0.85
stbrp_pack_rectsFunction · 0.85
ImUpperPowerOfTwoFunction · 0.85
ImFontAtlasBuildFinishFunction · 0.85
ClearTexDataMethod · 0.80
IsLoadedMethod · 0.80

Tested by

no test coverage detected