| 3222 | } |
| 3223 | |
| 3224 | ImFont* ImFontAtlas::AddFontFromFileTTF(const char* filename, float size_pixels, const ImFontConfig* font_cfg_template, const ImWchar* glyph_ranges) |
| 3225 | { |
| 3226 | IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas!"); |
| 3227 | size_t data_size = 0; |
| 3228 | void* data = ImFileLoadToMemory(filename, "rb", &data_size, 0); |
| 3229 | if (!data) |
| 3230 | { |
| 3231 | if (font_cfg_template == NULL || (font_cfg_template->Flags & ImFontFlags_NoLoadError) == 0) |
| 3232 | { |
| 3233 | IMGUI_DEBUG_LOG("While loading '%s'\n", filename); |
| 3234 | IM_ASSERT_USER_ERROR(0, "Could not load font file!"); |
| 3235 | } |
| 3236 | return NULL; |
| 3237 | } |
| 3238 | ImFontConfig font_cfg = font_cfg_template ? *font_cfg_template : ImFontConfig(); |
| 3239 | if (font_cfg.Name[0] == '\0') |
| 3240 | { |
| 3241 | // Store a short copy of filename into the font name for convenience |
| 3242 | const char* p; |
| 3243 | for (p = filename + ImStrlen(filename); p > filename && p[-1] != '/' && p[-1] != '\\'; p--) {} |
| 3244 | ImFormatString(font_cfg.Name, IM_COUNTOF(font_cfg.Name), "%s", p); |
| 3245 | } |
| 3246 | return AddFontFromMemoryTTF(data, (int)data_size, size_pixels, &font_cfg, glyph_ranges); |
| 3247 | } |
| 3248 | |
| 3249 | // NB: Transfer ownership of 'font_data' to ImFontAtlas, unless font_cfg_template->FontDataOwnedByAtlas == false. Owned TTF buffer will be deleted after Build(). |
| 3250 | ImFont* ImFontAtlas::AddFontFromMemoryTTF(void* font_data, int font_data_size, float size_pixels, const ImFontConfig* font_cfg_template, const ImWchar* glyph_ranges) |
nothing calls this directly
no test coverage detected