[librsvg: 5/9] layout::Shape: keep UserSpacePaintSource for stroke and fill, not PaintSource




commit 011ee5cd792b8be2c441cf0c207c50bc70f164b6
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Oct 5 21:17:09 2022 -0500

    layout::Shape: keep UserSpacePaintSource for stroke and fill, not PaintSource
    
    Now that shapes can compute their extents, they can very well
    normalize their paint sources into UserSpacePaintSource.
    
    While we are at it, make layout::Text also not carry a duplicated
    stroke_paint_source, by making compute_stroke_and_fill_box() take a
    user-space one.
    
    Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/757>

 src/drawing_ctx.rs | 22 ++++++----------------
 src/layout.rs      |  5 ++---
 src/shapes.rs      | 12 ++++--------
 src/text.rs        |  1 -
 4 files changed, 12 insertions(+), 28 deletions(-)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index c2b670b5b..fc458798a 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -1273,7 +1273,6 @@ impl DrawingCtx {
 
     pub fn draw_shape(
         &mut self,
-        view_params: &ViewParams,
         shape: &Shape,
         stacking_ctx: &StackingContext,
         acquired_nodes: &mut AcquiredNodes<'_>,
@@ -1317,15 +1316,6 @@ impl DrawingCtx {
                     &dc.initial_viewport,
                 )?;
 
-                let stroke_paint =
-                    shape
-                        .stroke_paint
-                        .to_user_space(&shape.extents, view_params, values);
-                let fill_paint =
-                    shape
-                        .fill_paint
-                        .to_user_space(&shape.extents, view_params, values);
-
                 if shape.is_visible {
                     for &target in &shape.paint_order.targets {
                         // fill and stroke operations will preserve the path.
@@ -1333,7 +1323,7 @@ impl DrawingCtx {
                         match target {
                             PaintTarget::Fill => {
                                 path_helper.set()?;
-                                dc.fill(&cr, an, &fill_paint)?;
+                                dc.fill(&cr, an, &shape.fill_paint)?;
                             }
 
                             PaintTarget::Stroke => {
@@ -1345,7 +1335,7 @@ impl DrawingCtx {
                                 } else {
                                     None
                                 };
-                                dc.stroke(&cr, an, &stroke_paint)?;
+                                dc.stroke(&cr, an, &shape.stroke_paint)?;
                                 if let Some(matrix) = backup_matrix {
                                     cr.set_matrix(matrix);
                                 }
@@ -1479,7 +1469,7 @@ impl DrawingCtx {
             let bbox = compute_stroke_and_fill_box(
                 &self.cr,
                 &span.stroke,
-                &span.stroke_paint_source,
+                &span.stroke_paint,
                 &self.initial_viewport,
             )?;
             self.cr.new_path();
@@ -2027,7 +2017,7 @@ impl CompositingAffines {
 fn compute_stroke_and_fill_extents(
     cr: &cairo::Context,
     stroke: &Stroke,
-    stroke_paint_source: &PaintSource,
+    stroke_paint_source: &UserSpacePaintSource,
     initial_viewport: &Viewport,
 ) -> Result<PathExtents, RenderingError> {
     // Dropping the precision of cairo's bezier subdivision, yielding 2x
@@ -2059,7 +2049,7 @@ fn compute_stroke_and_fill_extents(
     // bounding box if so.
 
     let stroke_extents = if !stroke.width.approx_eq_cairo(0.0)
-        && !matches!(stroke_paint_source, PaintSource::None)
+        && !matches!(stroke_paint_source, UserSpacePaintSource::None)
     {
         let backup_matrix = if stroke.non_scaling {
             let matrix = cr.matrix();
@@ -2096,7 +2086,7 @@ fn compute_stroke_and_fill_extents(
 fn compute_stroke_and_fill_box(
     cr: &cairo::Context,
     stroke: &Stroke,
-    stroke_paint_source: &PaintSource,
+    stroke_paint_source: &UserSpacePaintSource,
     initial_viewport: &Viewport,
 ) -> Result<BoundingBox, RenderingError> {
     let extents =
diff --git a/src/layout.rs b/src/layout.rs
index 465b202d8..79c5ca3f3 100644
--- a/src/layout.rs
+++ b/src/layout.rs
@@ -78,8 +78,8 @@ pub struct Shape {
     pub is_visible: bool,
     pub paint_order: PaintOrder,
     pub stroke: Stroke,
-    pub stroke_paint: Arc<PaintSource>,
-    pub fill_paint: Arc<PaintSource>,
+    pub stroke_paint: UserSpacePaintSource,
+    pub fill_paint: UserSpacePaintSource,
     pub fill_rule: FillRule,
     pub clip_rule: ClipRule,
     pub shape_rendering: ShapeRendering,
@@ -114,7 +114,6 @@ pub struct TextSpan {
     pub paint_order: PaintOrder,
     pub stroke: Stroke,
     pub stroke_paint: UserSpacePaintSource,
-    pub stroke_paint_source: Arc<PaintSource>,
     pub fill_paint: UserSpacePaintSource,
     pub text_rendering: TextRendering,
     pub link_target: Option<String>,
diff --git a/src/shapes.rs b/src/shapes.rs
index 2d26bbdec..ad8e3259c 100644
--- a/src/shapes.rs
+++ b/src/shapes.rs
@@ -118,6 +118,9 @@ fn draw_basic_shape(
 
     let extents = draw_ctx.compute_path_extents(&shape_def.path)?;
 
+    let stroke_paint = stroke_paint.to_user_space(&extents, &view_params, values);
+    let fill_paint = fill_paint.to_user_space(&extents, &view_params, values);
+
     let shape = Shape {
         path: shape_def.path,
         extents,
@@ -143,14 +146,7 @@ fn draw_basic_shape(
         values,
     );
 
-    draw_ctx.draw_shape(
-        &view_params,
-        &shape,
-        &stacking_ctx,
-        acquired_nodes,
-        values,
-        clipping,
-    )
+    draw_ctx.draw_shape(&shape, &stacking_ctx, acquired_nodes, values, clipping)
 }
 
 macro_rules! impl_draw {
diff --git a/src/text.rs b/src/text.rs
index 0b6575183..6115d09a0 100644
--- a/src/text.rs
+++ b/src/text.rs
@@ -850,7 +850,6 @@ impl Draw for Text {
                         paint_order: span.paint_order,
                         stroke: span.stroke,
                         stroke_paint,
-                        stroke_paint_source: span.stroke_paint,
                         fill_paint,
                         text_rendering: span.text_rendering,
                         link_target: span.link_target,


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