use {
ElementId,
Node,
};
pub trait ElementType {
fn is_referenced(&self) -> bool;
fn is_basic_shape(&self) -> bool;
fn is_shape(&self) -> bool;
fn is_container(&self) -> bool;
fn is_text_content(&self) -> bool;
fn is_text_content_child(&self) -> bool;
fn is_graphic(&self) -> bool;
fn is_gradient(&self) -> bool;
}
macro_rules! is_func {
($name:ident, $($pattern:tt)+) => (
fn $name(&self) -> bool {
if let Some(id) = self.tag_id() {
match id {
$($pattern)+ => true,
_ => false
}
} else {
false
}
}
)
}
impl ElementType for Node {
is_func!(is_referenced,
ElementId::AltGlyphDef
| ElementId::ClipPath
| ElementId::Cursor
| ElementId::Filter
| ElementId::LinearGradient
| ElementId::Marker
| ElementId::Mask
| ElementId::Pattern
| ElementId::RadialGradient
| ElementId::Symbol);
is_func!(is_basic_shape,
ElementId::Rect
| ElementId::Circle
| ElementId::Ellipse
| ElementId::Line
| ElementId::Polyline
| ElementId::Polygon);
is_func!(is_shape,
ElementId::Circle
| ElementId::Ellipse
| ElementId::Line
| ElementId::Path
| ElementId::Polygon
| ElementId::Polyline
| ElementId::Rect);
is_func!(is_container,
ElementId::A
| ElementId::Defs
| ElementId::Glyph
| ElementId::G
| ElementId::Marker
| ElementId::Mask
| ElementId::MissingGlyph
| ElementId::Pattern
| ElementId::Svg
| ElementId::Switch
| ElementId::Symbol);
is_func!(is_text_content,
ElementId::AltGlyph
| ElementId::TextPath
| ElementId::Text
| ElementId::Tref
| ElementId::Tspan);
is_func!(is_text_content_child,
ElementId::AltGlyph
| ElementId::TextPath
| ElementId::Tref
| ElementId::Tspan);
is_func!(is_graphic,
ElementId::Circle
| ElementId::Ellipse
| ElementId::Image
| ElementId::Line
| ElementId::Path
| ElementId::Polygon
| ElementId::Polyline
| ElementId::Rect
| ElementId::Text
| ElementId::Use);
is_func!(is_gradient,
ElementId::LinearGradient
| ElementId::RadialGradient);
}