diagrams-rasterific-1.4: Rasterific backend for diagrams.

Copyright(c) 2014-2015 diagrams-rasterific team (see LICENSE)
LicenseBSD-style (see LICENSE)
Maintainerdiagrams-discuss@googlegroups.com
Safe HaskellNone
LanguageHaskell2010

Diagrams.Backend.Rasterific

Contents

Description

A full-featured rendering backend for diagrams using Rasterific, implemented natively in Haskell (making it easy to use on any platform). Can create png, tif, bmp, jpg, pdf, and animated GIFs.

To invoke the Rasterific backend, you have three options.

  • You can use the Diagrams.Backend.Rasterific.CmdLine module to create standalone executables which output images when invoked.
  • You can use the renderRasterific function provided by this module, which gives you more flexible programmatic control over when and how images are output (making it easy to, for example, write a single program that outputs multiple images, or one that outputs images dynamically based on user input, and so on).
  • For the most flexibility (e.g. if you want access to the resulting Rasterific value directly in memory without writing it to disk), you can manually invoke the renderDia method from the Backend instance for Rasterific. In particular, renderDia has the generic type
renderDia :: b -> Options b v n -> QDiagram b v n m -> Result b v n

(omitting a few type class constraints). b represents the backend type, v the vector space, n the numeric field, and m the type of monoidal query annotations on the diagram. Options and Result are associated data and type families, respectively, which yield the type of option records and rendering results specific to any particular backend. For b ~ Rasterific, v ~ V2, and n ~ n, we have

data Options Rasterific V2 n = RasterificOptions
       { _size      :: SizeSpec2D n -- ^ The requested size of the output
       }
type family Result Rasterific V2 n = 'Image PixelRGBA8'

So the type of renderDia resolves to

renderDia :: Rasterific -> Options Rasterific V2 n -> QDiagram Rasterific V2 n m -> 'Image PixelRGBA8'

which you could call like renderDia Rasterific (RasterificOptions (mkWidth 250)) myDiagram.

Synopsis

Rasterific backend

data Rasterific Source #

This data declaration is simply used as a token to distinguish the Rasterific backend: (1) when calling functions where the type inference engine would otherwise have no way to know which backend you wanted to use, and (2) as an argument to the Backend and Renderable type classes.

Constructors

Rasterific 

Instances

Eq Rasterific Source # 
Ord Rasterific Source # 
Read Rasterific Source # 
Show Rasterific Source # 
TypeableFloat n => Backend Rasterific V2 n Source # 
TypeableFloat n => Renderable (Text n) Rasterific Source # 

Methods

render :: Rasterific -> Text n -> Render Rasterific (V (Text n)) (N (Text n)) #

TypeableFloat n => Renderable (DImage n Embedded) Rasterific Source # 
TypeableFloat n => Renderable (Path V2 n) Rasterific Source # 

Methods

render :: Rasterific -> Path V2 n -> Render Rasterific (V (Path V2 n)) (N (Path V2 n)) #

Show n => Show (Options Rasterific V2 n) Source # 
Monoid (Render Rasterific V2 n) Source # 
Hashable n => Hashable (Options Rasterific V2 n) Source # 
type V Rasterific Source # 
type V Rasterific = V2
type N Rasterific Source # 
data Options Rasterific V2 Source # 
data Render Rasterific V2 Source # 
data Render Rasterific V2 = R (RenderM n ())
type Result Rasterific V2 n Source # 
type ResultOf [(QDiagram Rasterific V2 n Any, GifDelay)] # 
type Args [(QDiagram Rasterific V2 n Any, GifDelay)] # 
type MainOpts [(String, QDiagram Rasterific V2 n Any)] # 
type MainOpts [(QDiagram Rasterific V2 n Any, GifDelay)] # 
type MainOpts (Animation Rasterific V2 n) # 
type MainOpts (QDiagram Rasterific V2 n Any) # 

data family Options b (v :: * -> *) n :: * #

Backend-specific rendering options.

Rendering

renderRasterific :: TypeableFloat n => FilePath -> SizeSpec V2 n -> QDiagram Rasterific V2 n Any -> IO () Source #

Render a Rasterific diagram to a file with the given size. The format is determined by the extension (.png, .tif, .bmp, .jpg and .pdf supported. (jpeg quality is 80, use writeJpeg to choose quality).

renderPdf :: TypeableFloat n => Int -> Int -> FilePath -> SizeSpec V2 n -> QDiagram Rasterific V2 n Any -> IO () Source #

Render a Rasterific diagram to a pdf file with given width and height

size :: ((~) (* -> *) (V a) v, (~) * (N a) n, Enveloped a, HasBasis v) => a -> v n #

The smallest positive vector that bounds the envelope of an object.

writeJpeg :: Word8 -> FilePath -> Result Rasterific V2 n -> IO () Source #

Render a Rasterific diagram to a jpeg file with given quality (between 0 and 100).

type GifDelay = Int #

Delay to wait before showing the next Gif image. The delay is expressed in 100th of seconds.

data GifLooping :: * #

Help to control the behaviour of GIF animation looping.

Constructors

LoopingNever

The animation will stop once the end is reached

LoopingForever

The animation will restart once the end is reached

LoopingRepeat Word16

The animation will repeat n times before stoping

animatedGif Source #

Arguments

:: TypeableFloat n 
=> FilePath 
-> SizeSpec V2 n 
-> GifLooping 
-> GifDelay

Delay in 100th of seconds (Int)

-> [QDiagram Rasterific V2 n Any] 
-> IO () 

Render a Rasterific diagram to an animated gif with the given size and uniform delay. Diagrams should be the same size.

Text with envelopes

texterific :: (TypeableFloat n, Renderable (Text n) b) => String -> QDiagram b V2 n Any Source #

Create a primitive text diagram from the given string, with baseline alignment, envelope and trace based on the BoundingBox of the text. Designed to be a replacement for the function text in Diagrams.TwoD.Text.

texterific' :: (TypeableFloat n, Renderable (Text n) b) => FontSlant -> FontWeight -> String -> QDiagram b V2 n Any Source #

Create a primitive text diagram from the given FontSlant, FontWeight, and string, with baseline alignment, envelope and trace based on the BoundingBox of the text.

Internals

These are low level functions whose implimentaion may change in the future. They're exported because they can sometimes be useful.

data PaletteOptions :: * #

To specify how the palette will be created.

Constructors

PaletteOptions 

Fields

defaultPaletteOptions :: PaletteOptions #

Default palette option, which aim at the best quality and maximum possible colors (256)

rasterGif Source #

Arguments

:: TypeableFloat n 
=> SizeSpec V2 n

Size of output (in pixels)

-> GifLooping

looping options

-> PaletteOptions

palette options

-> [(QDiagram Rasterific V2 n Any, Int)]

Diagram zipped with its delay (100th of seconds)

-> Either String ByteString 

Turn a list of diagrams into a gif.

rasterRgb8 :: TypeableFloat n => SizeSpec V2 n -> QDiagram Rasterific V2 n Any -> Image PixelRGB8 Source #

Render a Rasterific diagram without an alpha channel.