1.10 |
Manages a font and properties of a font. More...
#include <font.h>
Public Types | |
using | Size = float |
Scalar used for font size. | |
enum class | Slant { normal = 0 , italic = 1 , oblique = 2 } |
Font slants. More... | |
enum class | Weight { normal = 0 , bold = 1 } |
Font weights. More... | |
Public Member Functions | |
Font () | |
Font (const std::string &face) | |
Create a font based on the supplied parameters. | |
Font (const std::string &face, Font::Size size, Font::Weight weight=Weight::normal, Font::Slant slant=Slant::normal) | |
Create a font based on the supplied parameters. | |
Font (const unsigned char *data, size_t len, Font::Size size) | |
Create a font from an in-memory font. | |
Font (Font::Size size) | |
Create a font based on the global default font, but with the specified size. | |
Font (Font::Size size, Font::Weight weight) | |
Create a font based on the global default font, but with the specified size and weight. | |
Font (Font::Slant slant) | |
Create a font based on the global default font, but with the specified slant. | |
Font (Font::Weight weight) | |
Create a font based on the global default font, but with the specified weight. | |
void | deserialize (const std::string &name, const std::string &value, const Serializer::Attributes &attrs) |
Deserialize. | |
EGT_NODISCARD const std::string & | face () const |
Get the face name the font. | |
void | face (const std::string &face) |
Set the face of the font. | |
void | on_screen_resized () |
Recompute the font size from the screen size but only if it has not been defined by the user. | |
EGT_NODISCARD cairo_scaled_font_t * | scaled_font () const |
Generates a FontConfig scaled font instance. | |
void | serialize (const std::string &name, Serializer &serializer) const |
Serialize to the specified serializer. | |
EGT_NODISCARD Font::Size | size () const |
Get the size of the font. | |
void | size (const Font::Size &s) |
Set the size of the font. | |
EGT_NODISCARD Font::Slant | slant () const |
Get the slant of the font. | |
void | slant (Font::Slant s) |
Set the slant of the font. | |
EGT_NODISCARD Font::Weight | weight () const |
Get the weight of the font. | |
void | weight (Font::Weight w) |
Set the weight of the font. | |
Static Public Member Functions | |
static void | reset_font_cache () |
Clears any internal font cache. | |
static void | shutdown_fonts () |
Basically, this will clear the font cache and shutdown FontConfig which will release all memory allocated by FontConfig. | |
Static Public Attributes | |
static constexpr const char * | DEFAULT_FACE = "Free Sans" |
Default font face. | |
static constexpr Font::Size | DEFAULT_SIZE = 18.f |
Default font size. | |
static constexpr Font::Slant | DEFAULT_SLANT = Font::Slant::normal |
Default font slant. | |
static constexpr Font::Weight | DEFAULT_WEIGHT = Font::Weight::normal |
Default font weight. | |
Protected Member Functions | |
void | direct_allocate () |
Protected Attributes | |
const unsigned char * | m_data {nullptr} |
std::string | m_face {DEFAULT_FACE} |
Font face name. | |
size_t | m_len {0} |
shared_cairo_scaled_font_t | m_scaled_font |
Only used when an in-memory font is created. | |
Font::Size | m_size |
Font size. | |
Font::Slant | m_slant {DEFAULT_SLANT} |
Font slant. | |
bool | m_use_default_size {true} |
Use default size. | |
Font::Weight | m_weight {DEFAULT_WEIGHT} |
Font weight. | |
Manages a font and properties of a font.
A Font consists of a type face, a size, and a weight. The font face must be installed on the system in order to use it. Usually, if the specified font face cannot be found on the system, a similar font face will be selected.
using Size = float |
Scalar used for font size.
Font | ( | ) |
|
explicit |
Create a font based on the supplied parameters.
[in] | face | The face name of the font. |
|
explicit |
Create a font from an in-memory font.
[in] | data | Raw memory to the font. |
[in] | len | Size of bytes of the ram memory. |
[in] | size | The size of the font. |
|
explicit |
Create a font based on the supplied parameters.
[in] | face | The face name of the font. |
[in] | size | The size of the font. |
[in] | weight | The weight of the font. |
[in] | slant | The slant of the font. |
|
explicit |
Create a font based on the global default font, but with the specified size.
[in] | size | The size of the font. |
|
explicit |
Create a font based on the global default font, but with the specified size and weight.
[in] | size | The size of the font. |
[in] | weight | The weight of the font. |
|
explicit |
Create a font based on the global default font, but with the specified weight.
[in] | weight | The weight of the font. |
|
explicit |
Create a font based on the global default font, but with the specified slant.
[in] | slant | The slant of the font. |
void deserialize | ( | const std::string & | name, |
const std::string & | value, | ||
const Serializer::Attributes & | attrs | ||
) |
Deserialize.
|
protected |
|
inline |
Get the face name the font.
|
inline |
Set the face of the font.
void on_screen_resized | ( | ) |
Recompute the font size from the screen size but only if it has not been defined by the user.
|
static |
Clears any internal font cache.
This will cause any new requests for fonts to be re-generated.
EGT_NODISCARD cairo_scaled_font_t * scaled_font | ( | ) | const |
Generates a FontConfig scaled font instance.
Internally, this may use a font cache to limit regeneration of the same font more than once.
void serialize | ( | const std::string & | name, |
Serializer & | serializer | ||
) | const |
Serialize to the specified serializer.
|
static |
Basically, this will clear the font cache and shutdown FontConfig which will release all memory allocated by FontConfig.
Typically, you should not need to call this. However, this is useful for debugging memory leaks and avoiding false positives in FontConfig. Once you call this function, requesting any Font to be created is likely to not work out well.
|
inline |
Get the size of the font.
|
inline |
Set the size of the font.
|
inline |
Get the slant of the font.
|
inline |
Set the slant of the font.
|
inline |
Get the weight of the font.
|
inline |
Set the weight of the font.
|
staticconstexpr |
Default font face.
|
staticconstexpr |
Default font size.
|
staticconstexpr |
Default font slant.
|
staticconstexpr |
Default font weight.
|
protected |
|
protected |
Font face name.
|
protected |
|
mutableprotected |
Only used when an in-memory font is created.
|
protected |
Font size.
|
protected |
Font slant.
|
protected |
Use default size.
|
protected |
Font weight.