diff --git a/Libraries/LibGfx/Font.cpp b/Libraries/LibGfx/Font.cpp index 2002d16a38..3b05960405 100644 --- a/Libraries/LibGfx/Font.cpp +++ b/Libraries/LibGfx/Font.cpp @@ -30,8 +30,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -152,6 +154,8 @@ Font::Font(const StringView& name, unsigned* rows, u8* widths, bool is_fixed_wid m_min_glyph_width = minimum; m_max_glyph_width = maximum; } + + set_family_fonts(); } Font::~Font() @@ -343,4 +347,35 @@ void Font::set_type(FontTypes type) m_glyph_widths = new_widths; } +void Font::set_family_fonts() +{ + String typeface; + String weight; + StringBuilder size; + + auto parts = this->name().split(' '); + if (parts.size() < 2) { + typeface = this->name(); + } else { + typeface = parts[0]; + weight = parts[1]; + } + + if (this->is_fixed_width()) { + size.appendf("%d", this->m_max_glyph_width); + size.append("x"); + } + size.appendf("%d", this->m_glyph_height); + + StringBuilder path; + + if (weight != "Bold") { + path.appendf("/res/fonts/%sBold%s.font", &typeface[0], &size.to_string()[0]); + m_bold_family_font = Font::load_from_file(path.to_string()); + if (m_bold_family_font) + set_boldface(true); + path.clear(); + } +} + } diff --git a/Libraries/LibGfx/Font.h b/Libraries/LibGfx/Font.h index 475f3a13e6..830e038397 100644 --- a/Libraries/LibGfx/Font.h +++ b/Libraries/LibGfx/Font.h @@ -110,6 +110,10 @@ public: bool is_fixed_width() const { return m_fixed_width; } void set_fixed_width(bool b) { m_fixed_width = b; } + const Font& bold_family_font() const { return *m_bold_family_font; } + bool has_boldface() const { return m_boldface; } + void set_boldface(bool b) { m_boldface = b; } + u8 glyph_spacing() const { return m_glyph_spacing; } void set_glyph_spacing(u8 spacing) { m_glyph_spacing = spacing; } @@ -130,6 +134,9 @@ private: static RefPtr load_from_memory(const u8*); static size_t glyph_count_by_type(FontTypes type); + void set_family_fonts(); + RefPtr m_bold_family_font; + String m_name; FontTypes m_type; size_t m_glyph_count { 256 }; @@ -146,6 +153,7 @@ private: u8 m_glyph_spacing { 0 }; bool m_fixed_width { false }; + bool m_boldface { false }; }; }