Java's font model
Java's font model is very simple (compared to that used by,
for example, a typographer).
A font is specified completely by its
- typeface name — e.g., 'roman', 'helvetica'
- style — plain, bold, italic
- size
In Java, fonts are objects of Font class. Creating a new font consists simply of creating a new object
of class Font, specifying the typeface name, style and size.
The unit of size of text is the point. A 'point' is
technically 1/72 of an imperial inch, so a 32-point font has characters that are nominally
one half an inch high. In reality the situation is more complicated than this, but since
the characters that will displayed depend on the screen size anyway, there's no point in
being more accurate.
Note that when drawing text using Graphics.drawString(), the co-ordinates given denote the left-hand end of the baseline of the text.
The baseline is the lowest point of most of the letters (like ‘ a’ , ‘
b’ , ‘ c’ ). Some letters (like ‘ q’ ) extend below the baseline;
you will need to take this into account when positioning text on the screen. For example,
if a program executes the line
g.drawString("abcdefg",
0, 0);
all that will be visible on the screen is the
tail of the letter ‘g'.
Back to
top

RITSEC - Global Campus
Copyright ?1999 RITSEC- Middlesex University. All rights reserved.
webmaster@globalcampus.com.eg
|