diff options
author | thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> | 2022-01-31 20:54:27 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-01 10:06:26 +0100 |
commit | a593b8318997a872b9a45bc61c1372bd39bba424 (patch) | |
tree | 95cc544a6866a148fdfbc2e3d21bfcbab2943511 /Userland | |
parent | 96895cd22c06cfa82c5cc2c03b091bd855e16e3b (diff) | |
download | serenity-a593b8318997a872b9a45bc61c1372bd39bba424.zip |
LibGfx+Applications: Add human readable name helper for fonts
This returns a more comprehensible name than raw weight and slope
metrics and is intended for use in UIs. Now displays human readable
font names in FontSettings, TerminalSettings and CharacterMap.
Diffstat (limited to 'Userland')
8 files changed, 14 insertions, 10 deletions
diff --git a/Userland/Applications/CharacterMap/CharacterMapWidget.cpp b/Userland/Applications/CharacterMap/CharacterMapWidget.cpp index 803fdeb781..6bc5df218b 100644 --- a/Userland/Applications/CharacterMap/CharacterMapWidget.cpp +++ b/Userland/Applications/CharacterMap/CharacterMapWidget.cpp @@ -144,7 +144,7 @@ void CharacterMapWidget::initialize_menubar(GUI::Window& window) void CharacterMapWidget::did_change_font() { m_glyph_map->set_font(font()); - m_font_name_label->set_text(font().qualified_name()); + m_font_name_label->set_text(font().human_readable_name()); m_output_box->set_font(font()); } diff --git a/Userland/Applications/DisplaySettings/FontSettings.gml b/Userland/Applications/DisplaySettings/FontSettings.gml index dadda2e083..279012364e 100644 --- a/Userland/Applications/DisplaySettings/FontSettings.gml +++ b/Userland/Applications/DisplaySettings/FontSettings.gml @@ -28,7 +28,6 @@ @GUI::Label { name: "default_font_label" - text: "Katica 10 400" } } @@ -61,7 +60,6 @@ @GUI::Label { name: "fixed_width_font_label" - text: "Csilla 10 400" } } diff --git a/Userland/Applications/DisplaySettings/FontSettingsWidget.cpp b/Userland/Applications/DisplaySettings/FontSettingsWidget.cpp index 5f4898e909..9b07151ba7 100644 --- a/Userland/Applications/DisplaySettings/FontSettingsWidget.cpp +++ b/Userland/Applications/DisplaySettings/FontSettingsWidget.cpp @@ -51,13 +51,13 @@ FontSettingsWidget::~FontSettingsWidget() static void update_label_with_font(GUI::Label& label, Gfx::Font const& font) { - label.set_text(font.qualified_name()); + label.set_text(font.human_readable_name()); label.set_font(font); } void FontSettingsWidget::apply_settings() { - GUI::WindowServerConnection::the().set_system_fonts(m_default_font_label->text(), m_fixed_width_font_label->text()); + GUI::WindowServerConnection::the().set_system_fonts(m_default_font_label->font().qualified_name(), m_fixed_width_font_label->font().qualified_name()); } } diff --git a/Userland/Applications/TerminalSettings/TerminalSettingsView.gml b/Userland/Applications/TerminalSettings/TerminalSettingsView.gml index 39dd69e061..a6140d4245 100644 --- a/Userland/Applications/TerminalSettings/TerminalSettingsView.gml +++ b/Userland/Applications/TerminalSettings/TerminalSettingsView.gml @@ -54,7 +54,6 @@ @GUI::Label { name: "terminal_font_label" - text: "Csilla 10 400" } } diff --git a/Userland/Applications/TerminalSettings/TerminalSettingsWidget.cpp b/Userland/Applications/TerminalSettings/TerminalSettingsWidget.cpp index 0399efe935..f961c8987a 100644 --- a/Userland/Applications/TerminalSettings/TerminalSettingsWidget.cpp +++ b/Userland/Applications/TerminalSettings/TerminalSettingsWidget.cpp @@ -129,13 +129,13 @@ TerminalSettingsViewWidget::TerminalSettingsViewWidget() else m_font = Gfx::FontDatabase::the().get_by_name(font_name); m_original_font = m_font; - font_text.set_text(m_font->qualified_name()); + font_text.set_text(m_font->human_readable_name()); font_text.set_font(m_font); font_button.on_click = [&](auto) { auto picker = GUI::FontPicker::construct(window(), m_font.ptr(), true); if (picker->exec() == GUI::Dialog::ExecOK) { m_font = picker->font(); - font_text.set_text(m_font->qualified_name()); + font_text.set_text(m_font->human_readable_name()); font_text.set_font(m_font); Config::write_string("Terminal", "Text", "Font", m_font->qualified_name()); } @@ -143,14 +143,18 @@ TerminalSettingsViewWidget::TerminalSettingsViewWidget() auto& font_selection = *find_descendant_of_type_named<GUI::Widget>("terminal_font_selection"); auto& use_default_font_button = *find_descendant_of_type_named<GUI::CheckBox>("terminal_font_defaulted"); - use_default_font_button.on_checked = [&](bool use_default_font) { + use_default_font_button.on_checked = [&, font_name](bool use_default_font) { if (use_default_font) { font_selection.set_enabled(false); m_font = Gfx::FontDatabase::the().default_fixed_width_font(); + font_text.set_text(m_font->human_readable_name()); + font_text.set_font(m_font); Config::write_string("Terminal", "Text", "Font", m_font->qualified_name()); } else { font_selection.set_enabled(true); - m_font = Gfx::FontDatabase::the().get_by_name(font_text.text()); + m_font = font_name.is_empty() + ? Gfx::FontDatabase::the().default_fixed_width_font() + : Gfx::FontDatabase::the().get_by_name(font_name); Config::write_string("Terminal", "Text", "Font", m_font->qualified_name()); } }; diff --git a/Userland/Libraries/LibGfx/BitmapFont.h b/Userland/Libraries/LibGfx/BitmapFont.h index b41c7def6e..e2b04ce096 100644 --- a/Userland/Libraries/LibGfx/BitmapFont.h +++ b/Userland/Libraries/LibGfx/BitmapFont.h @@ -105,6 +105,7 @@ public: String variant() const override; String qualified_name() const override; + String human_readable_name() const override { return String::formatted("{} {} {}", family(), variant(), presentation_size()); } private: BitmapFont(String name, String family, u8* rows, u8* widths, bool is_fixed_width, diff --git a/Userland/Libraries/LibGfx/Font.h b/Userland/Libraries/LibGfx/Font.h index da9fec975b..a7be32e9de 100644 --- a/Userland/Libraries/LibGfx/Font.h +++ b/Userland/Libraries/LibGfx/Font.h @@ -135,6 +135,7 @@ public: virtual String variant() const = 0; virtual String qualified_name() const = 0; + virtual String human_readable_name() const = 0; Font const& bold_variant() const; diff --git a/Userland/Libraries/LibGfx/TrueTypeFont/Font.h b/Userland/Libraries/LibGfx/TrueTypeFont/Font.h index dacb159786..c85c8caf5b 100644 --- a/Userland/Libraries/LibGfx/TrueTypeFont/Font.h +++ b/Userland/Libraries/LibGfx/TrueTypeFont/Font.h @@ -146,6 +146,7 @@ public: virtual String family() const override { return m_font->family(); } virtual String variant() const override { return m_font->variant(); } virtual String qualified_name() const override { return String::formatted("{} {} {} {}", family(), presentation_size(), weight(), slope()); } + virtual String human_readable_name() const override { return String::formatted("{} {} {}", family(), variant(), presentation_size()); } private: NonnullRefPtr<TTF::Font> m_font; |