Java Reference
In-Depth Information
16
frame.setSize(
420
,
150
);
17
frame.setVisible(
true
);
18
}
19
}
// end class Fonts
Fig. 13.12
|
Using fonts. (Part 2 of 2.)
Font Metrics
Sometimes it's necessary to get information about the current drawing font, such as its
name, style and size. Several
Font
methods used to get font information are summarized
in Fig. 13.10. Method
getStyle
returns an integer value representing the current style.
The integer value returned is either
Font.PLAIN
,
Font.ITALIC
,
Font.BOLD
or the combi-
nation of
Font.ITALIC
and
Font.BOLD
. Method
getFamily
returns the name of the font
family to which the current font belongs. The name of the font family is platform specific.
Font
methods are also available to test the style of the current font, and these too are sum-
marized in Fig. 13.10. Methods
isPlain
,
isBold
and
isItalic
return
true
if the current
font style is plain, bold or italic, respectively.
Figure 13.13 illustrates some of the common
font metrics
, which provide precise
information about a font, such as
height
,
descent
(the amount a character dips below the
baseline),
ascent
(the amount a character rises above the baseline) and
leading
(the differ-
ence between the descent of one line of text and the ascent of the line of text below it—
that is, the interline spacing).
leading
height
ascent
baseline
descent
Fig. 13.13
|
Font metrics.
Class
FontMetrics
declares several methods for obtaining font metrics. These
methods and
Graphics
method
getFontMetrics
are summarized in Fig. 13.14. The
application of Figs. 13.15-13.16 uses the methods of Fig. 13.14 to obtain font metric
information for two fonts.