summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorVincent Robinson <robinsonvincent89@gmail.com>2021-12-30 12:54:21 -0800
committerGitHub <noreply@github.com>2021-12-30 12:54:21 -0800
commit4a16ab3585dafdf4d36b2807a1ee9507be64b363 (patch)
tree1e29c6719de7a9a2e9982cfe662c981b245523ab /src/client
parent14c7fae378fc40f88d3c430dea2cb726afc005b1 (diff)
downloadminetest-4a16ab3585dafdf4d36b2807a1ee9507be64b363.tar.gz
minetest-4a16ab3585dafdf4d36b2807a1ee9507be64b363.tar.bz2
minetest-4a16ab3585dafdf4d36b2807a1ee9507be64b363.zip
Improve TTF support for pixel-style fonts (#11848)
Diffstat (limited to 'src/client')
-rw-r--r--src/client/fontengine.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/client/fontengine.cpp b/src/client/fontengine.cpp
index 35e908b0c..e537b756c 100644
--- a/src/client/fontengine.cpp
+++ b/src/client/fontengine.cpp
@@ -66,11 +66,13 @@ FontEngine::FontEngine(gui::IGUIEnvironment* env) :
g_settings->registerChangedCallback("font_path_bolditalic", font_setting_changed, NULL);
g_settings->registerChangedCallback("font_shadow", font_setting_changed, NULL);
g_settings->registerChangedCallback("font_shadow_alpha", font_setting_changed, NULL);
+ g_settings->registerChangedCallback("font_size_divisible_by", font_setting_changed, NULL);
g_settings->registerChangedCallback("fallback_font_path", font_setting_changed, NULL);
}
g_settings->registerChangedCallback("mono_font_path", font_setting_changed, NULL);
g_settings->registerChangedCallback("mono_font_size", font_setting_changed, NULL);
+ g_settings->registerChangedCallback("mono_font_size_divisible_by", font_setting_changed, NULL);
g_settings->registerChangedCallback("screen_dpi", font_setting_changed, NULL);
g_settings->registerChangedCallback("gui_scaling", font_setting_changed, NULL);
}
@@ -252,15 +254,18 @@ gui::IGUIFont *FontEngine::initFont(const FontSpec &spec)
if (spec.italic)
setting_suffix.append("_italic");
- u32 size = std::floor(RenderingEngine::getDisplayDensity() *
- g_settings->getFloat("gui_scaling") * spec.size);
+ u32 size = std::max<u32>(spec.size * RenderingEngine::getDisplayDensity() *
+ g_settings->getFloat("gui_scaling"), 1);
- if (size == 0) {
- errorstream << "FontEngine: attempt to use font size 0" << std::endl;
- errorstream << " display density: " << RenderingEngine::getDisplayDensity() << std::endl;
- abort();
+ // Constrain the font size to a certain multiple, if necessary
+ u16 divisible_by = g_settings->getU16(setting_prefix + "font_size_divisible_by");
+ if (divisible_by > 1) {
+ size = std::max<u32>(
+ std::round((double)size / divisible_by) * divisible_by, divisible_by);
}
+ sanity_check(size != 0);
+
u16 font_shadow = 0;
u16 font_shadow_alpha = 0;
g_settings->getU16NoEx(setting_prefix + "font_shadow", font_shadow);