1
0
mirror of synced 2025-02-26 06:18:05 +01:00

sys: Try to not load unifont if graphics drivers can't handle it

This commit is contained in:
WerWolv 2022-12-14 09:25:37 +01:00
parent e3f2541fde
commit f23351f11c

View File

@ -91,7 +91,7 @@ namespace hex::init {
return result; return result;
} }
bool loadFonts() { static bool loadFontsImpl(bool loadUnicode) {
float fontSize = ImHexApi::System::getFontSize(); float fontSize = ImHexApi::System::getFontSize();
const auto &fontFile = ImHexApi::System::getCustomFontPath(); const auto &fontFile = ImHexApi::System::getCustomFontPath();
@ -122,10 +122,6 @@ namespace hex::init {
ICON_MIN_VS, ICON_MAX_VS, 0 ICON_MIN_VS, ICON_MAX_VS, 0
}; };
ImWchar unifontRange[] = {
0x0100, 0xFFF0, 0
};
if (fontFile.empty()) { if (fontFile.empty()) {
// Load default font if no custom one has been specified // Load default font if no custom one has been specified
@ -133,7 +129,7 @@ namespace hex::init {
fonts->AddFontDefault(&cfg); fonts->AddFontDefault(&cfg);
} else { } else {
// Load custom font // Load custom font
fonts->AddFontFromFileTTF(hex::toUTF8String(fontFile).c_str(), 0, &cfg, ranges.Data); // Needs conversion to char for Windows fonts->AddFontFromFileTTF(hex::toUTF8String(fontFile).c_str(), 0, &cfg, ranges.Data);
} }
cfg.MergeMode = true; cfg.MergeMode = true;
@ -141,11 +137,20 @@ namespace hex::init {
fonts->AddFontFromMemoryCompressedTTF(font_awesome_compressed_data, font_awesome_compressed_size, 0, &cfg, fontAwesomeRange); fonts->AddFontFromMemoryCompressedTTF(font_awesome_compressed_data, font_awesome_compressed_size, 0, &cfg, fontAwesomeRange);
fonts->AddFontFromMemoryCompressedTTF(codicons_compressed_data, codicons_compressed_size, 0, &cfg, codiconsRange); 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 (loadUnicode)
if (enableUnicode) fonts->AddFontFromMemoryCompressedTTF(unifont_compressed_data, unifont_compressed_size, 0, &cfg, ranges.Data);
fonts->AddFontFromMemoryCompressedTTF(unifont_compressed_data, unifont_compressed_size, 0, &cfg, unifontRange);
fonts->Build(); if (!fonts->Build()) {
if (loadUnicode) {
log::error("Failed to build font atlas! Disabling Unicode support.");
ContentRegistry::Settings::write("hex.builtin.setting.general", "hex.builtin.setting.general.enable_unicode", false);
IM_DELETE(fonts);
return loadFontsImpl(false);
} else {
log::error("Failed to build font atlas! Check your Graphics driver!");
return false;
}
}
View::setFontAtlas(fonts); View::setFontAtlas(fonts);
View::setFontConfig(cfg); View::setFontConfig(cfg);
@ -153,6 +158,10 @@ namespace hex::init {
return true; return true;
} }
bool loadFonts() {
return loadFontsImpl(ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.enable_unicode", true));
}
bool deleteSharedData() { bool deleteSharedData() {
EventManager::clear(); EventManager::clear();