30.07.2013 Views

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 16 Graphics and Multimedia 697<br />

<strong>Program</strong>mers can define precise information about a font’s metrics (or properties), such<br />

as height, descent (the amount that characters dip below the baseline), ascent (the amount<br />

that characters rise above the baseline) and leading (the difference between the ascent of one<br />

line and the decent of the previous line). Figure 16.10 illustrates these properties.<br />

Class FontFamily defines characteristics common <strong>to</strong> a group of related fonts. Class<br />

FontFamily provides several methods used <strong>to</strong> determine the font metrics that are shared<br />

by members of a particular family. These methods are summarized in Fig. 16.11.<br />

The program shown in Fig. 16.12 calls method ToString <strong>to</strong> display the metrics of<br />

two fonts. Line 21 creates Font arial and sets it <strong>to</strong> 12-point Arial font. Line 22 uses<br />

class Font property FontFamily <strong>to</strong> obtain object arial’s FontFamily object. Lines<br />

30–31 call ToString <strong>to</strong> output the String representation of the font. Lines 33–47 then<br />

use methods of class FontFamily <strong>to</strong> return integers specifying the ascent, descent, height<br />

and leading of the font. Lines 50–67 repeat this process for font sansSerif, a Font<br />

object derived from the MS Sans Serif FontFamily.<br />

height xy1Õ<br />

Fig. 16.10 An illustration of font metrics.<br />

Method Description<br />

GetCellAscent Returns an Integer representing the ascent of a font as measured<br />

in design units.<br />

GetCellDescent Returns an Integer representing the descent of a font as measured<br />

in design units.<br />

GetEmHeight Returns an Integer representing the height of a font as measured<br />

in design points.<br />

GetLineSpacing Returns an Integer representing the distance between two consecutive<br />

lines of text as measured in design units.<br />

Fig. 16.11 FontFamily methods that return font-metrics information.<br />

1 ' Fig. 16.12: UsingFontMetrics.vb<br />

2 ' Displaying font metric information.<br />

3<br />

4 Imports System<br />

5 Imports System.Drawing<br />

6 Imports System.Drawing.Text<br />

leading<br />

ascent<br />

baseline<br />

descent<br />

Fig. 16.12 FontFamily class used <strong>to</strong> obtain font-metric information (part 1 of 3).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!