More code clean up
Now all freetype related file are written in c++ class, which enable better coding style with current stk Windows build tested, the edge showing issue doesn't happen on Windows btw Maybe driver problems?
This commit is contained in:
parent
ebeca35460
commit
486495d976
@ -1093,7 +1093,7 @@ namespace GUIEngine
|
||||
#endif // ENABLE_FREETYPE
|
||||
|
||||
#ifdef ENABLE_FREETYPE
|
||||
ScalableFont* sfont =new ScalableFont(g_env,Normal);
|
||||
ScalableFont* sfont =new ScalableFont(g_env,T_NORMAL);
|
||||
sfont->setKerningHeight(0);
|
||||
#else
|
||||
ScalableFont* sfont =
|
||||
@ -1106,7 +1106,7 @@ namespace GUIEngine
|
||||
g_font = sfont;
|
||||
|
||||
#ifdef ENABLE_FREETYPE
|
||||
ScalableFont* digit_font =new ScalableFont(g_env,Digit);
|
||||
ScalableFont* digit_font =new ScalableFont(g_env,T_DIGIT);
|
||||
#else
|
||||
ScalableFont* digit_font =
|
||||
new ScalableFont(g_env,
|
||||
@ -1147,7 +1147,7 @@ namespace GUIEngine
|
||||
|
||||
|
||||
#ifdef ENABLE_FREETYPE
|
||||
ScalableFont* sfont2 =new ScalableFont(g_env,Bold);
|
||||
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;
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
#ifdef ENABLE_FREETYPE
|
||||
#include "guiengine/freetype_environment.hpp"
|
||||
#include "guiengine/TTF_handling.hpp"
|
||||
#include "guiengine/get_font_properties.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "utils/log.hpp"
|
||||
|
||||
|
@ -15,9 +15,8 @@
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifdef ENABLE_FREETYPE
|
||||
#include "guiengine/TTF_handling.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "guiengine/get_font_properties.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@ -28,7 +27,28 @@ namespace irr
|
||||
{
|
||||
namespace gui
|
||||
{
|
||||
TTFfile getTTFAndChar(const core::stringc &langname, TTFLoadingType type, FontUse& fu)
|
||||
|
||||
getFontProperties::getFontProperties (const core::stringc &langname, TTFLoadingType type, FontUse &fu)
|
||||
{
|
||||
findScale();
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case T_NORMAL:
|
||||
loadChar(langname, fu, normal_text_scale);
|
||||
break;
|
||||
case T_DIGIT:
|
||||
fu = F_DIGIT;
|
||||
loadNumber(normal_text_scale);
|
||||
break;
|
||||
case T_BOLD:
|
||||
fu = F_BOLD;
|
||||
loadBoldChar(title_text_scale);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void getFontProperties::findScale()
|
||||
{
|
||||
//Borrowed from engine.cpp:
|
||||
// font size is resolution-dependent.
|
||||
@ -44,28 +64,11 @@ TTFfile getTTFAndChar(const core::stringc &langname, TTFLoadingType type, FontUs
|
||||
if (screen_width < 1200) scale = std::max(0, screen_width - 640) / 750.0f;
|
||||
if (screen_width < 900 || screen_height < 700) scale = std::min(scale, 0.05f);
|
||||
|
||||
float normal_text_scale = 0.7f + 0.2f*scale;
|
||||
float title_text_scale = 0.2f + 0.2f*scale;
|
||||
|
||||
TTFfile ttf_file;
|
||||
switch(type)
|
||||
{
|
||||
case Normal:
|
||||
loadChar(langname, &ttf_file, fu, normal_text_scale);
|
||||
break;
|
||||
case Digit:
|
||||
fu = F_DIGIT;
|
||||
loadNumber(&ttf_file, normal_text_scale);
|
||||
break;
|
||||
case Bold:
|
||||
fu = F_BOLD;
|
||||
loadBoldChar(&ttf_file, title_text_scale);
|
||||
break;
|
||||
}
|
||||
return ttf_file;
|
||||
normal_text_scale = 0.7f + 0.2f*scale;
|
||||
title_text_scale = 0.2f + 0.2f*scale;
|
||||
}
|
||||
|
||||
void loadChar(const core::stringc langname, TTFfile* ttf_file, FontUse& fu, float scale)
|
||||
void getFontProperties::loadChar(const core::stringc langname, FontUse& fu, float scale)
|
||||
{
|
||||
//Determine which ttf file to load first
|
||||
if (langname == "ar" || langname == "fa")
|
||||
@ -88,38 +91,38 @@ void loadChar(const core::stringc langname, TTFfile* ttf_file, FontUse& fu, floa
|
||||
else
|
||||
fu = F_DEFAULT; //Default font file
|
||||
|
||||
ttf_file->size = (int)(29*scale); //Set to default size
|
||||
size = (int)(29*scale); //Set to default size
|
||||
|
||||
ttf_file->usedchar = translations->getCurrentAllChar(); //Loading unique characters
|
||||
usedchar = translations->getCurrentAllChar(); //Loading unique characters
|
||||
for (int i = 33; i < 256; ++i)
|
||||
ttf_file->usedchar.insert((wchar_t)i); //Include basic Latin too
|
||||
ttf_file->usedchar.insert((wchar_t)160); //Non-breaking space
|
||||
ttf_file->usedchar.insert((wchar_t)215); //Used on resolution selection screen (X).
|
||||
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).
|
||||
|
||||
//There's specific handling for some language, we may need more after more translation are added or problems found out.
|
||||
if (langname == "el")
|
||||
ttf_file->size = (int)(28*scale); //Set lower size of font for Greek as it uses lots amount of space.
|
||||
size = (int)(28*scale); //Set lower size of font for Greek as it uses lots amount of space.
|
||||
}
|
||||
|
||||
void loadNumber(TTFfile* ttf_file, float scale)
|
||||
void getFontProperties::loadNumber(float scale)
|
||||
{
|
||||
ttf_file->size = (int)(40*scale); //Set default size for Big Digit Text
|
||||
size = (int)(40*scale); //Set default size for Big Digit Text
|
||||
for (int i = 46; i < 59; ++i) //Include chars used by timer and laps count only
|
||||
ttf_file->usedchar.insert((wchar_t)i); //FIXME have to load 46 " . " to make 47 " / " display correctly, why?
|
||||
usedchar.insert((wchar_t)i); //FIXME have to load 46 " . " to make 47 " / " display correctly, why?
|
||||
}
|
||||
|
||||
void loadBoldChar(TTFfile* ttf_file, float scale)
|
||||
void getFontProperties::loadBoldChar(float scale)
|
||||
{
|
||||
ttf_file->size = (int)(120*scale); //Set default size for Bold Text
|
||||
size = (int)(120*scale); //Set default size for Bold Text
|
||||
for (int i = 33; i < 256; ++i)
|
||||
ttf_file->usedchar.insert((wchar_t)i);
|
||||
usedchar.insert((wchar_t)i);
|
||||
|
||||
setlocale(LC_ALL, "en_US.UTF8");
|
||||
std::set<wchar_t>::iterator it = ttf_file->usedchar.begin();
|
||||
while (it != ttf_file->usedchar.end())
|
||||
std::set<wchar_t>::iterator it = usedchar.begin();
|
||||
while (it != usedchar.end())
|
||||
{
|
||||
if (iswlower((wchar_t)*it))
|
||||
it = ttf_file->usedchar.erase(it);
|
||||
it = usedchar.erase(it);
|
||||
else
|
||||
++it;
|
||||
}
|
||||
@ -127,4 +130,3 @@ void loadBoldChar(TTFfile* ttf_file, float scale)
|
||||
|
||||
} // end namespace gui
|
||||
} // end namespace irr
|
||||
#endif // ENABLE_FREETYPE
|
@ -16,9 +16,6 @@
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include <irrlicht.h>
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace irr
|
||||
@ -26,20 +23,28 @@ namespace irr
|
||||
namespace gui
|
||||
{
|
||||
|
||||
enum TTFLoadingType {Normal, Digit, Bold};
|
||||
|
||||
enum FontUse {F_DEFAULT, F_CJK, F_AR, F_LAYNE, F_BOLD, F_DIGIT};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
std::set<wchar_t> usedchar;
|
||||
unsigned short size;
|
||||
}TTFfile;
|
||||
enum TTFLoadingType {T_NORMAL, T_DIGIT, T_BOLD};
|
||||
|
||||
TTFfile getTTFAndChar(const core::stringc &langname, TTFLoadingType, FontUse&);
|
||||
void loadChar(core::stringc, TTFfile*, FontUse&, float);
|
||||
void loadNumber(TTFfile*, float);
|
||||
void loadBoldChar(TTFfile*, float);
|
||||
class getFontProperties
|
||||
{
|
||||
public:
|
||||
getFontProperties (const core::stringc &langname, TTFLoadingType type, FontUse &fu);
|
||||
|
||||
unsigned short size;
|
||||
std::set<wchar_t> usedchar;
|
||||
|
||||
private:
|
||||
void loadChar(core::stringc, FontUse&, float);
|
||||
void loadNumber(float);
|
||||
void loadBoldChar(float);
|
||||
|
||||
void findScale();
|
||||
|
||||
float normal_text_scale;
|
||||
float title_text_scale;
|
||||
};
|
||||
|
||||
} // end namespace gui
|
||||
} // end namespace irr
|
@ -20,7 +20,7 @@
|
||||
#include <cmath>
|
||||
#include <cwctype>
|
||||
|
||||
#define cur_face GUIEngine::get_Freetype()->ft_face[fu]
|
||||
#define cur_face GUIEngine::get_Freetype()->ft_face[fu]
|
||||
#define gp_creator GUIEngine::get_GP_Creator()
|
||||
|
||||
namespace irr
|
||||
@ -377,14 +377,14 @@ bool ScalableFont::loadTTF()
|
||||
//Determine which font(face) and size to load,
|
||||
//also get all used char base on current language settings
|
||||
FontUse fu;
|
||||
TTFfile TTF_file = getTTFAndChar(translations->getCurrentLanguageNameCode().c_str(), m_type, fu);
|
||||
getFontProperties cur_prop(translations->getCurrentLanguageNameCode().c_str(), m_type, fu);
|
||||
|
||||
std::vector <s32> offset;
|
||||
std::vector <s32> bx;
|
||||
std::vector <s32> advance;
|
||||
std::vector <s32> height;
|
||||
|
||||
err = FT_Set_Pixel_Sizes(cur_face, 0, TTF_file.size);
|
||||
err = FT_Set_Pixel_Sizes(cur_face, 0, cur_prop.size);
|
||||
if (err)
|
||||
Log::error("ScalableFont::loadTTF", "Can't set font size.");
|
||||
|
||||
@ -396,7 +396,7 @@ bool ScalableFont::loadTTF()
|
||||
u32 texno = 0;
|
||||
SpriteBank->addTexture(NULL);
|
||||
gp_creator->createNewGlyphPage();
|
||||
for (it = TTF_file.usedchar.begin(); it != TTF_file.usedchar.end(); ++it)
|
||||
for (it = cur_prop.usedchar.begin(); it != cur_prop.usedchar.end(); ++it)
|
||||
{
|
||||
SGUISpriteFrame f;
|
||||
SGUISprite s;
|
||||
@ -463,7 +463,7 @@ bool ScalableFont::loadTTF()
|
||||
}
|
||||
|
||||
// Check for glyph page which can fit all characters
|
||||
if (it == --TTF_file.usedchar.end())
|
||||
if (it == --cur_prop.usedchar.end())
|
||||
{
|
||||
SpriteBank->setTexture(texno, Driver->addTexture("Glyph_page", gp_creator->getPage()));
|
||||
gp_creator->clearGlyphPage();
|
||||
@ -471,24 +471,24 @@ bool ScalableFont::loadTTF()
|
||||
}
|
||||
|
||||
//Fix unused glyphs....
|
||||
if (m_type == Normal || Bold)
|
||||
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)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 "-".
|
||||
|
||||
if (m_type == Normal)
|
||||
if (m_type == T_NORMAL)
|
||||
{
|
||||
CharacterMap[(wchar_t)8204] = 0; //They are zero width chars found in Arabic.
|
||||
CharacterMap[(wchar_t)65279] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_type == Bold)
|
||||
if (m_type == T_BOLD)
|
||||
{
|
||||
setlocale(LC_ALL, "en_US.UTF8");
|
||||
for (it = TTF_file.usedchar.begin(); it != TTF_file.usedchar.end(); ++it)
|
||||
for (it = cur_prop.usedchar.begin(); it != cur_prop.usedchar.end(); ++it)
|
||||
{
|
||||
if (iswupper((wchar_t)*it))
|
||||
CharacterMap[towlower((wchar_t)*it)] = getAreaIDFromCharacter(*it, NULL);
|
||||
@ -524,11 +524,11 @@ bool ScalableFont::loadTTF()
|
||||
WrongCharacter = getAreaIDFromCharacter(L' ', NULL);
|
||||
|
||||
//Add 5 for ttf bitmap to display Chinese better, 40 for digit font to display separately
|
||||
//Consider fallback font (Bold) too
|
||||
MaxHeight = (int)((current_maxheight + (m_type == Digit ? 40 : 5) +
|
||||
(m_type == Bold ? 20 : 0))*m_scale);
|
||||
//Consider fallback font (bold) too
|
||||
MaxHeight = (int)((current_maxheight + (m_type == T_DIGIT ? 40 : 5) +
|
||||
(m_type == T_BOLD ? 20 : 0))*m_scale);
|
||||
|
||||
if (m_type == Digit)
|
||||
if (m_type == T_DIGIT)
|
||||
{
|
||||
for(wchar_t c='0'; c<='9'; c++)
|
||||
{
|
||||
@ -541,20 +541,20 @@ bool ScalableFont::loadTTF()
|
||||
|
||||
switch (m_type)
|
||||
{
|
||||
case Normal:
|
||||
case T_NORMAL:
|
||||
Log::info("ScalableFont::loadTTF", "Created %d glyphs "
|
||||
"supporting %d characters for normal font %s at %d dpi using %d glyph page(s)."
|
||||
, Areas.size(), CharacterMap.size(), cur_face->family_name, TTF_file.size, texno + 1);
|
||||
, Areas.size(), CharacterMap.size(), cur_face->family_name, cur_prop.size, texno + 1);
|
||||
break;
|
||||
case Digit:
|
||||
case T_DIGIT:
|
||||
Log::info("ScalableFont::loadTTF", "Created %d glyphs "
|
||||
"supporting %d characters for high-res digits font %s at %d dpi using %d glyph page(s)."
|
||||
, Areas.size(), CharacterMap.size(), cur_face->family_name, TTF_file.size, texno + 1);
|
||||
, Areas.size(), CharacterMap.size(), cur_face->family_name, cur_prop.size, texno + 1);
|
||||
break;
|
||||
case Bold:
|
||||
case T_BOLD:
|
||||
Log::info("ScalableFont::loadTTF", "Created %d glyphs "
|
||||
"supporting %d characters for bold title font %s at %d dpi using %d glyph page(s)."
|
||||
, Areas.size(), CharacterMap.size(), cur_face->family_name, TTF_file.size, texno + 1);
|
||||
, Areas.size(), CharacterMap.size(), cur_face->family_name, cur_prop.size, texno + 1);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -847,10 +847,10 @@ void ScalableFont::doDraw(const core::stringw& text,
|
||||
int Vpadding = floor((float) area.offsety*
|
||||
(fallback[i] ? m_scale*m_fallback_font_scale : m_scale));
|
||||
offset.X += Hpadding;
|
||||
offset.Y += Vpadding + floor(m_type == Digit ? 20*m_scale : 0); //Additional offset for digit text
|
||||
offset.Y += Vpadding + floor(m_type == T_DIGIT ? 20*m_scale : 0); //Additional offset for digit text
|
||||
offsets.push_back(offset);
|
||||
offset.X -= Hpadding;
|
||||
offset.Y -= Vpadding + floor(m_type == Digit ? 20*m_scale : 0);
|
||||
offset.Y -= Vpadding + floor(m_type == T_DIGIT ? 20*m_scale : 0);
|
||||
}
|
||||
else //Billboard text specific
|
||||
{
|
||||
@ -859,10 +859,10 @@ void ScalableFont::doDraw(const core::stringw& text,
|
||||
int Vpadding = floor((float) area.offsety_bt*
|
||||
(fallback[i] ? m_scale*m_fallback_font_scale : m_scale));
|
||||
offset.X += Hpadding;
|
||||
offset.Y += Vpadding + floor(m_type == Digit ? 20*m_scale : 0); //Additional offset for digit text
|
||||
offset.Y += Vpadding + floor(m_type == T_DIGIT ? 20*m_scale : 0); //Additional offset for digit text
|
||||
offsets.push_back(offset);
|
||||
offset.X -= Hpadding;
|
||||
offset.Y -= Vpadding + floor(m_type == Digit ? 20*m_scale : 0);
|
||||
offset.Y -= Vpadding + floor(m_type == T_DIGIT ? 20*m_scale : 0);
|
||||
}
|
||||
#else
|
||||
offset.X += area.underhang;
|
||||
@ -994,7 +994,7 @@ void ScalableFont::doDraw(const core::stringw& text,
|
||||
}
|
||||
|
||||
#ifdef ENABLE_FREETYPE
|
||||
if (fallback[n] || m_type == Bold)
|
||||
if (fallback[n] || m_type == T_BOLD)
|
||||
#else
|
||||
if (fallback[n])
|
||||
#endif // ENABLE_FREETYPE
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "utils/leak_check.hpp"
|
||||
|
||||
#ifdef ENABLE_FREETYPE
|
||||
#include "guiengine/TTF_handling.hpp"
|
||||
#include "guiengine/get_font_properties.hpp"
|
||||
#endif // ENABLE_FREETYPE
|
||||
|
||||
#include "IrrCompileConfig.h"
|
||||
|
Loading…
x
Reference in New Issue
Block a user