[librsvg: 16/31] ViewParams::with_units - Allow creating a ViewParams from another one
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 16/31] ViewParams::with_units - Allow creating a ViewParams from another one
- Date: Thu, 3 Jun 2021 02:27:10 +0000 (UTC)
commit 0066fc1d1ac3a18df54a04b9888638da9e64e7b6
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Jun 2 18:32:59 2021 -0500
ViewParams::with_units - Allow creating a ViewParams from another one
Now that we don't push a coordinate system except in a single place,
the rest of the code doesn't need the whole DrawingCtx just to get the
ViewParams for a particular CoordUnits.
src/drawing_ctx.rs | 24 +++++++++++++++++++++---
src/gradient.rs | 6 +++---
src/paint_server.rs | 8 ++++----
src/pattern.rs | 8 ++++----
4 files changed, 32 insertions(+), 14 deletions(-)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index c24f0f80..90162318 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -68,6 +68,22 @@ impl ViewParams {
viewport_stack: None,
}
}
+
+ pub fn with_units(&self, units: CoordUnits) -> ViewParams {
+ match units {
+ CoordUnits::ObjectBoundingBox => ViewParams {
+ dpi: self.dpi,
+ vbox: ViewBox::from(Rect::from_size(1.0, 1.0)),
+ viewport_stack: None,
+ },
+
+ CoordUnits::UserSpaceOnUse => ViewParams {
+ dpi: self.dpi,
+ vbox: self.vbox,
+ viewport_stack: None,
+ },
+ }
+ }
}
impl Drop for ViewParams {
@@ -731,12 +747,14 @@ impl DrawingCtx {
let current_color = values.color().0;
+ let params = temporary_draw_ctx.get_view_params();
+
let stroke_paint_source = Rc::new(
values
.stroke()
.0
.resolve(acquired_nodes, values.stroke_opacity().0, current_color)
- .to_user_space(&bbox, &temporary_draw_ctx, values),
+ .to_user_space(&bbox, ¶ms, values),
);
let fill_paint_source = Rc::new(
@@ -744,7 +762,7 @@ impl DrawingCtx {
.fill()
.0
.resolve(acquired_nodes, values.fill_opacity().0, current_color)
- .to_user_space(&bbox, &temporary_draw_ctx, values),
+ .to_user_space(&bbox, ¶ms, values),
);
// Filter functions (like "blend()", not the <filter> element) require
@@ -753,7 +771,7 @@ impl DrawingCtx {
// here and pass them down.
let user_space_params = NormalizeParams::new(
values,
- &temporary_draw_ctx.get_view_params_for_units(CoordUnits::UserSpaceOnUse),
+ ¶ms.with_units(CoordUnits::UserSpaceOnUse),
);
(
diff --git a/src/gradient.rs b/src/gradient.rs
index 6f5130b9..fa61796d 100644
--- a/src/gradient.rs
+++ b/src/gradient.rs
@@ -8,7 +8,7 @@ use markup5ever::{
use crate::bbox::BoundingBox;
use crate::coord_units::CoordUnits;
use crate::document::{AcquiredNodes, NodeId, NodeStack};
-use crate::drawing_ctx::DrawingCtx;
+use crate::drawing_ctx::{DrawingCtx, ViewParams};
use crate::element::{Draw, Element, ElementResult, SetAttributes};
use crate::error::*;
use crate::href::{is_href, set_href};
@@ -682,7 +682,7 @@ impl ResolvedGradient {
pub fn to_user_space(
&self,
bbox: &BoundingBox,
- draw_ctx: &DrawingCtx,
+ current_params: &ViewParams,
values: &ComputedValues,
) -> Option<UserSpaceGradient> {
let units = self.units.0;
@@ -692,7 +692,7 @@ impl ResolvedGradient {
return None;
};
- let view_params = draw_ctx.get_view_params_for_units(units);
+ let view_params = current_params.with_units(units);
let params = NormalizeParams::new(values, &view_params);
let transform = transform.pre_transform(&self.transform).invert()?;
diff --git a/src/paint_server.rs b/src/paint_server.rs
index 8ac01795..3fa6812d 100644
--- a/src/paint_server.rs
+++ b/src/paint_server.rs
@@ -4,7 +4,7 @@ use cssparser::Parser;
use crate::bbox::BoundingBox;
use crate::document::{AcquiredNodes, NodeId};
-use crate::drawing_ctx::DrawingCtx;
+use crate::drawing_ctx::{DrawingCtx, ViewParams};
use crate::element::Element;
use crate::error::{AcquireError, NodeIdError, ParseError, ValueErrorKind};
use crate::gradient::{ResolvedGradient, UserSpaceGradient};
@@ -193,20 +193,20 @@ impl PaintSource {
pub fn to_user_space(
&self,
bbox: &BoundingBox,
- draw_ctx: &DrawingCtx,
+ current_params: &ViewParams,
values: &ComputedValues,
) -> UserSpacePaintSource {
match *self {
PaintSource::None => UserSpacePaintSource::None,
PaintSource::SolidColor(c) => UserSpacePaintSource::SolidColor(c),
- PaintSource::Gradient(ref g, c) => match (g.to_user_space(bbox, draw_ctx, values), c) {
+ PaintSource::Gradient(ref g, c) => match (g.to_user_space(bbox, current_params, values), c) {
(Some(gradient), c) => UserSpacePaintSource::Gradient(gradient, c),
(None, Some(c)) => UserSpacePaintSource::SolidColor(c),
(None, None) => UserSpacePaintSource::None,
},
- PaintSource::Pattern(ref p, c) => match (p.to_user_space(bbox, draw_ctx, values), c) {
+ PaintSource::Pattern(ref p, c) => match (p.to_user_space(bbox, current_params, values), c) {
(Some(pattern), c) => UserSpacePaintSource::Pattern(pattern, c),
(None, Some(c)) => UserSpacePaintSource::SolidColor(c),
(None, None) => UserSpacePaintSource::None,
diff --git a/src/pattern.rs b/src/pattern.rs
index c33ba11d..63316a01 100644
--- a/src/pattern.rs
+++ b/src/pattern.rs
@@ -6,7 +6,7 @@ use crate::aspect_ratio::*;
use crate::bbox::BoundingBox;
use crate::coord_units::CoordUnits;
use crate::document::{AcquiredNodes, NodeId, NodeStack};
-use crate::drawing_ctx::DrawingCtx;
+use crate::drawing_ctx::{DrawingCtx, ViewParams};
use crate::element::{Draw, Element, ElementResult, SetAttributes};
use crate::error::*;
use crate::href::{is_href, set_href};
@@ -327,13 +327,13 @@ impl ResolvedPattern {
pub fn to_user_space(
&self,
bbox: &BoundingBox,
- draw_ctx: &DrawingCtx,
+ current_params: &ViewParams,
values: &ComputedValues,
) -> Option<UserSpacePattern> {
let node_with_children = self.node_with_children()?;
- let params =
- NormalizeParams::new(values, &draw_ctx.get_view_params_for_units(self.units.0));
+ let view_params = current_params.with_units(self.units.0);
+ let params = NormalizeParams::new(values, &view_params);
let rect = self.get_rect(¶ms);
let bbrect = bbox.rect.unwrap();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]