mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:07:35 +00:00
LibGFX: Move default_xxx_font() methods from Font to FontDatabase
When we have an abstract font class it makes no sense to keep these methods in the Font class.
This commit is contained in:
parent
1a072a61fb
commit
b4d1390714
48 changed files with 152 additions and 115 deletions
|
@ -33,6 +33,7 @@
|
|||
#include <LibGUI/Label.h>
|
||||
#include <LibGUI/Widget.h>
|
||||
#include <LibGfx/Font.h>
|
||||
#include <LibGfx/FontDatabase.h>
|
||||
|
||||
namespace GUI {
|
||||
|
||||
|
@ -82,7 +83,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::Font::default_bold_font());
|
||||
label.set_font(Gfx::FontDatabase::default_bold_font());
|
||||
};
|
||||
make_label(m_name, true);
|
||||
// If we are displaying a dialog for an application, insert 'SerenityOS' below the application name
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <LibGUI/Button.h>
|
||||
#include <LibGUI/Painter.h>
|
||||
#include <LibGfx/Font.h>
|
||||
#include <LibGfx/FontDatabase.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
#include <LibGfx/StylePainter.h>
|
||||
|
||||
|
@ -89,7 +90,7 @@ void Button::paint_event(PaintEvent& event)
|
|||
painter.blit_disabled(icon_location, *m_icon, m_icon->rect(), palette());
|
||||
}
|
||||
}
|
||||
auto& font = is_checked() ? Gfx::Font::default_bold_font() : this->font();
|
||||
auto& font = is_checked() ? Gfx::FontDatabase::default_bold_font() : this->font();
|
||||
if (m_icon && !text().is_empty()) {
|
||||
content_rect.move_by(m_icon->width() + 4, 0);
|
||||
content_rect.set_width(content_rect.width() - m_icon->width() - 4);
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <LibGUI/Painter.h>
|
||||
#include <LibGUI/Window.h>
|
||||
#include <LibGfx/Font.h>
|
||||
#include <LibGfx/FontDatabase.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
|
||||
namespace GUI {
|
||||
|
@ -72,7 +73,7 @@ Calendar::Calendar(Core::DateTime date_time)
|
|||
m_day_name_container->set_background_role(Gfx::ColorRole::HoverHighlight);
|
||||
for (auto& day : m_day_names) {
|
||||
day = m_day_name_container->add<GUI::Label>();
|
||||
day->set_font(Gfx::Font::default_bold_font());
|
||||
day->set_font(Gfx::FontDatabase::default_bold_font());
|
||||
}
|
||||
|
||||
m_calendar_tile_container = add<GUI::Widget>();
|
||||
|
@ -357,13 +358,13 @@ void Calendar::CalendarTile::paint_event(GUI::PaintEvent& event)
|
|||
} else if (is_selected()) {
|
||||
painter.draw_rect(frame_inner_rect(), palette().base_text());
|
||||
}
|
||||
painter.draw_text(day_rect, display_date, Gfx::Font::default_bold_font(), Gfx::TextAlignment::Center, palette().base_text());
|
||||
painter.draw_text(day_rect, display_date, Gfx::FontDatabase::default_bold_font(), Gfx::TextAlignment::Center, palette().base_text());
|
||||
} else if (is_outside_selection()) {
|
||||
painter.draw_text(day_rect, display_date, Gfx::Font::default_font(), Gfx::TextAlignment::Center, Color::LightGray);
|
||||
painter.draw_text(day_rect, display_date, Gfx::FontDatabase::default_font(), Gfx::TextAlignment::Center, Color::LightGray);
|
||||
} else {
|
||||
if (!has_grid() && is_selected())
|
||||
painter.draw_rect(frame_inner_rect(), palette().base_text());
|
||||
painter.draw_text(day_rect, display_date, Gfx::Font::default_font(), Gfx::TextAlignment::Center, palette().base_text());
|
||||
painter.draw_text(day_rect, display_date, Gfx::FontDatabase::default_font(), Gfx::TextAlignment::Center, palette().base_text());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include <LibGUI/SortingProxyModel.h>
|
||||
#include <LibGUI/TextBox.h>
|
||||
#include <LibGUI/ToolBar.h>
|
||||
#include <LibGfx/FontDatabase.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace GUI {
|
||||
|
@ -253,7 +254,7 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, Options options, const
|
|||
m_preview_image->set_fixed_size(160, 160);
|
||||
|
||||
m_preview_name_label = m_preview_container->add<Label>();
|
||||
m_preview_name_label->set_font(Gfx::Font::default_bold_font());
|
||||
m_preview_name_label->set_font(Gfx::FontDatabase::default_bold_font());
|
||||
m_preview_name_label->set_fixed_height(m_preview_name_label->font().glyph_height());
|
||||
|
||||
m_preview_geometry_label = m_preview_container->add<Label>();
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <LibGUI/Model.h>
|
||||
#include <LibGUI/Painter.h>
|
||||
#include <LibGUI/Window.h>
|
||||
#include <LibGfx/FontDatabase.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
#include <LibGfx/StylePainter.h>
|
||||
|
||||
|
@ -42,7 +43,7 @@ HeaderView::HeaderView(AbstractTableView& table_view, Gfx::Orientation orientati
|
|||
: m_table_view(table_view)
|
||||
, m_orientation(orientation)
|
||||
{
|
||||
set_font(Gfx::Font::default_bold_font());
|
||||
set_font(Gfx::FontDatabase::default_bold_font());
|
||||
|
||||
if (m_orientation == Gfx::Orientation::Horizontal) {
|
||||
set_fixed_height(16);
|
||||
|
|
|
@ -72,7 +72,7 @@ TextEditor::TextEditor(Type type)
|
|||
set_visualize_trailing_whitespace(false);
|
||||
set_scrollbars_enabled(is_multi_line());
|
||||
if (is_multi_line())
|
||||
set_font(Gfx::Font::default_fixed_width_font());
|
||||
set_font(Gfx::FontDatabase::default_fixed_width_font());
|
||||
vertical_scrollbar().set_step(line_height());
|
||||
m_cursor = { 0, 0 };
|
||||
m_automatic_selection_scroll_timer = add<Core::Timer>(100, [this] {
|
||||
|
|
|
@ -61,6 +61,7 @@
|
|||
#include <LibGUI/WindowServerConnection.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibGfx/Font.h>
|
||||
#include <LibGfx/FontDatabase.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -127,7 +128,7 @@ Widget::Widget()
|
|||
: Core::Object(nullptr, true)
|
||||
, m_background_role(Gfx::ColorRole::Window)
|
||||
, m_foreground_role(Gfx::ColorRole::WindowText)
|
||||
, m_font(Gfx::Font::default_font())
|
||||
, m_font(Gfx::FontDatabase::default_font())
|
||||
, m_palette(Application::the()->palette().impl())
|
||||
{
|
||||
REGISTER_RECT_PROPERTY("relative_rect", relative_rect, set_relative_rect);
|
||||
|
@ -645,7 +646,7 @@ void Widget::set_font(const Gfx::Font* font)
|
|||
return;
|
||||
|
||||
if (!font)
|
||||
m_font = Gfx::Font::default_font();
|
||||
m_font = Gfx::FontDatabase::default_font();
|
||||
else
|
||||
m_font = *font;
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibGfx/ClassicWindowTheme.h>
|
||||
#include <LibGfx/Font.h>
|
||||
#include <LibGfx/FontDatabase.h>
|
||||
#include <LibGfx/Painter.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
#include <LibGfx/StylePainter.h>
|
||||
|
@ -73,13 +74,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 = Font::default_bold_font();
|
||||
auto& title_font = FontDatabase::default_bold_font();
|
||||
|
||||
auto titlebar_rect = title_bar_rect(WindowType::Normal, window_rect, palette);
|
||||
auto titlebar_icon_rect = title_bar_icon_rect(WindowType::Normal, window_rect, palette);
|
||||
auto titlebar_inner_rect = title_bar_text_rect(WindowType::Normal, window_rect, palette);
|
||||
auto titlebar_title_rect = titlebar_inner_rect;
|
||||
titlebar_title_rect.set_width(Font::default_bold_font().width(title_text));
|
||||
titlebar_title_rect.set_width(FontDatabase::default_bold_font().width(title_text));
|
||||
|
||||
auto [title_color, border_color, border_color2, stripes_color, shadow_color] = compute_frame_colors(window_state, palette);
|
||||
|
||||
|
@ -109,7 +110,7 @@ void ClassicWindowTheme::paint_normal_frame(Painter& painter, WindowState window
|
|||
|
||||
IntRect ClassicWindowTheme::title_bar_rect(WindowType window_type, const IntRect& window_rect, const Palette& palette) const
|
||||
{
|
||||
auto& title_font = Font::default_bold_font();
|
||||
auto& title_font = FontDatabase::default_bold_font();
|
||||
auto window_titlebar_height = title_bar_height(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;
|
||||
|
@ -207,7 +208,7 @@ Vector<IntRect> ClassicWindowTheme::layout_buttons(WindowType window_type, const
|
|||
|
||||
int ClassicWindowTheme::title_bar_height(const Palette& palette) const
|
||||
{
|
||||
auto& title_font = Font::default_bold_font();
|
||||
auto& title_font = FontDatabase::default_bold_font();
|
||||
return max(palette.window_title_height(), title_font.glyph_height() + 8);
|
||||
}
|
||||
|
||||
|
|
|
@ -60,46 +60,6 @@ struct [[gnu::packed]] FontFileHeader
|
|||
char family[32];
|
||||
};
|
||||
|
||||
Font& Font::default_font()
|
||||
{
|
||||
static Font* font;
|
||||
if (!font) {
|
||||
font = FontDatabase::the().get_by_name("Katica 10 400");
|
||||
ASSERT(font);
|
||||
}
|
||||
return *font;
|
||||
}
|
||||
|
||||
Font& Font::default_fixed_width_font()
|
||||
{
|
||||
static Font* font;
|
||||
if (!font) {
|
||||
font = FontDatabase::the().get_by_name("Csilla 10 400");
|
||||
ASSERT(font);
|
||||
}
|
||||
return *font;
|
||||
}
|
||||
|
||||
Font& Font::default_bold_fixed_width_font()
|
||||
{
|
||||
static Font* font;
|
||||
if (!font) {
|
||||
font = FontDatabase::the().get_by_name("Csilla 10 700");
|
||||
ASSERT(font);
|
||||
}
|
||||
return *font;
|
||||
}
|
||||
|
||||
Font& Font::default_bold_font()
|
||||
{
|
||||
static Font* font;
|
||||
if (!font) {
|
||||
font = FontDatabase::the().get_by_name("Katica 10 700");
|
||||
ASSERT(font);
|
||||
}
|
||||
return *font;
|
||||
}
|
||||
|
||||
NonnullRefPtr<Font> Font::clone() const
|
||||
{
|
||||
size_t bytes_per_glyph = sizeof(u32) * glyph_height();
|
||||
|
|
|
@ -75,12 +75,6 @@ private:
|
|||
|
||||
class Font : public RefCounted<Font> {
|
||||
public:
|
||||
static Font& default_font();
|
||||
static Font& default_bold_font();
|
||||
|
||||
static Font& default_fixed_width_font();
|
||||
static Font& default_bold_fixed_width_font();
|
||||
|
||||
NonnullRefPtr<Font> clone() const;
|
||||
static NonnullRefPtr<Font> create(u8 glyph_height, u8 glyph_width, bool fixed, FontTypes type);
|
||||
|
||||
|
|
|
@ -44,6 +44,46 @@ FontDatabase& FontDatabase::the()
|
|||
return *s_the;
|
||||
}
|
||||
|
||||
Font& FontDatabase::default_font()
|
||||
{
|
||||
static Font* font;
|
||||
if (!font) {
|
||||
font = FontDatabase::the().get_by_name("Katica 10 400");
|
||||
ASSERT(font);
|
||||
}
|
||||
return *font;
|
||||
}
|
||||
|
||||
Font& FontDatabase::default_fixed_width_font()
|
||||
{
|
||||
static Font* font;
|
||||
if (!font) {
|
||||
font = FontDatabase::the().get_by_name("Csilla 10 400");
|
||||
ASSERT(font);
|
||||
}
|
||||
return *font;
|
||||
}
|
||||
|
||||
Font& FontDatabase::default_bold_fixed_width_font()
|
||||
{
|
||||
static Font* font;
|
||||
if (!font) {
|
||||
font = FontDatabase::the().get_by_name("Csilla 10 700");
|
||||
ASSERT(font);
|
||||
}
|
||||
return *font;
|
||||
}
|
||||
|
||||
Font& FontDatabase::default_bold_font()
|
||||
{
|
||||
static Font* font;
|
||||
if (!font) {
|
||||
font = FontDatabase::the().get_by_name("Katica 10 700");
|
||||
ASSERT(font);
|
||||
}
|
||||
return *font;
|
||||
}
|
||||
|
||||
struct FontDatabase::Private {
|
||||
HashMap<String, RefPtr<Gfx::Font>> full_name_to_font_map;
|
||||
};
|
||||
|
|
|
@ -37,6 +37,12 @@ class FontDatabase {
|
|||
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();
|
||||
|
||||
RefPtr<Gfx::Font> get(const String& family, unsigned size, unsigned weight);
|
||||
RefPtr<Gfx::Font> get_by_name(const StringView&);
|
||||
void for_each_font(Function<void(const Gfx::Font&)>);
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "Bitmap.h"
|
||||
#include "Emoji.h"
|
||||
#include "Font.h"
|
||||
#include "FontDatabase.h"
|
||||
#include "Gamma.h"
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/Function.h>
|
||||
|
@ -72,7 +73,7 @@ Painter::Painter(Gfx::Bitmap& bitmap)
|
|||
{
|
||||
ASSERT(bitmap.format() == Gfx::BitmapFormat::RGB32 || bitmap.format() == Gfx::BitmapFormat::RGBA32);
|
||||
m_state_stack.append(State());
|
||||
state().font = &Font::default_font();
|
||||
state().font = &FontDatabase::default_font();
|
||||
state().clip_rect = { { 0, 0 }, bitmap.size() };
|
||||
m_clip_origin = state().clip_rect;
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ TerminalWidget::TerminalWidget(int ptm_fd, bool automatic_size_policy, RefPtr<Co
|
|||
|
||||
auto font_entry = m_config->read_entry("Text", "Font", "default");
|
||||
if (font_entry == "default")
|
||||
set_font(Gfx::Font::default_fixed_width_font());
|
||||
set_font(Gfx::FontDatabase::default_fixed_width_font());
|
||||
else
|
||||
set_font(Gfx::FontDatabase::the().get_by_name(font_entry));
|
||||
|
||||
|
@ -1022,7 +1022,7 @@ void TerminalWidget::did_change_font()
|
|||
m_line_height = font().glyph_height() + m_line_spacing;
|
||||
|
||||
// TODO: try to find a bold version of the new font (e.g. CsillaThin7x10 -> CsillaBold7x10)
|
||||
const Gfx::Font& bold_font = Gfx::Font::default_bold_fixed_width_font();
|
||||
const Gfx::Font& bold_font = Gfx::FontDatabase::default_bold_fixed_width_font();
|
||||
|
||||
if (bold_font.glyph_height() == font().glyph_height() && bold_font.glyph_width(' ') == font().glyph_width(' '))
|
||||
m_bold_font = &bold_font;
|
||||
|
|
|
@ -202,7 +202,7 @@ void StyleProperties::load_font() const
|
|||
|
||||
if (!found_font) {
|
||||
dbgln("Font not found: '{}' {} {}", family, size, weight);
|
||||
found_font = Gfx::Font::default_font();
|
||||
found_font = Gfx::FontDatabase::default_font();
|
||||
}
|
||||
|
||||
m_font = found_font;
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include <LibGUI/Button.h>
|
||||
#include <LibGUI/TextBox.h>
|
||||
#include <LibGfx/FontDatabase.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Event.h>
|
||||
#include <LibWeb/HTML/EventNames.h>
|
||||
|
@ -86,12 +87,12 @@ RefPtr<Layout::Node> HTMLInputElement::create_layout_node(const CSS::StyleProper
|
|||
auto& widget = downcast<Layout::WidgetBox>(layout_node())->widget();
|
||||
const_cast<HTMLInputElement*>(this)->set_attribute(HTML::AttributeNames::value, static_cast<const GUI::TextBox&>(widget).text());
|
||||
};
|
||||
int text_width = Gfx::Font::default_font().width(value());
|
||||
int text_width = Gfx::FontDatabase::default_font().width(value());
|
||||
auto size_value = attribute(HTML::AttributeNames::size);
|
||||
if (!size_value.is_null()) {
|
||||
auto size = size_value.to_uint();
|
||||
if (size.has_value())
|
||||
text_width = Gfx::Font::default_font().glyph_width('x') * size.value();
|
||||
text_width = Gfx::FontDatabase::default_font().glyph_width('x') * size.value();
|
||||
}
|
||||
text_box.set_relative_rect(0, 0, text_width + 20, 20);
|
||||
return adopt(*new Layout::WidgetBox(document(), *this, text_box));
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include <LibGUI/Painter.h>
|
||||
#include <LibGfx/Font.h>
|
||||
#include <LibGfx/FontDatabase.h>
|
||||
#include <LibGfx/ImageDecoder.h>
|
||||
#include <LibGfx/StylePainter.h>
|
||||
#include <LibWeb/Layout/ImageBox.h>
|
||||
|
@ -79,7 +80,7 @@ void ImageBox::prepare_for_replaced_layout()
|
|||
|
||||
if (renders_as_alt_text()) {
|
||||
auto& image_element = downcast<HTML::HTMLImageElement>(dom_node());
|
||||
auto& font = Gfx::Font::default_font();
|
||||
auto& font = Gfx::FontDatabase::default_font();
|
||||
auto alt = image_element.alt();
|
||||
if (alt.is_empty())
|
||||
alt = image_element.src();
|
||||
|
@ -107,7 +108,7 @@ void ImageBox::paint(PaintContext& context, PaintPhase phase)
|
|||
if (phase == PaintPhase::Foreground) {
|
||||
if (renders_as_alt_text()) {
|
||||
auto& image_element = downcast<HTML::HTMLImageElement>(dom_node());
|
||||
context.painter().set_font(Gfx::Font::default_font());
|
||||
context.painter().set_font(Gfx::FontDatabase::default_font());
|
||||
Gfx::StylePainter::paint_frame(context.painter(), enclosing_int_rect(absolute_rect()), context.palette(), Gfx::FrameShape::Container, Gfx::FrameShadow::Sunken, 2);
|
||||
auto alt = image_element.alt();
|
||||
if (alt.is_empty())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue