|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectprocessing.candy.SVG
public class SVG
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 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.
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, because it would increase the download size of any applet by 20%, and 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:
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).
February 2008 revisions by fry (Processing 0136)
| Nested Class Summary | |
|---|---|
class |
SVG.Path
|
| Field Summary | |
|---|---|
float |
height
|
float |
width
|
| Constructor Summary | |
|---|---|
SVG(PApplet parent,
java.lang.String filename)
Initializes a new SVG Object with the given filename. |
|
SVG(PApplet parent,
XMLElement svg)
Initializes a new SVG Object with the given filename. |
|
| Method Summary | |
|---|---|
void |
draw()
Temporary hack for gradient handling. |
void |
draw(float x,
float y)
Convenience method to draw at a particular location. |
void |
draw(float x,
float y,
float c,
float d)
|
void |
drawImpl()
Draws the SVG document. |
void |
drawMode(int which)
Set the orientation for drawn objects, similar to PImage.imageMode(). |
void |
fillGradient(java.lang.String name,
float x,
float y,
float r)
|
void |
fillGradient(java.lang.String name,
float x1,
float y1,
float x2,
float y2)
|
SVG |
get(java.lang.String name)
Get a particular element based on its SVG ID. |
void |
ignoreStyles()
Overrides SVG-set styles and uses PGraphics styles and colors. |
void |
ignoreStyles(boolean state)
Enables or disables style information (fill and stroke) set in the file. |
float |
parseUnitSize(java.lang.String text)
Parse a size that may have a suffix for its units. |
void |
print()
Prints out the SVG document useful for parsing |
void |
strokeGradient(java.lang.String name,
float x,
float y,
float r)
|
void |
strokeGradient(java.lang.String name,
float x1,
float y1,
float x2,
float y2)
|
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public float width
public float height
| Constructor Detail |
|---|
public SVG(PApplet parent,
java.lang.String filename)
public SVG(PApplet parent,
XMLElement svg)
| Method Detail |
|---|
public float parseUnitSize(java.lang.String text)
public SVG get(java.lang.String name)
// This code grabs "Layer 3" and the shapes beneath it.
SVG layer3 = svg.get("Layer 3");
public void strokeGradient(java.lang.String name,
float x,
float y,
float r)
public void strokeGradient(java.lang.String name,
float x1,
float y1,
float x2,
float y2)
public void fillGradient(java.lang.String name,
float x,
float y,
float r)
public void fillGradient(java.lang.String name,
float x1,
float y1,
float x2,
float y2)
public void draw()
public void draw(float x,
float y)
public void draw(float x,
float y,
float c,
float d)
public void drawImpl()
public void drawMode(int which)
which - Either CORNER, CORNERS, or CENTER.public void ignoreStyles()
public void ignoreStyles(boolean state)
state - true to use user-specified stroke/fill, false for svg versionpublic void print()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||