=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.


=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.


=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 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=

  * I haven't yet uploaded to PyPI.
  * I haven't tried to make it choke on some large real-world SVG files.
  * I've only tested on Windows.


=Plans=

It would be nice to handle arcs as well as straight lines. Beziers I can live
without.

It would be nice to handle linear gradient fills. Radial gradient fills I can
live without.

I don't plan to render line paths. (I'm using them to represent things like
collision boundaries)

It would be nice to represent animation somehow. I'm not sure whether animation
frames should be crammed into a single svg file, maybe on different layers or
somesuch.

There are redundancies in the vertex arrays that are produced from
tessellation. It would be nice to eliminate these.


=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].

