paulb@218 | 1 | #!/usr/bin/env python |
paulb@218 | 2 | |
paulb@218 | 3 | """ |
paulb@218 | 4 | SVG-specific document support. |
paulb@218 | 5 | |
paulb@218 | 6 | Copyright (C) 2007 Paul Boddie <paul@boddie.org.uk> |
paulb@218 | 7 | |
paulb@218 | 8 | This library is free software; you can redistribute it and/or |
paulb@218 | 9 | modify it under the terms of the GNU Lesser General Public |
paulb@218 | 10 | License as published by the Free Software Foundation; either |
paulb@218 | 11 | version 2.1 of the License, or (at your option) any later version. |
paulb@218 | 12 | |
paulb@218 | 13 | This library is distributed in the hope that it will be useful, |
paulb@218 | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
paulb@218 | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
paulb@218 | 16 | Lesser General Public License for more details. |
paulb@218 | 17 | |
paulb@218 | 18 | You should have received a copy of the GNU Lesser General Public |
paulb@218 | 19 | License along with this library; if not, write to the Free Software |
paulb@218 | 20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
paulb@218 | 21 | """ |
paulb@218 | 22 | |
paulb@218 | 23 | import libxml2dom |
paulb@218 | 24 | from libxml2dom.macrolib import * |
paulb@218 | 25 | from libxml2dom.macrolib import \ |
paulb@218 | 26 | createDocument as Node_createDocument, \ |
paulb@218 | 27 | parseString as Node_parseString, parseURI as Node_parseURI, \ |
paulb@218 | 28 | parseFile as Node_parseFile, \ |
paulb@218 | 29 | toString as Node_toString, toStream as Node_toStream, \ |
paulb@218 | 30 | toFile as Node_toFile |
paulb@218 | 31 | |
paulb@218 | 32 | class SVGImplementation(libxml2dom.Implementation): |
paulb@218 | 33 | |
paulb@218 | 34 | "Contains an SVG-specific implementation." |
paulb@218 | 35 | |
paulb@218 | 36 | def get_node(self, _node, context_node): |
paulb@218 | 37 | if Node_nodeType(_node) == context_node.ELEMENT_NODE and \ |
paulb@218 | 38 | Node_namespaceURI(_node) == "http://www.w3.org/2000/svg" and \ |
paulb@218 | 39 | Node_localName(_node) == "svg": |
paulb@218 | 40 | |
paulb@218 | 41 | return SVGElement(_node, self, context_node.ownerDocument) |
paulb@218 | 42 | else: |
paulb@218 | 43 | return libxml2dom.Implementation.get_node(self, _node, context_node) |
paulb@218 | 44 | |
paulb@218 | 45 | class SVGElement(libxml2dom.Node): |
paulb@218 | 46 | |
paulb@218 | 47 | "An SVG-specific top-level element." |
paulb@218 | 48 | |
paulb@218 | 49 | NAV_AUTO = 1 |
paulb@218 | 50 | NAV_NEXT = 2 |
paulb@218 | 51 | NAV_PREV = 3 |
paulb@218 | 52 | NAV_UP = 4 |
paulb@218 | 53 | NAV_UP_RIGHT = 5 |
paulb@218 | 54 | NAV_RIGHT = 6 |
paulb@218 | 55 | NAV_DOWN_RIGHT = 7 |
paulb@218 | 56 | NAV_DOWN = 8 |
paulb@218 | 57 | NAV_DOWN_LEFT = 9 |
paulb@218 | 58 | NAV_LEFT = 10 |
paulb@218 | 59 | NAV_UP_LEFT = 11 |
paulb@218 | 60 | |
paulb@218 | 61 | def parse(stream_or_string, html=0): |
paulb@218 | 62 | return libxml2dom.parse(stream_or_string, html, default_impl) |
paulb@218 | 63 | |
paulb@218 | 64 | def parseFile(filename, html=0): |
paulb@218 | 65 | return libxml2dom.parseFile(filename, html, default_impl) |
paulb@218 | 66 | |
paulb@218 | 67 | def parseString(s, html=0): |
paulb@218 | 68 | return libxml2dom.parseString(s, html, default_impl) |
paulb@218 | 69 | |
paulb@218 | 70 | def parseURI(uri, html=0): |
paulb@218 | 71 | return libxml2dom.parseURI(uri, html, default_impl) |
paulb@218 | 72 | |
paulb@218 | 73 | # Single instance of the implementation. |
paulb@218 | 74 | |
paulb@218 | 75 | default_impl = SVGImplementation() |
paulb@218 | 76 | |
paulb@218 | 77 | # vim: tabstop=4 expandtab shiftwidth=4 |