14#include <egt/detail/math.h>
15#include <egt/geometry.h>
16#include <egt/serialize.h>
94 static constexpr const char* DEFAULT_FACE =
"Free Sans";
96 static constexpr Font::Weight DEFAULT_WEIGHT = Font::Weight::normal;
109 explicit Font(
const std::string& face);
118 explicit Font(
const unsigned char* data,
size_t len,
169 EGT_NODISCARD
const std::string&
face()
const {
return m_face; }
174 void face(
const std::string& face) { m_face =
face; direct_allocate(); }
184 void size(
const Font::Size& s) { m_use_default_size =
false; m_size = s; direct_allocate(); }
262 void deserialize(
const std::string& name,
const std::string& value,
297 std::string m_face{DEFAULT_FACE};
310 const unsigned char* m_data{
nullptr};
314 bool m_use_default_size{
true};
321static_assert(detail::rule_of_5<Font>(),
"must fulfill rule of 5");
338 return !(lhs == rhs);
Manages a font and properties of a font.
Definition font.h:41
EGT_NODISCARD Font::Slant slant() const
Get the slant of the font.
Definition font.h:199
Font(const std::string &face)
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::Weight weight)
Create a font based on the global default font, but with the specified weight.
void size(const Font::Size &s)
Set the size of the font.
Definition font.h:184
EGT_NODISCARD Font::FontExtents extents() const
Get the font extents based on a default context.
static void reset_font_cache()
Clears any internal font cache.
Font(Font::Size size, Font::Weight weight)
Create a font based on the global default font, but with the specified size and weight.
EGT_NODISCARD egt::Size text_size(const std::string &text) const
Get the size of a rectangle containing the text, based on a default context.
Font(Font::Slant slant)
Create a font based on the global default font, but with the specified slant.
Extent ascent
Definition font.h:51
void face(const std::string &face)
Set the face of the font.
Definition font.h:174
Extent descent
Definition font.h:52
void deserialize(const std::string &name, const std::string &value, const Serializer::Attributes &attrs)
Deserialize.
Font::Size m_size
Font size.
Definition font.h:300
EGT_NODISCARD Font::Size size() const
Get the size of the font.
Definition font.h:179
Extent max_y_advance
Definition font.h:55
void serialize(const std::string &name, Serializer &serializer) const
Serialize to the specified serializer.
Extent y_advance
Definition font.h:68
Extent x_advance
Definition font.h:67
float Extent
Definition font.h:44
EGT_NODISCARD Font::Weight weight() const
Get the weight of the font.
Definition font.h:189
static void shutdown_fonts()
Basically, this will clear the font cache and shutdown FontConfig which will release all memory alloc...
EGT_NODISCARD const detail::InternalFont & scaled_font() const
Generates a FontConfig scaled font instance.
Font(Font::Size size)
Create a font based on the global default font, but with the specified size.
Extent x_bearing
Definition font.h:63
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.
void on_screen_resized()
Recompute the font size from the screen size but only if it has not been defined by the user.
Slant
Font slants.
Definition font.h:87
float Size
Scalar used for font size.
Definition font.h:72
Extent y_bearing
Definition font.h:64
Extent height
Definition font.h:53
EGT_NODISCARD Font::TextExtents extents(const std::string &text) const
Get the text extents based on a default context.
Weight
Font weights.
Definition font.h:78
void weight(Font::Weight w)
Set the weight of the font.
Definition font.h:194
Extent width
Definition font.h:65
Extent max_x_advance
Definition font.h:54
void slant(Font::Slant s)
Set the slant of the font.
Definition font.h:204
std::shared_ptr< detail::InternalFont > m_scaled_font
Only used when an in-memory font is created.
Definition font.h:309
EGT_NODISCARD const std::string & face() const
Get the face name the font.
Definition font.h:169
Font extent.
Definition font.h:50
Text extent.
Definition font.h:62
Abstract base serializer class.
Definition serialize.h:34
std::list< std::pair< std::string, std::string > > Attributes
Attributes array type.
Definition serialize.h:45
constexpr bool float_equal(const float f1, const float f2)
Safe equal comparison of float values.
Definition math.h:107
constexpr bool operator!=(const Color &lhs, const Color &rhs)
Color operator.
Definition color.h:509
EGT_API void reset_global_font()
Reset global Font.
EGT_API const Font * global_font()
Get the global Font.
EGT_API std::ostream & operator<<(std::ostream &os, const Color &color)
Overloaded std::ostream insertion operator.
constexpr bool operator==(const Color &lhs, const Color &rhs)
Color operator.
Definition color.h:500
EGT framework namespace.
Definition animation.h:24