diff --git a/fonts/fontdejavusansmono.png b/fonts/fontdejavusansmono.png
deleted file mode 100644
index 02ad41352..000000000
Binary files a/fonts/fontdejavusansmono.png and /dev/null differ
diff --git a/fonts/fontlucida.png b/fonts/fontlucida.png
deleted file mode 100644
index ab7bb70b8..000000000
Binary files a/fonts/fontlucida.png and /dev/null differ
diff --git a/fonts/liberation_sans_14.xml b/fonts/liberation_sans_14.xml
new file mode 100644
index 000000000..c17cd046d
--- /dev/null
+++ b/fonts/liberation_sans_14.xml
@@ -0,0 +1,100 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/fonts/liberation_sans_14_img.png b/fonts/liberation_sans_14_img.png
new file mode 100644
index 000000000..3b1fcc060
Binary files /dev/null and b/fonts/liberation_sans_14_img.png differ
diff --git a/fonts/lucida_sans_10.xml b/fonts/lucida_sans_10.xml
new file mode 100755
index 000000000..d54e9f6a6
Binary files /dev/null and b/fonts/lucida_sans_10.xml differ
diff --git a/fonts/lucida_sans_100.png b/fonts/lucida_sans_100.png
new file mode 100755
index 000000000..1c9ca6590
Binary files /dev/null and b/fonts/lucida_sans_100.png differ
diff --git a/fonts/lucida_sans_11.xml b/fonts/lucida_sans_11.xml
new file mode 100755
index 000000000..33d06c376
Binary files /dev/null and b/fonts/lucida_sans_11.xml differ
diff --git a/fonts/lucida_sans_110.png b/fonts/lucida_sans_110.png
new file mode 100755
index 000000000..77625492c
Binary files /dev/null and b/fonts/lucida_sans_110.png differ
diff --git a/fonts/lucida_sans_12.xml b/fonts/lucida_sans_12.xml
new file mode 100755
index 000000000..382981dcf
Binary files /dev/null and b/fonts/lucida_sans_12.xml differ
diff --git a/fonts/lucida_sans_120.png b/fonts/lucida_sans_120.png
new file mode 100755
index 000000000..e05ee0fda
Binary files /dev/null and b/fonts/lucida_sans_120.png differ
diff --git a/fonts/lucida_sans_14.xml b/fonts/lucida_sans_14.xml
new file mode 100755
index 000000000..99398d792
Binary files /dev/null and b/fonts/lucida_sans_14.xml differ
diff --git a/fonts/lucida_sans_140.png b/fonts/lucida_sans_140.png
new file mode 100755
index 000000000..5ef95e088
Binary files /dev/null and b/fonts/lucida_sans_140.png differ
diff --git a/fonts/lucida_sans_16.xml b/fonts/lucida_sans_16.xml
new file mode 100755
index 000000000..b07c1119f
Binary files /dev/null and b/fonts/lucida_sans_16.xml differ
diff --git a/fonts/lucida_sans_160.png b/fonts/lucida_sans_160.png
new file mode 100755
index 000000000..cb07e3f48
Binary files /dev/null and b/fonts/lucida_sans_160.png differ
diff --git a/fonts/lucida_sans_18.xml b/fonts/lucida_sans_18.xml
new file mode 100755
index 000000000..881aff18d
Binary files /dev/null and b/fonts/lucida_sans_18.xml differ
diff --git a/fonts/lucida_sans_180.png b/fonts/lucida_sans_180.png
new file mode 100755
index 000000000..c739c80fc
Binary files /dev/null and b/fonts/lucida_sans_180.png differ
diff --git a/fonts/lucida_sans_20.xml b/fonts/lucida_sans_20.xml
new file mode 100755
index 000000000..329c226c0
Binary files /dev/null and b/fonts/lucida_sans_20.xml differ
diff --git a/fonts/lucida_sans_200.png b/fonts/lucida_sans_200.png
new file mode 100755
index 000000000..c3f883fc5
Binary files /dev/null and b/fonts/lucida_sans_200.png differ
diff --git a/fonts/lucida_sans_22.xml b/fonts/lucida_sans_22.xml
new file mode 100755
index 000000000..14d0cc2b9
Binary files /dev/null and b/fonts/lucida_sans_22.xml differ
diff --git a/fonts/lucida_sans_220.png b/fonts/lucida_sans_220.png
new file mode 100755
index 000000000..fb0edfe0d
Binary files /dev/null and b/fonts/lucida_sans_220.png differ
diff --git a/fonts/lucida_sans_24.xml b/fonts/lucida_sans_24.xml
new file mode 100755
index 000000000..5956f46e6
Binary files /dev/null and b/fonts/lucida_sans_24.xml differ
diff --git a/fonts/lucida_sans_240.png b/fonts/lucida_sans_240.png
new file mode 100755
index 000000000..5826e80d8
Binary files /dev/null and b/fonts/lucida_sans_240.png differ
diff --git a/fonts/lucida_sans_26.xml b/fonts/lucida_sans_26.xml
new file mode 100755
index 000000000..ae10ff8d7
Binary files /dev/null and b/fonts/lucida_sans_26.xml differ
diff --git a/fonts/lucida_sans_260.png b/fonts/lucida_sans_260.png
new file mode 100755
index 000000000..13a9c89c9
Binary files /dev/null and b/fonts/lucida_sans_260.png differ
diff --git a/fonts/lucida_sans_28.xml b/fonts/lucida_sans_28.xml
new file mode 100755
index 000000000..c1b3361d3
Binary files /dev/null and b/fonts/lucida_sans_28.xml differ
diff --git a/fonts/lucida_sans_280.png b/fonts/lucida_sans_280.png
new file mode 100755
index 000000000..9ffdc01e7
Binary files /dev/null and b/fonts/lucida_sans_280.png differ
diff --git a/fonts/lucida_sans_36.xml b/fonts/lucida_sans_36.xml
new file mode 100755
index 000000000..ca300d6de
Binary files /dev/null and b/fonts/lucida_sans_36.xml differ
diff --git a/fonts/lucida_sans_360.png b/fonts/lucida_sans_360.png
new file mode 100755
index 000000000..53b957c65
Binary files /dev/null and b/fonts/lucida_sans_360.png differ
diff --git a/fonts/lucida_sans_4.xml b/fonts/lucida_sans_4.xml
new file mode 100755
index 000000000..edc5af951
Binary files /dev/null and b/fonts/lucida_sans_4.xml differ
diff --git a/fonts/lucida_sans_40.png b/fonts/lucida_sans_40.png
new file mode 100755
index 000000000..954ac0d35
Binary files /dev/null and b/fonts/lucida_sans_40.png differ
diff --git a/fonts/lucida_sans_48.xml b/fonts/lucida_sans_48.xml
new file mode 100755
index 000000000..c8c75974d
Binary files /dev/null and b/fonts/lucida_sans_48.xml differ
diff --git a/fonts/lucida_sans_480.png b/fonts/lucida_sans_480.png
new file mode 100755
index 000000000..afc87a5cd
Binary files /dev/null and b/fonts/lucida_sans_480.png differ
diff --git a/fonts/lucida_sans_56.xml b/fonts/lucida_sans_56.xml
new file mode 100755
index 000000000..9f2cc831e
Binary files /dev/null and b/fonts/lucida_sans_56.xml differ
diff --git a/fonts/lucida_sans_560.png b/fonts/lucida_sans_560.png
new file mode 100755
index 000000000..04185d85d
Binary files /dev/null and b/fonts/lucida_sans_560.png differ
diff --git a/fonts/lucida_sans_6.xml b/fonts/lucida_sans_6.xml
new file mode 100755
index 000000000..069c9aa80
Binary files /dev/null and b/fonts/lucida_sans_6.xml differ
diff --git a/fonts/lucida_sans_60.png b/fonts/lucida_sans_60.png
new file mode 100755
index 000000000..d67af5feb
Binary files /dev/null and b/fonts/lucida_sans_60.png differ
diff --git a/fonts/lucida_sans_8.xml b/fonts/lucida_sans_8.xml
new file mode 100755
index 000000000..44f0e6a74
Binary files /dev/null and b/fonts/lucida_sans_8.xml differ
diff --git a/fonts/lucida_sans_80.png b/fonts/lucida_sans_80.png
new file mode 100755
index 000000000..726423ee2
Binary files /dev/null and b/fonts/lucida_sans_80.png differ
diff --git a/fonts/lucida_sans_9.xml b/fonts/lucida_sans_9.xml
new file mode 100755
index 000000000..99aa6447c
Binary files /dev/null and b/fonts/lucida_sans_9.xml differ
diff --git a/fonts/lucida_sans_90.png b/fonts/lucida_sans_90.png
new file mode 100755
index 000000000..c13e5d0bd
Binary files /dev/null and b/fonts/lucida_sans_90.png differ
diff --git a/fonts/mono_dejavu_sans_10.xml b/fonts/mono_dejavu_sans_10.xml
new file mode 100755
index 000000000..0276cedb6
Binary files /dev/null and b/fonts/mono_dejavu_sans_10.xml differ
diff --git a/fonts/mono_dejavu_sans_100.png b/fonts/mono_dejavu_sans_100.png
new file mode 100755
index 000000000..28d9e7c47
Binary files /dev/null and b/fonts/mono_dejavu_sans_100.png differ
diff --git a/fonts/mono_dejavu_sans_11.xml b/fonts/mono_dejavu_sans_11.xml
new file mode 100755
index 000000000..f727ed2bb
Binary files /dev/null and b/fonts/mono_dejavu_sans_11.xml differ
diff --git a/fonts/mono_dejavu_sans_110.png b/fonts/mono_dejavu_sans_110.png
new file mode 100755
index 000000000..4536b514c
Binary files /dev/null and b/fonts/mono_dejavu_sans_110.png differ
diff --git a/fonts/mono_dejavu_sans_12.xml b/fonts/mono_dejavu_sans_12.xml
new file mode 100755
index 000000000..38f6427be
Binary files /dev/null and b/fonts/mono_dejavu_sans_12.xml differ
diff --git a/fonts/mono_dejavu_sans_120.png b/fonts/mono_dejavu_sans_120.png
new file mode 100755
index 000000000..147d9a160
Binary files /dev/null and b/fonts/mono_dejavu_sans_120.png differ
diff --git a/fonts/mono_dejavu_sans_14.xml b/fonts/mono_dejavu_sans_14.xml
new file mode 100755
index 000000000..b90a34960
Binary files /dev/null and b/fonts/mono_dejavu_sans_14.xml differ
diff --git a/fonts/mono_dejavu_sans_140.png b/fonts/mono_dejavu_sans_140.png
new file mode 100755
index 000000000..f9f0d29ca
Binary files /dev/null and b/fonts/mono_dejavu_sans_140.png differ
diff --git a/fonts/mono_dejavu_sans_16.xml b/fonts/mono_dejavu_sans_16.xml
new file mode 100755
index 000000000..3f7d2c2a2
Binary files /dev/null and b/fonts/mono_dejavu_sans_16.xml differ
diff --git a/fonts/mono_dejavu_sans_160.png b/fonts/mono_dejavu_sans_160.png
new file mode 100755
index 000000000..0b6af705d
Binary files /dev/null and b/fonts/mono_dejavu_sans_160.png differ
diff --git a/fonts/mono_dejavu_sans_18.xml b/fonts/mono_dejavu_sans_18.xml
new file mode 100755
index 000000000..92865cbfc
Binary files /dev/null and b/fonts/mono_dejavu_sans_18.xml differ
diff --git a/fonts/mono_dejavu_sans_180.png b/fonts/mono_dejavu_sans_180.png
new file mode 100755
index 000000000..17391f3f6
Binary files /dev/null and b/fonts/mono_dejavu_sans_180.png differ
diff --git a/fonts/mono_dejavu_sans_20.xml b/fonts/mono_dejavu_sans_20.xml
new file mode 100755
index 000000000..acd8c77d0
Binary files /dev/null and b/fonts/mono_dejavu_sans_20.xml differ
diff --git a/fonts/mono_dejavu_sans_200.png b/fonts/mono_dejavu_sans_200.png
new file mode 100755
index 000000000..58a61d5ea
Binary files /dev/null and b/fonts/mono_dejavu_sans_200.png differ
diff --git a/fonts/mono_dejavu_sans_22.xml b/fonts/mono_dejavu_sans_22.xml
new file mode 100755
index 000000000..eafb4def6
Binary files /dev/null and b/fonts/mono_dejavu_sans_22.xml differ
diff --git a/fonts/mono_dejavu_sans_220.png b/fonts/mono_dejavu_sans_220.png
new file mode 100755
index 000000000..df6d0d1af
Binary files /dev/null and b/fonts/mono_dejavu_sans_220.png differ
diff --git a/fonts/mono_dejavu_sans_24.xml b/fonts/mono_dejavu_sans_24.xml
new file mode 100755
index 000000000..fc8b6232e
Binary files /dev/null and b/fonts/mono_dejavu_sans_24.xml differ
diff --git a/fonts/mono_dejavu_sans_240.png b/fonts/mono_dejavu_sans_240.png
new file mode 100755
index 000000000..0eeb06a78
Binary files /dev/null and b/fonts/mono_dejavu_sans_240.png differ
diff --git a/fonts/mono_dejavu_sans_26.xml b/fonts/mono_dejavu_sans_26.xml
new file mode 100755
index 000000000..829f09948
Binary files /dev/null and b/fonts/mono_dejavu_sans_26.xml differ
diff --git a/fonts/mono_dejavu_sans_260.png b/fonts/mono_dejavu_sans_260.png
new file mode 100755
index 000000000..86ce54e1a
Binary files /dev/null and b/fonts/mono_dejavu_sans_260.png differ
diff --git a/fonts/mono_dejavu_sans_28.xml b/fonts/mono_dejavu_sans_28.xml
new file mode 100755
index 000000000..b5b25bd07
Binary files /dev/null and b/fonts/mono_dejavu_sans_28.xml differ
diff --git a/fonts/mono_dejavu_sans_280.png b/fonts/mono_dejavu_sans_280.png
new file mode 100755
index 000000000..da99da824
Binary files /dev/null and b/fonts/mono_dejavu_sans_280.png differ
diff --git a/fonts/mono_dejavu_sans_4.xml b/fonts/mono_dejavu_sans_4.xml
new file mode 100755
index 000000000..cfebb39b3
Binary files /dev/null and b/fonts/mono_dejavu_sans_4.xml differ
diff --git a/fonts/mono_dejavu_sans_40.png b/fonts/mono_dejavu_sans_40.png
new file mode 100755
index 000000000..413817a7e
Binary files /dev/null and b/fonts/mono_dejavu_sans_40.png differ
diff --git a/fonts/mono_dejavu_sans_6.xml b/fonts/mono_dejavu_sans_6.xml
new file mode 100755
index 000000000..d0e1de21d
Binary files /dev/null and b/fonts/mono_dejavu_sans_6.xml differ
diff --git a/fonts/mono_dejavu_sans_60.png b/fonts/mono_dejavu_sans_60.png
new file mode 100755
index 000000000..7126f4d7b
Binary files /dev/null and b/fonts/mono_dejavu_sans_60.png differ
diff --git a/fonts/mono_dejavu_sans_8.xml b/fonts/mono_dejavu_sans_8.xml
new file mode 100755
index 000000000..c48bf7ccc
Binary files /dev/null and b/fonts/mono_dejavu_sans_8.xml differ
diff --git a/fonts/mono_dejavu_sans_80.png b/fonts/mono_dejavu_sans_80.png
new file mode 100755
index 000000000..8ff7924dc
Binary files /dev/null and b/fonts/mono_dejavu_sans_80.png differ
diff --git a/fonts/mono_dejavu_sans_9.xml b/fonts/mono_dejavu_sans_9.xml
new file mode 100755
index 000000000..74e841034
Binary files /dev/null and b/fonts/mono_dejavu_sans_9.xml differ
diff --git a/fonts/mono_dejavu_sans_90.png b/fonts/mono_dejavu_sans_90.png
new file mode 100755
index 000000000..78872ddc8
Binary files /dev/null and b/fonts/mono_dejavu_sans_90.png differ
diff --git a/minetest.conf.example b/minetest.conf.example
index 0d2c44c61..91b3251c0 100644
--- a/minetest.conf.example
+++ b/minetest.conf.example
@@ -215,6 +215,8 @@
#directional_colored_fog = true
#tooltip_show_delay = 400
# Delay showing tooltips, in miliseconds
+#screen_dpi = 72
+# adjust dpi configuration to your screen (PC/MAC only) e.g. for 4k screens
# Default timeout for cURL, in milliseconds
# Only has an effect if compiled with cURL
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1a84c3714..98a2f5a94 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -453,6 +453,7 @@ set(minetest_SRCS
convert_json.cpp
drawscene.cpp
filecache.cpp
+ fontengine.cpp
game.cpp
guiChatConsole.cpp
guiEngine.cpp
diff --git a/src/client.cpp b/src/client.cpp
index 074ac9ba6..e9172e6fc 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -2726,7 +2726,7 @@ void Client::afterContentReceived(IrrlichtDevice *device, gui::IGUIFont* font)
{
verbosestream<<"Updating item textures and meshes"< names = m_itemdef->getAll();
size_t size = names.size();
size_t count = 0;
@@ -2739,7 +2739,7 @@ void Client::afterContentReceived(IrrlichtDevice *device, gui::IGUIFont* font)
count++;
percent = count*100/size;
if (count%50 == 0) // only update every 50 item
- draw_load_screen(text, device, guienv, font, 0, percent);
+ draw_load_screen(text, device, guienv, 0, percent);
}
delete[] text;
}
@@ -2775,7 +2775,7 @@ void Client::makeScreenshot(IrrlichtDevice *device)
irr::video::IVideoDriver *driver = device->getVideoDriver();
irr::video::IImage* const raw_image = driver->createScreenShot();
if (raw_image) {
- irr::video::IImage* const image = driver->createImage(video::ECF_R8G8B8,
+ irr::video::IImage* const image = driver->createImage(video::ECF_R8G8B8,
raw_image->getDimension());
if (image) {
diff --git a/src/constants.h b/src/constants.h
index f22a6e8af..d23f6bdf4 100644
--- a/src/constants.h
+++ b/src/constants.h
@@ -98,7 +98,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
* GUI related things
*/
#define LEGACY_SCALING (2./3.)
-#define DEFAULT_FONT_SIZE (13.0 / LEGACY_SCALING)
+#define TTF_DEFAULT_FONT_SIZE (13.0 / LEGACY_SCALING)
+#define DEFAULT_FONT_SIZE (14)
#define DEFAULT_IMGSIZE (48.0)
#define DEFAULT_XSPACING ((15.0 + (1.0 / 3.0)))
#define DEFAULT_YSPACING (9.0)
diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp
index 72eac76c2..a8ae9e251 100644
--- a/src/defaultsettings.cpp
+++ b/src/defaultsettings.cpp
@@ -187,10 +187,23 @@ void set_default_settings(Settings *settings)
settings->setDefault("fallback_font_shadow", "1");
settings->setDefault("fallback_font_shadow_alpha", "128");
+
+ std::stringstream fontsize;
+ fontsize << TTF_DEFAULT_FONT_SIZE;
+
+ settings->setDefault("font_size", fontsize.str());
+ settings->setDefault("mono_font_size", fontsize.str());
+ settings->setDefault("fallback_font_size", fontsize.str());
#else
- settings->setDefault("freetype", "false");
- settings->setDefault("font_path", porting::getDataPath("fonts" DIR_DELIM "fontlucida.png"));
- settings->setDefault("mono_font_path", porting::getDataPath("fonts" DIR_DELIM "fontdejavusansmono.png"));
+ settings->setDefault("freetype", "false");
+ settings->setDefault("font_path", porting::getDataPath("fonts" DIR_DELIM "lucida_sans"));
+ settings->setDefault("mono_font_path", porting::getDataPath("fonts" DIR_DELIM "mono_dejavu_sans"));
+
+ std::stringstream fontsize;
+ fontsize << DEFAULT_FONT_SIZE;
+
+ settings->setDefault("font_size", fontsize.str());
+ settings->setDefault("mono_font_size", fontsize.str());
#endif
// Server stuff
@@ -317,22 +330,8 @@ void set_default_settings(Settings *settings)
settings->setDefault("gui_scaling", "0.7");
}
settings->setDefault("curl_verify_cert","false");
-#endif
-}
-
-void late_init_default_settings(Settings* settings)
-{
-#ifndef SERVER
- std::stringstream fontsize;
- fontsize << floor(
- DEFAULT_FONT_SIZE *
- porting::getDisplayDensity() *
- settings->getFloat("gui_scaling")
- );
-
- settings->setDefault("font_size", fontsize.str());
- settings->setDefault("mono_font_size", fontsize.str());
- settings->setDefault("fallback_font_size", fontsize.str());
+#else
+ settings->setDefault("screen_dpi", "72");
#endif
}
diff --git a/src/defaultsettings.h b/src/defaultsettings.h
index 8c7f88a78..20274a003 100644
--- a/src/defaultsettings.h
+++ b/src/defaultsettings.h
@@ -28,12 +28,6 @@ class Settings;
*/
void set_default_settings(Settings *settings);
-/**
- * initialize default values which require knowledge about gui
- * @param settings pointer to settings
- */
-void late_init_default_settings(Settings* settings);
-
/**
* override a default settings by settings from another settings element
* @param settings target settings pointer
diff --git a/src/drawscene.cpp b/src/drawscene.cpp
index 20c2e22be..ba3316143 100644
--- a/src/drawscene.cpp
+++ b/src/drawscene.cpp
@@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "clouds.h"
#include "clientmap.h"
#include "util/timetaker.h"
+#include "fontengine.h"
typedef enum {
LEFT = -1,
@@ -500,21 +501,18 @@ void draw_scene(video::IVideoDriver* driver, scene::ISceneManager* smgr,
Text will be removed when the screen is drawn the next time.
Additionally, a progressbar can be drawn when percent is set between 0 and 100.
*/
-/*gui::IGUIStaticText **/
void draw_load_screen(const std::wstring &text, IrrlichtDevice* device,
- gui::IGUIEnvironment* guienv, gui::IGUIFont* font, float dtime,
- int percent, bool clouds )
+ gui::IGUIEnvironment* guienv, float dtime, int percent, bool clouds )
{
- video::IVideoDriver* driver = device->getVideoDriver();
- v2u32 screensize = driver->getScreenSize();
- const wchar_t *loadingtext = text.c_str();
- core::vector2d textsize_u = font->getDimension(loadingtext);
- core::vector2d textsize(textsize_u.X,textsize_u.Y);
- core::vector2d center(screensize.X/2, screensize.Y/2);
- core::rect textrect(center - textsize/2, center + textsize/2);
+ video::IVideoDriver* driver = device->getVideoDriver();
+ v2u32 screensize = porting::getWindowSize();
+
+ v2s32 textsize(glb_fontengine->getTextWidth(text), glb_fontengine->getLineHeight());
+ v2s32 center(screensize.X / 2, screensize.Y / 2);
+ core::rect textrect(center - textsize / 2, center + textsize / 2);
gui::IGUIStaticText *guitext = guienv->addStaticText(
- loadingtext, textrect, false, false);
+ text.c_str(), textrect, false, false);
guitext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
bool cloud_menu_background = clouds && g_settings->getBool("menu_clouds");
@@ -522,25 +520,33 @@ void draw_load_screen(const std::wstring &text, IrrlichtDevice* device,
{
g_menuclouds->step(dtime*3);
g_menuclouds->render();
- driver->beginScene(true, true, video::SColor(255,140,186,250));
+ driver->beginScene(true, true, video::SColor(255, 140, 186, 250));
g_menucloudsmgr->drawAll();
}
else
- driver->beginScene(true, true, video::SColor(255,0,0,0));
+ driver->beginScene(true, true, video::SColor(255, 0, 0, 0));
- if (percent >= 0 && percent <= 100) // draw progress bar
+ // draw progress bar
+ if ((percent >= 0) && (percent <= 100))
{
- core::vector2d barsize(256,32);
- core::rect barrect(center-barsize/2, center+barsize/2);
- driver->draw2DRectangle(video::SColor(255,255,255,255),barrect, NULL); // border
- driver->draw2DRectangle(video::SColor(255,64,64,64), core::rect (
- barrect.UpperLeftCorner+1,
+ v2s32 barsize(
+ // 342 is (approximately) 256/0.75 to keep bar on same size as
+ // before with default settings
+ 342 * porting::getDisplayDensity() *
+ g_settings->getFloat("gui_scaling"),
+ glb_fontengine->getTextHeight() * 2);
+
+ core::rect barrect(center - barsize / 2, center + barsize / 2);
+ driver->draw2DRectangle(video::SColor(255, 255, 255, 255),barrect, NULL); // border
+ driver->draw2DRectangle(video::SColor(255, 64, 64, 64), core::rect (
+ barrect.UpperLeftCorner + 1,
barrect.LowerRightCorner-1), NULL); // black inside the bar
- driver->draw2DRectangle(video::SColor(255,128,128,128), core::rect (
- barrect.UpperLeftCorner+1,
+ driver->draw2DRectangle(video::SColor(255, 128, 128, 128), core::rect (
+ barrect.UpperLeftCorner + 1,
core::vector2d(
- barrect.LowerRightCorner.X-(barsize.X-1)+percent*(barsize.X-2)/100,
- barrect.LowerRightCorner.Y-1)), NULL); // the actual progress
+ barrect.LowerRightCorner.X -
+ (barsize.X - 1) + percent * (barsize.X - 2) / 100,
+ barrect.LowerRightCorner.Y - 1)), NULL); // the actual progress
}
guienv->drawAll();
driver->endScene();
diff --git a/src/drawscene.h b/src/drawscene.h
index 062552516..3268bcbf2 100644
--- a/src/drawscene.h
+++ b/src/drawscene.h
@@ -26,8 +26,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
void draw_load_screen(const std::wstring &text, IrrlichtDevice* device,
- gui::IGUIEnvironment* guienv, gui::IGUIFont* font, float dtime=0,
- int percent=0, bool clouds=true);
+ gui::IGUIEnvironment* guienv, float dtime=0, int percent=0,
+ bool clouds=true);
void draw_scene(video::IVideoDriver* driver, scene::ISceneManager* smgr,
Camera& camera, Client& client, LocalPlayer* player, Hud& hud,
diff --git a/src/fontengine.cpp b/src/fontengine.cpp
new file mode 100644
index 000000000..c1e36d6c8
--- /dev/null
+++ b/src/fontengine.cpp
@@ -0,0 +1,463 @@
+/*
+Minetest
+Copyright (C) 2010-2014 sapier
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+#include "fontengine.h"
+#include "log.h"
+#include "main.h"
+#include "config.h"
+#include "porting.h"
+#include "constants.h"
+#include "filesys.h"
+
+#if USE_FREETYPE
+#include "gettext.h"
+#include "xCGUITTFont.h"
+#endif
+
+/** maximum size distance for getting a "similar" font size */
+#define MAX_FONT_SIZE_OFFSET 10
+
+/** reference to access font engine, has to be initialized by main */
+FontEngine* glb_fontengine = NULL;
+
+/** callback to be used on change of font size setting */
+static void font_setting_changed(const std::string) {
+ glb_fontengine->readSettings();
+}
+
+/******************************************************************************/
+FontEngine::FontEngine(Settings* main_settings, gui::IGUIEnvironment* env) :
+ m_settings(main_settings),
+ m_env(env),
+ m_font_cache(),
+ m_default_size(),
+ m_currentMode(FM_Standard),
+ m_lastMode(),
+ m_lastSize(0),
+ m_lastFont(NULL)
+{
+
+ for ( unsigned int i = 0; i < FM_MaxMode; i++) {
+ m_default_size[i] = (FontMode) FONT_SIZE_UNSPECIFIED;
+ }
+
+ assert(m_settings != NULL);
+ assert(m_env != NULL);
+ assert(m_env->getSkin() != NULL);
+
+ m_currentMode = FM_Simple;
+
+#if USE_FREETYPE
+ if (g_settings->getBool("freetype")) {
+ m_default_size[FM_Standard] = m_settings->getU16("font_size");
+ m_default_size[FM_Fallback] = m_settings->getU16("fallback_font_size");
+ m_default_size[FM_Mono] = m_settings->getU16("mono_font_size");
+
+ if (is_yes(gettext("needs_fallback_font"))) {
+ m_currentMode = FM_Fallback;
+ }
+ else {
+ m_currentMode = FM_Standard;
+ }
+ }
+
+ // having freetype but not using it is quite a strange case so we need to do
+ // special handling for it
+ if (m_currentMode == FM_Simple) {
+ std::stringstream fontsize;
+ fontsize << DEFAULT_FONT_SIZE;
+ m_settings->setDefault("font_size", fontsize.str());
+ m_settings->setDefault("mono_font_size", fontsize.str());
+ }
+#endif
+
+ m_default_size[FM_Simple] = m_settings->getU16("font_size");
+ m_default_size[FM_SimpleMono] = m_settings->getU16("mono_font_size");
+
+ updateSkin();
+
+ if (m_currentMode == FM_Standard) {
+ m_settings->registerChangedCallback("font_size", font_setting_changed);
+ m_settings->registerChangedCallback("font_path", font_setting_changed);
+ m_settings->registerChangedCallback("font_shadow", font_setting_changed);
+ m_settings->registerChangedCallback("font_shadow_alpha", font_setting_changed);
+ }
+ else if (m_currentMode == FM_Fallback) {
+ m_settings->registerChangedCallback("fallback_font_size", font_setting_changed);
+ m_settings->registerChangedCallback("fallback_font_path", font_setting_changed);
+ m_settings->registerChangedCallback("fallback_font_shadow", font_setting_changed);
+ m_settings->registerChangedCallback("fallback_font_shadow_alpha", font_setting_changed);
+ }
+
+ m_settings->registerChangedCallback("mono_font_path", font_setting_changed);
+ m_settings->registerChangedCallback("mono_font_size", font_setting_changed);
+ m_settings->registerChangedCallback("screen_dpi", font_setting_changed);
+ m_settings->registerChangedCallback("gui_scaling", font_setting_changed);
+}
+
+/******************************************************************************/
+FontEngine::~FontEngine()
+{
+ cleanCache();
+}
+
+/******************************************************************************/
+void FontEngine::cleanCache()
+{
+ for ( unsigned int i = 0; i < FM_MaxMode; i++) {
+
+ for (std::map::iterator iter
+ = m_font_cache[i].begin();
+ iter != m_font_cache[i].end(); iter++) {
+ iter->second->drop();
+ iter->second = NULL;
+ }
+ m_font_cache[i].clear();
+ }
+}
+
+/******************************************************************************/
+irr::gui::IGUIFont* FontEngine::getFont(unsigned int font_size, FontMode mode)
+{
+ if (mode == FM_Unspecified) {
+ mode = m_currentMode;
+ }
+ else if ((mode == FM_Mono) && (m_currentMode == FM_Simple)) {
+ mode = FM_SimpleMono;
+ }
+
+ if (font_size == FONT_SIZE_UNSPECIFIED) {
+ font_size = m_default_size[mode];
+ }
+
+ if ((font_size == m_lastSize) && (mode == m_lastMode)) {
+ return m_lastFont;
+ }
+
+ if (m_font_cache[mode].find(font_size) == m_font_cache[mode].end()) {
+ initFont(font_size, mode);
+ }
+
+ if (m_font_cache[mode].find(font_size) == m_font_cache[mode].end()) {
+ return NULL;
+ }
+
+ m_lastSize = font_size;
+ m_lastMode = mode;
+ m_lastFont = m_font_cache[mode][font_size];
+
+ return m_font_cache[mode][font_size];
+}
+
+/******************************************************************************/
+unsigned int FontEngine::getTextHeight(unsigned int font_size, FontMode mode)
+{
+ irr::gui::IGUIFont* font = getFont(font_size, mode);
+
+ // use current skin font as fallback
+ if (font == NULL) {
+ font = m_env->getSkin()->getFont();
+ }
+ assert(font != NULL);
+
+ return font->getDimension(L"Some unimportant example String").Height;
+}
+
+/******************************************************************************/
+unsigned int FontEngine::getTextWidth(const std::wstring& text,
+ unsigned int font_size, FontMode mode)
+{
+ irr::gui::IGUIFont* font = getFont(font_size, mode);
+
+ // use current skin font as fallback
+ if (font == NULL) {
+ font = m_env->getSkin()->getFont();
+ }
+ assert(font != NULL);
+
+ return font->getDimension(text.c_str()).Width;
+}
+
+
+/** get line height for a specific font (including empty room between lines) */
+unsigned int FontEngine::getLineHeight(unsigned int font_size, FontMode mode)
+{
+ irr::gui::IGUIFont* font = getFont(font_size, mode);
+
+ // use current skin font as fallback
+ if (font == NULL) {
+ font = m_env->getSkin()->getFont();
+ }
+ assert(font != NULL);
+
+ return font->getDimension(L"Some unimportant example String").Height
+ + font->getKerningHeight();
+}
+
+/******************************************************************************/
+unsigned int FontEngine::getDefaultFontSize()
+{
+ return m_default_size[m_currentMode];
+}
+
+/******************************************************************************/
+void FontEngine::readSettings()
+{
+#if USE_FREETYPE
+ if (g_settings->getBool("freetype")) {
+ m_default_size[FM_Standard] = m_settings->getU16("font_size");
+ m_default_size[FM_Fallback] = m_settings->getU16("fallback_font_size");
+ m_default_size[FM_Mono] = m_settings->getU16("mono_font_size");
+
+ if (is_yes(gettext("needs_fallback_font"))) {
+ m_currentMode = FM_Fallback;
+ }
+ else {
+ m_currentMode = FM_Standard;
+ }
+ }
+#endif
+ m_default_size[FM_Simple] = m_settings->getU16("font_size");
+ m_default_size[FM_SimpleMono] = m_settings->getU16("mono_font_size");
+
+ cleanCache();
+ updateFontCache();
+ updateSkin();
+}
+
+/******************************************************************************/
+void FontEngine::updateSkin()
+{
+ gui::IGUIFont *font = getFont();
+
+ if (font)
+ m_env->getSkin()->setFont(font);
+ else
+ errorstream << "FontEngine: Default font file: " <<
+ "\n\t\"" << m_settings->get("font_path") << "\"" <<
+ "\n\trequired for current screen configuration was not found" <<
+ " or was invalid file format." <<
+ "\n\tUsing irrlicht default font." << std::endl;
+
+ // If we did fail to create a font our own make irrlicht find a default one
+ font = m_env->getSkin()->getFont();
+ assert(font);
+
+ u32 text_height = font->getDimension(L"Hello, world!").Height;
+ infostream << "text_height=" << text_height << std::endl;
+}
+
+/******************************************************************************/
+void FontEngine::updateFontCache()
+{
+ /* the only font to be initialized is default one,
+ * all others are re-initialized on demand */
+ initFont(m_default_size[m_currentMode], m_currentMode);
+
+ /* reset font quick access */
+ m_lastMode = FM_Unspecified;
+ m_lastSize = 0;
+ m_lastFont = NULL;
+}
+
+/******************************************************************************/
+void FontEngine::initFont(unsigned int basesize, FontMode mode)
+{
+
+ std::string font_config_prefix;
+
+ if (mode == FM_Unspecified) {
+ mode = m_currentMode;
+ }
+
+ switch (mode) {
+
+ case FM_Standard:
+ font_config_prefix = "";
+ break;
+
+ case FM_Fallback:
+ font_config_prefix = "fallback_";
+ break;
+
+ case FM_Mono:
+ font_config_prefix = "mono_";
+ if (m_currentMode == FM_Simple)
+ mode = FM_SimpleMono;
+ break;
+
+ case FM_Simple: /* Fallthrough */
+ case FM_SimpleMono: /* Fallthrough */
+ default:
+ font_config_prefix = "";
+
+ }
+
+ if (m_font_cache[mode].find(basesize) != m_font_cache[mode].end())
+ return;
+
+ if ((mode == FM_Simple) || (mode == FM_SimpleMono)) {
+ initSimpleFont(basesize, mode);
+ return;
+ }
+#if USE_FREETYPE
+ else {
+ if (! is_yes(m_settings->get("freetype"))) {
+ return;
+ }
+ unsigned int size = floor(
+ porting::getDisplayDensity() *
+ m_settings->getFloat("gui_scaling") *
+ basesize);
+ u32 font_shadow = 0;
+ u32 font_shadow_alpha = 0;
+
+ try {
+ font_shadow =
+ g_settings->getU16(font_config_prefix + "font_shadow");
+ } catch (SettingNotFoundException&) {}
+ try {
+ font_shadow_alpha =
+ g_settings->getU16(font_config_prefix + "font_shadow_alpha");
+ } catch (SettingNotFoundException&) {}
+
+ std::string font_path = g_settings->get(font_config_prefix + "font_path");
+
+ if (font_path.substr(font_path.length() -4) != ".ttf") {
+ errorstream << "FontEngine: \"" << font_path
+ << "\" doesn't seem to be a ttf File." << std::endl;
+ return;
+ }
+
+ irr::gui::IGUIFont* font = gui::CGUITTFont::createTTFont(m_env,
+ font_path.c_str(), size, true, true, font_shadow,
+ font_shadow_alpha);
+
+ if (font != NULL) {
+ font->grab();
+ m_font_cache[mode][basesize] = font;
+ }
+ else {
+ errorstream << "FontEngine: failed to load freetype font: "
+ << font_path << std::endl;
+ }
+ }
+#endif
+}
+
+/** initialize a font without freetype */
+void FontEngine::initSimpleFont(unsigned int basesize, FontMode mode)
+{
+ assert((mode == FM_Simple) || (mode == FM_SimpleMono));
+
+ std::string font_path = "";
+ if (mode == FM_Simple) {
+ font_path = m_settings->get("font_path");
+ } else {
+ font_path = m_settings->get("mono_font_path");
+ }
+ std::string basename = font_path;
+ std::string ending = font_path.substr(font_path.length() -4);
+
+ if (ending == ".ttf") {
+ errorstream << "FontEngine: Not trying to open \"" << font_path
+ << "\" which seems to be a truetype font." << std::endl;
+ return;
+ }
+
+ if ((ending == ".xml") || ( ending == ".png")) {
+ basename = font_path.substr(0,font_path.length()-4);
+ }
+
+ if (basesize == FONT_SIZE_UNSPECIFIED)
+ basesize = DEFAULT_FONT_SIZE;
+
+ unsigned int size = floor(
+ porting::getDisplayDensity() *
+ m_settings->getFloat("gui_scaling") *
+ basesize);
+
+ irr::gui::IGUIFont* font = NULL;
+
+ for(unsigned int offset = 0; offset < MAX_FONT_SIZE_OFFSET; offset++) {
+
+ // try opening positive offset
+ std::stringstream fontsize_plus_png;
+ fontsize_plus_png << basename << "_" << (size + offset) << ".png";
+
+ if (fs::PathExists(fontsize_plus_png.str())) {
+ font = m_env->getFont(fontsize_plus_png.str().c_str());
+
+ if (font) {
+ verbosestream << "FontEngine: found font: " << fontsize_plus_png.str() << std::endl;
+ break;
+ }
+ }
+
+ std::stringstream fontsize_plus_xml;
+ fontsize_plus_xml << basename << "_" << (size + offset) << ".xml";
+
+ if (fs::PathExists(fontsize_plus_xml.str())) {
+ font = m_env->getFont(fontsize_plus_xml.str().c_str());
+
+ if (font) {
+ verbosestream << "FontEngine: found font: " << fontsize_plus_xml.str() << std::endl;
+ break;
+ }
+ }
+
+ // try negative offset
+ std::stringstream fontsize_minus_png;
+ fontsize_minus_png << basename << "_" << (size - offset) << ".png";
+
+ if (fs::PathExists(fontsize_minus_png.str())) {
+ font = m_env->getFont(fontsize_minus_png.str().c_str());
+
+ if (font) {
+ verbosestream << "FontEngine: found font: " << fontsize_minus_png.str() << std::endl;
+ break;
+ }
+ }
+
+ std::stringstream fontsize_minus_xml;
+ fontsize_minus_xml << basename << "_" << (size - offset) << ".xml";
+
+ if (fs::PathExists(fontsize_minus_xml.str())) {
+ font = m_env->getFont(fontsize_minus_xml.str().c_str());
+
+ if (font) {
+ verbosestream << "FontEngine: found font: " << fontsize_minus_xml.str() << std::endl;
+ break;
+ }
+ }
+ }
+
+ // try name direct
+ if (font == NULL) {
+ if (fs::PathExists(font_path)) {
+ font = m_env->getFont(font_path.c_str());
+ if (font)
+ verbosestream << "FontEngine: found font: " << font_path << std::endl;
+ }
+ }
+
+ if (font != NULL) {
+ font->grab();
+ m_font_cache[mode][basesize] = font;
+ }
+}
diff --git a/src/fontengine.h b/src/fontengine.h
new file mode 100644
index 000000000..6a5339770
--- /dev/null
+++ b/src/fontengine.h
@@ -0,0 +1,140 @@
+/*
+Minetest
+Copyright (C) 2010-2014 sapier
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+#ifndef __FONTENGINE_H__
+#define __FONTENGINE_H__
+
+#include