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
Notes: sideshowbarker 2024-07-18 03:33:47 +09:00
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_paste_action->set_enabled(GUI::Clipboard::the().mime_type() == "glyph/x-fonteditor");
m_delete_action = GUI::CommonActions::make_delete_action([&](auto&) {
m_edited_font->set_glyph_width(m_glyph_map_widget->selected_glyph(), m_edited_font->max_glyph_width());
m_delete_action = GUI::CommonActions::make_delete_action([this, update_statusbar](auto&) {
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_map_widget->update_glyph(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);
if (m_edited_font->is_fixed_width())
m_glyph_editor_present_checkbox->set_checked(false, GUI::AllowCallback::No);
else
m_glyph_editor_width_spinbox->set_value(0, GUI::AllowCallback::No);
update_statusbar();
});
m_undo_action = GUI::CommonActions::make_undo_action([&](auto&) {
undo();

View file

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