浏览代码

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.)
Nico Weber 1 年之前
父节点
当前提交
2d8a22f4b4
共有 1 个文件被更改,包括 15 次插入0 次删除
  1. 15 0
      Userland/Libraries/LibPDF/Renderer.cpp

+ 15 - 0
Userland/Libraries/LibPDF/Renderer.cpp

@@ -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 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)));
     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) {
     if (!m_rendering_preferences.show_images) {
         show_empty_image(width, height);
         show_empty_image(width, height);
         return {};
         return {};