Better title font to all languages

I tested all language, all of the them only needs 2 glyph page
to load their needed chars.
This commit is contained in:
Benau 2015-10-13 07:55:26 +08:00
parent 786bc5d5b6
commit a756f9f90e
3 changed files with 24 additions and 17 deletions

View File

@ -92,7 +92,7 @@ void getFontProperties::loadChar(const core::stringc langname, FontUse& fu, floa
fu = F_DEFAULT; //Default font file
usedchar = translations->getCurrentAllChar(); //Loading unique characters
for (int i = 33; i < 256; ++i)
for (int i = 32; i < 256; ++i)
usedchar.insert((wchar_t)i); //Include basic Latin too
usedchar.insert((wchar_t)160); //Non-breaking space
usedchar.insert((wchar_t)215); //Used on resolution selection screen (X).
@ -115,27 +115,28 @@ void getFontProperties::loadBoldChar(float scale)
{
size = (int)(120*scale); //Set default size for Bold Text
//Start to insert from 65 (char code of A) to 640 which is the end+1 of latin-extended-B
for (int i = 65; i < 640; ++i)
usedchar.insert((wchar_t)i);
usedchar = translations->getCurrentAllChar(); //Loading unique characters
for (int i = 65; i < 256; ++i)
usedchar.insert((wchar_t)i); //Include basic Latin too, starting from A (char code 65)
setlocale(LC_ALL, "en_US.UTF8");
std::set<wchar_t>::iterator it = usedchar.begin();
while (it != usedchar.end())
{
if (iswlower((wchar_t)*it) || !iswalpha((wchar_t)*it))
//Only use all capital letter for bold char with latin (<640 of char code).
if ((iswlower((wchar_t)*it) || !iswalpha((wchar_t)*it)) && *it < 640)
it = usedchar.erase(it);
else
++it;
}
//Final hack to make stk display title properly
//33 , 160, 304 is char code to "!", Non-breaking space, and Capital I-dotted
//Remove Capital I-dotted with using "I" altogether.
usedchar.insert((wchar_t)33);
usedchar.insert((wchar_t)160);
usedchar.erase((wchar_t)304);
for (int i = 32; i < 65; ++i)
usedchar.insert((wchar_t)i); //Include basic symbol (from space (char code 32) to @(char code 64))
usedchar.insert((wchar_t)160); //Non-breaking space
usedchar.erase((wchar_t)170);
usedchar.erase((wchar_t)186); //Remove Ordinal indicator (char code 170 and 186)
usedchar.erase((wchar_t)304); //Remove Capital I-dotted (char code 304) with using "I" altogether.
}
} // end namespace gui

View File

@ -391,7 +391,9 @@ bool ScalableFont::loadTTF()
u32 texno = 0;
SpriteBank->addTexture(NULL);
gp_creator->createNewGlyphPage();
for (it = cur_prop.usedchar.begin(); it != cur_prop.usedchar.end(); ++it)
it = cur_prop.usedchar.begin();
while (it != cur_prop.usedchar.end())
{
SGUISpriteFrame f;
SGUISprite s;
@ -469,13 +471,16 @@ bool ScalableFont::loadTTF()
SpriteBank->setTexture(texno, Driver->addTexture("Glyph_page", gp_creator->getPage()));
gp_creator->clearGlyphPage();
}
if (*it == (wchar_t)32 && SpriteBank->getPositions().size() == 1)
continue; //Preventing getAreaIDFromCharacter of whitespace == 0, which make space disappear
else ++it;
}
//Fix unused glyphs....
if (m_type == T_NORMAL || T_BOLD)
{
CharacterMap[(wchar_t)32] = getAreaIDFromCharacter((wchar_t)160, NULL); //Use non-breaking space glyph to all space/tab characters.
CharacterMap[(wchar_t)9] = getAreaIDFromCharacter((wchar_t)160, NULL);
CharacterMap[(wchar_t)9] = getAreaIDFromCharacter((wchar_t)160, NULL); //Use non-breaking space glyph to tab.
CharacterMap[(wchar_t)173] = 0; //Don't need a glyph for the soft hypen, as it only print when not having enough space.
//And then it will convert to a "-".
@ -491,7 +496,7 @@ bool ScalableFont::loadTTF()
setlocale(LC_ALL, "en_US.UTF8");
for (it = cur_prop.usedchar.begin(); it != cur_prop.usedchar.end(); ++it)
{
if (iswupper((wchar_t)*it))
if (iswupper((wchar_t)*it) && *it < 640)
CharacterMap[towlower((wchar_t)*it)] = getAreaIDFromCharacter(*it, NULL);
}
}
@ -510,11 +515,11 @@ bool ScalableFont::loadTTF()
//at the bottom line, so no addition is required, but if we can make draw2dimage draw
//characters close to the bottom line too, than only one offsety is needed.
if (!n) //Skip soft hypen and space
if (!n) //Skip width-less characters
a.bearingx = 0;
else
a.bearingx = bx.at(n);
if (!n) //Skip soft hypen and space
if (!n) //Skip width-less characters
a.width = 0;
else
a.width = advance.at(n);

View File

@ -333,6 +333,7 @@ void OptionsScreenUI::eventCallback(Widget* widget, const std::string& name, con
//Reload fonts for new translation when using freetype
GUIEngine::cleanHollowCopyFont();
GUIEngine::getFont()->recreateFromLanguage();
GUIEngine::getTitleFont()->recreateFromLanguage();
GUIEngine::reloadHollowCopyFont(GUIEngine::getFont());
#endif // ENABLE_FREETYPE