[librsvg: 9/10] filter: simplify parsing
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 9/10] filter: simplify parsing
- Date: Tue, 15 Dec 2020 00:26:54 +0000 (UTC)
commit 6f4fe38e9eeb109bffda69cc38e930473af83044
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Dec 12 19:18:34 2020 +0100
filter: simplify parsing
Do not use IRI since None is not allowed. Also add a TODO to
clarify why we have a FilterValue wrapper type with a single
variant for now.
src/drawing_ctx.rs | 4 ++--
src/filter.rs | 36 ++++++++++++++++++------------------
2 files changed, 20 insertions(+), 20 deletions(-)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index 40481bca..b471fc7e 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -860,10 +860,10 @@ impl DrawingCtx {
.try_fold(
child_surface,
|surface, filter| -> Result<_, RenderingError> {
- let FilterValue::URL(filter_uri) = filter;
+ let FilterValue::Url(f) = filter;
self.run_filter(
acquired_nodes,
- &filter_uri,
+ &f,
node,
values,
surface,
diff --git a/src/filter.rs b/src/filter.rs
index a6f4fc8c..ffa7d5a3 100644
--- a/src/filter.rs
+++ b/src/filter.rs
@@ -10,7 +10,6 @@ use crate::document::{AcquiredNodes, NodeId};
use crate::drawing_ctx::ViewParams;
use crate::element::{Draw, Element, ElementResult, SetAttributes};
use crate::error::ValueErrorKind;
-use crate::iri::IRI;
use crate::length::*;
use crate::node::{Node, NodeBorrow};
use crate::parsers::{Parse, ParseValue};
@@ -151,8 +150,10 @@ impl Draw for Filter {}
#[derive(Debug, Clone, PartialEq)]
pub enum FilterValue {
- URL(NodeId),
+ Url(NodeId),
+ // TODO: add functions from https://www.w3.org/TR/filter-effects-1/#filter-functions
}
+
#[derive(Debug, Clone, PartialEq)]
pub struct FilterValueList(Vec<FilterValue>);
@@ -178,8 +179,11 @@ impl FilterValueList {
return false;
}
- self.iter().all(|filter| match filter {
- FilterValue::URL(filter_uri) => match acquired_nodes.acquire(filter_uri) {
+ self.iter()
+ .map(|v| match v {
+ FilterValue::Url(v) => v,
+ })
+ .all(|v| match acquired_nodes.acquire(v) {
Ok(acquired) => {
let filter_node = acquired.get();
@@ -189,7 +193,7 @@ impl FilterValueList {
rsvg_log!(
"element {} will not be filtered since \"{}\" is not a filter",
node,
- filter_uri,
+ v,
);
false
}
@@ -199,12 +203,11 @@ impl FilterValueList {
rsvg_log!(
"element {} will not be filtered since its filter \"{}\" was not found",
node,
- filter_uri,
+ v,
);
false
}
- },
- })
+ })
}
}
@@ -213,15 +216,12 @@ impl Parse for FilterValueList {
let mut result = FilterValueList::default();
loop {
- let state = parser.state();
-
- if let Ok(IRI::Resource(uri)) = parser.try_parse(|p| IRI::parse(p)) {
- result.0.push(FilterValue::URL(uri));
- } else {
- parser.reset(&state);
- let token = parser.next()?.clone();
- return Err(parser.new_basic_unexpected_token_error(token).into());
- }
+ let loc = parser.current_source_location();
+
+ let url = parser.expect_url()?;
+ let node_id =
+ NodeId::parse(&url).map_err(|e| loc.new_custom_error(ValueErrorKind::from(e)))?;
+ result.0.push(FilterValue::Url(node_id));
if parser.is_exhausted() {
break;
@@ -242,7 +242,7 @@ mod tests {
let n2 = NodeId::External("test.svg".to_string(), "baz".to_string());
assert_eq!(
FilterValueList::parse_str("url(foo.svg#bar) url(test.svg#baz)").unwrap(),
- FilterValueList(vec![FilterValue::URL(n1), FilterValue::URL(n2)])
+ FilterValueList(vec![FilterValue::Url(n1), FilterValue::Url(n2)])
);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]