diff --git a/Userland/Applications/FontEditor/GlyphEditorWidget.cpp b/Userland/Applications/FontEditor/GlyphEditorWidget.cpp index 6042867db5..be0e375716 100644 --- a/Userland/Applications/FontEditor/GlyphEditorWidget.cpp +++ b/Userland/Applications/FontEditor/GlyphEditorWidget.cpp @@ -215,40 +215,19 @@ void GlyphEditorWidget::rotate_90(Gfx::RotationDirection direction) update(); } -void GlyphEditorWidget::flip_vertically() +void GlyphEditorWidget::flip(Gfx::Orientation orientation) { if (on_undo_event) on_undo_event(); auto bitmap = font().raw_glyph(m_glyph).glyph_bitmap(); auto matrix = glyph_as_matrix(bitmap); + auto vertical = orientation == Gfx::Orientation::Vertical; for (int y = 0; y < bitmap.height(); y++) { for (int x = 0; x < bitmap.width(); x++) { - int source_x = x; - int source_y = bitmap.height() - 1 - y; - bool value = matrix[source_y][source_x]; - bitmap.set_bit_at(x, y, value); - } - } - - if (on_glyph_altered) - on_glyph_altered(m_glyph); - update(); -} - -void GlyphEditorWidget::flip_horizontally() -{ - if (on_undo_event) - on_undo_event(); - - auto bitmap = font().raw_glyph(m_glyph).glyph_bitmap(); - auto matrix = glyph_as_matrix(bitmap); - - for (int y = 0; y < bitmap.height(); y++) { - for (int x = 0; x < bitmap.width(); x++) { - int source_x = bitmap.width() - 1 - x; - int source_y = y; + int source_x = vertical ? x : bitmap.width() - 1 - x; + int source_y = vertical ? bitmap.height() - 1 - y : y; bool value = matrix[source_y][source_x]; bitmap.set_bit_at(x, y, value); } diff --git a/Userland/Applications/FontEditor/GlyphEditorWidget.h b/Userland/Applications/FontEditor/GlyphEditorWidget.h index 3abc344fef..05f18ece74 100644 --- a/Userland/Applications/FontEditor/GlyphEditorWidget.h +++ b/Userland/Applications/FontEditor/GlyphEditorWidget.h @@ -28,8 +28,7 @@ public: bool is_glyph_empty(); void rotate_90(Gfx::RotationDirection); - void flip_vertically(); - void flip_horizontally(); + void flip(Gfx::Orientation); int preferred_width() const; int preferred_height() const; diff --git a/Userland/Applications/FontEditor/MainWidget.cpp b/Userland/Applications/FontEditor/MainWidget.cpp index 6374aa582a..d99fa037d7 100644 --- a/Userland/Applications/FontEditor/MainWidget.cpp +++ b/Userland/Applications/FontEditor/MainWidget.cpp @@ -283,11 +283,11 @@ ErrorOr MainWidget::create_actions() }); m_flip_horizontal_action = GUI::Action::create("Flip Horizontally", { Mod_Ctrl | Mod_Shift, Key_Q }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-flip-horizontal.png"sv)), [&](auto&) { - m_glyph_editor_widget->flip_horizontally(); + m_glyph_editor_widget->flip(Gfx::Orientation::Horizontal); }); m_flip_vertical_action = GUI::Action::create("Flip Vertically", { Mod_Ctrl | Mod_Shift, Key_W }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-flip-vertical.png"sv)), [&](auto&) { - m_glyph_editor_widget->flip_vertically(); + m_glyph_editor_widget->flip(Gfx::Orientation::Vertical); }); m_copy_text_action = GUI::Action::create("Copy as Te&xt", { Mod_Ctrl, Key_T }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-copy.png"sv)), [&](auto&) {