use svgdom::{
Attribute,
};
use super::prelude::*;
pub fn resolve_inherit(doc: &Document) {
let mut ids = Vec::new();
for (_, mut node) in doc.root().descendants().svg() {
ids.clear();
{
let attrs = node.attributes();
for (aid, attr) in attrs.iter().svg() {
if let AValue::Inherit = attr.value {
ids.push(aid);
}
}
}
for id in &ids {
resolve_impl(&mut node, *id);
}
}
}
fn resolve_impl(node: &mut Node, attr: AId) {
if let Some(n) = node.ancestors().skip(1).find(|n| n.has_attribute(attr)) {
let av = n.attributes().get_value(attr).cloned();
if let Some(av) = av {
node.set_attribute((attr, av.clone()));
}
} else {
match Attribute::default(attr) {
Some(a) => node.set_attribute((attr, a.value)),
None => {
warn!("Failed to resolve attribute: {}. Removing it.",
node.attributes().get(attr).unwrap());
node.remove_attribute(attr);
}
}
}
}