enable.savage.svg.document module

SVGDocument

class enable.savage.svg.document.ResourceGetter(dirname=None)[source]

Bases: object

Simple context for getting relative-pathed resources.

classmethod fromfilename(filename)[source]

Use the directory containing this file as the base directory.

newbase(dirname)[source]

Return a new ResourceGetter using a new base directory found relative to this one.

open_image(path)[source]

Resolve and read an image into an appropriate object for the renderer.

open_svg(path)[source]

Resolve and read an SVG file into an Element.

resolve(path)[source]

Resolve a path and the associated opener function against this context.

class enable.savage.svg.document.SVGDocument(element, resources=None, renderer=<class 'enable.savage.svg.backends.null.null_renderer.NullRenderer'>)[source]

Bases: object

addCircleToDocument(node, path)[source]
addEllipseToDocument(node, path)[source]
addGroupToDocument(node)[source]

For parent elements: push on a state, then process all child elements

addImageToDocument(node)[source]

Add an <image> tag to the document.

addLineToDocument(node, path)[source]
addPathDataToDocument(node, path)[source]
addPathDataToPath(data, path)[source]
addPolyLineToDocument(node, path)[source]
addPolygonToDocument(node, path)[source]
addRectToDocument(node, path)[source]
addStrokeToPath(path, stroke)[source]

Given a stroke from a path command (in the form (command, arguments)) create the path commands that represent it.

TODO: break out into (yet another) class/module, especially so we can get O(1) dispatch on type?

addSwitchToDocument(node)[source]

Process a <switch> tag.

addTextToDocument(node)[source]
addUseToDocument(node)[source]

Add a <use> tag to the document.

classmethod createFromFile(filename, renderer)[source]
createTransformOpsFromNode(node, attribute='transform')[source]

Returns an oplist for transformations. This applies to a node, not the current state because the transform stack is saved in the graphics context.

This oplist does not include the push/pop state commands

createTransformOpsFromXY(node)[source]

On some nodes, x and y attributes cause a translation of the coordinate system.

dereference(href, resources=None)[source]

Find the element specified by the give href.

Parameters
  • href (str) – The reference pointing to the desired element. Forms like ‘url(uri#theid)’ and ‘uri#xpointer(id(theid))’ will be normalized to pull out just the uri and the id.

  • resources (ResourceGetter, optional) – The ResourceGetter to use. If not provided, the one attached to the SVGDocument is used. This is useful when silly test suites like to test annoying XLink features. FIXME: <sigh> xml:base is inheritable.

Returns

element

Return type

Element

Raises

KeyError : – If the element is not found.

findIDs(element, uri='')[source]

Iterate through the tree under an element and record all elements which specify an id attribute.

The root element is given the ID ‘’ in addition to whatever id= attribute it may be given.

generatePathOps(path)[source]

Look at the current state and generate the draw operations (fill, stroke, neither) for the path.

getBrushFromState(path=None)[source]
getFontFromState()[source]
getLocalState(element, state=None)[source]

Get the state local to an element.

getPenFromState()[source]
getSize()[source]
parseStops(element)[source]

Parse the color stops from a gradient definition.

processElement(element)[source]

Process one element of the XML tree. Returns the path representing the node, and an operation list for drawing the node.

Parent nodes should return a path (for hittesting), but no draw operations

render(context)[source]
property state

Retrieve the current state, without popping

class enable.savage.svg.document.XMLNS(url)[source]

Bases: object

Utility object for dealing the namespaced names quoted the way ElementTree requires.

enable.savage.svg.document.attrAsFloat(node, attr, defaultValue='0')[source]
enable.savage.svg.document.fractionalValue(value)[source]

Parse a string consisting of a float in the range [0..1] or a percentage as a float number in the range [0..1].

enable.savage.svg.document.normalize_href(href)[source]

Normalize an href to remove url(…) and xpointer(id(…)) extraneous bits.

Parameters

href (str) –

Returns

  • uri (str) – A URI (or maybe a file system path) to the resource.

  • fragment (str) – The normalized #fragment, if any

enable.savage.svg.document.pathHandler(func)[source]

decorator for methods which return a path operation Creates the path they will fill, and generates the path operations for the node

enable.savage.svg.document.valueToPixels(val, defaultUnits='px')[source]