mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:48:11 +00:00
LibGfx: Add Gfx::Font::bold_variant() that does a proper font lookup
We previously had a cached bold variant font in Gfx::Font that was very haphazardly located by filename pattern. This patches replaces that mechanism with a proper Gfx::FontDatabase lookup for the same font but with bold weight (700).
This commit is contained in:
parent
0f66589007
commit
412a91d58f
4 changed files with 16 additions and 25 deletions
|
@ -136,7 +136,7 @@ DirectoryView::DirectoryView(Mode mode)
|
||||||
setup_actions();
|
setup_actions();
|
||||||
|
|
||||||
m_error_label = add<GUI::Label>();
|
m_error_label = add<GUI::Label>();
|
||||||
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();
|
setup_model();
|
||||||
|
|
||||||
|
|
|
@ -427,7 +427,7 @@ void TextEditor::paint_event(PaintEvent& event)
|
||||||
painter.draw_text(
|
painter.draw_text(
|
||||||
ruler_line_rect.shrunken(2, 0).translated(0, m_line_spacing / 2),
|
ruler_line_rect.shrunken(2, 0).translated(0, m_line_spacing / 2),
|
||||||
String::number(i + 1),
|
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,
|
Gfx::TextAlignment::TopRight,
|
||||||
is_current_line ? palette().ruler_active_text() : palette().ruler_inactive_text());
|
is_current_line ? palette().ruler_active_text() : palette().ruler_inactive_text());
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,8 +116,6 @@ Font::Font(String name, String family, unsigned* rows, u8* widths, bool is_fixed
|
||||||
m_min_glyph_width = minimum;
|
m_min_glyph_width = minimum;
|
||||||
m_max_glyph_width = maximum;
|
m_max_glyph_width = maximum;
|
||||||
}
|
}
|
||||||
|
|
||||||
set_family_fonts();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Font::~Font()
|
Font::~Font()
|
||||||
|
@ -310,22 +308,19 @@ void Font::set_type(FontTypes type)
|
||||||
m_glyph_widths = new_widths;
|
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
|
String Font::qualified_name() const
|
||||||
{
|
{
|
||||||
return String::formatted("{} {} {}", family(), presentation_size(), weight());
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,10 +124,6 @@ public:
|
||||||
bool is_fixed_width() const { return m_fixed_width; }
|
bool is_fixed_width() const { return m_fixed_width; }
|
||||||
void set_fixed_width(bool b) { m_fixed_width = b; }
|
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; }
|
u8 glyph_spacing() const { return m_glyph_spacing; }
|
||||||
void set_glyph_spacing(u8 spacing) { m_glyph_spacing = spacing; }
|
void set_glyph_spacing(u8 spacing) { m_glyph_spacing = spacing; }
|
||||||
|
|
||||||
|
@ -147,6 +143,8 @@ public:
|
||||||
|
|
||||||
String qualified_name() const;
|
String qualified_name() const;
|
||||||
|
|
||||||
|
const Font& bold_variant() const;
|
||||||
|
|
||||||
private:
|
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);
|
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 update_x_height() { m_x_height = m_baseline - m_mean_line; };
|
||||||
|
|
||||||
void set_family_fonts();
|
|
||||||
RefPtr<Font> m_bold_family_font;
|
|
||||||
|
|
||||||
String m_name;
|
String m_name;
|
||||||
String m_family;
|
String m_family;
|
||||||
FontTypes m_type;
|
FontTypes m_type;
|
||||||
|
@ -179,8 +174,9 @@ private:
|
||||||
u16 m_weight { 0 };
|
u16 m_weight { 0 };
|
||||||
|
|
||||||
bool m_fixed_width { false };
|
bool m_fixed_width { false };
|
||||||
bool m_boldface { false };
|
|
||||||
bool m_owns_arrays { false };
|
bool m_owns_arrays { false };
|
||||||
|
|
||||||
|
mutable RefPtr<Gfx::Font> m_bold_variant;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue