diff --git a/lib/libimhex/include/hex/api/imhex_api.hpp b/lib/libimhex/include/hex/api/imhex_api.hpp index 9aae1e67b..67da2e8f4 100644 --- a/lib/libimhex/include/hex/api/imhex_api.hpp +++ b/lib/libimhex/include/hex/api/imhex_api.hpp @@ -745,16 +745,12 @@ EXPORT_MODULE namespace hex { namespace Fonts { - struct GlyphRange { u16 begin, end; }; struct Offset { float x, y; }; struct MergeFont { std::string name; std::vector fontData; - std::vector glyphRanges; Offset offset; - u32 flags; - std::optional scalable; std::optional defaultSize; }; @@ -777,15 +773,8 @@ EXPORT_MODULE namespace hex { } - GlyphRange glyph(const char *glyph); - GlyphRange glyph(u32 codepoint); - GlyphRange range(const char *glyphBegin, const char *glyphEnd); - GlyphRange range(u32 codepointBegin, u32 codepointEnd); - - void loadFont(const std::fs::path &path, const std::vector &glyphRanges = {}, Offset offset = {}, u32 flags = 0, std::optional scalable = std::nullopt, std::optional defaultSize = std::nullopt); - void loadFont(const std::string &name, const std::span &data, const std::vector &glyphRanges = {}, Offset offset = {}, u32 flags = 0, std::optional scalable = std::nullopt, std::optional defaultSize = std::nullopt); - - constexpr float DefaultFontSize = 13.0; + void loadFont(const std::fs::path &path, Offset offset = {}, std::optional defaultSize = std::nullopt); + void loadFont(const std::string &name, const std::span &data, Offset offset = {}, std::optional defaultSize = std::nullopt); void registerFont(const UnlocalizedString &fontName); ImFont* getFont(const UnlocalizedString &fontName); diff --git a/lib/libimhex/source/api/imhex_api.cpp b/lib/libimhex/source/api/imhex_api.cpp index 995ab8f45..aa17ca90e 100644 --- a/lib/libimhex/source/api/imhex_api.cpp +++ b/lib/libimhex/source/api/imhex_api.cpp @@ -1052,41 +1052,7 @@ namespace hex { return getFont(m_fontName); } - - GlyphRange glyph(const char *glyph) { - u32 codepoint; - ImTextCharFromUtf8(&codepoint, glyph, nullptr); - - return { - .begin = u16(codepoint), - .end = u16(codepoint) - }; - } - GlyphRange glyph(u32 codepoint) { - return { - .begin = u16(codepoint), - .end = u16(codepoint) - }; - } - GlyphRange range(const char *glyphBegin, const char *glyphEnd) { - u32 codepointBegin, codepointEnd; - ImTextCharFromUtf8(&codepointBegin, glyphBegin, nullptr); - ImTextCharFromUtf8(&codepointEnd, glyphEnd, nullptr); - - return { - .begin = u16(codepointBegin), - .end = u16(codepointEnd) - }; - } - - GlyphRange range(u32 codepointBegin, u32 codepointEnd) { - return { - .begin = u16(codepointBegin), - .end = u16(codepointEnd) - }; - } - - void loadFont(const std::fs::path &path, const std::vector &glyphRanges, Offset offset, u32 flags, std::optional scalable, std::optional defaultSize) { + void loadFont(const std::fs::path &path, Offset offset, std::optional defaultSize) { wolv::io::File fontFile(path, wolv::io::File::Mode::Read); if (!fontFile.isValid()) { log::error("Failed to load font from file '{}'", wolv::util::toUTF8String(path)); @@ -1096,22 +1062,16 @@ namespace hex { impl::s_fonts->emplace_back(MergeFont { wolv::util::toUTF8String(path.filename()), fontFile.readVector(), - glyphRanges, offset, - flags, - scalable, defaultSize }); } - void loadFont(const std::string &name, const std::span &data, const std::vector &glyphRanges, Offset offset, u32 flags, std::optional scalable, std::optional defaultSize) { + void loadFont(const std::string &name, const std::span &data, Offset offset, std::optional defaultSize) { impl::s_fonts->emplace_back(MergeFont { name, { data.begin(), data.end() }, - glyphRanges, offset, - flags, - scalable, defaultSize }); } diff --git a/main/gui/source/init/splash_window.cpp b/main/gui/source/init/splash_window.cpp index a9c2610d9..ca75ca094 100644 --- a/main/gui/source/init/splash_window.cpp +++ b/main/gui/source/init/splash_window.cpp @@ -528,7 +528,6 @@ namespace hex::init { ImFontConfig cfg; cfg.OversampleH = cfg.OversampleV = 1, cfg.PixelSnapH = true; - cfg.SizePixels = ImHexApi::Fonts::DefaultFontSize; io.Fonts->AddFontDefault(&cfg); } diff --git a/plugins/fonts/source/fonts.cpp b/plugins/fonts/source/fonts.cpp index ebc140f5f..0c5547a4e 100644 --- a/plugins/fonts/source/fonts.cpp +++ b/plugins/fonts/source/fonts.cpp @@ -1,14 +1,8 @@ #include #include - #include -#include - -#include -#include - namespace hex::fonts { static auto s_defaultFont = ImHexApi::Fonts::Font("hex.fonts.font.default"); @@ -19,23 +13,9 @@ namespace hex::fonts { const ImHexApi::Fonts::Font& CodeEditor() { return s_codeEditorFont; } void registerFonts() { - using namespace ImHexApi::Fonts; - - /** - * !!IMPORTANT!! - * Always load the font files in decreasing size of their glyphs. This will make the rasterize be more - * efficient when packing the glyphs into the font atlas and therefor make the atlas much smaller. - */ - - ImHexApi::Fonts::loadFont("Blender Icons", romfs::get("fonts/blendericons.ttf").span(),{ { ICON_MIN_BI, ICON_MAX_BI } }, { -1_scaled, -1_scaled }); - - ImHexApi::Fonts::loadFont("VS Codicons", romfs::get("fonts/codicons.ttf").span(), - { - { ICON_MIN_VS, ICON_MAX_VS } - }, - { 0, -2 }); - - ImHexApi::Fonts::loadFont("Unifont", romfs::get("fonts/unifont.otf").span(), { }, {}, 0, false, 16); + ImHexApi::Fonts::loadFont("Blender Icons", romfs::get("fonts/blendericons.ttf").span(), { -1, -1 }); + ImHexApi::Fonts::loadFont("VS Codicons", romfs::get("fonts/codicons.ttf").span(), { 0, -2 }); + ImHexApi::Fonts::loadFont("Unifont", romfs::get("fonts/unifont.otf").span(), { 0, 0 }, 10); } } \ No newline at end of file diff --git a/plugins/fonts/source/library_fonts.cpp b/plugins/fonts/source/library_fonts.cpp index 5510a6729..9f3bf0e70 100644 --- a/plugins/fonts/source/library_fonts.cpp +++ b/plugins/fonts/source/library_fonts.cpp @@ -63,7 +63,7 @@ namespace hex::fonts { if (*imguiFont == nullptr) { if (settings.isPixelPerfectFont()) { auto defaultConfig = config; - defaultConfig.SizePixels = ImHexApi::Fonts::DefaultFontSize; + defaultConfig.SizePixels = 0; *imguiFont = atlas->AddFontDefault(&defaultConfig); } else { static auto jetbrainsFont = romfs::get("fonts/JetBrainsMono.ttf"); @@ -81,7 +81,7 @@ namespace hex::fonts { for (auto &extraFont : ImHexApi::Fonts::impl::getMergeFonts()) { config.GlyphOffset = { extraFont.offset.x, -extraFont.offset.y }; config.GlyphOffset *= ImHexApi::System::getGlobalScale(); - atlas->AddFontFromMemoryTTF(const_cast(extraFont.fontData.data()), extraFont.fontData.size(), 0.0F, &config); + atlas->AddFontFromMemoryTTF(const_cast(extraFont.fontData.data()), extraFont.fontData.size(), extraFont.defaultSize.value_or(0), &config); } }