From 5a095cc993435df301950147bd327d843203f343 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 11 May 2025 17:42:36 +0200 Subject: [PATCH] fix: Icon scaling when using pixel perfect font --- plugins/fonts/source/font_loader.cpp | 4 ++-- plugins/fonts/source/font_settings.cpp | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/plugins/fonts/source/font_loader.cpp b/plugins/fonts/source/font_loader.cpp index c201d727d..d74274044 100644 --- a/plugins/fonts/source/font_loader.cpp +++ b/plugins/fonts/source/font_loader.cpp @@ -57,7 +57,7 @@ namespace hex::fonts { if (fontName.find("icon") != std::string::npos) actualFontSize = ImHexApi::Fonts::pointsToPixels(fontSize); else - actualFontSize = fontSize; + actualFontSize = fontSize; if (FT_Set_Pixel_Sizes(face, actualFontSize, actualFontSize) != 0) { log::fatal("Failed to set pixel size"); @@ -187,7 +187,7 @@ namespace hex::fonts { // If there's no custom font set, or it failed to load, fall back to the default font if (!defaultFont.has_value()) { if (pixelPerfectFont) { - fontSize = std::max(1.0F, std::floor(ImHexApi::System::getGlobalScale() * ImHexApi::System::getBackingScaleFactor() * 13.0F)); + realFontSize = fontSize = std::max(1.0F, std::floor(ImHexApi::System::getBackingScaleFactor() * 13.0F)); defaultFont = fontAtlas->addDefaultFont(); std::string defaultFontName = "Proggy Clean"; memcpy(fontAtlas->getAtlas()->ConfigData[fontIndex].Name, defaultFontName.c_str(), defaultFontName.size()); diff --git a/plugins/fonts/source/font_settings.cpp b/plugins/fonts/source/font_settings.cpp index dcbe12bcd..fdb994aef 100644 --- a/plugins/fonts/source/font_settings.cpp +++ b/plugins/fonts/source/font_settings.cpp @@ -101,13 +101,14 @@ namespace hex::fonts { } bool SliderPoints::draw(const std::string &name) { - float value = ImHexApi::Fonts::pixelsToPoints(m_value); - float min = ImHexApi::Fonts::pixelsToPoints(m_min); - float max = ImHexApi::Fonts::pixelsToPoints(m_max); + auto scaleFactor = ImHexApi::System::getBackingScaleFactor(); + float value = ImHexApi::Fonts::pixelsToPoints(m_value) * scaleFactor; + float min = ImHexApi::Fonts::pixelsToPoints(m_min) * scaleFactor; + float max = ImHexApi::Fonts::pixelsToPoints(m_max) * scaleFactor; auto changed = ImGui::SliderFloat(name.c_str(), &value, min, max, "%.0f pt"); - m_value = ImHexApi::Fonts::pointsToPixels(value); + m_value = ImHexApi::Fonts::pointsToPixels(value / scaleFactor); return changed; }