java.awt
public class Font extends Object implements Serializable
Field Summary | |
---|---|
static int | BOLD
Constant indicating a "bold" font. |
static int | CENTER_BASELINE
Constant indicating the baseline mode characteristic of Chinese. |
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.
|
protected String | name
The logical name of this font.
|
protected float | pointSize
The size of this font in points.
|
static int | PLAIN
Constant indicating a "plain" font. |
static int | ROMAN_BASELINE
Constant indicating the baseline mode characteristic of Roman. |
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 | |
---|---|
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 | |
---|---|
boolean | canDisplay(char c)
Checks if specified character maps to a glyph in this font.
|
int | canDisplayUpTo(String s)
Checks how much of a given string can be mapped to glyphs in
this font.
|
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.
|
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. |
static Font | createFont(int fontFormat, File file)
Creates a new font from a File object.
|
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. |
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. |
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. |
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.
|
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. |
Font | deriveFont(int style, float size)
Produces a new {@link Font} based on the current font, adjusted to a
new size and style.
|
Font | deriveFont(float size)
Produces a new {@link Font} based on the current font, adjusted to a
new size.
|
Font | deriveFont(int style)
Produces a new {@link Font} based on the current font, adjusted to a
new style.
|
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.
|
Font | deriveFont(AffineTransform a)
Produces a new {@link Font} based on the current font, subjected
to a new affine transformation.
|
Font | deriveFont(Map<? extends AttributedCharacterIterator.Attribute,?> attributes)
Produces a new {@link 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 {@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.
|
String | getFamily()
Returns the family name of this font. |
String | getFamily(Locale lc)
Returns the family name of this font. |
static Font | getFont(String propname, Font defval)
Returns a Font object from the passed property name.
|
static Font | getFont(String propname)
Returns a Font object from the passed property name.
|
static Font | getFont(Map<? extends AttributedCharacterIterator.Attribute,?> attributes)
Returns a font appropriate for the given attribute set.
|
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 {@link #ITALIC}. |
LineMetrics | getLineMetrics(String text, int begin, int limit, FontRenderContext rc)
Returns a {@link LineMetrics} object constructed with the specified
text and {@link FontRenderContext}.
|
LineMetrics | getLineMetrics(char[] chars, int begin, int limit, FontRenderContext rc)
Returns a {@link LineMetrics} object constructed with the specified
text and {@link FontRenderContext}.
|
LineMetrics | getLineMetrics(CharacterIterator ci, int begin, int limit, FontRenderContext rc)
Returns a {@link LineMetrics} object constructed with the specified
text and {@link FontRenderContext}.
|
LineMetrics | getLineMetrics(String str, FontRenderContext frc)
Determines the line metrics for a run of text.
|
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}
|
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()
Returns a native peer object for this font.
|
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(String str, FontRenderContext frc)
Returns the logical bounds of the specified string when rendered with this
font in the specified {@link 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 {@link 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 {@link FontRenderContext}. |
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}. |
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}.
|
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 | 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.
|
layoutGlyphVector
, indicating that the
orientation of a text run is from left to right.
Since: 1.4
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
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
layoutGlyphVector
, indicating that the
orientation of a text run is from right to left.
Since: 1.4
Since: 1.0
Since: 1.0
Since: 1.0
Since: 1.0
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
createFont
that the supplied font data
is in Type1 format.
Since: 1.5
Font
with the specified
attributes.
Parameters: name The name of the font. style The font style. size The font point size.
Parameters: c The character to check.
Returns: Whether the character has a corresponding glyph in this font.
Since: 1.2
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
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
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
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
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
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.
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.
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.
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.
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.
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
Parameters: size The size of the newly created font.
Returns: A clone of the current font, with the specified size.
Since: 1.2
Parameters: style The style of the newly created font.
Returns: A clone of the current font, with the specified style.
Since: 1.2
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
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
Parameters: attributes Attributes of the newly created font.
Returns: A clone of the current font, with the specified attributes.
Since: 1.2
null
.
Font
.
Returns: true
if the specified object is equal to this
object, false
otherwise.
Returns: A map of chracter attributes which this font currently has set.
See Also: getAvailableAttributes Attribute TextAttribute
Returns: An array of chracter attribute keys which this font understands.
See Also: getAttributes Attribute TextAttribute
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
Returns: A string containing the font family name.
Since: 1.2
See Also: getName getFontName getAvailableFontFamilyNames
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
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.
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.
Parameters: attributes The attributes required for the new font.
Returns: A new Font with the given attributes.
Since: 1.2
See Also: TextAttribute
Returns: The font face name of the font.
Since: 1.2
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
Returns: The italic angle.
See Also: POSTURE
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
.
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
.
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
.
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
Parameters: rc Context in which to evaluate bounding boxes.
Returns: The maximal bounding box.
Returns: The missing glyph code.
Since: 1.2
Returns: The logical name of the font.
See Also: getFamily getFontName
[ 0, getNumGlyphs() - 1 ]
.
Returns: The number of glyphs in this font.
Since: 1.2
Deprecated:
Returns a native peer object for this font.Returns: A native peer object for this font.
Returns: The PostScript Name of this font.
Since: 1.2
See Also: getName getFamily getFontName
Returns: The font size
Returns: The font size
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
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
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
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[])
Returns: code representing the style of this font.
Returns: The current transformation.
Returns: A hash for this font.
Returns: Whether this font has uniform line metrics.
See Also: LineMetrics Font
Returns: true
if this font is bold, false
otherwise.
Returns: true
if this font is italic, false
otherwise.
Returns: true
if this is a plain font, false
otherwise.
Returns: true
iff the font has a non-identity affine
transformation applied to it.
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
.
Returns: A string representation of this font.