1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:48:11 +00:00

LibPDF/PDFViewer: Support rotated pages

This commit is contained in:
Matthew Olsson 2021-05-10 11:52:48 -07:00 committed by Andreas Kling
parent fbe712e265
commit d5f94aaa7b
3 changed files with 22 additions and 3 deletions

View file

@ -87,5 +87,16 @@ RefPtr<Gfx::Bitmap> PDFViewer::render_page(const PDF::Page& page)
auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, { width, height });
PDF::Renderer::render(*m_document, page, bitmap);
if (page.rotate != 0) {
int rotation_count = (page.rotate / 90) % 4;
if (rotation_count == 3) {
bitmap = bitmap->rotated(Gfx::RotationDirection::CounterClockwise);
} else {
for (int i = 0; i < rotation_count; i++)
bitmap = bitmap->rotated(Gfx::RotationDirection::Clockwise);
}
}
return bitmap;
}