SuperTuxKart
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
FontWithFace Class Referenceabstract

An abstract class which contains functions which convert vector fonts into bitmap and render them in STK. More...

#include <font_with_face.hpp>

Inheritance diagram for FontWithFace:
Inheritance graph
[legend]

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. More...
 
virtual ~FontWithFace ()
 Destructor. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
void dumpGlyphPage ()
 Write the current glyph page in png inside current running directory. More...
 
gui::IGUISpriteBank * getSpriteBank () const
 Return the sprite bank. More...
 
const FontAreagetAreaFromCharacter (const wchar_t c, bool *fallback_font) const
 Return the FontArea about a character. More...
 
unsigned int getDPI () const
 Return the dpi of this face. More...
 
FaceTTFgetFaceTTF () const
 
void insertGlyph (unsigned font_number, unsigned glyph_index)
 Render a glyph for a character into bitmap and save it into the glyph page. More...
 
int getFontMaxHeight () const
 
virtual bool disableTextShaping () const
 
float getInverseShaping () const
 
virtual bool useColorGlyphPage () const
 
void setDPI ()
 Set the face dpi which is resolution-dependent. More...
 

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. More...
 
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. More...
 
void setFallbackFontScale (float scale)
 Set the scaling of fallback font. More...
 

Protected Attributes

int m_font_max_height
 Used in vertical dimension calculation. More...
 
int m_glyph_max_height
 Used in top side bearing calculation. More...
 

Private Member Functions

float getCharWidth (const FontArea &area, bool fallback, float scale) const
 Return a character width. More...
 
bool loadedChar (wchar_t c) const
 Test if a character has already been tried to be loaded. More...
 
const GlyphInfogetGlyphInfo (wchar_t c) const
 Get the GlyphInfo from m_character_glyph_info_map about a character. More...
 
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. More...
 
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. More...
 
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. More...
 
virtual bool supportLazyLoadChar () const
 Override it if sub-class should not do lazy loading characters. More...
 
virtual unsigned int getGlyphPageSize () const =0
 Defined by sub-class about the texture size of glyph page, it should be a power of two. More...
 
virtual float getScalingFactorOne () const =0
 Defined by sub-class about the scaling factor 1. More...
 
virtual unsigned int getScalingFactorTwo () const =0
 Defined by sub-class about the scaling factor 2. More...
 
virtual bool isBold () const
 Override it if sub-class has bold outline. More...
 
const FontAreagetUnknownFontArea () 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. More...
 
virtual int shapeOutline (FT_Outline *outline) const
 Override it if any outline shaping is needed to be done before rendering the glyph into bitmap. More...
 

Private Attributes

FaceTTFm_face_ttf
 FaceTTF to load glyph from. More...
 
FontWithFacem_fallback_font
 Fallback font to use if some character isn't supported by this font. More...
 
float m_fallback_font_scale
 Scaling for fallback font. More...
 
std::set< wchar_t > m_new_char_holder
 A temporary holder to store new characters to be inserted. More...
 
gui::IGUISpriteBank * m_spritebank
 Sprite bank to store each glyph. More...
 
unsigned int m_current_height
 The current max height at current drawing line in glyph page. More...
 
unsigned int m_used_width
 The used width in glyph page. More...
 
unsigned int m_used_height
 The used height in glyph page. More...
 
unsigned int m_face_dpi
 The dpi of this font. More...
 
float m_inverse_shaping
 Used to undo the scale on text shaping, only need to take care of width. More...
 
std::map< wchar_t, GlyphInfom_character_glyph_info_map
 Store a list of loaded and tested character to a GlyphInfo. More...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ FontWithFace()

FontWithFace::FontWithFace ( const std::string &  name)

Constructor.

It will initialize the m_spritebank and TTF files to use.

Parameters
nameThe name of face, used by irrlicht to distinguish spritebank.
ttfFaceTTF for this face to use.

◆ ~FontWithFace()

FontWithFace::~FontWithFace ( )
virtual

Destructor.

Clears the glyph page and sprite bank.

Member Function Documentation

◆ addLazyLoadChar()

void FontWithFace::addLazyLoadChar ( wchar_t  c)
inlineprivate

Add a character into m_new_char_holder for lazy loading later.

◆ dumpGlyphPage() [1/2]

void FontWithFace::dumpGlyphPage ( const std::string &  name)

Write the current glyph page in png inside current running directory.

Mainly for debug use.

Parameters
nameThe file name.

◆ dumpGlyphPage() [2/2]

void FontWithFace::dumpGlyphPage ( )

Write the current glyph page in png inside current running directory.

Useful in gdb without parameter.

◆ getAreaFromCharacter()

const FontArea & FontWithFace::getAreaFromCharacter ( const wchar_t  c,
bool *  fallback_font 
) const

Return the FontArea about a character.

Parameters
cThe character to get.
[out]fallback_fontWhether fallback font is used.

◆ getCharacterFromPos()

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.

Parameters
textThe text to be calculated.
pixel_xThe specific position.
font_settingsFontSettings to use.
Returns
The index of the character, -1 means no character in such position.

◆ getCharWidth()

float FontWithFace::getCharWidth ( const FontArea area,
bool  fallback,
float  scale 
) const
private

Return a character width.

Parameters
areaFontArea to get glyph metrics.
fallbackIf fallback font is used.
scaleThe scaling of the character.
Returns
The calculated width with suitable scaling.

◆ getDimension()

core::dimension2d< u32 > FontWithFace::getDimension ( const core::stringw &  text,
FontSettings font_settings = NULL 
)
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.

Parameters
textThe text to be calculated.
font_settingsFontSettings to use.
Returns
The dimension of text

◆ getDPI()

unsigned int FontWithFace::getDPI ( ) const
inline

Return the dpi of this face.

◆ getGlyphInfo()

const GlyphInfo& FontWithFace::getGlyphInfo ( wchar_t  c) const
inlineprivate

Get the GlyphInfo from m_character_glyph_info_map about a character.

Parameters
cCharacter to get.
Returns
GlyphInfo of this character.

◆ getGlyphPageSize()

virtual unsigned int FontWithFace::getGlyphPageSize ( ) const
privatepure virtual

Defined by sub-class about the texture size of glyph page, it should be a power of two.

Implemented in DigitFace, BoldFace, and RegularFace.

◆ getScalingFactorOne()

virtual float FontWithFace::getScalingFactorOne ( ) const
privatepure virtual

Defined by sub-class about the scaling factor 1.

Implemented in DigitFace, BoldFace, and RegularFace.

◆ getScalingFactorTwo()

virtual unsigned int FontWithFace::getScalingFactorTwo ( ) const
privatepure virtual

Defined by sub-class about the scaling factor 2.

Implemented in DigitFace, BoldFace, and RegularFace.

◆ getSpriteBank()

gui::IGUISpriteBank* FontWithFace::getSpriteBank ( ) const
inline

Return the sprite bank.

◆ insertCharacters()

void FontWithFace::insertCharacters ( const wchar_t *  in_ptr,
bool  first_load = false 
)
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.

Parameters
in_ptrCharacters to check.
first_loadIf true, it will ignore supportLazyLoadChar, which is called in reset.

◆ insertGlyph()

void FontWithFace::insertGlyph ( unsigned  font_number,
unsigned  glyph_index 
)

Render a glyph for a character into bitmap and save it into the glyph page.

Parameters
font_numberFont number in FaceTTF ttf list
glyph_indexGlyph index in ttf

◆ isBold()

virtual bool FontWithFace::isBold ( ) const
inlineprivatevirtual

Override it if sub-class has bold outline.

Reimplemented in BoldFace.

◆ loadedChar()

bool FontWithFace::loadedChar ( wchar_t  c) const
inlineprivate

Test if a character has already been tried to be loaded.

Parameters
cCharacter to test.
Returns
True if tested.

◆ loadGlyphInfo()

void FontWithFace::loadGlyphInfo ( wchar_t  c)
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.

Parameters
cThe character to be loaded.

◆ render()

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.

Parameters
glGlyphLayout rendered by libraqm to be rendering.
positionThe position to be rendering.
colorThe color used when rendering.
hcenterIf rendered horizontally center.
vcenterIf rendered vertically center.
clipIf clipping is needed.
font_settingsFontSettings to use.
char_collectorFontCharCollector to render billboard text.

◆ setDPI()

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.

◆ setFallbackFont()

void FontWithFace::setFallbackFont ( FontWithFace face)
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.

Parameters
faceA FontWithFace font.

◆ setFallbackFontScale()

void FontWithFace::setFallbackFontScale ( float  scale)
inlineprotected

Set the scaling of fallback font.

Parameters
scaleThe scaling to set.

◆ shapeOutline()

virtual int FontWithFace::shapeOutline ( FT_Outline *  outline) const
inlineprivatevirtual

Override it if any outline shaping is needed to be done before rendering the glyph into bitmap.

Returns
A FT_Error value if needed.

Reimplemented in BoldFace.

◆ supportChar()

bool FontWithFace::supportChar ( wchar_t  c)
inlineprivate

Tells whether a character is supported by all TTFs in m_face_ttf which is determined by GlyphInfo of this character.

Parameters
cCharacter to test.
Returns
True if it's supported.

◆ supportLazyLoadChar()

virtual bool FontWithFace::supportLazyLoadChar ( ) const
inlineprivatevirtual

Override it if sub-class should not do lazy loading characters.

Reimplemented in DigitFace.

◆ text2GlyphsWithoutShaping()

std::vector< gui::GlyphLayout > FontWithFace::text2GlyphsWithoutShaping ( const core::stringw &  t)
private

Convert text to drawable GlyphLayout without text shaping, used in digit font or debugging message.

Member Data Documentation

◆ m_character_glyph_info_map

std::map<wchar_t, GlyphInfo> FontWithFace::m_character_glyph_info_map
private

Store a list of loaded and tested character to a GlyphInfo.

◆ m_current_height

unsigned int FontWithFace::m_current_height
private

The current max height at current drawing line in glyph page.

◆ m_face_dpi

unsigned int FontWithFace::m_face_dpi
private

The dpi of this font.

◆ m_face_ttf

FaceTTF* FontWithFace::m_face_ttf
private

FaceTTF to load glyph from.

◆ m_fallback_font

FontWithFace* FontWithFace::m_fallback_font
private

Fallback font to use if some character isn't supported by this font.

◆ m_fallback_font_scale

float FontWithFace::m_fallback_font_scale
private

Scaling for fallback font.

◆ m_font_max_height

int FontWithFace::m_font_max_height
protected

Used in vertical dimension calculation.

◆ m_glyph_max_height

int FontWithFace::m_glyph_max_height
protected

Used in top side bearing calculation.

◆ m_inverse_shaping

float FontWithFace::m_inverse_shaping
private

Used to undo the scale on text shaping, only need to take care of width.

◆ m_new_char_holder

std::set<wchar_t> FontWithFace::m_new_char_holder
private

A temporary holder to store new characters to be inserted.

◆ m_spritebank

gui::IGUISpriteBank* FontWithFace::m_spritebank
private

Sprite bank to store each glyph.

◆ m_used_height

unsigned int FontWithFace::m_used_height
private

The used height in glyph page.

◆ m_used_width

unsigned int FontWithFace::m_used_width
private

The used width in glyph page.


The documentation for this class was generated from the following files: