1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 11:47:35 +00:00

LibPDF+PDFViewer: Extract Renderer::apply_page_rotation()

No behavior change.
This commit is contained in:
Nico Weber 2024-02-25 09:36:21 -05:00 committed by Andreas Kling
parent 5e9395b808
commit 03fab7089a
3 changed files with 15 additions and 9 deletions

View file

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