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
43 FontSpec(unsigned int font_size, FontMode mode, bool bold, bool italic) :
51 return (mode << 2) | (bold << 1) | italic;
64 FontEngine(Settings* main_settings, gui::IGUIEnvironment* env);
68 // Get best possible font specified by FontSpec
69 irr::gui::IGUIFont *getFont(FontSpec spec);
71 irr::gui::IGUIFont *getFont(unsigned int font_size=FONT_SIZE_UNSPECIFIED,
72 FontMode mode=FM_Unspecified)
74 FontSpec spec(font_size, mode, m_default_bold, m_default_italic);
78 /** get text height for a specific font */
79 unsigned int getTextHeight(const FontSpec &spec);
81 /** get text width if a text for a specific font */
82 unsigned int getTextHeight(
83 unsigned int font_size=FONT_SIZE_UNSPECIFIED,
84 FontMode mode=FM_Unspecified)
86 FontSpec spec(font_size, mode, m_default_bold, m_default_italic);
87 return getTextHeight(spec);
90 unsigned int getTextWidth(const std::wstring &text, const FontSpec &spec);
92 /** get text width if a text for a specific font */
93 unsigned int getTextWidth(const std::wstring& text,
94 unsigned int font_size=FONT_SIZE_UNSPECIFIED,
95 FontMode mode=FM_Unspecified)
97 FontSpec spec(font_size, mode, m_default_bold, m_default_italic);
98 return getTextWidth(text, spec);
101 unsigned int getTextWidth(const std::string &text, const FontSpec &spec)
103 return getTextWidth(utf8_to_wide(text), spec);
106 unsigned int getTextWidth(const std::string& text,
107 unsigned int font_size=FONT_SIZE_UNSPECIFIED,
108 FontMode mode=FM_Unspecified)
110 FontSpec spec(font_size, mode, m_default_bold, m_default_italic);
111 return getTextWidth(utf8_to_wide(text), spec);
114 /** get line height for a specific font (including empty room between lines) */
115 unsigned int getLineHeight(const FontSpec &spec);
117 unsigned int getLineHeight(unsigned int font_size=FONT_SIZE_UNSPECIFIED,
118 FontMode mode=FM_Unspecified)
120 FontSpec spec(font_size, mode, m_default_bold, m_default_italic);
121 return getLineHeight(spec);
124 /** get default font size */
125 unsigned int getDefaultFontSize();
127 /** initialize font engine */
128 void initialize(Settings* main_settings, gui::IGUIEnvironment* env);
130 /** update internal parameters from settings */
134 /** update content of font cache in case of a setting change made it invalid */
135 void updateFontCache();
137 /** initialize a new font */
138 gui::IGUIFont *initFont(const FontSpec &spec);
140 /** initialize a font without freetype */
141 gui::IGUIFont *initSimpleFont(const FontSpec &spec);
143 /** update current minetest skin with font changes */
149 /** pointer to settings for registering callbacks or reading config */
150 Settings* m_settings = nullptr;
152 /** pointer to irrlicht gui environment */
153 gui::IGUIEnvironment* m_env = nullptr;
155 /** internal storage for caching fonts of different size */
156 std::map<unsigned int, irr::gui::IGUIFont*> m_font_cache[FM_MaxMode << 2];
158 /** default font size to use */
159 unsigned int m_default_size[FM_MaxMode];
161 /** default bold and italic */
162 bool m_default_bold = false;
163 bool m_default_italic = false;
165 /** current font engine mode */
166 FontMode m_currentMode = FM_Standard;
168 DISABLE_CLASS_COPY(FontEngine);
171 /** interface to access main font engine*/
172 extern FontEngine* g_fontengine;