Path toJSON

From SVG

This proposal adds a method to SVG Paths (and the Path() object) to allow them to be serialized as a normalized JSON object.

This derives from the SVG 1.1 SVGPathSeg Interface.

Syntax

[
  {
    "type": "MoveTo",
    "absolute": ''boolean'',
    "x": ''float'',
    "y": ''float''
  },

  {
    "type": "LineTo",
    "absolute": ''boolean'',
    "x": ''float'',
    "y": ''float''
  },

  {
    "type": "LineToHorizontal",
    "absolute": ''boolean'',
    "x": ''float''
  },

  {
    "type": "LineToVertical",
    "absolute": ''boolean'',
    "y": ''float''
  },

  {
    "type": "CubicCurveTo",
    "absolute": ''boolean'',
    "x": ''float'',
    "y": ''float'',
    "x1": ''float'',
    "y1": ''float'',
    "x2": ''float'',
    "y2": ''float''
  },

  {
    "type": "QuadraticCurveTo",
    "absolute": ''boolean'',
    "x": ''float'',
    "y": ''float'',
    "x1": ''float'',
    "y1": ''float''
  },

  {
    "type": "SmoothQuadraticCurveTo",
    "absolute": ''boolean'',
    "x": ''float'',
    "y": ''float''
  },

  {
    "type": "SmoothCubicCurveTo",
    "absolute": ''boolean'',
    "x": ''float'',
    "y": ''float'',
    "x2": ''float'',
    "y2": ''float''
  },

  {
    "type": "ArcBetween",
    "absolute": ''boolean'',
    "x": ''float'',
    "y": ''float'',
    "r1": ''float'',
    "r2": ''float'',
    "rotation": ''float'',
    "largeArc": ''boolean'',
    "clockwise": ''boolean''
  },

  {
    type: "ClosePath"
  }
]

Issues

The 'largeArc' and 'clockwise' properties of "ArcBetween" may be better stated as enums rather than bools: "size: [big|small]" and "direction: [cw|ccw]"


Commands

MoveTo

Absolute

Represents the "absolute moveto" (M) path data command.

Corresponds to PATHSEG_MOVETO_ABS.

Relative

Represents the "relative moveto" (m) path data command.

Corresponds to PATHSEG_MOVETO_REL.

LineTo

Absolute

Represents the "absolute lineto" (L) path data command.

Corresponds to PATHSEG_LINETO_ABS.

Relative

Represents the "relative lineto" (l) path data command.

Corresponds to PATHSEG_LINETO_REL.

ArcBetween

Absolute

Represents the "absolute arcbetween" (A) path data command.

Corresponds to PATHSEG_ARC_ABS.

Relative

Represents the "relative arcbetween" (a) path data command.

Corresponds to PATHSEG_ARC_REL.

Horizontal LineTo

Absolute

Represents the "absolute horizontal lineto" (H) path data command.

Corresponds to PATHSEG_LINETO_HORIZONTAL_ABS.

Relative

Represents the "relative horizontal lineto" (h) path data command.

Corresponds to PATHSEG_LINETO_HORIZONTAL_REL.

Vertical LineTo

Absolute

Represents the "absolute vertical lineto" (V) path data command.

Corresponds to PATHSEG_LINETO_VERTICAL_ABS.

Relative

Represents the "relative vertical lineto" (v) path data command.

Corresponds to PATHSEG_LINETO_VERTICAL_REL.

Cubic Bézier CurveTo

Absolute

Represents the "absolute cubic Bézier curveto" C) path data command.

Corresponds to PATHSEG_CURVETO_CUBIC_ABS.

Relative

Represents the "relative cubic Bézier curveto" C) path data command.

Corresponds to PATHSEG_CURVETO_CUBIC_REL.

Quadratic Bézier CurveTo

Absolute

Represents the "absolute quadratic Bézier curveto" (Q) path data command.

Corresponds to PATHSEG_CURVETO_QUADRATIC_ABS.

Relative

Represents the "relative quadratic Bézier curveto" (q) path data command.

Corresponds to PATHSEG_CURVETO_QUADRATIC_REL.

Smooth Cubic Bézier CurveTo

Absolute

Represents the "absolute smooth cubic curveto" (S) path data command.

Corresponds to PATHSEG_CURVETO_CUBIC_SMOOTH_ABS.

Relative

Represents the "relative smooth cubic curveto" (s) path data command.

Corresponds to PATHSEG_CURVETO_CUBIC_SMOOTH_REL.

Smooth Quadratic Bézier CurveTo

Absolute

Represents the "absolute smooth quadratic curveto" (T) path data command.

Corresponds to PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS.

Relative

Represents the "relative smooth quadratic curveto" (t) path data command.

Corresponds to PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL.

ClosePath

Represents the "closepath" (z) path data command.

Corresponds to PATHSEG_CLOSEPATH.

Unknown

The unit type is not one of predefined types. It is invalid to attempt to define a new value of this type or to attempt to switch an existing value to this type.

Corresponds to PATHSEG_UNKNOWN.


Attributes

pathSegType

The type of the path segment as specified by one of the constants defined on this interface.

Corresponds to 'pathSegType (readonly unsigned short)

pathSegTypeAsLetter

The type of the path segment, specified by the corresponding command name.

Corresponds to 'pathSegTypeAsLetter (readonly DOMString)