Commit 9825bb3f authored by Peter Achten's avatar Peter Achten

restructured svg library

parent 1ae9d83f
This diff is collapsed.
implementation module Graphics.Scalable.Image
from StdList import repeat
from Data.Maybe import :: Maybe (..), instance Functor Maybe, maybeToList
from Data.Functor import class Functor (..)
import iTasks.UI.Editor
import iTasks.Extensions.Platform
import iTasks.UI.JS.Encoding
import iTasks.Extensions.SVG.Internal.SVGEditor
import Graphics.Scalable.Internal.Image`
:: Image m :== Image` m
empty :: !Span !Span -> Image m
empty xspan yspan = Empty` xspan yspan
text :: !FontDef !String -> Image m
text font str = Text` font str
circle :: !Span -> Image m
circle diameter = Circle` diameter
ellipse :: !Span !Span -> Image m
ellipse diax diay = Ellipse` diax diay
square :: !Span -> Image m
square edge = Square` edge
rect :: !Span !Span -> Image m
rect xspan yspan = Rect` xspan yspan
xline :: !Span -> Image m
xline xspan = Polyline` [(zero,zero),(xspan,zero)]
yline :: !Span -> Image m
yline yspan = Polyline` [(zero,zero),(zero,yspan)]
line :: !Span !Span -> Image m
line xspan yspan = Polyline` [(zero,zero),(xspan,yspan)]
polyline :: ![ImageOffset] -> Image m
polyline offsets = Polyline` offsets
polygon :: ![ImageOffset] -> Image m
polygon offsets = Polygon` offsets
rotate :: !Angle !(Image m) -> Image m
rotate a image = Rotate` a image
flipx :: !(Image m) -> Image m
flipx image = Flipx` image
flipy :: !(Image m) -> Image m
flipy image = Flipy` image
fit :: !Span !Span !(Image m) -> Image m
fit xspan yspan image = Fit` xspan yspan image
fitx :: !Span !(Image m) -> Image m
fitx xspan image = Fitx` xspan image
fity :: !Span !(Image m) -> Image m
fity yspan image = Fity` yspan image
scale :: !Real !Real !(Image m) -> Image m
scale fx fy image = Scale` fx fy image
scalex :: !Real !(Image m) -> Image m
scalex fx image = Scale` fx 1.0 image
scaley :: !Real !(Image m) -> Image m
scaley fy image = Scale` 1.0 fy image
skewx :: !Angle !(Image m) -> Image m
skewx a image = Skewx` a image
skewy :: !Angle !(Image m) -> Image m
skewy a image = Skewy` a image
overlay :: ![XYAlign] ![ImageOffset] ![Image m] !(Host m) -> Image m
overlay aligns offsets images host = Overlay` aligns offsets images (toHost` host)
collage :: ![ImageOffset] ![Image m] !(Host m) -> Image m
collage offsets images host = Overlay` (repeat (AtLeft,AtTop)) offsets images (toHost` host)
beside :: ![YAlign] ![Span] !(Maybe Span) ![ImageOffset] ![Image m] !(Host m) -> Image m
beside ylayouts column_widths row_height offsets imgs host
= Grid` (Rows 1) (RowMajor, LeftToRight, TopToBottom) [(AtLeft, ylayout) \\ ylayout <- ylayouts] column_widths (maybeToList row_height) offsets imgs (toHost` host)
above :: ![XAlign] ![Span] !(Maybe Span) ![ImageOffset] ![Image m] !(Host m) -> Image m
above xlayouts row_heights column_width offsets imgs host
= Grid` (Columns 1) (ColumnMajor, LeftToRight, TopToBottom) [(xlayout, AtTop) \\ xlayout <- xlayouts] (maybeToList column_width) row_heights offsets imgs (toHost` host)
grid :: !GridDimension !GridLayout ![XYAlign] ![Span] ![Span] ![ImageOffset] ![Image m] !(Host m) -> Image m
grid dimension layout aligns column_widths row_heights offsets images host
= Grid` dimension layout aligns column_widths row_heights offsets images (toHost` host)
:: Host m = NoHost | Host (Image m)
toHost` :: !(Host m) -> Host` m
toHost` NoHost = NoHost`
toHost` (Host img) = Host` img
class tuneImage attr :: !(Image m) !(attr m) -> Image m
(<@<) infixl 2 :: !(Image m) !(attr m) -> Image m | tuneImage attr
(<@<) image attr = tuneImage image attr
(>@>) infixr 2 :: !(attr m) !(Image m) -> Image m | tuneImage attr
(>@>) attr image = tuneImage image attr
tuneIf :: !Bool !(Image m) !(attr m) -> Image m | tuneImage attr
tuneIf True img t = tuneImage img t
tuneIf _ img _ = img
:: NoAttr m = NoAttr
:: DashAttr m = { dash :: ![Int] }
:: FillAttr m = { fill :: !SVGColor }
:: LineEndMarker m = { endmarker :: !Image m }
:: LineMidMarker m = { midmarker :: !Image m }
:: LineStartMarker m = { startmarker :: !Image m }
:: MaskAttr m = { mask :: !Image m }
:: OpacityAttr m = { opacity :: !Real }
:: StrokeAttr m = { stroke :: !SVGColor }
:: StrokeWidthAttr m = { strokewidth :: !Span }
:: XRadiusAttr m = { xradius :: !Span }
:: YRadiusAttr m = { yradius :: !Span }
instance tuneImage NoAttr where tuneImage image _ = image
instance tuneImage DashAttr where tuneImage image attr = Attr` (BasicImageAttr` (BasicImgDashAttr attr.DashAttr.dash)) image
instance tuneImage FillAttr where tuneImage image attr = Attr` (BasicImageAttr` (BasicImgFillAttr attr.FillAttr.fill)) image
instance tuneImage LineEndMarker where tuneImage image attr = Attr` (LineMarkerAttr` {LineMarkerAttr | markerImg = attr.LineEndMarker.endmarker, markerPos = LineMarkerEnd}) image
instance tuneImage LineMidMarker where tuneImage image attr = Attr` (LineMarkerAttr` {LineMarkerAttr | markerImg = attr.LineMidMarker.midmarker, markerPos = LineMarkerMid}) image
instance tuneImage LineStartMarker where tuneImage image attr = Attr` (LineMarkerAttr` {LineMarkerAttr | markerImg = attr.LineStartMarker.startmarker, markerPos = LineMarkerStart}) image
instance tuneImage MaskAttr where tuneImage image attr = Attr` (MaskAttr` attr.MaskAttr.mask) image
instance tuneImage OpacityAttr where tuneImage image attr = Attr` (BasicImageAttr` (BasicImgFillOpacityAttr attr.OpacityAttr.opacity)) image
instance tuneImage StrokeAttr where tuneImage image attr = Attr` (BasicImageAttr` (BasicImgStrokeAttr attr.StrokeAttr.stroke)) image
instance tuneImage StrokeWidthAttr where tuneImage image attr = Attr` (BasicImageAttr` (BasicImgStrokeWidthAttr attr.StrokeWidthAttr.strokewidth)) image
instance tuneImage XRadiusAttr where tuneImage image attr = Attr` (BasicImageAttr` (BasicImgXRadiusAttr attr.XRadiusAttr.xradius)) image
instance tuneImage YRadiusAttr where tuneImage image attr = Attr` (BasicImageAttr` (BasicImgYRadiusAttr attr.YRadiusAttr.yradius)) image
instance tuneImage DraggableAttr where tuneImage image attr = Attr` (HandlerAttr` (ImgEventhandlerDraggableAttr attr)) image
instance tuneImage OnClickAttr where tuneImage image attr = Attr` (HandlerAttr` (ImgEventhandlerOnClickAttr attr)) image
instance tuneImage OnMouseDownAttr where tuneImage image attr = Attr` (HandlerAttr` (ImgEventhandlerOnMouseDownAttr attr)) image
instance tuneImage OnMouseMoveAttr where tuneImage image attr = Attr` (HandlerAttr` (ImgEventhandlerOnMouseMoveAttr attr)) image
instance tuneImage OnMouseOutAttr where tuneImage image attr = Attr` (HandlerAttr` (ImgEventhandlerOnMouseOutAttr attr)) image
instance tuneImage OnMouseOverAttr where tuneImage image attr = Attr` (HandlerAttr` (ImgEventhandlerOnMouseOverAttr attr)) image
instance tuneImage OnMouseUpAttr where tuneImage image attr = Attr` (HandlerAttr` (ImgEventhandlerOnMouseUpAttr attr)) image
class margin a where
margin :: !a !(Image m) -> Image m
instance margin Span where
margin sp im = margin (sp, sp, sp, sp) im
instance margin (!Span, !Span) where
margin (sp1, sp2) im = margin (sp1, sp2, sp1, sp2) im
instance margin (!Span, !Span, !Span) where
margin (sp1, sp2, sp3) im = margin (sp1, sp2, sp3, sp2) im
instance margin (!Span, !Span, !Span, !Span) where
margin (sp1, sp2, sp3, sp4) image = Margin` {Margins` | n=sp1, e=sp2, s=sp3, w=sp4} image
tag :: !*ImageTag !(Image m) -> Image m
tag t image = Tag` t image
tagWithSrc :: !*TagSource !(Image m) -> *(!(!Image m, !ImageTag), !*TagSource)
tagWithSrc [(nut, t) : tsrc] image
= ((Tag` t image, nut), tsrc)
fromSVGEditor :: !(SVGEditor s v) -> Editor s | iTask s & JSEncode{|*|} s
fromSVGEditor {SVGEditor | initView,renderImage,updView,updModel}
= fromSVGEditor` {SVGEditor` | initView` = initView
, renderImage` = renderImage
, updView` = updView
, updModel` = updModel
}
definition module Graphics.Scalable.Internal.Image
from Data.Maybe import :: Maybe
from Data.Set import :: Set
from Data.Map import :: Map
from Data.Error import :: MaybeError (..)
from Math.Geometry import :: Angle
from StdOverloaded import class zero (..), class + (..), class - (..), class ~ (..), class sign (..),
class abs (..), class < (..), class == (..), class toReal (..), class / (..), class * (..)
import Graphics.Scalable.Types
import Graphics.Scalable.Internal.Types
:: Image` m :== TextSpans [ImgTagNo] -> (Img, ImgEventhandlers m, ImgTexts, ImgMasks, ImgSpans, GridSpans, ImgTags, [ImgTagNo])
:: TextSpans :== Map FontDef (FontDescent, Map String TextSpan) // of each font, the font descent and of each text the width
:: ImgEventhandlers m :== Map ImgTagNo [ImgEventhandler m] // the registered event handlers of the image identified by the id (once registered, an event handler can not be overruled)
:: ImgTexts :== Map FontDef (Set String) // of each font, the collection of texts
:: ImgMasks :== Map ImgTagNo Img // of each mask, the mask-image (associate the id with (MaskImg id))
:: ImgSpans :== Map ImgTagNo ImageSpan // of each image, its (width,height)
:: GridSpans :== Map ImgTagNo GridSpan // of each grid, the spans of its columns and the spans of its rows
:: ImgTags :== Map ImageTag ImgTagNo // map user-tag to system number
:: FontDescent :== Real
:: TextSpan :== Real
:: ImgEventhandler m
= ImgEventhandlerOnClickAttr !(OnClickAttr m)
| ImgEventhandlerOnMouseDownAttr !(OnMouseDownAttr m)
| ImgEventhandlerOnMouseUpAttr !(OnMouseUpAttr m)
| ImgEventhandlerOnMouseOverAttr !(OnMouseOverAttr m)
| ImgEventhandlerOnMouseMoveAttr !(OnMouseMoveAttr m)
| ImgEventhandlerOnMouseOutAttr !(OnMouseOutAttr m)
| ImgEventhandlerDraggableAttr !(DraggableAttr m)
:: GridSpan
= { col_spans :: ![Span]
, row_spans :: ![Span]
}
:: Img
= { uniqId :: !ImgTagNo // the unique system identification within the entire image
, host :: !HostImg // the host of this image
, transform :: !Maybe ImgTransform // the optional transform of the basic/composite image
, overlays :: ![Img] // the back-to-front ordering of images 'on top of' host
, offsets :: ![ImageOffset] // the offsets matching one-by-one with .overlays
}
:: HostImg
= BasicHostImg !BasicImg !(Set BasicImgAttr)
| RawHostImg !String
| CompositeImg !Img
:: BasicImg
= EmptyImg
| TextImg !FontDef !String
| CircleImg
| RectImg
| EllipseImg
| PolylineImg !LineMarkers ![ImageOffset]
| PolygonImg !LineMarkers ![ImageOffset]
:: LineMarkers
= { lineStart :: !Maybe Img
, lineMid :: !Maybe Img
, lineEnd :: !Maybe Img
}
:: BasicImgAttr // attributes that are applicable only on basic images
= BasicImgStrokeAttr !SVGColor
| BasicImgStrokeWidthAttr !Span
| BasicImgXRadiusAttr !Span
| BasicImgYRadiusAttr !Span
| BasicImgStrokeOpacityAttr !Real
| BasicImgFillOpacityAttr !Real
| BasicImgFillAttr !SVGColor
| BasicImgDashAttr ![Int]
:: ImgTransform
= RotateImg !Angle
| SkewXImg !Angle
| SkewYImg !Angle
| FitImg !Span !Span
| FitXImg !Span
| FitYImg !Span
| ScaleImg !Real !Real
| FlipXImg
| FlipYImg
| MaskImg !ImgTagNo // the id-img pair is stored in the ImgMasks table
:: Host` m
= NoHost`
| Host` (Image` m)
:: Markers` m
= { markerStart` :: !Maybe (Image` m)
, markerMid` :: !Maybe (Image` m)
, markerEnd` :: !Maybe (Image` m)
}
tag` :: !*ImageTag !(Image` m) -> Image` m
tagWithSrc` :: !*TagSource !(Image` m) -> *(!(!Image` m, !ImageTag), !*TagSource)
empty` :: !Span !Span !TextSpans ![ImgTagNo] -> (!Img,!ImgEventhandlers m,!ImgTexts,!ImgMasks,!ImgSpans,!GridSpans,!ImgTags,![ImgTagNo])
text` :: !FontDef !String !TextSpans ![ImgTagNo] -> (!Img,!ImgEventhandlers m,!ImgTexts,!ImgMasks,!ImgSpans,!GridSpans,!ImgTags,![ImgTagNo])
circle` :: !Span !TextSpans ![ImgTagNo] -> (!Img,!ImgEventhandlers m,!ImgTexts,!ImgMasks,!ImgSpans,!GridSpans,!ImgTags,![ImgTagNo])
ellipse` :: !Span !Span !TextSpans ![ImgTagNo] -> (!Img,!ImgEventhandlers m,!ImgTexts,!ImgMasks,!ImgSpans,!GridSpans,!ImgTags,![ImgTagNo])
rect` :: !Span !Span !TextSpans ![ImgTagNo] -> (!Img,!ImgEventhandlers m,!ImgTexts,!ImgMasks,!ImgSpans,!GridSpans,!ImgTags,![ImgTagNo])
raw` :: !Span !Span !String !TextSpans ![ImgTagNo] -> (!Img,!ImgEventhandlers m,!ImgTexts,!ImgMasks,!ImgSpans,!GridSpans,!ImgTags,![ImgTagNo])
polyline` :: !(Markers` m) ![ImageOffset] !TextSpans ![ImgTagNo] -> (!Img,!ImgEventhandlers m,!ImgTexts,!ImgMasks,!ImgSpans,!GridSpans,!ImgTags,![ImgTagNo])
polygon` :: !(Markers` m) ![ImageOffset] !TextSpans ![ImgTagNo] -> (!Img,!ImgEventhandlers m,!ImgTexts,!ImgMasks,!ImgSpans,!GridSpans,!ImgTags,![ImgTagNo])
fit` :: !Span !Span !(Image` m) !TextSpans ![ImgTagNo] -> (!Img,!ImgEventhandlers m,!ImgTexts,!ImgMasks,!ImgSpans,!GridSpans,!ImgTags,![ImgTagNo])
fitx` :: !Span !(Image` m) !TextSpans ![ImgTagNo] -> (!Img,!ImgEventhandlers m,!ImgTexts,!ImgMasks,!ImgSpans,!GridSpans,!ImgTags,![ImgTagNo])
fity` :: !Span !(Image` m) !TextSpans ![ImgTagNo] -> (!Img,!ImgEventhandlers m,!ImgTexts,!ImgMasks,!ImgSpans,!GridSpans,!ImgTags,![ImgTagNo])
scale` :: !Real !Real !(Image` m) !TextSpans ![ImgTagNo] -> (!Img,!ImgEventhandlers m,!ImgTexts,!ImgMasks,!ImgSpans,!GridSpans,!ImgTags,![ImgTagNo])
rotate` :: !Angle !(Image` m) !TextSpans ![ImgTagNo] -> (!Img,!ImgEventhandlers m,!ImgTexts,!ImgMasks,!ImgSpans,!GridSpans,!ImgTags,![ImgTagNo])
flipx` :: !(Image` m) !TextSpans ![ImgTagNo] -> (!Img,!ImgEventhandlers m,!ImgTexts,!ImgMasks,!ImgSpans,!GridSpans,!ImgTags,![ImgTagNo])
flipy` :: !(Image` m) !TextSpans ![ImgTagNo] -> (!Img,!ImgEventhandlers m,!ImgTexts,!ImgMasks,!ImgSpans,!GridSpans,!ImgTags,![ImgTagNo])
skewx` :: !Angle !(Image` m) !TextSpans ![ImgTagNo] -> (!Img,!ImgEventhandlers m,!ImgTexts,!ImgMasks,!ImgSpans,!GridSpans,!ImgTags,![ImgTagNo])
skewy` :: !Angle !(Image` m) !TextSpans ![ImgTagNo] -> (!Img,!ImgEventhandlers m,!ImgTexts,!ImgMasks,!ImgSpans,!GridSpans,!ImgTags,![ImgTagNo])
mask` :: !(Image` m) !(Image` m) !TextSpans ![ImgTagNo] -> (!Img,!ImgEventhandlers m,!ImgTexts,!ImgMasks,!ImgSpans,!GridSpans,!ImgTags,![ImgTagNo])
grid` :: !GridDimension !GridLayout ![XYAlign] ![Span] ![Span] ![ImageOffset] ![Image` m] !(Host` m)
!TextSpans ![ImgTagNo] -> (!Img,!ImgEventhandlers m,!ImgTexts,!ImgMasks,!ImgSpans,!GridSpans,!ImgTags,![ImgTagNo])
overlay` :: ![XYAlign] ![ImageOffset] ![Image` m] !(Host` m)
!TextSpans ![ImgTagNo] -> (!Img,!ImgEventhandlers m,!ImgTexts,!ImgMasks,!ImgSpans,!GridSpans,!ImgTags,![ImgTagNo])
tuneAttr` :: !(Image` m) !BasicImgAttr -> Image` m
tuneHandler` :: !(Image` m) !(ImgEventhandler m) -> Image` m
:: SpanResolveError :== String
resolve_spans :: !ImgTags !TextSpans !Img !ImgMasks !ImgSpans !GridSpans -> MaybeError SpanResolveError (!Img,!ImgMasks,!ImgSpans,!GridSpans)
// only for testing purposes:
//dummyTextSpans :: ImgTexts -> TextSpans
definition module Graphics.Scalable.Internal.Image`
from Data.Maybe import :: Maybe
from Data.Set import :: Set
from Data.Map import :: Map
from Data.Error import :: MaybeError (..)
from Math.Geometry import :: Angle
from StdOverloaded import class zero (..), class + (..), class - (..), class ~ (..), class sign (..),
class abs (..), class < (..), class == (..), class toReal (..), class / (..), class * (..)
import Graphics.Scalable.Types
import Graphics.Scalable.Internal.Types
:: Image` m
= Empty` !Span !Span
| Circle` !Span
| Ellipse` !Span !Span
| Square` !Span
| Rect` !Span !Span
| Polyline` ![ImageSpan]
| Polygon` ![ImageSpan]
| Text` !FontDef !String
| Rotate` !Angle !(Image` m)
| Flipx` !(Image` m)
| Flipy` !(Image` m)
| Fit` !Span !Span !(Image` m)
| Fitx` !Span !(Image` m)
| Fity` !Span !(Image` m)
| Scale` !Real !Real !(Image` m)
| Skewx` !Angle !(Image` m)
| Skewy` !Angle !(Image` m)
| Attr` !(ImageAttr` m) !(Image` m)
| Margin` !Margins` !(Image` m)
| Tag` !ImageTag !(Image` m)
| Overlay` ![XYAlign] ![ImageOffset] ![Image` m] !(Host` m)
| Grid` !GridDimension !GridLayout ![XYAlign] ![Span] ![Span] ![ImageOffset] ![Image` m] !(Host` m)
:: ImageAttr` m
= BasicImageAttr` !BasicImgAttr
| LineMarkerAttr` !(LineMarkerAttr m)
| MaskAttr` !(Image` m)
| HandlerAttr` !(ImgEventhandler m)
:: ImgTables m
= { imgEventhandlers :: !ImgEventhandlers m
, imgNewFonts :: !ImgFonts
, imgNewTexts :: !ImgTexts
, imgMasks :: !ImgMasks
, imgLineMarkers :: !ImgLineMarkers
, imgPaths :: !ImgPaths
, imgSpans :: !ImgSpans
, imgGrids :: !GridSpans
, imgTags :: !ImgTags
, imgUniqIds :: !ImgTagNo
}
:: FontSpans :== Map FontDef FontDescent // of each font, the font descent
:: ImgFonts :== Set FontDef // the collection of fonts used in the image for which no metrics are available
:: TextSpans :== Map FontDef (Map String TextSpan) // of each font, of each text of that font, the width
:: ImgEventhandlers m :== Map ImgTagNo [ImgEventhandler m] // the registered event handlers of the image identified by the id (once registered, an event handler can not be overruled)
:: ImgTexts :== Map FontDef (Set String) // of each font, the collection of texts
:: ImgMasks :== Map ImgTagNo Img // of each mask, the mask-image (associate the id with (MaskImg id))
:: ImgLineMarkers :== Map ImgTagNo LineMarkers // of each poly(gon/line) with markers, its markers
:: ImgPaths :== Map ImgTagNo ImgPath // of each poly(gon/line), initially its connecting points, and secondly, its span
:: ImgSpans :== Map ImgTagNo ImageSpan // of each image, its (width,height)
:: GridSpans :== Map ImgTagNo GridSpan // of each grid, the spans of its columns and the spans of its rows
:: ImgTags :== Map ImageTag ImgTagNo // map user-tag to system number
:: FontDescent :== Real
:: TextSpan :== Real
:: ImgEventhandler m
= ImgEventhandlerOnClickAttr !(OnClickAttr m)
| ImgEventhandlerOnMouseDownAttr !(OnMouseDownAttr m)
| ImgEventhandlerOnMouseUpAttr !(OnMouseUpAttr m)
| ImgEventhandlerOnMouseOverAttr !(OnMouseOverAttr m)
| ImgEventhandlerOnMouseMoveAttr !(OnMouseMoveAttr m)
| ImgEventhandlerOnMouseOutAttr !(OnMouseOutAttr m)
| ImgEventhandlerDraggableAttr !(DraggableAttr m)
:: ImgPath
= { pathPoints :: ![ImageOffset] // the connecting points of the path
, pathSpan :: !ImageSpan // the span of the path (also stored in imgSpans after resolving span-expressions)
}
:: LineMarkers
= { lineStart :: !Maybe Img
, lineMid :: !Maybe Img
, lineEnd :: !Maybe Img
}
:: GridSpan
= { col_spans :: ![Span]
, row_spans :: ![Span]
}
:: Img
= { uniqId :: !ImgTagNo // the unique system identification within the entire image
, host :: !HostImg // the host of this image
, transform :: !Maybe ImgTransform // the optional transform of the basic/composite image
, overlays :: ![Img] // the back-to-front ordering of images 'on top of' host
, offsets :: ![ImageOffset] // the offsets matching one-by-one with .overlays
}
:: HostImg
= BasicHostImg !BasicImg !(Set BasicImgAttr)
| RawHostImg !String
| CompositeImg !Img
:: BasicImg
= EmptyImg
| TextImg !FontDef !String
| CircleImg
| RectImg
| EllipseImg
| PolylineImg
| PolygonImg
:: BasicImgAttr // attributes that are applicable only on basic images
= BasicImgDashAttr ![Int]
| BasicImgFillAttr !SVGColor
| BasicImgFillOpacityAttr !Real
| BasicImgStrokeAttr !SVGColor
| BasicImgStrokeOpacityAttr !Real
| BasicImgStrokeWidthAttr !Span
| BasicImgXRadiusAttr !Span
| BasicImgYRadiusAttr !Span
:: LineMarkerAttr m
= { markerImg :: !Image` m
, markerPos :: !LineMarkerPos
}
:: ImgTransform
= RotateImg !Angle
| SkewXImg !Angle
| SkewYImg !Angle
| FitImg !Span !Span
| FitXImg !Span
| FitYImg !Span
| ScaleImg !Real !Real
| FlipXImg
| FlipYImg
| MaskImg !ImgTagNo // the id-img pair is stored in the ImgMasks table
:: Host` m
= NoHost`
| Host` (Image` m)
:: Markers` m
= { markerStart` :: !Maybe (Image` m)
, markerMid` :: !Maybe (Image` m)
, markerEnd` :: !Maybe (Image` m)
}
defaultMarkers` :: Markers` m
defaultLineMarkers :: LineMarkers
:: Margins`
= { n :: !Span, e :: !Span, s :: !Span, w :: !Span }
defaultMargins` :: Margins`
toImg :: !(Image` m) !FontSpans !TextSpans !(ImgTables m) -> (!Img,!ImgTables m)
:: SpanResolveError :== String
resolve_all_spans :: !ImgTags !FontSpans !TextSpans !Img !ImgMasks !ImgLineMarkers !ImgPaths !ImgSpans !GridSpans
-> MaybeError SpanResolveError (!Img,!ImgMasks,!ImgLineMarkers,!ImgPaths,!ImgSpans,!GridSpans)
definition module Graphics.Scalable.Internal.Types
import Graphics.Scalable.Types
:: Span
= PxSpan !Real // (PxSpan a) is a pixels
| LookupSpan !LookupSpan // (LookupSpan a) needs to be looked up after computing dimensions
| AddSpan !Span !Span // (AddSpan a b) is span a + span b
| SubSpan !Span !Span // (SubSpan a b) is span a - span b
| MulSpan !Span !Span // (MulSpan a b) is span a * span k
| DivSpan !Span !Span // (DivSpan a b) is span a / span k
| AbsSpan !Span // (AbsSpan a) is absolute value of span a
| MinSpan ![Span] // (MinSpan as) is minimum span value in as
| MaxSpan ![Span] // (MaxSpan as) is maximum span value in as
:: LookupSpan
= ColumnXSpan !ImageTag !Int // (ColumnXSpan t a) is x-span of column number a in grid tagged with t
| RowYSpan !ImageTag !Int // (RowYSpan t a) is y-span of row number a in grid tagged with t
| ImageXSpan !ImageTag // (ImageXSpan t) is x-span of image tagged with t
| ImageYSpan !ImageTag // (ImageYSpan t) is y-span of image tagged with t
| TextXSpan !FontDef !String // (TextXSpan a b) is width of text b written in font a
| PathXSpan !ImageTag // (PathXSpan t) is x-span of path element tagged with t
| PathYSpan !ImageTag // (PathYSpan t) is y-span of path element tagged with t
class (*.) infixl 7 a :: !a !n -> Span | toReal n
class (/.) infixl 7 a :: !a !n -> Span | toReal n
instance zero Span
instance + Span
instance - Span
instance abs Span
instance ~ Span
instance *. Span, Real, Int
instance * Span
instance /. Span, Real, Int
instance / Span
isPxSpan :: !Span -> Bool // returns True only if argument is (PxSpan ...)
getPxSpan :: !Span -> Real // returns r only if argument is (PxSpan r), aborts otherwise
px :: !Real -> Span // (px r) is r pixels
textxspan :: !FontDef !String -> Span // (textxspan font str) is the x-span of str written in font
imagexspan :: !ImageTag -> Span // (imagexspan t) is x-span of image tagged with t
imageyspan :: !ImageTag -> Span // (imageyspan t) is y-span of image tagged with t
columnspan :: !ImageTag !Int -> Span // (columnspan t i) is x-span of column i (counting from 0) in grid tagged with t
rowspan :: !ImageTag !Int -> Span // (rowspan t i) is y-span of row i (counting from 0) in grid tagged with t
minSpan :: ![Span] -> Span // (minSpan as) is the minimum of as (zero if as = [])
maxSpan :: ![Span] -> Span // (maxSpan as) is the maximum of as (zero if as = [])
:: ImageTag
= ImageTagUser !ImgTagNo !String
| ImageTagSystem !ImgTagNo
:: ImgTagNo :== Int // internal numbering of (sub) images
instance == ImageTag
instance < ImageTag
definition module Graphics.Scalable.Types
from Data.Maybe import :: Maybe (..)
from Data.Set import :: Set
from Text.HTML import :: SVGColor
from StdOverloaded import class zero (..), class + (..), class - (..), class ~ (..), class sign (..),
class abs (..), class < (..), class == (..), class toReal (..), class / (..), class * (..)
from Graphics.Scalable.Internal.Types import
:: Span, class *. (..), class /. (..), instance zero Span, instance + Span, instance - Span, instance * Span, instance / Span,
instance abs Span, instance ~ Span, instance *. Span, instance *. Real, instance *. Int,
instance /. Span, instance /. Real, instance /. Int,
px, textxspan, imagexspan, imageyspan, columnspan, rowspan, minSpan, maxSpan,
:: ImageTag, instance == ImageTag, instance < ImageTag
:: ImageSpan :== (!Span, !Span)
:: ImageOffset :== (!Span, !Span)
:: FontDef
= { fontfamily :: !String
, fontysize :: !Real
, fontstretch :: !String
, fontstyle :: !String
, fontvariant :: !String
, fontweight :: !String
}
normalFontDef :: !String !Real -> FontDef // (normalFontDef family size) sets all other fields to "normal"
instance == FontDef
instance < FontDef
instance toString FontDef
:: LineMarkerPos
= LineMarkerEnd
| LineMarkerMid
| LineMarkerStart
instance == LineMarkerPos
:: *TagSource :== *[TagRef]
:: *TagRef :== *(!ImageTag, !*ImageTag)
:: GridDimension = Rows !Int | Columns !Int
:: GridLayout :== (!GridMajor, !GridXLayout, !GridYLayout)
:: GridMajor = ColumnMajor | RowMajor
:: GridXLayout = LeftToRight | RightToLeft
:: GridYLayout = TopToBottom | BottomToTop
:: XAlign = AtLeft | AtMiddleX | AtRight
:: YAlign = AtTop | AtMiddleY | AtBottom
:: XYAlign :== (!XAlign, !YAlign)
:: OnClickAttr m = { onclick :: !(Int m -> m), local :: !Bool }
:: OnMouseDownAttr m = { onmousedown :: !(m -> m), local :: !Bool }
:: OnMouseUpAttr m = { onmouseup :: !(m -> m), local :: !Bool }
:: OnMouseOverAttr m = { onmouseover :: !(m -> m), local :: !Bool }
:: OnMouseMoveAttr m = { onmousemove :: !(m -> m), local :: !Bool }
:: OnMouseOutAttr m = { onmouseout :: !(m -> m), local :: !Bool }
:: DraggableAttr m = { draggable :: !(SVGDragFun m) }
:: SVGDragFun m :== (Set ImageTag) (Real,Real) m -> m // \tags (x,y) model: tags is the set of ImageTag-s associated with the 'dragged-on' image, (x,y) the location within that image
:: RGB = { r :: !Int, g :: !Int, b :: !Int }
class toSVGColor a :: !a -> SVGColor
instance toSVGColor String, RGB
instance zero RGB
implementation module Graphics.Scalable.Types
import Data.Maybe
import Data.List
from Text.HTML import :: SVGColor (..)
from Data.Set import :: Set, instance == (Set a), instance < (Set a)
import StdBool, StdInt, StdReal, StdString
import Graphics.Scalable.Internal.Types
normalFontDef :: !String !Real -> FontDef // (normalFontDef family size) sets all other fields to "normal"
normalFontDef family size
= {fontfamily = family, fontysize = size, fontstretch = "normal", fontstyle = "normal", fontvariant = "normal", fontweight = "normal"}
instance == FontDef where == fd1 fd2 = fd1 === fd2
instance < FontDef where < fd1 fd2 = fd1.fontfamily < fd2.fontfamily
|| fd1.fontysize < fd2.fontysize
|| fd1.fontstretch < fd2.fontstretch
|| fd1.fontstyle < fd2.fontstyle
|| fd1.fontvariant < fd2.fontvariant
|| fd1.fontweight < fd2.fontweight