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
38
39
40
41
42
// 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 svgdom::{
NodeType,
};
use super::prelude::*;
pub fn resolve_tref(doc: &mut Document) {
for mut tref in doc.root().descendants().filter(|n| n.is_tag_name(EId::Tref)) {
let av = tref.attributes().get_value(("xlink", AId::Href)).cloned();
let text_elem = if let Some(AValue::Link(ref link)) = av {
link.clone()
} else {
continue;
};
// 'All character data within the referenced element, including character data enclosed
// within additional markup, will be rendered.'
//
// So we don't care about attributes and everything. Just collecting text nodes data.
let mut text = String::new();
for node in text_elem.descendants().filter(|n| n.is_text()) {
text.push_str(&node.text());
}
let text_node = doc.create_node(NodeType::Text, text);
tref.append(text_node);
tref.set_tag_name(EId::Tspan);
tref.remove_attribute(("xlink", AId::Href));
for (aid, attr) in text_elem.attributes().iter().svg() {
if !tref.has_attribute(aid) && attr.is_inheritable() {
tref.set_attribute(attr.clone());
}
}
}
}