1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:17:44 +00:00

FontEditor+LibGfx: Allow user to specify if a specific glyph is present

This replaces the glyph width spinbox in the font editor with a
checkbox when editing fixed width fonts that indicates if the
currently selected character's glyph is present in the edited font
(For variable width fonts a non zero width implies presence)

This commit also changes the background color of glyphs in the glyph
map based on the presence of each specific glyph in the font.
This commit is contained in:
Idan Horowitz 2021-04-18 21:12:52 +03:00 committed by Andreas Kling
parent 08d1b16a8d
commit 18ae37439a
5 changed files with 33 additions and 8 deletions

View file

@ -105,6 +105,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&&
m_glyph_editor_container = *find_descendant_of_type_named<GUI::Widget>("glyph_editor_container");
m_left_column_container = *find_descendant_of_type_named<GUI::Widget>("left_column_container");
m_glyph_editor_width_spinbox = *find_descendant_of_type_named<GUI::SpinBox>("glyph_editor_width_spinbox");
m_glyph_editor_present_checkbox = *find_descendant_of_type_named<GUI::CheckBox>("glyph_editor_present_checkbox");
m_name_textbox = *find_descendant_of_type_named<GUI::TextBox>("name_textbox");
m_family_textbox = *find_descendant_of_type_named<GUI::TextBox>("family_textbox");
m_presentation_spinbox = *find_descendant_of_type_named<GUI::SpinBox>("presentation_spinbox");
@ -206,7 +207,9 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&&
m_edited_font->set_glyph_width(m_glyph_map_widget->selected_glyph(), m_edited_font->max_glyph_width());
m_glyph_editor_widget->delete_glyph();
m_glyph_map_widget->update_glyph(m_glyph_map_widget->selected_glyph());
m_glyph_editor_width_spinbox->set_value(m_edited_font->glyph_width(m_glyph_map_widget->selected_glyph()));
auto glyph_width = m_edited_font->raw_glyph_width(m_glyph_map_widget->selected_glyph());
m_glyph_editor_width_spinbox->set_value(glyph_width);
m_glyph_editor_present_checkbox->set_checked(glyph_width > 0);
});
m_open_preview_action = GUI::Action::create("Preview Font", Gfx::Bitmap::load_from_file("/res/icons/16x16/find.png"), [&](auto&) {
if (!m_font_preview_window)
@ -242,7 +245,9 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&&
m_glyph_map_widget->on_glyph_selected = [&](int glyph) {
m_glyph_editor_widget->set_glyph(glyph);
m_glyph_editor_width_spinbox->set_value(m_edited_font->glyph_width(m_glyph_map_widget->selected_glyph()));
auto glyph_width = m_edited_font->raw_glyph_width(m_glyph_map_widget->selected_glyph());
m_glyph_editor_width_spinbox->set_value(glyph_width);
m_glyph_editor_present_checkbox->set_checked(glyph_width > 0);
StringBuilder builder;
builder.appendff("{:#02x} (", glyph);
if (glyph < 128) {
@ -255,7 +260,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&&
builder.append(128 | (glyph % 64));
}
builder.append(") ");
builder.appendff("[{}x{}]", m_edited_font->glyph_width(glyph), m_edited_font->glyph_height());
builder.appendff("[{}x{}]", m_edited_font->raw_glyph_width(glyph), m_edited_font->glyph_height());
statusbar.set_text(builder.to_string());
};
@ -269,8 +274,11 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&&
m_fixed_width_checkbox->on_checked = [&, update_demo](bool checked) {
m_edited_font->set_fixed_width(checked);
m_glyph_editor_width_spinbox->set_enabled(!m_edited_font->is_fixed_width());
m_glyph_editor_width_spinbox->set_value(m_edited_font->glyph_width(m_glyph_map_widget->selected_glyph()));
auto glyph_width = m_edited_font->raw_glyph_width(m_glyph_map_widget->selected_glyph());
m_glyph_editor_width_spinbox->set_visible(!checked);
m_glyph_editor_width_spinbox->set_value(glyph_width);
m_glyph_editor_present_checkbox->set_visible(checked);
m_glyph_editor_present_checkbox->set_checked(glyph_width > 0);
m_glyph_editor_widget->update();
update_demo();
};
@ -282,6 +290,13 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&&
update_demo();
};
m_glyph_editor_present_checkbox->on_checked = [this, update_demo](bool checked) {
m_edited_font->set_glyph_width(m_glyph_map_widget->selected_glyph(), checked ? m_edited_font->glyph_fixed_width() : 0);
m_glyph_editor_widget->update();
m_glyph_map_widget->update_glyph(m_glyph_map_widget->selected_glyph());
update_demo();
};
m_weight_combobox->on_change = [this]() {
m_edited_font->set_weight(GUI::name_to_weight(m_weight_combobox->text()));
};
@ -332,8 +347,9 @@ void FontEditorWidget::initialize(const String& path, RefPtr<Gfx::BitmapFont>&&
m_glyph_editor_container->set_fixed_size(m_glyph_editor_widget->preferred_width(), m_glyph_editor_widget->preferred_height());
m_left_column_container->set_fixed_width(m_glyph_editor_widget->preferred_width());
m_glyph_editor_width_spinbox->set_enabled(!m_edited_font->is_fixed_width());
m_glyph_editor_width_spinbox->set_visible(!m_edited_font->is_fixed_width());
m_glyph_editor_width_spinbox->set_max(m_edited_font->max_glyph_width());
m_glyph_editor_present_checkbox->set_visible(m_edited_font->is_fixed_width());
m_name_textbox->set_text(m_edited_font->name());
m_family_textbox->set_text(m_edited_font->family());