libSDL2pp
C++ bindings/wrapper for SDL2
Loading...
Searching...
No Matches
List of all members
SDL2pp::Font Class Reference

Holder of a loaded font. More...

#include <SDL2pp/Font.hh>

Public Member Functions

Construction and destruction
 Font (TTF_Font *font)
 Construct from existing TTF_Font structure.
 
 Font (const std::string &file, int ptsize, long index=0)
 Loads font from .ttf or .fon file.
 
 Font (RWops &rwops, int ptsize, long index=0)
 Loads font with RWops.
 
virtual ~Font ()
 Destructor.
 
Copy and move
 Font (Font &&other) noexcept
 Move constructor.
 
Fontoperator= (Font &&other) noexcept
 Move assignment.
 
 Font (const Font &)=delete
 Deleted copy constructor.
 
Fontoperator= (const Font &)=delete
 Deleted assignment operator.
 
Compatibility with legacy SDL code
TTF_Font * Get () const
 Get pointer to managed TTF_Font structure.
 
Attributes: font style
int GetStyle () const
 Get the rendering style of the loaded font.
 
FontSetStyle (int style=TTF_STYLE_NORMAL)
 Set the rendering style of the loaded font.
 
int GetOutline () const
 Get the current outline size of the loaded font.
 
FontSetOutline (int outline=0)
 Set the outline pixel width of the loaded font.
 
Attributes: font settings
int GetHinting () const
 Get the current hinting setting of the loaded font.
 
FontSetHinting (int hinting=TTF_HINTING_NORMAL)
 Set the hinting of the loaded font.
 
bool GetKerning () const
 Get the current kerning setting of the loaded font.
 
FontSetKerning (bool allowed=true)
 Set whether to use kerning when rendering the loaded font.
 
Attributes: font metrics
int GetHeight () const
 Get the maximum pixel height of all glyphs of the loaded font.
 
int GetAscent () const
 Get the maximum pixel ascent of all glyphs of the loaded font.
 
int GetDescent () const
 Get the maximum pixel descent of all glyphs of the loaded font.
 
int GetLineSkip () const
 Get the recommended pixel height of a rendered line of text of the loaded font.
 
Attributes: face attributes
long GetNumFaces () const
 Get the number of faces ("sub-fonts") available in the loaded font.
 
bool IsFixedWidth () const
 Test if the current font face of the loaded font is a fixed width font.
 
Optional< std::string > GetFamilyName () const
 Get the current font face family name from the loaded font.
 
Optional< std::string > GetStyleName () const
 Get the current font face style name from the loaded font.
 
Attributes: glyphs
int IsGlyphProvided (Uint16 ch) const
 Get the status of the availability of the glyph from the loaded font.
 
void GetGlyphMetrics (Uint16 ch, int &minx, int &maxx, int &miny, int &maxy, int &advance) const
 Get glyph metrics of the UNICODE char.
 
Rect GetGlyphRect (Uint16 ch) const
 Get rect part of glyph metrics of the UNICODE char.
 
int GetGlyphAdvance (Uint16 ch) const
 Get advance part of glyph metrics of the UNICODE char.
 
Attributes: text metrics
Point GetSizeText (const std::string &text) const
 Calculate the resulting surface size of the LATIN1 encoded text rendered using font.
 
Point GetSizeUTF8 (const std::string &text) const
 Calculate the resulting surface size of the UTF8 encoded text rendered using font.
 
Point GetSizeUNICODE (const Uint16 *text) const
 Calculate the resulting surface size of the UNICODE encoded text rendered using font.
 
Point GetSizeUNICODE (const std::u16string &text) const
 Calculate the resulting surface size of the UNICODE encoded text rendered using font.
 
Rendering: solid
Surface RenderText_Solid (const std::string &text, SDL_Color fg)
 Render LATIN1 text using solid mode.
 
Surface RenderUTF8_Solid (const std::string &text, SDL_Color fg)
 Render UTF8 text using solid mode.
 
Surface RenderUNICODE_Solid (const Uint16 *text, SDL_Color fg)
 Render UNICODE encoded text using solid mode.
 
Surface RenderUNICODE_Solid (const std::u16string &text, SDL_Color fg)
 Render UNICODE encoded text using solid mode.
 
Surface RenderGlyph_Solid (Uint16 ch, SDL_Color fg)
 Render the glyph for UNICODE character using solid mode.
 
Rendering: shaded
Surface RenderText_Shaded (const std::string &text, SDL_Color fg, SDL_Color bg)
 Render LATIN1 text using shaded mode.
 
Surface RenderUTF8_Shaded (const std::string &text, SDL_Color fg, SDL_Color bg)
 Render UTF8 text using shaded mode.
 
Surface RenderUNICODE_Shaded (const Uint16 *text, SDL_Color fg, SDL_Color bg)
 Render UNICODE encoded text using shaded mode.
 
Surface RenderUNICODE_Shaded (const std::u16string &text, SDL_Color fg, SDL_Color bg)
 Render UNICODE encoded text using shaded mode.
 
Surface RenderGlyph_Shaded (Uint16 ch, SDL_Color fg, SDL_Color bg)
 Render the glyph for UNICODE character using shaded mode.
 
Rendering: blended
Surface RenderText_Blended (const std::string &text, SDL_Color fg)
 Render LATIN1 text using blended mode.
 
Surface RenderUTF8_Blended (const std::string &text, SDL_Color fg)
 Render UTF8 text using blended mode.
 
Surface RenderUNICODE_Blended (const Uint16 *text, SDL_Color fg)
 Render UNICODE encoded text using blended mode.
 
Surface RenderUNICODE_Blended (const std::u16string &text, SDL_Color fg)
 Render UNICODE encoded text using blended mode.
 
Surface RenderGlyph_Blended (Uint16 ch, SDL_Color fg)
 Render the glyph for UNICODE character using blended mode.
 

Detailed Description

Holder of a loaded font.

See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC56

Constructor & Destructor Documentation

◆ Font() [1/5]

SDL2pp::Font::Font ( TTF_Font *  font)
explicit

Construct from existing TTF_Font structure.

Parameters
[in]fontExisting TTF_Font to manage

◆ Font() [2/5]

SDL2pp::Font::Font ( const std::string &  file,
int  ptsize,
long  index = 0 
)

Loads font from .ttf or .fon file.

Parameters
[in]filePointer File name to load font from
[in]ptsizePoint size (based on 72DPI) to load font as. This basically translates to pixel height
[in]indexChoose a font face from a file containing multiple font faces. The first face is always index 0
Exceptions
SDL2pp::Exception
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC14
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC16

◆ Font() [3/5]

SDL2pp::Font::Font ( RWops rwops,
int  ptsize,
long  index = 0 
)

Loads font with RWops.

Parameters
[in]rwopsRWops to load font from
[in]ptsizePoint size (based on 72DPI) to load font as. This basically translates to pixel height
[in]indexChoose a font face from a file containing multiple font faces. The first face is always index 0
Exceptions
SDL2pp::Exception
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC15
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC17

◆ ~Font()

SDL2pp::Font::~Font ( )
virtual

◆ Font() [4/5]

SDL2pp::Font::Font ( Font &&  other)
noexcept

Move constructor.

Parameters
[in]otherSDL2pp::Font object to move data from

◆ Font() [5/5]

SDL2pp::Font::Font ( const Font )
delete

Deleted copy constructor.

This class is not copyable

Member Function Documentation

◆ Get()

TTF_Font * SDL2pp::Font::Get ( ) const

Get pointer to managed TTF_Font structure.

Returns
Pointer to managed TTF_Font structure

◆ GetAscent()

int SDL2pp::Font::GetAscent ( ) const

Get the maximum pixel ascent of all glyphs of the loaded font.

Returns
The maximum pixel ascent of all glyphs in the font

This can also be interpreted as the distance from the top of the font to the baseline. It could be used when drawing an individual glyph relative to a top point, by combining it with the glyph's maxy metric to resolve the top of the rectangle used when blitting the glyph on the screen.

rect.y = top + Font.GetAscent() - glyph_metric.maxy;
Holder of a loaded font.
Definition: Font.hh:48
int GetAscent() const
Get the maximum pixel ascent of all glyphs of the loaded font.
Definition: Font.cc:110
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC30

◆ GetDescent()

int SDL2pp::Font::GetDescent ( ) const

Get the maximum pixel descent of all glyphs of the loaded font.

Returns
The maximum pixel height of all glyphs in the font

This can also be interpreted as the distance from the baseline to the bottom of the font. It could be used when drawing an individual glyph relative to a bottom point, by combining it with the glyph's maxy metric to resolve the top of the rectangle used when blitting the glyph on the screen.

rect.y = bottom - TTF_FontDescent(font) - glyph_metric.maxy;
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC31

◆ GetFamilyName()

Optional< std::string > SDL2pp::Font::GetFamilyName ( ) const

Get the current font face family name from the loaded font.

Returns
The current family name of of the face of the font, or NullOpt perhaps

This function may return NullOpt, in which case the information is not available.

See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC35

◆ GetGlyphAdvance()

int SDL2pp::Font::GetGlyphAdvance ( Uint16  ch) const

Get advance part of glyph metrics of the UNICODE char.

Parameters
[in]chUNICODE char to get the glyph metrics for
Returns
Advance offset into
Exceptions
SDL2pp::Exception
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC38
http://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html

◆ GetGlyphMetrics()

void SDL2pp::Font::GetGlyphMetrics ( Uint16  ch,
int &  minx,
int &  maxx,
int &  miny,
int &  maxy,
int &  advance 
) const

Get glyph metrics of the UNICODE char.

Parameters
[in]chUNICODE char to get the glyph metrics for
[out]minxVariable to store the returned minimum X offset into
[out]maxxVariable to store the returned maximum X offset into
[out]minyVariable to store the returned minimum Y offset into
[out]maxyVariable to store the returned maximum Y offset into
[out]advanceVariable to store the returned advance offset into
Exceptions
SDL2pp::Exception
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC38
http://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html

◆ GetGlyphRect()

Rect SDL2pp::Font::GetGlyphRect ( Uint16  ch) const

Get rect part of glyph metrics of the UNICODE char.

Parameters
[in]chUNICODE char to get the glyph metrics for
Returns
Rect representing glyph offset info
Exceptions
SDL2pp::Exception
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC38
http://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html

◆ GetHeight()

int SDL2pp::Font::GetHeight ( ) const

Get the maximum pixel height of all glyphs of the loaded font.

Returns
The maximum pixel height of all glyphs in the font

You may use this height for rendering text as close together vertically as possible, though adding at least one pixel height to it will space it so they can't touch. Remember that SDL_ttf doesn't handle multiline printing, so you are responsible for line spacing, see the GetLineSkip() as well.

See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC29

◆ GetHinting()

int SDL2pp::Font::GetHinting ( ) const

Get the current hinting setting of the loaded font.

Returns
The hinting type matching one of the following defined values: TTF_HINTING_NORMAL, TTF_HINTING_LIGHT, TTF_HINTING_MONO, TTF_HINTING_NONE. If no hinting is set then TTF_HINTING_NORMAL is returned
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC25

◆ GetKerning()

bool SDL2pp::Font::GetKerning ( ) const

Get the current kerning setting of the loaded font.

Returns
False if kerning is disabled. True when enabled. The default for a newly loaded font is true, enabled
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC27

◆ GetLineSkip()

int SDL2pp::Font::GetLineSkip ( ) const

Get the recommended pixel height of a rendered line of text of the loaded font.

Returns
The maximum pixel height of all glyphs in the font

This is usually larger than the GetHeight() of the font

See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC32

◆ GetNumFaces()

long SDL2pp::Font::GetNumFaces ( ) const

Get the number of faces ("sub-fonts") available in the loaded font.

Returns
The number of faces in the font

This is a count of the number of specific fonts (based on size and style and other typographical features perhaps) contained in the font itself. It seems to be a useless fact to know, since it can't be applied in any other SDL_ttf functions.

See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC33

◆ GetOutline()

int SDL2pp::Font::GetOutline ( ) const

Get the current outline size of the loaded font.

Returns
The size of the outline currently set on the font, in pixels
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC23

◆ GetSizeText()

Point SDL2pp::Font::GetSizeText ( const std::string &  text) const

Calculate the resulting surface size of the LATIN1 encoded text rendered using font.

Parameters
[in]textString to size up
Returns
Point representing dimensions of the rendered text
Exceptions
SDL2pp::Exception

No actual rendering is done, however correct kerning is done to get the actual width. The height returned in h is the same as you can get using GetHeight()

See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC39

◆ GetSizeUNICODE() [1/2]

Point SDL2pp::Font::GetSizeUNICODE ( const std::u16string &  text) const

Calculate the resulting surface size of the UNICODE encoded text rendered using font.

Parameters
[in]textUNICODE null terminated string to size up
Returns
Point representing dimensions of the rendered text
Exceptions
SDL2pp::Exception

No actual rendering is done, however correct kerning is done to get the actual width. The height returned in h is the same as you can get using GetHeight()

See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC41

◆ GetSizeUNICODE() [2/2]

Point SDL2pp::Font::GetSizeUNICODE ( const Uint16 *  text) const

Calculate the resulting surface size of the UNICODE encoded text rendered using font.

Parameters
[in]textUNICODE null terminated string to size up
Returns
Point representing dimensions of the rendered text
Exceptions
SDL2pp::Exception

No actual rendering is done, however correct kerning is done to get the actual width. The height returned in h is the same as you can get using GetHeight()

See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC41

◆ GetSizeUTF8()

Point SDL2pp::Font::GetSizeUTF8 ( const std::string &  text) const

Calculate the resulting surface size of the UTF8 encoded text rendered using font.

Parameters
[in]textUTF8 encoded string to size up
Returns
Point representing dimensions of the rendered text
Exceptions
SDL2pp::Exception

No actual rendering is done, however correct kerning is done to get the actual width. The height returned in h is the same as you can get using GetHeight()

See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC40

◆ GetStyle()

int SDL2pp::Font::GetStyle ( ) const

Get the rendering style of the loaded font.

Returns
The style as a bitmask composed of the following masks: TTF_STYLE_BOLD, TTF_STYLE_ITALIC, TTF_STYLE_UNDERLINE, TTF_STYLE_STRIKETHROUGH. If no style is set then TTF_STYLE_NORMAL is returned
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC21

◆ GetStyleName()

Optional< std::string > SDL2pp::Font::GetStyleName ( ) const

Get the current font face style name from the loaded font.

Returns
The current style name of of the face of the font, or NullOpt perhaps

This function may return NullOpt, in which case the information is not available

See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC36

◆ IsFixedWidth()

bool SDL2pp::Font::IsFixedWidth ( ) const

Test if the current font face of the loaded font is a fixed width font.

Returns
True if font is a fixed width font. False if not a fixed width font

Fixed width fonts are monospace, meaning every character that exists in the font is the same width, thus you can assume that a rendered string's width is going to be the result of a simple calculation:

glyph_width * string_length
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC34

◆ IsGlyphProvided()

int SDL2pp::Font::IsGlyphProvided ( Uint16  ch) const

Get the status of the availability of the glyph from the loaded font.

Parameters
[in]chUnicode character to test glyph availability of
Returns
The index of the glyph for ch in font, or 0 for an undefined character code
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC37

◆ operator=() [1/2]

Font & SDL2pp::Font::operator= ( const Font )
delete

Deleted assignment operator.

This class is not copyable

◆ operator=() [2/2]

Font & SDL2pp::Font::operator= ( Font &&  other)
noexcept

Move assignment.

Parameters
[in]otherSDL2pp::Font object to move data from
Returns
Reference to self

◆ RenderGlyph_Blended()

Surface SDL2pp::Font::RenderGlyph_Blended ( Uint16  ch,
SDL_Color  fg 
)

Render the glyph for UNICODE character using blended mode.

Parameters
[in]chUNICODE character to render
[in]fgColor to render the glyph in
Returns
Surface containing rendered text
Exceptions
SDL2pp::Exception
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC54

◆ RenderGlyph_Shaded()

Surface SDL2pp::Font::RenderGlyph_Shaded ( Uint16  ch,
SDL_Color  fg,
SDL_Color  bg 
)

Render the glyph for UNICODE character using shaded mode.

Parameters
[in]chUNICODE character to render
[in]fgColor to render the glyph in
[in]bgColor to render the background box in
Returns
Surface containing rendered text
Exceptions
SDL2pp::Exception
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC50

◆ RenderGlyph_Solid()

Surface SDL2pp::Font::RenderGlyph_Solid ( Uint16  ch,
SDL_Color  fg 
)

Render the glyph for UNICODE character using solid mode.

Parameters
[in]chUNICODE character to render
[in]fgColor to render the glyph in
Returns
Surface containing rendered text
Exceptions
SDL2pp::Exception
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC46

◆ RenderText_Blended()

Surface SDL2pp::Font::RenderText_Blended ( const std::string &  text,
SDL_Color  fg 
)

Render LATIN1 text using blended mode.

Parameters
[in]textLATIN1 string to render
[in]fgColor to render the text in
Returns
Surface containing rendered text
Exceptions
SDL2pp::Exception
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC51

◆ RenderText_Shaded()

Surface SDL2pp::Font::RenderText_Shaded ( const std::string &  text,
SDL_Color  fg,
SDL_Color  bg 
)

Render LATIN1 text using shaded mode.

Parameters
[in]textLATIN1 string to render
[in]fgColor to render the text in
[in]bgColor to render the background box in
Returns
Surface containing rendered text
Exceptions
SDL2pp::Exception
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC47

◆ RenderText_Solid()

Surface SDL2pp::Font::RenderText_Solid ( const std::string &  text,
SDL_Color  fg 
)

Render LATIN1 text using solid mode.

Parameters
[in]textLATIN1 string to render
[in]fgColor to render the text in
Returns
Surface containing rendered text
Exceptions
SDL2pp::Exception
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC43

◆ RenderUNICODE_Blended() [1/2]

Surface SDL2pp::Font::RenderUNICODE_Blended ( const std::u16string &  text,
SDL_Color  fg 
)

Render UNICODE encoded text using blended mode.

Parameters
[in]textUNICODE encoded string to render
[in]fgColor to render the text in
Returns
Surface containing rendered text
Exceptions
SDL2pp::Exception
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC53

◆ RenderUNICODE_Blended() [2/2]

Surface SDL2pp::Font::RenderUNICODE_Blended ( const Uint16 *  text,
SDL_Color  fg 
)

Render UNICODE encoded text using blended mode.

Parameters
[in]textUNICODE encoded string to render
[in]fgColor to render the text in
Returns
Surface containing rendered text
Exceptions
SDL2pp::Exception
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC53

◆ RenderUNICODE_Shaded() [1/2]

Surface SDL2pp::Font::RenderUNICODE_Shaded ( const std::u16string &  text,
SDL_Color  fg,
SDL_Color  bg 
)

Render UNICODE encoded text using shaded mode.

Parameters
[in]textUNICODE encoded string to render
[in]fgColor to render the text in
[in]bgColor to render the background box in
Returns
Surface containing rendered text
Exceptions
SDL2pp::Exception
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC49

◆ RenderUNICODE_Shaded() [2/2]

Surface SDL2pp::Font::RenderUNICODE_Shaded ( const Uint16 *  text,
SDL_Color  fg,
SDL_Color  bg 
)

Render UNICODE encoded text using shaded mode.

Parameters
[in]textUNICODE encoded string to render
[in]fgColor to render the text in
[in]bgColor to render the background box in
Returns
Surface containing rendered text
Exceptions
SDL2pp::Exception
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC49

◆ RenderUNICODE_Solid() [1/2]

Surface SDL2pp::Font::RenderUNICODE_Solid ( const std::u16string &  text,
SDL_Color  fg 
)

Render UNICODE encoded text using solid mode.

Parameters
[in]textUNICODE encoded string to render
[in]fgColor to render the text in
Returns
Surface containing rendered text
Exceptions
SDL2pp::Exception
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC45

◆ RenderUNICODE_Solid() [2/2]

Surface SDL2pp::Font::RenderUNICODE_Solid ( const Uint16 *  text,
SDL_Color  fg 
)

Render UNICODE encoded text using solid mode.

Parameters
[in]textUNICODE encoded string to render
[in]fgColor to render the text in
Returns
Surface containing rendered text
Exceptions
SDL2pp::Exception
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC45

◆ RenderUTF8_Blended()

Surface SDL2pp::Font::RenderUTF8_Blended ( const std::string &  text,
SDL_Color  fg 
)

Render UTF8 text using blended mode.

Parameters
[in]textUTF8 string to render
[in]fgColor to render the text in
Returns
Surface containing rendered text
Exceptions
SDL2pp::Exception
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC52

◆ RenderUTF8_Shaded()

Surface SDL2pp::Font::RenderUTF8_Shaded ( const std::string &  text,
SDL_Color  fg,
SDL_Color  bg 
)

Render UTF8 text using shaded mode.

Parameters
[in]textUTF8 string to render
[in]fgColor to render the text in
[in]bgColor to render the background box in
Returns
Surface containing rendered text
Exceptions
SDL2pp::Exception
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC48

◆ RenderUTF8_Solid()

Surface SDL2pp::Font::RenderUTF8_Solid ( const std::string &  text,
SDL_Color  fg 
)

Render UTF8 text using solid mode.

Parameters
[in]textUTF8 string to render
[in]fgColor to render the text in
Returns
Surface containing rendered text
Exceptions
SDL2pp::Exception
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC44

◆ SetHinting()

Font & SDL2pp::Font::SetHinting ( int  hinting = TTF_HINTING_NORMAL)

Set the hinting of the loaded font.

Parameters
[in]hintingThe hinting setting desired, which is one of: TTF_HINTING_NORMAL, TTF_HINTING_LIGHT, TTF_HINTING_MONO, TTF_HINTING_NONE. The default is TTF_HINTING_NORMAL

You should experiment with this setting if you know which font you are using beforehand, especially when using smaller sized fonts. If the user is selecting a font, you may wish to let them select the hinting mode for that font as well

Note
This will flush the internal cache of previously rendered glyphs, even if there is no change in hinting, so it may be best to check the current hinting by using GetHinting() first
Returns
Reference to self
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC26

◆ SetKerning()

Font & SDL2pp::Font::SetKerning ( bool  allowed = true)

Set whether to use kerning when rendering the loaded font.

Parameters
[in]allowedFalse to disable kerning, true to enable kerning. The default is true, enabled

Set whether to use kerning when rendering the loaded font. This has no effect on individual glyphs, but rather when rendering whole strings of characters, at least a word at a time. Perhaps the only time to disable this is when kerning is not working for a specific font, resulting in overlapping glyphs or abnormal spacing within words.

Returns
Reference to self
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC28

◆ SetOutline()

Font & SDL2pp::Font::SetOutline ( int  outline = 0)

Set the outline pixel width of the loaded font.

Parameters
[in]outlineThe size of outline desired, in pixels. Use 0 (zero) to turn off outlining.
Note
This will flush the internal cache of previously rendered glyphs, even if there is no change in outline size, so it may be best to check the current outline size by using GetOutline() first
Returns
Reference to self
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC24

◆ SetStyle()

Font & SDL2pp::Font::SetStyle ( int  style = TTF_STYLE_NORMAL)

Set the rendering style of the loaded font.

Parameters
[in]styleThe style as a bitmask composed of the following masks: TTF_STYLE_BOLD, TTF_STYLE_ITALIC, TTF_STYLE_UNDERLINE, TTF_STYLE_STRIKETHROUGH. If no style is desired then use TTF_STYLE_NORMAL, which is the default.
Note
This will flush the internal cache of previously rendered glyphs, even if there is no change in style, so it may be best to check the current style by using GetStyle() first
TTF_STYLE_UNDERLINE may cause surfaces created by TTF_RenderGlyph_* functions to be extended vertically, downward only, to encompass the underline if the original glyph metrics didn't allow for the underline to be drawn below. This does not change the math used to place a glyph using glyph metrics. On the other hand TTF_STYLE_STRIKETHROUGH doesn't extend the glyph, since this would invalidate the metrics used to position the glyph when blitting, because they would likely be extended vertically upward. There is perhaps a workaround, but it would require programs to be smarter about glyph blitting math than they are currently designed for. Still, sometimes the underline or strikethrough may be outside of the generated surface, and thus not visible when blitted to the screen. In this case, you should probably turn off these styles and draw your own strikethroughs and underlines.
Returns
Reference to self
See also
https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC22

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