From c4c4ead9d243bdd197290ddba230c7fc70a7cb0f Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sun, 23 Jul 2023 09:58:21 -0400 Subject: [PATCH] MacPDF: Highdpi! --- Meta/Lagom/Contrib/MacPDF/LagomPDFView.mm | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Meta/Lagom/Contrib/MacPDF/LagomPDFView.mm b/Meta/Lagom/Contrib/MacPDF/LagomPDFView.mm index a72ea1a91d..1b01444082 100644 --- a/Meta/Lagom/Contrib/MacPDF/LagomPDFView.mm +++ b/Meta/Lagom/Contrib/MacPDF/LagomPDFView.mm @@ -23,12 +23,15 @@ } @end -static PDF::PDFErrorOr> render(PDF::Document& document) +static PDF::PDFErrorOr> render(PDF::Document& document, NSSize size) { NSLog(@"num pages %@", @(document.get_page_count())); int page_index = 0; auto page = TRY(document.get_page(page_index)); - auto page_size = Gfx::IntSize { 800, round_to(800 * page.media_box.height() / page.media_box.width()) }; + + Gfx::IntSize page_size; + page_size.set_width(size.width); + page_size.set_height(size.height); auto bitmap = TRY(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, page_size)); @@ -80,16 +83,17 @@ static NSBitmapImageRep* ns_from_gfx(NonnullRefPtr bitmap_p) { static bool did_load = false; if (!did_load) { + NSSize pixel_size = [self convertSizeToBacking:self.bounds.size]; did_load = true; if (auto doc_or = [self load]; !doc_or.is_error()) { _doc = doc_or.value(); - if (auto bitmap_or = render(*_doc); !bitmap_or.is_error()) + if (auto bitmap_or = render(*_doc, pixel_size); !bitmap_or.is_error()) _rep = ns_from_gfx(bitmap_or.value()); } else { NSLog(@"failed to load: %@", @(doc_or.error().message().characters())); } } - [_rep drawAtPoint:NSMakePoint(0, 0)]; + [_rep drawInRect:self.bounds]; } @end