| 3000 | #endif // #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS |
| 3001 | |
| 3002 | ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg_in) |
| 3003 | { |
| 3004 | // Sanity Checks |
| 3005 | IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas!"); |
| 3006 | IM_ASSERT((font_cfg_in->FontData != NULL && font_cfg_in->FontDataSize > 0) || (font_cfg_in->FontLoader != NULL)); |
| 3007 | //IM_ASSERT(font_cfg_in->SizePixels > 0.0f && "Is ImFontConfig struct correctly initialized?"); |
| 3008 | IM_ASSERT(font_cfg_in->RasterizerDensity > 0.0f && "Is ImFontConfig struct correctly initialized?"); |
| 3009 | if (font_cfg_in->GlyphOffset.x != 0.0f || font_cfg_in->GlyphOffset.y != 0.0f || font_cfg_in->GlyphMinAdvanceX != 0.0f || font_cfg_in->GlyphMaxAdvanceX != FLT_MAX) |
| 3010 | IM_ASSERT(font_cfg_in->SizePixels != 0.0f && "Specifying glyph offset/advances requires a reference size to base it on."); |
| 3011 | |
| 3012 | // Lazily create builder on the first call to AddFont |
| 3013 | if (Builder == NULL) |
| 3014 | ImFontAtlasBuildInit(this); |
| 3015 | |
| 3016 | // Create new font |
| 3017 | ImFont* font; |
| 3018 | if (!font_cfg_in->MergeMode) |
| 3019 | { |
| 3020 | font = IM_NEW(ImFont)(); |
| 3021 | font->FontId = FontNextUniqueID++; |
| 3022 | font->Flags = font_cfg_in->Flags; |
| 3023 | font->LegacySize = font_cfg_in->SizePixels; |
| 3024 | font->CurrentRasterizerDensity = font_cfg_in->RasterizerDensity; |
| 3025 | Fonts.push_back(font); |
| 3026 | } |
| 3027 | else |
| 3028 | { |
| 3029 | IM_ASSERT(Fonts.Size > 0 && "Cannot use MergeMode for the first font"); // When using MergeMode make sure that a font has already been added before. You can use ImGui::GetIO().Fonts->AddFontDefault() to add the default imgui font. |
| 3030 | font = font_cfg_in->DstFont ? font_cfg_in->DstFont : Fonts.back(); |
| 3031 | } |
| 3032 | |
| 3033 | // Add to list |
| 3034 | Sources.push_back(*font_cfg_in); |
| 3035 | ImFontConfig* font_cfg = &Sources.back(); |
| 3036 | if (font_cfg->DstFont == NULL) |
| 3037 | font_cfg->DstFont = font; |
| 3038 | font->Sources.push_back(font_cfg); |
| 3039 | ImFontAtlasBuildUpdatePointers(this); // Pointers to Sources are otherwise dangling after we called Sources.push_back(). |
| 3040 | |
| 3041 | if (font_cfg->FontDataOwnedByAtlas == false) |
| 3042 | { |
| 3043 | font_cfg->FontDataOwnedByAtlas = true; |
| 3044 | font_cfg->FontData = ImMemdup(font_cfg->FontData, (size_t)font_cfg->FontDataSize); |
| 3045 | } |
| 3046 | |
| 3047 | // Sanity check |
| 3048 | // We don't round cfg.SizePixels yet as relative size of merged fonts are used afterwards. |
| 3049 | if (font_cfg->GlyphExcludeRanges != NULL) |
| 3050 | { |
| 3051 | int size = 0; |
| 3052 | for (const ImWchar* p = font_cfg->GlyphExcludeRanges; p[0] != 0; p++, size++) {} |
| 3053 | IM_ASSERT((size & 1) == 0 && "GlyphExcludeRanges[] size must be multiple of two!"); |
| 3054 | IM_ASSERT((size <= 64) && "GlyphExcludeRanges[] size must be small!"); |
| 3055 | font_cfg->GlyphExcludeRanges = (ImWchar*)ImMemdup(font_cfg->GlyphExcludeRanges, sizeof(font_cfg->GlyphExcludeRanges[0]) * (size + 1)); |
| 3056 | } |
| 3057 | if (font_cfg->FontLoader != NULL) |
| 3058 | { |
| 3059 | IM_ASSERT(font_cfg->FontLoader->FontBakedLoadGlyph != NULL); |
nothing calls this directly
no test coverage detected