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.
19 #ifndef __FONTENGINE_H__
20 #define __FONTENGINE_H__
26 #include "IGUIEnvironment.h"
29 #define FONT_SIZE_UNSPECIFIED 0xFFFFFFFF
45 FontEngine(Settings* main_settings, gui::IGUIEnvironment* env);
50 irr::gui::IGUIFont* getFont(unsigned int font_size=FONT_SIZE_UNSPECIFIED,
51 FontMode mode=FM_Unspecified);
53 /** get text height for a specific font */
54 unsigned int getTextHeight(unsigned int font_size=FONT_SIZE_UNSPECIFIED,
55 FontMode mode=FM_Unspecified);
57 /** get text width if a text for a specific font */
58 unsigned int getTextWidth(const std::string& text,
59 unsigned int font_size=FONT_SIZE_UNSPECIFIED,
60 FontMode mode=FM_Unspecified)
62 return getTextWidth(utf8_to_wide(text));
65 /** get text width if a text for a specific font */
66 unsigned int getTextWidth(const std::wstring& text,
67 unsigned int font_size=FONT_SIZE_UNSPECIFIED,
68 FontMode mode=FM_Unspecified);
70 /** get line height for a specific font (including empty room between lines) */
71 unsigned int getLineHeight(unsigned int font_size=FONT_SIZE_UNSPECIFIED,
72 FontMode mode=FM_Unspecified);
74 /** get default font size */
75 unsigned int getDefaultFontSize();
77 /** initialize font engine */
78 void initialize(Settings* main_settings, gui::IGUIEnvironment* env);
80 /** update internal parameters from settings */
84 /** disable copy constructor */
89 m_currentMode(FM_Standard),
95 /** update content of font cache in case of a setting change made it invalid */
96 void updateFontCache();
98 /** initialize a new font */
99 void initFont(unsigned int basesize, FontMode mode=FM_Unspecified);
101 /** initialize a font without freetype */
102 void initSimpleFont(unsigned int basesize, FontMode mode);
104 /** update current minetest skin with font changes */
110 /** pointer to settings for registering callbacks or reading config */
111 Settings* m_settings;
113 /** pointer to irrlicht gui environment */
114 gui::IGUIEnvironment* m_env;
116 /** internal storage for caching fonts of different size */
117 std::map<unsigned int, irr::gui::IGUIFont*> m_font_cache[FM_MaxMode];
119 /** default font size to use */
120 unsigned int m_default_size[FM_MaxMode];
122 /** current font engine mode */
123 FontMode m_currentMode;
125 /** font mode of last request */
128 /** size of last request */
129 unsigned int m_lastSize;
131 /** last font returned */
132 irr::gui::IGUIFont* m_lastFont;
136 /** interface to access main font engine*/
137 extern FontEngine* g_fontengine;