[librsvg] filters/* - Use AttributeResultExt's .attribute() instead of a more verbose .map_err()
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] filters/* - Use AttributeResultExt's .attribute() instead of a more verbose .map_err()
- Date: Tue, 4 Jun 2019 23:00:29 +0000 (UTC)
commit ca9d028e69b469e8d772dc8e19cf26700057bf03
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Jun 4 17:59:47 2019 -0500
filters/* - Use AttributeResultExt's .attribute() instead of a more verbose .map_err()
rsvg_internals/src/filters/color_matrix.rs | 6 +-
rsvg_internals/src/filters/component_transfer.rs | 12 ++--
rsvg_internals/src/filters/composite.rs | 10 +--
rsvg_internals/src/filters/convolve_matrix.rs | 14 ++---
rsvg_internals/src/filters/displacement_map.rs | 4 +-
rsvg_internals/src/filters/gaussian_blur.rs | 4 +-
rsvg_internals/src/filters/light/light_source.rs | 79 ++++++++----------------
rsvg_internals/src/filters/light/lighting.rs | 12 ++--
rsvg_internals/src/filters/morphology.rs | 4 +-
rsvg_internals/src/filters/offset.rs | 6 +-
rsvg_internals/src/filters/turbulence.rs | 8 +--
11 files changed, 66 insertions(+), 93 deletions(-)
---
diff --git a/rsvg_internals/src/filters/color_matrix.rs b/rsvg_internals/src/filters/color_matrix.rs
index 3f2920c3..6bda603b 100644
--- a/rsvg_internals/src/filters/color_matrix.rs
+++ b/rsvg_internals/src/filters/color_matrix.rs
@@ -5,7 +5,7 @@ use markup5ever::{local_name, LocalName};
use nalgebra::{Matrix3, Matrix4x5, Matrix5, Vector5};
use crate::drawing_ctx::DrawingCtx;
-use crate::error::NodeError;
+use crate::error::{AttributeResultExt, NodeError};
use crate::node::{NodeResult, NodeTrait, RsvgNode};
use crate::number_list::{NumberList, NumberListError, NumberListLength};
use crate::parsers::{self, ParseError};
@@ -102,7 +102,7 @@ impl NodeTrait for ColorMatrix {
}
OperationType::Saturate => {
let s = parsers::number(value)
- .map_err(|err| NodeError::attribute_error(attr.clone(), err))?;
+ .attribute(attr.clone())?;
if s < 0.0 || s > 1.0 {
return Err(NodeError::value_error(attr, "expected value from 0 to 1"));
}
@@ -118,7 +118,7 @@ impl NodeTrait for ColorMatrix {
}
OperationType::HueRotate => {
let degrees = parsers::number(value)
- .map_err(|err| NodeError::attribute_error(attr, err))?;
+ .attribute(attr.clone())?;
let (sin, cos) = degrees.to_radians().sin_cos();
diff --git a/rsvg_internals/src/filters/component_transfer.rs
b/rsvg_internals/src/filters/component_transfer.rs
index 9351663b..c36a6212 100644
--- a/rsvg_internals/src/filters/component_transfer.rs
+++ b/rsvg_internals/src/filters/component_transfer.rs
@@ -5,7 +5,7 @@ use cairo::{self, ImageSurface};
use markup5ever::{local_name, LocalName};
use crate::drawing_ctx::DrawingCtx;
-use crate::error::NodeError;
+use crate::error::{AttributeResultExt, NodeError};
use crate::node::{NodeResult, NodeTrait, NodeType, RsvgNode};
use crate::number_list::{NumberList, NumberListError, NumberListLength};
use crate::parsers::{self, ParseError};
@@ -228,19 +228,19 @@ impl NodeTrait for FuncX {
self.table_values.replace(v);
}
local_name!("slope") => self.slope.set(
- parsers::number(value).map_err(|err| NodeError::attribute_error(attr, err))?,
+ parsers::number(value).attribute(attr)?,
),
local_name!("intercept") => self.intercept.set(
- parsers::number(value).map_err(|err| NodeError::attribute_error(attr, err))?,
+ parsers::number(value).attribute(attr)?,
),
local_name!("amplitude") => self.amplitude.set(
- parsers::number(value).map_err(|err| NodeError::attribute_error(attr, err))?,
+ parsers::number(value).attribute(attr)?,
),
local_name!("exponent") => self.exponent.set(
- parsers::number(value).map_err(|err| NodeError::attribute_error(attr, err))?,
+ parsers::number(value).attribute(attr)?,
),
local_name!("offset") => self.offset.set(
- parsers::number(value).map_err(|err| NodeError::attribute_error(attr, err))?,
+ parsers::number(value).attribute(attr)?,
),
_ => (),
}
diff --git a/rsvg_internals/src/filters/composite.rs b/rsvg_internals/src/filters/composite.rs
index 73c6c4a1..9ee4bf22 100644
--- a/rsvg_internals/src/filters/composite.rs
+++ b/rsvg_internals/src/filters/composite.rs
@@ -5,7 +5,7 @@ use cssparser::{CowRcStr, Parser, Token};
use markup5ever::local_name;
use crate::drawing_ctx::DrawingCtx;
-use crate::error::{NodeError, ValueErrorKind};
+use crate::error::{AttributeResultExt, ValueErrorKind};
use crate::node::{NodeResult, NodeTrait, RsvgNode};
use crate::parsers::{self, Parse, ParseValue};
use crate::property_bag::PropertyBag;
@@ -73,16 +73,16 @@ impl NodeTrait for Composite {
}
local_name!("operator") => self.operator.set(attr.parse(value)?),
local_name!("k1") => self.k1.set(
- parsers::number(value).map_err(|err| NodeError::attribute_error(attr, err))?,
+ parsers::number(value).attribute(attr)?,
),
local_name!("k2") => self.k2.set(
- parsers::number(value).map_err(|err| NodeError::attribute_error(attr, err))?,
+ parsers::number(value).attribute(attr)?,
),
local_name!("k3") => self.k3.set(
- parsers::number(value).map_err(|err| NodeError::attribute_error(attr, err))?,
+ parsers::number(value).attribute(attr)?,
),
local_name!("k4") => self.k4.set(
- parsers::number(value).map_err(|err| NodeError::attribute_error(attr, err))?,
+ parsers::number(value).attribute(attr)?,
),
_ => (),
}
diff --git a/rsvg_internals/src/filters/convolve_matrix.rs b/rsvg_internals/src/filters/convolve_matrix.rs
index e1fa4bcb..a7e69849 100644
--- a/rsvg_internals/src/filters/convolve_matrix.rs
+++ b/rsvg_internals/src/filters/convolve_matrix.rs
@@ -5,7 +5,7 @@ use markup5ever::{local_name, LocalName};
use nalgebra::{DMatrix, Dynamic, VecStorage};
use crate::drawing_ctx::DrawingCtx;
-use crate::error::NodeError;
+use crate::error::{AttributeResultExt, NodeError};
use crate::node::{NodeResult, NodeTrait, RsvgNode};
use crate::number_list::{NumberList, NumberListError, NumberListLength};
use crate::parsers::{self, ParseError};
@@ -66,7 +66,7 @@ impl NodeTrait for ConvolveMatrix {
match attr {
local_name!("order") => self.order.set(
parsers::integer_optional_integer(value)
- .map_err(|err| NodeError::attribute_error(attr.clone(), err))
+ .attribute(attr.clone())
.and_then(|(x, y)| {
if x > 0 && y > 0 {
Ok((x as u32, y as u32))
@@ -80,7 +80,7 @@ impl NodeTrait for ConvolveMatrix {
),
local_name!("divisor") => self.divisor.set(Some(
parsers::number(value)
- .map_err(|err| NodeError::attribute_error(attr.clone(), err))
+ .attribute(attr.clone())
.and_then(|x| {
if x != 0.0 {
Ok(x)
@@ -90,12 +90,12 @@ impl NodeTrait for ConvolveMatrix {
})?,
)),
local_name!("bias") => self.bias.set(
- parsers::number(value).map_err(|err| NodeError::attribute_error(attr, err))?,
+ parsers::number(value).attribute(attr)?,
),
local_name!("edgeMode") => self.edge_mode.set(EdgeMode::parse(attr, value)?),
local_name!("kernelUnitLength") => self.kernel_unit_length.set(Some(
parsers::number_optional_number(value)
- .map_err(|err| NodeError::attribute_error(attr.clone(), err))
+ .attribute(attr.clone())
.and_then(|(x, y)| {
if x > 0.0 && y > 0.0 {
Ok((x, y))
@@ -126,7 +126,7 @@ impl NodeTrait for ConvolveMatrix {
match attr {
local_name!("targetX") => self.target_x.set(Some(
parsers::integer(value)
- .map_err(|err| NodeError::attribute_error(attr.clone(), err))
+ .attribute(attr.clone())
.and_then(|x| {
if x >= 0 && x < self.order.get().0 as i32 {
Ok(x as u32)
@@ -140,7 +140,7 @@ impl NodeTrait for ConvolveMatrix {
)),
local_name!("targetY") => self.target_y.set(Some(
parsers::integer(value)
- .map_err(|err| NodeError::attribute_error(attr.clone(), err))
+ .attribute(attr.clone())
.and_then(|x| {
if x >= 0 && x < self.order.get().1 as i32 {
Ok(x as u32)
diff --git a/rsvg_internals/src/filters/displacement_map.rs b/rsvg_internals/src/filters/displacement_map.rs
index 60c72385..58cbf488 100644
--- a/rsvg_internals/src/filters/displacement_map.rs
+++ b/rsvg_internals/src/filters/displacement_map.rs
@@ -4,7 +4,7 @@ use cairo::{self, ImageSurface, MatrixTrait};
use markup5ever::{local_name, LocalName};
use crate::drawing_ctx::DrawingCtx;
-use crate::error::NodeError;
+use crate::error::{AttributeResultExt, NodeError};
use crate::node::{NodeResult, NodeTrait, RsvgNode};
use crate::parsers::{self, ParseError};
use crate::property_bag::PropertyBag;
@@ -57,7 +57,7 @@ impl NodeTrait for DisplacementMap {
self.in2.replace(Some(Input::parse(attr, value)?));
}
local_name!("scale") => self.scale.set(
- parsers::number(value).map_err(|err| NodeError::attribute_error(attr, err))?,
+ parsers::number(value).attribute(attr)?,
),
local_name!("xChannelSelector") => self
.x_channel_selector
diff --git a/rsvg_internals/src/filters/gaussian_blur.rs b/rsvg_internals/src/filters/gaussian_blur.rs
index e41ea7a1..1ed55fd2 100644
--- a/rsvg_internals/src/filters/gaussian_blur.rs
+++ b/rsvg_internals/src/filters/gaussian_blur.rs
@@ -7,7 +7,7 @@ use markup5ever::local_name;
use nalgebra::{DMatrix, Dynamic, VecStorage};
use crate::drawing_ctx::DrawingCtx;
-use crate::error::NodeError;
+use crate::error::{AttributeResultExt, NodeError};
use crate::node::{NodeResult, NodeTrait, RsvgNode};
use crate::parsers;
use crate::property_bag::PropertyBag;
@@ -52,7 +52,7 @@ impl NodeTrait for GaussianBlur {
match attr {
local_name!("stdDeviation") => self.std_deviation.set(
parsers::number_optional_number(value)
- .map_err(|err| NodeError::attribute_error(attr.clone(), err))
+ .attribute(attr.clone())
.and_then(|(x, y)| {
if x >= 0.0 && y >= 0.0 {
Ok((x, y))
diff --git a/rsvg_internals/src/filters/light/light_source.rs
b/rsvg_internals/src/filters/light/light_source.rs
index 7cd75cd0..c4399bb3 100644
--- a/rsvg_internals/src/filters/light/light_source.rs
+++ b/rsvg_internals/src/filters/light/light_source.rs
@@ -5,7 +5,7 @@ use cssparser;
use markup5ever::local_name;
use nalgebra::Vector3;
-use crate::error::NodeError;
+use crate::error::AttributeResultExt;
use crate::filters::context::FilterContext;
use crate::node::{NodeResult, NodeTrait, RsvgNode};
use crate::parsers;
@@ -207,14 +207,10 @@ impl NodeTrait for LightSource {
ref azimuth,
ref elevation,
} => match attr {
- local_name!("azimuth") => azimuth.set(
- parsers::number(value)
- .map_err(|err| NodeError::attribute_error(attr, err))?,
- ),
- local_name!("elevation") => elevation.set(
- parsers::number(value)
- .map_err(|err| NodeError::attribute_error(attr, err))?,
- ),
+ local_name!("azimuth") => azimuth.set(parsers::number(value).attribute(attr)?),
+ local_name!("elevation") => {
+ elevation.set(parsers::number(value).attribute(attr)?)
+ }
_ => (),
},
LightSource::Point {
@@ -222,18 +218,9 @@ impl NodeTrait for LightSource {
ref y,
ref z,
} => match attr {
- local_name!("x") => x.set(
- parsers::number(value)
- .map_err(|err| NodeError::attribute_error(attr, err))?,
- ),
- local_name!("y") => y.set(
- parsers::number(value)
- .map_err(|err| NodeError::attribute_error(attr, err))?,
- ),
- local_name!("z") => z.set(
- parsers::number(value)
- .map_err(|err| NodeError::attribute_error(attr, err))?,
- ),
+ local_name!("x") => x.set(parsers::number(value).attribute(attr)?),
+ local_name!("y") => y.set(parsers::number(value).attribute(attr)?),
+ local_name!("z") => z.set(parsers::number(value).attribute(attr)?),
_ => (),
},
LightSource::Spot {
@@ -246,38 +233,24 @@ impl NodeTrait for LightSource {
ref specular_exponent,
ref limiting_cone_angle,
} => match attr {
- local_name!("x") => x.set(
- parsers::number(value)
- .map_err(|err| NodeError::attribute_error(attr, err))?,
- ),
- local_name!("y") => y.set(
- parsers::number(value)
- .map_err(|err| NodeError::attribute_error(attr, err))?,
- ),
- local_name!("z") => z.set(
- parsers::number(value)
- .map_err(|err| NodeError::attribute_error(attr, err))?,
- ),
- local_name!("pointsAtX") => points_at_x.set(
- parsers::number(value)
- .map_err(|err| NodeError::attribute_error(attr, err))?,
- ),
- local_name!("pointsAtY") => points_at_y.set(
- parsers::number(value)
- .map_err(|err| NodeError::attribute_error(attr, err))?,
- ),
- local_name!("pointsAtZ") => points_at_z.set(
- parsers::number(value)
- .map_err(|err| NodeError::attribute_error(attr, err))?,
- ),
- local_name!("specularExponent") => specular_exponent.set(
- parsers::number(value)
- .map_err(|err| NodeError::attribute_error(attr, err))?,
- ),
- local_name!("limitingConeAngle") => limiting_cone_angle.set(Some(
- parsers::number(value)
- .map_err(|err| NodeError::attribute_error(attr, err))?,
- )),
+ local_name!("x") => x.set(parsers::number(value).attribute(attr)?),
+ local_name!("y") => y.set(parsers::number(value).attribute(attr)?),
+ local_name!("z") => z.set(parsers::number(value).attribute(attr)?),
+ local_name!("pointsAtX") => {
+ points_at_x.set(parsers::number(value).attribute(attr)?)
+ }
+ local_name!("pointsAtY") => {
+ points_at_y.set(parsers::number(value).attribute(attr)?)
+ }
+ local_name!("pointsAtZ") => {
+ points_at_z.set(parsers::number(value).attribute(attr)?)
+ }
+ local_name!("specularExponent") => {
+ specular_exponent.set(parsers::number(value).attribute(attr)?)
+ }
+ local_name!("limitingConeAngle") => {
+ limiting_cone_angle.set(Some(parsers::number(value).attribute(attr)?))
+ }
_ => (),
},
}
diff --git a/rsvg_internals/src/filters/light/lighting.rs b/rsvg_internals/src/filters/light/lighting.rs
index bc8fc88a..ae23f8cd 100644
--- a/rsvg_internals/src/filters/light/lighting.rs
+++ b/rsvg_internals/src/filters/light/lighting.rs
@@ -9,7 +9,7 @@ use num_traits::identities::Zero;
use rayon::prelude::*;
use crate::drawing_ctx::DrawingCtx;
-use crate::error::NodeError;
+use crate::error::{AttributeResultExt, NodeError};
use crate::filters::{
context::{FilterContext, FilterOutput, FilterResult},
light::{
@@ -105,11 +105,11 @@ impl NodeTrait for Lighting {
for (attr, value) in pbag.iter() {
match attr {
local_name!("surfaceScale") => self.surface_scale.set(
- parsers::number(value).map_err(|err| NodeError::attribute_error(attr, err))?,
+ parsers::number(value).attribute(attr)?,
),
local_name!("kernelUnitLength") => self.kernel_unit_length.set(Some(
parsers::number_optional_number(value)
- .map_err(|err| NodeError::attribute_error(attr.clone(), err))
+ .attribute(attr.clone())
.and_then(|(x, y)| {
if x > 0.0 && y > 0.0 {
Ok((x, y))
@@ -133,7 +133,7 @@ impl NodeTrait for Lighting {
match attr {
local_name!("diffuseConstant") => diffuse_constant.set(
parsers::number(value)
- .map_err(|err| NodeError::attribute_error(attr.clone(), err))
+ .attribute(attr.clone())
.and_then(|x| {
if x >= 0.0 {
Ok(x)
@@ -157,7 +157,7 @@ impl NodeTrait for Lighting {
match attr {
local_name!("specularConstant") => specular_constant.set(
parsers::number(value)
- .map_err(|err| NodeError::attribute_error(attr.clone(), err))
+ .attribute(attr.clone())
.and_then(|x| {
if x >= 0.0 {
Ok(x)
@@ -171,7 +171,7 @@ impl NodeTrait for Lighting {
),
local_name!("specularExponent") => specular_exponent.set(
parsers::number(value)
- .map_err(|err| NodeError::attribute_error(attr.clone(), err))
+ .attribute(attr.clone())
.and_then(|x| {
if x >= 1.0 && x <= 128.0 {
Ok(x)
diff --git a/rsvg_internals/src/filters/morphology.rs b/rsvg_internals/src/filters/morphology.rs
index 6d7dd87e..763737af 100644
--- a/rsvg_internals/src/filters/morphology.rs
+++ b/rsvg_internals/src/filters/morphology.rs
@@ -5,7 +5,7 @@ use cairo::{self, ImageSurface, MatrixTrait};
use markup5ever::{local_name, LocalName};
use crate::drawing_ctx::DrawingCtx;
-use crate::error::NodeError;
+use crate::error::{AttributeResultExt, NodeError};
use crate::node::{NodeResult, NodeTrait, RsvgNode};
use crate::parsers::{self, ParseError};
use crate::property_bag::PropertyBag;
@@ -58,7 +58,7 @@ impl NodeTrait for Morphology {
local_name!("operator") => self.operator.set(Operator::parse(attr, value)?),
local_name!("radius") => self.radius.set(
parsers::number_optional_number(value)
- .map_err(|err| NodeError::attribute_error(attr.clone(), err))
+ .attribute(attr.clone())
.and_then(|(x, y)| {
if x >= 0.0 && y >= 0.0 {
Ok((x, y))
diff --git a/rsvg_internals/src/filters/offset.rs b/rsvg_internals/src/filters/offset.rs
index cef0e7e7..58e4faf7 100644
--- a/rsvg_internals/src/filters/offset.rs
+++ b/rsvg_internals/src/filters/offset.rs
@@ -3,7 +3,7 @@ use cairo::{self, ImageSurface, MatrixTrait};
use std::cell::Cell;
use crate::drawing_ctx::DrawingCtx;
-use crate::error::NodeError;
+use crate::error::AttributeResultExt;
use crate::node::{NodeResult, NodeTrait, RsvgNode};
use crate::parsers;
use crate::property_bag::PropertyBag;
@@ -42,10 +42,10 @@ impl NodeTrait for Offset {
for (attr, value) in pbag.iter() {
match attr {
local_name!("dx") => self.dx.set(
- parsers::number(value).map_err(|err| NodeError::attribute_error(attr, err))?,
+ parsers::number(value).attribute(attr)?,
),
local_name!("dy") => self.dy.set(
- parsers::number(value).map_err(|err| NodeError::attribute_error(attr, err))?,
+ parsers::number(value).attribute(attr)?,
),
_ => (),
}
diff --git a/rsvg_internals/src/filters/turbulence.rs b/rsvg_internals/src/filters/turbulence.rs
index 14e91ea7..fac5a4f7 100644
--- a/rsvg_internals/src/filters/turbulence.rs
+++ b/rsvg_internals/src/filters/turbulence.rs
@@ -4,7 +4,7 @@ use cairo::{self, ImageSurface, MatrixTrait};
use markup5ever::{local_name, LocalName};
use crate::drawing_ctx::DrawingCtx;
-use crate::error::NodeError;
+use crate::error::{AttributeResultExt, NodeError};
use crate::node::{CascadedValues, NodeResult, NodeTrait, RsvgNode};
use crate::parsers::{self, ParseError};
use crate::property_bag::PropertyBag;
@@ -69,7 +69,7 @@ impl NodeTrait for Turbulence {
match attr {
local_name!("baseFrequency") => self.base_frequency.set(
parsers::number_optional_number(value)
- .map_err(|err| NodeError::attribute_error(attr.clone(), err))
+ .attribute(attr.clone())
.and_then(|(x, y)| {
if x >= 0.0 && y >= 0.0 {
Ok((x, y))
@@ -79,7 +79,7 @@ impl NodeTrait for Turbulence {
})?,
),
local_name!("numOctaves") => self.num_octaves.set(
- parsers::integer(value).map_err(|err| NodeError::attribute_error(attr, err))?,
+ parsers::integer(value).attribute(attr)?,
),
// Yes, seed needs to be parsed as a number and then truncated.
local_name!("seed") => self.seed.set(
@@ -91,7 +91,7 @@ impl NodeTrait for Turbulence {
f64::from(i32::max_value()),
) as i32
})
- .map_err(|err| NodeError::attribute_error(attr, err))?,
+ .attribute(attr)?,
),
local_name!("stitchTiles") => {
self.stitch_tiles.set(StitchTiles::parse(attr, value)?)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]