1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use super::prelude::*;
pub fn fix_recursive_pattern(doc: &Document) {
// If a pattern child has a link to the pattern itself
// then we have to replace it with `none`.
// Otherwise we will get endless loop/recursion and stack overflow.
for pattern_node in doc.root().descendants().filter(|n| n.is_tag_name(EId::Pattern)) {
for mut node in pattern_node.descendants() {
let mut check_attr = |aid: AId| {
let av = node.attributes().get_value(aid).cloned();
if let Some(AValue::Paint(link, _)) = av {
if link == pattern_node {
node.set_attribute((aid, AValue::None));
} else {
// Check that linked node children doesn't link this pattern.
for node2 in link.descendants() {
let av2 = node2.attributes().get_value(aid).cloned();
if let Some(AValue::Paint(link2, _)) = av2 {
if link2 == pattern_node {
node.set_attribute((aid, AValue::None));
}
}
}
}
}
};
check_attr(AId::Fill);
check_attr(AId::Stroke);
}
}
}