ThorVG  v0.13
Textfinal

A class to represent text objects in a graphical context, allowing for rendering and manipulation of unicode text. More...

Inheritance diagram for Text:

Public Member Functions

Result font (const char *name, float size, const char *style=nullptr) noexcept
 Sets the font properties for the text. More...
 
Result text (const char *text) noexcept
 Assigns the given unicode text to be rendered. More...
 
Result fill (uint8_t r, uint8_t g, uint8_t b) noexcept
 Sets the text color. More...
 
Result fill (std::unique_ptr< Fill > f) noexcept
 Sets the gradient fill for all of the figures from the text. More...
 
- Public Member Functions inherited from Paint
Result rotate (float degree) noexcept
 Sets the angle by which the object is rotated. More...
 
Result scale (float factor) noexcept
 Sets the scale value of the object. More...
 
Result translate (float x, float y) noexcept
 Sets the values by which the object is moved in a two-dimensional space. More...
 
Result transform (const Matrix &m) noexcept
 Sets the matrix of the affine transformation for the object. More...
 
Matrix transform () noexcept
 Gets the matrix of the affine transformation of the object. More...
 
Result opacity (uint8_t o) noexcept
 Sets the opacity of the object. More...
 
Result composite (std::unique_ptr< Paint > target, CompositeMethod method) noexcept
 Sets the composition target object and the composition method. More...
 
Result blend (BlendMethod method) const noexcept
 Sets the blending method for the paint object. More...
 
TVG_DEPRECATED Result bounds (float *x, float *y, float *w, float *h) const noexcept
 Gets the bounding box of the paint object before any transformation. More...
 
Result bounds (float *x, float *y, float *w, float *h, bool transformed) const noexcept
 Gets the axis-aligned bounding box of the paint object. More...
 
Paintduplicate () const noexcept
 Duplicates the object. More...
 
uint8_t opacity () const noexcept
 Gets the opacity value of the object. More...
 
CompositeMethod composite (const Paint **target) const noexcept
 Gets the composition target object and the composition method. More...
 
BlendMethod blend () const noexcept
 Gets the blending method of the object. More...
 
uint32_t identifier () const noexcept
 Return the unique id value of the paint instance. More...
 

Static Public Member Functions

static Result load (const std::string &path) noexcept
 Loads a scalable font data(ttf) from a file. More...
 
static Result unload (const std::string &path) noexcept
 Unloads the specified scalable font data (TTF) that was previously loaded. More...
 
static std::unique_ptr< Textgen () noexcept
 Creates a new Text object. More...
 
static uint32_t identifier () noexcept
 Return the unique id value of this class. More...
 

Detailed Description

A class to represent text objects in a graphical context, allowing for rendering and manipulation of unicode text.

Note
Experimental API

Member Function Documentation

◆ fill() [1/2]

Result fill ( std::unique_ptr< Fill f)
noexcept

Sets the gradient fill for all of the figures from the text.

The parts of the text defined as inner are filled.

Parameters
[in]fThe unique pointer to the gradient fill.
Return values
Result::Successwhen succeed, Result::MemoryCorruption otherwise.
Result::InsufficientConditionwhen the font has not been set up prior to this operation.
Note
Either a solid color or a gradient fill is applied, depending on what was set as last.
Experimental API
See also
Text::font()

◆ fill() [2/2]

Result fill ( uint8_t  r,
uint8_t  g,
uint8_t  b 
)
noexcept

Sets the text color.

Parameters
[in]rThe red color channel value in the range [0 ~ 255]. The default value is 0.
[in]gThe green color channel value in the range [0 ~ 255]. The default value is 0.
[in]bThe blue color channel value in the range [0 ~ 255]. The default value is 0.
Return values
Result::Successwhen succeed.
Result::InsufficientConditionwhen the font has not been set up prior to this operation.
See also
Text::font()
Note
Experimental API

◆ font()

Result font ( const char *  name,
float  size,
const char *  style = nullptr 
)
noexcept

Sets the font properties for the text.

This function allows you to define the font characteristics used for text rendering. It sets the font name, size and optionally the style.

Parameters
[in]nameThe name of the font. This should correspond to a font available in the canvas.
[in]sizeThe size of the font in points. This determines how large the text will appear.
[in]styleThe style of the font. It can be used to set the font to 'italic'. If not specified, the default style is used. Only 'italic' style is supported currently.
Return values
Result::Successwhen the font properties are set successfully.
Result::InsufficientConditionwhen the specified name cannot be found.
Note
Experimental API

◆ gen()

static std::unique_ptr<Text> gen ( )
staticnoexcept

Creates a new Text object.

Returns
A new Text object.
Note
Experimental API

◆ identifier()

static uint32_t identifier ( )
staticnoexcept

Return the unique id value of this class.

This method can be referred for identifying the Text class type.

Returns
The type id of the Text class.

◆ load()

static Result load ( const std::string &  path)
staticnoexcept

Loads a scalable font data(ttf) from a file.

ThorVG efficiently caches the loaded data using the specified path as a key. This means that loading the same file again will not result in duplicate operations; instead, ThorVG will reuse the previously loaded font data.

Parameters
[in]pathThe path to the font file.
Return values
Result::SuccessWhen succeed.
Result::InvalidArgumentsIn case the path is invalid.
Result::NonSupportWhen trying to load a file with an unknown extension.
Result::UnknownIf an error occurs at a later stage.
Note
Experimental API
See also
Text::unload(const std::string& path)

◆ text()

Result text ( const char *  text)
noexcept

Assigns the given unicode text to be rendered.

This function sets the unicode string that will be displayed by the rendering system. The text is set according to the specified UTF encoding method, which defaults to UTF-8.

Parameters
[in]textThe multi-byte text encoded with utf8 string to be rendered.
Return values
Result::Successwhen succeed.
Note
Experimental API

◆ unload()

static Result unload ( const std::string &  path)
staticnoexcept

Unloads the specified scalable font data (TTF) that was previously loaded.

This function is used to release resources associated with a font file that has been loaded into memory.

Parameters
[in]pathThe file path of the loaded font.
Return values
Result::SuccessSuccessfully unloads the font data.
Result::InsufficientConditionFails if the loader is not initialized.
Note
If the font data is currently in use, it will not be immediately unloaded.
Experimental API
See also
Text::load(const std::string& path)