|
Java Platform 1.2 Beta 4 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Font
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 given writing system, for example lowercase-g. When a given character is drawn, 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 2D API is Unicode. For more information on Unicode you may visit the site http://www.unicode.org.
Characters and glyphs do not have one-to-one correspondence. As an 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 may have many faces, e.g. 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 nameis the same as used by java.awt.Font in JDK 1.1 and earlier releases. The java.awt.Toolkit.getFontList() method returns a short list of these logical names which are mapped onto specific fonts available on specific platforms. 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 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, Helvetica 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. GraphicsEnvironment.getAllFonts() 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.
Toolkit.getFontList()
,
GraphicsEnvironment.getFonts(java.util.Map)
,
GraphicsEnvironment.getAllFonts()
, Serialized FormField Summary | |
static int | BOLD
The bold style constant. |
static int | CENTER_BASELINE
|
static int | HANGING_BASELINE
|
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
|
protected int | size
The point size of this font, rounded to integer. |
protected int | style
The style of the font, as passed to the constructor. |
Constructor Summary | |
Font(Map attributes)
Create 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)
A convenience overload. |
int | canDisplayUpTo(CharacterIterator iter,
int start,
int limit)
Indicates whether a string is displayable by this Font. |
int | canDisplayUpTo(String str)
Indicates whether a string is displayable by this Font. |
GlyphVector | createGlyphVector(FontRenderContext frc,
char[] chars)
|
GlyphVector | createGlyphVector(FontRenderContext frc,
CharacterIterator ci)
|
GlyphVector | createGlyphVector(FontRenderContext frc,
int[] glyphCodes)
|
GlyphVector | createGlyphVector(FontRenderContext frc,
String str)
|
static Font | decode(String str)
Returns the specified font using the name passed in. |
Font | deriveFont(AffineTransform trans)
Creates a new Font object by replicating the current Font object with a new transform associated with it. |
Font | deriveFont(float size)
Creates a new Font object by replicating the current Font object with a new size associated with it. |
Font | deriveFont(int style,
AffineTransform trans)
Creates a new Font object by replicating the current Font object with a new style and transform associated with it. |
Font | deriveFont(int style,
float size)
Creates a new Font object by replicating the current Font object with a new style and size associated with it. |
Font | deriveFont(int style)
Creates a new Font object by replicating the current Font object with a new style associated with it. |
Font | deriveFont(Map attributes)
Creates a new Font object by replicating the current Font object with a new set of font attributes associated with it. |
boolean | equals(Object obj)
Compares this object to the specified object. |
protected void | finalize()
|
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)
Return the baseline appropriate for displaying this character. |
String | getFamily()
Returns the family name of the font (for example, Helvetica). |
String | getFamily(Locale l)
Returns the family name of the font (for example, Helvetica), localized for the given Locale. |
static Font | getFont(Map attributes)
Returns a font appropriate to this attribute set. |
static Font | getFont(String nm,
Font font)
Returns the specified font from the system properties list. |
static Font | getFont(String nm)
Returns a font from the system properties list. |
String | getFontName()
Returns the font face name of the font (for example, Helvetica Bold). |
String | getFontName(Locale l)
Returns the font face name of the font (for example, Helvetica Fett) localized for the specified locale. |
float | getItalicAngle()
Returns the italic angle of this font. |
LineMetrics | getLineMetrics(char[] chars,
int beginIndex,
int limit,
FontRenderContext frc)
|
LineMetrics | getLineMetrics(CharacterIterator ci,
int beginIndex,
int limit,
FontRenderContext frc)
|
LineMetrics | getLineMetrics(String str,
FontRenderContext frc)
|
LineMetrics | getLineMetrics(String str,
int beginIndex,
int limit,
FontRenderContext frc)
|
Rectangle2D | getMaxCharBounds(FontRenderContext frc)
|
int | getMissingGlyphCode()
Returns the glyphCode which is used when the font does not have a glyph for a specified unicode |
String | getName()
Returns the logical name of the font. |
int | getNumGlyphs()
Returns number of glyphs in the font. |
java.awt.peer.FontPeer | getPeer()
Deprecated. Font rendering is now platform independent. |
String | getPSName()
Returns the postscript name of the font. |
int | getSize()
Returns the point size of the font, rounded to integer. |
float | getSize2D()
Returns the point size of the font in float. |
Rectangle2D | getStringBounds(char[] chars,
int beginIndex,
int limit,
FontRenderContext frc)
|
Rectangle2D | getStringBounds(CharacterIterator ci,
int beginIndex,
int limit,
FontRenderContext frc)
|
Rectangle2D | getStringBounds(String str,
FontRenderContext frc)
|
Rectangle2D | getStringBounds(String str,
int beginIndex,
int limit,
FontRenderContext frc)
|
int | getStyle()
Returns the style of the font. |
AffineTransform | getTransform()
Returns a copy of the transform associated with this font. |
int | hashCode()
Returns a hashcode for this font. |
boolean | hasUniformLineMetrics()
|
boolean | isBold()
Indicates whether the font's style is bold. |
boolean | isItalic()
Indicates whether the font's style is italic. |
boolean | isPlain()
Indicates whether the font's style is plain. |
String | toString()
Converts this 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
protected int style
protected int size
protected float pointSize
Constructor Detail |
public Font(String name, int style, int size)
name
- the font name. This can be a logical font name or a
font face name. A logical name must be one of Dialog, DialogInput,
Monospaced, Serif, SansSerif, or Symbol.
style
- the style constant for the font.
size
- the point size of the font.Toolkit.getFontList()
,
GraphicsEnvironment.getFonts(java.util.Map)
,
GraphicsEnvironment.getAllFonts()
,
GraphicsEnvironment.getAvailableFontFamilyNames()
public Font(Map attributes)
Method Detail |
public java.awt.peer.FontPeer getPeer()
public static Font getFont(Map attributes)
public AffineTransform getTransform()
public String getFamily()
getName()
,
getFontName()
public String getFamily(Locale l)
l
- Locale for which to get the family name.getFontName()
,
Locale
public String getPSName()
public String getName()
getFamily()
,
getFontName()
public String getFontName()
getFamily()
,
getName()
public String getFontName(Locale l)
l
- Get the localized font face name for this locale.getFamily()
,
Locale
public int getStyle()
isPlain()
,
isBold()
,
isItalic()
public int getSize()
The Java2D 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 (see GraphicsConfiguration.getDefaultTransform() and GraphicsConfiguration.getNormalizingTransform()), 72 user space units equal 1 inch in device space. In this case one point is 1/72 of an inch.
getSize2D()
,
GraphicsConfiguration.getDefaultTransform()
,
GraphicsConfiguration.getNormalizingTransform()
public float getSize2D()
getSize()
public boolean isPlain()
true
if the font is plain;
false
otherwise.getStyle()
public boolean isBold()
true
if the font is bold;
false
otherwise.getStyle()
public boolean isItalic()
true
if the font is italic;
false
otherwise.getStyle()
public static Font getFont(String nm)
nm
- the property name.public static Font decode(String str)
str
- the name.public static Font getFont(String nm, Font font)
nm
- the property name.
font
- a default font to return if property 'nm' is not defined.public int hashCode()
public boolean equals(Object obj)
obj
- the object to compare with.public String toString()
public int getNumGlyphs()
public int getMissingGlyphCode()
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 will use the same baseline.
c
- a character used to identify the writing system#getBaselineOffsetsFor
,
ROMAN_BASELINE
,
CENTER_BASELINE
,
HANGING_BASELINE
public Map getAttributes()
public AttributedCharacterIterator.Attribute[] getAvailableAttributes()
public Font deriveFont(int style, float size)
style
- the style for the new Font.
size
- the size in float for the new Font.public Font deriveFont(int style, AffineTransform trans)
style
- the style for the new Font.
trans
- the AffineTransform associated with the new Font.public Font deriveFont(float size)
size
- the size in float for the new Font.public Font deriveFont(AffineTransform trans)
trans
- the AffineTransform associated with the new Font.public Font deriveFont(int style)
style
- the style for the new Font.public Font deriveFont(Map attributes)
attributes
- a map of attributes enabled for the new Font.public boolean canDisplay(char c)
c
- a unicode character code.public int canDisplayUpTo(String str)
str
- a String object.public int canDisplayUpTo(char[] text, int start, int limit)
public int canDisplayUpTo(CharacterIterator iter, int start, int limit)
text
- a CharacterIterator object.public float getItalicAngle()
public boolean hasUniformLineMetrics()
public LineMetrics getLineMetrics(String str, FontRenderContext frc)
public LineMetrics getLineMetrics(String str, int beginIndex, int limit, FontRenderContext frc)
public LineMetrics getLineMetrics(char[] chars, int beginIndex, int limit, FontRenderContext frc)
public LineMetrics getLineMetrics(CharacterIterator ci, int beginIndex, int limit, FontRenderContext frc)
public Rectangle2D getStringBounds(String str, FontRenderContext frc)
public Rectangle2D getStringBounds(String str, int beginIndex, int limit, FontRenderContext frc)
public Rectangle2D getStringBounds(char[] chars, int beginIndex, int limit, FontRenderContext frc)
public Rectangle2D getStringBounds(CharacterIterator ci, int beginIndex, int limit, FontRenderContext frc)
public Rectangle2D getMaxCharBounds(FontRenderContext frc)
public GlyphVector createGlyphVector(FontRenderContext frc, String str)
public GlyphVector createGlyphVector(FontRenderContext frc, char[] chars)
public GlyphVector createGlyphVector(FontRenderContext frc, CharacterIterator ci)
public GlyphVector createGlyphVector(FontRenderContext frc, int[] glyphCodes)
protected void finalize() throws Throwable
|
Java Platform 1.2 Beta 4 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |