1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 02:27:43 +00:00

FontEditor: Set width to zero when deleting a glyph

Previously, Delete left a glyph's width maximized.
This commit is contained in:
thankyouverycool 2021-09-21 17:34:35 -04:00 committed by Andreas Kling
parent ca6cb6cec3
commit 1ae4caca4b
2 changed files with 13 additions and 10 deletions

View file

@ -241,13 +241,15 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&&
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_paste_action->set_enabled(GUI::Clipboard::the().mime_type() == "glyph/x-fonteditor"); m_paste_action->set_enabled(GUI::Clipboard::the().mime_type() == "glyph/x-fonteditor");
m_delete_action = GUI::CommonActions::make_delete_action([&](auto&) { m_delete_action = GUI::CommonActions::make_delete_action([this, update_statusbar](auto&) {
m_edited_font->set_glyph_width(m_glyph_map_widget->selected_glyph(), m_edited_font->max_glyph_width()); if (m_glyph_editor_widget->is_glyph_empty() && m_edited_font->raw_glyph_width(m_glyph_map_widget->selected_glyph()) == 0)
return;
m_glyph_editor_widget->delete_glyph(); m_glyph_editor_widget->delete_glyph();
m_glyph_map_widget->update_glyph(m_glyph_map_widget->selected_glyph()); if (m_edited_font->is_fixed_width())
auto glyph_width = m_edited_font->raw_glyph_width(m_glyph_map_widget->selected_glyph()); m_glyph_editor_present_checkbox->set_checked(false, GUI::AllowCallback::No);
m_glyph_editor_width_spinbox->set_value(glyph_width); else
m_glyph_editor_present_checkbox->set_checked(glyph_width > 0); m_glyph_editor_width_spinbox->set_value(0, GUI::AllowCallback::No);
update_statusbar();
}); });
m_undo_action = GUI::CommonActions::make_undo_action([&](auto&) { m_undo_action = GUI::CommonActions::make_undo_action([&](auto&) {
undo(); undo();

View file

@ -39,9 +39,10 @@ void GlyphEditorWidget::delete_glyph()
if (on_undo_event) if (on_undo_event)
on_undo_event(); on_undo_event();
auto bitmap = font().raw_glyph(m_glyph).glyph_bitmap(); auto bitmap = font().raw_glyph(m_glyph).glyph_bitmap();
for (int x = 0; x < bitmap.width(); x++) for (int x = 0; x < font().max_glyph_width(); x++)
for (int y = 0; y < bitmap.height(); y++) for (int y = 0; y < font().glyph_height(); y++)
bitmap.set_bit_at(x, y, false); bitmap.set_bit_at(x, y, false);
font().set_glyph_width(m_glyph, 0);
if (on_glyph_altered) if (on_glyph_altered)
on_glyph_altered(m_glyph); on_glyph_altered(m_glyph);
update(); update();
@ -155,8 +156,8 @@ void GlyphEditorWidget::paint_event(GUI::PaintEvent& event)
bool GlyphEditorWidget::is_glyph_empty() bool GlyphEditorWidget::is_glyph_empty()
{ {
auto bitmap = font().raw_glyph(m_glyph).glyph_bitmap(); auto bitmap = font().raw_glyph(m_glyph).glyph_bitmap();
for (int x = 0; x < bitmap.width(); x++) for (int x = 0; x < font().max_glyph_width(); x++)
for (int y = 0; y < bitmap.height(); y++) for (int y = 0; y < font().glyph_height(); y++)
if (bitmap.bit_at(x, y)) if (bitmap.bit_at(x, y))
return false; return false;
return true; return true;