diff --git a/lib/libimhex/include/hex/api/imhex_api.hpp b/lib/libimhex/include/hex/api/imhex_api.hpp index 0675b8960..34d48c202 100644 --- a/lib/libimhex/include/hex/api/imhex_api.hpp +++ b/lib/libimhex/include/hex/api/imhex_api.hpp @@ -698,6 +698,7 @@ namespace hex { std::vector glyphRanges; Offset offset; u32 flags; + std::optional defaultSize; }; namespace impl { @@ -716,8 +717,8 @@ namespace hex { 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); - void loadFont(const std::string &name, const std::span &data, const std::vector &glyphRanges = {}, Offset offset = {}, u32 flags = 0); + void loadFont(const std::fs::path &path, const std::vector &glyphRanges = {}, Offset offset = {}, u32 flags = 0, 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 defaultSize = std::nullopt); constexpr static float DefaultFontSize = 13.0; diff --git a/lib/libimhex/source/api/imhex_api.cpp b/lib/libimhex/source/api/imhex_api.cpp index 41e99a08c..94c9d2faf 100644 --- a/lib/libimhex/source/api/imhex_api.cpp +++ b/lib/libimhex/source/api/imhex_api.cpp @@ -915,7 +915,7 @@ namespace hex { }; } - void loadFont(const std::fs::path &path, const std::vector &glyphRanges, Offset offset, u32 flags) { + void loadFont(const std::fs::path &path, const std::vector &glyphRanges, Offset offset, u32 flags, 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)); @@ -927,17 +927,19 @@ namespace hex { fontFile.readVector(), glyphRanges, offset, - flags + flags, + defaultSize }); } - void loadFont(const std::string &name, const std::span &data, const std::vector &glyphRanges, Offset offset, u32 flags) { + void loadFont(const std::string &name, const std::span &data, const std::vector &glyphRanges, Offset offset, u32 flags, std::optional defaultSize) { impl::s_fonts->emplace_back(Font { name, { data.begin(), data.end() }, glyphRanges, offset, - flags + flags, + defaultSize }); } diff --git a/plugins/builtin/source/content/init_tasks.cpp b/plugins/builtin/source/content/init_tasks.cpp index 50bb0605f..c9de53b8f 100644 --- a/plugins/builtin/source/content/init_tasks.cpp +++ b/plugins/builtin/source/content/init_tasks.cpp @@ -278,6 +278,7 @@ namespace hex::plugin::builtin { // Disable merge mode for this font but retain the rest of the configuration cfg.MergeMode = false; + cfg.SizePixels = font.defaultSize.value_or(fontSize); ON_SCOPE_EXIT { cfg.MergeMode = true; }; // Construct a range that only contains the first glyph of the font diff --git a/plugins/fonts/source/fonts.cpp b/plugins/fonts/source/fonts.cpp index 8c7af8ec9..1cf3c2c18 100644 --- a/plugins/fonts/source/fonts.cpp +++ b/plugins/fonts/source/fonts.cpp @@ -18,15 +18,15 @@ namespace hex::fonts { * 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("Blender Icons", romfs::get("fonts/blendericons.ttf").span(),{ { ICON_MIN_BI, ICON_MAX_BI } }, { -1_scaled, -1_scaled }, 0, 13); ImHexApi::Fonts::loadFont("VS Codicons", romfs::get("fonts/codicons.ttf").span(), { { ICON_MIN_VS, ICON_MAX_VS } }, - { -1_scaled, -1_scaled }); + { -1_scaled, -1_scaled }, 0, 13); - ImHexApi::Fonts::loadFont("Unifont", romfs::get("fonts/unifont.otf").span()); + ImHexApi::Fonts::loadFont("Unifont", romfs::get("fonts/unifont.otf").span(), {}, {}, 0, 16); } } \ No newline at end of file