Closed joelburget closed 10 years ago
That's brilliant, thanks a lot!
This also requires adding the 'measureText' FFI to the ghcjs-canvas, right?
Is this the implementation you had in mind?
measureText :: Text -> Context -> IO Double
measureText t ctx = js_measureText (toJSString t) ctx
>>= getProp "width"
>>= liftM fromJust . fromJSRef
{-# INLINE measureText #-}
foreign import javascript unsafe "$2.measureText($1)"
js_measureText :: JSString -> Context -> IO (JSRef a)
Oops, forgot I made this change as well!
That's essentially what I had, though I had the width
selection in Javascript rather than Haskell.
measureText :: Text -> Context -> IO Double
measureText t ctx = js_measureText (toJSString t) ctx
foreign import javascript unsafe "$2.measureText($1).width"
js_measureText :: JSString -> Context -> IO Double
Preview. Oops, looks like the images are missing at the moment, but you should still be able to see the rendered text.