14#include <egt/detail/math.h>
15#include <egt/serialize.h>
61 static constexpr const char* DEFAULT_FACE =
"Free Sans";
63 static constexpr Font::Weight DEFAULT_WEIGHT = Font::Weight::normal;
67 static constexpr Font::Slant DEFAULT_SLANT = Font::Slant::normal;
76 explicit Font(
const std::string& face);
85 explicit Font(
const unsigned char* data,
size_t len,
136 EGT_NODISCARD
const std::string&
face()
const {
return m_face; }
141 void face(
const std::string& face) { m_face =
face; direct_allocate(); }
151 void size(
const Font::Size& s) { m_use_default_size =
false; m_size = s; direct_allocate(); }
189 void deserialize(
const std::string& name,
const std::string& value,
224 std::string m_face{DEFAULT_FACE};
237 const unsigned char* m_data{
nullptr};
241 bool m_use_default_size{
true};
248static_assert(detail::rule_of_5<Font>(),
"must fulfill rule of 5");
265 return !(lhs == rhs);
Manages a font and properties of a font.
Definition font.h:35
EGT_NODISCARD Font::Slant slant() const
Get the slant of the font.
Definition font.h:166
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:151
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.
Font(Font::Slant slant)
Create a font based on the global default font, but with the specified slant.
void face(const std::string &face)
Set the face of the font.
Definition font.h:141
void deserialize(const std::string &name, const std::string &value, const Serializer::Attributes &attrs)
Deserialize.
Font::Size m_size
Font size.
Definition font.h:227
EGT_NODISCARD Font::Size size() const
Get the size of the font.
Definition font.h:146
void serialize(const std::string &name, Serializer &serializer) const
Serialize to the specified serializer.
EGT_NODISCARD cairo_scaled_font_t * scaled_font() const
Generates a FontConfig scaled font instance.
EGT_NODISCARD Font::Weight weight() const
Get the weight of the font.
Definition font.h:156
static void shutdown_fonts()
Basically, this will clear the font cache and shutdown FontConfig which will release all memory alloc...
Font(Font::Size size)
Create a font based on the global default font, but with the specified size.
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:54
float Size
Scalar used for font size.
Definition font.h:39
Weight
Font weights.
Definition font.h:45
void weight(Font::Weight w)
Set the weight of the font.
Definition font.h:161
void slant(Font::Slant s)
Set the slant of the font.
Definition font.h:171
shared_cairo_scaled_font_t m_scaled_font
Only used when an in-memory font is created.
Definition font.h:236
EGT_NODISCARD const std::string & face() const
Get the face name the font.
Definition font.h:136
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
std::shared_ptr< cairo_scaled_font_t > shared_cairo_scaled_font_t
Shared pointer for a cairo font.
Definition types.h:47
EGT framework namespace.
Definition animation.h:24