wumpus-core-0.42.0: Pure Haskell PostScript and SVG generation.

MaintainerStephen Tetley <stephen.tetley@gmail.com>




This module re-exports types and functions from Wumpus.Core.PictureInternal but makes them opaque. Contructors are provided by Wumpus.Core.Picture.

Note - whilst the Picture types support the Eq class the implementations are not efficient, e.g. In the case of Primitive, one of the constructors has to unwind a functional Hughes list. The Eq instance is considered a legacy feature (or burden) as the types have expanded.


Picture types

data Picture u Source

Picture is a leaf attributed tree - where attributes are colour, line-width etc. It is parametric on the unit type of points (typically Double).

Wumpus's leaf attributed tree, is not directly matched to PostScript's picture representation, which might be considered a node attributed tree (if you consider graphics state changes less imperatively - setting attributes rather than global state change).

Considered as a node-attributed tree PostScript precolates graphics state updates downwards in the tree (vis-a-vis inherited attributes in an attibute grammar), where a graphics state change deeper in the tree overrides a higher one.

Wumpus on the other hand, simply labels each leaf with its drawing attributes - there is no attribute inheritance. When it draws the PostScript picture it does some optimization to avoid generating excessive graphics state changes in the PostScript code.

Omitting some details, Picture is a simple non-empty leaf-labelled rose tree via:

 tree = Leaf [primitive] | Picture [tree]

The additional constructors are convenience:

Clip nests a picture (tree) inside a clipping path.

The Group constructor allows local shared graphics state updates for the SVG renderer - in some instances this can improve the code size of the generated SVG.


Show u => Show (Picture u) 
(Num u, PSUnit u) => Format (Picture u) 
(Num u, Ord u) => Translate (Picture u) 
(Num u, Ord u) => Scale (Picture u) 
(Real u, Floating u) => RotateAbout (Picture u) 
(Real u, Floating u) => Rotate (Picture u) 
(Num u, Ord u) => Transform (Picture u) 
Boundary (Picture u) 

data FontCtx Source

Set the font delta for SVG rendering.

Note - this does not change the default colour or font style. It is solely a backdoor into the SVG renderer to potential allow some code size reductions.


data Primitive u Source

Wumpus's drawings are built from two fundamental primitives: paths (straight line segments and Bezier curves) and labels (single lines of text).

Ellipses are a included as a primitive only for optimization - drawing a reasonable circle with Bezier curves needs at least eight curves. This is inconvenient for drawing dots which can otherwise be drawn with a single arc command.

Wumpus does not follow PostScript employing arc as a general path primitive - arcs are used only to draw ellipses. This is because arcs do not enjoy the nice properties of Bezier curves, whereby the affine transformation of a Bezier curve can simply be achieved by the affine transformation of it's control points.

Ellipses are represented by their center, half-width and half-height. Half-width and half-height are used so the bounding box can be calculated using only multiplication, and thus initially only obliging a Num constraint on the unit. Though typically for affine transformations a Fractional constraint is also obliged.

To represent XLink hyperlinks, Primitives can be annotated with some a hyperlink (likewise a passive font change for better SVG code generation) and grouped - a hyperlinked arrow would want the tip and the arrow body both to be incorporated in thelink even though they are two drawing primitives.

This means that Primitives aren't strictly primitive as the actual implementation is a tree.


Eq u => Eq (Primitive u) 
Show u => Show (Primitive u) 
PSUnit u => Format (Primitive u) 
Num u => Translate (Primitive u) 
Num u => Scale (Primitive u) 
(Real u, Floating u) => RotateAbout (Primitive u) 
(Real u, Floating u) => Rotate (Primitive u) 
(Real u, Floating u, FromPtSize u) => Boundary (Primitive u) 

data XLink Source

Primitives can be grouped with hyperlinks in SVG output.

Note - this is always printed as xlink:href=.... Other types of xlink can be modelled with the unrestrained SvgAnno type.

data PrimPath u Source

PrimPath - start point and a list of path segments.


Eq u => Eq (PrimPath u) 
Show u => Show (PrimPath u) 
PSUnit u => Format (PrimPath u) 

data PrimPathSegment u Source

PrimPathSegment - either a relative cubic Bezier curve-to or a relative line-to.


Eq u => Eq (PrimPathSegment u) 
Show u => Show (PrimPathSegment u) 
PSUnit u => Format (PrimPathSegment u) 

data PrimLabel u Source

Label - represented by baseline-left point and text.

Baseline-left is the dx * dy of the PrimCTM.


Eq u => Eq (PrimLabel u) 
Show u => Show (PrimLabel u) 
PSUnit u => Format (PrimLabel u) 

type KerningChar u = (u, EscapedChar)Source

A Char (possibly escaped) paired with is displacement from the previous KerningChar.

Printable unit for PostScript

class Num a => PSUnit a whereSource