From 2d8a22f4b46d374d284923f5f8bd5183ad523cf5 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 16 Jan 2024 20:38:41 -0500 Subject: [PATCH] LibPDF: Clip images too Since we can't clip against a general path yet, this clips images against the bounding box of the current clip path as well. Clips for images are often rectangular, so this works out well. (We wastefully still decode and color-convert the entire image. In a follow-up, we could consider only converting the unclipped part.) --- Userland/Libraries/LibPDF/Renderer.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Userland/Libraries/LibPDF/Renderer.cpp b/Userland/Libraries/LibPDF/Renderer.cpp index 59ccd4a92e..1f1371ccc0 100644 --- a/Userland/Libraries/LibPDF/Renderer.cpp +++ b/Userland/Libraries/LibPDF/Renderer.cpp @@ -1225,6 +1225,21 @@ PDFErrorOr Renderer::show_image(NonnullRefPtr image) auto width = TRY(m_document->resolve_to(image_dict->get_value(CommonNames::Width))); auto height = TRY(m_document->resolve_to(image_dict->get_value(CommonNames::Height))); + class ClipRAII { + public: + ClipRAII(Renderer& renderer) + : m_renderer(renderer) + { + m_renderer.activate_clip(); + } + ~ClipRAII() { m_renderer.deactivate_clip(); } + + private: + Renderer& m_renderer; + }; + + ClipRAII clip_raii(*this); + if (!m_rendering_preferences.show_images) { show_empty_image(width, height); return {};