java.awt
Class Font

java.lang.Object
  extended by java.awt.Font
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
FontUIResource

public class Font
extends Object
implements Serializable

This class represents a windowing system font.

See Also:
Serialized Form

Field Summary
static int BOLD
          Constant indicating a "bold" font.
static int CENTER_BASELINE
          Constant indicating the baseline mode characteristic of Chinese.
static String DIALOG
           
static String DIALOG_INPUT
           
static int HANGING_BASELINE
          Constant indicating the baseline mode characteristic of Devanigri.
static int ITALIC
          Constant indicating an "italic" font.
static int LAYOUT_LEFT_TO_RIGHT
          A flag for layoutGlyphVector, indicating that the orientation of a text run is from left to right.
static int LAYOUT_NO_LIMIT_CONTEXT
          A flag for layoutGlyphVector, indicating that the text does not contain valid characters after the limit position.
static int LAYOUT_NO_START_CONTEXT
          A flag for layoutGlyphVector, indicating that the text does not contain valid characters before the start position.
static int LAYOUT_RIGHT_TO_LEFT
          A flag for layoutGlyphVector, indicating that the orientation of a text run is from right to left.
static String MONOSPACED
           
protected  String name
          The logical name of this font.
static int PLAIN
          Constant indicating a "plain" font.
protected  float pointSize
          The size of this font in points.
static int ROMAN_BASELINE
          Constant indicating the baseline mode characteristic of Roman.
static String SANS_SERIF
           
static String SERIF
           
protected  int size
          The size of this font in points, rounded.
protected  int style
          The style of this font -- PLAIN, BOLD, ITALIC or BOLD+ITALIC.
static int TRUETYPE_FONT
          Indicates to createFont that the supplied font data is in TrueType format.
static int TYPE1_FONT
          Indicates to createFont that the supplied font data is in Type1 format.
 
Constructor Summary
protected Font(Font font)
           
  Font(Map<? extends AttributedCharacterIterator.Attribute,?> attrs)
           
  Font(String name, int style, int size)
          Initializes a new instance of Font with the specified attributes.
 
Method Summary
 boolean canDisplay(char c)
          Checks if specified character maps to a glyph in this font.
 boolean canDisplay(int codePoint)
           
 int canDisplayUpTo(char[] text, int start, int limit)
          Checks how much of a given sequence of text can be mapped to glyphs in this font.
 int canDisplayUpTo(CharacterIterator i, int start, int limit)
          Checks how much of a given sequence of text can be mapped to glyphs in this font.
 int canDisplayUpTo(String s)
          Checks how much of a given string can be mapped to glyphs in this font.
static Font createFont(int fontFormat, File file)
          Creates a new font from a File object.
static Font createFont(int fontFormat, InputStream is)
          Creates a new font with point size 1 and PLAIN style, reading font data from the provided input stream.
 GlyphVector createGlyphVector(FontRenderContext ctx, char[] chars)
          Maps characters to glyphs in a one-to-one relationship, returning a new GlyphVector with a mapped glyph for each input character.
 GlyphVector createGlyphVector(FontRenderContext ctx, CharacterIterator i)
          Maps characters to glyphs in a one-to-one relationship, returning a new GlyphVector with a mapped glyph for each input character.
 GlyphVector createGlyphVector(FontRenderContext ctx, int[] glyphCodes)
          Extracts a sequence of glyphs from a font, returning a new GlyphVector with a mapped glyph for each input glyph code.
 GlyphVector createGlyphVector(FontRenderContext ctx, String str)
          Maps characters to glyphs in a one-to-one relationship, returning a new GlyphVector with a mapped glyph for each input character.
static Font decode(String fontspec)
          Creates a Font object from the specified string, which is in one of the following formats: fontname-style-pointsize fontname-style fontname-pointsize fontname The style should be one of BOLD, ITALIC, or BOLDITALIC.
 Font deriveFont(AffineTransform a)
          Produces a new Font based on the current font, subjected to a new affine transformation.
 Font deriveFont(float size)
          Produces a new Font based on the current font, adjusted to a new size.
 Font deriveFont(int style)
          Produces a new Font based on the current font, adjusted to a new style.
 Font deriveFont(int style, AffineTransform a)
          Produces a new Font based on the current font, adjusted to a new style and subjected to a new affine transformation.
 Font deriveFont(int style, float size)
          Produces a new Font based on the current font, adjusted to a new size and style.
 Font deriveFont(Map<? extends AttributedCharacterIterator.Attribute,?> attributes)
          Produces a new Font based on the current font, adjusted to a new set of attributes.
 boolean equals(Object obj)
          Tests whether or not the specified object is equal to this font.
 Map<TextAttribute,?> getAttributes()
          Returns a map of chracter attributes which this font currently has set.
 AttributedCharacterIterator.Attribute[] getAvailableAttributes()
          Returns an array of chracter attribute keys which this font understands.
 byte getBaselineFor(char c)
          Returns a baseline code (one of ROMAN_BASELINE, CENTER_BASELINE or HANGING_BASELINE) indicating which baseline this font will measure baseline offsets for, when presenting glyph metrics for a given character.
 String getFamily()
          Returns the family name of this font.
 String getFamily(Locale lc)
          Returns the family name of this font.
static Font getFont(Map<? extends AttributedCharacterIterator.Attribute,?> attributes)
          Returns a font appropriate for the given attribute set.
static Font getFont(String propname)
          Returns a Font object from the passed property name.
static Font getFont(String propname, Font defval)
          Returns a Font object from the passed property name.
 String getFontName()
          Returns the font face name of the font.
 String getFontName(Locale lc)
          Returns the font face name of the font.
 float getItalicAngle()
          Returns the italic angle of this font, a measurement of its slant when style is ITALIC.
 LineMetrics getLineMetrics(char[] chars, int begin, int limit, FontRenderContext rc)
          Returns a LineMetrics object constructed with the specified text and FontRenderContext.
 LineMetrics getLineMetrics(CharacterIterator ci, int begin, int limit, FontRenderContext rc)
          Returns a LineMetrics object constructed with the specified text and FontRenderContext.
 LineMetrics getLineMetrics(String str, FontRenderContext frc)
          Determines the line metrics for a run of text.
 LineMetrics getLineMetrics(String text, int begin, int limit, FontRenderContext rc)
          Returns a LineMetrics object constructed with the specified text and FontRenderContext.
 Rectangle2D getMaxCharBounds(FontRenderContext rc)
          Returns the maximal bounding box of all the bounding boxes in this font, when the font's bounding boxes are evaluated in a given FontRenderContext
 int getMissingGlyphCode()
          Returns the glyph code this font uses to represent missing glyphs.
 String getName()
          Returns the logical name of the font.
 int getNumGlyphs()
          Returns the overall number of glyphs in this font.
 FontPeer getPeer()
          Deprecated.  
 String getPSName()
          Returns the PostScript Name of this font.
 int getSize()
          Returns the size of the font, in typographics points (1/72 of an inch), rounded to an integer.
 float getSize2D()
          Returns the size of the font, in typographics points (1/72 of an inch).
 Rectangle2D getStringBounds(char[] chars, int begin, int limit, FontRenderContext frc)
          Returns the logical bounds of the specified string when rendered with this font in the specified FontRenderContext.
 Rectangle2D getStringBounds(CharacterIterator ci, int begin, int limit, FontRenderContext frc)
          Returns the logical bounds of the specified string when rendered with this font in the specified FontRenderContext.
 Rectangle2D getStringBounds(String str, FontRenderContext frc)
          Returns the logical bounds of the specified string when rendered with this font in the specified FontRenderContext.
 Rectangle2D getStringBounds(String str, int begin, int limit, FontRenderContext frc)
          Returns the logical bounds of the specified string when rendered with this font in the specified FontRenderContext.
 int getStyle()
          Returns integer code representing the sum of style flags of this font, a combination of either PLAIN, BOLD, or ITALIC.
 AffineTransform getTransform()
          Returns a copy of the affine transformation this font is currently subject to, if any.
 int hashCode()
          Returns a hash value for this font.
 boolean hasLayoutAttributes()
           
 boolean hasUniformLineMetrics()
          Indicates whether this font's line metrics are uniform.
 boolean isBold()
          Tests whether or not this font is bold.
 boolean isItalic()
          Tests whether or not this font is italic.
 boolean isPlain()
          Tests whether or not this is a plain font.
 boolean isTransformed()
          Indicates whether this font is subject to a non-identity affine transformation.
 GlyphVector layoutGlyphVector(FontRenderContext frc, char[] chars, int start, int limit, int flags)
          Produces a glyph vector representing a full layout fo the specified text in this font.
 String toString()
          Returns a string representation of this font.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

PLAIN

public static final int PLAIN
Constant indicating a "plain" font.

See Also:
Constant Field Values

BOLD

public static final int BOLD
Constant indicating a "bold" font.

See Also:
Constant Field Values

ITALIC

public static final int ITALIC
Constant indicating an "italic" font.

See Also:
Constant Field Values

ROMAN_BASELINE

public static final int ROMAN_BASELINE
Constant indicating the baseline mode characteristic of Roman.

See Also:
Constant Field Values

CENTER_BASELINE

public static final int CENTER_BASELINE
Constant indicating the baseline mode characteristic of Chinese.

See Also:
Constant Field Values

HANGING_BASELINE

public static final int HANGING_BASELINE
Constant indicating the baseline mode characteristic of Devanigri.

See Also:
Constant Field Values

TRUETYPE_FONT

public static final int TRUETYPE_FONT
Indicates to createFont that the supplied font data is in TrueType format.

Specification Note: The Sun JavaDoc for J2SE 1.4 does not indicate whether this value also subsumes OpenType. OpenType is essentially the same format as TrueType, but allows to define glyph shapes in the same way as PostScript, using cubic bezier curves.

Since:
1.3
See Also:
Constant Field Values

TYPE1_FONT

public static final int TYPE1_FONT
Indicates to createFont that the supplied font data is in Type1 format.

Since:
1.5
See Also:
Constant Field Values

LAYOUT_LEFT_TO_RIGHT

public static final int LAYOUT_LEFT_TO_RIGHT
A flag for layoutGlyphVector, indicating that the orientation of a text run is from left to right.

Since:
1.4
See Also:
Constant Field Values

LAYOUT_RIGHT_TO_LEFT

public static final int LAYOUT_RIGHT_TO_LEFT
A flag for layoutGlyphVector, indicating that the orientation of a text run is from right to left.

Since:
1.4
See Also:
Constant Field Values

LAYOUT_NO_START_CONTEXT

public static final int LAYOUT_NO_START_CONTEXT
A flag for layoutGlyphVector, indicating that the text does not contain valid characters before the start position. If this flag is set, layoutGlyphVector does not examine the text before start, even if this would be necessary to select the correct glyphs (e.g., for Arabic text).

Since:
1.4
See Also:
Constant Field Values

LAYOUT_NO_LIMIT_CONTEXT

public static final int LAYOUT_NO_LIMIT_CONTEXT
A flag for layoutGlyphVector, indicating that the text does not contain valid characters after the limit position. If this flag is set, layoutGlyphVector does not examine the text after limit, even if this would be necessary to select the correct glyphs (e.g., for Arabic text).

Since:
1.4
See Also:
Constant Field Values

DIALOG

public static final String DIALOG
Since:
1.6
See Also:
Constant Field Values

DIALOG_INPUT

public static final String DIALOG_INPUT
Since:
1.6
See Also:
Constant Field Values

MONOSPACED

public static final String MONOSPACED
Since:
1.6
See Also:
Constant Field Values

SANS_SERIF

public static final String SANS_SERIF
Since:
1.6
See Also:
Constant Field Values

SERIF

public static final String SERIF
Since:
1.6
See Also:
Constant Field Values

name

protected String name
The logical name of this font.

Since:
1.0

size

protected int size
The size of this font in points, rounded.

Since:
1.0

pointSize

protected float pointSize
The size of this font in points.

Since:
1.0

style

protected int style
The style of this font -- PLAIN, BOLD, ITALIC or BOLD+ITALIC.

Since:
1.0
Constructor Detail

Font

protected Font(Font font)

Font

public Font(String name,
            int style,
            int size)
Initializes a new instance of Font with the specified attributes.

Parameters:
name - The name of the font.
style - The font style.
size - The font point size.

Font

public Font(Map<? extends AttributedCharacterIterator.Attribute,?> attrs)
Method Detail

decode

public static Font decode(String fontspec)
Creates a Font object from the specified string, which is in one of the following formats:

The style should be one of BOLD, ITALIC, or BOLDITALIC. The default style if none is specified is PLAIN. The default size if none is specified is 12.

Parameters:
fontspec - a string specifying the required font (null permitted, interpreted as 'Dialog-PLAIN-12').
Returns:
A font.

getFont

public static Font getFont(String propname,
                           Font defval)
Returns a Font object from the passed property name.

Parameters:
propname - The name of the system property.
defval - Value to use if the property is not found.
Returns:
The requested font, or default if the property not exist or is malformed.

getFont

public static Font getFont(String propname)
Returns a Font object from the passed property name.

Parameters:
propname - The name of the system property.
Returns:
The requested font, or null if the property not exist or is malformed.

getName

public String getName()
Returns the logical name of the font. A logical name is the name the font was constructed with. It may be the name of a logical font (one of 6 required names in all java environments) or it may be a face name.

Returns:
The logical name of the font.
See Also:
getFamily(), getFontName()

getSize

public int getSize()
Returns the size of the font, in typographics points (1/72 of an inch), rounded to an integer.

Returns:
The font size

getSize2D

public float getSize2D()
Returns the size of the font, in typographics points (1/72 of an inch).

Returns:
The font size

isPlain

public boolean isPlain()
Tests whether or not this is a plain font. This will be true if and only if neither the bold nor the italics style is set.

Returns:
true if this is a plain font, false otherwise.

isBold

public boolean isBold()
Tests whether or not this font is bold.

Returns:
true if this font is bold, false otherwise.

isItalic

public boolean isItalic()
Tests whether or not this font is italic.

Returns:
true if this font is italic, false otherwise.

getFamily

public String getFamily()
Returns the family name of this font. A family name describes a design or "brand name" (such as Helvetica or Palatino). It is less specific than a font face name (such as Helvetica Bold).

Returns:
A string containing the font family name.
Since:
1.2
See Also:
getName(), getFontName(), GraphicsEnvironment.getAvailableFontFamilyNames()

getStyle

public int getStyle()
Returns integer code representing the sum of style flags of this font, a combination of either PLAIN, BOLD, or ITALIC.

Returns:
code representing the style of this font.
See Also:
isPlain(), isBold(), isItalic()

canDisplay

public boolean canDisplay(char c)
Checks if specified character maps to a glyph in this font.

Parameters:
c - The character to check.
Returns:
Whether the character has a corresponding glyph in this font.
Since:
1.2

canDisplay

public boolean canDisplay(int codePoint)

canDisplayUpTo

public int canDisplayUpTo(String s)
Checks how much of a given string can be mapped to glyphs in this font.

Parameters:
s - The string to check.
Returns:
The index of the first character in s which cannot be converted to a glyph by this font, or -1 if all characters can be mapped to glyphs.
Since:
1.2

canDisplayUpTo

public int canDisplayUpTo(char[] text,
                          int start,
                          int limit)
Checks how much of a given sequence of text can be mapped to glyphs in this font.

Parameters:
text - Array containing the text to check.
start - Position of first character to check in text.
limit - Position of last character to check in text.
Returns:
The index of the first character in the indicated range which cannot be converted to a glyph by this font, or -1 if all characters can be mapped to glyphs.
Throws:
IndexOutOfBoundsException - if the range [start, limit] is invalid in text.
Since:
1.2

canDisplayUpTo

public int canDisplayUpTo(CharacterIterator i,
                          int start,
                          int limit)
Checks how much of a given sequence of text can be mapped to glyphs in this font.

Parameters:
i - Iterator over the text to check.
start - Position of first character to check in i.
limit - Position of last character to check in i.
Returns:
The index of the first character in the indicated range which cannot be converted to a glyph by this font, or -1 if all characters can be mapped to glyphs.
Throws:
IndexOutOfBoundsException - if the range [start, limit] is invalid in i.
Since:
1.2

createFont

public static Font createFont(int fontFormat,
                              InputStream is)
                       throws FontFormatException,
                              IOException
Creates a new font with point size 1 and PLAIN style, reading font data from the provided input stream. The resulting font can have further fonts derived from it using its deriveFont method.

Parameters:
fontFormat - Integer code indicating the format the font data is in.Currently this can only be TRUETYPE_FONT.
is - InputStream from which font data will be read. This stream is not closed after font data is extracted.
Returns:
A new Font of the format indicated.
Throws:
IllegalArgumentException - if fontType is not recognized.
FontFormatException - if data in InputStream is not of format indicated.
IOException - if insufficient data is present on InputStream.
Since:
1.3

createFont

public static Font createFont(int fontFormat,
                              File file)
                       throws FontFormatException,
                              IOException
Creates a new font from a File object.

Parameters:
fontFormat - - Integer code indicating the format the font data is in.Currently this can only be TRUETYPE_FONT.
file - - a File from which font data will be read.
Returns:
A new Font of the format indicated.
Throws:
IllegalArgumentException - if fontType is not recognized.
NullPointerException - if file is null.
FontFormatException - if data in the file is invalid or cannot be read..
SecurityException - if the caller has no read permission for the file.
IOException - if the file cannot be read
Since:
1.5
See Also:
layoutGlyphVector(FontRenderContext, char[], int, int, int)

createGlyphVector

public GlyphVector createGlyphVector(FontRenderContext ctx,
                                     String str)
Maps characters to glyphs in a one-to-one relationship, returning a new GlyphVector with a mapped glyph for each input character. This sort of mapping is often sufficient for some scripts such as Roman, but is inappropriate for scripts with special shaping or contextual layout requirements such as Arabic, Indic, Hebrew or Thai.

Parameters:
ctx - The rendering context used for precise glyph placement.
str - The string to convert to Glyphs.
Returns:
A new GlyphVector containing glyphs mapped from str, through the font's cmap table.
See Also:
layoutGlyphVector(FontRenderContext, char[], int, int, int)

createGlyphVector

public GlyphVector createGlyphVector(FontRenderContext ctx,
                                     CharacterIterator i)
Maps characters to glyphs in a one-to-one relationship, returning a new GlyphVector with a mapped glyph for each input character. This sort of mapping is often sufficient for some scripts such as Roman, but is inappropriate for scripts with special shaping or contextual layout requirements such as Arabic, Indic, Hebrew or Thai.

Parameters:
ctx - The rendering context used for precise glyph placement.
i - Iterator over the text to convert to glyphs.
Returns:
A new GlyphVector containing glyphs mapped from str, through the font's cmap table.
See Also:
layoutGlyphVector(FontRenderContext, char[], int, int, int)

createGlyphVector

public GlyphVector createGlyphVector(FontRenderContext ctx,
                                     char[] chars)
Maps characters to glyphs in a one-to-one relationship, returning a new GlyphVector with a mapped glyph for each input character. This sort of mapping is often sufficient for some scripts such as Roman, but is inappropriate for scripts with special shaping or contextual layout requirements such as Arabic, Indic, Hebrew or Thai.

Parameters:
ctx - The rendering context used for precise glyph placement.
chars - Array of characters to convert to glyphs.
Returns:
A new GlyphVector containing glyphs mapped from str, through the font's cmap table.
See Also:
layoutGlyphVector(FontRenderContext, char[], int, int, int)

createGlyphVector

public GlyphVector createGlyphVector(FontRenderContext ctx,
                                     int[] glyphCodes)
Extracts a sequence of glyphs from a font, returning a new GlyphVector with a mapped glyph for each input glyph code.

Parameters:
ctx - The rendering context used for precise glyph placement.
glyphCodes - Array of characters to convert to glyphs.
Returns:
A new GlyphVector containing glyphs mapped from str, through the font's cmap table.
See Also:
layoutGlyphVector(FontRenderContext, char[], int, int, int)

deriveFont

public Font deriveFont(int style,
                       float size)
Produces a new Font based on the current font, adjusted to a new size and style.

Parameters:
style - The style of the newly created font.
size - The size of the newly created font.
Returns:
A clone of the current font, with the specified size and style.
Since:
1.2

deriveFont

public Font deriveFont(float size)
Produces a new Font based on the current font, adjusted to a new size.

Parameters:
size - The size of the newly created font.
Returns:
A clone of the current font, with the specified size.
Since:
1.2

deriveFont

public Font deriveFont(int style)
Produces a new Font based on the current font, adjusted to a new style.

Parameters:
style - The style of the newly created font.
Returns:
A clone of the current font, with the specified style.
Since:
1.2

deriveFont

public Font deriveFont(int style,
                       AffineTransform a)
Produces a new Font based on the current font, adjusted to a new style and subjected to a new affine transformation.

Parameters:
style - The style of the newly created font.
a - The transformation to apply.
Returns:
A clone of the current font, with the specified style and transform.
Throws:
IllegalArgumentException - If transformation is null.
Since:
1.2

deriveFont

public Font deriveFont(AffineTransform a)
Produces a new Font based on the current font, subjected to a new affine transformation.

Parameters:
a - The transformation to apply.
Returns:
A clone of the current font, with the specified transform.
Throws:
IllegalArgumentException - If transformation is null.
Since:
1.2

deriveFont

public Font deriveFont(Map<? extends AttributedCharacterIterator.Attribute,?> attributes)
Produces a new Font based on the current font, adjusted to a new set of attributes.

Parameters:
attributes - Attributes of the newly created font.
Returns:
A clone of the current font, with the specified attributes.
Since:
1.2

getAttributes

public Map<TextAttribute,?> getAttributes()
Returns a map of chracter attributes which this font currently has set.

Returns:
A map of chracter attributes which this font currently has set.
See Also:
getAvailableAttributes(), AttributedCharacterIterator.Attribute, TextAttribute

getAvailableAttributes

public AttributedCharacterIterator.Attribute[] getAvailableAttributes()
Returns an array of chracter attribute keys which this font understands.

Returns:
An array of chracter attribute keys which this font understands.
See Also:
getAttributes(), AttributedCharacterIterator.Attribute, TextAttribute

getBaselineFor

public byte getBaselineFor(char c)
Returns a baseline code (one of ROMAN_BASELINE, CENTER_BASELINE or HANGING_BASELINE) indicating which baseline this font will measure baseline offsets for, when presenting glyph metrics for a given character. Baseline offsets describe the position of a glyph relative to an invisible line drawn under, through the center of, or over a line of rendered text, respectively. Different scripts use different baseline modes, so clients should not assume all baseline offsets in a glyph vector are from a common baseline.

Parameters:
c - The character code to select a baseline mode for.
Returns:
The baseline mode which would be used in a glyph associated with the provided character.
Since:
1.2
See Also:
LineMetrics.getBaselineOffsets()

getFamily

public String getFamily(Locale lc)
Returns the family name of this font. A family name describes a typographic style (such as Helvetica or Palatino). It is more specific than a logical font name (such as Sans Serif) but less specific than a font face name (such as Helvetica Bold).

Parameters:
lc - The locale in which to describe the name of the font family.
Returns:
A string containing the font family name, localized for the provided locale.
Since:
1.2
See Also:
getName(), getFontName(), GraphicsEnvironment.getAvailableFontFamilyNames(), Locale

getFont

public static Font getFont(Map<? extends AttributedCharacterIterator.Attribute,?> attributes)
Returns a font appropriate for the given attribute set.

Parameters:
attributes - The attributes required for the new font.
Returns:
A new Font with the given attributes.
Since:
1.2
See Also:
TextAttribute

getFontName

public String getFontName()
Returns the font face name of the font. A font face name describes a specific variant of a font family (such as Helvetica Bold). It is more specific than both a font family name (such as Helvetica) and a logical font name (such as Sans Serif).

Returns:
The font face name of the font.
Since:
1.2
See Also:
getName(), getFamily()

getFontName

public String getFontName(Locale lc)
Returns the font face name of the font. A font face name describes a specific variant of a font family (such as Helvetica Bold). It is more specific than both a font family name (such as Helvetica).

Parameters:
lc - The locale in which to describe the name of the font face.
Returns:
A string containing the font face name, localized for the provided locale.
Since:
1.2
See Also:
getName(), getFamily()

getItalicAngle

public float getItalicAngle()
Returns the italic angle of this font, a measurement of its slant when style is ITALIC. The precise meaning is the inverse slope of a caret line which "best measures" the font's italic posture.

Returns:
The italic angle.
See Also:
TextAttribute.POSTURE

getLineMetrics

public LineMetrics getLineMetrics(String text,
                                  int begin,
                                  int limit,
                                  FontRenderContext rc)
Returns a LineMetrics object constructed with the specified text and FontRenderContext.

Parameters:
text - The string to calculate metrics from.
begin - Index of first character in text to measure.
limit - Index of last character in text to measure.
rc - Context for calculating precise glyph placement and hints.
Returns:
A new LineMetrics object.
Throws:
IndexOutOfBoundsException - if the range [begin, limit] is invalid in text.

getLineMetrics

public LineMetrics getLineMetrics(char[] chars,
                                  int begin,
                                  int limit,
                                  FontRenderContext rc)
Returns a LineMetrics object constructed with the specified text and FontRenderContext.

Parameters:
chars - The string to calculate metrics from.
begin - Index of first character in text to measure.
limit - Index of last character in text to measure.
rc - Context for calculating precise glyph placement and hints.
Returns:
A new LineMetrics object.
Throws:
IndexOutOfBoundsException - if the range [begin, limit] is invalid in chars.

getLineMetrics

public LineMetrics getLineMetrics(CharacterIterator ci,
                                  int begin,
                                  int limit,
                                  FontRenderContext rc)
Returns a LineMetrics object constructed with the specified text and FontRenderContext.

Parameters:
ci - The string to calculate metrics from.
begin - Index of first character in text to measure.
limit - Index of last character in text to measure.
rc - Context for calculating precise glyph placement and hints.
Returns:
A new LineMetrics object.
Throws:
IndexOutOfBoundsException - if the range [begin, limit] is invalid in ci.

getMaxCharBounds

public Rectangle2D getMaxCharBounds(FontRenderContext rc)
Returns the maximal bounding box of all the bounding boxes in this font, when the font's bounding boxes are evaluated in a given FontRenderContext

Parameters:
rc - Context in which to evaluate bounding boxes.
Returns:
The maximal bounding box.

getMissingGlyphCode

public int getMissingGlyphCode()
Returns the glyph code this font uses to represent missing glyphs. This code will be present in glyph vectors when the font was unable to locate a glyph to represent a particular character code.

Returns:
The missing glyph code.
Since:
1.2

getNumGlyphs

public int getNumGlyphs()
Returns the overall number of glyphs in this font. This number is one more than the greatest glyph code used in any glyph vectors this font produces. In other words, glyph codes are taken from the range [ 0, getNumGlyphs() - 1 ].

Returns:
The number of glyphs in this font.
Since:
1.2

getPSName

public String getPSName()
Returns the PostScript Name of this font.

Returns:
The PostScript Name of this font.
Since:
1.2
See Also:
getName(), getFamily(), getFontName()

getStringBounds

public Rectangle2D getStringBounds(String str,
                                   FontRenderContext frc)
Returns the logical bounds of the specified string when rendered with this font in the specified FontRenderContext. This box will include the glyph origin, ascent, advance, height, and leading, but may not include all diacritics or accents. To get the complete visual bounding box of all the glyphs in a run of text, use the TextLayout.getBounds() method of TextLayout.

Parameters:
str - The string to measure.
frc - The context in which to make the precise glyph measurements.
Returns:
A bounding box covering the logical bounds of the specified text.
See Also:
createGlyphVector(FontRenderContext, String)

getStringBounds

public Rectangle2D getStringBounds(String str,
                                   int begin,
                                   int limit,
                                   FontRenderContext frc)
Returns the logical bounds of the specified string when rendered with this font in the specified FontRenderContext. This box will include the glyph origin, ascent, advance, height, and leading, but may not include all diacritics or accents. To get the complete visual bounding box of all the glyphs in a run of text, use the TextLayout.getBounds() method of TextLayout.

Parameters:
str - The string to measure.
begin - Index of the first character in str to measure.
limit - Index of the last character in str to measure.
frc - The context in which to make the precise glyph measurements.
Returns:
A bounding box covering the logical bounds of the specified text.
Throws:
IndexOutOfBoundsException - if the range [begin, limit] is invalid in str.
Since:
1.2
See Also:
createGlyphVector(FontRenderContext, String)

getStringBounds

public Rectangle2D getStringBounds(CharacterIterator ci,
                                   int begin,
                                   int limit,
                                   FontRenderContext frc)
Returns the logical bounds of the specified string when rendered with this font in the specified FontRenderContext. This box will include the glyph origin, ascent, advance, height, and leading, but may not include all diacritics or accents. To get the complete visual bounding box of all the glyphs in a run of text, use the TextLayout.getBounds() method of TextLayout.

Parameters:
ci - The text to measure.
begin - Index of the first character in ci to measure.
limit - Index of the last character in ci to measure.
frc - The context in which to make the precise glyph measurements.
Returns:
A bounding box covering the logical bounds of the specified text.
Throws:
IndexOutOfBoundsException - if the range [begin, limit] is invalid in ci.
Since:
1.2
See Also:
createGlyphVector(FontRenderContext, CharacterIterator)

getStringBounds

public Rectangle2D getStringBounds(char[] chars,
                                   int begin,
                                   int limit,
                                   FontRenderContext frc)
Returns the logical bounds of the specified string when rendered with this font in the specified FontRenderContext. This box will include the glyph origin, ascent, advance, height, and leading, but may not include all diacritics or accents. To get the complete visual bounding box of all the glyphs in a run of text, use the TextLayout.getBounds() method of TextLayout.

Parameters:
chars - The text to measure.
begin - Index of the first character in ci to measure.
limit - Index of the last character in ci to measure.
frc - The context in which to make the precise glyph measurements.
Returns:
A bounding box covering the logical bounds of the specified text.
Throws:
IndexOutOfBoundsException - if the range [begin, limit] is invalid in chars.
Since:
1.2
See Also:
createGlyphVector(FontRenderContext, char[])

getTransform

public AffineTransform getTransform()
Returns a copy of the affine transformation this font is currently subject to, if any.

Returns:
The current transformation.

hasUniformLineMetrics

public boolean hasUniformLineMetrics()
Indicates whether this font's line metrics are uniform. A font may be composed of several "subfonts", each covering a different code range, and each with their own line metrics. A font with no subfonts, or subfonts with identical line metrics, is said to have "uniform" line metrics.

Returns:
Whether this font has uniform line metrics.
See Also:
LineMetrics, getLineMetrics(String, FontRenderContext)

isTransformed

public boolean isTransformed()
Indicates whether this font is subject to a non-identity affine transformation.

Returns:
true iff the font has a non-identity affine transformation applied to it.

layoutGlyphVector

public GlyphVector layoutGlyphVector(FontRenderContext frc,
                                     char[] chars,
                                     int start,
                                     int limit,
                                     int flags)
Produces a glyph vector representing a full layout fo the specified text in this font. Full layouts may include complex shaping and reordering operations, for scripts such as Arabic or Hindi. Bidirectional (bidi) layout is not performed in this method; text should have its bidi direction specified with one of the flags LAYOUT_LEFT_TO_RIGHT or LAYOUT_RIGHT_TO_LEFT. Some types of layout (notably Arabic glyph shaping) may examine context characters beyond the bounds of the indicated range, in order to select an appropriate shape. The flags LAYOUT_NO_START_CONTEXT and LAYOUT_NO_LIMIT_CONTEXT can be provided to prevent these extra context areas from being examined, for instance if they contain invalid characters.

Parameters:
frc - Context in which to perform the layout.
chars - Text to perform layout on.
start - Index of first character to perform layout on.
limit - Index of last character to perform layout on.
flags - Combination of flags controlling layout.
Returns:
A new GlyphVector representing the specified text.
Throws:
IndexOutOfBoundsException - if the range [begin, limit] is invalid in chars.

getPeer

public FontPeer getPeer()
Deprecated. 

Returns a native peer object for this font.

Returns:
A native peer object for this font.

hashCode

public int hashCode()
Returns a hash value for this font.

Overrides:
hashCode in class Object
Returns:
A hash for this font.
See Also:
Object.equals(Object), System.identityHashCode(Object)

equals

public boolean equals(Object obj)
Tests whether or not the specified object is equal to this font. This will be true if and only if:

Overrides:
equals in class Object
Parameters:
obj - the Object to compare to
Returns:
true if the specified object is equal to this object, false otherwise.
See Also:
Object.hashCode()

toString

public String toString()
Returns a string representation of this font.

Overrides:
toString in class Object
Returns:
A string representation of this font.
See Also:
Object.getClass(), Object.hashCode(), Class.getName(), Integer.toHexString(int)

getLineMetrics

public LineMetrics getLineMetrics(String str,
                                  FontRenderContext frc)
Determines the line metrics for a run of text.

Parameters:
str - the text run to be measured.
frc - the font rendering parameters that are used for the measurement. The exact placement and size of text slightly depends on device-specific characteristics, for instance the device resolution or anti-aliasing. For this reason, the returned measurement will only be accurate if the passed FontRenderContext correctly reflects the relevant parameters. Hence, frc should be obtained from the same Graphics2D that will be used for drawing, and any rendering hints should be set to the desired values before obtaining frc.
See Also:
Graphics2D.getFontRenderContext()

hasLayoutAttributes

public boolean hasLayoutAttributes()