=Description=

[http://code.google.com/p/svgload/ SvgBatch]

A Python package to load SVG vector graphic files, and convert
them into [http://www.pyglet.org pyglet] Batch objects, for OpenGL rendering.

The polygons from the SVG file are tesselated using GLU functions, and used to
create a pyglet Batch object of indexed vertex arrays. The Batch will aggregate
all paths from an SVG file into a single OpenGL GL_TRIANGLES primitive for
rendering. Each path is also exposed in its untessellated form, indexed by 'id'
attribute, so the application could use them for collision detection, for
example.

Currently only a subset of SVG is handled - closed polygons, filled with solid
color. These may comprise multiple loops (disjoint areas or holes), but must be
made up from straight line edges. Arc polygon edges, gradient fills and other
SVG entities (such as rectangles or text) are not currently handled.

Requires [http://www.pyglet.org pyglet].

=Status=

Nominally complete, and works with some simple SVG files that were generated by
[http://www.inkscape.org/ Inkscape], but has not yet been used in earnest.


=Download=

If you have setuptools installed, then '`easy_install svgbatch`' should install
this package in your Python _site-packages_ directory, from where your own
projects can import it.

Alternatively, download the [http://pypi.python.org/pypi/svgbatch source distribution from PyPI], which can either be incorporated as a package
directly within your own project's source tree, or else installed to
_site-packages_ using '`python setup.py install`'.

Finally, to download the whole thing, including tests and some test data, try
checking out from [http://code.google.com/p/svgload/source/checkout Subversion
on Google Code].


=Usage=

Very straightforward:

{{{
  svg = SvgBatch('data/logo.svg')
  batch = svg.create_batch()
}}}

`create_batch()` returns a [http://www.pyglet.org/doc/api/index.html pyglet
Batch object], which can be rendered in a pyglet program using `batch.draw()`
(see [http://code.google.com/p/svgload/source/browse/trunk/demo.py demo.py].)

Each path in the input SVG can include multiple loops, including holes or
islands.  The resulting batch is populated with one primitive for each filled
path tag in the SVG. The primitives are all indexed vertices of GL_TRIANGLES,
which I understand the batch will aggregate into a single large primitive.

The untessellated geometry of the loaded paths can also be accessed for things
other than rendering (eg. if your application wants to access the vertices of
the loaded shape to create a collision boundary):

{{{
  path = svg.path_by_id['pathid']
}}}

where `pathid` is the string ID of the path tag in the SVG file. This can be
set from within Inkscape by selecting _Object properties_ for the path. The
returned Path object has the following attributes:

  * *id*: string, copied from the svg tag's id attribute
  * *color*: triple of unsigned bytes, (r, g, b)
  * *loops*: a list of loops. A loop is a list of vertices. A vertex is a pair of floats or ints.
  * *bounds*: an object which provides xmin, xmax, ymin, ymax, denoting the axis-aligned extents of the path
  * *offset(x, y)*: a method which will add the given offset to all vertices in the path


=Known Issues=

  * It generally chokes on real-world SVG files other than the small ones I'm saving from Inkscape, due to unhandled SVG entities such as rectangles or text.
  * I've only tested on Windows.


=Plans=

See [http://code.google.com/p/svgload/source/browse/trunk/TODO.txt TODO.txt]


=Acknowledgements=

Many thanks to Martin O'Leary of supereffective.org, whos
[http://www.supereffective.org/pages/Squirtle-SVG-Library Squirtle] module
formed a major inspiration for this entire project, and in particular for his
sublime tesselation code, which I have copied wholesale under the terms of the
BSD.

This project requires the fabulous [http://www.pyglet.org pyglet].

