processing.core

## Class PShapeSVG

- Object
- - PShape
  - - PShapeSVG

- All Implemented Interfaces:
    PConstants
  Direct Known Subclasses:
    PShapeSVG.Font, PShapeSVG.FontGlyph

      public class PShapeSVG
      extends PShape

  This class is not part of the Processing API and should not be used directly. Instead, use loadShape() and methods like it, which will make use of this class. Using this class directly will cause your code to break when combined with future versions of Processing.

  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. Starting with release 0149, this library has been incorporated into the core via the loadShape() command, because vector shape data is just as important as the image data from loadImage().

  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.

  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);
       }

  This code is based on the Candy library written by Michael Chang, which was later revised and expanded for use as a Processing core library by Ben Fry. Thanks to Ricard Marxer Pinon for help with better Inkscape support in 0154.

  Late October 2008 revisions from ricardmp, incorporated by fry (0154)

  - Better style attribute handling, enabling better Inkscape support.
  October 2008 revisions by fry (Processing 0149, pre-1.0)
  - Candy is no longer a separate library, and is instead part of core.
  - Loading now works through loadShape()
  - Shapes are now drawn using the new PGraphics shape() method.
  August 2008 revisions by fry (Processing 0149)
  - Major changes to rework around PShape.
  - Now implementing more of the "transform" attribute.
  February 2008 revisions by fry (Processing 0136)
  - Added support for quadratic curves in paths (Q, q, T, and t operators)
  - Support for reading SVG font data (though not rendering it yet)
  Revisions for "Candy 2" November 2006 by fry
  - Switch to the new processing.xml library
  - Several bug fixes for parsing of shape data
  - Support for linear and radial gradients
  - Support for additional types of shapes
  - Added compound shapes (shapes with interior points)
  - Added methods to get shapes from an internal table
  Revision 10/31/06 by flux
  - 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 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
  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 added for Candy 2
  - Patterns
  - Embedded images
  For those interested, the SVG specification can be found here.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `PShapeSVG.Font`
    `class` | `PShapeSVG.FontGlyph`

  - ### Field Summary

    - ### Fields inherited from class PShape

      `colorMode, colorModeA, colorModeX, colorModeY, colorModeZ, depth, GEOMETRY, height, INSIDE_BEGIN_END_ERROR, OUTSIDE_BEGIN_END_ERROR, PATH, PRIMITIVE, width`

    - ### Fields inherited from interface 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_DEPTH_MASK, DISABLE_DEPTH_SORT, DISABLE_DEPTH_TEST, DISABLE_NATIVE_FONTS, DISABLE_OPENGL_ERRORS, DISABLE_OPTIMIZED_STROKE, DISABLE_RETINA_PIXELS, DISABLE_STROKE_PERSPECTIVE, DISABLE_STROKE_PURE, DISABLE_TEXTURE_MIPMAPS, DODGE, DOWN, DXF, ELLIPSE, ENABLE_DEPTH_MASK, ENABLE_DEPTH_SORT, ENABLE_DEPTH_TEST, ENABLE_NATIVE_FONTS, ENABLE_OPENGL_ERRORS, ENABLE_OPTIMIZED_STROKE, ENABLE_RETINA_PIXELS, ENABLE_STROKE_PERSPECTIVE, ENABLE_STROKE_PURE, ENABLE_TEXTURE_MIPMAPS, ENTER, EPSILON, ERODE, ERROR_BACKGROUND_IMAGE_FORMAT, ERROR_BACKGROUND_IMAGE_SIZE, ERROR_PUSHMATRIX_OVERFLOW, ERROR_PUSHMATRIX_UNDERFLOW, ERROR_TEXTFONT_NULL_PFONT, ESC, EXCLUSION, 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, 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, SPHERE, SPOT, SQUARE, SUBTRACT, 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

    Constructors
    Constructor and Description
    `PShapeSVG(XML svg)` Initializes a new SVG Object from the given PNode.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `PShape` | `getChild(String name)` Get a particular element based on its SVG ID.
    `void` | `print()` Prints out the SVG document.

    - ### Methods inherited from class PShape

      `addChild, addChild, addName, ambient, ambient, ambient, applyMatrix, applyMatrix, applyMatrix, applyMatrix, applyMatrix, beginContour, beginShape, beginShape, bezierDetail, bezierVertex, bezierVertex, colorMode, colorMode, colorMode, colorMode, contains, curveDetail, curveTightness, curveVertex, curveVertex, disableStyle, draw, drawImpl, emissive, emissive, emissive, enableStyle, endContour, endShape, endShape, 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, is3D, isClosed, isVisible, noFill, normal, noStroke, noTexture, noTint, quadraticVertex, quadraticVertex, removeChild, resetMatrix, rotate, rotate, rotateX, rotateY, rotateZ, scale, scale, scale, setAmbient, setAmbient, setEmissive, setEmissive, 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`

    - ### Methods inherited from class Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### PShapeSVG

          public PShapeSVG(XML svg)

      Initializes a new SVG Object from the given PNode.

  - ### Method Detail

    - #### getChild

          public PShape getChild(String name)

      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");

      Overrides:
        `getChild` in class `PShape`
      Parameters:
        `name` - the name of the shape to get

    - #### print

          public void print()

      Prints out the SVG document. Useful for parsing.