1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:38:11 +00:00

FontEditor: Consolidate GlyphEditor's flip_{horizontally,vertically}

This commit is contained in:
thankyouverycool 2022-10-25 07:11:58 -04:00 committed by Andreas Kling
parent d867871bda
commit 894b41ef4d
3 changed files with 7 additions and 29 deletions

View file

@ -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);
}