packages feed

diagrams-postscript 0.6.0.1 → 0.7

raw patch · 3 files changed

+95/−43 lines, 3 filesdep +filepathdep ~basedep ~diagrams-coredep ~diagrams-libnew-uploaderPVP ok

version bump matches the API change (PVP)

Dependencies added: filepath

Dependency ranges changed: base, diagrams-core, diagrams-lib, monoid-extras

API changes (from Hackage documentation)

- Diagrams.Backend.Postscript: instance Renderable (Segment R2) Postscript
+ Diagrams.Backend.Postscript: instance Bounded OutputFormat
+ Diagrams.Backend.Postscript: instance Enum OutputFormat
+ Diagrams.Backend.Postscript: instance Eq OutputFormat
+ Diagrams.Backend.Postscript: instance Ord OutputFormat
+ Diagrams.Backend.Postscript: instance Read OutputFormat
+ Diagrams.Backend.Postscript: instance Renderable (Segment Closed R2) Postscript
+ Diagrams.Backend.Postscript: instance Show (Options Postscript R2)
+ Diagrams.Backend.Postscript: instance Show OutputFormat
+ Diagrams.Backend.Postscript: instance Typeable OutputFormat
+ Diagrams.Backend.Postscript.CmdLine: animMain :: Animation Postscript R2 -> IO ()

Files

diagrams-postscript.cabal view
@@ -1,5 +1,5 @@ Name:                diagrams-postscript-Version:             0.6.0.1+Version:             0.7 Synopsis:            Postscript backend for diagrams drawing EDSL Description:         This package provides a modular backend for rendering                      diagrams created with the diagrams EDSL using Postscript.@@ -20,6 +20,7 @@ Category:            Graphics Build-type:          Simple Cabal-version:       >=1.10+Tested-with:         GHC == 7.4.2, GHC == 7.6.1 Source-repository head   type:     git   location: https://github.com/diagrams/diagrams-postscript.git@@ -29,15 +30,16 @@                        Diagrams.Backend.Postscript.CmdLine                        Graphics.Rendering.Postscript   Hs-source-dirs:      src-  Build-depends:       base >= 4.2 && < 4.7,+  Build-depends:       base >= 4.2 && < 4.8,                        mtl >= 2.0 && < 2.2,+                       filepath,                        dlist >= 0.5 && < 0.6,                        vector-space >= 0.7.7 && < 0.9,-                       diagrams-core >= 0.6 && < 0.7,-                       diagrams-lib >= 0.6 && < 0.7,+                       diagrams-core >= 0.7 && < 0.8,+                       diagrams-lib >= 0.7 && < 0.8,                        cmdargs >= 0.6 && < 0.11,                        split >= 0.1.2 && < 0.3,-                       monoid-extras >= 0.2.2 && < 0.3,+                       monoid-extras >= 0.3 && < 0.4,                        semigroups >= 0.3.4 && < 0.10   default-language:    Haskell2010 
src/Diagrams/Backend/Postscript.hs view
@@ -1,12 +1,12 @@-{-# LANGUAGE TypeFamilies-           , MultiParamTypeClasses-           , FlexibleInstances-           , FlexibleContexts-           , TypeSynonymInstances-           , DeriveDataTypeable-           , ViewPatterns-           , NoMonomorphismRestriction-  #-}+{-# LANGUAGE DeriveDataTypeable        #-}+{-# LANGUAGE FlexibleContexts          #-}+{-# LANGUAGE FlexibleInstances         #-}+{-# LANGUAGE GADTs                     #-}+{-# LANGUAGE MultiParamTypeClasses     #-}+{-# LANGUAGE NoMonomorphismRestriction #-}+{-# LANGUAGE TypeFamilies              #-}+{-# LANGUAGE TypeSynonymInstances      #-}+{-# LANGUAGE ViewPatterns              #-}  ----------------------------------------------------------------------------- -- |@@ -47,29 +47,29 @@  import qualified Graphics.Rendering.Postscript as C -import Diagrams.Prelude+import           Diagrams.Prelude -import Diagrams.Core.Transform+import           Diagrams.Core.Transform -import Diagrams.TwoD.Ellipse-import Diagrams.TwoD.Shapes-import Diagrams.TwoD.Adjust (adjustDia2D)-import Diagrams.TwoD.Size (requiredScaleT)-import Diagrams.TwoD.Text-import Diagrams.TwoD.Path (Clip(..), getFillRule)+import           Diagrams.TwoD.Adjust          (adjustDia2D)+import           Diagrams.TwoD.Ellipse+import           Diagrams.TwoD.Path            (Clip (..), getFillRule)+import           Diagrams.TwoD.Shapes+import           Diagrams.TwoD.Size            (requiredScaleT)+import           Diagrams.TwoD.Text -import Control.Applicative ((<$>))-import Control.Monad (when)-import Data.Maybe (catMaybes, fromMaybe)+import           Control.Applicative           ((<$>))+import           Control.Monad                 (when)+import           Data.Maybe                    (catMaybes, fromMaybe) -import Data.VectorSpace+import           Data.VectorSpace -import Data.Monoid hiding ((<>))-import Data.Monoid.MList-import Data.Monoid.Split-import qualified Data.List.NonEmpty as N-import qualified Data.Foldable as F-import Data.Typeable+import qualified Data.Foldable                 as F+import qualified Data.List.NonEmpty            as N+import           Data.Monoid                   hiding ((<>))+import           Data.Monoid.MList+import           Data.Monoid.Split+import           Data.Typeable  -- | This data declaration is simply used as a token to distinguish this rendering engine. data Postscript = Postscript@@ -78,6 +78,7 @@ -- | Postscript only supports EPS style output at the moment.  Future formats would each --   have their own associated properties that affect the output. data OutputFormat = EPS -- ^ Encapsulated Postscript output.+  deriving (Eq, Ord, Read, Show, Enum, Bounded, Typeable)  instance Monoid (Render Postscript R2) where   mempty  = C $ return ()@@ -92,6 +93,7 @@           , psSizeSpec     :: SizeSpec2D   -- ^ the requested size of the output           , psOutputFormat :: OutputFormat -- ^ the output format and associated options           }+    deriving Show    withStyle _ s t (C r) = C $ do     C.save@@ -115,7 +117,7 @@    adjustDia c opts d = adjustDia2D psSizeSpec setPsSize c opts d     where setPsSize sz o = o { psSizeSpec = sz }-    + sizeFromSpec size = case size of    Width w'   -> (w',w')    Height h'  -> (h',h')@@ -137,7 +139,7 @@         combineSizes (o:os) = o { psSizeSpec = uncurry Dims . fromMaxPair . sconcat $ f o N.:| fmap f os }          where f = mkMax . sizeFromSpec . psSizeSpec-      +        doRenderPages _ (PostscriptOptions file size out) rs =         let surfaceF surface = C.renderPagesWith surface (map (\(C r) -> r) rs)             (w,h) = sizeFromSpec size@@ -204,21 +206,25 @@         (b1,b2) = unr2 $ apply t unitY         (c1,c2) = unr2 $ transl t -instance Renderable (Segment R2) Postscript where-  render _ (Linear (unr2 -> v)) = C $ uncurry C.relLineTo v+instance Renderable (Segment Closed R2) Postscript where+  render _ (Linear (OffsetClosed (unr2 -> v))) = C $ uncurry C.relLineTo v   render _ (Cubic (unr2 -> (x1,y1))                   (unr2 -> (x2,y2))-                  (unr2 -> (x3,y3))) = C $ C.relCurveTo x1 y1 x2 y2 x3 y3+                  (OffsetClosed (unr2 -> (x3,y3))))+    = C $ C.relCurveTo x1 y1 x2 y2 x3 y3  instance Renderable (Trail R2) Postscript where-  render _ (Trail segs c) = C $ do-    mapM_ renderC segs-    when c C.closePath+  render _ t = flip withLine t $ renderT . lineSegments+    where+      renderT segs =+        C $ do+          mapM_ renderC segs+          when (isLoop t) C.closePath  instance Renderable (Path R2) Postscript where   render _ (Path trs) = C $ C.newPath >> F.mapM_ renderTrail trs-    where renderTrail (p, tr) = do-            uncurry C.moveTo (unp2 p)+    where renderTrail (viewLoc -> (unp2 -> p, tr)) = do+            uncurry C.moveTo p             renderC tr  instance Renderable Text Postscript where
src/Diagrams/Backend/Postscript/CmdLine.hs view
@@ -35,6 +35,7 @@        ( defaultMain        , multiMain        , pagesMain+       , animMain        , Postscript        ) where @@ -46,12 +47,16 @@ import Prelude  import Data.Maybe          (fromMaybe)+import Control.Monad       (forM_) import Control.Applicative ((<$>)) import Control.Monad       (when) import Data.List.Split import Data.List           (intercalate) +import Text.Printf+ import System.Environment  (getArgs, getProgName)+import System.FilePath     (addExtension, splitExtension)  data DiagramOpts = DiagramOpts                    { width     :: Maybe Int@@ -59,6 +64,7 @@                    , output    :: FilePath                    , selection :: Maybe String                    , list      :: Bool+                   , fpu       :: Double                    }   deriving (Show, Data, Typeable) @@ -82,6 +88,10 @@    , list = def          &= (if sel then help "List all available diagrams" else ignore)++  , fpu = 30+          &= typ "FLOAT"+          &= help "Frames per unit time (for animations)"   }   &= summary "Command-line diagram generation."   &= program prog@@ -111,6 +121,7 @@ --   -w --width=INT         Desired width of the output image --   -h --height=INT        Desired height of the output image --   -o --output=FILE       Output file+--   -f --fpu=FLOAT         Frames per unit time (for animations) --   -? --help              Display help message --   -V --version           Print version information -- @@@ -120,7 +131,7 @@ -- @ -- $ ghc --make MyDiagram -----   # output image.png with a width of 400pt (and auto-determined height)+--   # output image.eps with a width of 400pt (and auto-determined height) -- $ ./MyDiagram -o image.eps -w 400 -- @ @@ -212,3 +223,36 @@   opts <- cmdArgs (diagramOpts prog False)   chooseRender opts (renderDias' ds) +-- | @animMain@ is like 'defaultMain', but renders an animation+-- instead of a diagram.  It takes as input an animation and produces+-- a command-line program which will crudely \"render\" the animation+-- by rendering one image for each frame, named by extending the given+-- output file name by consecutive integers.  For example if the given+-- output file name is @foo\/blah.eps@, the frames will be saved in+-- @foo\/blah001.eps@, @foo\/blah002.eps@, and so on (the number of+-- padding digits used depends on the total number of frames).  It is+-- up to the user to take these images and stitch them together into+-- an actual animation format (using, /e.g./ @ffmpeg@).+--+--   Of course, this is a rather crude method of rendering animations;+--   more sophisticated methods will likely be added in the future.+--+-- The @--fpu@ option can be used to control how many frames will be+-- output for each second (unit time) of animation.+animMain :: Animation Postscript R2 -> IO ()+animMain anim = do+  prog <- getProgName+  opts <- cmdArgs (diagramOpts prog False)+  let frames  = simulate (toRational $ fpu opts) anim+      nDigits = length . show . length $ frames+  forM_ (zip [1..] frames) $ \(i,d) ->+    chooseRender (indexize nDigits i opts) (renderDia' d)++-- | @indexize d n@ adds the integer index @n@ to the end of the+--   output file name, padding with zeros if necessary so that it uses+--   at least @d@ digits.+indexize :: Int -> Integer -> DiagramOpts -> DiagramOpts+indexize nDigits i opts = opts { output = output' }+  where fmt         = "%0" ++ show nDigits ++ "d"+        output'     = addExtension (base ++ printf fmt (i::Integer)) ext+        (base, ext) = splitExtension (output opts)