SuperTuxKart
Loading...
Searching...
No Matches
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.
 
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 FontAreagetAreaFromCharacter (const wchar_t c, bool *fallback_font) const
 Return the FontArea about a character.
 
unsigned int getDPI () const
 Return the dpi of this face.
 
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.
 
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 GlyphInfogetGlyphInfo (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 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.
 
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

FaceTTFm_face_ttf
 FaceTTF to load glyph from.
 
FontWithFacem_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, GlyphInfom_character_glyph_info_map
 Store a list of loaded and tested character to a GlyphInfo.
 

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

◆ dumpGlyphPage() [1/2]

void FontWithFace::dumpGlyphPage ( )

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

Useful in gdb without parameter.

◆ dumpGlyphPage() [2/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.

◆ 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

◆ 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 BoldFace, DigitFace, and RegularFace.

◆ getScalingFactorOne()

virtual float FontWithFace::getScalingFactorOne ( ) const
privatepure virtual

Defined by sub-class about the scaling factor 1.

Implemented in BoldFace, DigitFace, and RegularFace.

◆ getScalingFactorTwo()

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

Defined by sub-class about the scaling factor 2.

Implemented in BoldFace, DigitFace, and RegularFace.

◆ init()

void FontWithFace::init ( )
virtual

Initialize the font structure, but don't load glyph here.

Reimplemented in BoldFace, DigitFace, and RegularFace.

◆ 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.

◆ reset()

void FontWithFace::reset ( )
virtual

Clear all the loaded characters, sub-class can do pre-loading of characters after this.

Reimplemented in BoldFace, DigitFace, and RegularFace.

◆ 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.


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