3 Copyright (C) 2010-2014 sapier <sapier at gmx dot net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "util/basic_macros.h"
27 #include <IGUIEnvironment.h>
30 #define FONT_SIZE_UNSPECIFIED 0xFFFFFFFF
46 FontEngine(Settings* main_settings, gui::IGUIEnvironment* env);
51 irr::gui::IGUIFont* getFont(unsigned int font_size=FONT_SIZE_UNSPECIFIED,
52 FontMode mode=FM_Unspecified);
54 /** get text height for a specific font */
55 unsigned int getTextHeight(unsigned int font_size=FONT_SIZE_UNSPECIFIED,
56 FontMode mode=FM_Unspecified);
58 /** get text width if a text for a specific font */
59 unsigned int getTextWidth(const std::string& text,
60 unsigned int font_size=FONT_SIZE_UNSPECIFIED,
61 FontMode mode=FM_Unspecified)
63 return getTextWidth(utf8_to_wide(text));
66 /** get text width if a text for a specific font */
67 unsigned int getTextWidth(const std::wstring& text,
68 unsigned int font_size=FONT_SIZE_UNSPECIFIED,
69 FontMode mode=FM_Unspecified);
71 /** get line height for a specific font (including empty room between lines) */
72 unsigned int getLineHeight(unsigned int font_size=FONT_SIZE_UNSPECIFIED,
73 FontMode mode=FM_Unspecified);
75 /** get default font size */
76 unsigned int getDefaultFontSize();
78 /** initialize font engine */
79 void initialize(Settings* main_settings, gui::IGUIEnvironment* env);
81 /** update internal parameters from settings */
85 /** update content of font cache in case of a setting change made it invalid */
86 void updateFontCache();
88 /** initialize a new font */
89 void initFont(unsigned int basesize, FontMode mode=FM_Unspecified);
91 /** initialize a font without freetype */
92 void initSimpleFont(unsigned int basesize, FontMode mode);
94 /** update current minetest skin with font changes */
100 /** pointer to settings for registering callbacks or reading config */
101 Settings* m_settings = nullptr;
103 /** pointer to irrlicht gui environment */
104 gui::IGUIEnvironment* m_env = nullptr;
106 /** internal storage for caching fonts of different size */
107 std::map<unsigned int, irr::gui::IGUIFont*> m_font_cache[FM_MaxMode];
109 /** default font size to use */
110 unsigned int m_default_size[FM_MaxMode];
112 /** current font engine mode */
113 FontMode m_currentMode = FM_Standard;
115 /** font mode of last request */
118 /** size of last request */
119 unsigned int m_lastSize = 0;
121 /** last font returned */
122 irr::gui::IGUIFont* m_lastFont = nullptr;
124 DISABLE_CLASS_COPY(FontEngine);
127 /** interface to access main font engine*/
128 extern FontEngine* g_fontengine;