rasterific-svg 0.1.1 → 0.2
raw patch · 6 files changed
+127/−123 lines, 6 filesdep ~svg-treePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: svg-tree
API changes (from Hackage documentation)
Files
- changelog +3/−0
- rasterific-svg.cabal +71/−71
- src/Graphics/Rasterific/Svg/PathConverter.hs +12/−12
- src/Graphics/Rasterific/Svg/RasterificRender.hs +11/−9
- src/Graphics/Rasterific/Svg/RasterificTextRendering.hs +6/−6
- src/Graphics/Rasterific/Svg/RenderContext.hs +24/−25
changelog view
@@ -1,5 +1,8 @@ -*-change-log-*- +v0.2 April 2015+ * Bumping: using svg-tree 0.3+ v0.1.1 April 2015 * Fix: Fixing GHC 7.10.1 related warnings * Fix: Group transparency.
rasterific-svg.cabal view
@@ -1,71 +1,71 @@--- Initial svg.cabal generated by cabal init. For further documentation, --- see http://haskell.org/cabal/users-guide/ -name: rasterific-svg -version: 0.1.1 -synopsis: SVG renderer based on Rasterific. -description: SVG renderer that will let you render svg-tree parsed - SVG file to a JuicyPixel image or Rasterific Drawing. -license: BSD3 -license-file: LICENSE -author: Vincent Berthoux -maintainer: Vincent Berthoux --- copyright: -extra-source-files: changelog -category: Graphics, Svg -build-type: Simple -cabal-version: >=1.10 - -Source-Repository head - Type: git - Location: git://github.com/Twinside/rasterific-svg.git - -Source-Repository this - Type: git - Location: git://github.com/Twinside/rasterific-svg.git - Tag: v0.1.1 - -library - hs-source-dirs: src - default-language: Haskell2010 - Ghc-options: -O3 -Wall - ghc-prof-options: -Wall -prof - -- -auto-all - exposed-modules: Graphics.Rasterific.Svg - other-modules: Graphics.Rasterific.Svg.RenderContext - , Graphics.Rasterific.Svg.PathConverter - , Graphics.Rasterific.Svg.RasterificRender - , Graphics.Rasterific.Svg.RasterificTextRendering - - build-depends: base >= 4.6 && < 4.9 - , directory - , bytestring >= 0.10 - , filepath - , binary >= 0.7 - , scientific >= 0.3 - , JuicyPixels >= 3.2 && < 3.3 - , containers >= 0.5 - , Rasterific >= 0.5.2.1 && < 0.6 - , FontyFruity >= 0.5 && < 0.6 - , svg-tree >= 0.2 && < 0.3 - , lens >= 4.5 && < 4.10 - , linear >= 1.16 - , vector >= 0.10 - , text >= 1.2 - , transformers >= 0.3 && < 0.5 - , mtl >= 2.1 && < 2.3 - -Executable svgrender - default-language: Haskell2010 - hs-source-dirs: exec-src - Main-Is: svgrender.hs - Ghc-options: -O3 -Wall - ghc-prof-options: -rtsopts -Wall -prof - Build-Depends: base >= 4.6 - , optparse-applicative >= 0.11 && < 0.12 - , rasterific-svg - , Rasterific - , JuicyPixels - , filepath - , FontyFruity - , svg-tree - +-- Initial svg.cabal generated by cabal init. For further documentation, +-- see http://haskell.org/cabal/users-guide/+name: rasterific-svg+version: 0.2+synopsis: SVG renderer based on Rasterific.+description: SVG renderer that will let you render svg-tree parsed+ SVG file to a JuicyPixel image or Rasterific Drawing.+license: BSD3+license-file: LICENSE+author: Vincent Berthoux+maintainer: Vincent Berthoux+-- copyright: +extra-source-files: changelog+category: Graphics, Svg+build-type: Simple+cabal-version: >=1.10++Source-Repository head+ Type: git+ Location: git://github.com/Twinside/rasterific-svg.git++Source-Repository this+ Type: git+ Location: git://github.com/Twinside/rasterific-svg.git+ Tag: v0.2++library+ hs-source-dirs: src+ default-language: Haskell2010+ Ghc-options: -O3 -Wall+ ghc-prof-options: -Wall -prof + -- -auto-all+ exposed-modules: Graphics.Rasterific.Svg+ other-modules: Graphics.Rasterific.Svg.RenderContext+ , Graphics.Rasterific.Svg.PathConverter+ , Graphics.Rasterific.Svg.RasterificRender+ , Graphics.Rasterific.Svg.RasterificTextRendering++ build-depends: base >= 4.6 && < 4.9+ , directory+ , bytestring >= 0.10+ , filepath+ , binary >= 0.7+ , scientific >= 0.3+ , JuicyPixels >= 3.2 && < 3.3+ , containers >= 0.5+ , Rasterific >= 0.5.2.1 && < 0.6+ , FontyFruity >= 0.5 && < 0.6+ , svg-tree >= 0.3 && < 0.4+ , lens >= 4.5 && < 4.10+ , linear >= 1.16+ , vector >= 0.10+ , text >= 1.2+ , transformers >= 0.3 && < 0.5+ , mtl >= 2.1 && < 2.3++Executable svgrender+ default-language: Haskell2010+ hs-source-dirs: exec-src+ Main-Is: svgrender.hs+ Ghc-options: -O3 -Wall+ ghc-prof-options: -rtsopts -Wall -prof+ Build-Depends: base >= 4.6+ , optparse-applicative >= 0.11 && < 0.12+ , rasterific-svg+ , Rasterific+ , JuicyPixels+ , filepath+ , FontyFruity+ , svg-tree+
src/Graphics/Rasterific/Svg/PathConverter.hs view
@@ -32,12 +32,12 @@ go (QuadraticBezier o lst) = QuadraticBezier o . pure <$> lst go (SmoothQuadraticBezierCurveTo o lst) = SmoothQuadraticBezierCurveTo o . pure <$> lst- go (ElipticalArc o lst) = ElipticalArc o . pure <$> lst+ go (EllipticalArc o lst) = EllipticalArc o . pure <$> lst go EndPath = [EndPath] toR :: RPoint -> R.Point {-# INLINE toR #-}-toR (L.V2 x y) = R.V2 x y+toR (L.V2 x y) = realToFrac <$> R.V2 x y svgPathToPrimitives :: Bool -> [PathCommand] -> [R.Primitive] svgPathToPrimitives _ lst | isPathWithArc lst = []@@ -67,14 +67,14 @@ ((pp, pp, pp), []) where pp = o ^+^ toR p go (o@(R.V2 _ y), _, fp) (HorizontalTo OriginAbsolute (c:_)) =- ((p, p, fp), R.line o p) where p = R.V2 c y+ ((p, p, fp), R.line o p) where p = R.V2 (realToFrac c) y go (o@(R.V2 x y), _, fp) (HorizontalTo OriginRelative (c:_)) =- ((p, p, fp), R.line o p) where p = R.V2 (x + c) y+ ((p, p, fp), R.line o p) where p = R.V2 (x + realToFrac c) y go (o@(R.V2 x _), _, fp) (VerticalTo OriginAbsolute (c:_)) =- ((p, p, fp), R.line o p) where p = R.V2 x c+ ((p, p, fp), R.line o p) where p = R.V2 x (realToFrac c) go (o@(R.V2 x y), _, fp) (VerticalTo OriginRelative (c:_)) =- ((p, p, fp), R.line o p) where p = R.V2 x (c + y)+ ((p, p, fp), R.line o p) where p = R.V2 x (realToFrac c + y) go (o, _, fp) (LineTo OriginRelative (c:_)) = ((p, p, fp), R.line o p) where p = o ^+^ toR c@@ -129,7 +129,7 @@ where c1' = o ^* 2 ^-^ control e' = o ^+^ toR e - go _ (ElipticalArc _ _) = error "Unimplemented"+ go _ (EllipticalArc _ _) = error "Unimplemented" -- | Conversion function between svg path to the rasterific one.@@ -162,14 +162,14 @@ ((pp, pp, pp), []) where pp = o ^+^ toR p go (R.V2 _ y, _, fp) (HorizontalTo OriginAbsolute (c:_)) =- ((p, p, fp), lineTo p) where p = R.V2 c y+ ((p, p, fp), lineTo p) where p = R.V2 (realToFrac c) y go (R.V2 x y, _, fp) (HorizontalTo OriginRelative (c:_)) =- ((p, p, fp), lineTo p) where p = R.V2 (x + c) y+ ((p, p, fp), lineTo p) where p = R.V2 (x + realToFrac c) y go (R.V2 x _, _, fp) (VerticalTo OriginAbsolute (c:_)) =- ((p, p, fp), lineTo p) where p = R.V2 x c+ ((p, p, fp), lineTo p) where p = R.V2 x (realToFrac c) go (R.V2 x y, _, fp) (VerticalTo OriginRelative (c:_)) =- ((p, p, fp), lineTo p) where p = R.V2 x (c + y)+ ((p, p, fp), lineTo p) where p = R.V2 x (realToFrac c + y) go (o, _, fp) (LineTo OriginRelative (c:_)) = ((p, p, fp), lineTo p) where p = o ^+^ toR c@@ -224,5 +224,5 @@ where c1' = o ^* 2 ^-^ control e' = o ^+^ toR e - go _ (ElipticalArc _ _) = error "Unimplemented"+ go _ (EllipticalArc _ _) = error "Unimplemented"
src/Graphics/Rasterific/Svg/RasterificRender.hs view
@@ -134,17 +134,19 @@ toTransformationMatrix :: Transformation -> RT.Transformation toTransformationMatrix = go where+ rf = realToFrac+ go (TransformMatrix a b c d e f) =- RT.Transformation a b c d e f- go (Translate x y) = RT.translate $ V2 x y- go (Scale xs Nothing) = RT.scale xs xs- go (Scale xs (Just ys)) = RT.scale xs ys+ RT.Transformation (rf a) (rf b) (rf c) (rf d) (rf e) (rf f)+ go (Translate x y) = RT.translate $ V2 (rf x) (rf y)+ go (Scale xs Nothing) = RT.scale (rf xs) (rf xs)+ go (Scale xs (Just ys)) = RT.scale (rf xs) (rf ys) go (Rotate angle Nothing) =- RT.rotate $ toRadian angle+ RT.rotate . toRadian $ rf angle go (Rotate angle (Just (cx, cy))) =- RT.rotateCenter (toRadian angle) $ V2 cx cy- go (SkewX v) = RT.skewX $ toRadian v- go (SkewY v) = RT.skewY $ toRadian v+ RT.rotateCenter (toRadian $ rf angle) $ V2 (rf cx) (rf cy)+ go (SkewX v) = RT.skewX . toRadian $ rf v+ go (SkewY v) = RT.skewY . toRadian $ rf v go TransformUnknown = mempty withTransform :: DrawAttributes -> R.Drawing a ()@@ -206,7 +208,7 @@ Nothing -> id Just OrientationAuto -> id Just (OrientationAngle a) -> - R.withTransformation (RT.rotate $ toRadian a)+ R.withTransformation (RT.rotate . toRadian $ realToFrac a) units = fromMaybe MarkerUnitStrokeWidth . _markerUnits
src/Graphics/Rasterific/Svg/RasterificTextRendering.hs view
@@ -141,7 +141,7 @@ , _charY = yC , _charDx = dxC , _charDy = dyC- , _charRotate = rotateC+ , _charRotate = realToFrac <$> rotateC , _charStroke = (,, joinOfSvg attr, capOfSvg attr) <$> sWidth <*> tex }@@ -212,7 +212,7 @@ lowerLeftCorner = boundLowerLeftCorner bounds toRPoint a b = linearisePoint ctxt mempty (a, b) mzero = Just $ Num 0- V2 pmx pmy = Just . Num <$> prevAbsolute+ V2 pmx pmy = Just . Num . realToFrac <$> prevAbsolute mayForcedPoint = case (_charX info, _charY info) of (Nothing, Nothing) -> Nothing@@ -230,7 +230,7 @@ Just p -> let newDelta = prevDelta ^+^ delta- positionDelta = p ^-^ lowerLeftCorner+ positionDelta = (realToFrac <$> p) ^-^ lowerLeftCorner trans = RT.translate $ positionDelta ^+^ newDelta in (newDelta, positionDelta, trans) @@ -435,10 +435,10 @@ startOffsetOfPath :: RenderContext -> DrawAttributes -> R.Path -> Number -> Float-startOffsetOfPath _ _ _ (Num i) = i-startOffsetOfPath _ attr _ (Em i) = emTransform attr i+startOffsetOfPath _ _ _ (Num i) = realToFrac i+startOffsetOfPath _ attr _ (Em i) = emTransform attr $ realToFrac i startOffsetOfPath _ _ tPath (Percent p) =- p * RO.approximatePathLength tPath+ realToFrac p * RO.approximatePathLength tPath startOffsetOfPath ctxt attr tPath num = startOffsetOfPath ctxt attr tPath $ stripUnits ctxt num
src/Graphics/Rasterific/Svg/RenderContext.hs view
@@ -103,11 +103,11 @@ abs <$> (maxi ^-^ mini) two = 2 :: Int coeff = sqrt (actualWidth ^^ two + actualHeight ^^ two)- / sqrt 2+ / sqrt 2 :: Float go num = case num of- Num n -> n- Em n -> emTransform attr n- Percent p -> p * coeff+ Num n -> realToFrac n+ Em n -> emTransform attr $ realToFrac n+ Percent p -> realToFrac p * coeff _ -> go $ stripUnits ctxt num boundbingBoxLinearise :: RenderContext -> DrawAttributes -> R.PlaneBound -> Point@@ -117,32 +117,32 @@ where R.V2 w h = abs <$> (maxi ^-^ mini) finalX nu = case nu of- Num n -> n- Em n -> emTransform attr n- Percent p -> p * w + xi+ Num n -> realToFrac n+ Em n -> emTransform attr $ realToFrac n+ Percent p -> realToFrac p * w + xi _ -> finalX $ stripUnits ctxt nu finalY nu = case nu of- Num n -> n- Em n -> emTransform attr n- Percent p -> p * h + yi+ Num n -> realToFrac n+ Em n -> emTransform attr $ realToFrac n+ Percent p -> realToFrac p * h + yi _ -> finalY $ stripUnits ctxt nu lineariseXLength :: RenderContext -> DrawAttributes -> Number- -> Coord-lineariseXLength _ _ (Num i) = i-lineariseXLength _ attr (Em i) = emTransform attr i-lineariseXLength ctxt _ (Percent p) = abs (xe - xs) * p+ -> Float+lineariseXLength _ _ (Num i) = realToFrac i+lineariseXLength _ attr (Em i) = emTransform attr $ realToFrac i+lineariseXLength ctxt _ (Percent p) = abs (xe - xs) * realToFrac p where (R.V2 xs _, R.V2 xe _) = _renderViewBox ctxt lineariseXLength ctxt attr num = lineariseXLength ctxt attr $ stripUnits ctxt num lineariseYLength :: RenderContext -> DrawAttributes -> Number- -> Coord-lineariseYLength _ _ (Num i) = i-lineariseYLength _ attr (Em n) = emTransform attr n-lineariseYLength ctxt _ (Percent p) = abs (ye - ys) * p+ -> Float+lineariseYLength _ _ (Num i) = realToFrac i+lineariseYLength _ attr (Em n) = emTransform attr $ realToFrac n+lineariseYLength ctxt _ (Percent p) = abs (ye - ys) * (realToFrac p) where (R.V2 _ ys, R.V2 _ ye) = _renderViewBox ctxt lineariseYLength ctxt attr num =@@ -158,16 +158,15 @@ emTransform :: DrawAttributes -> Float -> Float emTransform attr n = case getLast $ _fontSize attr of- Nothing -> 16 * n- Just (Num v) -> v * n+ Nothing -> 16 * realToFrac n+ Just (Num v) -> realToFrac v * n Just _ -> 16 * n lineariseLength :: RenderContext -> DrawAttributes -> Number- -> Coord-lineariseLength _ _ (Num i) = i-lineariseLength _ attr (Em i) =- emTransform attr i-lineariseLength ctxt _ (Percent v) = v * coeff+ -> Float+lineariseLength _ _ (Num i) = realToFrac i+lineariseLength _ attr (Em i) = emTransform attr $ realToFrac i+lineariseLength ctxt _ (Percent v) = realToFrac v * coeff where (R.V2 x1 y1, R.V2 x2 y2) = _renderViewBox ctxt actualWidth = abs $ x2 - x1