[Ur] UrWeb SVG inclusion trial, needs revision

Gabriel Riba gabriel at xarxaire.com
Thu Mar 12 15:56:00 EDT 2015


Since HTML5 admits an SVG tag as html to enclose vector graphics tags,

I have tried to add some types to ensure that they are properly enclosed 
by an svg html tag, mimicking other types in Basis.urs.

I have succeeded in the goal, but It probably can be done better.

There is a quirk, since SVG can be an html level tag but also an inner 
svg fragment container, but I have not treated this case.

(* -- file SVG.urs *)

con svg = [Svg]
con xsvg = xml svg [] []

con svgTagAttrs = [X = string, Y = string, Width = string,
                    Height = string,
                    ViewBox = string, PreserveAspectRatio = string,
                    ZoomAndPan = string] ++ boxAttrs

val svg : unit -> tag svgTagAttrs body svg [] []

con svgTag = fn (attrs :: {Type}) =>
         ctx ::: {Unit} ->
         [[Svg] ~ ctx] =>
         unit -> tag attrs ([Svg] ++ ctx) ([Svg] ++ ctx) [] []

(*** SVG Events *)

con graphicsElementsEvents = focusEvents ++ mouseEvents
con docEvents = resizeEvents ++ scrollEvents

(*** SVG Attrs *)

con commonAttrs = [Id = id, Base = string]
con langSpaceAttrs = [Lang = string, Space= string]
con transformAttrs = [Transform = string]
con testAttrs = [RequiredFeatures = string, RequiredExtensions = string,
                  SystemLanguage = string]

con typicalAttrs = commonAttrs ++ langSpaceAttrs ++ transformAttrs ++
                    testAttrs ++ graphicsElementsEvents

(*** SVG tags *)

val path : svgTag ([D = string, PathLength = string] ++ typicalAttrs)
val text : svgTag ([X = string, Y = string, Dx = string, Dy = string,
                     Rotate = string, TextLength = string,
                     LengthAdjust = string] ++ typicalAttrs)

(* ------------------- *)
(* -- project file *)

html5
rewrite url SVGTest/main
ffi SVG

$/list
$/string
SVGTest

(* ------------------- *)
(* -- test program added as attachment *)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SVGTest.tar.gz
Type: application/x-gzip
Size: 1296 bytes
Desc: not available
URL: <http://www.impredicative.com/pipermail/ur/attachments/20150312/9ffe57f5/attachment.bin>


More information about the Ur mailing list