0 | module Web.Canvas.Scene
 1 |
 2 | import Data.Linear.Token
 3 | import Web.Canvas.Hints
 4 | import Web.Canvas.Shape
 5 | import Web.Canvas.Style
 6 | import Web.Canvas.Transformation
 7 | import Web.Internal.HtmlPrim
 8 |
 9 | %default total
10 |
11 | --------------------------------------------------------------------------------
12 | --          Text Metrics
13 | --------------------------------------------------------------------------------
14 |
15 | export
16 | %foreign "browser:lambda:x=>x.actualBoundingBoxAscent"
17 | actualBoundingBoxAscent : TextMetrics -> Double
18 |
19 | export
20 | %foreign "browser:lambda:x=>x.actualBoundingBoxDescent"
21 | actualBoundingBoxDescent : TextMetrics -> Double
22 |
23 | export
24 | %foreign "browser:lambda:x=>x.actualBoundingBoxLeft"
25 | actualBoundingBoxLeft : TextMetrics -> Double
26 |
27 | export
28 | %foreign "browser:lambda:x=>x.actualBoundingBoxRight"
29 | actualBoundingBoxRight : TextMetrics -> Double
30 |
31 | export
32 | %foreign "browser:lambda:x=>x.alphabeticBaseline"
33 | alphabeticBaseline : TextMetrics -> Double
34 |
35 | export
36 | %foreign "browser:lambda:x=>x.emHeightAscent"
37 | emHeightAscent : TextMetrics -> Double
38 |
39 | export
40 | %foreign "browser:lambda:x=>x.emHeightDescent"
41 | emHeightDescent : TextMetrics -> Double
42 |
43 | export
44 | %foreign "browser:lambda:x=>x.fontBoundingBoxAscent"
45 | fontBoundingBoxAscent : TextMetrics -> Double
46 |
47 | export
48 | %foreign "browser:lambda:x=>x.fontBoundingBoxDescent"
49 | fontBoundingBoxDescent : TextMetrics -> Double
50 |
51 | export
52 | %foreign "browser:lambda:x=>x.hangingBaseline"
53 | hangingBaseline : TextMetrics -> Double
54 |
55 | export
56 | %foreign "browser:lambda:x=>x.ideographicBaseline"
57 | ideographicBaseline : TextMetrics -> Double
58 |
59 | export
60 | %foreign "browser:lambda:x=>x.width"
61 | width : TextMetrics -> Double
62 |
63 | %foreign "browser:lambda:(c,d,a,b,f,s,w)=>{d0 = c.direction; b0 = c.textBaseline; a0 = c.textAlign; f0 = c.font; c.font = f; c.direction = d; c.textBaseline = b; c.textAlign = a; res = c.measureText(s); c.font = f0; c.direction = d0; c.textBaseline = b0; c.textAlign = a0; return res}"
64 | prim__measureText :
65 |      CanvasText
66 |   -> (dir, align, baseline, font, text : String)
67 |   -> PrimIO TextMetrics
68 |
69 | ||| Compute the `TextMetrics` for the given text in the given font.
70 | export %inline
71 | measureText :
72 |      {auto ct : CanvasText}
73 |   -> CanvasDirection
74 |   -> CanvasTextAlign
75 |   -> CanvasTextBaseline
76 |   -> (font,text : String)
77 |   -> IO1 TextMetrics
78 | measureText d a b f t = ffi $ prim__measureText ct (toFFI d) (toFFI a) (toFFI b) f t
79 |
80 | parameters {auto cs : CanvasState}
81 |   export %inline
82 |   save : IO1 ()
83 |   save = ffi $ prim__save cs
84 |
85 |   export %inline
86 |   restore : IO1 ()
87 |   restore = ffi $ prim__restore cs
88 |