Quellcode durchsuchen

LibPDF+PDFViewer: Extract Renderer::apply_page_rotation()

No behavior change.
Nico Weber vor 1 Jahr
Ursprung
Commit
03fab7089a

+ 1 - 9
Userland/Applications/PDFViewer/PDFViewer.cpp

@@ -350,15 +350,7 @@ PDF::PDFErrorOr<NonnullRefPtr<Gfx::Bitmap>> 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<void> PDFViewer::cache_page_dimensions(bool recalculate_fixed_info)

+ 12 - 0
Userland/Libraries/LibPDF/Renderer.cpp

@@ -50,6 +50,18 @@ PDFErrorsOr<void> Renderer::render(Document& document, Page const& page, RefPtr<
     return Renderer(document, page, bitmap, background_color, rendering_preferences).render();
 }
 
+ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Renderer::apply_page_rotation(NonnullRefPtr<Gfx::Bitmap> 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 });

+ 2 - 0
Userland/Libraries/LibPDF/Renderer.h

@@ -104,6 +104,8 @@ class Renderer {
 public:
     static PDFErrorsOr<void> render(Document&, Page const&, RefPtr<Gfx::Bitmap>, Color background_color, RenderingPreferences preferences);
 
+    static ErrorOr<NonnullRefPtr<Gfx::Bitmap>> apply_page_rotation(NonnullRefPtr<Gfx::Bitmap>, Page const&, int extra_degrees = 0);
+
     struct FontCacheKey {
         NonnullRefPtr<DictObject> font_dictionary;
         float font_size;