Skip to content

Commit 6b66275

Browse files
author
Chris Waterson
committed
add methods for dealing with text.
1 parent b9a2129 commit 6b66275

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

src/Graphics/Canvas.purs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,66 @@ foreign import transform
376376
\ };\
377377
\}" :: forall eff. Transform -> Context2D -> Eff (canvas :: Canvas | eff) Context2D
378378

379+
-- |
380+
-- Text
381+
--
382+
383+
type TextMetrics = { width :: Number }
384+
385+
foreign import font
386+
"function font(ctx) {\
387+
\ return function() {\
388+
\ return ctx.font;\
389+
\ };\
390+
\}" :: forall eff. Context2D -> Eff (canvas :: Canvas | eff) String
391+
392+
foreign import setFont
393+
"function setFont(fontspec) {\
394+
\ return function(ctx) {\
395+
\ return function() {\
396+
\ ctx.font = fontspec;\
397+
\ return ctx;\
398+
\ };\
399+
\ };\
400+
\}" :: forall eff. String -> Context2D -> Eff (canvas :: Canvas | eff) Context2D
401+
402+
foreign import fillText
403+
"function fillText(ctx) {\
404+
\ return function(text) {\
405+
\ return function(x) {\
406+
\ return function(y) {\
407+
\ return function() {\
408+
\ ctx.fillText(text, x, y);\
409+
\ return ctx;\
410+
\ };\
411+
\ };\
412+
\ };\
413+
\ };\
414+
\}" :: forall eff. Context2D -> String -> Number -> Number -> Eff (canvas :: Canvas | eff) Context2D
415+
416+
foreign import strokeText
417+
"function strokeText(ctx) {\
418+
\ return function(text) {\
419+
\ return function(x) {\
420+
\ return function(y) {\
421+
\ return function() {\
422+
\ ctx.fillText(text, x, y);\
423+
\ return ctx;\
424+
\ };\
425+
\ };\
426+
\ };\
427+
\ };\
428+
\}" :: forall eff. Context2D -> String -> Number -> Number -> Eff (canvas :: Canvas | eff) Context2D
429+
430+
foreign import measureText
431+
"function measureText(ctx) {\
432+
\ return function(text) {\
433+
\ return function() {\
434+
\ return ctx.measureText(text);\
435+
\ };\
436+
\ };\
437+
\}" :: forall eff. Context2D -> String -> Eff (canvas :: Canvas | eff) TextMetrics
438+
379439
-- |
380440
-- Context
381441
--

0 commit comments

Comments
 (0)