From 6a012ad79f95673a36531c27c81e0efa6c6ec664 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 20 May 2021 18:40:48 +0200 Subject: [PATCH] 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. :^) --- Tests/LibGfx/TestFontHandling.cpp | 5 ----- Userland/Applications/Calendar/AddEventDialog.cpp | 2 +- Userland/Applications/HexEditor/HexEditor.cpp | 2 +- .../Applications/SystemMonitor/MemoryStatsWidget.cpp | 2 +- .../SystemMonitor/ProcessStateWidget.cpp | 2 +- Userland/Applications/SystemMonitor/main.cpp | 2 +- Userland/Demos/LibGfxDemo/main.cpp | 2 +- Userland/DevTools/HackStudio/EditorWrapper.cpp | 3 ++- Userland/Games/Chess/ChessWidget.cpp | 6 ++++-- Userland/Games/Solitaire/Card.cpp | 2 +- Userland/Libraries/LibGUI/AboutDialog.cpp | 2 +- Userland/Libraries/LibGUI/Button.cpp | 2 +- Userland/Libraries/LibGUI/HeaderView.cpp | 2 +- Userland/Libraries/LibGUI/Wizards/WizardPage.cpp | 6 +++--- Userland/Libraries/LibGfx/ClassicWindowTheme.cpp | 12 ++++++------ Userland/Libraries/LibGfx/FontDatabase.cpp | 10 ---------- Userland/Libraries/LibGfx/FontDatabase.h | 1 - Userland/Libraries/LibWeb/CSS/StyleProperties.cpp | 2 +- .../NotificationServer/NotificationWindow.cpp | 2 +- Userland/Services/Taskbar/ShutdownDialog.cpp | 2 +- Userland/Services/Taskbar/TaskbarButton.cpp | 2 +- Userland/Services/Taskbar/TaskbarWindow.cpp | 2 +- Userland/Services/WindowServer/Menu.cpp | 4 ++-- Userland/Services/WindowServer/WindowManager.cpp | 2 +- 24 files changed, 33 insertions(+), 46 deletions(-) diff --git a/Tests/LibGfx/TestFontHandling.cpp b/Tests/LibGfx/TestFontHandling.cpp index 82e209bce0b..b2c1e087e4f 100644 --- a/Tests/LibGfx/TestFontHandling.cpp +++ b/Tests/LibGfx/TestFontHandling.cpp @@ -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; diff --git a/Userland/Applications/Calendar/AddEventDialog.cpp b/Userland/Applications/Calendar/AddEventDialog.cpp index 0aa92a81402..9f972ea2910 100644 --- a/Userland/Applications/Calendar/AddEventDialog.cpp +++ b/Userland/Applications/Calendar/AddEventDialog.cpp @@ -46,7 +46,7 @@ AddEventDialog::AddEventDialog(Core::DateTime date_time, Window* parent_window) auto& add_label = top_container.add("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(); event_title_textbox.set_fixed_height(20); diff --git a/Userland/Applications/HexEditor/HexEditor.cpp b/Userland/Applications/HexEditor/HexEditor.cpp index bc57d5b4b68..bf0dab37386 100644 --- a/Userland/Applications/HexEditor/HexEditor.cpp +++ b/Userland/Applications/HexEditor/HexEditor.cpp @@ -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()); } diff --git a/Userland/Applications/SystemMonitor/MemoryStatsWidget.cpp b/Userland/Applications/SystemMonitor/MemoryStatsWidget.cpp index 70266c8925c..8b66213a7c6 100644 --- a/Userland/Applications/SystemMonitor/MemoryStatsWidget.cpp +++ b/Userland/Applications/SystemMonitor/MemoryStatsWidget.cpp @@ -42,7 +42,7 @@ MemoryStatsWidget::MemoryStatsWidget(GraphWidget& graph) container.set_layout(); container.set_fixed_size(275, 12); auto& description_label = container.add(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(); label.set_text_alignment(Gfx::TextAlignment::CenterRight); diff --git a/Userland/Applications/SystemMonitor/ProcessStateWidget.cpp b/Userland/Applications/SystemMonitor/ProcessStateWidget.cpp index 9b17340f656..2ff01db2bad 100644 --- a/Userland/Applications/SystemMonitor/ProcessStateWidget.cpp +++ b/Userland/Applications/SystemMonitor/ProcessStateWidget.cpp @@ -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(); } } diff --git a/Userland/Applications/SystemMonitor/main.cpp b/Userland/Applications/SystemMonitor/main.cpp index 4220c0aa8e3..58bfa8fd211 100644 --- a/Userland/Applications/SystemMonitor/main.cpp +++ b/Userland/Applications/SystemMonitor/main.cpp @@ -456,7 +456,7 @@ NonnullRefPtr build_process_window(pid_t pid) } auto& process_name_label = hero_container.add(); - 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(), diff --git a/Userland/Demos/LibGfxDemo/main.cpp b/Userland/Demos/LibGfxDemo/main.cpp index 30dcefcb59a..a0421adecef 100644 --- a/Userland/Demos/LibGfxDemo/main.cpp +++ b/Userland/Demos/LibGfxDemo/main.cpp @@ -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); diff --git a/Userland/DevTools/HackStudio/EditorWrapper.cpp b/Userland/DevTools/HackStudio/EditorWrapper.cpp index 128eff2ca1f..26ff288ec8b 100644 --- a/Userland/DevTools/HackStudio/EditorWrapper.cpp +++ b/Userland/DevTools/HackStudio/EditorWrapper.cpp @@ -66,7 +66,8 @@ EditorWrapper::~EditorWrapper() void EditorWrapper::set_editor_has_focus(Badge, 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(); } diff --git a/Userland/Games/Chess/ChessWidget.cpp b/Userland/Games/Chess/ChessWidget.cpp index 92921bb6bed..db1e05fb56a 100644 --- a/Userland/Games/Chess/ChessWidget.cpp +++ b/Userland/Games/Chess/ChessWidget.cpp @@ -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) { diff --git a/Userland/Games/Solitaire/Card.cpp b/Userland/Games/Solitaire/Card.cpp index 20e79c128e0..122abd6c143 100644 --- a/Userland/Games/Solitaire/Card.cpp +++ b/Userland/Games/Solitaire/Card.cpp @@ -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); diff --git a/Userland/Libraries/LibGUI/AboutDialog.cpp b/Userland/Libraries/LibGUI/AboutDialog.cpp index fcac58c0451..f0118e667d8 100644 --- a/Userland/Libraries/LibGUI/AboutDialog.cpp +++ b/Userland/Libraries/LibGUI/AboutDialog.cpp @@ -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 diff --git a/Userland/Libraries/LibGUI/Button.cpp b/Userland/Libraries/LibGUI/Button.cpp index 7b7aa662c43..107eaccbe5d 100644 --- a/Userland/Libraries/LibGUI/Button.cpp +++ b/Userland/Libraries/LibGUI/Button.cpp @@ -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()); diff --git a/Userland/Libraries/LibGUI/HeaderView.cpp b/Userland/Libraries/LibGUI/HeaderView.cpp index cb9fe2d2020..db0f704bee7 100644 --- a/Userland/Libraries/LibGUI/HeaderView.cpp +++ b/Userland/Libraries/LibGUI/HeaderView.cpp @@ -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); diff --git a/Userland/Libraries/LibGUI/Wizards/WizardPage.cpp b/Userland/Libraries/LibGUI/Wizards/WizardPage.cpp index 7ea3be7c70d..5ab950bf83e 100644 --- a/Userland/Libraries/LibGUI/Wizards/WizardPage.cpp +++ b/Userland/Libraries/LibGUI/Wizards/WizardPage.cpp @@ -28,12 +28,12 @@ WizardPage::WizardPage(const String& title_text, const String& subtitle_text) header_widget.set_layout(); header_widget.layout()->set_margins({ 30, 15, 30, 0 }); m_title_label = header_widget.add