diff --git a/Userland/Applications/PDFViewer/PDFViewer.cpp b/Userland/Applications/PDFViewer/PDFViewer.cpp index 15cdfc0362..72abb439d8 100644 --- a/Userland/Applications/PDFViewer/PDFViewer.cpp +++ b/Userland/Applications/PDFViewer/PDFViewer.cpp @@ -350,15 +350,7 @@ PDF::PDFErrorOr> PDFViewer::render_page(u32 page_inde return bitmap; } - 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; + return TRY(PDF::Renderer::apply_page_rotation(bitmap, page, m_rotations)); } PDF::PDFErrorOr PDFViewer::cache_page_dimensions(bool recalculate_fixed_info) diff --git a/Userland/Libraries/LibPDF/Renderer.cpp b/Userland/Libraries/LibPDF/Renderer.cpp index a2962f8fe8..574bc6692b 100644 --- a/Userland/Libraries/LibPDF/Renderer.cpp +++ b/Userland/Libraries/LibPDF/Renderer.cpp @@ -50,6 +50,18 @@ PDFErrorsOr Renderer::render(Document& document, Page const& page, RefPtr< return Renderer(document, page, bitmap, background_color, rendering_preferences).render(); } +ErrorOr> Renderer::apply_page_rotation(NonnullRefPtr bitmap, Page const& page, int extra_degrees) +{ + int rotation_count = ((page.rotate + extra_degrees) / 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; +} + static void rect_path(Gfx::Path& path, float x, float y, float width, float height) { path.move_to({ x, y }); diff --git a/Userland/Libraries/LibPDF/Renderer.h b/Userland/Libraries/LibPDF/Renderer.h index 9c9d6350df..4b0b9a2bbd 100644 --- a/Userland/Libraries/LibPDF/Renderer.h +++ b/Userland/Libraries/LibPDF/Renderer.h @@ -104,6 +104,8 @@ class Renderer { public: static PDFErrorsOr render(Document&, Page const&, RefPtr, Color background_color, RenderingPreferences preferences); + static ErrorOr> apply_page_rotation(NonnullRefPtr, Page const&, int extra_degrees = 0); + struct FontCacheKey { NonnullRefPtr font_dictionary; float font_size;