616 Graphics and Java2D Chapter 11 Portability Tip (Space web hosting)

616 Graphics and Java2D Chapter 11 Portability Tip 11.3 Java provides several standardized font names and maps these into system-specific font names for portability. This is transparent to the programmer. Font methods are also available to test the style of the current font and are summarized in Fig. 11.8. The isPlain method returns true if the current font style is plain. The isBold method returns true if the current font style is bold. The isItalic method returns trueif the current font style is italic. Sometimes precise information about a font s metrics must be known such as height, descent (the amount a character dips below the baseline), ascent (the amount a character rises above the baseline) and leading (the difference between the descent of one line of text and the ascent of the line of text below it i.e., the interline spacing). Figure 11.10 illustrates some of the common font metrics. Note that the coordinate passed to drawString corresponds to the lower-left corner of the baseline of the font. Class FontMetrics defines several methods for obtaining font metrics. These methods and Graphics method getFontMetricsare summarized in Fig. 11.11. leading height ascent Xy1 baseline descent Fig. 11.10 Font metrics. Method Description public int getAscent() // FontMetrics class Returns a value representing the ascent of a font in points. public int getDescent() // FontMetrics class Returns a value representing the descent of a font in points. public int getLeading() // FontMetrics class Returns a value representing the leading of a font in points. public int getHeight() // FontMetrics class Returns a value representing the height of a font in points. public FontMetrics getFontMetrics() // Graphics class Returns the FontMetricsobject for the current drawing Font. public FontMetrics getFontMetrics( Font f ) // Graphics class Returns the FontMetricsobject for the specified Fontargument. Fig. 11.11 FontMetricsand Graphicsmethods for obtaining font metrics. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01

Leave a Reply