[librsvg: 6/12] Image: put the is_visible flag here




commit 4ccdcd945cacb01b246bd2831364b8f527d3b7ec
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Jun 3 12:57:00 2021 -0500

    Image: put the is_visible flag here
    
    Do the same transformation as we did with Shape, so that visibility is
    not computed in the callback to with_discrete_layer().

 src/drawing_ctx.rs | 48 ++++++++++++++++++++++++++----------------------
 src/image.rs       |  3 +++
 src/layout.rs      |  1 +
 3 files changed, 30 insertions(+), 22 deletions(-)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index d47e6da3..6a712557 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -1321,33 +1321,37 @@ impl DrawingCtx {
             None
         };
 
-        self.with_discrete_layer(
-            stacking_ctx,
-            acquired_nodes,
-            values,
-            clipping,
-            None,
-            &mut |_an, dc| {
-                let saved_cr = SavedCr::new(dc);
-
-                if let Some(_params) = saved_cr.draw_ctx.push_new_viewport(
-                    Some(vbox),
-                    image.rect,
-                    image.aspect,
-                    clip_mode,
-                ) {
-                    if values.is_visible() {
+        // The bounding box for <image> is decided by the values of the image's x, y, w, h
+        // and not by the final computed image bounds.
+        let bounds = self.empty_bbox().with_rect(image.rect);
+
+        if image.is_visible {
+            self.with_discrete_layer(
+                stacking_ctx,
+                acquired_nodes,
+                values,
+                clipping,
+                None,
+                &mut |_an, dc| {
+                    let saved_cr = SavedCr::new(dc);
+
+                    if let Some(_params) = saved_cr.draw_ctx.push_new_viewport(
+                        Some(vbox),
+                        image.rect,
+                        image.aspect,
+                        clip_mode,
+                    ) {
                         saved_cr
                             .draw_ctx
                             .paint_surface(&image.surface, image_width, image_height);
                     }
-                }
 
-                // The bounding box for <image> is decided by the values of x, y, w, h
-                // and not by the final computed image bounds.
-                Ok(saved_cr.draw_ctx.empty_bbox().with_rect(image.rect))
-            },
-        )
+                    Ok(bounds)
+                },
+            )
+        } else {
+            Ok(bounds)
+        }
     }
 
     // TODO: just like we have Shape with all its parameters, do the same for a layout::Text.
diff --git a/src/image.rs b/src/image.rs
index d13f92ec..67cc564c 100644
--- a/src/image.rs
+++ b/src/image.rs
@@ -79,12 +79,15 @@ impl Draw for Image {
         let w = self.width.to_user(&params);
         let h = self.height.to_user(&params);
 
+        let is_visible = values.is_visible();
+
         let rect = Rect::new(x, y, x + w, y + h);
 
         let overflow = values.overflow();
 
         let image = layout::Image {
             surface,
+            is_visible,
             rect,
             aspect: self.aspect,
             overflow,
diff --git a/src/layout.rs b/src/layout.rs
index b488b8a0..958fbd54 100644
--- a/src/layout.rs
+++ b/src/layout.rs
@@ -80,6 +80,7 @@ pub struct Shape {
 /// Image in user-space coordinates.
 pub struct Image {
     pub surface: SharedImageSurface,
+    pub is_visible: bool,
     pub rect: Rect,
     pub aspect: AspectRatio,
     pub overflow: Overflow,


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