W3C HTML 工作组公布了HTML 5工作草案的10项更新,其中
HTML Canvas的2D元素 HTML Canvas 2D Context
草案里新增了绘制文字的接口,这是非常值得期待的功能,canvas可以图文并茂了,在游戏、图表都是常用的情景
10 Drawing text to the canvas
-
context .
-
Fills or strokes (respectively) the given text at the given position. If a maximum width is provided, the text will be scaled to fit that width if necessary.
metrics =
context .
-
Returns a
TextMetrics
object with the metrics of the given text in the current font.
metrics .
-
Returns the advance width of the text that was passed to the
measureText()
method.
fillText
(
text,
x,
y [,
maxWidth ] )
context .
strokeText
(
text,
x,
y [,
maxWidth ] )
measureText
(
text)
width