hps 0.1 → 0.2
raw patch · 13 files changed
+62/−21 lines, 13 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
+ Graphics.PS.Font: fontName :: Font -> String
+ Graphics.PS.Font: fontSize :: Font -> Double
+ Graphics.PS.GS: defaultGS :: Color -> GS
+ Graphics.PS.Statistics: Statistics :: Integer -> Integer -> Integer -> Integer -> Integer -> Statistics
+ Graphics.PS.Statistics: data Statistics
+ Graphics.PS.Statistics: nCurveTo :: Statistics -> Integer
+ Graphics.PS.Statistics: nGlyph :: Statistics -> Integer
+ Graphics.PS.Statistics: nLineTo :: Statistics -> Integer
+ Graphics.PS.Statistics: nMoveTo :: Statistics -> Integer
+ Graphics.PS.Statistics: nTransform :: Statistics -> Integer
- Graphics.PS.Transform: rotate :: (Transformable a) => Double -> a -> a
+ Graphics.PS.Transform: rotate :: Transformable a => Double -> a -> a
- Graphics.PS.Transform: scale :: (Transformable a) => Double -> Double -> a -> a
+ Graphics.PS.Transform: scale :: Transformable a => Double -> Double -> a -> a
- Graphics.PS.Transform: translate :: (Transformable a) => Double -> Double -> a -> a
+ Graphics.PS.Transform: translate :: Transformable a => Double -> Double -> a -> a
- Graphics.PS.Unit: mm_pt :: (Floating a) => a -> a
+ Graphics.PS.Unit: mm_pt :: Floating a => a -> a
- Graphics.PS.Unit: radians :: (Floating a) => a -> a
+ Graphics.PS.Unit: radians :: Floating a => a -> a
Files
- Graphics/PS/Bezier.hs +2/−0
- Graphics/PS/Font.hs +3/−1
- Graphics/PS/GS.hs +7/−2
- Graphics/PS/Glyph.hs +1/−0
- Graphics/PS/Image.hs +1/−0
- Graphics/PS/Matrix.hs +5/−0
- Graphics/PS/PS.hs +2/−0
- Graphics/PS/Path.hs +3/−2
- Graphics/PS/Pt.hs +5/−1
- Graphics/PS/Query.hs +4/−0
- Graphics/PS/Statistics.hs +19/−9
- README +1/−1
- hps.cabal +9/−5
Graphics/PS/Bezier.hs view
@@ -12,6 +12,8 @@ y = y1 * c + 2 * y2 * b * mu + y3 * a --} +-- | Four-point bezier curve interpolation. The index (mu) is+-- in the range zero to one. bezier4 :: Pt -> Pt -> Pt -> Pt -> Double -> Pt bezier4 (Pt x1 y1) (Pt x2 y2) (Pt x3 y3) (Pt x4 y4) mu = let a = 1 - mu
Graphics/PS/Font.hs view
@@ -1,4 +1,6 @@ module Graphics.PS.Font (Font(..)) where -data Font = Font String Double+-- | Font data type.+data Font = Font { fontName :: String+ , fontSize :: Double } deriving (Eq, Show)
Graphics/PS/GS.hs view
@@ -2,7 +2,7 @@ , LineCap(..) , LineJoin(..) , Color(..)- , greyGS ) where+ , defaultGS, greyGS ) where data LineCap = ButtCap | RoundCap @@ -22,8 +22,13 @@ data GS = GS Color LineWidth LineCap LineJoin ([Int], Int) Double deriving (Eq, Show) +-- | Default GS of indicated color.+defaultGS :: Color -> GS+defaultGS c = GS c 1.0 ButtCap MiterJoin ([], 0) 10.0++-- | Default GS of indicated shade of grey. greyGS :: Double -> GS-greyGS g = GS (RGB g g g) 1.0 ButtCap MiterJoin ([], 0) 10.0+greyGS g = defaultGS (RGB g g g) {-- blackGS :: GS
Graphics/PS/Glyph.hs view
@@ -1,3 +1,4 @@ module Graphics.PS.Glyph (Glyph) where +-- | Character data type. type Glyph = Char
Graphics/PS/Image.hs view
@@ -4,6 +4,7 @@ import qualified Graphics.PS.Path as P import qualified Graphics.PS.GS as G +-- | Image data type. data Image = Stroke G.GS P.Path | Fill G.GS P.Path | ITransform M.Matrix Image
Graphics/PS/Matrix.hs view
@@ -4,6 +4,7 @@ type R = Double +-- | Transformation matrix data type. data Matrix = Matrix R R R R R R deriving (Eq, Show) @@ -49,12 +50,15 @@ fromInteger n = let n' = fromInteger n in Matrix n' 0 0 n' 0 0 +-- | A translation matrix with independent x and y offsets. translation :: R -> R -> M translation = Matrix 1 0 0 1 +-- | A scaling matrix with independent x and y scalars. scaling :: R -> R -> M scaling x y = Matrix x 0 0 y 0 0 +-- | A rotation matrix through the indicated angle (in radians). rotation :: R -> M rotation a = let c = cos a@@ -62,6 +66,7 @@ t = negate s in Matrix c s t c 0 0 +-- | The identity matrix. identity :: M identity = Matrix 1 0 0 1 0 0
Graphics/PS/PS.hs view
@@ -204,6 +204,8 @@ let f n = floor (mm_pt (fromIntegral n)::Double) in P.Paper (f w) (f h) +-- | Write a postscript file. The list of images are written+-- one per page. ps :: String -> P.Paper -> [I.Image] -> IO () ps f d p = do h <- openFile f WriteMode
Graphics/PS/Path.hs view
@@ -8,6 +8,7 @@ import Graphics.PS.Glyph import Graphics.PS.Font +-- | Path data type, in cartesian space. data Path = MoveTo Pt | LineTo Pt | CurveTo Pt Pt Pt@@ -114,8 +115,6 @@ ,LineTo (Pt x4 y4) ,arcNegative (Pt x y) ir ea sa] --- Perform transformations- flatten' :: Matrix -> Path -> Path flatten' m (MoveTo p) = MoveTo (ptTransform m p) flatten' m (LineTo p) = LineTo (ptTransform m p)@@ -126,6 +125,8 @@ in CurveTo (f p) (f q) (f r) flatten' _ (Text _ _) = error "cannot flatten text" +-- | Apply any transformations at path. The resulting path will not+-- have any transformation nodes. flatten :: Path -> Path flatten = flatten' identity
Graphics/PS/Pt.hs view
@@ -5,6 +5,7 @@ import Graphics.PS.Matrix +-- | Point data type, component values are real. data Pt = Pt Double Double deriving (Eq, Show) @@ -21,11 +22,12 @@ instance Ord Pt where (Pt x0 y0) <= (Pt x1 y1) = x0 <= x1 && y0 <= y1 +-- | Origin, ie. (Pt 0 0). origin :: Pt origin = Pt 0 0 ptXYs :: [Pt] -> [Double]-ptXYs [] = []+ptXYs [] = [] ptXYs (Pt x y : ps) = x : y : ptXYs ps ptOp :: (Double -> Double -> Double) -> Pt -> Pt -> Pt@@ -37,9 +39,11 @@ ptMax :: Pt -> Pt -> Pt ptMax = ptOp max +-- | Convert from polar to rectangular co-ordinates. polarToRectangular :: Pt -> Pt polarToRectangular (Pt r t) = Pt (r * cos t) (r * sin t) +-- | Apply a transformation matrix to a point. ptTransform :: Matrix -> Pt -> Pt ptTransform (Matrix a b c d e f) (Pt x y) = let x' = x * a + y * c + e
Graphics/PS/Query.hs view
@@ -6,6 +6,7 @@ import Graphics.PS.Bezier import Graphics.PS.Path +-- | Locate the starting point of the path. startPt :: Path -> Maybe Pt startPt (MoveTo p) = Just p startPt (Join p _) = startPt p@@ -18,11 +19,13 @@ startPt' (Join p _) = startPt' p startPt' _ = Nothing +-- | Ensure path begins with a MoveTo. mkValid :: Path -> Path mkValid p = f (startPt' p) where f (Just q) = MoveTo q +++ p f Nothing = p +-- | Locate the end point of the path. endPt :: Path -> Maybe Pt endPt (MoveTo p) = Just p endPt (LineTo p) = Just p@@ -30,6 +33,7 @@ endPt (Join _ p) = endPt p endPt _ = Nothing +-- | Add a LineTo the start point of path. close :: Path -> Path close p = f (startPt p) where f (Just q) = p +++ LineTo q
Graphics/PS/Statistics.hs view
@@ -1,20 +1,30 @@-module Graphics.PS.Statistics ( pathStatistics ) where+module Graphics.PS.Statistics ( Statistics(..)+ , pathStatistics ) where import Graphics.PS.Path -type Statistics = (Integer, Integer, Integer, Integer, Integer)+-- | Path statistics data type.+data Statistics = Statistics {+ nMoveTo :: Integer+ , nLineTo :: Integer+ , nCurveTo :: Integer+ , nGlyph :: Integer+ , nTransform :: Integer } plus :: Statistics -> Statistics -> Statistics-plus (m1, l1, c1, g1, t1) (m2, l2, c2, g2, t2) = - (m1 + m2, l1 + l2, c1 + c2, g1 + g2, t1 + t2)+plus p q =+ let (Statistics m1 l1 c1 g1 t1) = p+ (Statistics m2 l2 c2 g2 t2) = q+ in Statistics (m1 + m2) (l1 + l2) (c1 + c2) (g1 + g2) (t1 + t2) st :: Path -> Statistics-st (MoveTo _) = (1, 0, 0, 0, 0)-st (LineTo _) = (0, 1, 0, 0, 0)-st (CurveTo _ _ _) = (0, 0, 1, 0, 0)-st (Text _ s) = (0, 0, 0, fromIntegral (length s), 0)-st (PTransform _ p) = (0, 0, 0, 0, 1) `plus` st p+st (MoveTo _) = Statistics 1 0 0 0 0+st (LineTo _) = Statistics 0 1 0 0 0+st (CurveTo _ _ _) = Statistics 0 0 1 0 0+st (Text _ s) = Statistics 0 0 0 (fromIntegral (length s)) 0+st (PTransform _ p) = Statistics 0 0 0 0 1 `plus` st p st (Join p1 p2) = st p1 `plus` st p2 +-- | Determine number of path components of each type. pathStatistics :: Path -> Statistics pathStatistics = st
README view
@@ -2,5 +2,5 @@ partial and trivial postcript rendering -(c) rohan drape 2006-2009+(c) rohan drape 2006-2010 gpl.2, http://gnu.org/copyleft/
hps.cabal view
@@ -1,16 +1,16 @@ Name: hps-Version: 0.1+Version: 0.2 Synopsis: Haskell Postscript Description: Haskell library partially implementing the postscript drawing model. License: GPL Category: Graphics-Copyright: Rohan Drape, 2006-2009+Copyright: Rohan Drape, 2006-2010 Author: Rohan Drape Maintainer: rd@slavepianos.org Stability: Experimental-Homepage: http://www.slavepianos.org/rd/f/972048/-Tested-With: GHC == 6.8.2+Homepage: http://slavepianos.org/rd/?t=hps+Tested-With: GHC == 6.10.3 Build-Type: Simple Cabal-Version: >= 1.6 @@ -21,7 +21,7 @@ Help/Screen.hs Library- Build-Depends: base == 3.*+ Build-Depends: base == 4.* GHC-Options: -Wall -fwarn-tabs Exposed-modules: Graphics.PS Graphics.PS.Pt@@ -38,3 +38,7 @@ Graphics.PS.Paper Graphics.PS.PS Graphics.PS.Unit++Source-Repository head+ Type: darcs+ Location: http://slavepianos.org/rd/sw/hps