Fix some bugs in title font and clean up more code

This commit is contained in:
Benau 2015-10-17 01:20:50 +08:00
parent ee60eb9a68
commit f557dce27e
5 changed files with 59 additions and 39 deletions

View File

@ -1072,6 +1072,47 @@ namespace GUIEngine
#ifdef ENABLE_FREETYPE
float normal_text_scale = 1;
float title_text_scale = 1;
ScalableFont* digit_font =new ScalableFont(g_env,T_DIGIT);
digit_font->setMonospaceDigits(true);
g_digit_font = digit_font;
ScalableFont* sfont2 =new ScalableFont(g_env,T_BOLD);
sfont2->setKerningWidth(0);
// Because the fallback font is much smaller than the title font:
sfont2->m_fallback_font_scale = 2.0f;
sfont2->m_fallback_kerning_width = 5;
ScalableFont* sfont =new ScalableFont(g_env,T_NORMAL);
sfont->setKerningHeight(0);
sfont->setScale(normal_text_scale);
g_font = sfont;
Private::font_height = g_font->getDimension( L"X" ).Height;
ScalableFont* sfont_larger = sfont->getHollowCopy();
sfont_larger->setScale(normal_text_scale*1.4f);
sfont_larger->setKerningHeight(0);
g_large_font = sfont_larger;
g_outline_font = sfont->getHollowCopy();
g_outline_font->m_black_border = true;
Private::large_font_height = g_large_font->getDimension( L"X" ).Height;
ScalableFont* sfont_smaller = sfont->getHollowCopy();
sfont_smaller->setScale(normal_text_scale*0.8f);
sfont_smaller->setKerningHeight(0);
g_small_font = sfont_smaller;
Private::small_font_height =
g_small_font->getDimension( L"X" ).Height;
sfont2->m_fallback_font = sfont;
sfont2->setScale(title_text_scale);
sfont2->m_black_border = true;
g_title_font = sfont2;
Private::title_font_height =
g_title_font->getDimension( L"X" ).Height;
#else
// font size is resolution-dependent.
// normal text will range from 0.8, in 640x* resolutions (won't scale
@ -1090,30 +1131,20 @@ namespace GUIEngine
float normal_text_scale = 0.7f + 0.2f*scale;
float title_text_scale = 0.2f + 0.2f*scale;
#endif // ENABLE_FREETYPE
#ifdef ENABLE_FREETYPE
ScalableFont* sfont =new ScalableFont(g_env,T_NORMAL);
sfont->setKerningHeight(0);
#else
ScalableFont* sfont =
new ScalableFont(g_env,
file_manager->getAssetChecked(FileManager::FONT,
"StkFont.xml",true) );
sfont->setKerningHeight(-5);
#endif // ENABLE_FREETYPE
sfont->setScale(normal_text_scale);
sfont->setKerningHeight(-5);
g_font = sfont;
#ifdef ENABLE_FREETYPE
ScalableFont* digit_font =new ScalableFont(g_env,T_DIGIT);
#else
ScalableFont* digit_font =
new ScalableFont(g_env,
file_manager->getAssetChecked(FileManager::FONT,
"BigDigitFont.xml",true));
digit_font->lazyLoadTexture(0); // make sure the texture is loaded for this one
#endif // ENABLE_FREETYPE
digit_font->setMonospaceDigits(true);
g_digit_font = digit_font;
@ -1121,11 +1152,7 @@ namespace GUIEngine
ScalableFont* sfont_larger = sfont->getHollowCopy();
sfont_larger->setScale(normal_text_scale*1.4f);
#ifdef ENABLE_FREETYPE
sfont_larger->setKerningHeight(0);
#else
sfont_larger->setKerningHeight(-5);
#endif // ENABLE_FREETYPE
g_large_font = sfont_larger;
g_outline_font = sfont->getHollowCopy();
@ -1135,40 +1162,29 @@ namespace GUIEngine
ScalableFont* sfont_smaller = sfont->getHollowCopy();
sfont_smaller->setScale(normal_text_scale*0.8f);
#ifdef ENABLE_FREETYPE
sfont_smaller->setKerningHeight(0);
#else
sfont_smaller->setKerningHeight(-5);
#endif // ENABLE_FREETYPE
g_small_font = sfont_smaller;
Private::small_font_height =
g_small_font->getDimension( L"X" ).Height;
#ifdef ENABLE_FREETYPE
ScalableFont* sfont2 =new ScalableFont(g_env,T_BOLD);
sfont2->setKerningWidth(0);
// Because the fallback font is much smaller than the title font:
sfont2->m_fallback_font_scale = 2.0f;
sfont2->m_fallback_kerning_width = 5;
#else
ScalableFont* sfont2 =
new ScalableFont(g_env,
file_manager->getAssetChecked(FileManager::FONT,
"title_font.xml",
true) );
sfont2->setKerningWidth(-18);
sfont2->m_fallback_font = sfont;
// Because the fallback font is much smaller than the title font:
sfont2->m_fallback_font_scale = 4.0f;
sfont2->m_fallback_kerning_width = 15;
#endif // ENABLE_FREETYPE
sfont2->m_fallback_font = sfont;
sfont2->setScale(title_text_scale);
sfont2->setKerningWidth(-18);
sfont2->m_black_border = true;
g_title_font = sfont2;
Private::title_font_height =
g_title_font->getDimension( L"X" ).Height;
#endif // ENABLE_FREETYPE
if (g_font != NULL) g_skin->setFont(g_font);

View File

@ -124,7 +124,8 @@ void getFontProperties::loadBoldChar(float scale)
while (it != usedchar.end())
{
//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)
//Remove all characters (>char code 8191) not used by the title
if (((iswlower((wchar_t)*it) || !iswalpha((wchar_t)*it)) && *it < 640) || *it > 8192)
it = usedchar.erase(it);
else
++it;
@ -134,8 +135,11 @@ void getFontProperties::loadBoldChar(float scale)
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
//Remove Ordinal indicator (char code 170 and 186)
usedchar.erase((wchar_t)170);
usedchar.erase((wchar_t)186); //Remove Ordinal indicator (char code 170 and 186)
usedchar.erase((wchar_t)186);
usedchar.erase((wchar_t)304); //Remove Capital I-dotted (char code 304) with using "I" altogether.
}

View File

@ -52,7 +52,8 @@ bool GlyphPageCreator::checkEnoughSpace(FT_Bitmap bits)
texture_size = d.getOptimalSize(!(GUIEngine::getDriver()->queryFeature(video::EVDF_TEXTURE_NPOT)),
!(GUIEngine::getDriver()->queryFeature(video::EVDF_TEXTURE_NSQUARE)), true, 0);
if (used_width + texture_size.Width > 512 && used_height + temp_height + texture_size.Height > 512)
if ((used_width + texture_size.Width > 512 && used_height + temp_height + texture_size.Height > 512)
|| used_height + texture_size.Height > 512)
return false;
return true;
}
@ -142,7 +143,6 @@ bool GlyphPageCreator::insertGlyph(FT_Bitmap bits, core::rect<s32>& rect)
u32 GlyphPageCreator::used_width = 0;
u32 GlyphPageCreator::used_height = 0;
u32 GlyphPageCreator::temp_height = 0;
video::IImage* GlyphPageCreator::page = 0;
} // guiengine
#endif // ENABLE_FREETYPE

View File

@ -40,13 +40,13 @@ namespace GUIEngine
* Mainly for debug use.
* \param fn The file name.
*/
static void dumpGlyphPage(const core::stringc fn);
void dumpGlyphPage(const core::stringc fn);
/** Check whether it is ok the fit the inputted glyph into the current glyph page.
* \param bits The Glyph bitmap inputted.
* \return True if there is enough space.
*/
static bool checkEnoughSpace(FT_Bitmap bits);
bool checkEnoughSpace(FT_Bitmap bits);
/** Reset position of glyph on the current glyph page.
*/
@ -54,12 +54,12 @@ namespace GUIEngine
/** Clear (fill it with transparent content) the current glyph page.
*/
static void createNewGlyphPage();
void createNewGlyphPage();
/** Used to get a glyph page which is loaded later for texture
* \return Glyph page image.
*/
static video::IImage* getPage();
video::IImage* getPage();
/** Used to insert a single glyph bitmap into the glyph page
* \param bits The Glyph bitmap inputted.
@ -75,7 +75,7 @@ namespace GUIEngine
/** A full glyph page.
*/
static video::IImage* page;
video::IImage* page;
static u32 temp_height;
static u32 used_width;

View File

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