SVGPath 1.0 → 1.0.1
raw patch · 2 files changed
+22/−16 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Graphics.SVG.ReadPath: ctp :: [PathCommand] -> [F2] -> F2 -> Bool -> Int -> F2 -> [[F2]]
Files
- SVGPath.cabal +1/−1
- src/Graphics/SVG/ReadPath.hs +21/−15
SVGPath.cabal view
@@ -1,5 +1,5 @@ Name: SVGPath -Version: 1.0 +Version: 1.0.1 Synopsis: Parsing the path command from SVG Description: Parsing the path command from SVG category: Graphics
src/Graphics/SVG/ReadPath.hs view
@@ -14,6 +14,7 @@ ( pathFromString, PathCommand(..), commandsToPoints, + ctp, bSubCurve ) where @@ -32,11 +33,15 @@ type X2 = X type Y2 = Y data PathCommand = - M_abs Tup | M_rel Tup | -- ^establish a new current point (with absolute coords or rel. to the current point) + M_abs Tup | -- ^Establish a new current point (with absolute coords) + M_rel Tup | -- ^Establish a new current point (with coords relative to the current point) Z | -- ^Close current subpath by drawing a straight line from current point to current subpath's initial point - L_abs Tup | L_rel Tup | -- ^a line from the current point to Tup which becomes the new current point - H_abs X | H_rel X | -- ^a horizontal line from the current point (cpx, cpy) to (x, cpy) - V_abs Y | V_rel Y | -- ^a vertical line from the current point (cpx, cpy) to (cpx, y) + L_abs Tup | -- ^A line from the current point to Tup which becomes the new current point + L_rel Tup | + H_abs X | -- ^A horizontal line from the current point (cpx, cpy) to (x, cpy) + H_rel X | + V_abs Y | -- ^A vertical line from the current point (cpx, cpy) to (cpx, y) + V_rel Y | C_abs (X1,Y1,X2,Y2,X,Y) | -- ^Draws a cubic Bézier curve from the current point to (x,y) using (x1,y1) as the -- ^control point at the beginning of the curve and (x2,y2) as the control point at the end of the curve. C_rel (X1,Y1,X2,Y2,X,Y) | @@ -46,11 +51,12 @@ -- point is coincident with the current point.) (x2,y2) is the second control point (i.e., the control point at -- the end of the curve). S_rel (X2,Y2,X,Y) | - Q_abs (X1,Y1,X,Y) | -- ^a quadr. Bézier curve from the curr. point to (x,y) using (x1,y1) as the control point - Q_rel (X1,Y1,X,Y) | -- ^nearly the same as cubic, but with one point less - T_abs Tup | T_rel Tup | -- ^T_Abs = Shorthand/smooth quadratic Bezier curveto - A_abs | -- ^A = elliptic arc - A_rel -- ^A = elliptic arc (not used) + Q_abs (X1,Y1,X,Y) | -- ^A quadr. Bézier curve from the curr. point to (x,y) using (x1,y1) as the control point + Q_rel (X1,Y1,X,Y) | -- ^Nearly the same as cubic, but with one point less + T_abs Tup | -- ^T_Abs = Shorthand/smooth quadratic Bezier curveto + T_rel Tup | + A_abs | -- ^A = Elliptic arc (not used) + A_rel deriving Show -- | convert a SVG path string into alist of commands @@ -81,10 +87,10 @@ do{ symbol "Z"; return [Z]; } <|> do{ symbol "L"; l <- many1 tupel2; return (map (\x-> L_abs x) l) } <|> do{ symbol "l"; l <- many1 tupel2; return (map (\x-> L_rel x) l) } <|> - do{ symbol "H"; l <- many1 integer; return (map (\x-> H_abs (fromIntegral x)) l) } <|> - do{ symbol "h"; l <- many1 integer; return (map (\x-> H_rel (fromIntegral x)) l) } <|> - do{ symbol "V"; l <- many1 integer; return (map (\x-> V_abs (fromIntegral x)) l) } <|> - do{ symbol "v"; l <- many1 integer; return (map (\x-> V_rel (fromIntegral x)) l) } <|> + do{ symbol "H"; l <- many1 myfloat; return (map (\x-> H_abs (realToFrac x)) l) } <|> + do{ symbol "h"; l <- many1 myfloat; return (map (\x-> H_rel (realToFrac x)) l) } <|> + do{ symbol "V"; l <- many1 myfloat; return (map (\x-> V_abs (realToFrac x)) l) } <|> + do{ symbol "v"; l <- many1 myfloat; return (map (\x-> V_rel (realToFrac x)) l) } <|> do{ symbol "C"; l <- many1 tupel6; return (map (\x-> C_abs x) l) } <|> do{ symbol "c"; l <- many1 tupel6; return (map (\x-> C_rel x) l) } <|> do{ symbol "S"; l <- many1 tupel4; return (map (\x-> S_abs x) l) } <|> @@ -199,10 +205,10 @@ -- an x-, y-resoultion raster. dx, dy is the width and height of a pixel of this raster. bSubCurve :: Bool -> (X,Y) -> [F2] -> [F2] bSubCurve useTex (dx,dy) bs | ((abs (p1x-p0x)) < dx && (abs (p1y-p0y)) < dy && (not useTex)) || -- line that is at most one pixel long + ((dx == 0 || dy == 0) && (not useTex)) || ((abs (p1x-p0x)) < 1 && (abs (p1y-p0y)) < 1 && useTex) || ((abs (p1x-p0x)) < 1 && p0x_int == p1x_int && useTex) || -- vertical line - ((abs (p1y-p0y)) < 1 && p0y_int == p1y_int && useTex) || -- horizontal line - (useTex == False && (dx == 0 || dy == 0)) + ((abs (p1y-p0y)) < 1 && p0y_int == p1y_int && useTex) -- horizontal line = [ (p0x, p0y), (p1x, p1y) ] | otherwise = firstArc ++ secondArc -- tail secondArc -- subdivide