All Packages Class Hierarchy This Package Previous Next Index
Class java.awt.Font
java.lang.Object
|
+----java.awt.Font
- public class Font
- extends Object
- implements Serializable
This class represents fonts. The capabilities of this class have been
extended over the java.awt.Font class in JDK 1.1 and earlier releases
to provide developers the ability to utilize more sophisticated
typographic features.
It is important to present the concepts behind using the words
character and glyph separately. A character is a symbol that
represents items like letters and numbers in a given writing system,
for example lowercase-g. When a given character is drawn, a shape
now represents this character. This shape is called a glyph.
Chararcter encoding is a conversion table that maps character codes
to glyph codes in the font. The character encoding used in the Java 2D
API is Unicode. For more information on Unicode you may visit the site
http://www.unicode.org.
Characters and glyphs do not have one-to-one correspondence. As an example
lowercase-a acute can be represented by two glyphs: lowercase-a
and acute.
Another example is ligatures such as ligature -fi which is a
single glyph representing two characters: f and i.
A font is a collection of glyphs. A font may have many faces, e.g.
heavy, medium, oblique, gothic and regular. All of these faces have
similar typographic design.
There are three different names that you can get from a Font object.
The logical font nameis the same as used by java.awt.Font in
JDK 1.1 and earlier releases. The java.awt.Toolkit.getFontList() method
returns a short list of these logical names which are mapped onto specific
fonts available on specific platforms. The font face name,
or just font name for short, is the name of a particular font
face, like Helvetica Bold. The family name is the name
of the font family that determines the typographic design across several
faces, like Helvetica. The font face name
is the one that should be used to specify fonts. This name signifies
actual fonts in the host system, and does not identify font
names with shape of font characters as the logical font name does.
The Font class represents an instance of a font face from a
collection of font faces that are present in the system resources
of the host system. As examples, Helvetica Bold and Courier Bold Italic
are font faces. There can be several Font objects associated with
a font face, each differing in size, style, transform and font features.
GraphicsEnvironment.getAllFonts() returns an array of all font faces
available in the system. These font faces are returned as Font objects
with a size of 1, identity transform and default font features. These
base fonts can then be used to derive new Font objects with varying
sizes, styles, transforms and font features via the deriveFont methods
in this class.
- See Also:
- getFontList, getFonts, getAllFonts
BOLD- The bold style constant.
CENTER_BASELINE-
DEFAULT-
fontName-
HANGING_BASELINE-
ITALIC- The italicized style constant.
MAX_COMBINING-
MAX_COMPONENT-
MAX_LIGATURE-
MAX_STANDARD-
name- The logical name of this font.
PLAIN- The plain style constant.
ROMAN_BASELINE-
size- The point size of this font, rounded to integer.
style- The style of the font, as passed to the constructor.
Font(AttributeSet)
- Create a new font with the specified attributes
Font(FontObject)
-
Font(String, int, int)
- Creates a new font from the specified name, style and point size.
canDisplay(char)
- Checks if this font has a glyph for the specified character.
canDisplayUpTo(char[], int, int)
- A convenience overload.
canDisplayUpTo(CharacterIterator, int, int)
- Indicates whether a string is displayable by this Font.
canDisplayUpTo(String)
- Indicates whether a string is displayable by this Font.
decode(String)
- Returns the specified font using the name passed in.
deriveFont(AffineTransform)
- Creates a new Font object by replicating the current Font object
with a new transform associated with it.
deriveFont(float)
- Creates a new Font object by replicating the current Font object
with a new size associated with it.
deriveFont(int)
- Creates a new Font object by replicating the current Font object
with a new style associated with it.
deriveFont(int, AffineTransform)
- Creates a new Font object by replicating the current Font object
with a new style, transform and font attributes associated with it.
deriveFont(int, float)
- Creates a new Font object by replicating the current Font object
with a new style, size and font attributes associated with it.
deriveFont(TextAttributeSet)
- Creates a new Font object by replicating the current Font object
with a new set of font attributes associated with it.
equals(Object)
- Compares this object to the specified object.
finalize()
- Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
getAdvance(char)
-
getAscent()
- Returns the ascent of the font above the roman baseline.
getAttributes()
- Returns an array of font attributes available in this font.
getAvailableAttributes()
- Returns the names of all the attributes supported by this font.
getBaselineFor(char)
- Return the baseline appropriate for displaying this character.
getBaselineOffset(byte)
- Returns the offset from the roman baseline of the font to the specified
baseline.
getBaselineOffsetsFor(char)
- Return a list of relative offsets for the different baselines.
getBestFontFor(AttributedCharacterIterator)
- Resolve styles on the character at start into an instance of Font
that can best render the text between start and limit.
getBestFontFor(AttributedCharacterIterator, int, int)
- Resolve styles on the character at start into an instance of Font
that can best render the text between start and limit.
getDescent()
- Returns the descent of the font above the roman baseline.
getFamily()
- Returns the family name of the font (for example, Helvetica).
getFamily(Locale)
- Returns the family name of the font (for example, Helvetica), localized
for the given Locale.
getFont(AttributeSet)
- Returns a font appropriate to this attribute set.
getFont(String)
- Returns a font from the system properties list.
getFont(String, Font)
- Returns the specified font from the system properties list.
getFontName()
- Returns the font face name of the font (for example, Helvetica Bold).
getFontName(Locale)
- Returns the font face name of the font (for example, Helvetica Fett)
localized for the specified locale.
getGlyphJustificationInfo(int)
- Return justification info for the glyph specified by glyphCode.
getGlyphMetrics(int)
- Returns the metrics information for a glyph specified by a glyph code.
getGlyphOutline(int, float, float)
- Returns the outline description of a glyph specified by a glyph code.
getGlyphSet(char[], int, int, byte, int[], byte[])
- Construct a GlyphSet for the text between start and limit.
getGlyphSet(CharacterIterator, int, int, byte, int[], byte[])
- Create a glyph set for the text between start and limit.
getGlyphSet(String)
- Converts all characters in the String Object to font glyph codes.
getItalicAngle()
- Returns the italic angle of this font.
getLeading()
- Returns the leading for this font;
getMaxAdvance()
- Returns the maximum advance of any glyph in this font.
getMaxBounds2D()
- Returns the maximum bounding box of this font.
getMetrics(GlyphSet, AffineTransform)
-
getMissingGlyphCode()
-
getName()
- Returns the logical name of the font.
getNumGlyphs()
- Returns number of glyphs in the font.
getOutline(GlyphSet, AffineTransform, float, float)
-
getPeer()
- Gets the peer of the font.
getPSName()
- Returns the postscript name of the font.
getRequestedAttributes()
- Returns the attribute set used to create this font.
getSize()
- Returns the point size of the font, rounded to integer.
getSize2D()
- Returns the point size of the font in float.
getStrikethroughOffsetFor(char)
- Return the strikethrough offset from the roman baseline for this
character.
getStrikethroughThicknessFor(char)
- Return the strikethrough thickness for this character.
getStyle()
- Returns the style of the font.
getTransform()
- Returns the transform associated with this font.
getUnderlineOffsetFor(char)
- Return the underline offset from the roman baseline for this character.
getUnderlineThicknessFor(char)
- Return the underline thickness for this character.
hashCode()
- Returns a hashcode for this font.
isBold()
- Indicates whether the font's style is bold.
isItalic()
- Indicates whether the font's style is italic.
isPlain()
- Returns true if the font is plain.
isUniformBaseline()
- Return true if this font places all glyphs on a single baseline.
isVerticalBaseline()
-
sameBaselineUpTo(char[], int, int)
- Return the index of the first character with a different baseline from the
character at start, or limit if all characters between start and limit have
the same baseline.
sameBaselineUpTo(CharacterIterator)
- Return the index of the first character with a different baseline from the
first character in the range, or end index if all characters in the range have
the same baseline.
toString()
- Converts this object to a String representation.
DEFAULT
public static final Font DEFAULT
PLAIN
public static final int PLAIN
- The plain style constant.
BOLD
public static final int BOLD
- The bold style constant. This can be combined with the other style
constants (except PLAIN) for mixed styles.
ITALIC
public static final int ITALIC
- The italicized style constant. This can be combined with the other
style constants (except PLAIN) for mixed styles.
ROMAN_BASELINE
public static final byte ROMAN_BASELINE
CENTER_BASELINE
public static final byte CENTER_BASELINE
HANGING_BASELINE
public static final byte HANGING_BASELINE
MAX_STANDARD
public static final int MAX_STANDARD
MAX_LIGATURE
public static final int MAX_LIGATURE
MAX_COMBINING
public static final int MAX_COMBINING
MAX_COMPONENT
public static final int MAX_COMPONENT
name
protected String name
- The logical name of this font.
fontName
protected String fontName
style
protected int style
- The style of the font, as passed to the constructor. This may be
PLAIN, BOLD, ITALIC, or BOLD+ITALIC.
size
protected int size
- The point size of this font, rounded to integer.
Font
public Font(String name,
int style,
int size)
- Creates a new font from the specified name, style and point size.
- Parameters:
- name - the font name. This can be a logical font name or a
font face name.
- style - the style constant for the font.
- size - the point size of the font.
- See Also:
- getFontList, getFonts, getAllFonts
Font
public Font(FontObject fontObject)
Font
public Font(AttributeSet attributes)
- Create a new font with the specified attributes
getPeer
public FontPeer getPeer()
- Gets the peer of the font.
- Returns:
- the peer of the font.
getFont
public static Font getFont(AttributeSet attributes)
- Returns a font appropriate to this attribute set.
getTransform
public AffineTransform getTransform()
- Returns the transform associated with this font.
getFamily
public String getFamily()
- Returns the family name of the font (for example, Helvetica).
Use getName to get the logical name of the font.
Use getFontName to get the font face name of the font.
- See Also:
- getName, getFontName
getFamily
public String getFamily(Locale l)
- Returns the family name of the font (for example, Helvetica), localized
for the given Locale.
Use getFontName to get the font face name of the font.
- Parameters:
- l - Locale for which to get the family name.
- See Also:
- getFontName, Locale
getPSName
public String getPSName()
- Returns the postscript name of the font.
Use getFamily to get the family name of the font.
Use getFontName to get the font face name of the font.
getName
public String getName()
- Returns the logical name of the font.
Use getFamily to get the family name of the font.
Use getFontName to get the font face name of the font.
- See Also:
- getFamily, getFontName
getFontName
public String getFontName()
- Returns the font face name of the font (for example, Helvetica Bold).
Use getFamily to get the family name of the font.
Use getName to get the logical name of the font.
- See Also:
- getFamily, getName
getFontName
public String getFontName(Locale l)
- Returns the font face name of the font (for example, Helvetica Fett)
localized for the specified locale.
Use getFamily to get the family name of the font.
- Parameters:
- l - Get the localized font face name for this locale.
- See Also:
- getFamily, Locale
getStyle
public int getStyle()
- Returns the style of the font. This may be
PLAIN, BOLD, ITALIC, or BOLD+ITALIC.
- See Also:
- isPlain, isBold, isItalic
getSize
public int getSize()
- Returns the point size of the font, rounded to integer.
Most users are familiar with the idea of using point size to
specify the size of glyphs in a font. This point size defines a
measurement between the baseline of one line to the baseline of the
following line in a single spaced text document. The point size is
based on typographic points, approximately 1/72 of an inch.
The Java2D API adopts the convention that one point is equivalent
to one unit in user coordinates. When using a normalized transform
for converting user space coordinates to device space coordinates
(see GraphicsConfiguration.getDefaultTransform() and
GraphicsConfiguration.getNormalizingTransform()), 72 user space units
equal 1 inch in device space. In this case one point is 1/72 of an
inch.
- See Also:
- getSize2D, getDefaultTransform, getNormalizingTransform
getSize2D
public float getSize2D()
- Returns the point size of the font in float.
- See Also:
- getSize
isPlain
public boolean isPlain()
- Returns true if the font is plain.
- See Also:
- getStyle
isBold
public boolean isBold()
- Indicates whether the font's style is bold.
- Returns:
true
if the font is bold;
false
otherwise.- See Also:
- getStyle
isItalic
public boolean isItalic()
- Indicates whether the font's style is italic.
- Returns:
true
if the font is italic;
false
otherwise.- See Also:
- getStyle
getFont
public static Font getFont(String nm)
- Returns a font from the system properties list.
- Parameters:
- nm - the property name.
decode
public static Font decode(String str)
- Returns the specified font using the name passed in.
- Parameters:
- str - the name.
getFont
public static Font getFont(String nm,
Font font)
- Returns the specified font from the system properties list.
- Parameters:
- nm - the property name.
- font - a default font to return if property 'nm' is not defined.
hashCode
public int hashCode()
- Returns a hashcode for this font.
- Returns:
- a hashcode value for this font.
- Overrides:
- hashCode in class Object
equals
public boolean equals(Object obj)
- Compares this object to the specified object.
- Parameters:
- obj - the object to compare with.
- Returns:
- true if the objects are the same; false otherwise.
- Overrides:
- equals in class Object
toString
public String toString()
- Converts this object to a String representation.
- Returns:
- a string representation of this object
- Overrides:
- toString in class Object
getNumGlyphs
public int getNumGlyphs()
- Returns number of glyphs in the font. Glyph codes for the font
will range from 0 to getNumGlyphs() - 1.
getMissingGlyphCode
public int getMissingGlyphCode()
isVerticalBaseline
public boolean isVerticalBaseline()
getGlyphMetrics
public GlyphMetrics getGlyphMetrics(int glyphCode)
- Returns the metrics information for a glyph specified by a glyph code.
- Parameters:
- glyphCode - the glyph to get metrics for.
- Returns:
- a GlyphMetrics object with metric information for the glyph.
getBaselineFor
public byte getBaselineFor(char c)
- Return the baseline appropriate for displaying this character.
Large fonts can support different writing systems, and each system can
use a different baseline.
The character argument determines the writing system to use. Clients
should not assume all characters will use the same baseline.
- Parameters:
- c - a character used to identify the writing system
- See Also:
- getBaselineOffsetsFor, ROMAN_BASELINE, CENTER_BASELINE, HANGING_BASELINE
getBaselineOffsetsFor
public float[] getBaselineOffsetsFor(char c)
- Return a list of relative offsets for the different baselines.
Large fonts can support different writing systems, and each system can
have its own set of preferred baseline offsets. The character argument
determines the writing system to use.
These all are relative to the most common baseline used with this font
(the one from which ascent and descent are measured). Negative values
are up on horizontal lines, and right on vertical lines.
- Parameters:
- c - a character used to identify the writing system
- See Also:
- getBaselineFor, ROMAN_BASELINE, CENTER_BASELINE, HANGING_BASELINE
isUniformBaseline
public boolean isUniformBaseline()
- Return true if this font places all glyphs on a single baseline.
sameBaselineUpTo
public int sameBaselineUpTo(CharacterIterator iter)
- Return the index of the first character with a different baseline from the
first character in the range, or end index if all characters in the range have
the same baseline.
sameBaselineUpTo
public int sameBaselineUpTo(char[] text,
int start,
int limit)
- Return the index of the first character with a different baseline from the
character at start, or limit if all characters between start and limit have
the same baseline.
getUnderlineOffsetFor
public float getUnderlineOffsetFor(char c)
- Return the underline offset from the roman baseline for this character.
getUnderlineThicknessFor
public float getUnderlineThicknessFor(char c)
- Return the underline thickness for this character. Zero means the
character is not underlined.
getStrikethroughOffsetFor
public float getStrikethroughOffsetFor(char c)
- Return the strikethrough offset from the roman baseline for this
character.
getStrikethroughThicknessFor
public float getStrikethroughThicknessFor(char c)
- Return the strikethrough thickness for this character. Zero means the
character is
not underlined.
getGlyphOutline
public Shape getGlyphOutline(int glyphCode,
float x,
float y)
- Returns the outline description of a glyph specified by a glyph code.
- Parameters:
- glyphCode - the glyph for which to get the outline.
- Returns:
- a Shape object representing the outline of the glyph.
getOutline
public Shape getOutline(GlyphSet glyphs,
AffineTransform tx,
float x,
float y)
getMetrics
public float[] getMetrics(GlyphSet glyphs,
AffineTransform tx)
getAdvance
public float getAdvance(char c)
getAttributes
public AttributeSet getAttributes()
- Returns an array of font attributes available in this font.
Attributes include things like ligatures and glyph substitution.
- Returns:
- a FontAttribute array.
getAvailableAttributes
public String[] getAvailableAttributes()
- Returns the names of all the attributes supported by this font.
These attributes may be used to derive other fonts.
getGlyphJustificationInfo
public GlyphJustificationInfo getGlyphJustificationInfo(int glyphCode)
- Return justification info for the glyph specified by glyphCode.
If left is true, return info for the left side of the glyph, otherwise
for the right.
If grow is true, return info for growing a line, otherwise for
shrinking it.
!!! unify into one set of information per glyph?
Then it's the accessing code's problem...
getRequestedAttributes
public AttributeSet getRequestedAttributes()
- Returns the attribute set used to create this font.
NOTE: This method may be moved into another class.
deriveFont
public Font deriveFont(int style,
float size)
- Creates a new Font object by replicating the current Font object
with a new style, size and font attributes associated with it.
- Parameters:
- style - the style for the new Font.
- size - the size in float for the new Font.
- attributes - an array of AttributeSets enabled for the new Font.
- Returns:
- a new Font object.
deriveFont
public Font deriveFont(int style,
AffineTransform trans)
- Creates a new Font object by replicating the current Font object
with a new style, transform and font attributes associated with it.
- Parameters:
- style - the style for the new Font.
- trans - the AffineTransform associated with the new Font.
- attributes - an array of AttributeSets enabled for the new Font.
- Returns:
- a new Font object.
deriveFont
public Font deriveFont(float size)
- Creates a new Font object by replicating the current Font object
with a new size associated with it.
- Parameters:
- size - the size in float for the new Font.
- Returns:
- a new Font object.
deriveFont
public Font deriveFont(AffineTransform trans)
- Creates a new Font object by replicating the current Font object
with a new transform associated with it.
- Parameters:
- trans - the AffineTransform associated with the new Font.
- Returns:
- a new Font object.
deriveFont
public Font deriveFont(int style)
- Creates a new Font object by replicating the current Font object
with a new style associated with it.
- Parameters:
- style - the style for the new Font.
- Returns:
- a new Font object.
deriveFont
public Font deriveFont(TextAttributeSet attributes)
- Creates a new Font object by replicating the current Font object
with a new set of font attributes associated with it.
- Parameters:
- attributes - an array of AttributeSets enabled for the new Font.
- Returns:
- a new Font object.
getGlyphSet
public GlyphSet getGlyphSet(CharacterIterator context,
int start,
int limit,
byte baseline,
int[] order,
byte[] levels)
- Create a glyph set for the text between start and limit.
- Parameters:
- context - the text for the entire line. The whole
context is provided for fonts that need to do glyph shaping.
- start - the start of the subrange for which to create glyphs.
- limit - the limit of the subrange for which to create glyphs.
- order - a mapping from logical to visual positions for
bidirectional text. For example, the value 5 at position 0 in the
array means that the character at logical position 0 (from the
start of the text in the iterator) displays at visual position 5
(assuming all characters are displayed).
If order is null, the visual position is the logical position.
Position zero in this array is position startIndex in the context.
The array length must be at least the number of characters in the
iterator.
Note the meaning of this array is the inverse of the mapping
passed to the GlyphSet constructor. This is to faciliate indexing
into the array using start and limit.
- levels - an array indicating the bidirection level of each
character. Even values are left to right, odd are right to left.
This will affect hit testing and cursor positioning.
If null, all characters are left to right. Position zero in this
array is position beginIndex in the context, and the array length
is greater than or equal to endIndex - beginIndex.
- See Also:
- GlyphSet
getGlyphSet
public GlyphSet getGlyphSet(char[] context,
int start,
int limit,
byte baseline,
int[] order,
byte[] levels)
- Construct a GlyphSet for the text between start and limit.
getGlyphSet
public GlyphSet getGlyphSet(String str)
- Converts all characters in the String Object to font glyph codes.
Glyph substitution may be performed.
- Parameters:
- str - a String object.
- Returns:
- a GlyphSet containing a collection of glyphs and glyph positions.
canDisplay
public boolean canDisplay(char c)
- Checks if this font has a glyph for the specified character.
- Parameters:
- c - a unicode character code.
- Returns:
- true if the font can display the character.
canDisplayUpTo
public int canDisplayUpTo(String str)
- Indicates whether a string is displayable by this Font.
For strings with Unicode encoding, it is important to know if a given
Font can display the string. This method returns an offset
into the String str which is the first character the Font
cannot display without using the missing glyph code. If the Font can
display all characters, -1 is returned.
- Parameters:
- str - a String object.
- Returns:
- an offset into the String object that can be displayed by this
font.
canDisplayUpTo
public int canDisplayUpTo(char[] text,
int start,
int limit)
- A convenience overload.
canDisplayUpTo
public int canDisplayUpTo(CharacterIterator iter,
int start,
int limit)
- Indicates whether a string is displayable by this Font.
For strings with Unicode encoding, it is important to know if a given
Font can display the string. This method returns an offset
into the String str which is the first character the Font
cannot display without using the missing glyph code . If the Font can
display all characters, -1 is returned.
- Parameters:
- text - a CharacterIterator object.
- Returns:
- an offset into the String object that can be displayed by this
font.
getBaselineOffset
public float getBaselineOffset(byte baselineType)
- Returns the offset from the roman baseline of the font to the specified
baseline.
getAscent
public float getAscent()
- Returns the ascent of the font above the roman baseline.
getDescent
public float getDescent()
- Returns the descent of the font above the roman baseline.
getLeading
public float getLeading()
- Returns the leading for this font;
getMaxAdvance
public float getMaxAdvance()
- Returns the maximum advance of any glyph in this font.
getMaxBounds2D
public Rectangle2D getMaxBounds2D()
- Returns the maximum bounding box of this font.
getItalicAngle
public float getItalicAngle()
- Returns the italic angle of this font.
getBestFontFor
public static Font getBestFontFor(AttributedCharacterIterator text)
- Resolve styles on the character at start into an instance of Font
that can best render the text between start and limit.
REMIND jk. Move it to graphics environment.
getBestFontFor
public static Font getBestFontFor(AttributedCharacterIterator text,
int start,
int limit)
- Resolve styles on the character at start into an instance of Font
that can best render the text between start and limit.
REMIND jk. Move it to graphics environment.
finalize
protected void finalize() throws Throwable
- Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
- Overrides:
- finalize in class Object
All Packages Class Hierarchy This Package Previous Next Index
Submit a bug or feature