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.)
This commit is contained in:
Nico Weber 2024-01-16 20:38:41 -05:00 committed by Sam Atkins
commit 2d8a22f4b4
Notes: sideshowbarker 2024-07-16 23:51:07 +09:00

View file

@ -1225,6 +1225,21 @@ PDFErrorOr<void> Renderer::show_image(NonnullRefPtr<StreamObject> image)
auto width = TRY(m_document->resolve_to<int>(image_dict->get_value(CommonNames::Width)));
auto height = TRY(m_document->resolve_to<int>(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 {};