svg-tree-0.6.2: 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 Source #

Basic coordiante type.

data Origin Source #

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

type Point = (Number, Number) Source #

Possibly context dependant point.

type RPoint = V2 Coord Source #

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

data PathCommand Source #

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 Source #

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 Source #

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 Source #

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 Source #

Little helper function to build a point.

serializeNumber :: Number -> String Source #

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

serializeTransformation :: Transformation -> String Source #

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

serializeTransformations :: [Transformation] -> String Source #

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

Drawing control types

data Cap Source #

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 Source # 

Methods

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

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

Show Cap Source # 

Methods

showsPrec :: Int -> Cap -> ShowS #

show :: Cap -> String #

showList :: [Cap] -> ShowS #

data LineJoin Source #

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

Constructors

JoinMiter

miter value

JoinBevel

bevel value

JoinRound

round value

data Number Source #

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

data Spread Source #

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

Constructors

SpreadRepeat

reapeat value

SpreadPad

pad value

SpreadReflect

`reflect value`

Instances

data Texture Source #

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.

data FillRule Source #

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 Source #

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

type Dpi = Int Source #

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

class WithDefaultSvg a where Source #

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 Source #

The default element.

Instances

WithDefaultSvg PreserveAspectRatio Source # 
WithDefaultSvg DrawAttributes Source # 
WithDefaultSvg PolyLine Source # 
WithDefaultSvg Polygon Source # 
WithDefaultSvg Line Source # 
WithDefaultSvg Rectangle Source # 
WithDefaultSvg Path Source # 
WithDefaultSvg Circle Source # 
WithDefaultSvg Ellipse Source # 
WithDefaultSvg GradientStop Source # 
WithDefaultSvg MeshGradientPatch Source # 
WithDefaultSvg MeshGradientRow Source # 
WithDefaultSvg MeshGradient Source # 
WithDefaultSvg Image Source # 
WithDefaultSvg Use Source # 
WithDefaultSvg TextInfo Source # 
WithDefaultSvg TextSpan Source # 
WithDefaultSvg TextPath Source # 
WithDefaultSvg Text Source # 
WithDefaultSvg Marker Source # 
WithDefaultSvg Tree Source # 
WithDefaultSvg LinearGradient Source # 
WithDefaultSvg RadialGradient Source # 
WithDefaultSvg Mask Source # 
WithDefaultSvg ClipPath Source # 
WithDefaultSvg Pattern Source # 
WithDefaultSvg (Group a) Source # 

Methods

defaultSvg :: Group a Source #

WithDefaultSvg (Symbol a) Source # 

Main type

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

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

Drawing attributes

data DrawAttributes Source #

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 Source # 
Show DrawAttributes Source # 
Monoid DrawAttributes Source # 
WithDefaultSvg DrawAttributes Source # 
HasDrawAttributes DrawAttributes Source # 

Methods

drawAttributes :: Lens' DrawAttributes DrawAttributes Source #

attrClass :: Lens' DrawAttributes [Text] Source #

attrId :: Lens' DrawAttributes (Maybe String) Source #

clipPathRef :: Lens' DrawAttributes (Last ElementRef) Source #

clipRule :: Lens' DrawAttributes (Last FillRule) Source #

fillColor :: Lens' DrawAttributes (Last Texture) Source #

fillOpacity :: Lens' DrawAttributes (Maybe Float) Source #

fillRule :: Lens' DrawAttributes (Last FillRule) Source #

fontFamily :: Lens' DrawAttributes (Last [String]) Source #

fontSize :: Lens' DrawAttributes (Last Number) Source #

fontStyle :: Lens' DrawAttributes (Last FontStyle) Source #

groupOpacity :: Lens' DrawAttributes (Maybe Float) Source #

markerEnd :: Lens' DrawAttributes (Last ElementRef) Source #

markerMid :: Lens' DrawAttributes (Last ElementRef) Source #

markerStart :: Lens' DrawAttributes (Last ElementRef) Source #

maskRef :: Lens' DrawAttributes (Last ElementRef) Source #

strokeColor :: Lens' DrawAttributes (Last Texture) Source #

strokeDashArray :: Lens' DrawAttributes (Last [Number]) Source #

strokeLineCap :: Lens' DrawAttributes (Last Cap) Source #

strokeLineJoin :: Lens' DrawAttributes (Last LineJoin) Source #

strokeMiterLimit :: Lens' DrawAttributes (Last Double) Source #

strokeOffset :: Lens' DrawAttributes (Last Number) Source #

strokeOpacity :: Lens' DrawAttributes (Maybe Float) Source #

strokeWidth :: Lens' DrawAttributes (Last Number) Source #

textAnchor :: Lens' DrawAttributes (Last TextAnchor) Source #

transform :: Lens' DrawAttributes (Maybe [Transformation]) Source #

class HasDrawAttributes c where Source #

Lenses for the DrawAttributes type.

Minimal complete definition

drawAttributes

Instances

HasDrawAttributes DrawAttributes Source # 

Methods

drawAttributes :: Lens' DrawAttributes DrawAttributes Source #

attrClass :: Lens' DrawAttributes [Text] Source #

attrId :: Lens' DrawAttributes (Maybe String) Source #

clipPathRef :: Lens' DrawAttributes (Last ElementRef) Source #

clipRule :: Lens' DrawAttributes (Last FillRule) Source #

fillColor :: Lens' DrawAttributes (Last Texture) Source #

fillOpacity :: Lens' DrawAttributes (Maybe Float) Source #

fillRule :: Lens' DrawAttributes (Last FillRule) Source #

fontFamily :: Lens' DrawAttributes (Last [String]) Source #

fontSize :: Lens' DrawAttributes (Last Number) Source #

fontStyle :: Lens' DrawAttributes (Last FontStyle) Source #

groupOpacity :: Lens' DrawAttributes (Maybe Float) Source #

markerEnd :: Lens' DrawAttributes (Last ElementRef) Source #

markerMid :: Lens' DrawAttributes (Last ElementRef) Source #

markerStart :: Lens' DrawAttributes (Last ElementRef) Source #

maskRef :: Lens' DrawAttributes (Last ElementRef) Source #

strokeColor :: Lens' DrawAttributes (Last Texture) Source #

strokeDashArray :: Lens' DrawAttributes (Last [Number]) Source #

strokeLineCap :: Lens' DrawAttributes (Last Cap) Source #

strokeLineJoin :: Lens' DrawAttributes (Last LineJoin) Source #

strokeMiterLimit :: Lens' DrawAttributes (Last Double) Source #

strokeOffset :: Lens' DrawAttributes (Last Number) Source #

strokeOpacity :: Lens' DrawAttributes (Maybe Float) Source #

strokeWidth :: Lens' DrawAttributes (Last Number) Source #

textAnchor :: Lens' DrawAttributes (Last TextAnchor) Source #

transform :: Lens' DrawAttributes (Maybe [Transformation]) Source #

class WithDrawAttributes a where Source #

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

Minimal complete definition

drawAttr

Methods

drawAttr :: Lens' a DrawAttributes Source #

Lens which can be used to read/write primitives.

Instances

WithDrawAttributes PolyLine Source # 
WithDrawAttributes Polygon Source # 
WithDrawAttributes Line Source # 
WithDrawAttributes Rectangle Source # 
WithDrawAttributes Path Source # 
WithDrawAttributes Circle Source # 
WithDrawAttributes Ellipse Source # 
WithDrawAttributes MeshGradient Source # 
WithDrawAttributes Image Source # 
WithDrawAttributes Use Source # 
WithDrawAttributes Text Source # 
WithDrawAttributes Marker Source # 
WithDrawAttributes Tree Source # 
WithDrawAttributes Mask Source # 
WithDrawAttributes ClipPath Source # 
WithDrawAttributes Pattern Source # 
WithDrawAttributes (Group a) Source # 
WithDrawAttributes (Symbol a) Source # 

SVG drawing primitives

Rectangle

data Rectangle Source #

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

Constructors

Rectangle 

Fields

Line

data Line Source #

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

Constructors

Line 

Fields

Polygon

data Polygon Source #

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

Constructors

Polygon 

Fields

Polyline

data PolyLine Source #

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

Constructors

PolyLine 

Fields

Path

data Path Source #

Type mapping the `<path>` svg tag.

Constructors

Path 

Fields

Circle

data Circle Source #

Define a `<circle>`.

Constructors

Circle 

Fields

Ellipse

data Ellipse Source #

Define an `<ellipse>`

Constructors

Ellipse 

Fields

Mesh (gradient mesh)

data GradientPathCommand Source #

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

data MeshGradient Source #

Define a `<meshgradient>` tag.

Constructors

MeshGradient 

Fields

Image

Use

data Use Source #

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 Source #

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

Constructors

Group 

Fields

Symbol

newtype Symbol a Source #

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

Constructors

Symbol 

Fields

Instances

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

Lenses associated with the Symbol type.

Text related types

Text

data Text Source #

Define the global `<tag>` SVG tag.

Constructors

Text 

Fields

class HasText c where Source #

Lenses for the Text type.

Minimal complete definition

text

data TextAnchor Source #

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 Source #

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

Text path

data TextPath Source #

Describe the `<textpath>` SVG tag.

Constructors

TextPath 

Fields

data TextPathSpacing Source #

Describe the content of the spacing text path attribute.

Constructors

TextPathSpacingExact

Map to the exact value.

TextPathSpacingAuto

Map to the auto value.

data TextPathMethod Source #

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 Source #

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

Constructors

SpanText !Text

Raw text

SpanTextRef !String

Equivalent to a `<tref>`

SpanSub !TextSpan

Define a `<tspan>`

data TextAdjust Source #

Define the possible values of the lengthAdjust attribute.

Constructors

TextAdjustSpacing

Value spacing

TextAdjustSpacingAndGlyphs

Value spacingAndGlyphs

Marker definition

data Marker Source #

Define the `<marker>` tag.

Constructors

Marker 

Fields

data Overflow Source #

Define the content of the markerUnits attribute on the Marker.

Constructors

OverflowVisible

Value visible

OverflowHidden

Value hidden

data MarkerOrientation Source #

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

Constructors

OrientationAuto

Auto value

OrientationAngle Coord

Specific angle.

data MarkerUnit Source #

Define the content of the markerUnits attribute on the Marker.

Constructors

MarkerUnitStrokeWidth

Value strokeWidth

MarkerUnitUserSpaceOnUse

Value userSpaceOnUse

Gradient definition

data GradientStop Source #

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

Constructors

GradientStop 

Fields

Linear Gradient

data LinearGradient Source #

Define a `<linearGradient>` tag.

Constructors

LinearGradient 

Fields

Radial Gradient

data RadialGradient Source #

Define a `<radialGradient>` tag.

Constructors

RadialGradient 

Fields

Pattern definition

data Pattern Source #

Define a `<pattern>` tag.

Constructors

Pattern 

Fields

Mask definition

Clip path definition

Aspect Ratio description

data Alignment Source #

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 Source #

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

Constructors

Meet 
Slice 

MISC functions

isPathArc :: PathCommand -> Bool Source #

Tell if the path command is an EllipticalArc.

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

Tell if a full path contain an EllipticalArc.

nameOfTree :: Tree -> Text Source #

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

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

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 Source #

Helper function mapping every tree element.

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

Fold all nodes of a SVG tree.

toUserUnit :: Dpi -> Number -> Number Source #

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 Source #

Helper function to modify inner value of a number