diff --git a/Applications/FileManager/DirectoryView.cpp b/Applications/FileManager/DirectoryView.cpp index 0568c3dafd..43cbf18004 100644 --- a/Applications/FileManager/DirectoryView.cpp +++ b/Applications/FileManager/DirectoryView.cpp @@ -136,7 +136,7 @@ DirectoryView::DirectoryView(Mode mode) setup_actions(); m_error_label = add(); - m_error_label->set_font(m_error_label->font().bold_family_font()); + m_error_label->set_font(m_error_label->font().bold_variant()); setup_model(); diff --git a/Libraries/LibGUI/TextEditor.cpp b/Libraries/LibGUI/TextEditor.cpp index 74bb703d26..cfbc16b833 100644 --- a/Libraries/LibGUI/TextEditor.cpp +++ b/Libraries/LibGUI/TextEditor.cpp @@ -427,7 +427,7 @@ void TextEditor::paint_event(PaintEvent& event) painter.draw_text( ruler_line_rect.shrunken(2, 0).translated(0, m_line_spacing / 2), String::number(i + 1), - is_current_line && font().has_boldface() ? font().bold_family_font() : font(), + is_current_line ? font().bold_variant() : font(), Gfx::TextAlignment::TopRight, is_current_line ? palette().ruler_active_text() : palette().ruler_inactive_text()); } diff --git a/Libraries/LibGfx/Font.cpp b/Libraries/LibGfx/Font.cpp index 17ee106e6d..02e4ac98dc 100644 --- a/Libraries/LibGfx/Font.cpp +++ b/Libraries/LibGfx/Font.cpp @@ -116,8 +116,6 @@ Font::Font(String name, String family, unsigned* rows, u8* widths, bool is_fixed m_min_glyph_width = minimum; m_max_glyph_width = maximum; } - - set_family_fonts(); } Font::~Font() @@ -310,22 +308,19 @@ void Font::set_type(FontTypes type) m_glyph_widths = new_widths; } -void Font::set_family_fonts() -{ - StringBuilder path; - - if (weight() != 700) { - path.appendff("/res/fonts/{}Bold{}.font", family(), presentation_size()); - auto spath = path.to_string(); - m_bold_family_font = Font::load_from_file(path.to_string()); - if (m_bold_family_font) - set_boldface(true); - } -} - String Font::qualified_name() const { return String::formatted("{} {} {}", family(), presentation_size(), weight()); } +const Font& Font::bold_variant() const +{ + if (m_bold_variant) + return *m_bold_variant; + m_bold_variant = Gfx::FontDatabase::the().get(m_family, m_presentation_size, 700); + if (!m_bold_variant) + m_bold_variant = this; + return *m_bold_variant; +} + } diff --git a/Libraries/LibGfx/Font.h b/Libraries/LibGfx/Font.h index f731093fd1..a997a53d0f 100644 --- a/Libraries/LibGfx/Font.h +++ b/Libraries/LibGfx/Font.h @@ -124,10 +124,6 @@ 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; } @@ -147,6 +143,8 @@ public: String qualified_name() const; + const Font& bold_variant() const; + private: Font(String name, String family, unsigned* rows, u8* widths, bool is_fixed_width, u8 glyph_width, u8 glyph_height, u8 glyph_spacing, FontTypes type, u8 baseline, u8 mean_line, u8 presentation_size, u16 weight, bool owns_arrays = false); @@ -155,9 +153,6 @@ private: void update_x_height() { m_x_height = m_baseline - m_mean_line; }; - void set_family_fonts(); - RefPtr m_bold_family_font; - String m_name; String m_family; FontTypes m_type; @@ -179,8 +174,9 @@ private: u16 m_weight { 0 }; bool m_fixed_width { false }; - bool m_boldface { false }; bool m_owns_arrays { false }; + + mutable RefPtr m_bold_variant; }; }