DRAW TEXT ON THE CANVAS

Drawing canvas text combines the capabilities of CSS fonts with the fill and stroke procedures described earlier in this chapter. Essentially, your font is defined using the same syntax as the CSS font property; this includes the ability to take advantage of @font-face, new in CSS3 and described in Chapter 4, “Styling with CSS3.” The text itself creates a path that can either be filled or stroked.

Start by specifying the font the text will be drawn as:

context.font = 'font-style font-variant font-weight font-size font-family';

All font values are order specific, although not all are required. At a minimum, you must specify font-size and font-family values to properly set a canvas font. All values use the same syntax ...

Get HTML5: Your visual blueprint™ for designing rich web pages and applications now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.