java.awt

Class Font

Implemented Interfaces:
Serializable
Known Direct 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
static int
PLAIN
Constant indicating a "plain" font.
static int
ROMAN_BASELINE
Constant indicating the baseline mode characteristic of Roman.
static String
SANS_SERIF
static String
SERIF
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.
protected String
name
The logical name of this font.
protected float
pointSize
The size of this font in points.
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.

Constructor Summary

Font(extends AttributedCharacterIterator.Attribute, ?> attrs)
Font(Font font)
Font(String name, int style, int size)
Initializes a new instance of Font with the specified attributes.

Method Summary

Map
?> getAttributes()
Returns a map of chracter attributes which this font currently has set.
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(String s)
Checks how much of a given string 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.
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, 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.
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.
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(extends AttributedCharacterIterator.Attribute, ?> attributes)
Produces a new Font based on the current font, adjusted to a new set of attributes.
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, float size)
Produces a new Font based on the current font, adjusted to a new size and 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(AffineTransform a)
Produces a new Font based on the current font, subjected to a new affine transformation.
boolean
equals(Object obj)
Tests whether or not the specified object is equal to this font.
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(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(String text, 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(CharacterIterator ci, 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.
String
getPSName()
Returns the PostScript Name of this font.
FontPeer
getPeer()
Deprecated.
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(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.
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(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.
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.
boolean
hasLayoutAttributes()
boolean
hasUniformLineMetrics()
Indicates whether this font's line metrics are uniform.
int
hashCode()
Returns a hash value for this font.
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, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

BOLD

public static final int BOLD
Constant indicating a "bold" font.
Field Value:
1

CENTER_BASELINE

public static final int CENTER_BASELINE
Constant indicating the baseline mode characteristic of Chinese.
Field Value:
1

DIALOG

public static final String DIALOG
Field Value:
"Dialog"
Since:
1.6

DIALOG_INPUT

public static final String DIALOG_INPUT
Field Value:
"DialogInput"
Since:
1.6

HANGING_BASELINE

public static final int HANGING_BASELINE
Constant indicating the baseline mode characteristic of Devanigri.
Field Value:
2

ITALIC

public static final int ITALIC
Constant indicating an "italic" font.
Field Value:
2

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.
Field Value:
0
Since:
1.4

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).
Field Value:
4
Since:
1.4

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).
Field Value:
2
Since:
1.4

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.
Field Value:
1
Since:
1.4

MONOSPACED

public static final String MONOSPACED
Field Value:
"Monospaced"
Since:
1.6

PLAIN

public static final int PLAIN
Constant indicating a "plain" font.
Field Value:
0

ROMAN_BASELINE

public static final int ROMAN_BASELINE
Constant indicating the baseline mode characteristic of Roman.
Field Value:
0

SANS_SERIF

public static final String SANS_SERIF
Field Value:
"SansSerif"
Since:
1.6

SERIF

public static final String SERIF
Field Value:
"Serif"
Since:
1.6

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.

Field Value:
0
Since:
1.3

TYPE1_FONT

public static final int TYPE1_FONT
Indicates to createFont that the supplied font data is in Type1 format.
Field Value:
1
Since:
1.5

name

protected String name
The logical name of this font.
Since:
1.0

pointSize

protected float pointSize
The size of this font in points.
Since:
1.0

size

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

style

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

Constructor Details

Font

public Font(extends AttributedCharacterIterator.Attribute,
            ?> attrs)

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.

Method Details

?> getAttributes

public Map?> 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.

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(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(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(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,
                              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

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

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.

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.

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.

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.

decode

public 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. 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.

deriveFont

public Font deriveFont(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

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,
                       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(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

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:

  • The object is not null.
  • The object is an instance of Font.
  • The object has the same names, style, size, and transform as this object.
Overrides:
equals in interface Object
Returns:
true if the specified object is equal to this object, false otherwise.

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.

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

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

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

getFont

public static Font getFont(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

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.

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.

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

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

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.

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(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(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.

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

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.

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

getPeer

public FontPeer getPeer()

Deprecated.

Returns a native peer object for this font.
Returns:
A native peer object for this font.

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

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

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

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.

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

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.

getTransform

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

hasLayoutAttributes

public boolean hasLayoutAttributes()

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.

hashCode

public int hashCode()
Returns a hash value for this font.
Overrides:
hashCode in interface Object
Returns:
A hash for this font.

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.

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.

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.

toString

public String toString()
Returns a string representation of this font.
Overrides:
toString in interface Object
Returns:
A string representation of this font.

Font.java -- Font object Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.