svg-tree-0.6.1: SVG file loader and serializer

Safe HaskellNone
LanguageHaskell2010

Graphics.Svg.Types

Contents

Description

This module define all the types used in the definition of a svg scene.

Most of the types are lensified.

Synopsis

Basic building types

type Coord = Double #

Basic coordiante type.

data Origin #

Tell if a path command is absolute (in the current user coordiante) or relative to the previous poitn.

Constructors

OriginAbsolute

Next point in absolute coordinate

OriginRelative

Next point relative to the previous

Instances

Eq Origin # 

Methods

(==) :: Origin -> Origin -> Bool #

(/=) :: Origin -> Origin -> Bool #

Show Origin # 

type Point = (Number, Number) #

Possibly context dependant point.

type RPoint = V2 Coord #

Real Point, fully determined and not dependant of the rendering context.

data PathCommand #

Path command definition.

Constructors

MoveTo !Origin ![RPoint]

M or m command

LineTo !Origin ![RPoint]

Line to, L or l Svg path command.

HorizontalTo !Origin ![Coord]

Equivalent to the H or h svg path command.

VerticalTo !Origin ![Coord]

Equivalent to the V or v svg path command.

CurveTo !Origin ![(RPoint, RPoint, RPoint)]

Cubic bezier, C or c command

SmoothCurveTo !Origin ![(RPoint, RPoint)]

Smooth cubic bezier, equivalent to S or s command

QuadraticBezier !Origin ![(RPoint, RPoint)]

Quadratic bezier, Q or q command

SmoothQuadraticBezierCurveTo !Origin ![RPoint]

Quadratic bezier, T or t command

EllipticalArc !Origin ![(Coord, Coord, Coord, Bool, Bool, RPoint)]

Eliptical arc, A or a command.

EndPath

Close the path, Z or z svg path command.

data Transformation #

Describe the content of the transformation attribute. see _transform and transform.

Constructors

TransformMatrix !Coord !Coord !Coord !Coord !Coord !Coord

Directly encode the translation matrix.

Translate !Double !Double

Translation along a vector

Scale !Double !(Maybe Double)

Scaling on both axis or on X axis and Y axis.

Rotate !Double !(Maybe (Double, Double))

Rotation around `(0, 0)` or around an optional point.

SkewX !Double

Skew transformation along the X axis.

SkewY !Double

Skew transformation along the Y axis.

TransformUnknown

Unkown transformation, like identity.

data ElementRef #

Correspond to the possible values of the the attributes which are either none or `url(#elem)`

Constructors

RefNone

Value for none

Ref String

Equivalent to `url()` attribute.

data CoordinateUnits #

Define the possible values of various *units attributes used in the definition of the gradients and masks.

Constructors

CoordUserSpace

userSpaceOnUse value

CoordBoundingBox

objectBoundingBox value

Building helpers

toPoint :: Number -> Number -> Point #

Little helper function to build a point.

serializeNumber :: Number -> String #

Encode the number to string which can be used in a CSS or a svg attributes.

serializeTransformation :: Transformation -> String #

Convert the Transformation to a string which can be directly used in a svg attributes.

serializeTransformations :: [Transformation] -> String #

Transform a list of transformations to a string for svg transform attributes.

Drawing control types

data Cap #

Describe how the line should be terminated when stroking them. Describe the values of the `stroke-linecap` attribute. See _strokeLineCap

Constructors

CapRound

End with a round (round value)

CapButt

Define straight just at the end (butt value)

CapSquare

Straight further of the ends (square value)

Instances

Eq Cap # 

Methods

(==) :: Cap -> Cap -> Bool #

(/=) :: Cap -> Cap -> Bool #

Show Cap # 

Methods

showsPrec :: Int -> Cap -> ShowS #

show :: Cap -> String #

showList :: [Cap] -> ShowS #

data LineJoin #

Define the possible values of the `stroke-linejoin` attribute. see _strokeLineJoin

Constructors

JoinMiter

miter value

JoinBevel

bevel value

JoinRound

round value

data Number #

Encode complex number possibly dependant to the current render size.

Constructors

Num Double

Simple coordinate in current user coordinate.

Px Double

With suffix "px"

Em Double

Number relative to the current font size.

Percent Double

Number relative to the current viewport size.

Pc Double 
Mm Double

Number in millimeters, relative to DPI.

Cm Double

Number in centimeters, relative to DPI.

Point Double

Number in points, relative to DPI.

Inches Double

Number in inches, relative to DPI.

Instances

Eq Number # 

Methods

(==) :: Number -> Number -> Bool #

(/=) :: Number -> Number -> Bool #

Show Number # 

data Spread #

Define the possible values for the spreadMethod values used for the gradient definitions.

Constructors

SpreadRepeat

reapeat value

SpreadPad

pad value

SpreadReflect

`reflect value`

Instances

Eq Spread # 

Methods

(==) :: Spread -> Spread -> Bool #

(/=) :: Spread -> Spread -> Bool #

Show Spread # 

data Texture #

Describe the different value which can be used in the fill or stroke attributes.

Constructors

ColorRef PixelRGBA8

Direct solid color (rgb)

TextureRef String

Link to a complex texture (url(#name))

FillNone

Equivalent to the none value.

Instances

data FillRule #

Describe the possile filling algorithms. Map the values of the `fill-rule` attributes.

Constructors

FillEvenOdd

Correspond to the evenodd value.

FillNonZero

Correspond to the nonzero value.

data FontStyle #

Classify the font style, used to search a matching font in the FontCache.

type Dpi = Int #

Alias describing a "dot per inch" information used for size calculation (see toUserUnit).

class WithDefaultSvg a where #

Define an empty 'default' element for the SVG tree. It is used as base when parsing the element from XML.

Minimal complete definition

defaultSvg

Methods

defaultSvg :: a #

The default element.

Instances

WithDefaultSvg PreserveAspectRatio # 
WithDefaultSvg DrawAttributes # 
WithDefaultSvg PolyLine # 
WithDefaultSvg Polygon # 

Methods

defaultSvg :: Polygon #

WithDefaultSvg Line # 

Methods

defaultSvg :: Line #

WithDefaultSvg Rectangle # 
WithDefaultSvg Path # 

Methods

defaultSvg :: Path #

WithDefaultSvg Circle # 

Methods

defaultSvg :: Circle #

WithDefaultSvg Ellipse # 

Methods

defaultSvg :: Ellipse #

WithDefaultSvg GradientStop # 
WithDefaultSvg MeshGradientPatch # 
WithDefaultSvg MeshGradientRow # 
WithDefaultSvg MeshGradient # 
WithDefaultSvg Image # 

Methods

defaultSvg :: Image #

WithDefaultSvg Use # 

Methods

defaultSvg :: Use #

WithDefaultSvg TextInfo # 
WithDefaultSvg TextSpan # 
WithDefaultSvg TextPath # 
WithDefaultSvg Text # 

Methods

defaultSvg :: Text #

WithDefaultSvg Marker # 

Methods

defaultSvg :: Marker #

WithDefaultSvg Tree # 

Methods

defaultSvg :: Tree #

WithDefaultSvg LinearGradient # 
WithDefaultSvg RadialGradient # 
WithDefaultSvg Mask # 

Methods

defaultSvg :: Mask #

WithDefaultSvg ClipPath # 
WithDefaultSvg Pattern # 

Methods

defaultSvg :: Pattern #

WithDefaultSvg (Group a) # 

Methods

defaultSvg :: Group a #

WithDefaultSvg (Symbol a) # 

Methods

defaultSvg :: Symbol a #

Main type

documentSize :: Dpi -> Document -> (Int, Int) #

Calculate the document size in function of the different available attributes in the document.

Drawing attributes

data DrawAttributes #

This type define how to draw any primitives, which color to use, how to stroke the primitives and the potential transformations to use.

All these attributes are propagated to the children.

Constructors

DrawAttributes 

Fields

Instances

Eq DrawAttributes # 
Show DrawAttributes # 
Monoid DrawAttributes # 
WithDefaultSvg DrawAttributes # 
HasDrawAttributes DrawAttributes # 

class HasDrawAttributes c where #

Lenses for the DrawAttributes type.

Minimal complete definition

drawAttributes

class WithDrawAttributes a where #

Class helping find the drawing attributes for all the SVG attributes.

Minimal complete definition

drawAttr

Methods

drawAttr :: Lens' a DrawAttributes #

Lens which can be used to read/write primitives.

SVG drawing primitives

Rectangle

data Rectangle #

Define a rectangle. Correspond to `<rectangle>` svg tag.

Constructors

Rectangle 

Fields

Line

data Line #

Define a simple line. Correspond to the `<line>` tag.

Constructors

Line 

Fields

class HasLine c where #

Lenses for the Line type.

Minimal complete definition

line

Polygon

data Polygon #

Primitive decriving polygon composed of segements. Correspond to the `<polygon>` tag

Constructors

Polygon 

Fields

Polyline

data PolyLine #

This primitive describe an unclosed suite of segments. Correspond to the `<polyline>` tag.

Constructors

PolyLine 

Fields

Path

data Path #

Type mapping the `<path>` svg tag.

Constructors

Path 

Fields

class HasPath c where #

Lenses for the Path type

Minimal complete definition

path

Circle

data Circle #

Define a `<circle>`.

Constructors

Circle 

Fields

Ellipse

data Ellipse #

Define an `<ellipse>`

Constructors

Ellipse 

Fields

Mesh (gradient mesh)

data GradientPathCommand #

Description of path used in meshgradient tag

Constructors

GLine !Origin !(Maybe RPoint)

Line to, L or l Svg path command.

GCurve !Origin !RPoint !RPoint !(Maybe RPoint)

Cubic bezier, C or c command

GClose

Z command

Image

data Image #

Define an `<image>` tag.

Constructors

Image 

Fields

Use

data Use #

Define an `<use>` for a named content. Every named content can be reused in the document using this element.

Constructors

Use 

Fields

Grouping primitives

Group

data Group a #

Define a SVG group, corresponding `<g>` tag.

Constructors

Group 

Fields

Instances

class HasGroup c a | c -> a where #

Lenses associated to the Group type.

Minimal complete definition

group

Symbol

newtype Symbol a #

Define the `<symbol>` tag, equivalent to a named group.

Constructors

Symbol 

Fields

Instances

Eq a => Eq (Symbol a) # 

Methods

(==) :: Symbol a -> Symbol a -> Bool #

(/=) :: Symbol a -> Symbol a -> Bool #

Show a => Show (Symbol a) # 

Methods

showsPrec :: Int -> Symbol a -> ShowS #

show :: Symbol a -> String #

showList :: [Symbol a] -> ShowS #

WithDefaultSvg (Symbol a) # 

Methods

defaultSvg :: Symbol a #

WithDrawAttributes (Symbol a) # 

groupOfSymbol :: forall a a. Iso (Symbol a) (Symbol a) (Group a) (Group a) #

Lenses associated with the Symbol type.

Text related types

Text

data Text #

Define the global `<tag>` SVG tag.

Constructors

Text 

Fields

class HasText c where #

Lenses for the Text type.

Minimal complete definition

text

data TextAnchor #

Tell where to anchor the text, where the position given is realative to the text.

Constructors

TextAnchorStart

The text with left aligned, or start at the postion If the point is the * then the text will be printed this way:

 *THE_TEXT_TO_PRINT

Equivalent to the start value.

TextAnchorMiddle

The text is middle aligned, so the text will be at the left and right of the position:

  THE_TEXT*TO_PRINT

Equivalent to the middle value.

TextAnchorEnd

The text is right aligned.

  THE_TEXT_TO_PRINT*

Equivalent to the end value.

textAt :: Point -> Text -> Text #

Little helper to create a SVG text at a given baseline position.

Text path

data TextPath #

Describe the `<textpath>` SVG tag.

Constructors

TextPath 

Fields

data TextPathSpacing #

Describe the content of the spacing text path attribute.

Constructors

TextPathSpacingExact

Map to the exact value.

TextPathSpacingAuto

Map to the auto value.

data TextPathMethod #

Describe the content of the method attribute on text path.

Constructors

TextPathAlign

Map to the align value.

TextPathStretch

Map to the stretch value.

Text span.

data TextSpanContent #

Define the content of a `<tspan>` tag.

Constructors

SpanText !Text

Raw text

SpanTextRef !String

Equivalent to a `<tref>`

SpanSub !TextSpan

Define a `<tspan>`

data TextSpan #

Define a `<tspan>` tag.

Constructors

TextSpan 

Fields

data TextInfo #

Define position information associated to `<text>` or `<tspan>` svg tag.

Constructors

TextInfo 

Fields

data TextAdjust #

Define the possible values of the lengthAdjust attribute.

Constructors

TextAdjustSpacing

Value spacing

TextAdjustSpacingAndGlyphs

Value spacingAndGlyphs

Marker definition

data Marker #

Define the `<marker>` tag.

Constructors

Marker 

Fields

data Overflow #

Define the content of the markerUnits attribute on the Marker.

Constructors

OverflowVisible

Value visible

OverflowHidden

Value hidden

data MarkerOrientation #

Define the orientation, associated to the orient attribute on the Marker

Constructors

OrientationAuto

Auto value

OrientationAngle Coord

Specific angle.

data MarkerUnit #

Define the content of the markerUnits attribute on the Marker.

Constructors

MarkerUnitStrokeWidth

Value strokeWidth

MarkerUnitUserSpaceOnUse

Value userSpaceOnUse

Gradient definition

data GradientStop #

Define a color stop for the gradients. Represent the `<stop>` SVG tag.

Constructors

GradientStop 

Fields

Linear Gradient

data LinearGradient #

Define a `<linearGradient>` tag.

Constructors

LinearGradient 

Fields

Radial Gradient

data RadialGradient #

Define a `<radialGradient>` tag.

Constructors

RadialGradient 

Fields

Pattern definition

data Pattern #

Define a `<pattern>` tag.

Constructors

Pattern 

Fields

Mask definition

data Mask #

Define a SVG `<mask>` tag.

Constructors

Mask 

Fields

Clip path definition

Aspect Ratio description

data Alignment #

This type represent the align information of the preserveAspectRatio SVGattribute

Constructors

AlignNone

"none" value

AlignxMinYMin 
AlignxMidYMin

"xMidYMin" value

AlignxMaxYMin

"xMaxYMin" value

AlignxMinYMid

"xMinYMid" value

AlignxMidYMid

"xMidYMid" value

AlignxMaxYMid

"xMaxYMid" value

AlignxMinYMax

"xMinYMax" value

AlignxMidYMax

"xMidYMax" value

AlignxMaxYMax

"xMaxYMax" value

data MeetSlice #

This type represent the "meet or slice" information of the preserveAspectRatio SVGattribute

Constructors

Meet 
Slice 

MISC functions

isPathArc :: PathCommand -> Bool #

Tell if the path command is an EllipticalArc.

isPathWithArc :: Foldable f => f PathCommand -> Bool #

Tell if a full path contain an EllipticalArc.

nameOfTree :: Tree -> Text #

For every element of a svg tree, associate it's SVG tag name.

zipTree :: ([[Tree]] -> Tree) -> Tree -> Tree #

Map a tree while propagating context information. The function passed in parameter receive a list representing the the path used to go arrive to the current node.

mapTree :: (Tree -> Tree) -> Tree -> Tree #

Helper function mapping every tree element.

foldTree :: (a -> Tree -> a) -> a -> Tree -> a #

Fold all nodes of a SVG tree.

toUserUnit :: Dpi -> Number -> Number #

This function replace all device dependant units to user units given it's DPI configuration. Preserve percentage and "em" notation.

mapNumber :: (Double -> Double) -> Number -> Number #

Helper function to modify inner value of a number