diff --git a/src/graphics/material_manager.hpp b/src/graphics/material_manager.hpp index fc95bc02f..6bd087e4c 100644 --- a/src/graphics/material_manager.hpp +++ b/src/graphics/material_manager.hpp @@ -24,11 +24,12 @@ namespace irr { - namespace video { class ITexture; enum E_MATERIAL_TYPE; } + namespace video { class ITexture; } namespace scene { class IMeshBuffer; class ISceneNode; } } using namespace irr; +#include #include #include #include diff --git a/src/graphics/stk_text_billboard.cpp b/src/graphics/stk_text_billboard.cpp index b0340c216..b8e3ee2b0 100644 --- a/src/graphics/stk_text_billboard.cpp +++ b/src/graphics/stk_text_billboard.cpp @@ -67,7 +67,7 @@ scene::IMesh* STKTextBillboard::getTextMesh(core::stringw text, gui::ScalableFon font->doDraw(text, core::rect(0, 0, size.Width, size.Height), video::SColor(255,255,255,255), false, false, NULL, this); - const float scale = 0.018f; + const float scale = (font->m_isTTF ? 0.03f : 0.018f); //Larger for ttf font as they are less bold //scene::SMesh* mesh = new scene::SMesh(); std::map buffers; diff --git a/src/guiengine/TTF_handling.cpp b/src/guiengine/TTF_handling.cpp index f36b68e5b..a26907d6e 100644 --- a/src/guiengine/TTF_handling.cpp +++ b/src/guiengine/TTF_handling.cpp @@ -23,16 +23,20 @@ // http://irrlicht.suckerfreegames.com/ #ifdef ENABLE_FREETYPE -#include "io/file_manager.hpp" #include "guiengine/TTF_handling.hpp" #include "graphics/irr_driver.hpp" +#include "io/file_manager.hpp" +#include "utils/translation.hpp" + #include +#include +#include namespace irr { namespace gui { -TTFfile getTTFAndChar(const std::string &langname, TTFLoadingType type, FontUse& fu) +TTFfile getTTFAndChar(const core::stringc &langname, TTFLoadingType type, FontUse& fu) { //Borrowed from engine.cpp: // font size is resolution-dependent. @@ -69,26 +73,24 @@ TTFfile getTTFAndChar(const std::string &langname, TTFLoadingType type, FontUse& return ttf_file; } -void loadChar(const std::string langname, TTFfile* ttf_file, FontUse& fu, float scale) +void loadChar(const core::stringc langname, TTFfile* ttf_file, FontUse& fu, float scale) { //Determine which ttf file to load first - if (langname.compare("ar") == 0 || langname.compare("fa") == 0) + if (langname == "ar" || langname == "fa") fu = F_AR; - else if (langname.compare("sq") == 0 || langname.compare("eu") == 0 - || langname.compare("br") == 0 || langname.compare("da") == 0 - || langname.compare("nl") == 0 || langname.compare("en") == 0 - || langname.compare("gd") == 0 || langname.compare("gl") == 0 - || langname.compare("de") == 0 || langname.compare("is") == 0 - || langname.compare("id") == 0 || langname.compare("it") == 0 - || langname.compare("nb") == 0 || langname.compare("nn") == 0 - || langname.compare("pt") == 0 || langname.compare("es") == 0 - || langname.compare("sv") == 0 || langname.compare("uz") == 0) + else if (langname == "sq" || langname == "eu" || langname == "br" || + langname == "da" || langname == "nl" || langname == "en" || + langname == "gd" || langname == "gl" || langname == "de" || + langname == "is" || langname == "id" || langname == "it" || + langname == "nb" || langname == "nn" || langname == "pt" || + langname == "es" || langname == "sv" || langname == "uz") //They are sorted out by running fc-list :lang="name" |grep Layne + //But we may get rid of the above by using a font that suitable for most language + //Like FreeSans/FreeSerif fu = F_LAYNE; - else if (langname.compare("zh") == 0 || langname.compare("ko") == 0 - || langname.compare("ja") == 0) + else if (langname == "zh" || langname == "ja" || langname == "ko") fu = F_CJK; else @@ -103,7 +105,7 @@ void loadChar(const std::string langname, TTFfile* ttf_file, FontUse& fu, float ttf_file->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.compare("el") == 0) + if (langname == "el") ttf_file->size = (int)(28*scale); //Set lower size of font for Greek as it uses lots amount of space. } diff --git a/src/guiengine/TTF_handling.hpp b/src/guiengine/TTF_handling.hpp index 269cc7c4e..69b4719a6 100644 --- a/src/guiengine/TTF_handling.hpp +++ b/src/guiengine/TTF_handling.hpp @@ -16,13 +16,11 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include "utils/translation.hpp" #include #include #include FT_FREETYPE_H -#include -#include +#include namespace irr { @@ -37,12 +35,11 @@ typedef struct { std::set usedchar; unsigned short size; - std::string filename; }TTFfile; -TTFfile getTTFAndChar(const std::string &langname, TTFLoadingType, FontUse&); +TTFfile getTTFAndChar(const core::stringc &langname, TTFLoadingType, FontUse&); video::IImage* generateTTFImage (FT_Bitmap, video::IVideoDriver*); -void loadChar(const std::string, TTFfile*, FontUse&, float); +void loadChar(core::stringc, TTFfile*, FontUse&, float); void loadNumber(TTFfile*, float); void loadBoldChar(TTFfile*, float); diff --git a/src/guiengine/freetype_environment.cpp b/src/guiengine/freetype_environment.cpp index a1419b1a1..5c4f65321 100644 --- a/src/guiengine/freetype_environment.cpp +++ b/src/guiengine/freetype_environment.cpp @@ -19,6 +19,7 @@ #include "guiengine/freetype_environment.hpp" #include "guiengine/TTF_handling.hpp" #include "io/file_manager.hpp" +#include "utils/log.hpp" namespace irr { diff --git a/src/guiengine/freetype_environment.hpp b/src/guiengine/freetype_environment.hpp index 08664ce4b..2752ef74d 100644 --- a/src/guiengine/freetype_environment.hpp +++ b/src/guiengine/freetype_environment.hpp @@ -16,8 +16,6 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include "io/file_manager.hpp" - #include #include FT_FREETYPE_H diff --git a/src/guiengine/scalable_font.cpp b/src/guiengine/scalable_font.cpp index 567c6dee2..d71770d50 100644 --- a/src/guiengine/scalable_font.cpp +++ b/src/guiengine/scalable_font.cpp @@ -16,7 +16,9 @@ #include #include +#include #include +#include #define cur_face GUIEngine::get_Freetype()->ft_face[fu] @@ -374,7 +376,7 @@ 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(), m_type, fu); + TTFfile TTF_file = getTTFAndChar(translations->getCurrentLanguageNameCode().c_str(), m_type, fu); std::vector offset; std::vector bx; @@ -467,6 +469,13 @@ bool ScalableFont::loadTTF() a.spriteno = n; a.offsety = current_maxheight - height.at(n) + offset.at(n); //Compute the correct offset as ttf texture image is cropped against the glyph fully. + + a.offsety_bt = -offset.at(n); //FIXME + //Specific offset for billboard text as billboard text seems to be drawn bottom-up, + //as the offset in calculated based on the fact that the characters are drawn all + //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 a.bearingx = 0; else @@ -578,6 +587,7 @@ s32 ScalableFont::getKerningWidth(const wchar_t* thisLetter, const wchar_t* prev } } #endif // ENABLE_FREETYPE + return ret; } @@ -796,16 +806,31 @@ void ScalableFont::doDraw(const core::stringw& text, const SFontArea &area = getAreaFromCharacter(c, &use_fallback_font); fallback[i] = use_fallback_font; #ifdef ENABLE_FREETYPE - //floor is used to prevent negligible movement when m_scale changes with resolution - int Hpadding = floor((float) area.bearingx* - (fallback[i] ? m_scale*m_fallback_font_scale : m_scale)); - 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 - offsets.push_back(offset); - offset.X -= Hpadding; - offset.Y -= Vpadding + floor(m_type == Digit ? 20*m_scale : 0); + if (charCollector == NULL) + { + //floor is used to prevent negligible movement when m_scale changes with resolution + int Hpadding = floor((float) area.bearingx* + (fallback[i] ? m_scale*m_fallback_font_scale : m_scale)); + 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 + offsets.push_back(offset); + offset.X -= Hpadding; + offset.Y -= Vpadding + floor(m_type == Digit ? 20*m_scale : 0); + } + else //Billboard text specific + { + int Hpadding = floor((float) area.bearingx* + (fallback[i] ? m_scale*m_fallback_font_scale : m_scale)); + 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 + offsets.push_back(offset); + offset.X -= Hpadding; + offset.Y -= Vpadding + floor(m_type == Digit ? 20*m_scale : 0); + } #else offset.X += area.underhang; offsets.push_back(offset); @@ -862,6 +887,7 @@ void ScalableFont::doDraw(const core::stringw& text, } else char_scale = 1.0f; + core::dimension2d size = source.getSize(); float scale = (fallback[n] ? m_scale*m_fallback_font_scale : m_scale); @@ -892,6 +918,7 @@ void ScalableFont::doDraw(const core::stringw& text, #ifdef FONT_DEBUG GL32_draw2DRectangle(video::SColor(255, 255,0,0), dest,clip); #endif + if (texture == NULL && !m_isTTF) { // perform lazy loading diff --git a/src/guiengine/scalable_font.hpp b/src/guiengine/scalable_font.hpp index b121378e4..7c9025bd8 100644 --- a/src/guiengine/scalable_font.hpp +++ b/src/guiengine/scalable_font.hpp @@ -19,6 +19,7 @@ #include "IReadFile.h" #include "irrArray.h" + #include #include @@ -189,6 +190,7 @@ private: s32 width; u32 spriteno; s32 offsety; + s32 offsety_bt; s32 bearingx; }; #else