-
-/** initialize a font without freetype */
-gui::IGUIFont *FontEngine::initSimpleFont(const FontSpec &spec)
-{
- assert(spec.mode == FM_Simple || spec.mode == FM_SimpleMono);
- assert(spec.size != FONT_SIZE_UNSPECIFIED);
-
- const std::string &font_path = g_settings->get(
- (spec.mode == FM_SimpleMono) ? "mono_font_path" : "font_path");
-
- size_t pos_dot = font_path.find_last_of('.');
- std::string basename = font_path, ending;
- if (pos_dot != std::string::npos)
- ending = lowercase(font_path.substr(pos_dot));
-
- if (ending == ".ttf") {
- errorstream << "FontEngine: Found font \"" << font_path
- << "\" but freetype is not available." << std::endl;
- return nullptr;
- }
-
- if (ending == ".xml" || ending == ".png")
- basename = font_path.substr(0, pos_dot);
-
- u32 size = std::floor(
- RenderingEngine::getDisplayDensity() *
- g_settings->getFloat("gui_scaling") *
- spec.size);
-
- irr::gui::IGUIFont *font = nullptr;
- std::string font_extensions[] = { ".png", ".xml" };
-
- // Find nearest matching font scale
- // Does a "zig-zag motion" (positibe/negative), from 0 to MAX_FONT_SIZE_OFFSET
- for (s32 zoffset = 0; zoffset < MAX_FONT_SIZE_OFFSET * 2; zoffset++) {
- std::stringstream path;
-
- // LSB to sign
- s32 sign = (zoffset & 1) ? -1 : 1;
- s32 offset = zoffset >> 1;
-
- for (const std::string &ext : font_extensions) {
- path.str(""); // Clear
- path << basename << "_" << (size + offset * sign) << ext;
-
- if (!fs::PathExists(path.str()))
- continue;
-
- font = m_env->getFont(path.str().c_str());
-
- if (font) {
- verbosestream << "FontEngine: found font: " << path.str() << std::endl;
- break;
- }
- }
-
- if (font)
- break;
- }
-
- // try name direct
- if (font == NULL) {
- if (fs::PathExists(font_path)) {
- font = m_env->getFont(font_path.c_str());
- if (font)
- verbosestream << "FontEngine: found font: " << font_path << std::endl;
- }
- }
-
- return font;
-}