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

PortabilityGHC only
Stabilityexperimental
Maintainerstephen.tetley@gmail.com

Wumpus.Core.SVG

Contents

Description

SVG is represented using XML.Light. XML.Light is a simple, generic XML representation (almost) everything is an element with attributes.

SVG output is monadic to handle clipping paths and configurable text encoding via a Reader monad.

SVG does not achieve clipping by changing the graphics state (being declarative SVG doesn't have a graphics state as such). Instead a clipping path has an id, subsequent elements that are bound by the clipping path are tagged with a clip-path attribute that references the clipping path id:

 clip-path=\"url(#clip1)\"

The operations to build XML elements (e.g. element_path) don't take more parameters than necessary, and are expected to be augmented with attributes using add_attr and add_attrs from the XML.Light library.

Synopsis

SVG Monad

type SvgM a = SvgT Id aSource

The SVG monad - which wraps a state monad to generate fresh names.

runSVG :: TextEncoder -> SvgM a -> aSource

Run the SVG monad.

newClipLabel :: SvgM StringSource

Generate a new clip label.

currentClipLabel :: SvgM StringSource

Get the current clip label.

Build SVG

unqualAttr :: String -> String -> AttrSource

Helper for XML.Light

xmlVersion :: String -> CDataSource

 <?xml version="1.0" encoding="..."?>

svgDocType :: CDataSource

 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"           
     "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" > 

gElement :: [Attr] -> [Element] -> ElementSource

 <g> ... </g>

Wumpus uses the g element (group) to achieve nesting.

svgElement :: [Element] -> ElementSource

 <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
 ...
 </svg>

attr_x :: PSUnit u => u -> AttrSource

 x="..."

attr_y :: PSUnit u => u -> AttrSource

 y="..."

attr_r :: PSUnit u => u -> AttrSource

 r="..."

attr_rx :: PSUnit u => u -> AttrSource

 rx="..."

attr_ry :: PSUnit u => u -> AttrSource

 ry="..."

attr_cx :: PSUnit u => u -> AttrSource

 cx="..."

attr_cy :: PSUnit u => u -> AttrSource

 cy="..."

element_path :: SvgPath -> ElementSource

 <path d="..." />

Note the argument to this function is an attribute rather than content. We have no use for empty paths.

element_clippath :: SvgPath -> ElementSource

 <clipPath>
 ...
 </clipPath>

element_text :: Node t => t -> ElementSource

 <text>...</text>

element_tspan :: String -> ElementSource

 <text>...</text>

content_text :: String -> ContentSource

Render the string as CDataText - see XML.Light.

attr_font_family :: String -> AttrSource

 font-family="..."

attr_font_size :: Int -> AttrSource

 font-size="..."

attr_font_weight :: String -> AttrSource

 font-weight="..."

attr_font_style :: String -> AttrSource

 font-style="..."

attr_id :: String -> AttrSource

 id="..."

attr_fill :: PSColour c => c -> AttrSource

 fill="rgb(..., ..., ...)"

attr_fill_none :: AttrSource

 fill="none"

attr_stroke :: PSColour c => c -> AttrSource

 stroke="rgb(..., ..., ...)"

attr_stroke_none :: AttrSource

 stroke="none"

attr_stroke_width :: PSUnit u => u -> AttrSource

 stroke-width="..."

attr_stroke_miterlimit :: PSUnit u => u -> AttrSource

 stroke-miterlimit="..."

attr_stroke_linejoin :: LineJoin -> AttrSource

 stroke-linejoin="..."

attr_stroke_dasharray :: [Int] -> AttrSource

 stroke-dasharray="..."

attr_stroke_dasharray_none :: AttrSource

 stroke-dasharray="none"

attr_stroke_dashoffset :: Int -> AttrSource

 stroke-dashoffset="..."

attr_color :: PSColour c => c -> AttrSource

 color="rgb(..., ..., ...)"

Gray or HSB values will be converted to and rendered as RGB.

attr_clippath :: String -> AttrSource

 clip-path="url(#...)"

val_matrix :: PSUnit u => u -> u -> u -> u -> u -> u -> StringSource

 matrix(..., ..., ..., ..., ..., ...)

val_colour :: PSColour c => c -> StringSource

 rgb(..., ..., ...)

HSB and gray scale are translated to RGB values.

val_rgb :: RGB3 Double -> StringSource

 rgb(..., ..., ...)

val_url :: String -> StringSource

 url(#...)

val_translate :: PSUnit u => u -> u -> StringSource

 translate(..., ...)

path_m :: PSUnit u => u -> u -> StringSource

 M ... ...

c.f. PostScript's moveto.

path_l :: PSUnit u => u -> u -> StringSource

 L ... ...

c.f. PostScript's lineto.

path_s :: PSUnit u => u -> u -> u -> u -> u -> u -> StringSource

 S ... ... ... ... ... ...

c.f. PostScript's curveto.