SVGPathNormalizer
SVGPathNormalizer copied to clipboard
SVGPathNormalizer
Most modern web browsers do not implement SVGAnimatedPathData.normalizedPathSegList probably because of its severe specification : for example, it is too difficult to express elliptical arcs by cubic bezier curves.
This normalizer expresses paths using the following commands only :
- SVG_PATHSEG_MOVETO_ABS (M),
- SVG_PATHSEG_LINETO_ABS (L),
- SVG_PATHSEG_CURVETO_CUBIC_ABS (C),
- SVG_PATHSEG_CURVETO_QUADRATIC_ABS (Q),
- SVG_PATHSEG_ARC_ABS (A) and
- SVG_PATHSEG_CLOSEPATH (z).
License
MIT License. See LICENSE file for more details.
Usage
- Import the file
svgpathnormalizer.jsin your HTML or SVG document - Get reference to
<path>element. For example, usedocument.getElementById(idString) - Get an instance of
SVGPathSegListviapathSegListproperty of the<path>element - Call
SVGPathNormalizer.normalizefunction with just one argument : the instance ofSVGPathSegList - You will get another instance of
SVGPathSegListwhich is normalized.
Please note that the original <path> will NOT be modified even if you modify the returned instance of SVGPathSegList.
Requirement
Your runtime environment MUST support SVG 1.1. Most modern web browsers - including Internet Explorer 11 - match the requirement.
Chrome 48 and Firefox 43 have removed SVGPathSegList implementation. So you will also require SVGPathSeg polyfill.