[librsvg: 40/51] convolve_matrix.rs: impl Parse for bool for the preserveAlpha attribute
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 40/51] convolve_matrix.rs: impl Parse for bool for the preserveAlpha attribute
- Date: Thu, 19 Dec 2019 01:51:23 +0000 (UTC)
commit 24f86fc7b2ecd5e47f6e369110edbed6a425a3fa
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Dec 18 10:33:16 2019 -0600
convolve_matrix.rs: impl Parse for bool for the preserveAlpha attribute
rsvg_internals/src/filters/convolve_matrix.rs | 27 ++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)
---
diff --git a/rsvg_internals/src/filters/convolve_matrix.rs b/rsvg_internals/src/filters/convolve_matrix.rs
index 90194f66..3816df86 100644
--- a/rsvg_internals/src/filters/convolve_matrix.rs
+++ b/rsvg_internals/src/filters/convolve_matrix.rs
@@ -1,4 +1,5 @@
use cairo::{self, ImageSurface};
+use cssparser::Parser;
use markup5ever::{expanded_name, local_name, namespace_url, ns, QualName};
use nalgebra::{DMatrix, Dynamic, VecStorage};
@@ -6,7 +7,7 @@ use crate::drawing_ctx::DrawingCtx;
use crate::error::*;
use crate::node::{NodeResult, NodeTrait, RsvgNode};
use crate::number_list::{NumberList, NumberListError, NumberListLength};
-use crate::parsers;
+use crate::parsers::{self, Parse, ParseValue};
use crate::property_bag::PropertyBag;
use crate::rect::IRect;
use crate::surface_utils::{
@@ -101,16 +102,8 @@ impl NodeTrait for FeConvolveMatrix {
.attribute(attr)?,
)
}
- expanded_name!(svg "preserveAlpha") => {
- self.preserve_alpha = match value {
- "false" => false,
- "true" => true,
- _ => {
- return Err(ValueErrorKind::parse_error("expected false or true"))
- .attribute(attr);
- }
- }
- }
+ expanded_name!(svg "preserveAlpha") => self.preserve_alpha = attr.parse(value)?,
+
_ => (),
}
}
@@ -362,3 +355,15 @@ impl EdgeMode {
}
}
}
+
+// Used for the preserveAlpha attribute
+impl Parse for bool {
+ fn parse(parser: &mut Parser<'_, '_>) -> Result<Self, ValueErrorKind> {
+ parse_identifiers!(
+ parser,
+ "false" => false,
+ "true" => true,
+ )
+ .map_err(|_: ParseError| ValueErrorKind::parse_error("parse error"))
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]