def update_tagrefs(self, mode='purge'): """Check tagrefs for deleted objects.""" defs = get_defs(self.document.getroot()) inkscape_tagrefs = self.get_tagrefs(defs) if len(inkscape_tagrefs): for tagref in inkscape_tagrefs: href = tagref.get(inkex.addNS('href', 'xlink'))[1:] if self.getElementById(href) is None: if mode == 'purge': tagref.getparent().remove(tagref) elif mode == 'placeholder': temp = inkex.etree.Element(inkex.addNS('path', 'svg')) temp.set('id', href) temp.set('d', 'M 0,0 Z') self.document.getroot().append(temp)
def get_defs(node): """Find <defs> in children of *node*, return first one found.""" path = '/svg:svg//svg:defs' try: return node.xpath(path, namespaces=inkex.NSS)[0] except IndexError: return inkex.etree.SubElement(node, inkex.addNS('defs', 'svg'))
def has_path_effect(node): """Check node for Inkscape path-effect attribute.""" return inkex.addNS('path-effect', 'inkscape') in node.attrib
def is_custom_shape(node): """Check node for Inkscape custom shape type.""" return inkex.addNS('type', 'sodipodi') in node.attrib
def is_basic_shape(node): """Check node for SVG basic shape tag.""" return node.tag in (inkex.addNS(tag, 'svg') for tag in SVG_SHAPES)
def is_path(node): """Check node for path tag.""" return node.tag == inkex.addNS('path', 'svg')
def is_group(node): """Check node for group tag.""" return node.tag == inkex.addNS('g', 'svg')
def is_text(node): """Check node for text tag.""" return node.tag == inkex.addNS('text', 'svg')
def is_image(node): """Check node for image tag.""" return node.tag == inkex.addNS('image', 'svg')