Spec-Zone .ru
спецификации, руководства, описания, API
|
|
JavaTM 2 Platform Standard Edition |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Font
The Font
class represents fonts. The capabilities of this
class have been extended over the java.awt.Font class in JDK(tm) 1.1
and earlier releases to provide for developers the ability to utilize
more sophisticated typographic features.
It is important to present the concepts behind using the words character and glyph separately. A character is a symbol that represents items like letters and numbers in a particular writing system. For example, lowercase-g is a character. When a particular character has been rendered, a shape now represents this character. This shape is called a glyph.
Chararcter encoding is a conversion table that maps character codes
to glyph codes in the font. The character encoding used in the
Java(tm) 2D API is Unicode. For more information on Unicode you can
visit the site
Characters and glyphs do not have one-to-one correspondence. For example, lowercase-a acute can be represented by two glyphs: lowercase-a and acute. Another example is ligatures such as ligature -fi which is a single glyph representing two characters, f and i.
A Font
is a collection of glyphs. A Font
can have many faces, such as heavy, medium, oblique, gothic and
regular. All of these faces have similar typographic design.
There are three different names that you can get from a
Font
object. The logical font name is the same as
that used by java.awt.Font in JDK 1.1 and earlier releases.
The font face name, or just font name for
short, is the name of a particular font face, like Helvetica Bold. The
family name is the name of the font family that determines the
typographic design across several faces, like Helvetica. The font face
name is the one that should be used to specify fonts. This name
signifies actual fonts in the host system, and does not identify font
names with the shape of font characters as the logical font name does.
The Font
class represents an instance of a font face from
a collection of font faces that are present in the system resources
of the host system. As examples, Arial Bold and Courier Bold Italic
are font faces. There can be several Font
objects
associated with a font face, each differing in size, style, transform
and font features.
The getAllFonts
method
of the GraphicsEnvironment
class returns an
array of all font faces available in the system. These font faces are
returned as Font
objects with a size of 1, identity
transform and default font features. These
base fonts can then be used to derive new Font
objects
with varying sizes, styles, transforms and font features via the
deriveFont
methods in this class.
GraphicsEnvironment.getAllFonts()
, Serialized FormField Summary | |
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 int |
HANGING_BASELINE
The baseline used in Devanigiri and similar scripts when laying out text |
static int |
ITALIC
The italicized style constant. |
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 |
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. |
Constructor Summary | |
Font(Map 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 | |
boolean |
canDisplay(char c)
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 specified String . |
int |
canDisplayUpTo(String str)
Indicates whether or not this Font can display a
specified String . |
GlyphVector |
createGlyphVector(FontRenderContext frc,
char[] chars)
Returns a new GlyphVector object created with the
specified array of characters and the specified
FontRenderContext . |
GlyphVector |
createGlyphVector(FontRenderContext frc,
CharacterIterator ci)
Returns a new GlyphVector object created with the
specified CharacterIterator and the specified
FontRenderContext . |
GlyphVector |
createGlyphVector(FontRenderContext frc,
int[] glyphCodes)
Returns a new GlyphVector object created with the
specified integer array and the specified
FontRenderContext . |
GlyphVector |
createGlyphVector(FontRenderContext frc,
String str)
Returns a new GlyphVector object created with the
specified String and the specified
FontRenderContext . |
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 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 . |
protected void |
finalize()
Disposes the native Font object. |
Map |
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 attributes)
Returns a Font appropriate to this attribute set. |
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)
Returns a LineMetrics object created with the specified
String and FontRenderContext . |
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. |
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 bounds of the specified array of characters in the specified FontRenderContext . |
Rectangle2D |
getStringBounds(CharacterIterator ci,
int beginIndex,
int limit,
FontRenderContext frc)
Returns the bounds of the characters indexed in the specified CharacterIterator in the
specified FontRenderContext . |
Rectangle2D |
getStringBounds(String str,
FontRenderContext frc)
Returns the bounds of the specified String in the
specified FontRenderContext . |
Rectangle2D |
getStringBounds(String str,
int beginIndex,
int limit,
FontRenderContext frc)
Returns the 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 |
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. |
String |
toString()
Converts this Font object to a String
representation. |
Methods inherited from class java.lang.Object |
clone,
getClass,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
public static final int PLAIN
public static final int BOLD
public static final int ITALIC
public static final int ROMAN_BASELINE
public static final int CENTER_BASELINE
public static final int HANGING_BASELINE
protected String name
Font
, as passed to the
constructor.getName()
protected int style
Font
, as passed to the constructor.
This style can be PLAIN, BOLD, ITALIC, or BOLD+ITALIC.getStyle()
protected int size
Font
, rounded to integer.getSize()
protected float pointSize
Font
in float
.getSize()
,
getSize2D()
Constructor Detail |
public Font(String name, int style, int size)
Font
from the specified name, style and
point size.name
- the font name. This can be a logical font name or a
font face name. A logical name must be either: Dialog, DialogInput,
Monospaced, Serif, SansSerif, or Symbol.style
- the style constant for the Font
The style argument is an integer bitmask that may
be PLAIN, or a bitwise union of BOLD and/or ITALIC
(for example, ITALIC or BOLD|ITALIC). Any other
bits set in the style parameter are ignored.
If the style argument does not conform to one of the expected
integer bitmasks then the style is set to PLAIN.size
- the point size of the Font
GraphicsEnvironment.getAllFonts()
,
GraphicsEnvironment.getAvailableFontFamilyNames()
public Font(Map attributes)
Font
with the specified attributes.
This Font
only recognizes keys defined in
TextAttribute
as attributes. If attributes
is null
, a new Font
is initialized
with default attributes.attributes
- the attributes to assign to the new
Font
, or null
Method Detail |
public java.awt.peer.FontPeer getPeer()
Font
.Font
.public static Font getFont(Map attributes)
Font
appropriate to this attribute set.attributes
- the attributes to assign to the new
Font
Font
created with the specified
attributes.public AffineTransform getTransform()
Font
.an
- AffineTransform
object representing the
transform attribute of this Font
object.public String getFamily()
Font
. For example,
Helvetica could be returned as a family name for the font
face name of Helvetica Bold.
Use getName
to get the logical name of the font.
Use getFontName
to get the font face name of the font.String
that is the family name of this
Font
.getName()
,
getFontName()
public String getFamily(Locale l)
Font
, localized for
the specified locale. For example, Helvetica could be returned as a
family name for the font face name of Helvetica Bold.
Use getFontName
to get the font face name of the font.l
- locale for which to get the family nameString
representing the family name of the
font, localized for the specified locale.getFontName()
,
Locale
public String getPSName()
Font
.
Use getFamily
to get the family name of the font.
Use getFontName
to get the font face name of the font.String
representing the postscript name of
this Font
.public String getName()
Font
.
Use getFamily
to get the family name of the font.
Use getFontName
to get the font face name of the font.String
representing the logical name of
this Font
.getFamily()
,
getFontName()
public String getFontName()
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.String
representing the font face name of
this Font
.getFamily()
,
getName()
public String getFontName(Locale l)
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.l
- a locale for which to get the font face nameString
representing the font face name,
localized for the specified locale.getFamily()
,
Locale
public int getStyle()
Font
. The style can be
PLAIN, BOLD, ITALIC, or BOLD+ITALIC.Font
isPlain()
,
isBold()
,
isItalic()
public int getSize()
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.
Font
in 1/72 of an
inch units.getSize2D()
,
GraphicsConfiguration.getDefaultTransform()
,
GraphicsConfiguration.getNormalizingTransform()
public float getSize2D()
Font
in
float
value.Font
as a
float
value.getSize()
public boolean isPlain()
Font
object's style is
PLAIN.true
if this Font
has a
PLAIN sytle;
false
otherwise.getStyle()
public boolean isBold()
Font
object's style is
BOLD.true
if this Font
object's
style is BOLD;
false
otherwise.getStyle()
public boolean isItalic()
Font
object's style is
ITALIC.true
if this Font
object's
style is ITALIC;
false
otherwise.getStyle()
public static Font getFont(String nm)
Font
object from the system properties list.nm
- the property nameFont
object that the property name
describes.public static Font decode(String str)
Font
that the str
argument describes. If str
is null
,
a new Font
is returned with the name "dialog", a
size of 12 and a PLAIN style.str
- the name of the font, or null
Font
object that str
describes, or a new default Font
if
str
is null
.public static Font getFont(String nm, Font font)
Font
from the system properties
list. As in the getProperty
method of
System
, the first
argument 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.
The property value should be one of the following forms:
"BOLD"
, "BOLDITALIC"
, or
"ITALIC"
, and point size is a decimal
representation of the point size.
The default style is PLAIN
. The default point size
is 12.
If the specified property is not found, the font
argument is returned instead.
nm
- the property namefont
- a default Font
to return if property
nm
is not definedFont
value of the property.public int hashCode()
Font
.Font
.public boolean equals(Object obj)
Font
object to the specified
Object
.obj
- the Object
to compare.true
if the objects are the same;
false
otherwise.public String toString()
Font
object to a String
representation.String
representation of this
Font
object.public int getNumGlyphs()
Font
. Glyph codes
for this Font
range from 0 to
getNumGlyphs()
- 1.Font
.public int getMissingGlyphCode()
Font
does not have a glyph for a specified unicode.Font
.public byte getBaselineFor(char c)
Large fonts can support different writing systems, and each system can use a different baseline. The character argument determines the writing system to use. Clients should not assume all characters use the same baseline.
c
- a character used to identify the writing systemLineMetrics.getBaselineOffsets()
,
ROMAN_BASELINE
,
CENTER_BASELINE
,
HANGING_BASELINE
public Map getAttributes()
Font
. Attributes include things like ligatures and
glyph substitution.Font
.public AttributedCharacterIterator.Attribute[] getAvailableAttributes()
Font
. These attributes can be used to derive other
fonts.Font
.public Font deriveFont(int style, float size)
Font
object by replicating this
Font
object and applying a new style and size.style
- the style for the new Font
size
- the size for the new Font
Font
object.public Font deriveFont(int style, AffineTransform trans)
Font
object by replicating this
Font
object and applying a new style and transform.style
- the style for the new Font
trans
- the AffineTransform
associated with the
new Font
Font
object.public Font deriveFont(float size)
Font
object by replicating the current
Font
object and applying a new size to it.size
- the size for the new Font
.Font
object.public Font deriveFont(AffineTransform trans)
Font
object by replicating the current
Font
object and applying a new transform to it.trans
- the AffineTransform
associated with the
new Font
Font
object.public Font deriveFont(int style)
Font
object by replicating the current
Font
object and applying a new style to it.style
- the style for the new Font
Font
object.public Font deriveFont(Map attributes)
Font
object by replicating the current
Font
object and applying a new set of font attributes
to it.attributes
- a map of attributes enabled for the new
Font
Font
object.public boolean canDisplay(char c)
Font
has a glyph for the specified
character.c
- a unicode character codetrue
if this Font
can display the
character; false
otherwise.public int canDisplayUpTo(String str)
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.str
- a String
objectstr
that points
to the first character in str
that this
Font
cannot display; or -1
if
this Font
can display all characters in
str
.public int canDisplayUpTo(char[] text, int start, int limit)
Font
can display
the characters in the specified text
starting at start
and ending at
limit
. This method is a convenience overload.text
- the specified array of charactersstart
- the specified starting offset into the specified array
of characterslimit
- the specified ending offset into the specified
array of characterspublic int canDisplayUpTo(CharacterIterator iter, int start, int limit)
Font
can display
the 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 this Font
can display all
characters, -1
is returned.text
- a CharacterIterator
objectstart
- the specified starting offset into the specified array
of characterslimit
- the specified ending offset into the specified
array of charactersString
object that can be
displayed by this Font
.public float getItalicAngle()
Font
.Font
.public boolean hasUniformLineMetrics()
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.true
if this Font
has
uniform line metrics; false
otherwise.public LineMetrics getLineMetrics(String str, FontRenderContext frc)
LineMetrics
object created with the specified
String
and FontRenderContext
.str
- the specified String
frc
- the specified FontRenderContext
LineMetrics
object created with the
specified String
and FontRenderContext
.public LineMetrics getLineMetrics(String str, int beginIndex, int limit, FontRenderContext frc)
LineMetrics
object created with the
specified arguments.str
- the specified String
beginIndex
- the initial offset of str
limit
- the end offset of str
frc
- the specified FontRenderContext
LineMetrics
object created with the
specified arguments.public LineMetrics getLineMetrics(char[] chars, int beginIndex, int limit, FontRenderContext frc)
LineMetrics
object created with the
specified arguments.chars
- an array of charactersbeginIndex
- the initial offset of chars
limit
- the end offset of chars
frc
- the specified FontRenderContext
LineMetrics
object created with the
specified arguments.public LineMetrics getLineMetrics(CharacterIterator ci, int beginIndex, int limit, FontRenderContext frc)
LineMetrics
object created with the
specified arguments.ci
- the specified CharacterIterator
beginIndex
- the initial offset in ci
limit
- the end offset of ci
frc
- the specified FontRenderContext
LineMetrics
object created with the
specified arguments.public Rectangle2D getStringBounds(String str, FontRenderContext frc)
String
in the
specified FontRenderContext
. The bounds is used
to layout the String
.str
- the specified String
frc
- the specified FontRenderContext
Rectangle2D
that is the bounding box of the
specified String
in the specified
FontRenderContext
.FontRenderContext
,
createGlyphVector(java.awt.font.FontRenderContext, java.lang.String)
public Rectangle2D getStringBounds(String str, int beginIndex, int limit, FontRenderContext frc)
String
in the
specified FontRenderContext
. The bounds is used
to layout the String
.str
- the specified String
beginIndex
- the initial offset of str
limit
- the end offset of str
frc
- the specified FontRenderContext
Rectangle2D
that is the bounding box of the
specified String
in the specified
FontRenderContext
.beginIndex
is
less than zero, or limit
is greater than the
length of str
, or beginIndex
is greater than limit
.FontRenderContext
,
createGlyphVector(java.awt.font.FontRenderContext, java.lang.String)
public Rectangle2D getStringBounds(char[] chars, int beginIndex, int limit, FontRenderContext frc)
FontRenderContext
.
The bounds is used to layout the String
created with the specified array of characters,
beginIndex
and limit
.chars
- an array of charactersbeginIndex
- the initial offset in the array of
characterslimit
- the end offset in the array of charactersfrc
- the specified FontRenderContext
Rectangle2D
that is the bounding box of the
specified array of characters in the specified
FontRenderContext
.beginIndex
is
less than zero, or limit
is greater than the
length of chars
, or beginIndex
is greater than limit
.FontRenderContext
,
createGlyphVector(java.awt.font.FontRenderContext, java.lang.String)
public Rectangle2D getStringBounds(CharacterIterator ci, int beginIndex, int limit, FontRenderContext frc)
CharacterIterator
in the
specified FontRenderContext
. The bounds is used
to layout the String
.ci
- the specified CharacterIterator
beginIndex
- the initial offset in ci
limit
- the end offset in ci
frc
- the specified FontRenderContext
Rectangle2D
that is the bounding box of the
characters indexed in the specified CharacterIterator
in the specified FontRenderContext
.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
FontRenderContext
,
createGlyphVector(java.awt.font.FontRenderContext, java.lang.String)
public Rectangle2D getMaxCharBounds(FontRenderContext frc)
FontRenderContext
.frc
- the specified FontRenderContext
Rectangle2D
that is the bounding box
for the character with the maximum bounds.public GlyphVector createGlyphVector(FontRenderContext frc, String str)
GlyphVector
object created with the
specified String
and the specified
FontRenderContext
.frc
- the specified FontRenderContext
str
- the specified String
GlyphVector
created with the
specified String
and the specified
FontRenderContext
.public GlyphVector createGlyphVector(FontRenderContext frc, char[] chars)
GlyphVector
object created with the
specified array of characters and the specified
FontRenderContext
.frc
- the specified FontRenderContext
chars
- the specified array of charactersGlyphVector
created with the
specified array of characters and the specified
FontRenderContext
.public GlyphVector createGlyphVector(FontRenderContext frc, CharacterIterator ci)
GlyphVector
object created with the
specified CharacterIterator
and the specified
FontRenderContext
.frc
- the specified FontRenderContext
ci
- the specified CharacterIterator
GlyphVector
created with the
specified CharacterIterator
and the specified
FontRenderContext
.public GlyphVector createGlyphVector(FontRenderContext frc, int[] glyphCodes)
GlyphVector
object created with the
specified integer array and the specified
FontRenderContext
.frc
- the specified FontRenderContext
glyphcodes
- the specified integer arrayGlyphVector
created with the
specified integer array and the specified
FontRenderContext
.protected void finalize() throws Throwable
Font
object.
|
JavaTM 2 Platform Standard Edition |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |