1
0
mirror of synced 2025-02-17 18:59:21 +01:00

impr: Load unifont at correct size

Fixes #1604
This commit is contained in:
WerWolv 2024-03-21 21:27:50 +01:00
parent 3b3701135f
commit 61b9c0970b
4 changed files with 13 additions and 9 deletions

View File

@ -704,6 +704,7 @@ namespace hex {
std::vector<GlyphRange> glyphRanges;
Offset offset;
u32 flags;
std::optional<u32> defaultSize;
};
namespace impl {
@ -722,8 +723,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<GlyphRange> &glyphRanges = {}, Offset offset = {}, u32 flags = 0);
void loadFont(const std::string &name, const std::span<const u8> &data, const std::vector<GlyphRange> &glyphRanges = {}, Offset offset = {}, u32 flags = 0);
void loadFont(const std::fs::path &path, const std::vector<GlyphRange> &glyphRanges = {}, Offset offset = {}, u32 flags = 0, std::optional<u32> defaultSize = std::nullopt);
void loadFont(const std::string &name, const std::span<const u8> &data, const std::vector<GlyphRange> &glyphRanges = {}, Offset offset = {}, u32 flags = 0, std::optional<u32> defaultSize = std::nullopt);
constexpr static float DefaultFontSize = 13.0;

View File

@ -920,7 +920,7 @@ namespace hex {
};
}
void loadFont(const std::fs::path &path, const std::vector<GlyphRange> &glyphRanges, Offset offset, u32 flags) {
void loadFont(const std::fs::path &path, const std::vector<GlyphRange> &glyphRanges, Offset offset, u32 flags, std::optional<u32> 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));
@ -932,17 +932,19 @@ namespace hex {
fontFile.readVector(),
glyphRanges,
offset,
flags
flags,
defaultSize
});
}
void loadFont(const std::string &name, const std::span<const u8> &data, const std::vector<GlyphRange> &glyphRanges, Offset offset, u32 flags) {
void loadFont(const std::string &name, const std::span<const u8> &data, const std::vector<GlyphRange> &glyphRanges, Offset offset, u32 flags, std::optional<u32> defaultSize) {
impl::s_fonts->emplace_back(Font {
name,
{ data.begin(), data.end() },
glyphRanges,
offset,
flags
flags,
defaultSize
});
}

View File

@ -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

View File

@ -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<u8>(),{ { ICON_MIN_BI, ICON_MAX_BI } }, { -1_scaled, -1_scaled });
ImHexApi::Fonts::loadFont("Blender Icons", romfs::get("fonts/blendericons.ttf").span<u8>(),{ { ICON_MIN_BI, ICON_MAX_BI } }, { -1_scaled, -1_scaled }, 0, 13);
ImHexApi::Fonts::loadFont("VS Codicons", romfs::get("fonts/codicons.ttf").span<u8>(),
{
{ 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<u8>());
ImHexApi::Fonts::loadFont("Unifont", romfs::get("fonts/unifont.otf").span<u8>(), {}, {}, 0, 16);
}
}