GeezerVison is showing docs.oracle.com — Font (Java Platform SE 8 )
Java™ Platform Standard Ed. 8
-
-
Field Summary
Fields
| Modifier and Type |
Field |
Description |
static int |
BOLD |
The bold style constant.
|
static int |
CENTER_BASELINE |
The baseline used in ideographic scripts like Chinese, Japanese,
and Korean when laying out text.
|
static String |
DIALOG |
A String constant for the canonical family name of the
logical font "Dialog".
|
static String |
DIALOG_INPUT |
A String constant for the canonical family name of the
logical font "DialogInput".
|
static int |
HANGING_BASELINE |
The baseline used in Devanigiri and similar scripts when laying
out text.
|
static int |
ITALIC |
The italicized style constant.
|
static int |
LAYOUT_LEFT_TO_RIGHT |
A flag to layoutGlyphVector indicating that text is left-to-right as
determined by Bidi analysis.
|
static int |
LAYOUT_NO_LIMIT_CONTEXT |
A flag to layoutGlyphVector indicating that text in the char array
after the indicated limit should not be examined.
|
static int |
LAYOUT_NO_START_CONTEXT |
A flag to layoutGlyphVector indicating that text in the char array
before the indicated start should not be examined.
|
static int |
LAYOUT_RIGHT_TO_LEFT |
A flag to layoutGlyphVector indicating that text is right-to-left as
determined by Bidi analysis.
|
static String |
MONOSPACED |
A String constant for the canonical family name of the
logical font "Monospaced".
|
protected String |
name |
The logical name of this Font, as passed to the
constructor.
|
static int |
PLAIN |
The plain style constant.
|
protected float |
pointSize |
The point size of this Font in float.
|
static int |
ROMAN_BASELINE |
The baseline used in most Roman scripts when laying out text.
|
static String |
SANS_SERIF |
A String constant for the canonical family name of the
logical font "SansSerif".
|
static String |
SERIF |
A String constant for the canonical family name of the
logical font "Serif".
|
protected int |
size |
The point size of this Font, rounded to integer.
|
protected int |
style |
The style of this Font, as passed to the constructor.
|
static int |
TRUETYPE_FONT |
Identify a font resource of type TRUETYPE.
|
static int |
TYPE1_FONT |
Identify a font resource of type TYPE1.
|
-
Constructor Summary
Constructors
| Modifier |
Constructor |
Description |
protected |
Font(Font font) |
Creates a new Font from the specified font.
|
|
Font(Map<? extends AttributedCharacterIterator.Attribute,?> attributes) |
Creates a new Font with the specified attributes.
|
|
Font(String name,
int style,
int size) |
Creates a new Font from the specified name, style and
point size.
|
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
| Modifier and Type |
Method |
Description |
boolean |
canDisplay(char c) |
Checks if this Font has a glyph for the specified
character.
|
boolean |
canDisplay(int codePoint) |
Checks if this Font has a glyph for the specified
character.
|
int |
canDisplayUpTo(char[] text,
int start,
int limit) |
Indicates whether or not this Font can display
the characters in the specified text
starting at start and ending at
limit.
|
int |
canDisplayUpTo(CharacterIterator iter,
int start,
int limit) |
Indicates whether or not this Font can display the
text specified by the iter starting at
start and ending at limit.
|
int |
canDisplayUpTo(String str) |
Indicates whether or not this Font can display a
specified String.
|
static Font |
createFont(int fontFormat,
File fontFile) |
Returns a new Font using the specified font type
and the specified font file.
|
static Font |
createFont(int fontFormat,
InputStream fontStream) |
Returns a new Font using the specified font type
and input data.
|
GlyphVector |
createGlyphVector(FontRenderContext frc,
char[] chars) |
Creates a GlyphVector by
mapping characters to glyphs one-to-one based on the
Unicode cmap in this Font.
|
GlyphVector |
createGlyphVector(FontRenderContext frc,
CharacterIterator ci) |
Creates a GlyphVector by
mapping the specified characters to glyphs one-to-one based on the
Unicode cmap in this Font.
|
GlyphVector |
createGlyphVector(FontRenderContext frc,
int[] glyphCodes) |
Creates a GlyphVector by
mapping characters to glyphs one-to-one based on the
Unicode cmap in this Font.
|
GlyphVector |
createGlyphVector(FontRenderContext frc,
String str) |
Creates a GlyphVector by
mapping characters to glyphs one-to-one based on the
Unicode cmap in this Font.
|
static Font |
decode(String str) |
Returns the Font that the str
argument describes.
|
Font |
deriveFont(AffineTransform trans) |
Creates a new Font object by replicating the current
Font object and applying a new transform to it.
|
Font |
deriveFont(float size) |
Creates a new Font object by replicating the current
Font object and applying a new size to it.
|
Font |
deriveFont(int style) |
Creates a new Font object by replicating the current
Font object and applying a new style to it.
|
Font |
deriveFont(int style,
AffineTransform trans) |
Creates a new Font object by replicating this
Font object and applying a new style and transform.
|
Font |
deriveFont(int style,
float size) |
Creates a new Font object by replicating this
Font object and applying a new style and size.
|
Font |
deriveFont(Map<? extends AttributedCharacterIterator.Attribute,?> attributes) |
Creates a new Font object by replicating the current
Font object and applying a new set of font attributes
to it.
|
boolean |
equals(Object obj) |
Compares this Font object to the specified
Object.
|
Map<TextAttribute,?> |
getAttributes() |
Returns a map of font attributes available in this
Font.
|
AttributedCharacterIterator.Attribute[] |
getAvailableAttributes() |
Returns the keys of all the attributes supported by this
Font.
|
byte |
getBaselineFor(char c) |
Returns the baseline appropriate for displaying this character.
|
String |
getFamily() |
Returns the family name of this Font.
|
String |
getFamily(Locale l) |
Returns the family name of this Font, localized for
the specified locale.
|
static Font |
getFont(Map<? extends AttributedCharacterIterator.Attribute,?> attributes) |
Returns a Font appropriate to the attributes.
|
static Font |
getFont(String nm) |
Returns a Font object from the system properties list.
|
static Font |
getFont(String nm,
Font font) |
Gets the specified Font from the system properties
list.
|
String |
getFontName() |
Returns the font face name of this Font.
|
String |
getFontName(Locale l) |
Returns the font face name of the Font, localized
for the specified locale.
|
float |
getItalicAngle() |
Returns the italic angle of this Font.
|
LineMetrics |
getLineMetrics(char[] chars,
int beginIndex,
int limit,
FontRenderContext frc) |
Returns a LineMetrics object created with the
specified arguments.
|
LineMetrics |
getLineMetrics(CharacterIterator ci,
int beginIndex,
int limit,
FontRenderContext frc) |
Returns a LineMetrics object created with the
specified arguments.
|
LineMetrics |
getLineMetrics(String str,
FontRenderContext frc) |
|
LineMetrics |
getLineMetrics(String str,
int beginIndex,
int limit,
FontRenderContext frc) |
Returns a LineMetrics object created with the
specified arguments.
|
Rectangle2D |
getMaxCharBounds(FontRenderContext frc) |
Returns the bounds for the character with the maximum
bounds as defined in the specified FontRenderContext.
|
int |
getMissingGlyphCode() |
Returns the glyphCode which is used when this Font
does not have a glyph for a specified unicode code point.
|
String |
getName() |
Returns the logical name of this Font.
|
int |
getNumGlyphs() |
Returns the number of glyphs in this Font.
|
java.awt.peer.FontPeer |
getPeer() |
Deprecated.
Font rendering is now platform independent.
|
String |
getPSName() |
Returns the postscript name of this Font.
|
int |
getSize() |
Returns the point size of this Font, rounded to
an integer.
|
float |
getSize2D() |
Returns the point size of this Font in
float value.
|
Rectangle2D |
getStringBounds(char[] chars,
int beginIndex,
int limit,
FontRenderContext frc) |
Returns the logical bounds of the specified array of characters
in the specified FontRenderContext.
|
Rectangle2D |
getStringBounds(CharacterIterator ci,
int beginIndex,
int limit,
FontRenderContext frc) |
Returns the logical bounds of the characters indexed in the
specified CharacterIterator in the
specified FontRenderContext.
|
Rectangle2D |
getStringBounds(String str,
FontRenderContext frc) |
Returns the logical bounds of the specified String in
the specified FontRenderContext.
|
Rectangle2D |
getStringBounds(String str,
int beginIndex,
int limit,
FontRenderContext frc) |
Returns the logical bounds of the specified String in
the specified FontRenderContext.
|
int |
getStyle() |
Returns the style of this Font.
|
AffineTransform |
getTransform() |
Returns a copy of the transform associated with this
Font.
|
int |
hashCode() |
Returns a hashcode for this Font.
|
boolean |
hasLayoutAttributes() |
Return true if this Font contains attributes that require extra
layout processing.
|
boolean |
hasUniformLineMetrics() |
Checks whether or not this Font has uniform
line metrics.
|
boolean |
isBold() |
Indicates whether or not this Font object's style is
BOLD.
|
boolean |
isItalic() |
Indicates whether or not this Font object's style is
ITALIC.
|
boolean |
isPlain() |
Indicates whether or not this Font object's style is
PLAIN.
|
boolean |
isTransformed() |
Indicates whether or not this Font object has a
transform that affects its size in addition to the Size
attribute.
|
GlyphVector |
layoutGlyphVector(FontRenderContext frc,
char[] text,
int start,
int limit,
int flags) |
Returns a new GlyphVector object, performing full
layout of the text if possible.
|
String |
toString() |
Converts this Font object to a String
representation.
|
-
-
Field Detail
-
DIALOG_INPUT
public static final String DIALOG_INPUT
A String constant for the canonical family name of the
logical font "DialogInput". It is useful in Font construction
to provide compile-time verification of the name.
- Since:
- 1.6
- See Also:
- Constant Field Values
-
SANS_SERIF
public static final String SANS_SERIF
A String constant for the canonical family name of the
logical font "SansSerif". It is useful in Font construction
to provide compile-time verification of the name.
- Since:
- 1.6
- See Also:
- Constant Field Values
-
MONOSPACED
public static final String MONOSPACED
A String constant for the canonical family name of the
logical font "Monospaced". It is useful in Font construction
to provide compile-time verification of the name.
- Since:
- 1.6
- See Also:
- Constant Field Values
-
CENTER_BASELINE
public static final int CENTER_BASELINE
The baseline used in ideographic scripts like Chinese, Japanese,
and Korean when laying out text.
- See Also:
- Constant Field Values
-
style
protected int style
The style of this Font, as passed to the constructor.
This style can be PLAIN, BOLD, ITALIC, or BOLD+ITALIC.
- Since:
- JDK1.0
- See Also:
getStyle()
-
Method Detail
-
getPeer
@Deprecated
public java.awt.peer.FontPeer getPeer()
Deprecated. Font rendering is now platform independent.
Gets the peer of this Font.
- Returns:
- the peer of the
Font.
- Since:
- JDK1.1
-
getFontName
public String getFontName()
Returns the font face name of this Font. For example,
Helvetica Bold could be returned as a font face name.
Use getFamily to get the family name of the font.
Use getName to get the logical name of the font.
- Returns:
- a
String representing the font face name of
this Font.
- Since:
- 1.2
- See Also:
getFamily(),
getName()
-
getFontName
public String getFontName(Locale l)
Returns the font face name of the Font, localized
for the specified locale. For example, Helvetica Fett could be
returned as the font face name.
Use getFamily to get the family name of the font.
- Parameters:
l - a locale for which to get the font face name
- Returns:
- a
String representing the font face name,
localized for the specified locale.
- See Also:
getFamily(),
Locale
-
getSize
public int getSize()
Returns the point size of this Font, rounded to
an integer.
Most users are familiar with the idea of using point size to
specify the size of glyphs in a font. This point size defines a
measurement between the baseline of one line to the baseline of the
following line in a single spaced text document. The point size is
based on typographic points, approximately 1/72 of an inch.
The Java(tm)2D API adopts the convention that one point is
equivalent to one unit in user coordinates. When using a
normalized transform for converting user space coordinates to
device space coordinates 72 user
space units equal 1 inch in device space. In this case one point
is 1/72 of an inch.
- Returns:
- the point size of this
Font in 1/72 of an
inch units.
- Since:
- JDK1.0
- See Also:
getSize2D(),
GraphicsConfiguration.getDefaultTransform(),
GraphicsConfiguration.getNormalizingTransform()
-
getFont
public static Font getFont(String nm)
Returns a Font object from the system properties list.
nm is treated as the name of a system property to be
obtained. The String value of this property is then
interpreted as a Font object according to the
specification of Font.decode(String)
If the specified property is not found, or the executing code does
not have permission to read the property, null is returned instead.
- Parameters:
nm - the property name
- Returns:
- a
Font object that the property name
describes, or null if no such property exists.
- Throws:
NullPointerException - if nm is null.
- Since:
- 1.2
- See Also:
decode(String)
-
getAttributes
public Map<TextAttribute,?> getAttributes()
Returns a map of font attributes available in this
Font. Attributes include things like ligatures and
glyph substitution.
- Returns:
- the attributes map of this
Font.
-
deriveFont
public Font deriveFont(int style,
float size)
Creates a new Font object by replicating this
Font object and applying a new style and size.
- Parameters:
style - the style for the new Font
size - the size for the new Font
- Returns:
- a new
Font object.
- Since:
- 1.2
-
deriveFont
public Font deriveFont(int style,
AffineTransform trans)
Creates a new Font object by replicating this
Font object and applying a new style and transform.
- Parameters:
style - the style for the new Font
trans - the AffineTransform associated with the
new Font
- Returns:
- a new
Font object.
- Throws:
IllegalArgumentException - if trans is
null
- Since:
- 1.2
-
deriveFont
public Font deriveFont(Map<? extends AttributedCharacterIterator.Attribute,?> attributes)
Creates a new Font object by replicating the current
Font object and applying a new set of font attributes
to it.
- Parameters:
attributes - a map of attributes enabled for the new
Font
- Returns:
- a new
Font object.
- Since:
- 1.2
-
canDisplayUpTo
public int canDisplayUpTo(String str)
Indicates whether or not this Font can display a
specified String. For strings with Unicode encoding,
it is important to know if a particular font can display the
string. This method returns an offset into the String
str which is the first character this
Font cannot display without using the missing glyph
code. If the Font can display all characters, -1 is
returned.
- Parameters:
str - a String object
- Returns:
- an offset into
str that points
to the first character in str that this
Font cannot display; or -1 if
this Font can display all characters in
str.
- Since:
- 1.2
-
canDisplayUpTo
public int canDisplayUpTo(char[] text,
int start,
int limit)
Indicates whether or not this Font can display
the characters in the specified text
starting at start and ending at
limit. This method is a convenience overload.
- Parameters:
text - the specified array of char values
start - the specified starting offset (in
chars) into the specified array of
char values
limit - the specified ending offset (in
chars) into the specified array of
char values
- Returns:
- an offset into
text that points
to the first character in text that this
Font cannot display; or -1 if
this Font can display all characters in
text.
- Since:
- 1.2
-
canDisplayUpTo
public int canDisplayUpTo(CharacterIterator iter,
int start,
int limit)
Indicates whether or not this Font can display the
text specified by the iter starting at
start and ending at limit.
- Parameters:
iter - a CharacterIterator object
start - the specified starting offset into the specified
CharacterIterator.
limit - the specified ending offset into the specified
CharacterIterator.
- Returns:
- an offset into
iter that points
to the first character in iter that this
Font cannot display; or -1 if
this Font can display all characters in
iter.
- Since:
- 1.2
-
hasUniformLineMetrics
public boolean hasUniformLineMetrics()
Checks whether or not this Font has uniform
line metrics. A logical Font might be a
composite font, which means that it is composed of different
physical fonts to cover different code ranges. Each of these
fonts might have different LineMetrics. If the
logical Font is a single
font then the metrics would be uniform.
- Returns:
true if this Font has
uniform line metrics; false otherwise.
-
getLineMetrics
public LineMetrics getLineMetrics(String str,
int beginIndex,
int limit,
FontRenderContext frc)
Returns a LineMetrics object created with the
specified arguments.
- Parameters:
str - the specified String
beginIndex - the initial offset of str
limit - the end offset of str
frc - the specified FontRenderContext
- Returns:
- a
LineMetrics object created with the
specified arguments.
-
getLineMetrics
public LineMetrics getLineMetrics(char[] chars,
int beginIndex,
int limit,
FontRenderContext frc)
Returns a LineMetrics object created with the
specified arguments.
- Parameters:
chars - an array of characters
beginIndex - the initial offset of chars
limit - the end offset of chars
frc - the specified FontRenderContext
- Returns:
- a
LineMetrics object created with the
specified arguments.
-
getLineMetrics
public LineMetrics getLineMetrics(CharacterIterator ci,
int beginIndex,
int limit,
FontRenderContext frc)
Returns a LineMetrics object created with the
specified arguments.
- Parameters:
ci - the specified CharacterIterator
beginIndex - the initial offset in ci
limit - the end offset of ci
frc - the specified FontRenderContext
- Returns:
- a
LineMetrics object created with the
specified arguments.
-
getStringBounds
public Rectangle2D getStringBounds(CharacterIterator ci,
int beginIndex,
int limit,
FontRenderContext frc)
Returns the logical bounds of the characters indexed in the
specified CharacterIterator in the
specified FontRenderContext. The logical bounds
contains the origin, ascent, advance, and height, which includes
the leading. The logical bounds does not always enclose all the
text. For example, in some languages and in some fonts, accent
marks can be positioned above the ascent or below the descent.
To obtain a visual bounding box, which encloses all the text,
use the getBounds method of
TextLayout.
Note: The returned bounds is in baseline-relative coordinates
(see class notes).
- Parameters:
ci - the specified CharacterIterator
beginIndex - the initial offset in ci
limit - the end offset in ci
frc - the specified FontRenderContext
- Returns:
- a
Rectangle2D that is the bounding box of the
characters indexed in the specified CharacterIterator
in the specified FontRenderContext.
- Throws:
IndexOutOfBoundsException - if beginIndex is
less than the start index of ci, or
limit is greater than the end index of
ci, or beginIndex is greater
than limit
- Since:
- 1.2
- See Also:
FontRenderContext,
createGlyphVector(java.awt.font.FontRenderContext, java.lang.String)
-
layoutGlyphVector
public GlyphVector layoutGlyphVector(FontRenderContext frc,
char[] text,
int start,
int limit,
int flags)
Returns a new GlyphVector object, performing full
layout of the text if possible. Full layout is required for
complex text, such as Arabic or Hindi. Support for different
scripts depends on the font and implementation.
Layout requires bidi analysis, as performed by
Bidi, and should only be performed on text that
has a uniform direction. The direction is indicated in the
flags parameter,by using LAYOUT_RIGHT_TO_LEFT to indicate a
right-to-left (Arabic and Hebrew) run direction, or
LAYOUT_LEFT_TO_RIGHT to indicate a left-to-right (English)
run direction.
In addition, some operations, such as Arabic shaping, require
context, so that the characters at the start and limit can have
the proper shapes. Sometimes the data in the buffer outside
the provided range does not have valid data. The values
LAYOUT_NO_START_CONTEXT and LAYOUT_NO_LIMIT_CONTEXT can be
added to the flags parameter to indicate that the text before
start, or after limit, respectively, should not be examined
for context.
All other values for the flags parameter are reserved.
- Parameters:
frc - the specified FontRenderContext
text - the text to layout
start - the start of the text to use for the GlyphVector
limit - the limit of the text to use for the GlyphVector
flags - control flags as described above
- Returns:
- a new
GlyphVector representing the text between
start and limit, with glyphs chosen and positioned so as to best represent
the text
- Throws:
ArrayIndexOutOfBoundsException - if start or limit is
out of bounds
- Since:
- 1.4
- See Also:
Bidi,
LAYOUT_LEFT_TO_RIGHT,
LAYOUT_RIGHT_TO_LEFT,
LAYOUT_NO_START_CONTEXT,
LAYOUT_NO_LIMIT_CONTEXT
Java™ Platform Standard Ed. 8
Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Copyright © 1993, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
|