MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / AddFontFromFileTTF

Method AddFontFromFileTTF

extern/imgui/imgui_draw.cpp:2144–2163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2142}
2143
2144ImFont* 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().
2166ImFont* ImFontAtlas::AddFontFromMemoryTTF(void* ttf_data, int ttf_size, float size_pixels, const ImFontConfig* font_cfg_template, const ImWchar* glyph_ranges)

Callers 2

initImguiMethod · 0.80
initImguiMethod · 0.80

Calls 3

ImFileLoadToMemoryFunction · 0.85
ImFontConfigClass · 0.85
ImFormatStringFunction · 0.85

Tested by

no test coverage detected