Class PShapeSVG
- All Implemented Interfaces:
PConstants
- Direct Known Subclasses:
PShapeJava2D
,PShapeSVG.Font
,PShapeSVG.FontGlyph
,PShapeSVG.Gradient
,PShapeSVG.LineOfText
,PShapeSVG.Text
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. View the SVG specification here.
We have no intention of turning this into a full-featured SVG library. The goal of this project is a basic shape importer that originally was small enough to be included with applets, meaning that its download size should be in the neighborhood of 25-30 Kb. Though we're far less limited nowadays on size constraints, we remain extremely limited in terms of time, and do not have volunteers who are available to maintain a larger SVG library.
For more sophisticated import/export, consider the Batik library from the Apache Software Foundation.
Batik is used in the SVG Export library in Processing 3, however using it for full SVG import is still a considerable amount of work. Wiring it to Java2D wouldn't be too bad, but using it with OpenGL, JavaFX, and features like begin/endRecord() and begin/endRaw() would be considerable effort.
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.
A minimal example program using SVG: (assuming a working moo.svg is in your data folder)
PShape moo; void setup() { size(400, 400); moo = loadShape("moo.svg"); } void draw() { background(255); shape(moo, mouseX, mouseY); }
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
static class
static class
static class
static class
static class
-
Field Summary
Fields inherited from class processing.core.PShape
colorMode, colorModeA, colorModeX, colorModeY, colorModeZ, depth, GEOMETRY, height, INSIDE_BEGIN_END_ERROR, NO_SUCH_VERTEX_ERROR, NO_VERTICES_ERROR, NOT_A_SIMPLE_VERTEX, OUTSIDE_BEGIN_END_ERROR, PATH, PER_VERTEX_UNSUPPORTED, PRIMITIVE, width
Fields inherited from interface processing.core.PConstants
ADD, ALPHA, ALT, AMBIENT, ARC, ARGB, ARROW, BACKSPACE, BASELINE, BEVEL, BEZIER_VERTEX, BLEND, BLUR, BOTTOM, BOX, BREAK, BURN, CENTER, CHATTER, CHORD, CLAMP, CLOSE, CODED, COMPLAINT, CONTROL, CORNER, CORNERS, CROSS, CURVE_VERTEX, CUSTOM, DARKEST, DEG_TO_RAD, DELETE, DIAMETER, DIFFERENCE, DILATE, DIRECTIONAL, DISABLE_ASYNC_SAVEFRAME, DISABLE_BUFFER_READING, DISABLE_DEPTH_MASK, DISABLE_DEPTH_SORT, DISABLE_DEPTH_TEST, DISABLE_KEY_REPEAT, DISABLE_NATIVE_FONTS, DISABLE_OPENGL_ERRORS, DISABLE_OPTIMIZED_STROKE, DISABLE_STROKE_PERSPECTIVE, DISABLE_STROKE_PURE, DISABLE_TEXTURE_MIPMAPS, DODGE, DOWN, DXF, ELLIPSE, ENABLE_ASYNC_SAVEFRAME, ENABLE_BUFFER_READING, ENABLE_DEPTH_MASK, ENABLE_DEPTH_SORT, ENABLE_DEPTH_TEST, ENABLE_KEY_REPEAT, ENABLE_NATIVE_FONTS, ENABLE_OPENGL_ERRORS, ENABLE_OPTIMIZED_STROKE, ENABLE_STROKE_PERSPECTIVE, ENABLE_STROKE_PURE, ENABLE_TEXTURE_MIPMAPS, ENTER, EPSILON, ERODE, ESC, EXCLUSION, FX2D, GIF, GRAY, GROUP, HALF_PI, HAND, HARD_LIGHT, HINT_COUNT, HSB, IMAGE, INVERT, JAVA2D, JPEG, LANDSCAPE, LEFT, LIGHTEST, LINE, LINE_LOOP, LINE_STRIP, LINES, LINUX, MACOS, MACOSX, MAX_FLOAT, MAX_INT, MIN_FLOAT, MIN_INT, MITER, MODEL, MODELVIEW, MOVE, MULTIPLY, NORMAL, OPAQUE, OPEN, OPENGL, ORTHOGRAPHIC, OTHER, OVERLAY, P2D, P3D, PDF, PERSPECTIVE, PI, PIE, platformNames, POINT, POINTS, POLYGON, PORTRAIT, POSTERIZE, PROBLEM, PROJECT, PROJECTION, QUAD, QUAD_BEZIER_VERTEX, QUAD_STRIP, QUADRATIC_VERTEX, QUADS, QUARTER_PI, RAD_TO_DEG, RADIUS, RECT, REPEAT, REPLACE, RETURN, RGB, RIGHT, ROUND, SCREEN, SHAPE, SHIFT, SOFT_LIGHT, SPAN, SPHERE, SPOT, SQUARE, SUBTRACT, SVG, TAB, TARGA, TAU, TEXT, THIRD_PI, THRESHOLD, TIFF, TOP, TRIANGLE, TRIANGLE_FAN, TRIANGLE_STRIP, TRIANGLES, TWO_PI, UP, VERTEX, WAIT, WHITESPACE, WINDOWS, X, Y, Z
-
Constructor Summary
-
Method Summary
Methods inherited from class processing.core.PShape
addChild, addChild, addName, ambient, ambient, ambient, applyMatrix, applyMatrix, applyMatrix, applyMatrix, applyMatrix, attrib, attrib, attrib, attribColor, attribNormal, attribPosition, beginContour, beginShape, beginShape, beginTessellation, beginTessellation, bezierDetail, bezierVertex, bezierVertex, colorMode, colorMode, colorMode, colorMode, contains, curveDetail, curveTightness, curveVertex, curveVertex, disableStyle, draw, emissive, emissive, emissive, enableStyle, endContour, endShape, endShape, endTessellation, fill, fill, fill, fill, fill, fill, findChild, getAmbient, getChild, getChildCount, getChildIndex, getChildren, getDepth, getEmissive, getFamily, getFill, getHeight, getKind, getName, getNormal, getNormal, getNormalX, getNormalY, getNormalZ, getParam, getParams, getParams, getParent, getShininess, getSpecular, getStroke, getStrokeWeight, getTessellation, getTextureU, getTextureV, getTint, getVertex, getVertex, getVertexCode, getVertexCodeCount, getVertexCodes, getVertexCount, getVertexX, getVertexY, getVertexZ, getWidth, is2D, is3D, isClosed, isVisible, noFill, normal, noStroke, noTexture, noTint, quadraticVertex, quadraticVertex, removeChild, resetMatrix, rotate, rotate, rotateX, rotateY, rotateZ, scale, scale, scale, set3D, setAmbient, setAmbient, setEmissive, setEmissive, setFamily, setFill, setFill, setFill, setKind, setName, setNormal, setPath, setShininess, setShininess, setSpecular, setSpecular, setStroke, setStroke, setStroke, setStrokeCap, setStrokeJoin, setStrokeWeight, setStrokeWeight, setTexture, setTextureMode, setTextureUV, setTint, setTint, setTint, setVertex, setVertex, setVertex, setVisible, shininess, specular, specular, specular, stroke, stroke, stroke, stroke, stroke, stroke, strokeCap, strokeJoin, strokeWeight, texture, textureMode, tint, tint, tint, tint, tint, tint, translate, translate, vertex, vertex, vertex, vertex
-
Constructor Details
-
PShapeSVG
Initializes a new SVG object from the given XML object.
-
-
Method Details
-
getChild
Get a particular element based on its SVG ID. When editing SVG by hand, this is the id="" tag on any SVG element. When editing from Illustrator, these IDs can be edited by expanding the layers palette. The names used in the layers palette, both for the layers or the shapes and groups beneath them can be used here.// This code grabs "Layer 3" and the shapes beneath it. PShape layer3 = svg.getChild("Layer 3");
-
print
public void print()Prints out the SVG document. Useful for parsing.
-