ougge/src/Resources/fonts.cpp
2025-05-19 03:26:18 +05:00

30 lines
867 B
C++

#include "fonts.hpp"
namespace ougge::resources {
// 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, nullptr, glyph_ranges);
}
ImFont* ImFont_LoadFromResource(ResourceFactory* res, f32 font_size, f32 dpi){
ImGuiIO& io = ImGui::GetIO();
font_size *= dpi;
ImFontConfig font_cfg = ImFontConfig();
std::sprintf(font_cfg.Name, "%s %ipx", res->path.c_str(), (i32)font_size);
char* font_data = new char[res->size];
res->openStream()->read(font_data, res->size);
return io.Fonts->AddFontFromMemoryTTF((void*)(font_data), res->size,
font_size, &font_cfg, glyph_ranges);
}
}