unicode fonts support
This commit is contained in:
parent
056904fab3
commit
5548e0f4a8
Binary file not shown.
@ -3,10 +3,15 @@
|
||||
|
||||
namespace GraphC::gui::fonts {
|
||||
|
||||
// select all glyphs from font
|
||||
static const ImWchar glyph_ranges[] = {
|
||||
0x0020, 0xFFFF, 0
|
||||
};
|
||||
|
||||
ImFont* ImFont_LoadFromFile(const std::string& file_path, f32 font_size, f32 dpi){
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
font_size *= dpi;
|
||||
return io.Fonts->AddFontFromFileTTF(file_path.c_str(), font_size);
|
||||
return io.Fonts->AddFontFromFileTTF(file_path.c_str(), font_size, nullptr, glyph_ranges);
|
||||
}
|
||||
|
||||
ImFont* ImFont_LoadEmbedded(const std::string& font_name, f32 font_size, f32 dpi){
|
||||
@ -14,12 +19,15 @@ ImFont* ImFont_LoadEmbedded(const std::string& font_name, f32 font_size, f32 dpi
|
||||
font_size *= dpi;
|
||||
ImFontConfig font_cfg = ImFontConfig();
|
||||
font_cfg.FontDataOwnedByAtlas = false;
|
||||
ksprintf(font_cfg.Name, IM_ARRAYSIZE(font_cfg.Name), "%s, %.0fpx", font_name, font_size);
|
||||
ksprintf(font_cfg.Name, IM_ARRAYSIZE(font_cfg.Name), "%s %ipx", font_name.c_str(), (i32)font_size);
|
||||
|
||||
const resources::EmbeddedResource** _res = nullptr;
|
||||
if(!resources::getMap()->tryGet("fonts/" + font_name + ".ttf", &_res))
|
||||
throw UsefulException(format("can't load embedded font '%s'", font_name.c_str()));
|
||||
const resources::EmbeddedResource* res = *_res;
|
||||
return io.Fonts->AddFontFromMemoryTTF((void*)(res->data), res->size, font_size, &font_cfg);
|
||||
|
||||
return io.Fonts->AddFontFromMemoryTTF((void*)(res->data), res->size,
|
||||
font_size, &font_cfg, glyph_ranges);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -73,8 +73,7 @@ void GUI::init(const char* window_title){
|
||||
// Setup Dear ImGui style
|
||||
ImGui::StyleColorsDark();
|
||||
f32 dpi = getDPI();
|
||||
io.FontDefault=fonts:: ImFont_LoadEmbedded(default_font, default_font_size, dpi);
|
||||
fonts:: ImFont_LoadEmbedded("Cousine-Regular", default_font_size, dpi);
|
||||
io.FontDefault = fonts::ImFont_LoadEmbedded(default_font, default_font_size, dpi);
|
||||
|
||||
ImNodes::CreateContext();
|
||||
ImNodes::StyleColorsDark();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user