Java Reference
In-Depth Information
CENA
. . .
with many more font names in the list.
How It Works
You first get a Toolkit object by calling the static method getDefaultToolkit() — this is the key
to the other information. The getScreenResolution() method returns the number of pixels per inch as
a value of type int . The getScreenSize() method returns a Dimension object that specifies the width
and height of the screen in pixels.
You use the getAvailableFontFamilyNames() method to get a String array containing the names of
the fonts, which you output to the console.
Font Metrics
Every component has a getFontMetrics() method that you can use to retrieve font metrics — a wealth of
dimensional data about a font. You pass a Font object as an argument to the method, and it returns an object
of type FontMetrics that you can use to obtain data relating to the particular font. For example, if aWindow
is a Frame object and myFont is a Font object, you could obtain a FontMetrics object corresponding to the
font with the following statement:
FontMetrics metrics = aWindow.getFontMetrics(myFont);
You could use the getFont() method for a component to explore the characteristics of the font that the
component contains. For example:
FontMetrics metrics = aWindow.getFontMetrics(aWindow.getFont());
You can now call any of the following FontMetrics methods for the object to get at the basic dimensions
of the font:
int getAscent() : Returns the ascent of the font, which is the distance from the baseline to the
top of the majority of the characters in the font. The baseline is the line on which the characters
rest. Depending on the font, some characters can extend beyond the ascent.
int getMaxAscent() : Returns the maximum ascent for the font. No character exceeds this ascent.
int getDescent() : Returns the descent of the font, which is the distance from the baseline to the
bottom of most of the font characters that extend below the baseline. Depending on the font, some
characters may extend beyond the descent for the font.
int getMaxDescent() : Returns the maximum descent of the characters in the font. No character
exceeds this descent.
int getLeading() : Returns the leading for the font, which is the line spacing for the font — that
is the spacing between the bottom of one line of text and the top of the next. The term originated
when type was actually made of lead, and there was a strip of lead between one line of type and
the next when a page was typeset.
int getHeight() : Returns the height of the font, which is defined as the sum of the ascent, the
descent, and the leading.
Search WWH ::




Custom Search