Skip to content
This repository has been archived by the owner on Oct 30, 2021. It is now read-only.

Commit

Permalink
Fixed marker attribute processing.
Browse files Browse the repository at this point in the history
  • Loading branch information
RazrFalcon committed Jan 17, 2018
1 parent 11da047 commit d2e5810
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 57 deletions.
51 changes: 1 addition & 50 deletions src/task/fix_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,60 +309,11 @@ fn rm_negative_len(node: &mut Node, id: AId) {
}
}

/// The `marker` attribute is not well supported, so we have to replace it
/// with `marker-start`, `marker-mid` and `marker-end`.
// The `marker` attribute should be removed, because it can be defined only in the CSS.
fn fix_marker(doc: &Document) {
let marker_attrs = &[
AId::MarkerStart,
AId::MarkerMid,
AId::MarkerEnd,
];

for mut node in doc.descendants() {
if node.has_attribute(AId::Marker) {
let v = node.attributes().get_value(AId::Marker).unwrap().clone();

for aid in marker_attrs {
node.set_attribute_if_none(*aid, &v);
}

node.remove_attribute(AId::Marker);
}
}
}

#[cfg(test)]
mod test_marker_attrs {
use super::*;
use svgdom::{Document, ToStringWithOptions};

macro_rules! test {
($name:ident, $in_text:expr, $out_text:expr) => (
base_test!($name, fix_invalid_attributes, $in_text, $out_text);
)
}

test!(fix_marker_1,
"<svg>
<marker id='m1'/>
<path marker='url(#m1)'/>
</svg>",
"<svg>
<marker id='m1'/>
<path marker-end='url(#m1)' marker-mid='url(#m1)' marker-start='url(#m1)'/>
</svg>
");

test!(fix_marker_2,
"<svg>
<marker id='m1'/>
<marker id='m2'/>
<path marker='url(#m1)' marker-start='url(#m2)'/>
</svg>",
"<svg>
<marker id='m1'/>
<marker id='m2'/>
<path marker-end='url(#m1)' marker-mid='url(#m1)' marker-start='url(#m2)'/>
</svg>
");
}
2 changes: 2 additions & 0 deletions tools/files-testing/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ fn clean_svg(exe_path: &str, in_path: &str, out_path: &str) -> bool {
return false;
}

// TODO: rewrite
if se.find("Error").is_some() {
// list of "not errors"
if se.find("Error: scripting is not supported.").is_some()
Expand All @@ -396,6 +397,7 @@ fn clean_svg(exe_path: &str, in_path: &str, out_path: &str) -> bool {
|| se.find("Error: Unsupported token at").is_some() // simplecss error
|| se.find("Error: invalid length at").is_some()
|| se.find("Error: cleaned file is bigger").is_some()
|| se.find("Error: failed to resolved attribute").is_some()
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"items": [
{
"name": "svgcleaner 0.9.2",
"name": "svgcleaner 0.9.3",
"value": 3
},
{
Expand Down
2 changes: 1 addition & 1 deletion tools/stats/data/correctness_chart_oxygen.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"items": [
{
"name": "svgcleaner 0.9.2",
"name": "svgcleaner 0.9.3",
"value": 0
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"items": [
{
"name": "svgcleaner 0.9.2",
"name": "svgcleaner 0.9.3",
"value": 1.8
},
{
Expand Down
2 changes: 1 addition & 1 deletion tools/stats/data/performance_chart_oxygen.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"items": [
{
"name": "svgcleaner 0.9.2",
"name": "svgcleaner 0.9.3",
"value": 16
},
{
Expand Down
4 changes: 2 additions & 2 deletions tools/stats/data/ratio_chart_W3C_SVG_11_TestSuite.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
},
"items": [
{
"name": "svgcleaner 0.9.2",
"value": 33.01
"name": "svgcleaner 0.9.3",
"value": 32.87
},
{
"name": "svgcleaner 0.9.0",
Expand Down
2 changes: 1 addition & 1 deletion tools/stats/data/ratio_chart_oxygen.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"items": [
{
"name": "svgcleaner 0.9.2",
"name": "svgcleaner 0.9.3",
"value": 61.34
},
{
Expand Down

0 comments on commit d2e5810

Please sign in to comment.