java.awt

Class Font

public class Font extends Object implements Serializable

This class represents a windowing system font.
Field Summary
static intBOLD
Constant indicating a "bold" font.
static intCENTER_BASELINE
Constant indicating the baseline mode characteristic of Chinese.
static intHANGING_BASELINE
Constant indicating the baseline mode characteristic of Devanigri.
static intITALIC
Constant indicating an "italic" font.
static intLAYOUT_LEFT_TO_RIGHT
A flag for layoutGlyphVector, indicating that the orientation of a text run is from left to right.
static intLAYOUT_NO_LIMIT_CONTEXT
A flag for layoutGlyphVector, indicating that the text does not contain valid characters after the limit position.
static intLAYOUT_NO_START_CONTEXT
A flag for layoutGlyphVector, indicating that the text does not contain valid characters before the start position.
static intLAYOUT_RIGHT_TO_LEFT
A flag for layoutGlyphVector, indicating that the orientation of a text run is from right to left.
protected Stringname
The logical name of this font.
protected floatpointSize
The size of this font in points.
static intPLAIN
Constant indicating a "plain" font.
static intROMAN_BASELINE
Constant indicating the baseline mode characteristic of Roman.
protected intsize
The size of this font in points, rounded.
protected intstyle
The style of this font -- PLAIN, BOLD, ITALIC or BOLD+ITALIC.
static intTRUETYPE_FONT
Indicates to createFont that the supplied font data is in TrueType format.
static intTYPE1_FONT
Indicates to createFont that the supplied font data is in Type1 format.
Constructor Summary
Font(String name, int style, int size)
Initializes a new instance of Font with the specified attributes.
Font(Map<? extends AttributedCharacterIterator.Attribute,?> attrs)
Method Summary
booleancanDisplay(char c)
Checks if specified character maps to a glyph in this font.
intcanDisplayUpTo(String s)
Checks how much of a given string can be mapped to glyphs in this font.
intcanDisplayUpTo(char[] text, int start, int limit)
Checks how much of a given sequence of text can be mapped to glyphs in this font.
intcanDisplayUpTo(CharacterIterator i, int start, int limit)
Checks how much of a given sequence of text can be mapped to glyphs in this font.
static FontcreateFont(int fontFormat, InputStream is)
Creates a new font with point size 1 and {@link #PLAIN} style, reading font data from the provided input stream.
static FontcreateFont(int fontFormat, File file)
Creates a new font from a File object.
GlyphVectorcreateGlyphVector(FontRenderContext ctx, String str)
Maps characters to glyphs in a one-to-one relationship, returning a new {@link GlyphVector} with a mapped glyph for each input character.
GlyphVectorcreateGlyphVector(FontRenderContext ctx, CharacterIterator i)
Maps characters to glyphs in a one-to-one relationship, returning a new {@link GlyphVector} with a mapped glyph for each input character.
GlyphVectorcreateGlyphVector(FontRenderContext ctx, char[] chars)
Maps characters to glyphs in a one-to-one relationship, returning a new {@link GlyphVector} with a mapped glyph for each input character.
GlyphVectorcreateGlyphVector(FontRenderContext ctx, int[] glyphCodes)
Extracts a sequence of glyphs from a font, returning a new {@link GlyphVector} with a mapped glyph for each input glyph code.
static Fontdecode(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.

FontderiveFont(int style, float size)
Produces a new {@link Font} based on the current font, adjusted to a new size and style.
FontderiveFont(float size)
Produces a new {@link Font} based on the current font, adjusted to a new size.
FontderiveFont(int style)
Produces a new {@link Font} based on the current font, adjusted to a new style.
FontderiveFont(int style, AffineTransform a)
Produces a new {@link Font} based on the current font, adjusted to a new style and subjected to a new affine transformation.
FontderiveFont(AffineTransform a)
Produces a new {@link Font} based on the current font, subjected to a new affine transformation.
FontderiveFont(Map<? extends AttributedCharacterIterator.Attribute,?> attributes)
Produces a new {@link Font} based on the current font, adjusted to a new set of attributes.
booleanequals(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.
bytegetBaselineFor(char c)
Returns a baseline code (one of {@link #ROMAN_BASELINE}, {@link #CENTER_BASELINE} or {@link #HANGING_BASELINE}) indicating which baseline this font will measure baseline offsets for, when presenting glyph metrics for a given character.
StringgetFamily()
Returns the family name of this font.
StringgetFamily(Locale lc)
Returns the family name of this font.
static FontgetFont(String propname, Font defval)
Returns a Font object from the passed property name.
static FontgetFont(String propname)
Returns a Font object from the passed property name.
static FontgetFont(Map<? extends AttributedCharacterIterator.Attribute,?> attributes)
Returns a font appropriate for the given attribute set.
StringgetFontName()
Returns the font face name of the font.
StringgetFontName(Locale lc)
Returns the font face name of the font.
floatgetItalicAngle()
Returns the italic angle of this font, a measurement of its slant when style is {@link #ITALIC}.
LineMetricsgetLineMetrics(String text, int begin, int limit, FontRenderContext rc)
Returns a {@link LineMetrics} object constructed with the specified text and {@link FontRenderContext}.
LineMetricsgetLineMetrics(char[] chars, int begin, int limit, FontRenderContext rc)
Returns a {@link LineMetrics} object constructed with the specified text and {@link FontRenderContext}.
LineMetricsgetLineMetrics(CharacterIterator ci, int begin, int limit, FontRenderContext rc)
Returns a {@link LineMetrics} object constructed with the specified text and {@link FontRenderContext}.
LineMetricsgetLineMetrics(String str, FontRenderContext frc)
Determines the line metrics for a run of text.
Rectangle2DgetMaxCharBounds(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 {@link FontRenderContext}
intgetMissingGlyphCode()
Returns the glyph code this font uses to represent missing glyphs.
StringgetName()
Returns the logical name of the font.
intgetNumGlyphs()
Returns the overall number of glyphs in this font.
FontPeergetPeer()
Returns a native peer object for this font.
StringgetPSName()
Returns the PostScript Name of this font.
intgetSize()
Returns the size of the font, in typographics points (1/72 of an inch), rounded to an integer.
floatgetSize2D()
Returns the size of the font, in typographics points (1/72 of an inch).
Rectangle2DgetStringBounds(String str, FontRenderContext frc)
Returns the logical bounds of the specified string when rendered with this font in the specified {@link FontRenderContext}.
Rectangle2DgetStringBounds(String str, int begin, int limit, FontRenderContext frc)
Returns the logical bounds of the specified string when rendered with this font in the specified {@link FontRenderContext}.
Rectangle2DgetStringBounds(CharacterIterator ci, int begin, int limit, FontRenderContext frc)
Returns the logical bounds of the specified string when rendered with this font in the specified {@link FontRenderContext}.
Rectangle2DgetStringBounds(char[] chars, int begin, int limit, FontRenderContext frc)
Returns the logical bounds of the specified string when rendered with this font in the specified {@link FontRenderContext}.
intgetStyle()
Returns integer code representing the sum of style flags of this font, a combination of either {@link #PLAIN}, {@link #BOLD}, or {@link #ITALIC}.
AffineTransformgetTransform()
Returns a copy of the affine transformation this font is currently subject to, if any.
inthashCode()
Returns a hash value for this font.
booleanhasUniformLineMetrics()
Indicates whether this font's line metrics are uniform.
booleanisBold()
Tests whether or not this font is bold.
booleanisItalic()
Tests whether or not this font is italic.
booleanisPlain()
Tests whether or not this is a plain font.
booleanisTransformed()
Indicates whether this font is subject to a non-identity affine transformation.
GlyphVectorlayoutGlyphVector(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.
StringtoString()
Returns a string representation of this font.

Field Detail

BOLD

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

CENTER_BASELINE

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

HANGING_BASELINE

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

ITALIC

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

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

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

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

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

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

PLAIN

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

ROMAN_BASELINE

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

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

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

TYPE1_FONT

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

Since: 1.5

Constructor Detail

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

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

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)
Creates a new font with point size 1 and {@link #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 {@link #TRUETYPE_FONT}. is {@link InputStream} from which font data will be read. This stream is not closed after font data is extracted.

Returns: A new {@link 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)
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 {@link #TRUETYPE_FONT}. file - a {@link File} from which font data will be read.

Returns: A new {@link 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: (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 {@link 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 {@link GlyphVector} containing glyphs mapped from str, through the font's cmap table.

See Also: (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 {@link 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 {@link GlyphVector} containing glyphs mapped from str, through the font's cmap table.

See Also: (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 {@link 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 {@link GlyphVector} containing glyphs mapped from str, through the font's cmap table.

See Also: (FontRenderContext, char[], int, int, int)

createGlyphVector

public GlyphVector createGlyphVector(FontRenderContext ctx, int[] glyphCodes)
Extracts a sequence of glyphs from a font, returning a new {@link 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 {@link GlyphVector} containing glyphs mapped from str, through the font's cmap table.

See Also: (FontRenderContext, char[], int, int, int)

UNKNOWN: This method is documented to perform character-to-glyph conversions, in the Sun documentation, but its second parameter name is "glyphCodes" and it is not clear to me why it would exist if its purpose was to transport character codes inside integers. I assume it is mis-documented in the Sun documentation.

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.

deriveFont

public Font deriveFont(int style, float size)
Produces a new {@link 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 {@link 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 {@link 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 {@link 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 {@link 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 {@link 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

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:

Returns: true if the specified object is equal to this object, false otherwise.

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 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 Attribute TextAttribute

getBaselineFor

public byte getBaselineFor(char c)
Returns a baseline code (one of {@link #ROMAN_BASELINE}, {@link #CENTER_BASELINE} or {@link #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: getBaselineOffsets

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 getAvailableFontFamilyNames

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 getAvailableFontFamilyNames Locale

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.

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 {@link #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: POSTURE

getLineMetrics

public LineMetrics getLineMetrics(String text, int begin, int limit, FontRenderContext rc)
Returns a {@link LineMetrics} object constructed with the specified text and {@link 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 {@link 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 {@link LineMetrics} object constructed with the specified text and {@link 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 {@link 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 {@link LineMetrics} object constructed with the specified text and {@link 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 {@link LineMetrics} object.

Throws: IndexOutOfBoundsException if the range [begin, limit] is invalid in ci.

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: getFontRenderContext

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 {@link 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.

See Also: getFamily getFontName

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

getPeer

public FontPeer getPeer()

Deprecated:

Returns a native peer object for this font.

Returns: A native peer object for this font.

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

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(String str, FontRenderContext frc)
Returns the logical bounds of the specified string when rendered with this font in the specified {@link 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 {@link TextLayout#getBounds} method of {@link 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: Font

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 {@link 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 {@link TextLayout#getBounds} method of {@link 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: Font

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 {@link 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 {@link TextLayout#getBounds} method of {@link 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: Font

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 {@link 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 {@link TextLayout#getBounds} method of {@link 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: (FontRenderContext, char[])

getStyle

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

Returns: code representing the style of this font.

See Also: isPlain isBold isItalic

getTransform

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

Returns: The current transformation.

hashCode

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

Returns: A hash for this font.

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 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 {@link #LAYOUT_LEFT_TO_RIGHT} or {@link #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 {@link #LAYOUT_NO_START_CONTEXT} and {@link #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 {@link 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.

Returns: A string representation of this font.