Copyright | (c) 2015 Tillmann Vogt <tillk.vogt@googlemail.com> |
---|---|
License | BSD3 |
Maintainer | diagrams-discuss@googlegroups.com |
Stability | stable |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Synopsis
- data Tag b n
- = Leaf Id (ViewBox n -> Path V2 n) ((HashMaps b n, ViewBox n) -> Diagram b)
- | Reference Id Id (ViewBox n -> Path V2 n) ((HashMaps b n, ViewBox n) -> Diagram b -> Diagram b)
- | SubTree Bool Id (Double, Double) (Maybe (ViewBox n)) (Maybe PreserveAR) (HashMaps b n -> Diagram b -> Diagram b) [Tag b n]
- | StyleTag [(Text, [(Text, Text)])]
- | FontTag (FontData b n)
- | Grad Id (Gr n)
- | Stop (HashMaps b n -> [GradientStop n])
- type HashMaps b n = (NodesMap b n, CSSMap, GradientsMap n)
- nodes :: Maybe (ViewBox n) -> (Nodelist b n, CSSlist, Gradlist n, Fontlist b n) -> Tag b n -> (Nodelist b n, CSSlist, Gradlist n, Fontlist b n)
- type Attrs = [(Text, Text)]
- type NodesMap b n = HashMap Text (Tag b n)
- type CSSMap = HashMap Text Attrs
- type GradientsMap n = HashMap Text (Gr n)
- data PreserveAR = PAR AlignSVG MeetOrSlice
- data AlignSVG = AlignXY Place Place
- data MeetOrSlice
- type Place = Double
- type ViewBox n = (n, n, n, n)
- data Gr n = Gr GradRefId GradientAttributes (Maybe (ViewBox n)) [CSSMap -> [GradientStop n]] (CSSMap -> GradientAttributes -> ViewBox n -> [CSSMap -> [GradientStop n]] -> Texture n)
- data GradientAttributes = GA {
- presentationAttributes :: PresentationAttributes
- class_ :: Maybe Text
- style :: Maybe Text
- x1 :: Maybe Text
- y1 :: Maybe Text
- x2 :: Maybe Text
- y2 :: Maybe Text
- cx :: Maybe Text
- cy :: Maybe Text
- r :: Maybe Text
- fx :: Maybe Text
- fy :: Maybe Text
- gradientUnits :: Maybe Text
- gradientTransform :: Maybe Text
- spreadMethod :: Maybe Text
- data PresentationAttributes = PA {
- alignmentBaseline :: Maybe Text
- baselineShift :: Maybe Text
- clip :: Maybe Text
- clipPath :: Maybe Text
- clipRule :: Maybe Text
- color :: Maybe Text
- colorInterpolation :: Maybe Text
- colorInterpolationFilters :: Maybe Text
- colorProfile :: Maybe Text
- colorRendering :: Maybe Text
- cursor :: Maybe Text
- direction :: Maybe Text
- display :: Maybe Text
- dominantBaseline :: Maybe Text
- enableBackground :: Maybe Text
- fill :: Maybe Text
- fillOpacity :: Maybe Text
- fillRuleSVG :: Maybe Text
- filter :: Maybe Text
- floodColor :: Maybe Text
- floodOpacity :: Maybe Text
- fontFamily :: Maybe Text
- fntSize :: Maybe Text
- fontSizeAdjust :: Maybe Text
- fontStretch :: Maybe Text
- fontStyle :: Maybe Text
- fontVariant :: Maybe Text
- fontWeight :: Maybe Text
- glyphOrientationHorizontal :: Maybe Text
- glyphOrientationVertical :: Maybe Text
- imageRendering :: Maybe Text
- kerning :: Maybe Text
- letterSpacing :: Maybe Text
- lightingColor :: Maybe Text
- markerEnd :: Maybe Text
- markerMid :: Maybe Text
- markerStart :: Maybe Text
- mask :: Maybe Text
- opacity :: Maybe Text
- overflow :: Maybe Text
- pointerEvents :: Maybe Text
- shapeRendering :: Maybe Text
- stopColor :: Maybe Text
- stopOpacity :: Maybe Text
- strokeSVG :: Maybe Text
- strokeDasharray :: Maybe Text
- strokeDashoffset :: Maybe Text
- strokeLinecap :: Maybe Text
- strokeLinejoin :: Maybe Text
- strokeMiterlimit :: Maybe Text
- strokeOpacity :: Maybe Text
- strokeWidth :: Maybe Text
- textAnchor :: Maybe Text
- textDecoration :: Maybe Text
- textRendering :: Maybe Text
- unicodeBidi :: Maybe Text
- visibility :: Maybe Text
- wordSpacing :: Maybe Text
- writingMode :: Maybe Text
- type GradRefId = Maybe Text
- expandGradMap :: GradientsMap n -> GradientsMap n
- insertRefs :: (V b ~ V2, N b ~ n, RealFloat n, Place ~ n) => (HashMaps b n, ViewBox n) -> Tag b n -> Diagram b
- preserveAspectRatio :: (V a ~ V2, N a ~ Place, Fractional (N a), Transformable a, Alignable a, HasOrigin a, Additive (V a), R2 (V a)) => Place -> Place -> Place -> Place -> PreserveAR -> a -> a
- data FontContent b n
- data FontData b n = FontData {
- fontId :: Maybe Text
- fontDataHorizontalOriginX :: Maybe Text
- fontDataHorizontalOriginY :: Maybe Text
- fontDataHorizontalAdvance :: n
- fontDataVerticalOriginX :: Maybe Text
- fontDataVerticalOriginY :: Maybe Text
- fontDataVerticalAdvance :: Maybe Text
- fontFace :: FontFace n
- fontMissingGlyph :: Glyph b n
- fontDataGlyphs :: SvgGlyphs n
- fontDataKerning :: KernMaps n
- data FontFace n = FontFace {
- fontDataFamily :: Maybe Text
- fontDataStyle :: Maybe Text
- fontDataVariant :: Maybe Text
- fontDataWeight :: Maybe Text
- fontDataStretch :: Maybe Text
- fontDataSize :: Maybe Text
- fontDataUnicodeRange :: Maybe Text
- fontDataUnitsPerEm :: Maybe Text
- fontDataPanose :: Maybe Text
- fontDataVerticalStem :: Maybe Text
- fontDataHorizontalStem :: Maybe Text
- fontDataSlope :: Maybe Text
- fontDataCapHeight :: Maybe Text
- fontDataXHeight :: Maybe Text
- fontDataAccentHeight :: Maybe Text
- fontDataAscent :: Maybe Text
- fontDataDescent :: Maybe Text
- fontDataWidths :: Maybe Text
- fontDataBoundingBox :: [n]
- fontDataIdeographicBaseline :: Maybe Text
- fontDataAlphabeticBaseline :: Maybe Text
- fontDataMathematicalBaseline :: Maybe Text
- fontDataHangingBaseline :: Maybe Text
- fontDataVIdeographicBaseline :: Maybe Text
- fontDataVAlphabeticBaseline :: Maybe Text
- fontDataVMathematicalBaseline :: Maybe Text
- fontDataVHangingBaseline :: Maybe Text
- fontDataUnderlinePos :: Maybe Text
- fontDataUnderlineThickness :: Maybe Text
- fontDataStrikethroughPos :: Maybe Text
- fontDataStrikethroughThickness :: Maybe Text
- fontDataOverlinePos :: Maybe Text
- fontDataOverlineThickness :: Maybe Text
- data Glyph b n = Glyph {}
- data KernDir
- data KernMaps n = KernMaps {}
- type SvgGlyphs n = HashMap Text (Maybe Text, n, Maybe Text)
- data Kern n = Kern {}
Tree data type
A tree structure is needed to handle refences to parts of the tree itself. The <defs>-section contains shapes that can be refered to, but the SVG standard allows to refer to every tag in the SVG-file.
Leaf | |
Reference | |
SubTree | |
| |
StyleTag [(Text, [(Text, Text)])] | A tag that contains CSS styles with selectors and attributes |
FontTag (FontData b n) | |
Grad Id (Gr n) | A gradient |
Stop (HashMaps b n -> [GradientStop n]) | We need to make this part of this data structure because Gradient tags can also contain description tags |
Extract data from the tree
nodes :: Maybe (ViewBox n) -> (Nodelist b n, CSSlist, Gradlist n, Fontlist b n) -> Tag b n -> (Nodelist b n, CSSlist, Gradlist n, Fontlist b n) Source #
Generate elements that can be referenced by their ID. The tree nodes are splitted into 4 groups of lists of (ID,value)-pairs):
- Nodes that contain elements that can be transformed to a diagram
- CSS classes with corresponding (attribute,value)-pairs, from the defs-tag
- Gradients
- Fonts
data PreserveAR Source #
data MeetOrSlice Source #
= Double | A value between 0 and 1, where 0 is the minimal value and 1 the maximal value |
Gr GradRefId GradientAttributes (Maybe (ViewBox n)) [CSSMap -> [GradientStop n]] (CSSMap -> GradientAttributes -> ViewBox n -> [CSSMap -> [GradientStop n]] -> Texture n) |
data GradientAttributes Source #
GA | |
|
data PresentationAttributes Source #
Instances
Show PresentationAttributes Source # | |
Defined in Diagrams.SVG.Tree showsPrec :: Int -> PresentationAttributes -> ShowS # show :: PresentationAttributes -> String # showList :: [PresentationAttributes] -> ShowS # |
expandGradMap :: GradientsMap n -> GradientsMap n Source #
Gradients contain references to include attributes/stops from other gradients. expandGradMap expands the gradient with these attributes and stops
insertRefs :: (V b ~ V2, N b ~ n, RealFloat n, Place ~ n) => (HashMaps b n, ViewBox n) -> Tag b n -> Diagram b Source #
Evaluate the tree into a diagram by inserting xlink:href references from nodes and gradients, applying clipping and passing the viewbox to the leafs
preserveAspectRatio :: (V a ~ V2, N a ~ Place, Fractional (N a), Transformable a, Alignable a, HasOrigin a, Additive (V a), R2 (V a)) => Place -> Place -> Place -> Place -> PreserveAR -> a -> a Source #
preserveAspectRatio is needed to fit an image into a frame that has a different aspect ratio than the image (e.g. 16:10 against 4:3). SVG embeds images the same way: http://www.w3.org/TR/SVG11/coords.html#PreserveAspectRatioAttribute
import Graphics.SVGFonts portrait preserveAR width height = stroke (readSVGFile preserveAR width height "portrait.svg") # showOrigin text' t = stroke (textSVG' $ TextOpts t lin INSIDE_H KERN False 1 1 ) # fc back # lc black # fillRule EvenOdd portraitMeet1 x y = (text' "PAR (AlignXY " ++ show x ++ " " show y ++ ") Meet") === (portrait (PAR (AlignXY x y) Meet) 200 100 <> rect 200 100) portraitMeet2 x y = (text' "PAR (AlignXY " ++ show x ++ " " show y ++ ") Meet") === (portrait (PAR (AlignXY x y) Meet) 100 200 <> rect 100 200) portraitSlice1 x y = (text' "PAR (AlignXY " ++ show x ++ " " show y ++ ") Slice") === (portrait (PAR (AlignXY x y) Slice) 100 200 <> rect 100 200) portraitSlice2 x y = (text' "PAR (AlignXY " ++ show x ++ " " show y ++ ") Slice") === (portrait (PAR (AlignXY x y) Slice) 200 100 <> rect 200 100) meetX = (text' "meet") === (portraitMeet1 0 0 ||| portraitMeet1 0.5 0 ||| portraitMeet1 1 0) meetY = (text' "meet") === (portraitMeet2 0 0 ||| portraitMeet2 0 0.5 ||| portraitMeet2 0 1) sliceX = (text' "slice") === (portraitSlice1 0 0 ||| portraitSlice1 0.5 0 ||| portraitSlice1 1 0) sliceY = (text' "slice") === (portraitSlice2 0 0 ||| portraitSlice2 0 0.5 ||| portraitSlice2 0 1) im = (text' "Image to fit") === (portrait (PAR (AlignXY 0 0) Meet) 123 456) viewport1 = (text' "Viewport1") === (rect 200 100) viewport2 = (text' "Viewport2") === (rect 100 200) imageAndViewports = im === viewport1 === viewport2 par = imageAndViewports ||| ( ( meetX ||| meetY) === ( sliceX ||| sliceY) )
preserveAspectRatio :: Width -> Height -> Width -> Height -> PreserveAR -> Diagram b -> Diagram b
All data in the <font>-tag
FontData | |
|