libSDL2pp
C++ bindings/wrapper for SDL2
|
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. | |
Font & | operator= (Font &&other) noexcept |
Move assignment. | |
Font (const Font &)=delete | |
Deleted copy constructor. | |
Font & | operator= (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. | |
Font & | SetStyle (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. | |
Font & | SetOutline (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. | |
Font & | SetHinting (int hinting=TTF_HINTING_NORMAL) |
Set the hinting of the loaded font. | |
bool | GetKerning () const |
Get the current kerning setting of the loaded font. | |
Font & | SetKerning (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. | |
Holder of a loaded font.
|
explicit |
Construct from existing TTF_Font structure.
[in] | font | Existing TTF_Font to manage |
SDL2pp::Font::Font | ( | const std::string & | file, |
int | ptsize, | ||
long | index = 0 |
||
) |
Loads font from .ttf or .fon file.
[in] | file | Pointer File name to load font from |
[in] | ptsize | Point size (based on 72DPI) to load font as. This basically translates to pixel height |
[in] | index | Choose a font face from a file containing multiple font faces. The first face is always index 0 |
SDL2pp::Exception |
SDL2pp::Font::Font | ( | RWops & | rwops, |
int | ptsize, | ||
long | index = 0 |
||
) |
Loads font with RWops.
[in] | rwops | RWops to load font from |
[in] | ptsize | Point size (based on 72DPI) to load font as. This basically translates to pixel height |
[in] | index | Choose a font face from a file containing multiple font faces. The first face is always index 0 |
SDL2pp::Exception |
|
virtual |
Destructor.
|
noexcept |
Move constructor.
[in] | other | SDL2pp::Font object to move data from |
|
delete |
Deleted copy constructor.
This class is not copyable
TTF_Font * SDL2pp::Font::Get | ( | ) | const |
Get pointer to managed TTF_Font structure.
int SDL2pp::Font::GetAscent | ( | ) | const |
Get the maximum pixel ascent of all glyphs of the loaded 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.
int SDL2pp::Font::GetDescent | ( | ) | const |
Get the maximum pixel descent of all glyphs of the loaded 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.
Optional< std::string > SDL2pp::Font::GetFamilyName | ( | ) | const |
Get the current font face family name from the loaded font.
This function may return NullOpt, in which case the information is not available.
int SDL2pp::Font::GetGlyphAdvance | ( | Uint16 | ch | ) | const |
Get advance part of glyph metrics of the UNICODE char.
[in] | ch | UNICODE char to get the glyph metrics for |
SDL2pp::Exception |
void SDL2pp::Font::GetGlyphMetrics | ( | Uint16 | ch, |
int & | minx, | ||
int & | maxx, | ||
int & | miny, | ||
int & | maxy, | ||
int & | advance | ||
) | const |
Get glyph metrics of the UNICODE char.
[in] | ch | UNICODE char to get the glyph metrics for |
[out] | minx | Variable to store the returned minimum X offset into |
[out] | maxx | Variable to store the returned maximum X offset into |
[out] | miny | Variable to store the returned minimum Y offset into |
[out] | maxy | Variable to store the returned maximum Y offset into |
[out] | advance | Variable to store the returned advance offset into |
SDL2pp::Exception |
Rect SDL2pp::Font::GetGlyphRect | ( | Uint16 | ch | ) | const |
Get rect part of glyph metrics of the UNICODE char.
[in] | ch | UNICODE char to get the glyph metrics for |
SDL2pp::Exception |
int SDL2pp::Font::GetHeight | ( | ) | const |
Get the maximum pixel height of all glyphs of the loaded 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.
int SDL2pp::Font::GetHinting | ( | ) | const |
Get the current hinting setting of the loaded font.
bool SDL2pp::Font::GetKerning | ( | ) | const |
Get the current kerning setting of the loaded font.
int SDL2pp::Font::GetLineSkip | ( | ) | const |
Get the recommended pixel height of a rendered line of text of the loaded font.
This is usually larger than the GetHeight() of the font
long SDL2pp::Font::GetNumFaces | ( | ) | const |
Get the number of faces ("sub-fonts") available in the loaded 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.
int SDL2pp::Font::GetOutline | ( | ) | const |
Get the current outline size of the loaded font.
Point SDL2pp::Font::GetSizeText | ( | const std::string & | text | ) | const |
Calculate the resulting surface size of the LATIN1 encoded text rendered using font.
[in] | text | String to size up |
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()
Point SDL2pp::Font::GetSizeUNICODE | ( | const std::u16string & | text | ) | const |
Calculate the resulting surface size of the UNICODE encoded text rendered using font.
[in] | text | UNICODE null terminated string to size up |
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()
Point SDL2pp::Font::GetSizeUNICODE | ( | const Uint16 * | text | ) | const |
Calculate the resulting surface size of the UNICODE encoded text rendered using font.
[in] | text | UNICODE null terminated string to size up |
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()
Point SDL2pp::Font::GetSizeUTF8 | ( | const std::string & | text | ) | const |
Calculate the resulting surface size of the UTF8 encoded text rendered using font.
[in] | text | UTF8 encoded string to size up |
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()
int SDL2pp::Font::GetStyle | ( | ) | const |
Get the rendering style of the loaded font.
Optional< std::string > SDL2pp::Font::GetStyleName | ( | ) | const |
Get the current font face style name from the loaded font.
This function may return NullOpt, in which case the information is not available
bool SDL2pp::Font::IsFixedWidth | ( | ) | const |
Test if the current font face of the loaded font is 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:
int SDL2pp::Font::IsGlyphProvided | ( | Uint16 | ch | ) | const |
Get the status of the availability of the glyph from the loaded font.
[in] | ch | Unicode character to test glyph availability of |
Deleted assignment operator.
This class is not copyable
Surface SDL2pp::Font::RenderGlyph_Blended | ( | Uint16 | ch, |
SDL_Color | fg | ||
) |
Render the glyph for UNICODE character using blended mode.
[in] | ch | UNICODE character to render |
[in] | fg | Color to render the glyph in |
SDL2pp::Exception |
Surface SDL2pp::Font::RenderGlyph_Shaded | ( | Uint16 | ch, |
SDL_Color | fg, | ||
SDL_Color | bg | ||
) |
Render the glyph for UNICODE character using shaded mode.
[in] | ch | UNICODE character to render |
[in] | fg | Color to render the glyph in |
[in] | bg | Color to render the background box in |
SDL2pp::Exception |
Surface SDL2pp::Font::RenderGlyph_Solid | ( | Uint16 | ch, |
SDL_Color | fg | ||
) |
Render the glyph for UNICODE character using solid mode.
[in] | ch | UNICODE character to render |
[in] | fg | Color to render the glyph in |
SDL2pp::Exception |
Surface SDL2pp::Font::RenderText_Blended | ( | const std::string & | text, |
SDL_Color | fg | ||
) |
Render LATIN1 text using blended mode.
[in] | text | LATIN1 string to render |
[in] | fg | Color to render the text in |
SDL2pp::Exception |
Surface SDL2pp::Font::RenderText_Shaded | ( | const std::string & | text, |
SDL_Color | fg, | ||
SDL_Color | bg | ||
) |
Render LATIN1 text using shaded mode.
[in] | text | LATIN1 string to render |
[in] | fg | Color to render the text in |
[in] | bg | Color to render the background box in |
SDL2pp::Exception |
Surface SDL2pp::Font::RenderText_Solid | ( | const std::string & | text, |
SDL_Color | fg | ||
) |
Render LATIN1 text using solid mode.
[in] | text | LATIN1 string to render |
[in] | fg | Color to render the text in |
SDL2pp::Exception |
Surface SDL2pp::Font::RenderUNICODE_Blended | ( | const std::u16string & | text, |
SDL_Color | fg | ||
) |
Render UNICODE encoded text using blended mode.
[in] | text | UNICODE encoded string to render |
[in] | fg | Color to render the text in |
SDL2pp::Exception |
Surface SDL2pp::Font::RenderUNICODE_Blended | ( | const Uint16 * | text, |
SDL_Color | fg | ||
) |
Render UNICODE encoded text using blended mode.
[in] | text | UNICODE encoded string to render |
[in] | fg | Color to render the text in |
SDL2pp::Exception |
Surface SDL2pp::Font::RenderUNICODE_Shaded | ( | const std::u16string & | text, |
SDL_Color | fg, | ||
SDL_Color | bg | ||
) |
Render UNICODE encoded text using shaded mode.
[in] | text | UNICODE encoded string to render |
[in] | fg | Color to render the text in |
[in] | bg | Color to render the background box in |
SDL2pp::Exception |
Surface SDL2pp::Font::RenderUNICODE_Shaded | ( | const Uint16 * | text, |
SDL_Color | fg, | ||
SDL_Color | bg | ||
) |
Render UNICODE encoded text using shaded mode.
[in] | text | UNICODE encoded string to render |
[in] | fg | Color to render the text in |
[in] | bg | Color to render the background box in |
SDL2pp::Exception |
Surface SDL2pp::Font::RenderUNICODE_Solid | ( | const std::u16string & | text, |
SDL_Color | fg | ||
) |
Render UNICODE encoded text using solid mode.
[in] | text | UNICODE encoded string to render |
[in] | fg | Color to render the text in |
SDL2pp::Exception |
Surface SDL2pp::Font::RenderUNICODE_Solid | ( | const Uint16 * | text, |
SDL_Color | fg | ||
) |
Render UNICODE encoded text using solid mode.
[in] | text | UNICODE encoded string to render |
[in] | fg | Color to render the text in |
SDL2pp::Exception |
Surface SDL2pp::Font::RenderUTF8_Blended | ( | const std::string & | text, |
SDL_Color | fg | ||
) |
Render UTF8 text using blended mode.
[in] | text | UTF8 string to render |
[in] | fg | Color to render the text in |
SDL2pp::Exception |
Surface SDL2pp::Font::RenderUTF8_Shaded | ( | const std::string & | text, |
SDL_Color | fg, | ||
SDL_Color | bg | ||
) |
Render UTF8 text using shaded mode.
[in] | text | UTF8 string to render |
[in] | fg | Color to render the text in |
[in] | bg | Color to render the background box in |
SDL2pp::Exception |
Surface SDL2pp::Font::RenderUTF8_Solid | ( | const std::string & | text, |
SDL_Color | fg | ||
) |
Render UTF8 text using solid mode.
[in] | text | UTF8 string to render |
[in] | fg | Color to render the text in |
SDL2pp::Exception |
Font & SDL2pp::Font::SetHinting | ( | int | hinting = TTF_HINTING_NORMAL | ) |
Set the hinting of the loaded font.
[in] | hinting | The 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
Font & SDL2pp::Font::SetKerning | ( | bool | allowed = true | ) |
Set whether to use kerning when rendering the loaded font.
[in] | allowed | False 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.
Font & SDL2pp::Font::SetOutline | ( | int | outline = 0 | ) |
Set the outline pixel width of the loaded font.
[in] | outline | The size of outline desired, in pixels. Use 0 (zero) to turn off outlining. |
Font & SDL2pp::Font::SetStyle | ( | int | style = TTF_STYLE_NORMAL | ) |
Set the rendering style of the loaded font.
[in] | style | 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 desired then use TTF_STYLE_NORMAL, which is the default. |