| 1 |
[](http://travis-ci.org/diagrams/diagrams-cairo) |
| 2 |
|
| 3 |
_diagrams-cairo_ is a rendering backend for [diagrams], a powerful, |
| 4 |
flexible, declarative domain-specific language for creating vector graphics, |
| 5 |
using the [Haskell programming language][haskell]. |
| 6 |
|
| 7 |
[diagrams]: http://projects.haskell.org/diagrams/ |
| 8 |
[haskell]: http://www.haskell.org/haskellwiki/Haskell |
| 9 |
|
| 10 |
_diagrams-cairo_ is implemented using the [cairo] rendering engine and |
| 11 |
is a fully-featured, officially supported backend for diagrams. |
| 12 |
|
| 13 |
[cairo]: http://www.cairographics.org/ |
| 14 |
|
| 15 |
# Installation |
| 16 |
|
| 17 |
``` |
| 18 |
cabal update && cabal install gtk2hs-buildtools diagrams-cairo |
| 19 |
``` |
| 20 |
|
| 21 |
# Basic usage |
| 22 |
|
| 23 |
A simple example that uses _diagrams-cairo_ to draw a blue circle: |
| 24 |
|
| 25 |
```haskell |
| 26 |
{-# LANGUAGE NoMonomorphismRestriction #-} |
| 27 |
{-# LANGUAGE FlexibleContexts #-} |
| 28 |
{-# LANGUAGE TypeFamilies #-} |
| 29 |
|
| 30 |
import Diagrams.Prelude |
| 31 |
import Diagrams.Backend.Cairo.CmdLine |
| 32 |
|
| 33 |
d :: Diagram B |
| 34 |
d = circle 1 # fc blue |
| 35 |
|
| 36 |
main = mainWith (pad 1.1 d) |
| 37 |
``` |
| 38 |
|
| 39 |
Save this to file named `Circle.hs` and compile it: |
| 40 |
|
| 41 |
``` |
| 42 |
ghc --make Circle.hs |
| 43 |
``` |
| 44 |
|
| 45 |
This will generate an executable which, when run, outputs a blue |
| 46 |
circle to some file. Run the executable with the `--help` option to |
| 47 |
find out more about how to call it. |
| 48 |
|
| 49 |
``` |
| 50 |
$ ./Circle --help |
| 51 |
./Circle |
| 52 |
|
| 53 |
Usage: ./Circle [-w|--width WIDTH] [-h|--height HEIGHT] [-o|--output OUTPUT] |
| 54 |
[--loop] [-s|--src ARG] [-i|--interval INTERVAL] |
| 55 |
Command-line diagram generation. |
| 56 |
|
| 57 |
Available options: |
| 58 |
-?,--help Show this help text |
| 59 |
-w,--width WIDTH Desired WIDTH of the output image |
| 60 |
-h,--height HEIGHT Desired HEIGHT of the output image |
| 61 |
-o,--output OUTPUT OUTPUT file |
| 62 |
-l,--loop Run in a self-recompiling loop |
| 63 |
-s,--src ARG Source file to watch |
| 64 |
-i,--interval INTERVAL When running in a loop, check for changes every INTERVAL seconds. |
| 65 |
ommand-line diagram generation. |
| 66 |
``` |
| 67 |
|
| 68 |
The output type will be automatically determined from the file |
| 69 |
extension. Currently PNG, PDF, PS, and SVG are supported. |
| 70 |
|
| 71 |
``` |
| 72 |
$ ./Circle -o circle.png -w 400 |
| 73 |
``` |
| 74 |
|
| 75 |
The command above generates a PNG file with a width of 400px. |
| 76 |
|
| 77 |
# Advanced usage |
| 78 |
|
| 79 |
Instead of just creating a standalone executable, the cairo backend |
| 80 |
can also be called from within a larger program. For more |
| 81 |
information, see the Diagram.Backend.Cairo module. |