Safe Haskell | None |
---|---|
Language | Haskell2010 |
SVG path manipulation
Synopsis
- parsePath :: Text -> Either String [PathCommand]
- svgToPathData :: Text -> [PathData Double]
- pathDataToSvg :: [PathData Double] -> Text
- data PathCommand
- = MoveTo !Origin ![Point Double]
- | LineTo !Origin ![Point Double]
- | HorizontalTo !Origin ![Double]
- | VerticalTo !Origin ![Double]
- | CurveTo !Origin ![(Point Double, Point Double, Point Double)]
- | SmoothCurveTo !Origin ![(Point Double, Point Double)]
- | QuadraticBezier !Origin ![(Point Double, Point Double)]
- | SmoothQuadraticBezierCurveTo !Origin ![Point Double]
- | EllipticalArc !Origin ![(Double, Double, Double, Bool, Bool, Point Double)]
- | EndPath
- data Origin
Parsing
Every element of an svg path can be thought of as exactly two points in space, with instructions of how to draw a curve between them. From this point of view, one which this library adopts, a path chart is thus very similar to a line chart. There's just a lot more information about the style of this line to deal with.
References:
parsePath :: Text -> Either String [PathCommand] Source #
Parse a raw path string.
>>>
let outerseg1 = "M-1.0,0.5 A0.5 0.5 0.0 1 1 0.0,-1.2320508075688774 1.0 1.0 0.0 0 0 -0.5,-0.3660254037844387 1.0 1.0 0.0 0 0 -1.0,0.5 Z"
>>>
parsePath outerseg1
Right [MoveTo OriginAbsolute [Point -1.0 0.5],EllipticalArc OriginAbsolute [(0.5,0.5,0.0,True,True,Point 0.0 -1.2320508075688774),(1.0,1.0,0.0,False,False,Point -0.5 -0.3660254037844387),(1.0,1.0,0.0,False,False,Point -1.0 0.5)],EndPath]
https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d
svgToPathData :: Text -> [PathData Double] Source #
Convert an SVG d path text snippet to a [PathData Double]
data PathCommand Source #
Path command definition (ripped from reanimate-svg).
MoveTo !Origin ![Point Double] | M or m command |
LineTo !Origin ![Point Double] | Line to, L or l Svg path command. |
HorizontalTo !Origin ![Double] | Equivalent to the H or h svg path command. |
VerticalTo !Origin ![Double] | Equivalent to the V or v svg path command. |
CurveTo !Origin ![(Point Double, Point Double, Point Double)] | Cubic bezier, C or c command |
SmoothCurveTo !Origin ![(Point Double, Point Double)] | Smooth cubic bezier, equivalent to S or s command |
QuadraticBezier !Origin ![(Point Double, Point Double)] | Quadratic bezier, Q or q command |
SmoothQuadraticBezierCurveTo !Origin ![Point Double] | Quadratic bezier, T or t command |
EllipticalArc !Origin ![(Double, Double, Double, Bool, Bool, Point Double)] | Elliptical arc, A or a command. |
EndPath | Close the path, Z or z svg path command. |