Skip to content

Commit bc712b5

Browse files
committed
Merge pull request supertuxkart#2378 from Benau/custom_font
Allow configurable fonts file names in stk-config
2 parents 8b916a7 + 7cf4d66 commit bc712b5

File tree

6 files changed

+48
-24
lines changed

6 files changed

+48
-24
lines changed

data/stk_config.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,4 +749,21 @@
749749
</heavy>
750750
</kart-type>
751751
</general-kart-defaults>
752+
753+
<!-- Here are the default fonts file names for STK.
754+
755+
Please DO NOT report bugs if there're crashes when using your custom font.
756+
This usually happen because the character map of the font is not in unicode mode
757+
(let's take Chinese for example, some fonts of it store the characters in BIG5 mode,
758+
which leads to crash with STK), but the fonts are to blame, what's the point of not
759+
using industry standard nowadays...
760+
-->
761+
<font default="Ubuntu-R.ttf"
762+
default_fallback="FreeSans.ttf"
763+
cjk="wqy-microhei.ttf"
764+
ar="NotoNaskhArabicUI-Bold.ttf"
765+
bold="Ubuntu-B.ttf"
766+
bold_fallback="FreeSansBold.ttf"
767+
digit="SigmarOne.otf" />
768+
752769
</config>

src/config/stk_config.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,17 @@ void STKConfig::getAllData(const XMLNode * root)
385385

386386
}
387387

388+
if(const XMLNode *font_node = root->getNode("font"))
389+
{
390+
font_node->get("default", &m_font_default );
391+
font_node->get("default_fallback", &m_font_default_fallback);
392+
font_node->get("cjk", &m_font_cjk );
393+
font_node->get("ar", &m_font_ar );
394+
font_node->get("bold", &m_font_bold );
395+
font_node->get("bold_fallback", &m_font_bold_fallback );
396+
font_node->get("digit", &m_font_digit );
397+
}
398+
388399
// Get the default KartProperties
389400
// ------------------------------
390401
const XMLNode *node = root -> getNode("general-kart-defaults");

src/config/stk_config.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,15 @@ class STKConfig : public NoCopy
160160
/** The field of view for 1, 2, 3, 4 player split screen. */
161161
float m_camera_fov[4];
162162

163+
/** File names of the default fonts in STK. */
164+
std::string m_font_default;
165+
std::string m_font_default_fallback;
166+
std::string m_font_cjk;
167+
std::string m_font_ar;
168+
std::string m_font_bold;
169+
std::string m_font_bold_fallback;
170+
std::string m_font_digit;
171+
163172
private:
164173
/** True if stk_config has been loaded. This is necessary if the
165174
* --stk-config command line parameter has been specified to avoid

src/guiengine/ft_environment.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "guiengine/ft_environment.hpp"
2020
#include "io/file_manager.hpp"
2121
#include "utils/log.hpp"
22+
#include "config/stk_config.hpp"
2223

2324
#include <algorithm>
2425

@@ -70,31 +71,31 @@ void FTEnvironment::checkError(FT_Error err, const irr::core::stringc desc)
7071
void FTEnvironment::loadFont()
7172
{
7273
checkError(FT_New_Face(m_ft_lib, (file_manager->getAssetChecked
73-
(FileManager::TTF, "Ubuntu-R.ttf", true)).c_str(),
74+
(FileManager::TTF, stk_config->m_font_default.c_str(), true)).c_str(),
7475
0, &m_ft_face[F_DEFAULT]), "loading F_DEFAULT");
7576

7677
checkError(FT_New_Face(m_ft_lib, (file_manager->getAssetChecked
77-
(FileManager::TTF, "FreeSans.ttf",true)).c_str(),
78+
(FileManager::TTF, stk_config->m_font_default_fallback.c_str(), true)).c_str(),
7879
0, &m_ft_face[F_DEFAULT_FALLBACK]), "loading F_DEFAULT_FALLBACK");
7980

8081
checkError(FT_New_Face(m_ft_lib, (file_manager->getAssetChecked
81-
(FileManager::TTF, "wqy-microhei.ttf",true)).c_str(),
82+
(FileManager::TTF, stk_config->m_font_cjk.c_str(), true)).c_str(),
8283
0, &m_ft_face[F_CJK]), "loading F_CJK");
8384

8485
checkError(FT_New_Face(m_ft_lib, (file_manager->getAssetChecked
85-
(FileManager::TTF, "NotoNaskhArabicUI-Bold.ttf",true)).c_str(),
86+
(FileManager::TTF, stk_config->m_font_ar.c_str(), true)).c_str(),
8687
0, &m_ft_face[F_AR]), "loading F_AR");
8788

8889
checkError(FT_New_Face(m_ft_lib, (file_manager->getAssetChecked
89-
(FileManager::TTF, "Ubuntu-B.ttf", true)).c_str(),
90+
(FileManager::TTF, stk_config->m_font_bold.c_str(), true)).c_str(),
9091
0, &m_ft_face[F_BOLD]), "loading F_BOLD");
9192

9293
checkError(FT_New_Face(m_ft_lib, (file_manager->getAssetChecked
93-
(FileManager::TTF, "FreeSansBold.ttf", true)).c_str(),
94+
(FileManager::TTF, stk_config->m_font_bold_fallback.c_str(), true)).c_str(),
9495
0, &m_ft_face[F_BOLD_FALLBACK]), "loading F_BOLD_FALLBACK");
9596

9697
checkError(FT_New_Face(m_ft_lib, (file_manager->getAssetChecked
97-
(FileManager::TTF, "SigmarOne.otf",true)).c_str(),
98+
(FileManager::TTF, stk_config->m_font_digit.c_str(),true)).c_str(),
9899
0, &m_ft_face[F_DIGIT]), "loading F_DIGIT");
99100

100101
//Set charmap

src/guiengine/scalable_font.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@
2323
#include "io/file_manager.hpp"
2424
#include "utils/translation.hpp"
2525

26-
#include <IAttributes.h>
27-
#include <IGUIEnvironment.h>
28-
#include <IGUISpriteBank.h>
29-
#include <IVideoDriver.h>
30-
3126
#include <clocale>
3227
#include <cmath>
3328
#include <cwctype>
@@ -310,7 +305,7 @@ bool ScalableFont::loadTTF()
310305

311306
m_glyph_max_height = curr_maxheight;
312307

313-
for(wchar_t c='0'; c<='9'; c++)
308+
for(wchar_t c = '0'; c <= '9'; c++)
314309
{
315310
SFontArea a = getAreaFromCharacter(c, NULL);
316311
m_max_digit_area.width = a.width;
@@ -815,7 +810,7 @@ void ScalableFont::doDraw(const core::stringw& text,
815810

816811
if (m_type == T_NORMAL || T_BOLD) //lazy load char, have to do this again
817812
{ //because some text isn't drawn with getDimension
818-
for (u32 i = 0; i<text_size; i++)
813+
for (u32 i = 0; i < text_size; i++)
819814
{
820815
wchar_t c = text[i];
821816
if (c == L'\r' || c == L'\n' || c == L' ' || c < 32) continue;
@@ -842,7 +837,7 @@ void ScalableFont::doDraw(const core::stringw& text,
842837
}
843838
}
844839

845-
for (u32 i = 0; i<text_size; i++)
840+
for (u32 i = 0; i < text_size; i++)
846841
{
847842
wchar_t c = text[i];
848843

src/guiengine/scalable_font.hpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@
2222
#include "guiengine/ft_environment.hpp"
2323
#include "utils/leak_check.hpp"
2424

25-
#include "IrrCompileConfig.h"
26-
#include "IGUIFontBitmap.h"
27-
#include "irrString.h"
28-
#include "irrMap.h"
29-
#include "IXMLReader.h"
30-
#include "IReadFile.h"
31-
#include "irrArray.h"
32-
33-
3425
#include <map>
3526
#include <string>
3627
#include <set>

0 commit comments

Comments
 (0)