CONTENTS | PREV | NEXT | Java 2D API |
Using the Font.deriveFont methods, you can create a new Font object with different attributes from an existing Font object. Often, a transform is applied to the existing Font to create a new derived Font. To do this, you would:
In this way, you could easily create a Font in a custom size or a skewed version of an existing Font.In the following code excerpt, an AffineTransform is applied to create a skewed version of the font Helvetica. The new derived font is then used to render a string.
// Create a transformation for the font.
AffineTransform fontAT = new AffineTransform();
fontAT.setToShear(-1.2, 0.0);
// Create a Font Object.
Font theFont = new Font("Helvetica", Font.PLAIN, 1);
// Derive a new font using the shear transform
theDerivedFont = theFont.deriveFont(fontAT);
// Create a StyledString object, specifying the text and the
// skewed font.
ss = new StyledString("Java", theDerivedFont);
// Render the string
g2.drawString(ss, 0.0f, 0.0f);