diagrams-postscript-1.4: Postscript backend for diagrams drawing EDSL

Copyright(c) 2013 Diagrams team (see LICENSE)
LicenseBSD-style (see LICENSE)
Safe HaskellNone




Convenient creation of command-line-driven executables for rendering diagrams using the Postscript backend.

  • defaultMain creates an executable which can render a single diagram at various options.
  • multiMain is like defaultMain but allows for a list of diagrams from which the user can choose one to render.
  • pagesMain is like defaultMain but renders a list of diagrams as pages in a single file.
  • animMain renders an animation at a given frame rate into separate files with an index number.
  • mainWith is a generic form that does all of the above but with a slightly scarier type. See Diagrams.Backend.CmdLine. This form can also take a function type that has a subtable final result (any of arguments to the above types) and Parseable arguments.

If you want to generate diagrams programmatically---i.e. if you want to do anything more complex than what the below functions provide---you have several options.

  • Use a function with mainWith. This may require making Parseable instances for custom argument types.
  • Make a new Mainable instance. This may require a newtype wrapper on your diagram type to avoid the existing instances. This gives you more control over argument parsing, intervening steps, and diagram creation.
  • Build option records and pass them along with a diagram to mainRender from Diagrams.Backend.CmdLine.
  • An even more flexible approach is to directly call renderDia; see Diagrams.Backend.Postscript for more information.

For a tutorial on command-line diagram creation see http://projects.haskell.org/diagrams/doc/cmdline.html.


General form of main

The mainWith method unifies all of the other forms of main and is now the recommended way to build a command-line diagrams program. It works as a direct replacement for defaultMain, multiMain, pagesMain, or animMain as well as allowing more general arguments. For example, given a function that produces a diagram when given an Int and a Colour Double, mainWith will produce a program that looks for additional number and color arguments.

... definitions ...
f :: Int -> Colour Double -> QDiagram Postscript V2 Double Any
f i c = ...

main = mainWith f

We can run this program as follows:

$ ghc --make MyDiagram

# output image.eps built by `f 20 red`
$ ./MyDiagram -o image.eps -w 200 20 red

mainWith :: (Mainable d, Parseable (MainOpts d)) => d -> IO () #

Main entry point for command-line diagram creation. This is the method that users will call from their program main. For instance an expected user program would take the following form.

import Diagrams.Prelude
import Diagrams.Backend.TheBestBackend.CmdLine

d :: Diagram B R2
d = ...

main = mainWith d

Most backends should be able to use the default implementation. A different implementation should be used to handle more complex interactions with the user.

Supported forms of main

animMain :: Animation Postscript V2 Double -> IO () #

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.

Backend tokens

data Postscript #

This data declaration is simply used as a token to distinguish this rendering engine.


Eq Postscript # 
Ord Postscript # 
Read Postscript # 
Show Postscript # 
Backend Postscript V2 Double # 
Renderable (Text Double) Postscript # 
Renderable (Path V2 Double) Postscript # 
Renderable (Trail V2 Double) Postscript # 
Show (Options Postscript V2 Double) # 
Monoid (Render Postscript V2 Double) # 
Hashable (Options Postscript V2 Double) # 
Renderable (Segment Closed V2 Double) Postscript # 
type V Postscript # 
type V Postscript = V2
type N Postscript # 
data Options Postscript V2 Double # 
type Result Postscript V2 Double # 
data Render Postscript V2 Double # 
data Render Postscript V2 Double = C (RenderM ())
type MainOpts [(String, QDiagram Postscript V2 Double Any)] # 
type MainOpts [QDiagram Postscript V2 Double Any] # 
type MainOpts (Animation Postscript V2 Double) # 
type MainOpts (QDiagram Postscript V2 Double Any) # 

type B = Postscript #

Orphan instances

Mainable [(String, QDiagram Postscript V2 Double Any)] # 
Mainable [QDiagram Postscript V2 Double Any] # 
Mainable (Animation Postscript V2 Double) # 
Mainable (QDiagram Postscript V2 Double Any) #