[librsvg: 5/12] layout::Image - new; move the image rendering parameters here.




commit a8e209242da39e777cdbc49ae57f2654a667430a
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Jun 3 12:43:58 2021 -0500

    layout::Image - new; move the image rendering parameters here.
    
    DrawingCtx.draw_image now takes a layout::Image.
    
    This is analogous to Shape / draw_shape.

 src/drawing_ctx.rs | 40 +++++++++++++++++++---------------------
 src/image.rs       | 27 +++++++++++++++++----------
 src/layout.rs      | 15 +++++++++++++--
 3 files changed, 49 insertions(+), 33 deletions(-)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index 2fbd4e4d..d47e6da3 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -22,7 +22,7 @@ use crate::error::{AcquireError, ImplementationLimit, RenderingError};
 use crate::filters::{self, FilterSpec};
 use crate::float_eq_cairo::ApproxEqCairo;
 use crate::gradient::{GradientVariant, SpreadMethod, UserSpaceGradient};
-use crate::layout::{Shape, StackingContext, Stroke};
+use crate::layout::{Image, Shape, StackingContext, Stroke};
 use crate::length::*;
 use crate::marker;
 use crate::node::{CascadedValues, Node, NodeBorrow, NodeDraw};
@@ -1296,17 +1296,15 @@ impl DrawingCtx {
     // same for a layout::Image.
     pub fn draw_image(
         &mut self,
-        surface: &SharedImageSurface,
-        rect: Rect,
-        aspect: AspectRatio,
-        node: &Node,
+        image: &Image,
+        stacking_ctx: &StackingContext,
         acquired_nodes: &mut AcquiredNodes<'_>,
         values: &ComputedValues,
         clipping: bool,
     ) -> Result<BoundingBox, RenderingError> {
-        let image_width = surface.width();
-        let image_height = surface.height();
-        if clipping || rect.is_empty() || image_width == 0 || image_height == 0 {
+        let image_width = image.surface.width();
+        let image_height = image.surface.height();
+        if clipping || image.rect.is_empty() || image_width == 0 || image_height == 0 {
             return Ok(self.empty_bbox());
         }
 
@@ -1314,18 +1312,17 @@ impl DrawingCtx {
         let image_height = f64::from(image_height);
         let vbox = ViewBox::from(Rect::from_size(image_width, image_height));
 
-        let clip_mode = if !values.is_overflow() && aspect.is_slice() {
+        let clip_mode = if !(image.overflow == Overflow::Auto
+            || image.overflow == Overflow::Visible)
+            && image.aspect.is_slice()
+        {
             Some(ClipMode::ClipToViewport)
         } else {
             None
         };
 
-        let elt = node.borrow_element();
-
-        let stacking_ctx = StackingContext::new(acquired_nodes, &elt, elt.get_transform(), values);
-
         self.with_discrete_layer(
-            &stacking_ctx,
+            stacking_ctx,
             acquired_nodes,
             values,
             clipping,
@@ -1333,21 +1330,22 @@ impl DrawingCtx {
             &mut |_an, dc| {
                 let saved_cr = SavedCr::new(dc);
 
-                if let Some(_params) =
-                    saved_cr
-                        .draw_ctx
-                        .push_new_viewport(Some(vbox), rect, aspect, clip_mode)
-                {
+                if let Some(_params) = saved_cr.draw_ctx.push_new_viewport(
+                    Some(vbox),
+                    image.rect,
+                    image.aspect,
+                    clip_mode,
+                ) {
                     if values.is_visible() {
                         saved_cr
                             .draw_ctx
-                            .paint_surface(surface, image_width, image_height);
+                            .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(rect))
+                Ok(saved_cr.draw_ctx.empty_bbox().with_rect(image.rect))
             },
         )
     }
diff --git a/src/image.rs b/src/image.rs
index ef91a8fc..d13f92ec 100644
--- a/src/image.rs
+++ b/src/image.rs
@@ -9,8 +9,9 @@ use crate::drawing_ctx::DrawingCtx;
 use crate::element::{Draw, ElementResult, SetAttributes};
 use crate::error::*;
 use crate::href::{is_href, set_href};
+use crate::layout::{self, StackingContext};
 use crate::length::*;
-use crate::node::{CascadedValues, Node};
+use crate::node::{CascadedValues, Node, NodeBorrow};
 use crate::parsers::ParseValue;
 use crate::rect::Rect;
 use crate::xml::Attributes;
@@ -78,14 +79,20 @@ impl Draw for Image {
         let w = self.width.to_user(&params);
         let h = self.height.to_user(&params);
 
-        draw_ctx.draw_image(
-            &surface,
-            Rect::new(x, y, x + w, y + h),
-            self.aspect,
-            node,
-            acquired_nodes,
-            values,
-            clipping,
-        )
+        let rect = Rect::new(x, y, x + w, y + h);
+
+        let overflow = values.overflow();
+
+        let image = layout::Image {
+            surface,
+            rect,
+            aspect: self.aspect,
+            overflow,
+        };
+
+        let elt = node.borrow_element();
+        let stacking_ctx = StackingContext::new(acquired_nodes, &elt, elt.get_transform(), values);
+
+        draw_ctx.draw_image(&image, &stacking_ctx, acquired_nodes, values, clipping)
     }
 }
diff --git a/src/layout.rs b/src/layout.rs
index d2d4cf80..b488b8a0 100644
--- a/src/layout.rs
+++ b/src/layout.rs
@@ -4,6 +4,7 @@
 
 use std::rc::Rc;
 
+use crate::aspect_ratio::AspectRatio;
 use crate::coord_units::CoordUnits;
 use crate::dasharray::Dasharray;
 use crate::document::AcquiredNodes;
@@ -14,9 +15,11 @@ use crate::paint_server::PaintSource;
 use crate::path_builder::Path;
 use crate::properties::ComputedValues;
 use crate::property_defs::{
-    ClipRule, FillRule, Filter, MixBlendMode, Opacity, PaintOrder, ShapeRendering, StrokeDasharray,
-    StrokeLinecap, StrokeLinejoin, StrokeMiterlimit,
+    ClipRule, FillRule, Filter, MixBlendMode, Opacity, Overflow, PaintOrder, ShapeRendering,
+    StrokeDasharray, StrokeLinecap, StrokeLinejoin, StrokeMiterlimit,
 };
+use crate::rect::Rect;
+use crate::surface_utils::shared_surface::SharedImageSurface;
 use crate::transform::Transform;
 use crate::unit_interval::UnitInterval;
 
@@ -74,6 +77,14 @@ pub struct Shape {
     pub marker_end: Option<Node>,
 }
 
+/// Image in user-space coordinates.
+pub struct Image {
+    pub surface: SharedImageSurface,
+    pub rect: Rect,
+    pub aspect: AspectRatio,
+    pub overflow: Overflow,
+}
+
 impl StackingContext {
     pub fn new(
         acquired_nodes: &mut AcquiredNodes<'_>,


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