SuperTuxKart
|
An abstract class which contains functions which convert vector fonts into bitmap and render them in STK. More...
#include <font_with_face.hpp>
Classes | |
class | FontCharCollector |
A class for STKTextBillboard to get font info to render billboard text. More... | |
struct | GlyphInfo |
Mapping of glyph index to a TTF in FaceTTF. More... | |
Public Member Functions | |
FontWithFace (const std::string &name) | |
Constructor. | |
virtual | ~FontWithFace () |
Destructor. | |
virtual void | init () |
Initialize the font structure, but don't load glyph here. | |
virtual void | reset () |
Clear all the loaded characters, sub-class can do pre-loading of characters after this. | |
virtual core::dimension2d< u32 > | getDimension (const core::stringw &text, FontSettings *font_settings=NULL) |
Get the dimension of text with support to different FontSettings, it will also do checking for missing characters in font and lazy load them. | |
int | getCharacterFromPos (const wchar_t *text, int pixel_x, FontSettings *font_settings=NULL) const |
Calculate the index of the character in the text on a specific position. | |
void | render (const std::vector< gui::GlyphLayout > &gl, const core::rect< s32 > &position, const video::SColor &color, bool hcenter, bool vcenter, const core::rect< s32 > *clip, FontSettings *font_settings, FontCharCollector *char_collector=NULL) |
Render text and clip it to the specified rectangle if wanted, it will also do checking for missing characters in font and lazy load them. | |
virtual void | drawText (const core::stringw &text, const core::rect< s32 > &position, const video::SColor &color, bool hcenter, bool vcenter, const core::rect< s32 > *clip, FontSettings *font_settings, FontCharCollector *char_collector=NULL) |
void | drawTextQuick (const core::stringw &text, const core::rect< s32 > &position, const video::SColor &color, bool hcenter, bool vcenter, const core::rect< s32 > *clip, FontSettings *font_settings, FontCharCollector *char_collector=NULL) |
void | dumpGlyphPage (const std::string &name) |
Write the current glyph page in png inside current running directory. | |
void | dumpGlyphPage () |
Write the current glyph page in png inside current running directory. | |
gui::IGUISpriteBank * | getSpriteBank () const |
Return the sprite bank. | |
const FontArea & | getAreaFromCharacter (const wchar_t c, bool *fallback_font) const |
Return the FontArea about a character. | |
unsigned int | getDPI () const |
Return the dpi of this face. | |
FaceTTF * | getFaceTTF () const |
void | insertGlyph (unsigned font_number, unsigned glyph_index) |
Render a glyph for a character into bitmap and save it into the glyph page. | |
int | getFontMaxHeight () const |
int | getGlyphMaxHeight () const |
virtual bool | disableTextShaping () const |
float | getInverseShaping () const |
virtual bool | useColorGlyphPage () const |
void | setDPI () |
Set the face dpi which is resolution-dependent. | |
Protected Member Functions | |
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. | |
void | updateCharactersList () |
Update the supported characters for this font if required. | |
void | setFallbackFont (FontWithFace *face) |
Set the fallback font for this font, so if some character is missing in this font, it will use that fallback font to try rendering it. | |
void | setFallbackFontScale (float scale) |
Set the scaling of fallback font. | |
Protected Attributes | |
int | m_font_max_height |
Used in vertical dimension calculation. | |
int | m_glyph_max_height |
Used in top side bearing calculation. | |
Private Member Functions | |
float | getCharWidth (const FontArea &area, bool fallback, float scale) const |
Return a character width. | |
bool | loadedChar (wchar_t c) const |
Test if a character has already been tried to be loaded. | |
const GlyphInfo & | getGlyphInfo (wchar_t c) const |
Get the GlyphInfo from m_character_glyph_info_map about a character. | |
bool | supportChar (wchar_t c) |
Tells whether a character is supported by all TTFs in m_face_ttf which is determined by GlyphInfo of this character. | |
void | loadGlyphInfo (wchar_t c) |
Convert a character to a glyph index in one of the font in m_face_ttf, it will find the first TTF that supports this character, if the final glyph_index is 0, this means such character is not supported by all TTFs in m_face_ttf. | |
void | createNewGlyphPage () |
Create a new glyph page by filling it with transparent content. | |
void | addLazyLoadChar (wchar_t c) |
Add a character into m_new_char_holder for lazy loading later. | |
virtual bool | supportLazyLoadChar () const |
Override it if sub-class should not do lazy loading characters. | |
virtual unsigned int | getGlyphPageSize () const =0 |
Defined by sub-class about the texture size of glyph page, it should be a power of two. | |
virtual float | getScalingFactorOne () const =0 |
Defined by sub-class about the scaling factor 1. | |
virtual unsigned int | getScalingFactorTwo () const =0 |
Defined by sub-class about the scaling factor 2. | |
virtual bool | isBold () const |
Override it if sub-class has bold outline. | |
const FontArea * | getUnknownFontArea () const |
std::vector< gui::GlyphLayout > | text2GlyphsWithoutShaping (const core::stringw &t) |
Convert text to drawable GlyphLayout without text shaping, used in digit font or debugging message. | |
virtual int | shapeOutline (FT_Outline *outline) const |
Override it if any outline shaping is needed to be done before rendering the glyph into bitmap. | |
Private Attributes | |
FaceTTF * | m_face_ttf |
FaceTTF to load glyph from. | |
FontWithFace * | m_fallback_font |
Fallback font to use if some character isn't supported by this font. | |
float | m_fallback_font_scale |
Scaling for fallback font. | |
std::set< wchar_t > | m_new_char_holder |
A temporary holder to store new characters to be inserted. | |
gui::IGUISpriteBank * | m_spritebank |
Sprite bank to store each glyph. | |
unsigned int | m_current_height |
The current max height at current drawing line in glyph page. | |
unsigned int | m_used_width |
The used width in glyph page. | |
unsigned int | m_used_height |
The used height in glyph page. | |
unsigned int | m_face_dpi |
The dpi of this font. | |
float | m_inverse_shaping |
Used to undo the scale on text shaping, only need to take care of width. | |
std::map< wchar_t, GlyphInfo > | m_character_glyph_info_map |
Store a list of loaded and tested character to a GlyphInfo. | |
An abstract class which contains functions which convert vector fonts into bitmap and render them in STK.
To make STK draw characters with different render option (like scaling, shadow) using a same FontWithFace, you need to wrap this with irr::gui::ScalableFont and configure the FontSettings for it.
FontWithFace::FontWithFace | ( | const std::string & | name | ) |
Constructor.
It will initialize the m_spritebank and TTF files to use.
name | The name of face, used by irrlicht to distinguish spritebank. |
ttf | FaceTTF for this face to use. |
|
virtual |
Destructor.
Clears the glyph page and sprite bank.
void FontWithFace::dumpGlyphPage | ( | ) |
Write the current glyph page in png inside current running directory.
Useful in gdb without parameter.
void FontWithFace::dumpGlyphPage | ( | const std::string & | name | ) |
Write the current glyph page in png inside current running directory.
Mainly for debug use.
name | The file name. |
const FontArea & FontWithFace::getAreaFromCharacter | ( | const wchar_t | c, |
bool * | fallback_font | ||
) | const |
Return the FontArea about a character.
c | The character to get. | |
[out] | fallback_font | Whether fallback font is used. |
int FontWithFace::getCharacterFromPos | ( | const wchar_t * | text, |
int | pixel_x, | ||
FontSettings * | font_settings = NULL |
||
) | const |
Calculate the index of the character in the text on a specific position.
text | The text to be calculated. |
pixel_x | The specific position. |
font_settings | FontSettings to use. |
|
private |
Return a character width.
area | FontArea to get glyph metrics. |
fallback | If fallback font is used. |
scale | The scaling of the character. |
|
virtual |
Get the dimension of text with support to different FontSettings, it will also do checking for missing characters in font and lazy load them.
text | The text to be calculated. |
font_settings | FontSettings to use. |
|
inlineprivate |
Get the GlyphInfo from m_character_glyph_info_map about a character.
c | Character to get. |
|
privatepure virtual |
Defined by sub-class about the texture size of glyph page, it should be a power of two.
Implemented in BoldFace, DigitFace, and RegularFace.
|
privatepure virtual |
Defined by sub-class about the scaling factor 1.
Implemented in BoldFace, DigitFace, and RegularFace.
|
privatepure virtual |
Defined by sub-class about the scaling factor 2.
Implemented in BoldFace, DigitFace, and RegularFace.
|
virtual |
Initialize the font structure, but don't load glyph here.
Reimplemented in BoldFace, DigitFace, and RegularFace.
|
inlineprotected |
Check characters to see if they are loaded in font, if not load them.
For font that doesn't need lazy loading, nothing will be done.
in_ptr | Characters to check. |
first_load | If true, it will ignore supportLazyLoadChar, which is called in reset. |
void FontWithFace::insertGlyph | ( | unsigned | font_number, |
unsigned | glyph_index | ||
) |
Render a glyph for a character into bitmap and save it into the glyph page.
font_number | Font number in FaceTTF ttf list |
glyph_index | Glyph index in ttf |
|
inlineprivatevirtual |
Override it if sub-class has bold outline.
Reimplemented in BoldFace.
|
inlineprivate |
Test if a character has already been tried to be loaded.
c | Character to test. |
|
private |
Convert a character to a glyph index in one of the font in m_face_ttf, it will find the first TTF that supports this character, if the final glyph_index is 0, this means such character is not supported by all TTFs in m_face_ttf.
c | The character to be loaded. |
void FontWithFace::render | ( | const std::vector< gui::GlyphLayout > & | gl, |
const core::rect< s32 > & | position, | ||
const video::SColor & | color, | ||
bool | hcenter, | ||
bool | vcenter, | ||
const core::rect< s32 > * | clip, | ||
FontSettings * | font_settings, | ||
FontCharCollector * | char_collector = NULL |
||
) |
Render text and clip it to the specified rectangle if wanted, it will also do checking for missing characters in font and lazy load them.
gl | GlyphLayout rendered by libraqm to be rendering. |
position | The position to be rendering. |
color | The color used when rendering. |
hcenter | If rendered horizontally center. |
vcenter | If rendered vertically center. |
clip | If clipping is needed. |
font_settings | FontSettings to use. |
char_collector | FontCharCollector to render billboard text. |
|
virtual |
Clear all the loaded characters, sub-class can do pre-loading of characters after this.
Reimplemented in BoldFace, DigitFace, and RegularFace.
void FontWithFace::setDPI | ( | ) |
Set the face dpi which is resolution-dependent.
Normal text will range from 0.8, in 640x* resolutions (won't scale below that) to 1.0, in 1024x* resolutions, and linearly up. Bold text will range from 0.2, in 640x* resolutions (won't scale below that) to 0.4, in 1024x* resolutions, and linearly up.
|
inlineprotected |
Set the fallback font for this font, so if some character is missing in this font, it will use that fallback font to try rendering it.
face | A FontWithFace font. |
|
inlineprotected |
Set the scaling of fallback font.
scale | The scaling to set. |
|
inlineprivatevirtual |
Override it if any outline shaping is needed to be done before rendering the glyph into bitmap.
Reimplemented in BoldFace.
|
inlineprivate |
Tells whether a character is supported by all TTFs in m_face_ttf which is determined by GlyphInfo of this character.
c | Character to test. |
|
inlineprivatevirtual |
Override it if sub-class should not do lazy loading characters.
Reimplemented in DigitFace.