processing.candy
Class SVG

java.lang.Object
  extended by processing.core.PShape
      extended by processing.candy.BaseObject
          extended by processing.candy.SVG
All Implemented Interfaces:
PConstants

public class SVG
extends BaseObject

Candy is a minimal SVG import library for Processing. Candy was written by Michael Chang, and later revised and expanded for use as a Processing core library by Ben Fry.

SVG stands for Scalable Vector Graphics, a portable graphics format. It is a vector format so it allows for infinite resolution and relatively small file sizes. Most modern media software can view SVG files, including Adobe products, Firefox, etc. Illustrator and Inkscape can edit SVG files.

We have no intention of turning this into a full-featured SVG library. The goal of this project is a basic shape importer that is small enough to be included with applets, meaning that its download size should be in the neighborhood of 25-30k. Because of this size, it is not made part of processing.core, as it's not a feature that will be used by the majority of our audience. For more sophisticated import/export, consider the Batik library from the Apache Software Foundation. Future improvements to this library may focus on this properly supporting a specific subset of SVG, for instance the simpler SVG profiles known as SVG Tiny or Basic, although we still would not support the interactivity options.

This library was specifically tested under SVG files created with Adobe Illustrator. We can't guarantee that it will work for any SVGs created with other software. In the future we would like to improve compatibility with Open Source software such as Inkscape, however initial tests show its base implementation produces more complicated files, and this will require more time.

An SVG created under Illustrator must be created in one of two ways:

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 processing.candy.*;
 import processing.xml.*;

 SVG moo;
 void setup() {
   size(400,400);
   moo = new SVG("moo.svg",this);
 }
 void draw() {
   moo.draw();
 }
 
Note that processing.xml needs to be imported as well. This may not be required when running code within the Processing environment, but when exported it may cause a NoClassDefError. This will be fixed in later releases of Processing (Bug 518).


August 2008 revisions by fry (Processing 0149)

February 2008 revisions by fry (Processing 0136) Revisions for "Candy 2" November 2006 by fry Revision 10/31/06 by flux Some SVG objects and features may not yet be supported. Here is a partial list of non-included features For those interested, the SVG specification can be found here.


Field Summary
 
Fields inherited from interface processing.core.PConstants
ADD, ALPHA, ALPHA_MASK, ALT, AMBIENT, ARGB, ARROW, BACKSPACE, BASELINE, BEVEL, BLEND, BLUE_MASK, BLUR, BOTTOM, BURN, CENTER, CENTER_RADIUS, CHATTER, CLOSE, CMYK, CODED, COMPLAINT, CONTROL, CORNER, CORNERS, CROSS, CUSTOM, DARKEST, DEG_TO_RAD, DELETE, DIFFERENCE, DILATE, DIRECTIONAL, DISABLE_ACCURATE_TEXTURES, DISABLE_DEPTH_SORT, DISABLE_DEPTH_TEST, DISABLE_NATIVE_FONTS, DISABLE_OPENGL_ERROR_REPORT, DODGE, DOWN, DXF, ENABLE_ACCURATE_TEXTURES, ENABLE_DEPTH_SORT, ENABLE_DEPTH_TEST, ENABLE_NATIVE_FONTS, ENABLE_OPENGL_2X_SMOOTH, ENABLE_OPENGL_4X_SMOOTH, ENABLE_OPENGL_ERROR_REPORT, ENTER, EPSILON, ERODE, ESC, EXCLUSION, GIF, GRAY, GREEN_MASK, GROUP, HALF_PI, HAND, HARD_LIGHT, HINT_COUNT, HSB, IMAGE, INVERT, JAVA2D, JPEG, LEFT, LIGHTEST, LINES, LINUX, MACOSX, MAX_FLOAT, MAX_INT, MIN_FLOAT, MIN_INT, MITER, MODEL, MOVE, MULTIPLY, NORMALIZED, OPAQUE, OPEN, OPENGL, ORTHOGRAPHIC, OTHER, OVERLAY, P2D, P3D, PDF, PERSPECTIVE, PI, PIXEL_CENTER, POINT, POINTS, POLYGON, POSTERIZE, PROBLEM, PROJECT, QUAD_STRIP, QUADS, QUARTER_PI, RAD_TO_DEG, RADIUS, RED_MASK, REPLACE, RETURN, RGB, RIGHT, ROUND, SCREEN, SHAPE, SHIFT, SOFT_LIGHT, SPOT, SQUARE, SUBTRACT, TAB, TARGA, TEXT, THIRD_PI, THRESHOLD, TIFF, TOP, TRIANGLE_FAN, TRIANGLE_STRIP, TRIANGLES, TWO_PI, UP, WAIT, WHITESPACE, WINDOWS
 
Constructor Summary
SVG(PApplet parent, java.lang.String filename)
          Initializes a new SVG Object with the given filename.
SVG(XMLElement svg)
          Initializes a new SVG Object with the given filename.
 
Method Summary
 
Methods inherited from class processing.candy.BaseObject
drawImpl, getChild, ignoreStyles, ignoreStyles, print
 
Methods inherited from class processing.core.PShape
addChild, applyMatrix, applyMatrix, draw, draw, draw, drawMode, findChild, getChild, getChildCount, getHeight, getName, getWidth, isVisible, post, resetMatrix, rotate, rotate, rotateX, rotateY, rotateZ, scale, scale, scale, setName, setVisible, translate, translate
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SVG

public SVG(PApplet parent,
           java.lang.String filename)
Initializes a new SVG Object with the given filename.


SVG

public SVG(XMLElement svg)
Initializes a new SVG Object with the given filename.