Luanti 5.15.0-dev
 
Loading...
Searching...
No Matches
gui::CGUITTFont Class Referencefinal

Class representing a TrueType font. More...

#include <CGUITTFont.h>

+ Inheritance diagram for gui::CGUITTFont:
+ Collaboration diagram for gui::CGUITTFont:

Public Member Functions

virtual ~CGUITTFont ()
 Destructor.
 
void setBatchLoadSize (u32 batch_size)
 Sets the amount of glyphs to batch load.
 
u32 getFontSize () const
 Get the font size.
 
bool useAutoHinting () const
 Check if the font auto-hinting is enabled.
 
bool useHinting () const
 Check if the font hinting is enabled.
 
bool useMonochrome () const
 Check if the font is being loaded as a monochrome font.
 
void setMonochrome (const bool flag)
 Tells the font to use monochrome rendering.
 
void setFontHinting (const bool enable, const bool enable_auto_hinting=true)
 Enables or disables font hinting.
 
virtual void draw (const core::stringw &utext, const core::rect< s32 > &position, video::SColor color, bool hcenter=false, bool vcenter=false, const core::rect< s32 > *clip=0) override
 Draws some text and clips it to the specified rectangle if wanted.
 
void draw (const EnrichedString &text, const core::rect< s32 > &position, bool hcenter=false, bool vcenter=false, const core::rect< s32 > *clip=0)
 
virtual core::dimension2du getDimension (const wchar_t *text) const override
 Returns the dimension of a text string.
 
virtual s32 getCharacterFromPos (const wchar_t *text, s32 pixel_x) const override
 Calculates the index of the character in the text which is on a specific position.
 
virtual void setKerningWidth (s32 kerning) override
 Sets global kerning width for the font.
 
virtual void setKerningHeight (s32 kerning) override
 Sets global kerning height for the font.
 
virtual core::vector2di getKerning (const wchar_t thisLetter, const wchar_t previousLetter) const override
 Returns the distance between letters.
 
virtual void setInvisibleCharacters (const wchar_t *s) override
 Define which characters should not be drawn by the font.
 
CGUITTGlyphPagegetLastGlyphPage () const
 Get the last glyph page if there's still available slots.
 
CGUITTGlyphPagecreateGlyphPage (const u8 pixel_mode)
 Create a new glyph page texture.
 
u32 getLastGlyphPageIndex () const
 Get the last glyph page's index.
 
void setFallback (gui::IGUIFont *font)
 Set font that should be used for glyphs not present in ours.
 
s32 getAscender () const
 

Static Public Member Functions

static CGUITTFontcreateTTFont (IGUIEnvironment *env, SGUITTFace *face, u32 size, bool antialias=true, bool preload=true, u32 shadow=0, u32 shadow_alpha=255)
 Creates a new TrueType font and returns a pointer to it.
 

Protected Attributes

bool use_monochrome
 
bool use_hinting
 
bool use_auto_hinting
 
u32 size
 
u32 batch_load_size
 

Private Member Functions

core::dimension2d< u32 > getDimension (const std::u32string &text) const
 
s32 getCharacterFromPos (const std::u32string &text, s32 pixel_x) const
 
std::u32string convertWCharToU32String (const wchar_t *const) const
 
 CGUITTFont (IGUIEnvironment *env)
 Constructor.
 
bool load (SGUITTFace *face, const u32 size, const bool antialias, const bool transparency, const bool preload)
 
void reset_images ()
 
void update_glyph_pages () const
 
void update_load_flags ()
 
u32 getLineHeight () const
 Gets the overall font height, including a line gap of 1 px.
 
u32 getWidthFromCharacter (char32_t c) const
 
u32 getHeightFromCharacter (char32_t c) const
 
u32 getGlyphIndexByChar (char32_t c) const
 Returns (index + 1) of this->Glyphs Returns 0 if no such glyph is provided by the font.
 
core::vector2di getKerning (const char32_t thisLetter, const char32_t previousLetter) const
 

Private Attributes

video::IVideoDriver * Driver = nullptr
 
FT_Face tt_face
 
FT_Size_Metrics font_metrics
 
FT_Int32 load_flags
 
core::array< CGUITTGlyphPage * > Glyph_Pages
 
core::array< SGUITTGlyphGlyphs
 
s32 GlobalKerningWidth = 0
 
s32 GlobalKerningHeight = 0
 
std::u32string InvisibleChars
 
u32 shadow_offset = 0
 
u32 shadow_alpha = 0
 
irr_ptr< gui::IGUIFont > fallback
 

Detailed Description

Class representing a TrueType font.

Constructor & Destructor Documentation

◆ ~CGUITTFont()

gui::CGUITTFont::~CGUITTFont ( )
virtual

Destructor.

References Driver, Glyphs, and reset_images().

+ Here is the call graph for this function:

◆ CGUITTFont()

gui::CGUITTFont::CGUITTFont ( IGUIEnvironment * env)
private

Constructor.

References Driver, and setInvisibleCharacters().

Referenced by createTTFont().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Function Documentation

◆ convertWCharToU32String()

std::u32string gui::CGUITTFont::convertWCharToU32String ( const wchar_t * const charArray) const
private

References p().

Referenced by draw(), getCharacterFromPos(), getDimension(), and setInvisibleCharacters().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createGlyphPage()

CGUITTGlyphPage * gui::CGUITTFont::createGlyphPage ( const u8 pixel_mode)

Create a new glyph page texture.

Parameters
pixel_modethe pixel mode defined by FT_Pixel_Mode

References gui::CGUITTGlyphPage::available_slots, gui::CGUITTGlyphPage::createPageTexture(), Driver, errorstream, Glyph_Pages, size, and tt_face.

Referenced by gui::SGUITTGlyph::preload().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createTTFont()

CGUITTFont * gui::CGUITTFont::createTTFont ( IGUIEnvironment * env,
SGUITTFace * face,
u32 size,
bool antialias = true,
bool preload = true,
u32 shadow = 0,
u32 shadow_alpha = 255 )
static

Creates a new TrueType font and returns a pointer to it.

The pointer must be drop()'ed when finished.

Parameters
envThe IGUIEnvironment the font loads out of.
sizeThe size of the font glyphs in pixels. Since this is the size of the individual glyphs, the true height of the font may change depending on the characters used.
antialiasset the use_monochrome (opposite to antialias) flag
preloadcreate texture with important glyphs directly
Returns
Returns a pointer to a CGUITTFont. Will return 0 if the font failed to load.

References CGUITTFont(), load(), shadow_alpha, shadow_offset, and size.

Referenced by FontEngine::initFont().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ draw() [1/2]

void gui::CGUITTFont::draw ( const core::stringw & utext,
const core::rect< s32 > & position,
video::SColor color,
bool hcenter = false,
bool vcenter = false,
const core::rect< s32 > * clip = 0 )
overridevirtual

Draws some text and clips it to the specified rectangle if wanted.

References draw().

Referenced by draw(), gui::StaticText::draw(), Hud::drawLuaElements(), and GUIChatConsole::drawText().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ draw() [2/2]

void gui::CGUITTFont::draw ( const EnrichedString & text,
const core::rect< s32 > & position,
bool hcenter = false,
bool vcenter = false,
const core::rect< s32 > * clip = 0 )

◆ getAscender()

s32 gui::CGUITTFont::getAscender ( ) const
inline

References font_metrics.

Referenced by TextDrawer::TextDrawer().

+ Here is the caller graph for this function:

◆ getCharacterFromPos() [1/2]

s32 gui::CGUITTFont::getCharacterFromPos ( const std::u32string & text,
s32 pixel_x ) const
private

References getKerning(), getWidthFromCharacter(), and x.

+ Here is the call graph for this function:

◆ getCharacterFromPos() [2/2]

s32 gui::CGUITTFont::getCharacterFromPos ( const wchar_t * text,
s32 pixel_x ) const
overridevirtual

Calculates the index of the character in the text which is on a specific position.

References convertWCharToU32String(), and getCharacterFromPos().

Referenced by getCharacterFromPos().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDimension() [1/2]

core::dimension2d< u32 > gui::CGUITTFont::getDimension ( const std::u32string & text) const
private

References getKerning(), getLineHeight(), and getWidthFromCharacter().

+ Here is the call graph for this function:

◆ getDimension() [2/2]

core::dimension2d< u32 > gui::CGUITTFont::getDimension ( const wchar_t * text) const
overridevirtual

Returns the dimension of a text string.

References convertWCharToU32String(), and getDimension().

Referenced by draw(), and getDimension().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFontSize()

u32 gui::CGUITTFont::getFontSize ( ) const
inline

Get the font size.

References size.

Referenced by GUITable::setTable().

+ Here is the caller graph for this function:

◆ getGlyphIndexByChar()

u32 gui::CGUITTFont::getGlyphIndexByChar ( char32_t c) const
private

Returns (index + 1) of this->Glyphs Returns 0 if no such glyph is provided by the font.

References batch_load_size, gui::SGUITTGlyph::createGlyphImage(), Driver, gui::SGUITTGlyph::glyph_page, Glyph_Pages, Glyphs, gui::SGUITTGlyph::isLoaded(), load_flags, gui::SGUITTGlyph::preload(), size, and tt_face.

Referenced by draw(), getHeightFromCharacter(), getKerning(), getWidthFromCharacter(), and load().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getHeightFromCharacter()

u32 gui::CGUITTFont::getHeightFromCharacter ( char32_t c) const
inlineprivate

References fallback, font_metrics, getGlyphIndexByChar(), and Glyphs.

+ Here is the call graph for this function:

◆ getKerning() [1/2]

core::vector2di gui::CGUITTFont::getKerning ( const char32_t thisLetter,
const char32_t previousLetter ) const
private

References fallback, getGlyphIndexByChar(), GlobalKerningHeight, GlobalKerningWidth, size, and tt_face.

+ Here is the call graph for this function:

◆ getKerning() [2/2]

core::vector2di gui::CGUITTFont::getKerning ( const wchar_t thisLetter,
const wchar_t previousLetter ) const
overridevirtual

Returns the distance between letters.

References getKerning().

Referenced by draw(), getCharacterFromPos(), getDimension(), and getKerning().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLastGlyphPage()

CGUITTGlyphPage * gui::CGUITTFont::getLastGlyphPage ( ) const

Get the last glyph page if there's still available slots.

If not, it will return zero.

References gui::CGUITTGlyphPage::available_slots, getLastGlyphPageIndex(), and Glyph_Pages.

Referenced by gui::SGUITTGlyph::preload().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLastGlyphPageIndex()

u32 gui::CGUITTFont::getLastGlyphPageIndex ( ) const
inline

Get the last glyph page's index.

References Glyph_Pages.

Referenced by getLastGlyphPage(), and gui::SGUITTGlyph::preload().

+ Here is the caller graph for this function:

◆ getLineHeight()

u32 gui::CGUITTFont::getLineHeight ( ) const
inlineprivate

Gets the overall font height, including a line gap of 1 px.

References font_metrics.

Referenced by draw(), and getDimension().

+ Here is the caller graph for this function:

◆ getWidthFromCharacter()

u32 gui::CGUITTFont::getWidthFromCharacter ( char32_t c) const
inlineprivate

References fallback, font_metrics, getGlyphIndexByChar(), and Glyphs.

Referenced by draw(), getCharacterFromPos(), and getDimension().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ load()

bool gui::CGUITTFont::load ( SGUITTFace * face,
const u32 size,
const bool antialias,
const bool transparency,
const bool preload )
private

References batch_load_size, Driver, gui::SGUITTFace::face, font_metrics, getGlyphIndexByChar(), Glyphs, size, tt_face, update_load_flags(), use_monochrome, and verbosestream.

Referenced by createTTFont().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reset_images()

void gui::CGUITTFont::reset_images ( )
private

References Glyph_Pages, Glyphs, and update_load_flags().

Referenced by ~CGUITTFont(), setFontHinting(), and setMonochrome().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setBatchLoadSize()

void gui::CGUITTFont::setBatchLoadSize ( u32 batch_size)
inline

Sets the amount of glyphs to batch load.

References batch_load_size.

◆ setFallback()

void gui::CGUITTFont::setFallback ( gui::IGUIFont * font)

Set font that should be used for glyphs not present in ours.

References fallback, and sanity_check.

◆ setFontHinting()

void gui::CGUITTFont::setFontHinting ( const bool enable,
const bool enable_auto_hinting = true )

Enables or disables font hinting.

Default: Hinting and auto-hinting true.

Parameters
enableIf false, font hinting is turned off. If true, font hinting is turned on.
enable_auto_hintingIf true, FreeType uses its own auto-hinting algorithm. If false, it tries to use the algorithm specified by the font.

References reset_images(), use_auto_hinting, and use_hinting.

+ Here is the call graph for this function:

◆ setInvisibleCharacters()

void gui::CGUITTFont::setInvisibleCharacters ( const wchar_t * s)
overridevirtual

Define which characters should not be drawn by the font.

References convertWCharToU32String(), and InvisibleChars.

Referenced by CGUITTFont().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setKerningHeight()

void gui::CGUITTFont::setKerningHeight ( s32 kerning)
overridevirtual

Sets global kerning height for the font.

References GlobalKerningHeight.

◆ setKerningWidth()

void gui::CGUITTFont::setKerningWidth ( s32 kerning)
overridevirtual

Sets global kerning width for the font.

References GlobalKerningWidth.

◆ setMonochrome()

void gui::CGUITTFont::setMonochrome ( const bool flag)

Tells the font to use monochrome rendering.

Default: false.

Parameters
flagIf true, the font draws using a monochrome image. If false, the font uses a grayscale image.

References reset_images(), and use_monochrome.

+ Here is the call graph for this function:

◆ update_glyph_pages()

void gui::CGUITTFont::update_glyph_pages ( ) const
private

References Glyph_Pages.

Referenced by draw().

+ Here is the caller graph for this function:

◆ update_load_flags()

void gui::CGUITTFont::update_load_flags ( )
inlineprivate

References load_flags, useAutoHinting(), useHinting(), and useMonochrome().

Referenced by load(), and reset_images().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ useAutoHinting()

bool gui::CGUITTFont::useAutoHinting ( ) const
inline

Check if the font auto-hinting is enabled.

Auto-hinting is FreeType's built-in font hinting engine.

References use_auto_hinting.

Referenced by update_load_flags().

+ Here is the caller graph for this function:

◆ useHinting()

bool gui::CGUITTFont::useHinting ( ) const
inline

Check if the font hinting is enabled.

References use_hinting.

Referenced by update_load_flags().

+ Here is the caller graph for this function:

◆ useMonochrome()

bool gui::CGUITTFont::useMonochrome ( ) const
inline

Check if the font is being loaded as a monochrome font.

The font can either be a 256 color grayscale font, or a 2 color monochrome font.

References use_monochrome.

Referenced by update_load_flags().

+ Here is the caller graph for this function:

Member Data Documentation

◆ batch_load_size

u32 gui::CGUITTFont::batch_load_size
protected

◆ Driver

video::IVideoDriver* gui::CGUITTFont::Driver = nullptr
private

◆ fallback

irr_ptr<gui::IGUIFont> gui::CGUITTFont::fallback
private

◆ font_metrics

FT_Size_Metrics gui::CGUITTFont::font_metrics
private

◆ GlobalKerningHeight

s32 gui::CGUITTFont::GlobalKerningHeight = 0
private

Referenced by getKerning(), and setKerningHeight().

◆ GlobalKerningWidth

s32 gui::CGUITTFont::GlobalKerningWidth = 0
private

Referenced by getKerning(), and setKerningWidth().

◆ Glyph_Pages

core::array<CGUITTGlyphPage*> gui::CGUITTFont::Glyph_Pages
mutableprivate

◆ Glyphs

core::array<SGUITTGlyph> gui::CGUITTFont::Glyphs
mutableprivate

◆ InvisibleChars

std::u32string gui::CGUITTFont::InvisibleChars
private

Referenced by draw(), and setInvisibleCharacters().

◆ load_flags

FT_Int32 gui::CGUITTFont::load_flags
private

◆ shadow_alpha

u32 gui::CGUITTFont::shadow_alpha = 0
private

Referenced by createTTFont(), and draw().

◆ shadow_offset

u32 gui::CGUITTFont::shadow_offset = 0
private

Referenced by createTTFont(), and draw().

◆ size

u32 gui::CGUITTFont::size
protected

◆ tt_face

FT_Face gui::CGUITTFont::tt_face
private

◆ use_auto_hinting

bool gui::CGUITTFont::use_auto_hinting
protected

Referenced by setFontHinting(), and useAutoHinting().

◆ use_hinting

bool gui::CGUITTFont::use_hinting
protected

Referenced by setFontHinting(), and useHinting().

◆ use_monochrome

bool gui::CGUITTFont::use_monochrome
protected

Referenced by load(), setMonochrome(), and useMonochrome().


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