LocalPlayer::accelerateHorizontal: cleanups
[oweals/minetest.git] / src / fontengine.cpp
index fa30b403813795a15ce3662d9117e835e63f046a..a4d96e0787388101684843a8d1554957bd8ad941 100644 (file)
@@ -16,17 +16,16 @@ You should have received a copy of the GNU Lesser General Public License along
 with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
+
 #include "fontengine.h"
-#include "log.h"
-#include "main.h"
+#include "client/renderingengine.h"
 #include "config.h"
 #include "porting.h"
-#include "constants.h"
 #include "filesys.h"
 
 #if USE_FREETYPE
 #include "gettext.h"
-#include "xCGUITTFont.h"
+#include "irrlicht_changes/CGUITTFont.h"
 #endif
 
 /** maximum size distance for getting a "similar" font size */
@@ -36,19 +35,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 FontEngine* g_fontengine = NULL;
 
 /** callback to be used on change of font size setting */
-static void font_setting_changed(const std::string, void *userdata) {
+static void font_setting_changed(const std::string &name, void *userdata)
+{
        g_fontengine->readSettings();
 }
 
 /******************************************************************************/
 FontEngine::FontEngine(Settings* main_settings, gui::IGUIEnvironment* env) :
        m_settings(main_settings),
-       m_env(env),
-       m_font_cache(),
-       m_currentMode(FM_Standard),
-       m_lastMode(),
-       m_lastSize(0),
-       m_lastFont(NULL)
+       m_env(env)
 {
 
        for (unsigned int i = 0; i < FM_MaxMode; i++) {
@@ -122,7 +117,7 @@ void FontEngine::cleanCache()
 
                for (std::map<unsigned int, irr::gui::IGUIFont*>::iterator iter
                                = m_font_cache[i].begin();
-                               iter != m_font_cache[i].end(); iter++) {
+                               iter != m_font_cache[i].end(); ++iter) {
                        iter->second->drop();
                        iter->second = NULL;
                }
@@ -319,10 +314,8 @@ void FontEngine::initFont(unsigned int basesize, FontMode mode)
                if (! is_yes(m_settings->get("freetype"))) {
                        return;
                }
-               unsigned int size = floor(
-                               porting::getDisplayDensity() *
-                               m_settings->getFloat("gui_scaling") *
-                               basesize);
+               unsigned int size = floor(RenderingEngine::getDisplayDensity() *
+                               m_settings->getFloat("gui_scaling") * basesize);
                u32 font_shadow       = 0;
                u32 font_shadow_alpha = 0;
 
@@ -343,11 +336,31 @@ void FontEngine::initFont(unsigned int basesize, FontMode mode)
 
                if (font != NULL) {
                        m_font_cache[mode][basesize] = font;
+                       return;
                }
-               else {
-                       errorstream << "FontEngine: failed to load freetype font: "
-                                       << font_path << std::endl;
+
+               // try fallback font
+               errorstream << "FontEngine: failed to load: " << font_path << ", trying to fall back "
+                               "to fallback font" << std::endl;
+
+               font_path = g_settings->get(font_config_prefix + "fallback_font_path");
+
+               font = gui::CGUITTFont::createTTFont(m_env,
+                       font_path.c_str(), size, true, true, font_shadow,
+                       font_shadow_alpha);
+
+               if (font != NULL) {
+                       m_font_cache[mode][basesize] = font;
+                       return;
                }
+
+               // give up
+               errorstream << "FontEngine: failed to load freetype font: "
+                               << font_path << std::endl;
+               errorstream << "minetest can not continue without a valid font. Please correct "
+                               "the 'font_path' setting or install the font file in the proper "
+                               "location" << std::endl;
+               abort();
        }
 #endif
 }
@@ -380,7 +393,7 @@ void FontEngine::initSimpleFont(unsigned int basesize, FontMode mode)
                basesize = DEFAULT_FONT_SIZE;
 
        unsigned int size = floor(
-                       porting::getDisplayDensity() *
+                       RenderingEngine::getDisplayDensity() *
                        m_settings->getFloat("gui_scaling") *
                        basesize);