diff --git a/Userland/Applications/PDFViewer/PDFViewer.cpp b/Userland/Applications/PDFViewer/PDFViewer.cpp index 1728652ecc..15cdfc0362 100644 --- a/Userland/Applications/PDFViewer/PDFViewer.cpp +++ b/Userland/Applications/PDFViewer/PDFViewer.cpp @@ -350,15 +350,13 @@ PDF::PDFErrorOr> PDFViewer::render_page(u32 page_inde return bitmap; } - if (page.rotate + m_rotations != 0) { - int rotation_count = ((page.rotate + m_rotations) / 90) % 4; - if (rotation_count == 3) { - bitmap = TRY(bitmap->rotated(Gfx::RotationDirection::CounterClockwise)); - } else { - for (int i = 0; i < rotation_count; i++) - bitmap = TRY(bitmap->rotated(Gfx::RotationDirection::Clockwise)); - } - } + int rotation_count = ((page.rotate + m_rotations) / 90) % 4; + if (rotation_count == 1) + bitmap = TRY(bitmap->rotated(Gfx::RotationDirection::Clockwise)); + else if (rotation_count == 2) + bitmap = TRY(bitmap->rotated(Gfx::RotationDirection::Flip)); + else if (rotation_count == 3) + bitmap = TRY(bitmap->rotated(Gfx::RotationDirection::CounterClockwise)); return bitmap; } diff --git a/Userland/Libraries/LibGfx/Bitmap.cpp b/Userland/Libraries/LibGfx/Bitmap.cpp index e2ecdc0569..b4648224ba 100644 --- a/Userland/Libraries/LibGfx/Bitmap.cpp +++ b/Userland/Libraries/LibGfx/Bitmap.cpp @@ -277,6 +277,19 @@ ErrorOr> Bitmap::clone() const ErrorOr> Bitmap::rotated(Gfx::RotationDirection rotation_direction) const { + if (rotation_direction == Gfx::RotationDirection::Flip) { + auto new_bitmap = TRY(Gfx::Bitmap::create(format(), { width(), height() }, scale())); + + auto w = this->physical_width(); + auto h = this->physical_height(); + for (int i = 0; i < w; i++) { + for (int j = 0; j < h; j++) + new_bitmap->set_pixel(w - i - 1, h - j - 1, this->get_pixel(i, j)); + } + + return new_bitmap; + } + auto new_bitmap = TRY(Gfx::Bitmap::create(this->format(), { height(), width() }, scale())); auto w = this->physical_width(); diff --git a/Userland/Libraries/LibGfx/Bitmap.h b/Userland/Libraries/LibGfx/Bitmap.h index c14d7d8d6f..109233a0eb 100644 --- a/Userland/Libraries/LibGfx/Bitmap.h +++ b/Userland/Libraries/LibGfx/Bitmap.h @@ -86,7 +86,8 @@ struct BackingStore; enum class RotationDirection { CounterClockwise, - Clockwise + Flip, + Clockwise, }; class Bitmap : public RefCounted {