Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 3. Text > 3.2. Setting Font Properties

3.2. Setting Font Properties

You can set the font of the text that you draw in a canvas with the context’s font property, which is a CSS3 font string consisting of the components in Table 3.1. From top to bottom, the font components in the table are listed in the order you use them for the context’s font property.

Table 3.1. Components of the font property

image

The default Canvas font is 10px sans-serif. The default values for font-style, font-variant, and font-weight are all normal.

Figure 3.4 shows an application that fills text with different fonts.

image

Figure 3.4. Specifying fonts

The strings in the application were generated by setting the context’s font property and subsequently printing that property using the context’s fillText() method.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint