fillText and strokeText
The context.fillText()
function (as shown in Figure 3-1) will
render solid-colored text to the canvas. The color used is set in the
context.fillColor property. The font
used is set in the context.font
property. The function call looks like this:
fillText([text],[x],[y],[maxWidth]);
where:
textThe text to render on the canvas.
xThe
xposition of the text on the canvas.yThe
yposition of the text on the canvas.maxWidthThe maximum width of the text as rendered on the canvas. At the time of this writing, support for this property was just being added to browsers.

Figure 3-1. fillText in action
The context.strokeText()
function (as shown in Figure 3-2) is similar, but it
specifies the outline of text strokes to the canvas. The color used to
render the stroke is set in the context.strokeColor property; the font used is
set in the context.font property. The
function call looks like:
strokeText([text],[x],[y],[maxWidth])
where:
textThe text to render on the canvas.
xThe
xposition of the text on the canvas.yThe
yposition of the text on the canvas.maxWidthThe maximum width of the text as rendered on the canvas. At the time of this writing, this property does not appear to be implemented in any browsers.

Figure 3-2. strokeText setting outline properties
The next iteration of Text ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access