1.1 --- a/libxml2dom/svg.py Tue Mar 13 00:15:13 2007 +0000
1.2 +++ b/libxml2dom/svg.py Tue Mar 13 00:16:45 2007 +0000
1.3 @@ -1,7 +1,8 @@
1.4 #!/usr/bin/env python
1.5
1.6 """
1.7 -SVG-specific document support.
1.8 +SVG-specific document support. See:
1.9 +http://www.w3.org/TR/SVGMobile12/python-binding.html
1.10
1.11 Copyright (C) 2007 Paul Boddie <paul@boddie.org.uk>
1.12
1.13 @@ -29,20 +30,51 @@
1.14 toString as Node_toString, toStream as Node_toStream, \
1.15 toFile as Node_toFile
1.16
1.17 +SVG_NAMESPACE = "http://www.w3.org/2000/svg"
1.18 +
1.19 class SVGImplementation(libxml2dom.Implementation):
1.20
1.21 "Contains an SVG-specific implementation."
1.22
1.23 + # Wrapping of documents.
1.24 +
1.25 + def adoptDocument(self, node):
1.26 + return SVGDocument(node, self)
1.27 +
1.28 + # Factory functions.
1.29 +
1.30 def get_node(self, _node, context_node):
1.31 if Node_nodeType(_node) == context_node.ELEMENT_NODE and \
1.32 - Node_namespaceURI(_node) == "http://www.w3.org/2000/svg" and \
1.33 - Node_localName(_node) == "svg":
1.34 + Node_namespaceURI(_node) == SVG_NAMESPACE:
1.35
1.36 - return SVGElement(_node, self, context_node.ownerDocument)
1.37 + if Node_localName(_node) == "svg":
1.38 + return SVGSVGElement(_node, self, context_node.ownerDocument)
1.39 + else:
1.40 + return SVGElement(_node, self, context_node.ownerDocument)
1.41 else:
1.42 return libxml2dom.Implementation.get_node(self, _node, context_node)
1.43
1.44 -class SVGElement(libxml2dom.Node):
1.45 +class SVGElement(libxml2dom.Node): # Element, EventTarget, TraitAccess, ElementTraversal
1.46 +
1.47 + "An SVG-specific element."
1.48 +
1.49 + def _id(self):
1.50 + return self.getAttribute("id")
1.51 +
1.52 + def _setId(self, value):
1.53 + self.setAttribute("id", value)
1.54 +
1.55 + id = property(_id, _setId)
1.56 +
1.57 +class SVGLocatable:
1.58 +
1.59 + "A locatable interface."
1.60 +
1.61 +class SVGLocatableElement(SVGElement, SVGLocatable):
1.62 +
1.63 + "A locatable element."
1.64 +
1.65 +class SVGSVGElement(SVGLocatableElement): # SVGTimedElement
1.66
1.67 "An SVG-specific top-level element."
1.68
1.69 @@ -58,6 +90,14 @@
1.70 NAV_LEFT = 10
1.71 NAV_UP_LEFT = 11
1.72
1.73 +class SVGDocument(libxml2dom.Document):
1.74 +
1.75 + "An SVG-specific document node."
1.76 +
1.77 + # NOTE: Define global (SVGGlobal).
1.78 +
1.79 +# Convenience functions.
1.80 +
1.81 def parse(stream_or_string, html=0):
1.82 return libxml2dom.parse(stream_or_string, html, default_impl)
1.83