From 3fccd03bbbfa736fafa0d1b8c053af2be135070c Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 14 Nov 2022 10:02:34 +0100 Subject: [PATCH] fix: Black screen issues when font atlas got too big --- main/source/init/tasks.cpp | 11 +++++------ main/source/window/window.cpp | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/main/source/init/tasks.cpp b/main/source/init/tasks.cpp index 2a80b42a0..e7daeb437 100644 --- a/main/source/init/tasks.cpp +++ b/main/source/init/tasks.cpp @@ -83,7 +83,6 @@ namespace hex::init { } bool loadFonts() { - const auto scale = ImHexApi::System::getNativeScale(); float fontSize = ImHexApi::System::getFontSize(); const auto &fontFile = ImHexApi::System::getCustomFontPath(); @@ -91,7 +90,7 @@ namespace hex::init { auto fonts = IM_NEW(ImFontAtlas)(); ImFontConfig cfg = {}; cfg.OversampleH = cfg.OversampleV = 1, cfg.PixelSnapH = true; - cfg.SizePixels = fontSize * scale; + cfg.SizePixels = fontSize; ImVector ranges; { @@ -125,17 +124,17 @@ namespace hex::init { fonts->AddFontDefault(&cfg); } else { // Load custom font - fonts->AddFontFromFileTTF(hex::toUTF8String(fontFile).c_str(), std::floor(fontSize * scale), &cfg, ranges.Data); // Needs conversion to char for Windows + fonts->AddFontFromFileTTF(hex::toUTF8String(fontFile).c_str(), 0, &cfg, ranges.Data); // Needs conversion to char for Windows } cfg.MergeMode = true; - fonts->AddFontFromMemoryCompressedTTF(font_awesome_compressed_data, font_awesome_compressed_size, fontSize * scale, &cfg, fontAwesomeRange); - fonts->AddFontFromMemoryCompressedTTF(codicons_compressed_data, codicons_compressed_size, fontSize * scale, &cfg, codiconsRange); + fonts->AddFontFromMemoryCompressedTTF(font_awesome_compressed_data, font_awesome_compressed_size, 0, &cfg, fontAwesomeRange); + fonts->AddFontFromMemoryCompressedTTF(codicons_compressed_data, codicons_compressed_size, 0, &cfg, codiconsRange); bool enableUnicode = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.enable_unicode", true); if (enableUnicode) - fonts->AddFontFromMemoryCompressedTTF(unifont_compressed_data, unifont_compressed_size, fontSize * scale, &cfg, unifontRange); + fonts->AddFontFromMemoryCompressedTTF(unifont_compressed_data, unifont_compressed_size, 0, &cfg, unifontRange); fonts->Build(); diff --git a/main/source/window/window.cpp b/main/source/window/window.cpp index d6d06db17..746283c2e 100644 --- a/main/source/window/window.cpp +++ b/main/source/window/window.cpp @@ -464,7 +464,7 @@ namespace hex { continue; if (view->isAvailable()) { - float fontScaling = std::max(1.0F, ImHexApi::System::getFontSize() / ImHexApi::System::DefaultFontSize); + float fontScaling = std::max(1.0F, ImHexApi::System::getFontSize() / ImHexApi::System::DefaultFontSize) * ImHexApi::System::getGlobalScale(); ImGui::SetNextWindowSizeConstraints(view->getMinSize() * fontScaling, view->getMaxSize() * fontScaling); view->drawContent(); } @@ -690,7 +690,7 @@ namespace hex { io.ConfigFlags |= ImGuiConfigFlags_DockingEnable | ImGuiConfigFlags_NavEnableKeyboard; io.ConfigWindowsMoveFromTitleBarOnly = true; - io.FontGlobalScale = 1.0F / ImHexApi::System::getNativeScale(); + io.FontGlobalScale = 1.0F; if (glfwGetPrimaryMonitor() != nullptr) { auto sessionType = hex::getEnvironmentVariable("XDG_SESSION_TYPE");