19 #ifndef HEADER_FONT_WITH_FACE_HPP
20 #define HEADER_FONT_WITH_FACE_HPP
22 #include "utils/cpp2011.hpp"
23 #include "utils/leak_check.hpp"
24 #include "utils/no_copy.hpp"
34 #include FT_FREETYPE_H
38 #include <GlyphLayout.h>
39 #include <dimension2d.h>
40 #include <irrString.h>
45 const int BEARING = 64;
85 const core::rect<float>& destRect,
86 const core::rect<s32>& sourceRect,
87 const video::SColor*
const colors) = 0;
105 if (!supportLazyLoadChar() && !first_load)
return;
107 for (
const wchar_t* p = in_ptr; *p; ++p)
109 if (*p == L
'\r' || *p == L
'\n' || *p < (
wchar_t)32)
116 else if (m_fallback_font != NULL)
118 if (!m_fallback_font->loadedChar(*p))
120 m_fallback_font->loadGlyphInfo(*p);
121 if (m_fallback_font->supportChar(*p))
122 m_fallback_font->addLazyLoadChar(*p);
129 void updateCharactersList();
144 GlyphInfo(
unsigned int font_num = 0,
unsigned int glyph_idx = 0) :
145 font_number(font_num), glyph_index(glyph_idx) {}
186 float getCharWidth(
const FontArea& area,
bool fallback,
float scale)
const;
193 std::map<wchar_t, GlyphInfo>::const_iterator n =
194 m_character_glyph_info_map.find(c);
195 if (n != m_character_glyph_info_map.end())
206 std::map<wchar_t, GlyphInfo>::const_iterator n =
207 m_character_glyph_info_map.find(c);
209 assert(n != m_character_glyph_info_map.end());
219 std::map<wchar_t, GlyphInfo>::const_iterator n =
220 m_character_glyph_info_map.find(c);
221 if (n != m_character_glyph_info_map.end())
223 return n->second.glyph_index > 0;
228 void loadGlyphInfo(
wchar_t c);
230 void createNewGlyphPage();
249 virtual bool isBold()
const {
return false; }
251 const FontArea* getUnknownFontArea()
const;
253 std::vector<gui::GlyphLayout> text2GlyphsWithoutShaping(
254 const core::stringw& t);
272 virtual
void reset();
274 virtual core::dimension2d<u32> getDimension(const core::stringw& text,
277 int getCharacterFromPos(const
wchar_t* text,
int pixel_x,
280 void render(const std::vector<gui::GlyphLayout>& gl,
281 const core::rect<s32>& position, const video::SColor& color,
282 bool hcenter,
bool vcenter, const core::rect<s32>* clip,
284 FontCharCollector* char_collector = NULL);
286 virtual
void drawText(const core::stringw& text,
287 const core::rect<s32>& position,
288 const video::SColor& color,
bool hcenter,
289 bool vcenter, const core::rect<s32>* clip,
291 FontCharCollector* char_collector = NULL);
293 void drawTextQuick(const core::stringw& text,
294 const core::rect<s32>& position,
295 const video::SColor& color,
bool hcenter,
bool vcenter,
296 const core::rect<s32>* clip,
298 FontCharCollector* char_collector = NULL);
300 void dumpGlyphPage(const std::
string& name);
302 void dumpGlyphPage();
305 gui::IGUISpriteBank* getSpriteBank()
const {
return m_spritebank; }
307 const FontArea& getAreaFromCharacter(
const wchar_t c,
308 bool* fallback_font)
const;
311 unsigned int getDPI()
const {
return m_face_dpi; }
313 FaceTTF* getFaceTTF()
const {
return m_face_ttf; }
315 void insertGlyph(
unsigned font_number,
unsigned glyph_index);
317 int getFontMaxHeight()
const {
return m_font_max_height; }
319 int getGlyphMaxHeight()
const {
return m_glyph_max_height; }
321 virtual bool disableTextShaping()
const {
return false; }
323 float getInverseShaping()
const {
return m_inverse_shaping; }
325 virtual bool useColorGlyphPage()
const {
return false; }
This class will load a list of TTF files from FontManager, and save them inside m_ft_faces for FontWi...
Definition: face_ttf.hpp:57
This class stores settings when rendering fonts, used when instantiating irr::gui::ScalableFont.
Definition: font_settings.hpp:33
A class for STKTextBillboard to get font info to render billboard text.
Definition: font_with_face.hpp:77
virtual void collectChar(video::ITexture *texture, const core::rect< float > &destRect, const core::rect< s32 > &sourceRect, const video::SColor *const colors)=0
Collect the character info for billboard text.
An abstract class which contains functions which convert vector fonts into bitmap and render them in ...
Definition: font_with_face.hpp:72
int m_font_max_height
Used in vertical dimension calculation.
Definition: font_with_face.hpp:92
void setFallbackFontScale(float scale)
Set the scaling of fallback font.
Definition: font_with_face.hpp:138
virtual bool supportLazyLoadChar() const
Override it if sub-class should not do lazy loading characters.
Definition: font_with_face.hpp:236
float m_inverse_shaping
Used to undo the scale on text shaping, only need to take care of width.
Definition: font_with_face.hpp:181
float m_fallback_font_scale
Scaling for fallback font.
Definition: font_with_face.hpp:159
virtual unsigned int getScalingFactorTwo() const =0
Defined by sub-class about the scaling factor 2.
unsigned int m_used_width
The used width in glyph page.
Definition: font_with_face.hpp:171
int m_glyph_max_height
Used in top side bearing calculation.
Definition: font_with_face.hpp:95
std::set< wchar_t > m_new_char_holder
A temporary holder to store new characters to be inserted.
Definition: font_with_face.hpp:162
virtual bool isBold() const
Override it if sub-class has bold outline.
Definition: font_with_face.hpp:249
virtual int shapeOutline(FT_Outline *outline) const
Override it if any outline shaping is needed to be done before rendering the glyph into bitmap.
Definition: font_with_face.hpp:260
void addLazyLoadChar(wchar_t c)
Add a character into m_new_char_holder for lazy loading later.
Definition: font_with_face.hpp:233
void setFallbackFont(FontWithFace *face)
Set the fallback font for this font, so if some character is missing in this font,...
Definition: font_with_face.hpp:134
virtual float getScalingFactorOne() const =0
Defined by sub-class about the scaling factor 1.
void insertCharacters(const wchar_t *in_ptr, bool first_load=false)
Check characters to see if they are loaded in font, if not load them.
Definition: font_with_face.hpp:103
unsigned int m_face_dpi
The dpi of this font.
Definition: font_with_face.hpp:177
const GlyphInfo & getGlyphInfo(wchar_t c) const
Get the GlyphInfo from m_character_glyph_info_map about a character.
Definition: font_with_face.hpp:204
unsigned int m_current_height
The current max height at current drawing line in glyph page.
Definition: font_with_face.hpp:168
bool loadedChar(wchar_t c) const
Test if a character has already been tried to be loaded.
Definition: font_with_face.hpp:191
unsigned int m_used_height
The used height in glyph page.
Definition: font_with_face.hpp:174
unsigned int getDPI() const
Return the dpi of this face.
Definition: font_with_face.hpp:311
virtual unsigned int getGlyphPageSize() const =0
Defined by sub-class about the texture size of glyph page, it should be a power of two.
bool supportChar(wchar_t c)
Tells whether a character is supported by all TTFs in m_face_ttf which is determined by GlyphInfo of ...
Definition: font_with_face.hpp:217
FontWithFace * m_fallback_font
Fallback font to use if some character isn't supported by this font.
Definition: font_with_face.hpp:156
virtual float getNativeScalingFactor() const
Defined by sub-class about the native scaling factor, to provide.
Definition: font_with_face.hpp:329
gui::IGUISpriteBank * m_spritebank
Sprite bank to store each glyph.
Definition: font_with_face.hpp:165
std::map< wchar_t, GlyphInfo > m_character_glyph_info_map
Store a list of loaded and tested character to a GlyphInfo.
Definition: font_with_face.hpp:183
FaceTTF * m_face_ttf
FaceTTF to load glyph from.
Definition: font_with_face.hpp:153
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:26
Glyph metrics for each glyph loaded.
Definition: face_ttf.hpp:37
Mapping of glyph index to a TTF in FaceTTF.
Definition: font_with_face.hpp:143
unsigned int glyph_index
Glyph index in the TTF, 0 means no such glyph.
Definition: font_with_face.hpp:149
unsigned int font_number
Index to a TTF in FaceTTF.
Definition: font_with_face.hpp:147