1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 08:27:46 +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:
Stephan Unverwerth 2020-12-29 18:25:13 +01:00 committed by Andreas Kling
parent 1a072a61fb
commit b4d1390714
48 changed files with 152 additions and 115 deletions

View file

@ -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);
}

View file

@ -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();

View file

@ -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);

View file

@ -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;
};

View file

@ -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&)>);

View file

@ -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;
}