Drawing text
There are two methods available to draw text on the canvas: strokeText()
and fillText()
. strokeText()
draws outlined text using the current lineWidth
and strokeStyle
, while fillText()
draws with the current fillStyle
. Both take the same parameters; the text to draw, and the x and y coordinates. The context object has a global font property to define which font
to use. You set its value the same you would when defining a font in CSS. Continuing where we left off in the previous chapter with our Canvas Pad application, we will add a new text drawing tool. You can find the source code for this section in Chapter 5/example5.1
.