[librsvg: 21/45] Pass a session to the PaintServer.resolve() functions




commit 2c2f0d1b997f58664d9932a1d7c41a49e38e7929
Author: Federico Mena Quintero <federico gnome org>
Date:   Mon Aug 22 19:20:24 2022 -0500

    Pass a session to the PaintServer.resolve() functions
    
    Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/731>

 src/drawing_ctx.rs  |  2 ++
 src/paint_server.rs |  4 +++-
 src/pattern.rs      |  4 +++-
 src/shapes.rs       |  6 ++++--
 src/structure.rs    |  2 ++
 src/text.rs         | 20 ++++++++++++++++++--
 6 files changed, 32 insertions(+), 6 deletions(-)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index 93a6e03d7..9193d1429 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -806,6 +806,7 @@ impl DrawingCtx {
                                         current_color,
                                         None,
                                         None,
+                                        self.session(),
                                     )
                                     .to_user_space(&bbox, &params, values),
                             );
@@ -820,6 +821,7 @@ impl DrawingCtx {
                                         current_color,
                                         None,
                                         None,
+                                        self.session(),
                                     )
                                     .to_user_space(&bbox, &params, values),
                             );
diff --git a/src/paint_server.rs b/src/paint_server.rs
index a744c7286..bc699dae3 100644
--- a/src/paint_server.rs
+++ b/src/paint_server.rs
@@ -12,6 +12,7 @@ use crate::node::NodeBorrow;
 use crate::parsers::Parse;
 use crate::pattern::{ResolvedPattern, UserSpacePattern};
 use crate::properties::ComputedValues;
+use crate::session::Session;
 use crate::unit_interval::UnitInterval;
 use crate::util;
 
@@ -126,6 +127,7 @@ impl PaintServer {
         current_color: cssparser::RGBA,
         context_fill: Option<PaintSource>,
         context_stroke: Option<PaintSource>,
+        session: &Session,
     ) -> PaintSource {
         match self {
             PaintServer::Iri {
@@ -147,7 +149,7 @@ impl PaintServer {
                             })
                         }
                         Element::Pattern(ref p) => {
-                            p.resolve(node, acquired_nodes, opacity).map(|p| {
+                            p.resolve(node, acquired_nodes, opacity, session).map(|p| {
                                 PaintSource::Pattern(
                                     p,
                                     alternate.map(|c| resolve_color(&c, opacity, current_color)),
diff --git a/src/pattern.rs b/src/pattern.rs
index 42f6aeb3a..e14bb3e29 100644
--- a/src/pattern.rs
+++ b/src/pattern.rs
@@ -15,6 +15,7 @@ use crate::node::{Node, NodeBorrow, WeakNode};
 use crate::parsers::ParseValue;
 use crate::properties::ComputedValues;
 use crate::rect::Rect;
+use crate::session::Session;
 use crate::transform::{Transform, TransformAttribute};
 use crate::unit_interval::UnitInterval;
 use crate::viewbox::*;
@@ -436,6 +437,7 @@ impl Pattern {
         node: &Node,
         acquired_nodes: &mut AcquiredNodes<'_>,
         opacity: UnitInterval,
+        session: &Session,
     ) -> Result<ResolvedPattern, AcquireError> {
         let Unresolved {
             mut pattern,
@@ -471,7 +473,7 @@ impl Pattern {
                     }
 
                     Err(e) => {
-                        rsvg_log!("Stopping pattern resolution: {}", e);
+                        rsvg_log_session!(session, "Stopping pattern resolution: {}", e);
                         pattern = pattern.resolve_from_defaults();
                         break;
                     }
diff --git a/src/shapes.rs b/src/shapes.rs
index 7cc8c5bba..b617da9e8 100644
--- a/src/shapes.rs
+++ b/src/shapes.rs
@@ -63,12 +63,15 @@ macro_rules! impl_draw {
 
                 let stroke = Stroke::new(values, &params);
 
+                let session = draw_ctx.session();
+
                 let stroke_paint = values.stroke().0.resolve(
                     acquired_nodes,
                     values.stroke_opacity().0,
                     values.color().0,
                     cascaded.context_fill.clone(),
                     cascaded.context_stroke.clone(),
+                    session,
                 );
 
                 let fill_paint = values.fill().0.resolve(
@@ -77,6 +80,7 @@ macro_rules! impl_draw {
                     values.color().0,
                     cascaded.context_fill.clone(),
                     cascaded.context_stroke.clone(),
+                    session,
                 );
 
                 let fill_rule = values.fill_rule();
@@ -87,8 +91,6 @@ macro_rules! impl_draw {
                 let marker_mid_node;
                 let marker_end_node;
 
-                let session = draw_ctx.session();
-
                 if shape_def.markers == Markers::Yes {
                     marker_start_node =
                         acquire_marker(session, acquired_nodes, &values.marker_start().0);
diff --git a/src/structure.rs b/src/structure.rs
index dac71a52c..8fb48c1be 100644
--- a/src/structure.rs
+++ b/src/structure.rs
@@ -368,6 +368,7 @@ impl Draw for Use {
                 values.color().0,
                 cascaded.context_fill.clone(),
                 cascaded.context_stroke.clone(),
+                draw_ctx.session(),
             );
 
             let fill_paint = values.fill().0.resolve(
@@ -376,6 +377,7 @@ impl Draw for Use {
                 values.color().0,
                 cascaded.context_fill.clone(),
                 cascaded.context_stroke.clone(),
+                draw_ctx.session(),
             );
 
             draw_ctx.draw_from_use_node(
diff --git a/src/text.rs b/src/text.rs
index a635b71b2..b4f77e3b1 100644
--- a/src/text.rs
+++ b/src/text.rs
@@ -21,6 +21,7 @@ use crate::properties::{
     TextAnchor, TextRendering, UnicodeBidi, WritingMode, XmlLang, XmlSpace,
 };
 use crate::rect::Rect;
+use crate::session::Session;
 use crate::space::{xml_space_normalize, NormalizeDefault, XmlSpaceNormalize};
 use crate::transform::Transform;
 use crate::xml::Attributes;
@@ -38,6 +39,9 @@ struct LayoutContext {
 
     /// For normalizing lengths.
     view_params: ViewParams,
+
+    /// Session metadata for the document
+    session: Session,
 }
 
 /// An absolutely-positioned array of `Span`s
@@ -451,6 +455,7 @@ impl PositionedSpan {
             self.values.color().0,
             None,
             None,
+            &layout_context.session,
         );
 
         let fill_paint = self.values.fill().0.resolve(
@@ -459,6 +464,7 @@ impl PositionedSpan {
             self.values.color().0,
             None,
             None,
+            &layout_context.session,
         );
 
         let paint_order = self.values.paint_order();
@@ -556,7 +562,14 @@ fn children_to_chunks(
 
                 Element::TRef(ref tref) => {
                     let cascaded = CascadedValues::clone_with_node(cascaded, &child);
-                    tref.to_chunks(&child, acquired_nodes, &cascaded, chunks, depth + 1);
+                    tref.to_chunks(
+                        &child,
+                        acquired_nodes,
+                        &cascaded,
+                        chunks,
+                        depth + 1,
+                        layout_context,
+                    );
                 }
 
                 _ => (),
@@ -763,6 +776,7 @@ impl Draw for Text {
                     transform: *transform,
                     font_options: dc.get_font_options(),
                     view_params: dc.get_view_params(),
+                    session: dc.session().clone(),
                 };
 
                 let mut x = self.x.to_user(&params);
@@ -859,6 +873,7 @@ impl TRef {
         cascaded: &CascadedValues<'_>,
         chunks: &mut Vec<Chunk>,
         depth: usize,
+        layout_context: &LayoutContext,
     ) {
         if self.link.is_none() {
             return;
@@ -875,7 +890,8 @@ impl TRef {
             let c = acquired.get();
             extract_chars_children_to_chunks_recursively(chunks, c, Rc::new(values.clone()), depth);
         } else {
-            rsvg_log!(
+            rsvg_log_session!(
+                layout_context.session,
                 "element {} references a nonexistent text source \"{}\"",
                 node,
                 link,


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