Contents | Package | Class | Tree | Deprecated | Index | Help | Java 1.2 Beta 3 | ||
PREV | NEXT | SHOW LISTS | HIDE LISTS |
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.
Field Summary | |
static int | BOLD
|
static byte | CENTER_BASELINE
|
static Font | DEFAULT
|
String | fontName
|
static byte | HANGING_BASELINE
|
static int | ITALIC
|
String | name
|
static int | PLAIN
|
static byte | ROMAN_BASELINE
|
int | size
|
int | style
|
Constructor Summary | |
Font(String name,
int style,
int size)
|
|
Font(sun.awt.font.FontObject fontObject)
|
|
Font(AttributeSet attributes)
|
Method Summary | |
boolean | canDisplay(char c)
|
int | canDisplayUpTo(String str)
|
int | canDisplayUpTo(char[] text,
int start,
int limit)
|
int | canDisplayUpTo(CharacterIterator iter,
int start,
int limit)
|
static Font | decode(String str)
|
Font | deriveFont(int style,
float size)
|
Font | deriveFont(int style,
AffineTransform trans)
|
Font | deriveFont(float size)
|
Font | deriveFont(AffineTransform trans)
|
Font | deriveFont(int style)
|
Font | deriveFont(TextAttributeSet attributes)
|
boolean | equals(Object obj)
|
void | finalize()
|
float | getAdvance(char c)
|
float | getAdvance(char[] text)
|
float | getAscent()
|
AttributeSet | getAttributes()
|
String[] | getAvailableAttributes()
|
byte | getBaselineFor(char c)
|
float | getBaselineOffset(byte baselineType)
|
float[] | getBaselineOffsetsFor(char c)
|
static Font | getBestFontFor(AttributedCharacterIterator text)
|
static Font | getBestFontFor(AttributedCharacterIterator text,
int start,
int limit)
|
float | getDescent()
|
String | getFamily()
|
String | getFamily(Locale l)
|
static Font | getFont(AttributeSet attributes)
|
static Font | getFont(String nm)
|
static Font | getFont(String nm,
Font font)
|
int | getFontID()
|
String | getFontName()
|
String | getFontName(Locale l)
|
GlyphJustificationInfo | getGlyphJustificationInfo(int glyphCode)
|
GlyphMetrics | getGlyphMetrics(int glyphCode)
|
Shape | getGlyphOutline(int glyphCode,
float x,
float y)
|
GlyphSet | getGlyphSet(CharacterIterator context,
int start,
int limit,
byte baseline,
int[] order,
byte[] levels)
|
GlyphSet | getGlyphSet(char[] context,
int start,
int limit,
byte baseline,
int[] order,
byte[] levels)
|
GlyphSet | getGlyphSet(String str)
|
float | getItalicAngle()
|
float | getLeading()
|
float | getMaxAdvance()
|
Rectangle2D | getMaxBounds2D()
|
float[] | getMetrics(GlyphSet glyphs,
AffineTransform tx)
|
int | getMissingGlyphCode()
|
String | getName()
|
int | getNumGlyphs()
|
Shape | getOutline(GlyphSet glyphs,
AffineTransform tx,
float x,
float y)
|
java.awt.peer.FontPeer | getPeer()
|
String | getPSName()
|
AttributeSet | getRequestedAttributes()
|
int | getSize()
|
float | getSize2D()
|
float | getStrikethroughOffsetFor(char c)
|
float | getStrikethroughThicknessFor(char c)
|
int | getStyle()
|
AffineTransform | getTransform()
|
float | getUnderlineOffsetFor(char c)
|
float | getUnderlineThicknessFor(char c)
|
int | hashCode()
|
boolean | isBold()
|
boolean | isItalic()
|
boolean | isPlain()
|
boolean | isUniformBaseline()
|
boolean | isVerticalBaseline()
|
int | sameBaselineUpTo(CharacterIterator iter)
|
int | sameBaselineUpTo(char[] text,
int start,
int limit)
|
String | toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final Font DEFAULT
public static final int PLAIN
public static final int BOLD
public static final int ITALIC
public static final byte ROMAN_BASELINE
public static final byte CENTER_BASELINE
public static final byte HANGING_BASELINE
protected String name
protected String fontName
protected int style
protected int size
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.
style
- the style constant for the font.
size
- the point size of the font.
public Font(sun.awt.font.FontObject fontObject)
public Font(AttributeSet attributes)
Method Detail |
public java.awt.peer.FontPeer getPeer()
public int getFontID()
public static Font getFont(AttributeSet attributes)
public AffineTransform getTransform()
public String getFamily()
public String getFamily(Locale l)
l
- Locale for which to get the family name.
public String getPSName()
public String getName()
public String getFontName()
public String getFontName(Locale l)
l
- Get the localized font face name for this locale.
public int getStyle()
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.
public float getSize2D()
public boolean isPlain()
public boolean isBold()
true
if the font is bold;
false
otherwise.public boolean isItalic()
true
if the font is italic;
false
otherwise.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 boolean isVerticalBaseline()
public GlyphMetrics getGlyphMetrics(int glyphCode)
glyphCode
- the glyph to get metrics for.
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
public float[] getBaselineOffsetsFor(char c)
Large fonts can support different writing systems, and each system can have its own set of preferred baseline offsets. The character argument determines the writing system to use.
These all are relative to the most common baseline used with this font (the one from which ascent and descent are measured). Negative values are up on horizontal lines, and right on vertical lines.
c
- a character used to identify the writing system
public boolean isUniformBaseline()
public int sameBaselineUpTo(CharacterIterator iter)
public int sameBaselineUpTo(char[] text, int start, int limit)
public float getUnderlineOffsetFor(char c)
public float getUnderlineThicknessFor(char c)
public float getStrikethroughOffsetFor(char c)
public float getStrikethroughThicknessFor(char c)
public Shape getGlyphOutline(int glyphCode, float x, float y)
glyphCode
- the glyph for which to get the outline.
x
- the x coordinate for the glyph's position.
y
- the y coordinate for the glyph's position,
indicating the font baseline for the glyph.
public Shape getOutline(GlyphSet glyphs, AffineTransform tx, float x, float y)
public float[] getMetrics(GlyphSet glyphs, AffineTransform tx)
public float getAdvance(char c)
public float getAdvance(char[] text)
public AttributeSet getAttributes()
public String[] getAvailableAttributes()
public GlyphJustificationInfo getGlyphJustificationInfo(int glyphCode)
public AttributeSet getRequestedAttributes()
public Font deriveFont(int style, float size)
style
- the style for the new Font.
size
- the size in float for the new Font.
attributes
- an array of AttributeSets enabled 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.
attributes
- an array of AttributeSets enabled for 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(TextAttributeSet attributes)
attributes
- an array of AttributeSets enabled for the new Font.
public GlyphSet getGlyphSet(CharacterIterator context, int start, int limit, byte baseline, int[] order, byte[] levels)
context
- the text for the entire line. The whole
context is provided for fonts that need to do glyph shaping.
start
- the start of the subrange for which to create glyphs.
limit
- the limit of the subrange for which to create glyphs.
order
- a mapping from logical to visual positions for
bidirectional text. For example, the value 5 at position 0 in the
array means that the character at logical position 0 (from the
start of the text in the iterator) displays at visual position 5
(assuming all characters are displayed).
If order is null, the visual position is the logical position. Position zero in this array is position startIndex in the context. The array length must be at least the number of characters in the iterator.
Note the meaning of this array is the inverse of the mapping passed to the GlyphSet constructor. This is to faciliate indexing into the array using start and limit.
levels
- an array indicating the bidirection level of each
character. Even values are left to right, odd are right to left.
This will affect hit testing and cursor positioning.
If null, all characters are left to right. Position zero in this
array is position beginIndex in the context, and the array length
is greater than or equal to endIndex - beginIndex.
public GlyphSet getGlyphSet(char[] context, int start, int limit, byte baseline, int[] order, byte[] levels)
public GlyphSet getGlyphSet(String str)
str
- a String object.
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 getBaselineOffset(byte baselineType)
public float getAscent()
public float getDescent()
public float getLeading()
public float getMaxAdvance()
public Rectangle2D getMaxBounds2D()
public float getItalicAngle()
public static Font getBestFontFor(AttributedCharacterIterator text)
public static Font getBestFontFor(AttributedCharacterIterator text, int start, int limit)
protected void finalize() throws Throwable
Contents | Package | Class | Tree | Deprecated | Index | Help | Java 1.2 Beta 3 | ||
PREV | NEXT | SHOW LISTS | HIDE LISTS |