[librsvg: 4/8] When clipping, only accept elements that can go inside a clipPath




commit eb974ccfa1728b156d5114541c2dd4b8f37b0452
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Jun 1 19:30:01 2021 -0500

    When clipping, only accept elements that can go inside a clipPath
    
    https://www.w3.org/TR/css-masking-1/#ClipPathElement indicates that
    only certain elements can appear inside a <clipPath>.

 src/drawing_ctx.rs | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index 7de70b60..01a9ae81 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -17,6 +17,7 @@ use crate::coord_units::CoordUnits;
 use crate::dasharray::Dasharray;
 use crate::document::{AcquiredNodes, NodeId};
 use crate::dpi::Dpi;
+use crate::element::Element;
 use crate::error::{AcquireError, ImplementationLimit, RenderingError};
 use crate::filters::{self, FilterSpec};
 use crate::float_eq_cairo::ApproxEqCairo;
@@ -501,7 +502,9 @@ impl DrawingCtx {
             let orig_transform = self.get_transform();
             self.cr.transform(node_transform.into());
 
-            for child in node.children().filter(|c| c.is_element()) {
+            for child in node.children().filter(|c| {
+                c.is_element() && element_can_be_used_inside_clip_path(&c.borrow_element())
+            }) {
                 child.draw(
                     acquired_nodes,
                     &CascadedValues::new(&cascaded, &child),
@@ -1665,6 +1668,23 @@ impl DrawingCtx {
     }
 }
 
+// https://www.w3.org/TR/css-masking-1/#ClipPathElement
+fn element_can_be_used_inside_clip_path(element: &Element) -> bool {
+    match *element {
+        Element::Circle(_)
+        | Element::Ellipse(_)
+        | Element::Line(_)
+        | Element::Path(_)
+        | Element::Polygon(_)
+        | Element::Polyline(_)
+        | Element::Rect(_)
+        | Element::Text(_)
+        | Element::Use(_) => true,
+
+        _ => false,
+    }
+}
+
 #[derive(Debug)]
 struct CompositingAffines {
     pub outside_temporary_surface: Transform,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]