Skip to content

Commit 2af5864

Browse files
committedAug 4, 2013
Make freetype usage configureable by a setting
1 parent 3fd84ed commit 2af5864

8 files changed

+48
-14
lines changed
 
File renamed without changes.
File renamed without changes.

‎minetest.conf.example

+3
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@
189189
# File in client/serverlist/ that contains your favorite servers displayed in the Multiplayer Tab
190190
#serverlist_file = favoriteservers.txt
191191

192+
# Whether freetype fonts are used, requires freetype support to be compiled in
193+
#freetype = true
194+
# Path to TrueTypeFont or bitmap
192195
#font_path = fonts/liberationsans.ttf
193196
#font_size = 13
194197
#mono_font_path = fonts/liberationmono.ttf

‎src/defaultsettings.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
1919

2020
#include "settings.h"
2121
#include "filesys.h"
22+
#include "config.h"
2223

2324
void set_default_settings(Settings *settings)
2425
{
@@ -141,10 +142,17 @@ void set_default_settings(Settings *settings)
141142
settings->setDefault("server_name", "");
142143
settings->setDefault("server_description", "");
143144

145+
#if USE_FREETYPE
146+
settings->setDefault("freetype", "true");
144147
settings->setDefault("font_path", porting::getDataPath("fonts" DIR_DELIM "liberationsans.ttf"));
145148
settings->setDefault("font_size", "13");
146149
settings->setDefault("mono_font_path", porting::getDataPath("fonts" DIR_DELIM "liberationmono.ttf"));
147150
settings->setDefault("mono_font_size", "13");
151+
#else
152+
settings->setDefault("freetype", "false");
153+
settings->setDefault("font_path", porting::getDataPath("fonts" DIR_DELIM "fontlucida.png"));
154+
settings->setDefault("mono_font_path", porting::getDataPath("textures" DIR_DELIM "fontdejavusansmono.png"));
155+
#endif
148156

149157
// Server stuff
150158
// "map-dir" doesn't exist by default.

‎src/guiChatConsole.cpp

+11-6
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,17 @@ GUIChatConsole::GUIChatConsole(
9494

9595
// load the font
9696
// FIXME should a custom texture_path be searched too?
97-
#if USE_FREETYPE
9897
std::string font_name = g_settings->get("mono_font_path");
99-
u16 font_size = g_settings->getU16("mono_font_size");
100-
m_font = gui::CGUITTFont::createTTFont(env, font_name.c_str(), font_size);
98+
#if USE_FREETYPE
99+
m_use_freetype = g_settings->getBool("freetype");
100+
if (m_use_freetype) {
101+
u16 font_size = g_settings->getU16("mono_font_size");
102+
m_font = gui::CGUITTFont::createTTFont(env, font_name.c_str(), font_size);
103+
} else {
104+
m_font = env->getFont(font_name.c_str());
105+
}
101106
#else
102-
std::string font_name = "fontdejavusansmono.png";
103-
m_font = env->getFont(getTexturePath(font_name).c_str());
107+
m_font = env->getFont(font_name.c_str());
104108
#endif
105109
if (m_font == NULL)
106110
{
@@ -122,7 +126,8 @@ GUIChatConsole::GUIChatConsole(
122126
GUIChatConsole::~GUIChatConsole()
123127
{
124128
#if USE_FREETYPE
125-
m_font->drop();
129+
if (m_use_freetype)
130+
m_font->drop();
126131
#endif
127132
}
128133

‎src/guiChatConsole.h

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2222

2323
#include "irrlichttypes_extrabloated.h"
2424
#include "chat.h"
25+
#include "config.h"
2526

2627
class Client;
2728

@@ -121,6 +122,9 @@ class GUIChatConsole : public gui::IGUIElement
121122
// font
122123
gui::IGUIFont* m_font;
123124
v2u32 m_fontsize;
125+
#if USE_FREETYPE
126+
bool m_use_freetype;
127+
#endif
124128
};
125129

126130

‎src/guiTextInputMenu.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2020
#include "guiTextInputMenu.h"
2121
#include "debug.h"
2222
#include "serialization.h"
23+
#include "main.h" // for g_settings
24+
#include "settings.h"
2325
#include <string>
2426
#include <IGUICheckBox.h>
2527
#include <IGUIEditBox.h>
@@ -109,11 +111,16 @@ void GUITextInputMenu::regenerateGui(v2u32 screensize)
109111
{
110112
core::rect<s32> rect(0, 0, 300, 30);
111113
rect = rect + v2s32(size.X/2-300/2, size.Y/2-30/2-25);
114+
gui::IGUIElement *e;
112115
#if USE_FREETYPE
113-
gui::IGUIElement *e = (gui::IGUIElement *) new gui::intlGUIEditBox(text.c_str(), true, Environment, this, 256, rect);
114-
e->drop();
116+
if (g_settings->getBool("freetype")) {
117+
e = (gui::IGUIElement *) new gui::intlGUIEditBox(text.c_str(), true, Environment, this, 256, rect);
118+
e->drop();
119+
} else {
120+
e = Environment->addEditBox(text.c_str(), rect, true, this, 256);
121+
}
115122
#else
116-
gui::IGUIElement *e = Environment->addEditBox(text.c_str(), rect, true, this, 256);
123+
e = Environment->addEditBox(text.c_str(), rect, true, this, 256);
117124
#endif
118125
Environment->setFocus(e);
119126

‎src/main.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -1388,12 +1388,18 @@ int main(int argc, char *argv[])
13881388

13891389
guienv = device->getGUIEnvironment();
13901390
gui::IGUISkin* skin = guienv->getSkin();
1391-
#if USE_FREETYPE
13921391
std::string font_path = g_settings->get("font_path");
1393-
u16 font_size = g_settings->getU16("font_size");
1394-
gui::IGUIFont *font = gui::CGUITTFont::createTTFont(guienv, font_path.c_str(), font_size);
1392+
gui::IGUIFont *font;
1393+
bool use_freetype = g_settings->getBool("freetype");
1394+
#if USE_FREETYPE
1395+
if (use_freetype) {
1396+
u16 font_size = g_settings->getU16("font_size");
1397+
font = gui::CGUITTFont::createTTFont(guienv, font_path.c_str(), font_size);
1398+
} else {
1399+
font = guienv->getFont(font_path.c_str());
1400+
}
13951401
#else
1396-
gui::IGUIFont* font = guienv->getFont(getTexturePath("fontlucida.png").c_str());
1402+
font = guienv->getFont(font_path.c_str());
13971403
#endif
13981404
if(font)
13991405
skin->setFont(font);
@@ -1736,7 +1742,8 @@ int main(int argc, char *argv[])
17361742
device->drop();
17371743

17381744
#if USE_FREETYPE
1739-
font->drop();
1745+
if (use_freetype)
1746+
font->drop();
17401747
#endif
17411748

17421749
#endif // !SERVER

0 commit comments

Comments
 (0)
Please sign in to comment.