candy

download
source

SVG Candy is an open source, minimal SVG import library for Processing. The last build for SVG Candy was for Processing version 0118.

SVG stands for Scalar Vector Graphics, a portable graphics format. It is a vector format so it allows for infinite resolution and relatively minute file sizes. Most modern media software can view SVG files, including Firefox, Adobe products, etc. You can use something like Illustrator to edit SVG files.

This library was specifically tested under SVG files created from Adobe Illustrator. I can't guarantee that it'll work for any SVG's created from anything else. In the future I will also test with open source graphics editing software so we'll reach maximal compatibility.

last update: 10-31-06 (list of changes)

Supported Features
The following are currently supported by SVG Candy

+ Fills and borders
+ Opacity
+ Transforms (translate, rotate)
+ Lines
+ Rectangles
+ Ellipses
+ Ovals
+ Polygons
+ Paths (bezier, moveto, curveto, absolute, relative)

Installation
SVG Candy uses Christian Riekoff's proXML to parse SVGs. You
will first need to install that package. Get it at:

http://www.texone.org/proxml

You will need the latest version of proXML for Candy to work.

Once you have that, download and extract Candy to
processing-xxxx/libraries
so that the contents is located in
processing-xxxx/libraries/candy

Restart Processing if it is already started.

Usage
In Processing under sketch->import library, candy should appear as a library. Import Candy.

An SVG created under Illustrator must be created in the following manner:

File->Save for Web (or control-alt-shift-s on a PC) .
Under settings, make sure the CSS properties is set to "PRESENTATION ATTRIBUTES"

example

(here, "P5SVG" is just a custom name I made for these settings)

Saving it any other way will most likely break Candy.

 

A minimal example program using Candy:
(assuming a working moo.svg is in your data folder)
  import proxml.*;
  import candy.*;

  SVG moo;
  void setup(){
 	 size(400,400);
	  moo = new SVG("moo.svg",this);
  } 
  void draw(){
	  moo.draw();
  } 

Note that proxml is imported as well. This is not needed when
running the app directly from Processing, as Candy will know
where it is. However when you export as an applet you will
also need to export proxml along with it to have working Candy

Methods
(there aren't many)

  SVG(String filename)

constructor
filename - string path to your svg file

  draw()

draws the svg to screen

  customStyle()

sets the SVG to use your own fills, strokes, strokeweights, etc

  SVGStyle()

sets the SVG to use style specified in the SVG file

  printSVG()  

prints the svg data to console

Known Issues
Certain SVGs contain additional heading that is different from SVGs generated from Adobe products. This will actually kill your SVG. I will try and address this problem on the next release.

Some SVG objects and features may not yet be supported. Here is a partial list of non-included features:
+ Rounded rectangles
+ Drop shadow objects
+ Typography
+ Layers
+ Patterns
+ Embedded images

Filled beziers will look messed up under OPENGL and P3D. This is not Candy's fault. File a petition, or something, at http://www.processing.org/discourse to get 3D/GL bezier fills fixed.

If you experience any other weirdness or bugs, please file them to flux -dot- blackcat -at- gmail -dot- com with subject: Delicious Candy

List of Changes
Revision 10/31/06
-this is the Halloween version of Candy :)
+Now properly supports Processing-0118
+Fixed a bunch of things for Casey's students and general buggity.
+Will now properly draw #FFFFFFFF colors (were being represented as -1)
+SVGs without <g> tags are now properly caught and loaded
+Added a method customStyle() for overriding SVG colors/styles
+Added a method SVGStyle() to go back to using SVG colors/styles