diff --git a/Userland/Libraries/LibCore/Object.h b/Userland/Libraries/LibCore/Object.h index c3b105aa54..105ca91260 100644 --- a/Userland/Libraries/LibCore/Object.h +++ b/Userland/Libraries/LibCore/Object.h @@ -347,4 +347,18 @@ T* Object::find_descendant_of_type_named(const String& name) requires IsBaseOffamily, set_font_family); + REGISTER_INT_PROPERTY("font_size", m_font->presentation_size, set_font_size); + REGISTER_FONT_WEIGHT_PROPERTY("font_weight", m_font->weight, set_font_weight); + + register_property( + "font_type", [this] { return m_font->is_fixed_width() ? "FixedWidth" : "Normal"; }, + [this](auto& value) { + if (value.to_string() == "FixedWidth") { + set_font_fixed_width(true); + return true; + } + if (value.to_string() == "Normal") { + set_font_fixed_width(false); + return true; + } + return false; + }); + register_property( "focus_policy", [this]() -> JsonValue { auto policy = focus_policy(); @@ -684,6 +702,29 @@ void Widget::set_font(const Gfx::Font* font) update(); } +void Widget::set_font_family(const String& family) +{ + set_font(Gfx::FontDatabase::the().get(family, m_font->presentation_size(), m_font->weight())); +} + +void Widget::set_font_size(unsigned size) +{ + set_font(Gfx::FontDatabase::the().get(m_font->family(), size, m_font->weight())); +} + +void Widget::set_font_weight(unsigned weight) +{ + set_font(Gfx::FontDatabase::the().get(m_font->family(), m_font->presentation_size(), weight)); +} + +void Widget::set_font_fixed_width(bool fixed_width) +{ + if (fixed_width) + set_font(Gfx::FontDatabase::the().get(Gfx::FontDatabase::the().default_fixed_width_font().family(), m_font->presentation_size(), m_font->weight())); + else + set_font(Gfx::FontDatabase::the().get(Gfx::FontDatabase::the().default_font().family(), m_font->presentation_size(), m_font->weight())); +} + void Widget::set_global_cursor_tracking(bool enabled) { auto* win = window(); diff --git a/Userland/Libraries/LibGUI/Widget.h b/Userland/Libraries/LibGUI/Widget.h index 9528dab9af..f9829a1843 100644 --- a/Userland/Libraries/LibGUI/Widget.h +++ b/Userland/Libraries/LibGUI/Widget.h @@ -239,9 +239,15 @@ public: bool fill_with_background_color() const { return m_fill_with_background_color; } const Gfx::Font& font() const { return *m_font; } + void set_font(const Gfx::Font*); void set_font(const Gfx::Font& font) { set_font(&font); } + void set_font_family(const String&); + void set_font_size(unsigned); + void set_font_weight(unsigned); + void set_font_fixed_width(bool); + void set_global_cursor_tracking(bool); bool global_cursor_tracking() const; diff --git a/Userland/Libraries/LibGfx/FontDatabase.h b/Userland/Libraries/LibGfx/FontDatabase.h index 4fb77b1d49..96d0519ae6 100644 --- a/Userland/Libraries/LibGfx/FontDatabase.h +++ b/Userland/Libraries/LibGfx/FontDatabase.h @@ -34,6 +34,21 @@ namespace Gfx { +namespace FontWeight { +enum { + Thin = 100, + ExtraLight = 200, + Light = 300, + Regular = 400, + Medium = 500, + SemiBold = 600, + Bold = 700, + ExtraBold = 800, + Black = 900, + ExtraBlack = 950 +}; +} + class FontDatabase { public: static FontDatabase& the();