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

MacPDF: Honor page rotation

This commit is contained in:
Nico Weber 2024-02-25 09:43:38 -05:00 committed by Andreas Kling
parent b11aaca609
commit 4e0fe9d9d0

View file

@ -24,9 +24,9 @@ static PDF::PDFErrorOr<NonnullRefPtr<Gfx::Bitmap>> render(PDF::Document& documen
{ {
auto page = TRY(document.get_page(page_index)); auto page = TRY(document.get_page(page_index));
Gfx::IntSize page_size; auto page_size = Gfx::IntSize { size.width, size.height };
page_size.set_width(size.width); if (int rotation_count = (page.rotate / 90) % 4; rotation_count % 2 == 1)
page_size.set_height(size.height); page_size = Gfx::IntSize { page_size.height(), page_size.width() };
auto bitmap = TRY(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, page_size)); auto bitmap = TRY(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, page_size));
@ -36,7 +36,7 @@ static PDF::PDFErrorOr<NonnullRefPtr<Gfx::Bitmap>> render(PDF::Document& documen
NSLog(@"warning: %@", @(error.message().characters())); NSLog(@"warning: %@", @(error.message().characters()));
} }
return bitmap; return TRY(PDF::Renderer::apply_page_rotation(bitmap, page));
} }
static NSBitmapImageRep* ns_from_gfx(NonnullRefPtr<Gfx::Bitmap> bitmap_p) static NSBitmapImageRep* ns_from_gfx(NonnullRefPtr<Gfx::Bitmap> bitmap_p)