File: README.markdown

package info (click to toggle)
haskell-diagrams-cairo 1.4.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 136 kB
  • sloc: haskell: 643; makefile: 2
file content (81 lines) | stat: -rw-r--r-- 2,405 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
[![Build Status](https://travis-ci.org/diagrams/diagrams-cairo.png?branch=master)](http://travis-ci.org/diagrams/diagrams-cairo)

_diagrams-cairo_ is a rendering backend for [diagrams], a powerful,
flexible, declarative domain-specific language for creating vector graphics,
using the [Haskell programming language][haskell].

[diagrams]: http://projects.haskell.org/diagrams/
[haskell]: http://www.haskell.org/haskellwiki/Haskell

_diagrams-cairo_ is implemented using the [cairo] rendering engine and
is a fully-featured, officially supported backend for diagrams.

[cairo]: http://www.cairographics.org/

# Installation

```
cabal update && cabal install gtk2hs-buildtools diagrams-cairo
```

# Basic usage

A simple example that uses _diagrams-cairo_ to draw a blue circle:

```haskell
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE FlexibleContexts          #-}
{-# LANGUAGE TypeFamilies              #-}

import Diagrams.Prelude
import Diagrams.Backend.Cairo.CmdLine

d :: Diagram B
d = circle 1 # fc blue

main = mainWith (pad 1.1 d)
```

Save this to file named `Circle.hs` and compile it:

```
ghc --make Circle.hs
```

This will generate an executable which, when run, outputs a blue
circle to some file. Run the executable with the `--help` option to
find out more about how to call it.

```
$ ./Circle --help
./Circle

Usage: ./Circle [-w|--width WIDTH] [-h|--height HEIGHT] [-o|--output OUTPUT]
                [--loop] [-s|--src ARG] [-i|--interval INTERVAL]
  Command-line diagram generation.

Available options:
  -?,--help                Show this help text
  -w,--width WIDTH         Desired WIDTH of the output image
  -h,--height HEIGHT       Desired HEIGHT of the output image
  -o,--output OUTPUT       OUTPUT file
  -l,--loop                Run in a self-recompiling loop
  -s,--src ARG             Source file to watch
  -i,--interval INTERVAL   When running in a loop, check for changes every INTERVAL seconds.
ommand-line diagram generation.
```

The output type will be automatically determined from the file
extension.  Currently PNG, PDF, PS, and SVG are supported.

```
$ ./Circle -o circle.png -w 400
```

The command above generates a PNG file with a width of 400px.

# Advanced usage

Instead of just creating a standalone executable, the cairo backend
can also be called from within a larger program.  For more
information, see the Diagram.Backend.Cairo module.