| 2142 | } |
| 2143 | |
| 2144 | ImFont* ImFontAtlas::AddFontFromFileTTF(const char* filename, float size_pixels, const ImFontConfig* font_cfg_template, const ImWchar* glyph_ranges) |
| 2145 | { |
| 2146 | IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas between NewFrame() and EndFrame/Render()!"); |
| 2147 | size_t data_size = 0; |
| 2148 | void* data = ImFileLoadToMemory(filename, "rb", &data_size, 0); |
| 2149 | if (!data) |
| 2150 | { |
| 2151 | IM_ASSERT_USER_ERROR(0, "Could not load font file!"); |
| 2152 | return NULL; |
| 2153 | } |
| 2154 | ImFontConfig font_cfg = font_cfg_template ? *font_cfg_template : ImFontConfig(); |
| 2155 | if (font_cfg.Name[0] == '\0') |
| 2156 | { |
| 2157 | // Store a short copy of filename into into the font name for convenience |
| 2158 | const char* p; |
| 2159 | for (p = filename + strlen(filename); p > filename && p[-1] != '/' && p[-1] != '\\'; p--) {} |
| 2160 | ImFormatString(font_cfg.Name, IM_ARRAYSIZE(font_cfg.Name), "%s, %.0fpx", p, size_pixels); |
| 2161 | } |
| 2162 | return AddFontFromMemoryTTF(data, (int)data_size, size_pixels, &font_cfg, glyph_ranges); |
| 2163 | } |
| 2164 | |
| 2165 | // NB: Transfer ownership of 'ttf_data' to ImFontAtlas, unless font_cfg_template->FontDataOwnedByAtlas == false. Owned TTF buffer will be deleted after Build(). |
| 2166 | ImFont* ImFontAtlas::AddFontFromMemoryTTF(void* ttf_data, int ttf_size, float size_pixels, const ImFontConfig* font_cfg_template, const ImWchar* glyph_ranges) |
no test coverage detected