MCPcopy Create free account
hub / github.com/VictorGordan/opengl-tutorials / AddFontFromFileTTF

Method AddFontFromFileTTF

ImGUI GLFW Tutorial/imgui/imgui_draw.cpp:2130–2149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2128}
2129
2130ImFont* ImFontAtlas::AddFontFromFileTTF(const char* filename, float size_pixels, const ImFontConfig* font_cfg_template, const ImWchar* glyph_ranges)
2131{
2132 IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas between NewFrame() and EndFrame/Render()!");
2133 size_t data_size = 0;
2134 void* data = ImFileLoadToMemory(filename, "rb", &data_size, 0);
2135 if (!data)
2136 {
2137 IM_ASSERT_USER_ERROR(0, "Could not load font file!");
2138 return NULL;
2139 }
2140 ImFontConfig font_cfg = font_cfg_template ? *font_cfg_template : ImFontConfig();
2141 if (font_cfg.Name[0] == '\0')
2142 {
2143 // Store a short copy of filename into into the font name for convenience
2144 const char* p;
2145 for (p = filename + strlen(filename); p > filename && p[-1] != '/' && p[-1] != '\\'; p--) {}
2146 ImFormatString(font_cfg.Name, IM_ARRAYSIZE(font_cfg.Name), "%s, %.0fpx", p, size_pixels);
2147 }
2148 return AddFontFromMemoryTTF(data, (int)data_size, size_pixels, &font_cfg, glyph_ranges);
2149}
2150
2151// NB: Transfer ownership of 'ttf_data' to ImFontAtlas, unless font_cfg_template->FontDataOwnedByAtlas == false. Owned TTF buffer will be deleted after Build().
2152ImFont* ImFontAtlas::AddFontFromMemoryTTF(void* ttf_data, int ttf_size, float size_pixels, const ImFontConfig* font_cfg_template, const ImWchar* glyph_ranges)

Callers

nothing calls this directly

Calls 3

ImFileLoadToMemoryFunction · 0.70
ImFontConfigClass · 0.70
ImFormatStringFunction · 0.70

Tested by

no test coverage detected