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"
25 #include "irrlichttypes.h"
28 #include <IGUIEnvironment.h>
31 #define FONT_SIZE_UNSPECIFIED 0xFFFFFFFF
36 _FM_Fallback, // do not use directly
44 FontSpec(unsigned int font_size, FontMode mode, bool bold, bool italic) :
52 return (mode << 2) | (static_cast<u8>(bold) << 1) | static_cast<u8>(italic);
65 FontEngine(gui::IGUIEnvironment* env);
69 // Get best possible font specified by FontSpec
70 irr::gui::IGUIFont *getFont(FontSpec spec);
72 irr::gui::IGUIFont *getFont(unsigned int font_size=FONT_SIZE_UNSPECIFIED,
73 FontMode mode=FM_Unspecified)
75 FontSpec spec(font_size, mode, m_default_bold, m_default_italic);
79 /** get text height for a specific font */
80 unsigned int getTextHeight(const FontSpec &spec);
82 /** get text width if a text for a specific font */
83 unsigned int getTextHeight(
84 unsigned int font_size=FONT_SIZE_UNSPECIFIED,
85 FontMode mode=FM_Unspecified)
87 FontSpec spec(font_size, mode, m_default_bold, m_default_italic);
88 return getTextHeight(spec);
91 unsigned int getTextWidth(const std::wstring &text, const FontSpec &spec);
93 /** get text width if a text for a specific font */
94 unsigned int getTextWidth(const std::wstring& text,
95 unsigned int font_size=FONT_SIZE_UNSPECIFIED,
96 FontMode mode=FM_Unspecified)
98 FontSpec spec(font_size, mode, m_default_bold, m_default_italic);
99 return getTextWidth(text, spec);
102 unsigned int getTextWidth(const std::string &text, const FontSpec &spec)
104 return getTextWidth(utf8_to_wide(text), spec);
107 unsigned int getTextWidth(const std::string& text,
108 unsigned int font_size=FONT_SIZE_UNSPECIFIED,
109 FontMode mode=FM_Unspecified)
111 FontSpec spec(font_size, mode, m_default_bold, m_default_italic);
112 return getTextWidth(utf8_to_wide(text), spec);
115 /** get line height for a specific font (including empty room between lines) */
116 unsigned int getLineHeight(const FontSpec &spec);
118 unsigned int getLineHeight(unsigned int font_size=FONT_SIZE_UNSPECIFIED,
119 FontMode mode=FM_Unspecified)
121 FontSpec spec(font_size, mode, m_default_bold, m_default_italic);
122 return getLineHeight(spec);
125 /** get default font size */
126 unsigned int getDefaultFontSize();
128 /** get font size for a specific mode */
129 unsigned int getFontSize(FontMode mode);
131 /** update internal parameters from settings */
135 irr::gui::IGUIFont *getFont(FontSpec spec, bool may_fail);
137 /** update content of font cache in case of a setting change made it invalid */
138 void updateFontCache();
140 /** initialize a new TTF font */
141 gui::IGUIFont *initFont(const FontSpec &spec);
143 /** initialize a font without freetype */
144 gui::IGUIFont *initSimpleFont(const FontSpec &spec);
146 /** update current minetest skin with font changes */
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;