LibGfx: Remove Gfx::FontDatabase::default_bold_font()

Instead use default_font().bold_variant() in cases where we want a bold
variant of the default font. :^)
This commit is contained in:
Andreas Kling 2021-05-20 18:40:48 +02:00
parent 068ddf4513
commit 6a012ad79f
Notes: sideshowbarker 2024-07-18 17:42:23 +09:00
24 changed files with 33 additions and 46 deletions

View File

@ -51,11 +51,6 @@ TEST_CASE(test_default_bold_fixed_width_font)
EXPECT(!Gfx::FontDatabase::default_bold_fixed_width_font().name().is_null());
}
TEST_CASE(test_default_bold_font)
{
EXPECT(!Gfx::FontDatabase::default_bold_font().name().is_null());
}
TEST_CASE(test_clone)
{
u8 glyph_height = 1;

View File

@ -46,7 +46,7 @@ AddEventDialog::AddEventDialog(Core::DateTime date_time, Window* parent_window)
auto& add_label = top_container.add<GUI::Label>("Add title & date:");
add_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
add_label.set_fixed_height(14);
add_label.set_font(Gfx::FontDatabase::default_bold_font());
add_label.set_font(Gfx::FontDatabase::default_font().bold_variant());
auto& event_title_textbox = top_container.add<GUI::TextBox>();
event_title_textbox.set_fixed_height(20);

View File

@ -497,7 +497,7 @@ void HexEditor::paint_event(GUI::PaintEvent& event)
painter.draw_text(
side_offset_rect,
line,
is_current_line ? Gfx::FontDatabase::default_bold_font() : font(),
is_current_line ? font().bold_variant() : font(),
Gfx::TextAlignment::TopLeft,
is_current_line ? palette().ruler_active_text() : palette().ruler_inactive_text());
}

View File

@ -42,7 +42,7 @@ MemoryStatsWidget::MemoryStatsWidget(GraphWidget& graph)
container.set_layout<GUI::HorizontalBoxLayout>();
container.set_fixed_size(275, 12);
auto& description_label = container.add<GUI::Label>(description);
description_label.set_font(Gfx::FontDatabase::default_bold_font());
description_label.set_font(Gfx::FontDatabase::default_font().bold_variant());
description_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
auto& label = container.add<GUI::Label>();
label.set_text_alignment(Gfx::TextAlignment::CenterRight);

View File

@ -45,7 +45,7 @@ public:
if (role == GUI::ModelRole::Font) {
if (index.column() == 0) {
return Gfx::FontDatabase::default_bold_font();
return Gfx::FontDatabase::default_font().bold_variant();
}
}

View File

@ -456,7 +456,7 @@ NonnullRefPtr<GUI::Window> build_process_window(pid_t pid)
}
auto& process_name_label = hero_container.add<GUI::Label>();
process_name_label.set_font(Gfx::FontDatabase::default_bold_font());
process_name_label.set_font(Gfx::FontDatabase::default_font().bold_variant());
process_name_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
process_name_label.set_text(String::formatted("{} (PID {})",
process_index.sibling_at_column(ProcessModel::Column::Name).data().to_string(),

View File

@ -147,7 +147,7 @@ void Canvas::draw()
painter.draw_rect({ 520, 410, 240, 80 }, Color::DarkGray);
painter.draw_text({ 520, 415, 240, 20 }, "Normal text", Gfx::FontDatabase::default_font(), Gfx::TextAlignment::CenterLeft, Color::Red);
painter.draw_text({ 520, 430, 240, 20 }, "Bold text", Gfx::FontDatabase::default_bold_font(), Gfx::TextAlignment::CenterLeft, Color::Green);
painter.draw_text({ 520, 430, 240, 20 }, "Bold text", Gfx::FontDatabase::default_font().bold_variant(), Gfx::TextAlignment::CenterLeft, Color::Green);
painter.draw_text({ 520, 450, 240, 20 }, "Normal text (fixed width)", Gfx::FontDatabase::default_fixed_width_font(), Gfx::TextAlignment::CenterLeft, Color::Blue);
painter.draw_text({ 520, 465, 240, 20 }, "Bold text (fixed width)", Gfx::FontDatabase::default_bold_fixed_width_font(), Gfx::TextAlignment::CenterLeft, Color::Yellow);

View File

@ -66,7 +66,8 @@ EditorWrapper::~EditorWrapper()
void EditorWrapper::set_editor_has_focus(Badge<Editor>, bool focus)
{
m_filename_label->set_font(focus ? Gfx::FontDatabase::default_bold_font() : Gfx::FontDatabase::default_font());
auto& font = Gfx::FontDatabase::default_font();
m_filename_label->set_font(focus ? font.bold_variant() : font);
}
LanguageClient& EditorWrapper::language_client() { return m_editor->language_client(); }

View File

@ -41,6 +41,8 @@ void ChessWidget::paint_event(GUI::PaintEvent& event)
Chess::Board& active_board = (m_playback ? board_playback() : board());
auto& coordinate_font = Gfx::FontDatabase::default_font().bold_variant();
Chess::Square::for_each([&](Chess::Square sq) {
Gfx::IntRect tile_rect;
if (side() == Chess::Color::White) {
@ -62,10 +64,10 @@ void ChessWidget::paint_event(GUI::PaintEvent& event)
auto shrunken_rect = tile_rect;
shrunken_rect.shrink(4, 4);
if (sq.rank == coord_rank_file)
painter.draw_text(shrunken_rect, coord.substring_view(0, 1), Gfx::FontDatabase::default_bold_font(), Gfx::TextAlignment::BottomRight, text_color);
painter.draw_text(shrunken_rect, coord.substring_view(0, 1), coordinate_font, Gfx::TextAlignment::BottomRight, text_color);
if (sq.file == coord_rank_file)
painter.draw_text(shrunken_rect, coord.substring_view(1, 1), Gfx::FontDatabase::default_bold_font(), Gfx::TextAlignment::TopLeft, text_color);
painter.draw_text(shrunken_rect, coord.substring_view(1, 1), coordinate_font, Gfx::TextAlignment::TopLeft, text_color);
}
for (auto& m : m_board_markings) {

View File

@ -88,7 +88,7 @@ Card::Card(Type type, uint8_t value)
}
Gfx::Painter painter(m_front);
auto& font = Gfx::FontDatabase::default_bold_font();
auto& font = Gfx::FontDatabase::default_font().bold_variant();
auto label = labels[value];
m_front->fill(Color::White);

View File

@ -63,7 +63,7 @@ AboutDialog::AboutDialog(const StringView& name, const Gfx::Bitmap* icon, Window
label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
label.set_fixed_height(14);
if (bold)
label.set_font(Gfx::FontDatabase::default_bold_font());
label.set_font(Gfx::FontDatabase::default_font().bold_variant());
};
make_label(m_name, true);
// If we are displaying a dialog for an application, insert 'SerenityOS' below the application name

View File

@ -75,7 +75,7 @@ void Button::paint_event(PaintEvent& event)
painter.blit_disabled(icon_location, *m_icon, m_icon->rect(), palette());
}
}
auto& font = is_checked() ? Gfx::FontDatabase::default_bold_font() : this->font();
auto& font = is_checked() ? this->font().bold_variant() : this->font();
if (m_icon && !text().is_empty()) {
content_rect.translate_by(m_icon->width() + icon_spacing(), 0);
content_rect.set_width(content_rect.width() - m_icon->width() - icon_spacing());

View File

@ -23,7 +23,7 @@ HeaderView::HeaderView(AbstractTableView& table_view, Gfx::Orientation orientati
: m_table_view(table_view)
, m_orientation(orientation)
{
set_font(Gfx::FontDatabase::default_bold_font());
set_font(Gfx::FontDatabase::default_font().bold_variant());
if (m_orientation == Gfx::Orientation::Horizontal) {
set_fixed_height(16);

View File

@ -28,12 +28,12 @@ WizardPage::WizardPage(const String& title_text, const String& subtitle_text)
header_widget.set_layout<VerticalBoxLayout>();
header_widget.layout()->set_margins({ 30, 15, 30, 0 });
m_title_label = header_widget.add<Label>(title_text);
m_title_label->set_font(Gfx::FontDatabase::the().default_bold_font());
m_title_label->set_fixed_height(Gfx::FontDatabase::the().default_bold_font().glyph_height() + 2);
m_title_label->set_font(Gfx::FontDatabase::default_font().bold_variant());
m_title_label->set_fixed_height(m_title_label->font().glyph_height() + 2);
m_title_label->set_text_alignment(Gfx::TextAlignment::TopLeft);
m_subtitle_label = header_widget.add<Label>(subtitle_text);
m_subtitle_label->set_text_alignment(Gfx::TextAlignment::TopLeft);
m_title_label->set_fixed_height(Gfx::FontDatabase::the().default_font().glyph_height());
m_subtitle_label->set_fixed_height(m_subtitle_label->font().glyph_height());
header_widget.layout()->add_spacer();
auto& separator = add<SeparatorWidget>(Gfx::Orientation::Horizontal);

View File

@ -58,13 +58,13 @@ void ClassicWindowTheme::paint_normal_frame(Painter& painter, WindowState window
frame_rect.set_location({ 0, 0 });
Gfx::StylePainter::paint_window_frame(painter, frame_rect, palette);
auto& title_font = FontDatabase::default_bold_font();
auto& title_font = FontDatabase::default_font().bold_variant();
auto titlebar_rect = this->titlebar_rect(WindowType::Normal, window_rect, palette);
auto titlebar_icon_rect = this->titlebar_icon_rect(WindowType::Normal, window_rect, palette);
auto titlebar_inner_rect = titlebar_text_rect(WindowType::Normal, window_rect, palette);
auto titlebar_title_rect = titlebar_inner_rect;
titlebar_title_rect.set_width(FontDatabase::default_bold_font().width(window_title));
titlebar_title_rect.set_width(title_font.width(window_title));
auto [title_color, border_color, border_color2, stripes_color, shadow_color] = compute_frame_colors(window_state, palette);
@ -100,12 +100,12 @@ void ClassicWindowTheme::paint_tool_window_frame(Painter& painter, WindowState w
frame_rect.set_location({ 0, 0 });
Gfx::StylePainter::paint_window_frame(painter, frame_rect, palette);
auto& title_font = FontDatabase::default_bold_font();
auto& title_font = FontDatabase::default_font().bold_variant();
auto titlebar_rect = this->titlebar_rect(WindowType::ToolWindow, window_rect, palette);
auto titlebar_inner_rect = titlebar_text_rect(WindowType::ToolWindow, window_rect, palette);
auto titlebar_title_rect = titlebar_inner_rect;
titlebar_title_rect.set_width(FontDatabase::default_bold_font().width(title_text));
titlebar_title_rect.set_width(title_font.width(title_text));
auto [title_color, border_color, border_color2, stripes_color, shadow_color] = compute_frame_colors(window_state, palette);
@ -134,7 +134,7 @@ IntRect ClassicWindowTheme::menubar_rect(WindowType window_type, const IntRect&
IntRect ClassicWindowTheme::titlebar_rect(WindowType window_type, const IntRect& window_rect, const Palette& palette) const
{
auto& title_font = FontDatabase::default_bold_font();
auto& title_font = FontDatabase::default_font().bold_variant();
auto window_titlebar_height = titlebar_height(window_type, palette);
// FIXME: The top of the titlebar doesn't get redrawn properly if this padding is different
int total_vertical_padding = title_font.glyph_height() - 1;
@ -235,7 +235,7 @@ Vector<IntRect> ClassicWindowTheme::layout_buttons(WindowType window_type, const
int ClassicWindowTheme::titlebar_height(WindowType window_type, const Palette& palette) const
{
auto& title_font = FontDatabase::default_bold_font();
auto& title_font = FontDatabase::default_font().bold_variant();
switch (window_type) {
case WindowType::Normal:
case WindowType::Notification:

View File

@ -54,16 +54,6 @@ Font& FontDatabase::default_bold_fixed_width_font()
return *font;
}
Font& FontDatabase::default_bold_font()
{
static Font* font;
if (!font) {
font = FontDatabase::the().get_by_name("Katica 10 700");
VERIFY(font);
}
return *font;
}
struct FontDatabase::Private {
HashMap<String, RefPtr<Gfx::Font>> full_name_to_font_map;
Vector<RefPtr<Typeface>> typefaces;

View File

@ -35,7 +35,6 @@ public:
static FontDatabase& the();
static Font& default_font();
static Font& default_bold_font();
static Font& default_fixed_width_font();
static Font& default_bold_fixed_width_font();

View File

@ -200,7 +200,7 @@ RefPtr<Gfx::Font> StyleProperties::font_fallback(bool monospace, bool bold) cons
return Gfx::FontDatabase::default_fixed_width_font();
if (bold)
return Gfx::FontDatabase::default_bold_font();
return Gfx::FontDatabase::default_font().bold_variant();
return Gfx::FontDatabase::default_font();
}

View File

@ -82,7 +82,7 @@ NotificationWindow::NotificationWindow(i32 client_id, const String& text, const
left_container.set_layout<GUI::VerticalBoxLayout>();
m_title_label = &left_container.add<GUI::Label>(title);
m_title_label->set_font(Gfx::FontDatabase::default_bold_font());
m_title_label->set_font(Gfx::FontDatabase::default_font().bold_variant());
m_title_label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
m_text_label = &left_container.add<GUI::Label>(text);
m_text_label->set_text_alignment(Gfx::TextAlignment::CenterLeft);

View File

@ -72,7 +72,7 @@ ShutdownDialog::ShutdownDialog()
auto& label = right_container.add<GUI::Label>("What would you like to do?");
label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
label.set_fixed_height(22);
label.set_font(Gfx::FontDatabase::default_bold_font());
label.set_font(Gfx::FontDatabase::default_font().bold_variant());
for (size_t i = 0; i < options.size(); i++) {
auto action = options[i];

View File

@ -89,7 +89,7 @@ void TaskbarButton::paint_event(GUI::PaintEvent& event)
{
VERIFY(icon());
auto& icon = *this->icon();
auto& font = is_checked() ? Gfx::FontDatabase::default_bold_font() : this->font();
auto& font = is_checked() ? this->font().bold_variant() : this->font();
auto& window = WindowList::the().ensure_window(m_identifier);
GUI::Painter painter(*this);

View File

@ -65,7 +65,7 @@ TaskbarWindow::TaskbarWindow(NonnullRefPtr<GUI::Menu> start_menu)
main_widget.layout()->set_margins({ 3, 3, 3, 1 });
m_start_button = GUI::Button::construct("Serenity");
m_start_button->set_font(Gfx::FontDatabase::default_bold_font());
m_start_button->set_font(Gfx::FontDatabase::default_font().bold_variant());
m_start_button->set_icon_spacing(0);
m_start_button->set_fixed_size(80, 21);
auto app_icon = GUI::Icon::default_icon("ladyball");

View File

@ -94,7 +94,7 @@ int Menu::content_width() const
for (auto& item : m_items) {
if (item.type() != MenuItem::Text)
continue;
auto& use_font = item.is_default() ? Gfx::FontDatabase::default_bold_font() : font();
auto& use_font = item.is_default() ? font().bold_variant() : font();
int text_width = use_font.width(Gfx::parse_ampersand_string(item.text()));
if (!item.shortcut_text().is_empty()) {
int shortcut_width = use_font.width(item.shortcut_text());
@ -245,7 +245,7 @@ void Menu::draw()
}
auto& previous_font = painter.font();
if (item.is_default())
painter.set_font(Gfx::FontDatabase::default_bold_font());
painter.set_font(previous_font.bold_variant());
painter.draw_ui_text(text_rect, item.text(), painter.font(), Gfx::TextAlignment::CenterLeft, text_color);
if (!item.shortcut_text().is_empty()) {
painter.draw_text(item.rect().translated(-right_padding(), 0), item.shortcut_text(), Gfx::TextAlignment::CenterRight, text_color);

View File

@ -99,7 +99,7 @@ const Gfx::Font& WindowManager::font() const
const Gfx::Font& WindowManager::window_title_font() const
{
return Gfx::FontDatabase::default_bold_font();
return Gfx::FontDatabase::default_font().bold_variant();
}
bool WindowManager::set_resolution(int width, int height, int scale)