MCPcopy Create free account
hub / github.com/BoomingTech/Piccolo / AddFontFromFileTTF

Method AddFontFromFileTTF

engine/3rdparty/imgui/imgui_draw.cpp:2150–2169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 3

mainFunction · 0.80
mainFunction · 0.80
initializeMethod · 0.80

Calls 3

ImFileLoadToMemoryFunction · 0.85
ImFontConfigClass · 0.85
ImFormatStringFunction · 0.85

Tested by

no test coverage detected