mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:28:12 +00:00
FontEditor: Standardize Gfx::RotationDirections for rotate_90()
This commit is contained in:
parent
fb00d3ed25
commit
d867871bda
3 changed files with 8 additions and 12 deletions
|
@ -189,21 +189,22 @@ static Vector<Vector<u8>> glyph_as_matrix(Gfx::GlyphBitmap const& bitmap)
|
|||
return result;
|
||||
}
|
||||
|
||||
void GlyphEditorWidget::rotate_90(Direction direction)
|
||||
void GlyphEditorWidget::rotate_90(Gfx::RotationDirection direction)
|
||||
{
|
||||
if (on_undo_event)
|
||||
on_undo_event();
|
||||
|
||||
auto bitmap = font().raw_glyph(m_glyph).glyph_bitmap();
|
||||
auto matrix = glyph_as_matrix(bitmap);
|
||||
auto clockwise = direction == Gfx::RotationDirection::Clockwise;
|
||||
|
||||
for (int y = 0; y < bitmap.height(); y++) {
|
||||
for (int x = 0; x < bitmap.width(); x++) {
|
||||
int source_x = (direction == Counterclockwise) ? max(bitmap.width() - 1 - y, 0) : y;
|
||||
int source_y = (direction == Counterclockwise) ? x : bitmap.width() - 1 - x;
|
||||
int source_x = clockwise ? y : max(bitmap.width() - 1 - y, 0);
|
||||
int source_y = clockwise ? bitmap.width() - 1 - x : x;
|
||||
bool value = false;
|
||||
if (source_x < bitmap.width() && source_y < bitmap.height()) {
|
||||
value = (direction == Counterclockwise && y >= bitmap.width()) ? false : matrix[source_y][source_x];
|
||||
value = (!clockwise && y >= bitmap.width()) ? false : matrix[source_y][source_x];
|
||||
}
|
||||
bitmap.set_bit_at(x, y, value);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue