Loading...
Searching...
No Matches
Gfx::CText Class Reference

Text rendering engine. More...

`#include <src/graphics/engine/text.h>`

## Classes

class | CQuadBatch

## Public Member Functions

| CText (CEngine *engine)
void | SetDevice (CDevice *device)
| Sets the device to be used.
std::string | GetError ()
| Returns the last encountered error.
bool | Create ()
| Initializes the font engine; must be called after SetDevice().
void | Destroy ()
| Frees resources before exit.
void | FlushCache ()
| Flushes cached textures.
bool | ReloadFonts ()
| Try to load new font files.
void | SetTabSize (int tabSize)
| Tab size management.
int | GetTabSize ()
void | DrawText (const std::string &text, std::vector< FontMetaChar >::iterator format, std::vector< FontMetaChar >::iterator end, float size, Math::Point pos, float width, TextAlign align, int eol, Color color=Color(0.0f, 0.0f, 0.0f, 1.0f))
| Draws text (multi-format).
void | DrawText (const std::string &text, FontType font, float size, Math::Point pos, float width, TextAlign align, int eol, Color color=Color(0.0f, 0.0f, 0.0f, 1.0f))
| Draws text (one font).
void | SizeText (const std::string &text, std::vector< FontMetaChar >::iterator format, std::vector< FontMetaChar >::iterator endFormat, float size, Math::Point pos, TextAlign align, Math::Point &start, Math::Point &end)
| Calculates dimensions for text (multi-format).
void | SizeText (const std::string &text, FontType font, float size, Math::Point pos, TextAlign align, Math::Point &start, Math::Point &end)
| Calculates dimensions for text (one font).
float | GetAscent (FontType font, float size)
| Returns the ascent font metric.
float | GetDescent (FontType font, float size)
| Returns the descent font metric.
float | GetHeight (FontType font, float size)
| Returns the height font metric.
int | GetHeightInt (FontType font, float size)
TEST_VIRTUAL float | GetStringWidth (const std::string &text, std::vector< FontMetaChar >::iterator format, std::vector< FontMetaChar >::iterator end, float size)
| Returns width of string (multi-format).
TEST_VIRTUAL float | GetStringWidth (std::string text, FontType font, float size)
| Returns width of string (single font).
TEST_VIRTUAL float | GetCharWidth (UTF8Char ch, FontType font, float size, float offset)
| Returns width of single character.
int | GetCharWidthInt (UTF8Char ch, FontType font, float size, float offset)
int | Justify (const std::string &text, std::vector< FontMetaChar >::iterator format, std::vector< FontMetaChar >::iterator end, float size, float width)
| Justifies a line of text (multi-format).
int | Justify (const std::string &text, FontType font, float size, float width)
| Justifies a line of text (one font).
int | Detect (const std::string &text, std::vector< FontMetaChar >::iterator format, std::vector< FontMetaChar >::iterator end, float size, float offset)
| Returns the most suitable position to a given offset (multi-format).
int | Detect (const std::string &text, FontType font, float size, float offset)
| Returns the most suitable position to a given offset (one font).
UTF8Char | TranslateSpecialChar (int specialChar)
CharTexture | GetCharTexture (UTF8Char ch, FontType font, float size)
Math::IntPoint | GetFontTextureSize ()

## Protected Member Functions

int | GetFontPointSize (float size) const
CachedFont * | GetOrOpenFont (FontType type, float size)
CharTexture | CreateCharTexture (UTF8Char ch, CachedFont *font)
FontTexture * | GetOrCreateFontTexture (Math::IntPoint tileSize)
FontTexture | CreateFontTexture (Math::IntPoint tileSize)
Math::IntPoint | GetNextTilePos (const FontTexture &fontTexture)
void | DrawString (const std::string &text, std::vector< FontMetaChar >::iterator format, std::vector< FontMetaChar >::iterator end, float size, Math::IntPoint pos, int width, int eol, Color color)
void | DrawString (const std::string &text, FontType font, float size, Math::IntPoint pos, int width, int eol, Color color)
void | DrawHighlight (FontMetaChar hl, Math::IntPoint pos, Math::IntPoint size)
void | DrawCharAndAdjustPos (UTF8Char ch, FontType font, float size, Math::IntPoint &pos, Color color)
void | StringToUTFCharList (const std::string &text, std::vector< UTF8Char > &chars)
void | StringToUTFCharList (const std::string &text, std::vector< UTF8Char > &chars, std::vector< FontMetaChar >::iterator format, std::vector< FontMetaChar >::iterator end)
int | GetCharSizeAt (Gfx::FontType font, const std::string &text, unsigned int index) const

## Protected Attributes

CEngine * | m_engine
CDevice * | m_device
std::string | m_error
float | m_defaultSize
int | m_tabSize
std::unique_ptr< FontsCache > | m_fontsCache
std::vector< FontTexture > | m_fontTextures
std::unique_ptr< CQuadBatch > | m_quadBatch

## Detailed Description

Text rendering engine.

CText is responsible for drawing text in 2D interface. Font rendering is done using textures generated by SDL_ttf from TTF font files.

All functions rendering text are divided into two types:

- single font - function takes a single FontType argument that (along with size) determines the font to be used for all characters,
- multi-font - function takes the text as one argument and a std::vector of FontMetaChar with per-character formatting information (font, highlights and some other info used by CEdit)

All font rendering is done in UTF-8.

## Member Function Documentation

## SetDevice()

void Gfx::CText::SetDevice | ( | CDevice * | device | ) |

Sets the device to be used.

## GetError()

std::string Gfx::CText::GetError | ( |  | ) |

Returns the last encountered error.

## Create()

bool Gfx::CText::Create | ( |  | ) |

Initializes the font engine; must be called after SetDevice().

## Destroy()

void Gfx::CText::Destroy | ( |  | ) |

Frees resources before exit.

## FlushCache()

void Gfx::CText::FlushCache | ( |  | ) |

Flushes cached textures.

## ReloadFonts()

bool Gfx::CText::ReloadFonts | ( |  | ) |

Try to load new font files.

## SetTabSize()

void Gfx::CText::SetTabSize | ( | int | tabSize | ) |

Tab size management.

## DrawText() [1/2]

void Gfx::CText::DrawText | ( | const std::string & | text,
|  | std::vector< FontMetaChar >::iterator | format,
|  | std::vector< FontMetaChar >::iterator | end,
|  | float | size,
|  | Math::Point | pos,
|  | float | width,
|  | TextAlign | align,
|  | int | eol,
|  | Color | color = Color(0.0f, 0.0f, 0.0f, 1.0f) )

Draws text (multi-format).

## DrawText() [2/2]

void Gfx::CText::DrawText | ( | const std::string & | text,
|  | FontType | font,
|  | float | size,
|  | Math::Point | pos,
|  | float | width,
|  | TextAlign | align,
|  | int | eol,
|  | Color | color = Color(0.0f, 0.0f, 0.0f, 1.0f) )

Draws text (one font).

## SizeText() [1/2]

void Gfx::CText::SizeText | ( | const std::string & | text,
|  | std::vector< FontMetaChar >::iterator | format,
|  | std::vector< FontMetaChar >::iterator | endFormat,
|  | float | size,
|  | Math::Point | pos,
|  | TextAlign | align,
|  | Math::Point & | start,
|  | Math::Point & | end )

Calculates dimensions for text (multi-format).

## SizeText() [2/2]

void Gfx::CText::SizeText | ( | const std::string & | text,
|  | FontType | font,
|  | float | size,
|  | Math::Point | pos,
|  | TextAlign | align,
|  | Math::Point & | start,
|  | Math::Point & | end )

Calculates dimensions for text (one font).

## GetAscent()

float Gfx::CText::GetAscent | ( | FontType | font,
|  | float | size )

Returns the ascent font metric.

## GetDescent()

float Gfx::CText::GetDescent | ( | FontType | font,
|  | float | size )

Returns the descent font metric.

## GetHeight()

float Gfx::CText::GetHeight | ( | FontType | font,
|  | float | size )

Returns the height font metric.

## GetStringWidth() [1/2]

float Gfx::CText::GetStringWidth | ( | const std::string & | text,
|  | std::vector< FontMetaChar >::iterator | format,
|  | std::vector< FontMetaChar >::iterator | end,
|  | float | size )

Returns width of string (multi-format).

## GetStringWidth() [2/2]

float Gfx::CText::GetStringWidth | ( | std::string | text,
|  | FontType | font,
|  | float | size )

Returns width of string (single font).

## GetCharWidth()

float Gfx::CText::GetCharWidth | ( | UTF8Char | ch,
|  | FontType | font,
|  | float | size,
|  | float | offset )

Returns width of single character.

## Justify() [1/2]

int Gfx::CText::Justify | ( | const std::string & | text,
|  | std::vector< FontMetaChar >::iterator | format,
|  | std::vector< FontMetaChar >::iterator | end,
|  | float | size,
|  | float | width )

Justifies a line of text (multi-format).

## Justify() [2/2]

int Gfx::CText::Justify | ( | const std::string & | text,
|  | FontType | font,
|  | float | size,
|  | float | width )

Justifies a line of text (one font).

## Detect() [1/2]

int Gfx::CText::Detect | ( | const std::string & | text,
|  | std::vector< FontMetaChar >::iterator | format,
|  | std::vector< FontMetaChar >::iterator | end,
|  | float | size,
|  | float | offset )

Returns the most suitable position to a given offset (multi-format).

## Detect() [2/2]

int Gfx::CText::Detect | ( | const std::string & | text,
|  | FontType | font,
|  | float | size,
|  | float | offset )

Returns the most suitable position to a given offset (one font).

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

- src/graphics/engine/text.h
- src/graphics/engine/text.cpp