Portability | GHC only |
---|---|
Stability | experimental |
Maintainer | stephen.tetley@gmail.com |
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.
- type SvgM a = SvgT Id a
- runSVG :: TextEncoder -> SvgM a -> a
- newClipLabel :: SvgM String
- currentClipLabel :: SvgM String
- type SvgPath = [String]
- unqualAttr :: String -> String -> Attr
- xmlVersion :: String -> CData
- svgDocType :: CData
- gElement :: [Attr] -> [Element] -> Element
- svgElement :: [Element] -> Element
- element_circle :: Element
- element_ellipse :: Element
- attr_x :: PSUnit u => u -> Attr
- attr_y :: PSUnit u => u -> Attr
- attr_r :: PSUnit u => u -> Attr
- attr_rx :: PSUnit u => u -> Attr
- attr_ry :: PSUnit u => u -> Attr
- attr_cx :: PSUnit u => u -> Attr
- attr_cy :: PSUnit u => u -> Attr
- element_path :: SvgPath -> Element
- element_clippath :: SvgPath -> Element
- element_text :: Node t => t -> Element
- element_tspan :: String -> Element
- content_text :: String -> Content
- attr_font_family :: String -> Attr
- attr_font_size :: Int -> Attr
- attr_font_weight :: String -> Attr
- attr_font_style :: String -> Attr
- attr_id :: String -> Attr
- attr_fill :: PSColour c => c -> Attr
- attr_fill_none :: Attr
- attr_stroke :: PSColour c => c -> Attr
- attr_stroke_none :: Attr
- attr_stroke_width :: PSUnit u => u -> Attr
- attr_stroke_miterlimit :: PSUnit u => u -> Attr
- attr_stroke_linecap :: LineCap -> Attr
- attr_stroke_linejoin :: LineJoin -> Attr
- attr_stroke_dasharray :: [Int] -> Attr
- attr_stroke_dasharray_none :: Attr
- attr_stroke_dashoffset :: Int -> Attr
- attr_color :: PSColour c => c -> Attr
- attr_clippath :: String -> Attr
- attr_transform :: String -> Attr
- val_matrix :: PSUnit u => u -> u -> u -> u -> u -> u -> String
- val_colour :: PSColour c => c -> String
- val_rgb :: RGB3 Double -> String
- val_url :: String -> String
- val_translate :: PSUnit u => u -> u -> String
- path_m :: PSUnit u => u -> u -> String
- path_l :: PSUnit u => u -> u -> String
- path_s :: PSUnit u => u -> u -> u -> u -> u -> u -> String
SVG Monad
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="..."?>
<!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>
element_circle :: ElementSource
<circle/>
element_ellipse :: ElementSource
<ellipse/>
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="..."
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(#...)"
attr_transform :: String -> AttrSource
transform=...
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_translate :: PSUnit u => u -> u -> StringSource
translate(..., ...)