Difference between revisions of "Python modules for extensions"
(added section on simpletransform) |
Christoffer (talk | contribs) |
||
Line 36: | Line 36: | ||
== cubicsuperpath.py == | == cubicsuperpath.py == | ||
An alternative path representation. access both handles of a node at once. | An alternative path representation. access both handles of a node at once. loses a paths open/closed identity. | ||
== simpletransform.py == | == simpletransform.py == |
Revision as of 15:19, 15 May 2013
inkex.py
This module encapsulates the basic behavior of a script extension, allowing the author to concentrate on manipulating the SVG data. The module provides an class Effect(). inkex.py was originally designed to provide the Effect (filter) extension type, but has been used for Input/Output extensions simply by overriding additional class methods.
Methods
- effect(): override with document processing code.
- affect(): actuate the script.
- xpathSingle(path): an xpath wrapper to return a single node.
- uniqueId(old_id, make_new_id = True): return an id that is unique in the document given a proposed id.
Properties
- document: DOM document
- selected: a list of nodes that were selected in inkscape
- doc_ids: all of the ids used in the document
- options: options passed to the script
simplestyle.py
Provides methods for dealing with css data embeded in SVG's style="" atribute
- parseStyle(string): Create a dictionary from the value of an inline style attribute
- formatStyle(dict): Format an inline style attribute from a dictionary
- isColor(c): Determine if its a color we can use. If not, leave it unchanged.
- parseColor(c): Creates a rgb int array
- formatColoria(a): int array to #rrggbb
- formatColorfa(a): float array to #rrggbb
- formatColor3i(r,g,b): 3 ints to #rrggbb
- formatColor3f(r,g,b): 3 floats to #rrggbb
- svgcolors: a dictionary defining legal color names and corresponding color values
simplepath.py
Provides functions to round trip svg path d="" attribute data and a simple path format mimicing that datastructure. additional functions for scaling translating and rotating path data.
cubicsuperpath.py
An alternative path representation. access both handles of a node at once. loses a paths open/closed identity.
simpletransform.py
Provides code to easily transform objects.
- parseTransform
- Takes a string such as rotate(10) and produces a transformation matrix. If you also supply an initial matrix, the new one will be composed with the old one.
- Available commands: translate, scale, rotate, skewX, skewY, matrix. Other examples:
- matrix = parseTransform('rotate(10)')
- matrix = parseTransform('skewY(10)')
- matrix = parseTransform('translate(10 10)')
- matrix = parseTransform(' rotate(10)')
- matrix = parseTransform('translate(700,210) rotate(-30)')
pturtle.py
Provides turtle graphics primitives with svg path data output
beziermisc.py
Utility functions for working with bezier curves
cspsubdiv.py
Decompose a path into polylines
ff*.py
an obscure set of tools for dealing with musical scales.