mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:27: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:
parent
08d1b16a8d
commit
18ae37439a
5 changed files with 33 additions and 8 deletions
|
@ -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_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_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_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_name_textbox = *find_descendant_of_type_named<GUI::TextBox>("name_textbox");
|
||||||
m_family_textbox = *find_descendant_of_type_named<GUI::TextBox>("family_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");
|
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_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_editor_widget->delete_glyph();
|
||||||
m_glyph_map_widget->update_glyph(m_glyph_map_widget->selected_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&) {
|
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)
|
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_map_widget->on_glyph_selected = [&](int glyph) {
|
||||||
m_glyph_editor_widget->set_glyph(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;
|
StringBuilder builder;
|
||||||
builder.appendff("{:#02x} (", glyph);
|
builder.appendff("{:#02x} (", glyph);
|
||||||
if (glyph < 128) {
|
if (glyph < 128) {
|
||||||
|
@ -255,7 +260,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&&
|
||||||
builder.append(128 | (glyph % 64));
|
builder.append(128 | (glyph % 64));
|
||||||
}
|
}
|
||||||
builder.append(") ");
|
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());
|
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_fixed_width_checkbox->on_checked = [&, update_demo](bool checked) {
|
||||||
m_edited_font->set_fixed_width(checked);
|
m_edited_font->set_fixed_width(checked);
|
||||||
m_glyph_editor_width_spinbox->set_enabled(!m_edited_font->is_fixed_width());
|
auto glyph_width = m_edited_font->raw_glyph_width(m_glyph_map_widget->selected_glyph());
|
||||||
m_glyph_editor_width_spinbox->set_value(m_edited_font->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();
|
m_glyph_editor_widget->update();
|
||||||
update_demo();
|
update_demo();
|
||||||
};
|
};
|
||||||
|
@ -282,6 +290,13 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&&
|
||||||
update_demo();
|
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_weight_combobox->on_change = [this]() {
|
||||||
m_edited_font->set_weight(GUI::name_to_weight(m_weight_combobox->text()));
|
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_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_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_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_name_textbox->set_text(m_edited_font->name());
|
||||||
m_family_textbox->set_text(m_edited_font->family());
|
m_family_textbox->set_text(m_edited_font->family());
|
||||||
|
|
|
@ -79,6 +79,7 @@ private:
|
||||||
RefPtr<GUI::SpinBox> m_mean_line_spinbox;
|
RefPtr<GUI::SpinBox> m_mean_line_spinbox;
|
||||||
RefPtr<GUI::SpinBox> m_presentation_spinbox;
|
RefPtr<GUI::SpinBox> m_presentation_spinbox;
|
||||||
RefPtr<GUI::SpinBox> m_glyph_editor_width_spinbox;
|
RefPtr<GUI::SpinBox> m_glyph_editor_width_spinbox;
|
||||||
|
RefPtr<GUI::CheckBox> m_glyph_editor_present_checkbox;
|
||||||
RefPtr<GUI::TextBox> m_name_textbox;
|
RefPtr<GUI::TextBox> m_name_textbox;
|
||||||
RefPtr<GUI::TextBox> m_family_textbox;
|
RefPtr<GUI::TextBox> m_family_textbox;
|
||||||
RefPtr<GUI::CheckBox> m_fixed_width_checkbox;
|
RefPtr<GUI::CheckBox> m_fixed_width_checkbox;
|
||||||
|
|
|
@ -34,6 +34,11 @@
|
||||||
@GUI::SpinBox {
|
@GUI::SpinBox {
|
||||||
name: "glyph_editor_width_spinbox"
|
name: "glyph_editor_width_spinbox"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GUI::CheckBox {
|
||||||
|
name: "glyph_editor_present_checkbox"
|
||||||
|
text: "Glyph Present"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GUI::Widget {
|
@GUI::Widget {
|
||||||
|
|
|
@ -107,7 +107,7 @@ void GlyphMapWidget::paint_event(GUI::PaintEvent& event)
|
||||||
painter.add_clip_rect(event.rect());
|
painter.add_clip_rect(event.rect());
|
||||||
|
|
||||||
painter.set_font(font());
|
painter.set_font(font());
|
||||||
painter.fill_rect(widget_inner_rect(), palette().base());
|
painter.fill_rect(widget_inner_rect(), palette().inactive_window_title());
|
||||||
|
|
||||||
for (int glyph = 0; glyph < m_glyph_count; ++glyph) {
|
for (int glyph = 0; glyph < m_glyph_count; ++glyph) {
|
||||||
Gfx::IntRect outer_rect = get_outer_rect(glyph);
|
Gfx::IntRect outer_rect = get_outer_rect(glyph);
|
||||||
|
@ -119,7 +119,8 @@ void GlyphMapWidget::paint_event(GUI::PaintEvent& event)
|
||||||
if (glyph == m_selected_glyph) {
|
if (glyph == m_selected_glyph) {
|
||||||
painter.fill_rect(outer_rect, is_focused() ? palette().selection() : palette().inactive_selection());
|
painter.fill_rect(outer_rect, is_focused() ? palette().selection() : palette().inactive_selection());
|
||||||
painter.draw_glyph(inner_rect.location(), glyph, is_focused() ? palette().selection_text() : palette().inactive_selection_text());
|
painter.draw_glyph(inner_rect.location(), glyph, is_focused() ? palette().selection_text() : palette().inactive_selection_text());
|
||||||
} else {
|
} else if (m_font->contains_glyph(glyph)) {
|
||||||
|
painter.fill_rect(outer_rect, palette().base());
|
||||||
painter.draw_glyph(inner_rect.location(), glyph, palette().base_text());
|
painter.draw_glyph(inner_rect.location(), glyph, palette().base_text());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,8 @@ public:
|
||||||
u8 glyph_height() const { return m_glyph_height; }
|
u8 glyph_height() const { return m_glyph_height; }
|
||||||
int x_height() const { return m_x_height; }
|
int x_height() const { return m_x_height; }
|
||||||
|
|
||||||
|
u8 raw_glyph_width(size_t ch) const { return m_glyph_widths[ch]; }
|
||||||
|
|
||||||
u8 min_glyph_width() const { return m_min_glyph_width; }
|
u8 min_glyph_width() const { return m_min_glyph_width; }
|
||||||
u8 max_glyph_width() const { return m_max_glyph_width; }
|
u8 max_glyph_width() const { return m_max_glyph_width; }
|
||||||
u8 glyph_fixed_width() const { return m_glyph_width; }
|
u8 glyph_fixed_width() const { return m_glyph_width; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue