Fontpublic class Font extends Object implements SerializableThe Font class represents fonts, which are used to
render text in a visible way.
A font provides the information needed to map sequences of
characters to sequences of glyphs
and to render sequences of glyphs on Graphics and
Component objects.
Characters and Glyphs
A character is a symbol that represents an item such as a letter,
a digit, or punctuation in an abstract way. For example, 'g' ,
LATIN SMALL LETTER G, is a character.
A glyph is a shape used to render a character or a sequence of
characters. In simple writing systems, such as Latin, typically one glyph
represents one character. In general, however, characters and glyphs do not
have one-to-one correspondence. For example, the character 'á'
LATIN SMALL LETTER A WITH ACUTE, can be represented by
two glyphs: one for 'a' and one for '´'. On the other hand, the
two-character string "fi" can be represented by a single glyph, an
"fi" ligature. In complex writing systems, such as Arabic or the South
and South-East Asian writing systems, the relationship between characters
and glyphs can be more complicated and involve context-dependent selection
of glyphs as well as glyph reordering.
A font encapsulates the collection of glyphs needed to render a selected set
of characters as well as the tables needed to map sequences of characters to
corresponding sequences of glyphs.
Physical and Logical Fonts
The Java Platform distinguishes between two kinds of fonts:
physical fonts and logical fonts.
Physical fonts are the actual font libraries containing glyph data
and tables to map from character sequences to glyph sequences, using a font
technology such as TrueType or PostScript Type 1.
All implementations of the Java Platform must support TrueType fonts;
support for other font technologies is implementation dependent.
Physical fonts may use names such as Helvetica, Palatino, HonMincho, or
any number of other font names.
Typically, each physical font supports only a limited set of writing
systems, for example, only Latin characters or only Japanese and Basic
Latin.
The set of available physical fonts varies between configurations.
Applications that require specific fonts can bundle them and instantiate
them using the {@link #createFont createFont} method.
Logical fonts are the five font families defined by the Java
platform which must be supported by any Java runtime environment:
Serif, SansSerif, Monospaced, Dialog, and DialogInput.
These logical fonts are not actual font libraries. Instead, the logical
font names are mapped to physical fonts by the Java runtime environment.
The mapping is implementation and usually locale dependent, so the look
and the metrics provided by them vary.
Typically, each logical font name maps to several physical fonts in order to
cover a large range of characters.
Peered AWT components, such as {@link Label Label} and
{@link TextField TextField}, can only use logical fonts.
For a discussion of the relative advantages and disadvantages of using
physical or logical fonts, see the
Internationalization FAQ
document.
Font Faces and Names
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 simply the
name that was used to construct the font.
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 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 {@link GraphicsEnvironment#getAllFonts() 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.
Font and TextAttribute
Font supports most
TextAttribute s. This makes some operations, such as
rendering underlined text, convenient since it is not
necessary to explicitly construct a TextLayout object.
Attributes can be set on a Font by constructing or deriving it
using a Map of TextAttribute values.
The values of some TextAttributes are not
serializable, and therefore attempting to serialize an instance of
Font that has such values will not serialize them.
This means a Font deserialized from such a stream will not compare
equal to the original Font that contained the non-serializable
attributes. This should very rarely pose a problem
since these attributes are typically used only in special
circumstances and are unlikely to be serialized.
FOREGROUND and BACKGROUND use
Paint values. The subclass Color is
serializable, while GradientPaint and
TexturePaint are not.
CHAR_REPLACEMENT uses
GraphicAttribute values. The subclasses
ShapeGraphicAttribute and
ImageGraphicAttribute are not serializable.
INPUT_METHOD_HIGHLIGHT uses
InputMethodHighlight values, which are
not serializable. See {@link java.awt.im.InputMethodHighlight}.
Clients who create custom subclasses of Paint and
GraphicAttribute can make them serializable and
avoid this problem. Clients who use input method highlights can
convert these to the platform-specific attributes for that
highlight on the current platform and set them on the Font as
a workaround.
The Map -based constructor and
deriveFont APIs ignore the FONT attribute, and it is
not retained by the Font; the static {@link #getFont} method should
be used if the FONT attribute might be present. See {@link
java.awt.font.TextAttribute#FONT} for more information.
Several attributes will cause additional rendering overhead
and potentially invoke layout. If a Font has such
attributes, the {@link #hasLayoutAttributes} method
will return true.
Note: Font rotations can cause text baselines to be rotated. In
order to account for this (rare) possibility, font APIs are
specified to return metrics and take parameters 'in
baseline-relative coordinates'. This maps the 'x' coordinate to
the advance along the baseline, (positive x is forward along the
baseline), and the 'y' coordinate to a distance along the
perpendicular to the baseline at 'x' (positive y is 90 degrees
clockwise from the baseline vector). APIs for which this is
especially important are called out as having 'baseline-relative
coordinates.' |
Fields Summary |
---|
private Hashtable | fRequestedAttributesThis is now only used during serialization. Typically
it is null. | public static final String | DIALOGA String constant for the canonical family name of the
logical font "Dialog". It is useful in Font construction
to provide compile-time verification of the name. | public static final String | DIALOG_INPUTA 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. | public static final String | SANS_SERIFA 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. | public static final String | SERIFA String constant for the canonical family name of the
logical font "Serif". It is useful in Font construction
to provide compile-time verification of the name. | public static final String | MONOSPACEDA 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. | public static final int | PLAINThe plain style constant. | public static final int | BOLDThe bold style constant. This can be combined with the other style
constants (except PLAIN) for mixed styles. | public static final int | ITALICThe italicized style constant. This can be combined with the other
style constants (except PLAIN) for mixed styles. | public static final int | ROMAN_BASELINEThe baseline used in most Roman scripts when laying out text. | public static final int | CENTER_BASELINEThe baseline used in ideographic scripts like Chinese, Japanese,
and Korean when laying out text. | public static final int | HANGING_BASELINEThe baseline used in Devanigiri and similar scripts when laying
out text. | public static final int | TRUETYPE_FONTIdentify a font resource of type TRUETYPE.
Used to specify a TrueType font resource to the
{@link #createFont} method. | public static final int | TYPE1_FONTIdentify a font resource of type TYPE1.
Used to specify a Type1 font resource to the
{@link #createFont} method. | protected String | nameThe logical name of this Font , as passed to the
constructor. | protected int | styleThe style of this Font , as passed to the constructor.
This style can be PLAIN, BOLD, ITALIC, or BOLD+ITALIC. | protected int | sizeThe point size of this Font , rounded to integer. | protected float | pointSizeThe point size of this Font in float . | private transient FontPeer | peerThe platform specific font information. | private transient long | pData | private transient Font2DHandle | font2DHandle | private transient AttributeValues | values | private transient boolean | hasLayoutAttributes | private transient boolean | createdFont | private transient boolean | nonIdentityTx | private static final AffineTransform | identityTx | private static final long | serialVersionUID | private static final int | RECOGNIZED_MASKFont recognizes all attributes except FONT. | private static final int | PRIMARY_MASKThese attributes are considered primary by the FONT attribute. | private static final int | SECONDARY_MASKThese attributes are considered secondary by the FONT attribute. | private static final int | LAYOUT_MASKThese attributes are handled by layout. | private static final int | EXTRA_MASK | private static final float[] | ssinfo | transient int | hash | private int | fontSerializedDataVersionThe Font Serializable Data Form. | private transient SoftReference | flmref | public static final int | LAYOUT_LEFT_TO_RIGHTA flag to layoutGlyphVector indicating that text is left-to-right as
determined by Bidi analysis. | public static final int | LAYOUT_RIGHT_TO_LEFTA flag to layoutGlyphVector indicating that text is right-to-left as
determined by Bidi analysis. | public static final int | LAYOUT_NO_START_CONTEXTA flag to layoutGlyphVector indicating that text in the char array
before the indicated start should not be examined. | public static final int | LAYOUT_NO_LIMIT_CONTEXTA flag to layoutGlyphVector indicating that text in the char array
after the indicated limit should not be examined. |
Constructors Summary |
---|
public Font(Map attributes)Creates a new Font with the specified attributes.
Only keys defined in {@link java.awt.font.TextAttribute TextAttribute}
are recognized. In addition the FONT attribute is
not recognized by this constructor
(see {@link #getAvailableAttributes}). Only attributes that have
values of valid types will affect the new Font .
If attributes is null , a new
Font is initialized with default values.
initFromValues(AttributeValues.fromMap(attributes, RECOGNIZED_MASK));
| protected Font(Font font)Creates a new Font from the specified font .
This constructor is intended for use by subclasses.
if (font.values != null) {
initFromValues(font.getAttributeValues().clone());
} else {
this.name = font.name;
this.style = font.style;
this.size = font.size;
this.pointSize = font.pointSize;
}
this.font2DHandle = font.font2DHandle;
this.createdFont = font.createdFont;
| public Font(String name, int style, int size)Creates a new Font from the specified name, style and
point size.
The font name can be a font face name or a font family name.
It is used together with the style to find an appropriate font face.
When a font family name is specified, the style argument is used to
select the most appropriate face from the family. When a font face
name is specified, the face's style and the style argument are
merged to locate the best matching font from the same family.
For example if face name "Arial Bold" is specified with style
Font.ITALIC , the font system looks for a face in the
"Arial" family that is bold and italic, and may associate the font
instance with the physical font face "Arial Bold Italic".
The style argument is merged with the specified face's style, not
added or subtracted.
This means, specifying a bold face and a bold style does not
double-embolden the font, and specifying a bold face and a plain
style does not lighten the font.
If no face for the requested style can be found, the font system
may apply algorithmic styling to achieve the desired style.
For example, if ITALIC is requested, but no italic
face is available, glyphs from the plain face may be algorithmically
obliqued (slanted).
Font name lookup is case insensitive, using the case folding
rules of the US locale.
If the name parameter represents something other than a
logical font, i.e. is interpreted as a physical font face or family, and
this cannot be mapped by the implementation to a physical font or a
compatible alternative, then the font system will map the Font
instance to "Dialog", such that for example, the family as reported
by {@link #getFamily() getFamily} will be "Dialog".
this.name = (name != null) ? name : "Default";
this.style = (style & ~0x03) == 0 ? style : 0;
this.size = size;
this.pointSize = size;
| private Font(String name, int style, float sizePts)
this.name = (name != null) ? name : "Default";
this.style = (style & ~0x03) == 0 ? style : 0;
this.size = (int)(sizePts + 0.5);
this.pointSize = sizePts;
| private Font(String name, int style, float sizePts, boolean created, Font2DHandle handle)
this(name, style, sizePts);
this.createdFont = created;
/* Fonts created from a stream will use the same font2D instance
* as the parent.
* One exception is that if the derived font is requested to be
* in a different style, then also check if its a CompositeFont
* and if so build a new CompositeFont from components of that style.
* CompositeFonts can only be marked as "created" if they are used
* to add fall backs to a physical font. And non-composites are
* always from "Font.createFont()" and shouldn't get this treatment.
*/
if (created) {
if (handle.font2D instanceof CompositeFont &&
handle.font2D.getStyle() != style) {
this.font2DHandle =
FontManager.getNewComposite(null, style, handle);
} else {
this.font2DHandle = handle;
}
}
| private Font(File fontFile, int fontFormat, boolean isCopy)
this.createdFont = true;
/* Font2D instances created by this method track their font file
* so that when the Font2D is GC'd it can also remove the file.
*/
this.font2DHandle =
FontManager.createFont2D(fontFile, fontFormat, isCopy).handle;
this.name = this.font2DHandle.font2D.getFontName(Locale.getDefault());
this.style = Font.PLAIN;
this.size = 1;
this.pointSize = 1f;
| private Font(AttributeValues values, String oldName, int oldStyle, boolean created, Font2DHandle handle)
this.createdFont = created;
if (created) {
this.font2DHandle = handle;
String newName = null;
if (oldName != null) {
newName = values.getFamily();
if (oldName.equals(newName)) newName = null;
}
int newStyle = 0;
if (oldStyle == -1) {
newStyle = -1;
} else {
if (values.getWeight() >= 2f) newStyle = BOLD;
if (values.getPosture() >= .2f) newStyle |= ITALIC;
if (oldStyle == newStyle) newStyle = -1;
}
if (handle.font2D instanceof CompositeFont) {
if (newStyle != -1 || newName != null) {
this.font2DHandle =
FontManager.getNewComposite(newName, newStyle, handle);
}
} else if (newName != null) {
this.createdFont = false;
this.font2DHandle = null;
}
}
initFromValues(values);
|
Methods Summary |
---|
private static void | applyStyle(int style, sun.font.AttributeValues values)
// WEIGHT_BOLD, WEIGHT_REGULAR
values.setWeight((style & BOLD) != 0 ? 2f : 1f);
// POSTURE_OBLIQUE, POSTURE_REGULAR
values.setPosture((style & ITALIC) != 0 ? .2f : 0f);
| private static void | applyTransform(java.awt.geom.AffineTransform trans, sun.font.AttributeValues values)
if (trans == null) {
throw new IllegalArgumentException("transform must not be null");
}
values.setTransform(trans);
| public boolean | canDisplay(char c)Checks if this Font has a glyph for the specified
character.
Note: This method cannot handle supplementary
characters. To support all Unicode characters, including
supplementary characters, use the {@link #canDisplay(int)}
method or canDisplayUpTo methods.
return getFont2D().canDisplay(c);
| public boolean | canDisplay(int codePoint)Checks if this Font has a glyph for the specified
character.
if (!Character.isValidCodePoint(codePoint)) {
throw new IllegalArgumentException("invalid code point: " +
Integer.toHexString(codePoint));
}
return getFont2D().canDisplay(codePoint);
| public int | canDisplayUpTo(java.lang.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.
return canDisplayUpTo(new StringCharacterIterator(str), 0,
str.length());
| 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.
while (start < limit && canDisplay(text[start])) {
++start;
}
return start == limit ? -1 : start;
| public int | canDisplayUpTo(java.text.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 .
for (char c = iter.setIndex(start);
iter.getIndex() < limit && canDisplay(c);
c = iter.next()) {
}
int result = iter.getIndex();
return result == limit ? -1 : result;
| public static java.awt.Font | createFont(int fontFormat, java.io.InputStream fontStream)Returns a new Font using the specified font type
and input data. The new Font is
created with a point size of 1 and style {@link #PLAIN PLAIN}.
This base font can then be used with the deriveFont
methods in this class to derive new Font objects with
varying sizes, styles, transforms and font features. This
method does not close the {@link InputStream}.
To make the Font available to Font constructors the
returned Font must be registered in the
GraphicsEnviroment by calling
{@link GraphicsEnvironment#registerFont(Font) registerFont(Font)}.
if (fontFormat != Font.TRUETYPE_FONT &&
fontFormat != Font.TYPE1_FONT) {
throw new IllegalArgumentException ("font format not recognized");
}
final InputStream fStream = fontStream;
Object ret = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() {
File tFile = null;
FileOutputStream outStream = null;
try {
tFile = File.createTempFile("+~JF", ".tmp", null);
/* Temp file deleted by font shutdown hook */
BufferedInputStream inStream =
new BufferedInputStream(fStream);
outStream = new FileOutputStream(tFile);
int bytesRead = 0;
int bufSize = 8192;
byte [] buf = new byte[bufSize];
while (bytesRead != -1) {
try {
bytesRead = inStream.read(buf, 0, bufSize);
} catch (Throwable t) {
throw new IOException();
}
if (bytesRead != -1) {
outStream.write(buf, 0, bytesRead);
}
}
/* don't close the input stream */
outStream.close();
} catch (IOException e) {
if (outStream != null) {
try {
outStream.close();
} catch (Exception e1) {
}
}
if (tFile != null) {
try {
tFile.delete();
} catch (Exception e2) {
}
}
return e;
}
return tFile;
}
});
if (ret instanceof File) {
return new Font((File)ret, fontFormat, true);
} else if (ret instanceof IOException) {
throw (IOException)ret;
} else {
throw new FontFormatException("Couldn't access font stream");
}
| public static java.awt.Font | createFont(int fontFormat, java.io.File fontFile)Returns a new Font using the specified font type
and the specified font file. The new Font is
created with a point size of 1 and style {@link #PLAIN PLAIN}.
This base font can then be used with the deriveFont
methods in this class to derive new Font objects with
varying sizes, styles, transforms and font features.
if (fontFormat != Font.TRUETYPE_FONT &&
fontFormat != Font.TYPE1_FONT) {
throw new IllegalArgumentException ("font format not recognized");
}
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
FilePermission filePermission =
new FilePermission(fontFile.getPath(), "read");
sm.checkPermission(filePermission);
}
if (!fontFile.canRead()) {
throw new IOException("Can't read " + fontFile);
}
return new Font(fontFile, fontFormat, false);
| public java.awt.font.GlyphVector | createGlyphVector(java.awt.font.FontRenderContext frc, java.lang.String str)Creates a {@link java.awt.font.GlyphVector GlyphVector} by
mapping characters to glyphs one-to-one based on the
Unicode cmap in this Font . This method does no other
processing besides the mapping of glyphs to characters. This
means that this method is not useful for some scripts, such
as Arabic, Hebrew, Thai, and Indic, that require reordering,
shaping, or ligature substitution.
return (GlyphVector)new StandardGlyphVector(this, str, frc);
| public java.awt.font.GlyphVector | createGlyphVector(java.awt.font.FontRenderContext frc, char[] chars)Creates a {@link java.awt.font.GlyphVector GlyphVector} by
mapping characters to glyphs one-to-one based on the
Unicode cmap in this Font . This method does no other
processing besides the mapping of glyphs to characters. This
means that this method is not useful for some scripts, such
as Arabic, Hebrew, Thai, and Indic, that require reordering,
shaping, or ligature substitution.
return (GlyphVector)new StandardGlyphVector(this, chars, frc);
| public java.awt.font.GlyphVector | createGlyphVector(java.awt.font.FontRenderContext frc, java.text.CharacterIterator ci)Creates a {@link java.awt.font.GlyphVector GlyphVector} by
mapping the specified characters to glyphs one-to-one based on the
Unicode cmap in this Font . This method does no other
processing besides the mapping of glyphs to characters. This
means that this method is not useful for some scripts, such
as Arabic, Hebrew, Thai, and Indic, that require reordering,
shaping, or ligature substitution.
return (GlyphVector)new StandardGlyphVector(this, ci, frc);
| public java.awt.font.GlyphVector | createGlyphVector(java.awt.font.FontRenderContext frc, int[] glyphCodes)Creates a {@link java.awt.font.GlyphVector GlyphVector} by
mapping characters to glyphs one-to-one based on the
Unicode cmap in this Font . This method does no other
processing besides the mapping of glyphs to characters. This
means that this method is not useful for some scripts, such
as Arabic, Hebrew, Thai, and Indic, that require reordering,
shaping, or ligature substitution.
return (GlyphVector)new StandardGlyphVector(this, glyphCodes, frc);
| public static java.awt.Font | decode(java.lang.String str)Returns the Font that the str
argument describes.
To ensure that this method returns the desired Font,
format the str parameter in
one of these ways
- fontname-style-pointsize
- fontname-pointsize
- fontname-style
- fontname
- fontname style pointsize
- fontname pointsize
- fontname style
- fontname
in which style is one of the four
case-insensitive strings:
"PLAIN" , "BOLD" , "BOLDITALIC" , or
"ITALIC" , and pointsize is a positive decimal integer
representation of the point size.
For example, if you want a font that is Arial, bold, with
a point size of 18, you would call this method with:
"Arial-BOLD-18".
This is equivalent to calling the Font constructor :
new Font("Arial", Font.BOLD, 18);
and the values are interpreted as specified by that constructor.
A valid trailing decimal field is always interpreted as the pointsize.
Therefore a fontname containing a trailing decimal value should not
be used in the fontname only form.
If a style name field is not one of the valid style strings, it is
interpreted as part of the font name, and the default style is used.
Only one of ' ' or '-' may be used to separate fields in the input.
The identified separator is the one closest to the end of the string
which separates a valid pointsize, or a valid style name from
the rest of the string.
Null (empty) pointsize and style fields are treated
as valid fields with the default value for that field.
Some font names may include the separator characters ' ' or '-'.
If str is not formed with 3 components, e.g. such that
style or pointsize fields are not present in
str , and fontname also contains a
character determined to be the separator character
then these characters where they appear as intended to be part of
fontname may instead be interpreted as separators
so the font name may not be properly recognised.
The default size is 12 and the default style is PLAIN.
If str does not specify a valid size, the returned
Font has a size of 12. If str does not
specify a valid style, the returned Font has a style of PLAIN.
If you do not specify a valid font name in
the str argument, this method will return
a font with the family name "Dialog".
To determine what font family names are available on
your system, use the
{@link GraphicsEnvironment#getAvailableFontFamilyNames()} method.
If str is null , a new Font
is returned with the family name "Dialog", a size of 12 and a
PLAIN style.
String fontName = str;
String styleName = "";
int fontSize = 12;
int fontStyle = Font.PLAIN;
if (str == null) {
return new Font(DIALOG, fontStyle, fontSize);
}
int lastHyphen = str.lastIndexOf('-");
int lastSpace = str.lastIndexOf(' ");
char sepChar = (lastHyphen > lastSpace) ? '-" : ' ";
int sizeIndex = str.lastIndexOf(sepChar);
int styleIndex = str.lastIndexOf(sepChar, sizeIndex-1);
int strlen = str.length();
if (sizeIndex > 0 && sizeIndex+1 < strlen) {
try {
fontSize =
Integer.valueOf(str.substring(sizeIndex+1)).intValue();
if (fontSize <= 0) {
fontSize = 12;
}
} catch (NumberFormatException e) {
/* It wasn't a valid size, if we didn't also find the
* start of the style string perhaps this is the style */
styleIndex = sizeIndex;
sizeIndex = strlen;
if (str.charAt(sizeIndex-1) == sepChar) {
sizeIndex--;
}
}
}
if (styleIndex >= 0 && styleIndex+1 < strlen) {
styleName = str.substring(styleIndex+1, sizeIndex);
styleName = styleName.toLowerCase(Locale.ENGLISH);
if (styleName.equals("bolditalic")) {
fontStyle = Font.BOLD | Font.ITALIC;
} else if (styleName.equals("italic")) {
fontStyle = Font.ITALIC;
} else if (styleName.equals("bold")) {
fontStyle = Font.BOLD;
} else if (styleName.equals("plain")) {
fontStyle = Font.PLAIN;
} else {
/* this string isn't any of the expected styles, so
* assume its part of the font name
*/
styleIndex = sizeIndex;
if (str.charAt(styleIndex-1) == sepChar) {
styleIndex--;
}
}
fontName = str.substring(0, styleIndex);
} else {
int fontEnd = strlen;
if (styleIndex > 0) {
fontEnd = styleIndex;
} else if (sizeIndex > 0) {
fontEnd = sizeIndex;
}
if (fontEnd > 0 && str.charAt(fontEnd-1) == sepChar) {
fontEnd--;
}
fontName = str.substring(0, fontEnd);
}
return new Font(fontName, fontStyle, fontSize);
| private sun.font.FontLineMetrics | defaultLineMetrics(java.awt.font.FontRenderContext frc)
FontLineMetrics flm = null;
if (flmref == null
|| (flm = (FontLineMetrics)flmref.get()) == null
|| !flm.frc.equals(frc)) {
/* The device transform in the frc is not used in obtaining line
* metrics, although it probably should be: REMIND find why not?
* The font transform is used but its applied in getFontMetrics, so
* just pass identity here
*/
float [] metrics = new float[8];
getFont2D().getFontMetrics(this, identityTx,
frc.getAntiAliasingHint(),
frc.getFractionalMetricsHint(),
metrics);
float ascent = metrics[0];
float descent = metrics[1];
float leading = metrics[2];
float ssOffset = 0;
if (values != null && values.getSuperscript() != 0) {
ssOffset = (float)getTransform().getTranslateY();
ascent -= ssOffset;
descent += ssOffset;
}
float height = ascent + descent + leading;
int baselineIndex = 0; // need real index, assumes roman for everything
// need real baselines eventually
float[] baselineOffsets = { 0, (descent/2f - ascent) / 2f, -ascent };
float strikethroughOffset = metrics[4];
float strikethroughThickness = metrics[5];
float underlineOffset = metrics[6];
float underlineThickness = metrics[7];
float italicAngle = getItalicAngle();
if (isTransformed()) {
AffineTransform ctx = values.getCharTransform(); // extract rotation
if (ctx != null) {
Point2D.Float pt = new Point2D.Float();
pt.setLocation(0, strikethroughOffset);
ctx.deltaTransform(pt, pt);
strikethroughOffset = pt.y;
pt.setLocation(0, strikethroughThickness);
ctx.deltaTransform(pt, pt);
strikethroughThickness = pt.y;
pt.setLocation(0, underlineOffset);
ctx.deltaTransform(pt, pt);
underlineOffset = pt.y;
pt.setLocation(0, underlineThickness);
ctx.deltaTransform(pt, pt);
underlineThickness = pt.y;
}
}
strikethroughOffset += ssOffset;
underlineOffset += ssOffset;
CoreMetrics cm = new CoreMetrics(ascent, descent, leading, height,
baselineIndex, baselineOffsets,
strikethroughOffset, strikethroughThickness,
underlineOffset, underlineThickness,
ssOffset, italicAngle);
flm = new FontLineMetrics(0, cm, frc);
flmref = new SoftReference(flm);
}
return (FontLineMetrics)flm.clone();
| public java.awt.Font | deriveFont(int style, float size)Creates a new Font object by replicating this
Font object and applying a new style and size.
if (values == null) {
return new Font(name, style, size, createdFont, font2DHandle);
}
AttributeValues newValues = getAttributeValues().clone();
int oldStyle = (this.style != style) ? this.style : -1;
applyStyle(style, newValues);
newValues.setSize(size);
return new Font(newValues, null, oldStyle, createdFont, font2DHandle);
| public java.awt.Font | deriveFont(int style, java.awt.geom.AffineTransform trans)Creates a new Font object by replicating this
Font object and applying a new style and transform.
AttributeValues newValues = getAttributeValues().clone();
int oldStyle = (this.style != style) ? this.style : -1;
applyStyle(style, newValues);
applyTransform(trans, newValues);
return new Font(newValues, null, oldStyle, createdFont, font2DHandle);
| public java.awt.Font | deriveFont(float size)Creates a new Font object by replicating the current
Font object and applying a new size to it.
if (values == null) {
return new Font(name, style, size, createdFont, font2DHandle);
}
AttributeValues newValues = getAttributeValues().clone();
newValues.setSize(size);
return new Font(newValues, null, -1, createdFont, font2DHandle);
| public java.awt.Font | deriveFont(java.awt.geom.AffineTransform trans)Creates a new Font object by replicating the current
Font object and applying a new transform to it.
AttributeValues newValues = getAttributeValues().clone();
applyTransform(trans, newValues);
return new Font(newValues, null, -1, createdFont, font2DHandle);
| public java.awt.Font | deriveFont(int style)Creates a new Font object by replicating the current
Font object and applying a new style to it.
if (values == null) {
return new Font(name, style, size, createdFont, font2DHandle);
}
AttributeValues newValues = getAttributeValues().clone();
int oldStyle = (this.style != style) ? this.style : -1;
applyStyle(style, newValues);
return new Font(newValues, null, oldStyle, createdFont, font2DHandle);
| public java.awt.Font | deriveFont(java.util.Map attributes)Creates a new Font object by replicating the current
Font object and applying a new set of font attributes
to it.
if (attributes == null) {
return this;
}
AttributeValues newValues = getAttributeValues().clone();
newValues.merge(attributes, RECOGNIZED_MASK);
return new Font(newValues, name, style, createdFont, font2DHandle);
| public boolean | equals(java.lang.Object obj)Compares this Font object to the specified
Object .
if (obj == this) {
return true;
}
if (obj != null) {
try {
Font font = (Font)obj;
if (size == font.size &&
style == font.style &&
nonIdentityTx == font.nonIdentityTx &&
hasLayoutAttributes == font.hasLayoutAttributes &&
pointSize == font.pointSize &&
name.equals(font.name)) {
/* 'values' is usually initialized lazily, except when
* the font is constructed from a Map, or derived using
* a Map or other values. So if only one font has
* the field initialized we need to initialize it in
* the other instance and compare.
*/
if (values == null) {
if (font.values == null) {
return true;
} else {
return getAttributeValues().equals(font.values);
}
} else {
return values.equals(font.getAttributeValues());
}
}
}
catch (ClassCastException e) {
}
}
return false;
| protected void | finalize()Disposes the native Font object.
if (this.peer != null) {
pDispose();
}
super.finalize();
| private sun.font.AttributeValues | getAttributeValues()Return the AttributeValues object associated with this
font. Most of the time, the internal object is null.
If required, it will be created from the 'standard'
state on the font. Only non-default values will be
set in the AttributeValues object.
Since the AttributeValues object is mutable, and it
is cached in the font, care must be taken to ensure that
it is not mutated.
if (values == null) {
values = new AttributeValues();
values.setFamily(name);
values.setSize(pointSize); // expects the float value.
if ((style & BOLD) != 0) {
values.setWeight(2); // WEIGHT_BOLD
}
if ((style & ITALIC) != 0) {
values.setPosture(.2f); // POSTURE_OBLIQUE
}
values.defineAll(PRIMARY_MASK); // for streaming compatibility
}
return values;
| public java.util.Map | getAttributes()Returns a map of font attributes available in this
Font . Attributes include things like ligatures and
glyph substitution.
return new AttributeMap(getAttributeValues());
| public java.text.AttributedCharacterIterator.Attribute[] | getAvailableAttributes()Returns the keys of all the attributes supported by this
Font . These attributes can be used to derive other
fonts.
// FONT is not supported by Font
Attribute attributes[] = {
TextAttribute.FAMILY,
TextAttribute.WEIGHT,
TextAttribute.WIDTH,
TextAttribute.POSTURE,
TextAttribute.SIZE,
TextAttribute.TRANSFORM,
TextAttribute.SUPERSCRIPT,
TextAttribute.CHAR_REPLACEMENT,
TextAttribute.FOREGROUND,
TextAttribute.BACKGROUND,
TextAttribute.UNDERLINE,
TextAttribute.STRIKETHROUGH,
TextAttribute.RUN_DIRECTION,
TextAttribute.BIDI_EMBEDDING,
TextAttribute.JUSTIFICATION,
TextAttribute.INPUT_METHOD_HIGHLIGHT,
TextAttribute.INPUT_METHOD_UNDERLINE,
TextAttribute.SWAP_COLORS,
TextAttribute.NUMERIC_SHAPING,
TextAttribute.KERNING,
TextAttribute.LIGATURES,
TextAttribute.TRACKING,
};
return attributes;
| public byte | getBaselineFor(char c)Returns the baseline appropriate for displaying this character.
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.
return getFont2D().getBaselineFor(c);
| public java.lang.String | getFamily()Returns the family name of this Font .
The family name of a font is font specific. Two fonts such as
Helvetica Italic and Helvetica Bold have the same family name,
Helvetica, whereas their font face names are
Helvetica Bold and Helvetica Italic. The list of
available family names may be obtained by using the
{@link GraphicsEnvironment#getAvailableFontFamilyNames()} method.
Use getName to get the logical name of the font.
Use getFontName to get the font face name of the font.
return getFamily_NoClientCode();
| public java.lang.String | getFamily(java.util.Locale l)Returns the family name of this Font , localized for
the specified locale.
The family name of a font is font specific. Two fonts such as
Helvetica Italic and Helvetica Bold have the same family name,
Helvetica, whereas their font face names are
Helvetica Bold and Helvetica Italic. The list of
available family names may be obtained by using the
{@link GraphicsEnvironment#getAvailableFontFamilyNames()} method.
Use getFontName to get the font face name of the font.
if (l == null) {
throw new NullPointerException("null locale doesn't mean default");
}
return getFont2D().getFamilyName(l);
| final java.lang.String | getFamily_NoClientCode()
return getFamily(Locale.getDefault());
| public static java.awt.Font | getFont(java.util.Map attributes)Returns a Font appropriate to the attributes.
If attributes contains a FONT attribute
with a valid Font as its value, it will be
merged with any remaining attributes. See
{@link java.awt.font.TextAttribute#FONT} for more
information.
// optimize for two cases:
// 1) FONT attribute, and nothing else
// 2) attributes, but no FONT
// avoid turning the attributemap into a regular map for no reason
if (attributes instanceof AttributeMap &&
((AttributeMap)attributes).getValues() != null) {
AttributeValues values = ((AttributeMap)attributes).getValues();
if (values.isNonDefault(EFONT)) {
Font font = values.getFont();
if (!values.anyDefined(SECONDARY_MASK)) {
return font;
}
// merge
values = font.getAttributeValues().clone();
values.merge(attributes, SECONDARY_MASK);
return new Font(values, font.name, font.style,
font.createdFont, font.font2DHandle);
}
return new Font(attributes);
}
Font font = (Font)attributes.get(TextAttribute.FONT);
if (font != null) {
if (attributes.size() > 1) { // oh well, check for anything else
AttributeValues values = font.getAttributeValues().clone();
values.merge(attributes, SECONDARY_MASK);
return new Font(values, font.name, font.style,
font.createdFont, font.font2DHandle);
}
return font;
}
return new Font(attributes);
| public static java.awt.Font | getFont(java.lang.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.
return getFont(nm, null);
| public static java.awt.Font | getFont(java.lang.String nm, java.awt.Font font)Gets the specified 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 forms accepted by
Font.decode(String)
If the specified property is not found, or the executing code does not
have permission to read the property, the font
argument is returned instead.
String str = null;
try {
str =System.getProperty(nm);
} catch(SecurityException e) {
}
if (str == null) {
return font;
}
return decode ( str );
| private sun.font.Font2D | getFont2D()
if (FontManager.usingPerAppContextComposites &&
font2DHandle != null &&
font2DHandle.font2D instanceof CompositeFont &&
((CompositeFont)(font2DHandle.font2D)).isStdComposite()) {
return FontManager.findFont2D(name, style,
FontManager.LOGICAL_FALLBACK);
} else if (font2DHandle == null) {
font2DHandle =
FontManager.findFont2D(name, style,
FontManager.LOGICAL_FALLBACK).handle;
}
/* Do not cache the de-referenced font2D. It must be explicitly
* de-referenced to pick up a valid font in the event that the
* original one is marked invalid
*/
return font2DHandle.font2D;
| public java.lang.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.
return getFontName(Locale.getDefault());
| public java.lang.String | getFontName(java.util.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.
if (l == null) {
throw new NullPointerException("null locale doesn't mean default");
}
return getFont2D().getFontName(l);
| public float | getItalicAngle()Returns the italic angle of this Font . The italic angle
is the inverse slope of the caret which best matches the posture of this
Font .
AffineTransform at = (isTransformed()) ? getTransform() : identityTx;
return getFont2D().getItalicAngle(this, at,
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF,
RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
| public java.awt.font.LineMetrics | getLineMetrics(java.lang.String str, java.awt.font.FontRenderContext frc)Returns a {@link LineMetrics} object created with the specified
String and {@link FontRenderContext}.
FontLineMetrics flm = defaultLineMetrics(frc);
flm.numchars = str.length();
return flm;
| public java.awt.font.LineMetrics | getLineMetrics(java.lang.String str, int beginIndex, int limit, java.awt.font.FontRenderContext frc)Returns a LineMetrics object created with the
specified arguments.
FontLineMetrics flm = defaultLineMetrics(frc);
int numChars = limit - beginIndex;
flm.numchars = (numChars < 0)? 0: numChars;
return flm;
| public java.awt.font.LineMetrics | getLineMetrics(char[] chars, int beginIndex, int limit, java.awt.font.FontRenderContext frc)Returns a LineMetrics object created with the
specified arguments.
FontLineMetrics flm = defaultLineMetrics(frc);
int numChars = limit - beginIndex;
flm.numchars = (numChars < 0)? 0: numChars;
return flm;
| public java.awt.font.LineMetrics | getLineMetrics(java.text.CharacterIterator ci, int beginIndex, int limit, java.awt.font.FontRenderContext frc)Returns a LineMetrics object created with the
specified arguments.
FontLineMetrics flm = defaultLineMetrics(frc);
int numChars = limit - beginIndex;
flm.numchars = (numChars < 0)? 0: numChars;
return flm;
| public java.awt.geom.Rectangle2D | getMaxCharBounds(java.awt.font.FontRenderContext frc)Returns the bounds for the character with the maximum
bounds as defined in the specified FontRenderContext .
Note: The returned bounds is in baseline-relative coordinates
(see {@link java.awt.Font class notes}).
float [] metrics = new float[4];
getFont2D().getFontMetrics(this, frc, metrics);
return new Rectangle2D.Float(0, -metrics[0],
metrics[3],
metrics[0] + metrics[1] + metrics[2]);
| public int | getMissingGlyphCode()Returns the glyphCode which is used when this Font
does not have a glyph for a specified unicode code point.
return getFont2D().getMissingGlyphCode();
| public java.lang.String | getName()Returns the logical name of this Font .
Use getFamily to get the family name of the font.
Use getFontName to get the font face name of the font.
return name;
| public int | getNumGlyphs()Returns the number of glyphs in this Font . Glyph codes
for this Font range from 0 to
getNumGlyphs() - 1.
return getFont2D().getNumGlyphs();
| public java.lang.String | getPSName()Returns the postscript name of this Font .
Use getFamily to get the family name of the font.
Use getFontName to get the font face name of the font.
return getFont2D().getPostscriptName();
| public java.awt.peer.FontPeer | getPeer()Gets the peer of this Font .
return getPeer_NoClientCode();
| final java.awt.peer.FontPeer | getPeer_NoClientCode()
if(peer == null) {
Toolkit tk = Toolkit.getDefaultToolkit();
this.peer = tk.getFontPeer(name, style);
}
return peer;
| 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.
return size;
| public float | getSize2D()Returns the point size of this Font in
float value.
return pointSize;
| public java.awt.geom.Rectangle2D | getStringBounds(java.lang.String str, java.awt.font.FontRenderContext frc)Returns the logical bounds of the specified String 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 {@link TextLayout#getBounds() getBounds} method of
TextLayout .
Note: The returned bounds is in baseline-relative coordinates
(see {@link java.awt.Font class notes}).
char[] array = str.toCharArray();
return getStringBounds(array, 0, array.length, frc);
| public java.awt.geom.Rectangle2D | getStringBounds(java.lang.String str, int beginIndex, int limit, java.awt.font.FontRenderContext frc)Returns the logical bounds of the specified String 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 {@link TextLayout#getBounds() getBounds} method of
TextLayout .
Note: The returned bounds is in baseline-relative coordinates
(see {@link java.awt.Font class notes}).
String substr = str.substring(beginIndex, limit);
return getStringBounds(substr, frc);
| public java.awt.geom.Rectangle2D | getStringBounds(char[] chars, int beginIndex, int limit, java.awt.font.FontRenderContext frc)Returns the logical bounds of the specified array of characters
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 {@link TextLayout#getBounds() getBounds} method of
TextLayout .
Note: The returned bounds is in baseline-relative coordinates
(see {@link java.awt.Font class notes}).
if (beginIndex < 0) {
throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
}
if (limit > chars.length) {
throw new IndexOutOfBoundsException("limit: " + limit);
}
if (beginIndex > limit) {
throw new IndexOutOfBoundsException("range length: " +
(limit - beginIndex));
}
// this code should be in textlayout
// quick check for simple text, assume GV ok to use if simple
boolean simple = values == null ||
(values.getKerning() == 0 && values.getLigatures() == 0 &&
values.getBaselineTransform() == null);
if (simple) {
for (int i = beginIndex; i < limit; ++i) {
char c = chars[i];
if (c >= '\u0590" && c <= '\u206f") {
simple = false;
break;
}
}
}
if (simple) {
GlyphVector gv = new StandardGlyphVector(this, chars, beginIndex,
limit - beginIndex, frc);
return gv.getLogicalBounds();
} else {
// need char array constructor on textlayout
String str = new String(chars, beginIndex, limit - beginIndex);
TextLayout tl = new TextLayout(str, this, frc);
return new Rectangle2D.Float(0, -tl.getAscent(), tl.getAdvance(),
tl.getAscent() + tl.getDescent() +
tl.getLeading());
}
| public java.awt.geom.Rectangle2D | getStringBounds(java.text.CharacterIterator ci, int beginIndex, int limit, java.awt.font.FontRenderContext frc)Returns the logical bounds of the characters indexed in the
specified {@link 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 {@link TextLayout#getBounds() getBounds} method of
TextLayout .
Note: The returned bounds is in baseline-relative coordinates
(see {@link java.awt.Font class notes}).
int start = ci.getBeginIndex();
int end = ci.getEndIndex();
if (beginIndex < start) {
throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
}
if (limit > end) {
throw new IndexOutOfBoundsException("limit: " + limit);
}
if (beginIndex > limit) {
throw new IndexOutOfBoundsException("range length: " +
(limit - beginIndex));
}
char[] arr = new char[limit - beginIndex];
ci.setIndex(beginIndex);
for(int idx = 0; idx < arr.length; idx++) {
arr[idx] = ci.current();
ci.next();
}
return getStringBounds(arr,0,arr.length,frc);
| public int | getStyle()Returns the style of this Font . The style can be
PLAIN, BOLD, ITALIC, or BOLD+ITALIC.
return style;
| public java.awt.geom.AffineTransform | getTransform()Returns a copy of the transform associated with this
Font . This transform is not necessarily the one
used to construct the font. If the font has algorithmic
superscripting or width adjustment, this will be incorporated
into the returned AffineTransform .
Typically, fonts will not be transformed. Clients generally
should call {@link #isTransformed} first, and only call this
method if isTransformed returns true.
/* The most common case is the identity transform. Most callers
* should call isTransformed() first, to decide if they need to
* get the transform, but some may not. Here we check to see
* if we have a nonidentity transform, and only do the work to
* fetch and/or compute it if so, otherwise we return a new
* identity transform.
*
* Note that the transform is _not_ necessarily the same as
* the transform passed in as an Attribute in a Map, as the
* transform returned will also reflect the effects of WIDTH and
* SUPERSCRIPT attributes. Clients who want the actual transform
* need to call getRequestedAttributes.
*/
if (nonIdentityTx) {
AttributeValues values = getAttributeValues();
AffineTransform at = values.isNonDefault(ETRANSFORM)
? new AffineTransform(values.getTransform())
: new AffineTransform();
if (values.getSuperscript() != 0) {
// can't get ascent and descent here, recursive call to this fn,
// so use pointsize
// let users combine super- and sub-scripting
int superscript = values.getSuperscript();
double trans = 0;
int n = 0;
boolean up = superscript > 0;
int sign = up ? -1 : 1;
int ss = up ? superscript : -superscript;
while ((ss & 7) > n) {
int newn = ss & 7;
trans += sign * (ssinfo[newn] - ssinfo[n]);
ss >>= 3;
sign = -sign;
n = newn;
}
trans *= pointSize;
double scale = Math.pow(2./3., n);
at.preConcatenate(AffineTransform.getTranslateInstance(0, trans));
at.scale(scale, scale);
// note on placement and italics
// We preconcatenate the transform because we don't want to translate along
// the italic angle, but purely perpendicular to the baseline. While this
// looks ok for superscripts, it can lead subscripts to stack on each other
// and bring the following text too close. The way we deal with potential
// collisions that can occur in the case of italics is by adjusting the
// horizontal spacing of the adjacent glyphvectors. Examine the italic
// angle of both vectors, if one is non-zero, compute the minimum ascent
// and descent, and then the x position at each for each vector along its
// italic angle starting from its (offset) baseline. Compute the difference
// between the x positions and use the maximum difference to adjust the
// position of the right gv.
}
if (values.isNonDefault(EWIDTH)) {
at.scale(values.getWidth(), 1f);
}
return at;
}
return new AffineTransform();
| public boolean | hasLayoutAttributes()Return true if this Font contains attributes that require extra
layout processing.
return hasLayoutAttributes;
| 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.
return false; // REMIND always safe, but prevents caller optimize
| public int | hashCode()Returns a hashcode for this Font .
if (hash == 0) {
hash = name.hashCode() ^ style ^ size;
/* It is possible many fonts differ only in transform.
* So include the transform in the hash calculation.
* nonIdentityTx is set whenever there is a transform in
* 'values'. The tests for null are required because it can
* also be set for other reasons.
*/
if (nonIdentityTx &&
values != null && values.getTransform() != null) {
hash ^= values.getTransform().hashCode();
}
}
return hash;
| private void | initFromValues(sun.font.AttributeValues values)Initialize the standard Font fields from the values object.
this.values = values;
values.defineAll(PRIMARY_MASK); // for 1.5 streaming compatibility
this.name = values.getFamily();
this.pointSize = values.getSize();
this.size = (int)(values.getSize() + 0.5);
if (values.getWeight() >= 2f) this.style |= BOLD; // not == 2f
if (values.getPosture() >= .2f) this.style |= ITALIC; // not == .2f
this.nonIdentityTx = values.anyNonDefault(EXTRA_MASK);
this.hasLayoutAttributes = values.anyNonDefault(LAYOUT_MASK);
| private static native void | initIDs()
| public boolean | isBold()Indicates whether or not this Font object's style is
BOLD.
return (style & BOLD) != 0;
| public boolean | isItalic()Indicates whether or not this Font object's style is
ITALIC.
return (style & ITALIC) != 0;
| public boolean | isPlain()Indicates whether or not this Font object's style is
PLAIN.
return style == 0;
| public boolean | isTransformed()Indicates whether or not this Font object has a
transform that affects its size in addition to the Size
attribute.
return nonIdentityTx;
| public java.awt.font.GlyphVector | layoutGlyphVector(java.awt.font.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.
GlyphLayout gl = GlyphLayout.get(null); // !!! no custom layout engines
StandardGlyphVector gv = gl.layout(this, frc, text,
start, limit-start, flags, null);
GlyphLayout.done(gl);
return gv;
| private native void | pDispose()
| private void | readObject(java.io.ObjectInputStream s)Reads the ObjectInputStream .
Unrecognized keys or values will be ignored.
s.defaultReadObject();
if (pointSize == 0) {
pointSize = (float)size;
}
// Handle fRequestedAttributes.
// in 1.5, we always streamed out the font values plus
// TRANSFORM, SUPERSCRIPT, and WIDTH, regardless of whether the
// values were default or not. In 1.6 we only stream out
// defined values. So, 1.6 streams in from a 1.5 stream,
// it check each of these values and 'undefines' it if the
// value is the default.
if (fRequestedAttributes != null) {
values = getAttributeValues(); // init
AttributeValues extras =
AttributeValues.fromSerializableHashtable(fRequestedAttributes);
if (!AttributeValues.is16Hashtable(fRequestedAttributes)) {
extras.unsetDefault(); // if legacy stream, undefine these
}
values = getAttributeValues().merge(extras);
this.nonIdentityTx = values.anyNonDefault(EXTRA_MASK);
this.hasLayoutAttributes = values.anyNonDefault(LAYOUT_MASK);
fRequestedAttributes = null; // don't need it any more
}
| public java.lang.String | toString()Converts this Font object to a String
representation.
String strStyle;
if (isBold()) {
strStyle = isItalic() ? "bolditalic" : "bold";
} else {
strStyle = isItalic() ? "italic" : "plain";
}
return getClass().getName() + "[family=" + getFamily() + ",name=" + name + ",style=" +
strStyle + ",size=" + size + "]";
| private void | writeObject(java.io.ObjectOutputStream s)Writes default serializable fields to a stream.
if (values != null) {
synchronized(values) {
// transient
fRequestedAttributes = values.toSerializableHashtable();
s.defaultWriteObject();
fRequestedAttributes = null;
}
} else {
s.defaultWriteObject();
}
|
|