Fix build and code clean up
Now billboard text should have a better alignment
This commit is contained in:
parent
d47faaaa89
commit
1e7e895d7f
@ -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 <irrlicht.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
@ -67,7 +67,7 @@ scene::IMesh* STKTextBillboard::getTextMesh(core::stringw text, gui::ScalableFon
|
||||
font->doDraw(text, core::rect<s32>(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<video::ITexture*, scene::SMeshBuffer*> buffers;
|
||||
|
@ -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 <algorithm>
|
||||
#include <clocale>
|
||||
#include <cwctype>
|
||||
|
||||
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.
|
||||
}
|
||||
|
||||
|
@ -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 <IVideoDriver.h>
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
#include <cwctype>
|
||||
#include <clocale>
|
||||
#include <set>
|
||||
|
||||
namespace irr
|
||||
{
|
||||
@ -37,12 +35,11 @@ typedef struct
|
||||
{
|
||||
std::set<wchar_t> 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);
|
||||
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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 <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
|
@ -16,7 +16,9 @@
|
||||
#include <IVideoDriver.h>
|
||||
#include <IXMLReader.h>
|
||||
|
||||
#include <clocale>
|
||||
#include <cmath>
|
||||
#include <cwctype>
|
||||
|
||||
#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 <s32> offset;
|
||||
std::vector <s32> 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<s32> 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
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "IReadFile.h"
|
||||
#include "irrArray.h"
|
||||
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
@ -189,6 +190,7 @@ private:
|
||||
s32 width;
|
||||
u32 spriteno;
|
||||
s32 offsety;
|
||||
s32 offsety_bt;
|
||||
s32 bearingx;
|
||||
};
|
||||
#else
|
||||
|
Loading…
x
Reference in New Issue
Block a user