1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-23 19:37:34 +00:00

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.
This commit is contained in:
thankyouverycool 2022-01-31 20:54:27 -05:00 committed by Andreas Kling
parent 96895cd22c
commit a593b83189
8 changed files with 14 additions and 10 deletions

View file

@ -144,7 +144,7 @@ void CharacterMapWidget::initialize_menubar(GUI::Window& window)
void CharacterMapWidget::did_change_font() void CharacterMapWidget::did_change_font()
{ {
m_glyph_map->set_font(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()); m_output_box->set_font(font());
} }

View file

@ -28,7 +28,6 @@
@GUI::Label { @GUI::Label {
name: "default_font_label" name: "default_font_label"
text: "Katica 10 400"
} }
} }
@ -61,7 +60,6 @@
@GUI::Label { @GUI::Label {
name: "fixed_width_font_label" name: "fixed_width_font_label"
text: "Csilla 10 400"
} }
} }

View file

@ -51,13 +51,13 @@ FontSettingsWidget::~FontSettingsWidget()
static void update_label_with_font(GUI::Label& label, Gfx::Font const& font) 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); label.set_font(font);
} }
void FontSettingsWidget::apply_settings() 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());
} }
} }

View file

@ -54,7 +54,6 @@
@GUI::Label { @GUI::Label {
name: "terminal_font_label" name: "terminal_font_label"
text: "Csilla 10 400"
} }
} }

View file

@ -129,13 +129,13 @@ TerminalSettingsViewWidget::TerminalSettingsViewWidget()
else else
m_font = Gfx::FontDatabase::the().get_by_name(font_name); m_font = Gfx::FontDatabase::the().get_by_name(font_name);
m_original_font = m_font; 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_text.set_font(m_font);
font_button.on_click = [&](auto) { font_button.on_click = [&](auto) {
auto picker = GUI::FontPicker::construct(window(), m_font.ptr(), true); auto picker = GUI::FontPicker::construct(window(), m_font.ptr(), true);
if (picker->exec() == GUI::Dialog::ExecOK) { if (picker->exec() == GUI::Dialog::ExecOK) {
m_font = picker->font(); 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); font_text.set_font(m_font);
Config::write_string("Terminal", "Text", "Font", m_font->qualified_name()); 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& 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"); 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) { if (use_default_font) {
font_selection.set_enabled(false); font_selection.set_enabled(false);
m_font = Gfx::FontDatabase::the().default_fixed_width_font(); 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()); Config::write_string("Terminal", "Text", "Font", m_font->qualified_name());
} else { } else {
font_selection.set_enabled(true); 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()); Config::write_string("Terminal", "Text", "Font", m_font->qualified_name());
} }
}; };

View file

@ -105,6 +105,7 @@ public:
String variant() const override; String variant() const override;
String qualified_name() const override; String qualified_name() const override;
String human_readable_name() const override { return String::formatted("{} {} {}", family(), variant(), presentation_size()); }
private: private:
BitmapFont(String name, String family, u8* rows, u8* widths, bool is_fixed_width, BitmapFont(String name, String family, u8* rows, u8* widths, bool is_fixed_width,

View file

@ -135,6 +135,7 @@ public:
virtual String variant() const = 0; virtual String variant() const = 0;
virtual String qualified_name() const = 0; virtual String qualified_name() const = 0;
virtual String human_readable_name() const = 0;
Font const& bold_variant() const; Font const& bold_variant() const;

View file

@ -146,6 +146,7 @@ public:
virtual String family() const override { return m_font->family(); } virtual String family() const override { return m_font->family(); }
virtual String variant() const override { return m_font->variant(); } 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 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: private:
NonnullRefPtr<TTF::Font> m_font; NonnullRefPtr<TTF::Font> m_font;