summaryrefslogtreecommitdiff
path: root/src/client/fontengine.h
diff options
context:
space:
mode:
authorSmallJoker <mk939@ymail.com>2019-10-17 20:40:50 +0200
committerSmallJoker <SmallJoker@users.noreply.github.com>2019-11-03 11:45:33 +0100
commit388ea737f5d37d637556bf40890948bfc36734ce (patch)
tree2017f52301eb54bfd14d0da9804f337bc956a1f7 /src/client/fontengine.h
parent72416a6a1f75d56abfad0f486e57fd32579b3604 (diff)
downloadminetest-388ea737f5d37d637556bf40890948bfc36734ce.tar.gz
minetest-388ea737f5d37d637556bf40890948bfc36734ce.tar.bz2
minetest-388ea737f5d37d637556bf40890948bfc36734ce.zip
Clean up font caching, fix bitmap fonts
Diffstat (limited to 'src/client/fontengine.h')
-rw-r--r--src/client/fontengine.h68
1 files changed, 40 insertions, 28 deletions
diff --git a/src/client/fontengine.h b/src/client/fontengine.h
index ecffc7660..53f14c45f 100644
--- a/src/client/fontengine.h
+++ b/src/client/fontengine.h
@@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define FONT_SIZE_UNSPECIFIED 0xFFFFFFFF
-enum FontMode {
+enum FontMode : u8 {
FM_Standard = 0,
FM_Mono,
FM_Fallback,
@@ -39,6 +39,24 @@ enum FontMode {
FM_Unspecified
};
+struct FontSpec {
+ FontSpec(unsigned int font_size, FontMode mode, bool bold, bool italic) :
+ size(font_size),
+ mode(mode),
+ bold(bold),
+ italic(italic) {}
+
+ u16 getHash()
+ {
+ return (mode << 2) | (bold << 1) | italic;
+ }
+
+ unsigned int size;
+ FontMode mode;
+ bool bold;
+ bool italic;
+};
+
class FontEngine
{
public:
@@ -47,62 +65,60 @@ public:
~FontEngine();
- /** get Font */
- irr::gui::IGUIFont *getFont(unsigned int font_size, FontMode mode,
- bool bold, bool italic);
+ // Get best possible font specified by FontSpec
+ irr::gui::IGUIFont *getFont(FontSpec spec);
irr::gui::IGUIFont *getFont(unsigned int font_size=FONT_SIZE_UNSPECIFIED,
FontMode mode=FM_Unspecified)
{
- return getFont(font_size, mode, m_default_bold, m_default_italic);
+ FontSpec spec(font_size, mode, m_default_bold, m_default_italic);
+ return getFont(spec);
}
/** get text height for a specific font */
- unsigned int getTextHeight(unsigned int font_size, FontMode mode,
- bool bold, bool italic);
+ unsigned int getTextHeight(const FontSpec &spec);
/** get text width if a text for a specific font */
unsigned int getTextHeight(
unsigned int font_size=FONT_SIZE_UNSPECIFIED,
FontMode mode=FM_Unspecified)
{
- return getTextHeight(font_size, mode, m_default_bold, m_default_italic);
+ FontSpec spec(font_size, mode, m_default_bold, m_default_italic);
+ return getTextHeight(spec);
}
- unsigned int getTextWidth(const std::wstring& text,
- unsigned int font_size, FontMode mode, bool bold, bool italic);
+ unsigned int getTextWidth(const std::wstring &text, const FontSpec &spec);
/** get text width if a text for a specific font */
unsigned int getTextWidth(const std::wstring& text,
unsigned int font_size=FONT_SIZE_UNSPECIFIED,
FontMode mode=FM_Unspecified)
{
- return getTextWidth(text, font_size, mode, m_default_bold,
- m_default_italic);
+ FontSpec spec(font_size, mode, m_default_bold, m_default_italic);
+ return getTextWidth(text, spec);
}
- unsigned int getTextWidth(const std::string& text,
- unsigned int font_size, FontMode mode, bool bold, bool italic)
+ unsigned int getTextWidth(const std::string &text, const FontSpec &spec)
{
- return getTextWidth(utf8_to_wide(text), font_size, mode, bold, italic);
+ return getTextWidth(utf8_to_wide(text), spec);
}
unsigned int getTextWidth(const std::string& text,
unsigned int font_size=FONT_SIZE_UNSPECIFIED,
FontMode mode=FM_Unspecified)
{
- return getTextWidth(utf8_to_wide(text), font_size, mode, m_default_bold,
- m_default_italic);
+ FontSpec spec(font_size, mode, m_default_bold, m_default_italic);
+ return getTextWidth(utf8_to_wide(text), spec);
}
/** get line height for a specific font (including empty room between lines) */
- unsigned int getLineHeight(unsigned int font_size, FontMode mode, bool bold,
- bool italic);
+ unsigned int getLineHeight(const FontSpec &spec);
unsigned int getLineHeight(unsigned int font_size=FONT_SIZE_UNSPECIFIED,
FontMode mode=FM_Unspecified)
{
- return getLineHeight(font_size, mode, m_default_bold, m_default_italic);
+ FontSpec spec(font_size, mode, m_default_bold, m_default_italic);
+ return getLineHeight(spec);
}
/** get default font size */
@@ -119,14 +135,10 @@ private:
void updateFontCache();
/** initialize a new font */
- void initFont(
- unsigned int basesize,
- FontMode mode,
- bool bold,
- bool italic);
+ gui::IGUIFont *initFont(const FontSpec &spec);
/** initialize a font without freetype */
- void initSimpleFont(unsigned int basesize, FontMode mode);
+ gui::IGUIFont *initSimpleFont(const FontSpec &spec);
/** update current minetest skin with font changes */
void updateSkin();
@@ -147,8 +159,8 @@ private:
unsigned int m_default_size[FM_MaxMode];
/** default bold and italic */
- bool m_default_bold;
- bool m_default_italic;
+ bool m_default_bold = false;
+ bool m_default_italic = false;
/** current font engine mode */
FontMode m_currentMode = FM_Standard;