ImportSVG

Sprite
ImportSVG

SVG XML import parser creating a list of svg shape objects.  AS3 rewrite of drawsvg_mm.as which was based on drawsvg.as.

Summary
ImportSVGSVG XML import parser creating a list of svg shape objects.
Public properties
shapesArray of ShapeSVG objects.
Public methods
parseSVGParses an SVG XML text into the shapes array.
generateCodeGenerates and returns an AS3 method that returns a Sprite representing the imported SVG path definitions.
numPointsReturns the number of line segment points in all defined shapes.
Private methods
findPathNodeRecursively looks at XML objects to find PATH nodes.
parseFillParses a SVG fill attribute.
parseStrokeParses a SVG stroke line style.
defineShapeReads a SVG path node.
createShapeDefCreates and returns a ShapeSVG object from the d attribute of the SVG PATH tag given in the cmds array.

Public properties

shapes

public var shapes: Array

Array of ShapeSVG objects.

Public methods

parseSVG

public function parseSVG(srcXML: String,
parseTolerance: int):int

Parses an SVG XML text into the shapes array.

Parameters

srcXMLSVG XML document
parseToleranceApproximation tolerance, see Bezier

Returns

Number of shapes found

generateCode

public function generateCode():String

Generates and returns an AS3 method that returns a Sprite representing the imported SVG path definitions.

numPoints

public function get numPoints():int

Returns the number of line segment points in all defined shapes.

Private methods

findPathNode

private function findPathNode(node: XMLNode,
defaultFill: Object,
defaultStroke: Object):void

Recursively looks at XML objects to find PATH nodes.  When one is found, it calls defineShape to parse the PATH node and calls createShapeDef to create a ShapeSVG object which is pushed onto the shapes array.

parseFill

private function parseFill(attributes: Object,
defaultFill: Object):Object

Parses a SVG fill attribute.

parseStroke

private function parseStroke(attributes: Object,
defaultStroke: Object):Object

Parses a SVG stroke line style.

defineShape

private function defineShape(node: XMLNode,
defaultFill: Object,
defaultStroke: Object):void

Reads a SVG path node.

Extracts

  • the rotation to be applied
  • an array of each letter command and coordinate in the d attribute
  • fill and stroke colors

Then calls createShapeDef to create a ShapeSVG object

createShapeDef

private function createShapeDef(cmds: Array,
rotation: int,
fill: Object,
stroke: Object):ShapeSVG

Creates and returns a ShapeSVG object from the d attribute of the SVG PATH tag given in the cmds array.

public var shapes: Array
Array of ShapeSVG objects.
Shape object used in SVG import.
public function parseSVG(srcXML: String,
parseTolerance: int):int
Parses an SVG XML text into the shapes array.
public function generateCode():String
Generates and returns an AS3 method that returns a Sprite representing the imported SVG path definitions.
public function get numPoints():int
Returns the number of line segment points in all defined shapes.
private function findPathNode(node: XMLNode,
defaultFill: Object,
defaultStroke: Object):void
Recursively looks at XML objects to find PATH nodes.
private function parseFill(attributes: Object,
defaultFill: Object):Object
Parses a SVG fill attribute.
private function parseStroke(attributes: Object,
defaultStroke: Object):Object
Parses a SVG stroke line style.
private function defineShape(node: XMLNode,
defaultFill: Object,
defaultStroke: Object):void
Reads a SVG path node.
private function createShapeDef(cmds: Array,
rotation: int,
fill: Object,
stroke: Object):ShapeSVG
Creates and returns a ShapeSVG object from the d attribute of the SVG PATH tag given in the cmds array.
Bezier approximation methods used in SVG import.
Close