@@ -17,6 +17,7 @@ module Graphics.Canvas
17
17
, Transform
18
18
, TranslateTransform
19
19
, TextAlign (..)
20
+ , TextBaseline (..)
20
21
, CanvasPattern
21
22
, PatternRepeat (..)
22
23
, CanvasGradient
@@ -75,6 +76,8 @@ module Graphics.Canvas
75
76
76
77
, textAlign
77
78
, setTextAlign
79
+ , textBaseline
80
+ , setTextBaseline
78
81
, font
79
82
, setFont
80
83
, fillText
@@ -527,6 +530,53 @@ setTextAlign ctx textalign =
527
530
toString AlignStart = " start"
528
531
toString AlignEnd = " end"
529
532
533
+ -- | Enumerates types of text baseline.
534
+ data TextBaseline
535
+ = BaselineTop
536
+ | BaselineHanging
537
+ | BaselineMiddle
538
+ | BaselineAlphabetic
539
+ | BaselineIdeographic
540
+ | BaselineBottom
541
+
542
+ instance showTextBaseline :: Show TextBaseline where
543
+ show BaselineTop = " BaselineTop"
544
+ show BaselineHanging = " BaselineHanging"
545
+ show BaselineMiddle = " BaselineMiddle"
546
+ show BaselineAlphabetic = " BaselineAlphabetic"
547
+ show BaselineIdeographic = " BaselineIdeographic"
548
+ show BaselineBottom = " BaselineBottom"
549
+
550
+ foreign import textBaselineImpl :: Context2D -> Effect String
551
+
552
+ -- | Get the current text baseline.
553
+ textBaseline :: Context2D -> Effect TextBaseline
554
+ textBaseline ctx = unsafeParseTextBaseline <$> textBaselineImpl ctx
555
+ where
556
+ unsafeParseTextBaseline :: String -> TextBaseline
557
+ unsafeParseTextBaseline " top" = BaselineTop
558
+ unsafeParseTextBaseline " hanging" = BaselineHanging
559
+ unsafeParseTextBaseline " middle" = BaselineMiddle
560
+ unsafeParseTextBaseline " alphabetic" = BaselineAlphabetic
561
+ unsafeParseTextBaseline " ideographic" = BaselineIdeographic
562
+ unsafeParseTextBaseline " bottom" = BaselineBottom
563
+ unsafeParseTextBaseline align = unsafeThrow $ " invalid TextBaseline: " <> align
564
+ -- ^ dummy to silence compiler warnings
565
+
566
+ foreign import setTextBaselineImpl :: Context2D -> String -> Effect Unit
567
+
568
+ -- | Set the current text baseline.
569
+ setTextBaseline :: Context2D -> TextBaseline -> Effect Unit
570
+ setTextBaseline ctx textbaseline =
571
+ setTextBaselineImpl ctx (toString textbaseline)
572
+ where
573
+ toString BaselineTop = " top"
574
+ toString BaselineHanging = " hanging"
575
+ toString BaselineMiddle = " middle"
576
+ toString BaselineAlphabetic = " alphabetic"
577
+ toString BaselineIdeographic = " ideographic"
578
+ toString BaselineBottom = " bottom"
579
+
530
580
-- | Text metrics:
531
581
-- |
532
582
-- | - The text width in pixels.
0 commit comments