Fonts are a very common concept, and I suddenly feel very ignorant when I see a lengthy description of the font in the Java API documentation.
The following is the original English:
Java. AWT. Font
Font
the class represents fonts, which is used to render text in a visible. A font provides the information needed to map sequences ofcharacters to sequences of glyphs and to Rende R sequences of glyphs on Graphics
and Component
objects.
Characters and Glyphs
A character is a symbol this represents an item such as a letter, a digit, or punctuation on an abstract. 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 does not have one-to-one correspondence. For example, the character ' á ' LATIN SMALL letter A with ACUTE, can is represented by both Glyphs:one for ' a ' and one for ‘′‘. On the other hand, the Two-character string "fi" can is 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 Cha Racters and glyphs can is 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, kinds of fonts: physical fonts andlogical fonts.
Physical fonts is the actual font libraries containing glyph data and tables to maps 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 the other font names. Typically, each physical font supports only a limited set of writing systems, for example, only Latin characters or only J Apanese 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 createFont
method.
Logical fonts is the five font families defined by the Java platform which must is supported by any Java runtime Environment:serif, Sansserif, monospaced, Dialog, and Dialoginput. These logical fonts is not actual font libraries. Instead, the logical font names is 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 is maps to several physical fonts on order to cover a large range of characters.
Peered AWT components, such as Label
TextField
and, can only use logical fonts.
For a discussion of the relative advantages and disadvantages of using physical or logical fonts, see theInternational ization FAQ document.
Font Faces and Names
A Font
can has many faces, such as heavy, medium, oblique, gothic and regular. All of these faces has similar typographic design.
There is three different names that's can get from a Font
object. Thelogical font name is simply the name of the used to construct the font. Thefont face name, or just font name for short, was the name of a particular font face, like Helvetica Bo Ld. Thefamily name is the name of the "the font family that determines" the typographic design across several faces, like H Elvetica.
The Font
class represents an instance of a font face from a collection of font faces that is present in the system Resou RCEs of the host system. As examples, Arial bold and Courier bold Italic are font faces. There can 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 Font
is returned as objects with a size of 1, Identity transform and default font features. These base fonts can then is 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 isn't necessary to explicitly construc T a TextLayout
object. Attributes can is set on a Font by constructing or deriving it using a Map
of TextAttribute
values.
The values of some textattributes
is not serializable, and therefore attempting to serialize an instance of Font
that has such values would not serialize them. This means a font deserialized from such a stream won't compare equal to the original font that contained the Non-seria Lizable attributes. This should very rarely pose a problem since these attributes is typically used only in special circumstances and is UNL Ikely to be serialized.
FOREGROUND
and BACKGROUND
use Paint
values. The subclass Color
is serializable GradientPaint
TexturePaint
.
CHAR_REPLACEMENT
Uses GraphicAttribute
values. The subclasses and is not ShapeGraphicAttribute
ImageGraphicAttribute
serializable.
INPUT_METHOD_HIGHLIGHT
Uses InputMethodHighlight
values, which is not serializable. See 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 CU Rrent platform and set them on the Font as a workaround.
Map
the-based constructor deriveFont
and APIs ignore the font attribute, and it isn't retained by the font; getFont
Method should is used if the FONT attribute might be present. See for more java.awt.font.TextAttribute.FONT
information.
Several attributes would cause additional rendering overhead and potentially invoke layout. If a Font
has such attributes, the hasLayoutAttributes()
method would return true.
Note:font rotations can cause text baselines to be rotated. In order to account for this (rare) possibility, font APIs is specified to return metrics and take parameters ' in Baselin E-relative coordinates '. This maps the ' x ' coordinate to the advance along the baseline, (positive x is forward along the baseline), and the ' Y ' Co Ordinate to a distance along the perpendicular to the baseline at ' x ' (positive y was degrees clockwise from the Baselin e vector). APIs for which the especially important is called out as has ' baseline-relative coordinates. '
In order to understand this note, installed a long time without the English dictionary, also downloaded the Chinese version of the API document, the following Chinese translation:
Font
class represents a font that you can use to render text in a visible way. Fonts provide the information needed to map a sequence of characters to a sequence of glyphs to Graphics
render a sequence of glyphs on objects and Component
objects.
Characters and glyphs
A character is a symbol that represents an item (such as a letter, a number, or a punctuation that has an abstract meaning). For example, ‘g‘
(G's Latin Small Letter ) is a character.
A glyph is a shape used to render a character or sequence of characters. In a simple writing system (such as Latin), a glyph is usually represented by a character. In general, however, there is no one-to-one correspondence between characters and glyphs. For example, theaccented Latin Small letter of the character ' á ' A can be represented by two glyphs: one is ' a ' and the other is ' a '. On the other hand, the two-character string "fi" can be represented by a single glyph "fi" ligature. In complex writing systems, such as Arabic or South Asian and Southeast Asian languages, the relationship between characters and glyphs can be more complex, involving contextual glyph selection and glyph reordering. The font encapsulates the set of glyphs required to render the selected character set, and also encapsulates the tables required to map the sequence of characters to the corresponding glyph sequence.
Physical fonts and logical fonts
Java Platform can differentiate between two types of fonts: physical fonts and logical fonts.
physical fonts are actual font libraries that contain glyph data and tables that map character sequences to glyph sequences using font techniques such as TrueType or PostScript Type 1. All implementations of Java Platform support TrueType fonts, and support for other font technologies is implementation-related. Physical fonts can use font names, such as Helvetica, Palatino, Honmincho, or any number of other font names. Typically, only a limited set of writing systems is supported for each physical font, for example, only Latin characters are supported, or only Japanese and basic Latin are supported. The available sets of physical fonts vary depending on the configuration. Applications that require a specific font can use createFont
methods to bundle the fonts and instantiate them.
logical fonts are the five font families defined by the Java platform that must be supported by all Java runtime environments: Serif, Sansserif, monospaced, Dialog, and Dialoginput. These logical fonts are not actual font libraries. In addition, the logical font names are mapped to physical fonts by the Java runtime environment. Mapping relationships are related to implementations and the usual locale, so they provide different skins and specifications. In general, to cover a large range of characters, each logical font name is mapped to several physical fonts.
AWT components (such as and) at the same level Label
TextField
can use only logical fonts.
For a discussion of the relative advantages and disadvantages of using physical fonts or logical fonts, see the Internationalization FAQ documentation.
Font appearance and name
Font
You can have multiple appearances, such as heavy, medium, oblique, gothic, and regular. All of these appearances have a similar typesetting design.
You can Font
get three different names from an object. The logical font name is just the name used to construct the font. The font appearance name , or appearance name , is the name of a particular font appearance, such as Helvetica Bold. The family name is the name of the font family and is used to determine the typographic design of a variety of appearances, such as Helvetica.
Font
The class represents an instance of the font appearance in the font appearance collection, which is located in the system resources of the host system. For example, Arial Bold and Courier bold Italic are font skins. There are several Font
objects that are related to the appearance of a font, each of which differs in size, style, transformation, and font characteristics.
GraphicsEnvironment
The method of the class getAllFonts
returns an array of all the available font skins in the system. These font skins are Font
returned as objects, with an object size of 1, with an identity transform and default font characteristics. These basic fonts can be used to derive new Font
objects that have varying sizes, styles, transformations, and font characteristics, which can be implemented through methods in this class deriveFont
.
Font and Textattribute
Font
Support for most TextAttribute
. This makes some operations, such as rendering underlined text, more convenient because there is no need to explicitly construct an TextLayout
object. TextAttribute
Map
You can set properties on a Font by using values to construct or derive properties.
Some TextAttributes
values are not serializable, so attempting to serialize an instance with such a value Font
does not make them serializable. This means that a font that is serialized from such a stream is not equal to the original font that contains the non-serializable attribute. This should be a problem that rarely arises, because these attributes are usually used only in special cases and cannot be serialized.
FOREGROUND
and BACKGROUND
use Paint
values. Subclasses Color
are serializable, GradientPaint
and TexturePaint
are non-serializable.
CHAR_REPLACEMENT
Use the GraphicAttribute
value. Subclasses ShapeGraphicAttribute
and ImageGraphicAttribute
are non-serializable.
INPUT_METHOD_HIGHLIGHT
Using a InputMethodHighlight
value, it is not serializable. Please refer to InputMethodHighlight
.
Clients that create Paint
and GraphicAttribute
customize subclasses of subclasses can make them serializable and avoid this problem. Clients highlighted with the input method can convert these to platform-specific properties to display them on the current platform and set them on the Font as a workaround.
Map
the Font property is ignored based on the construction method and deriveFont
API, and it is not preserved through the font, or the static method should be used if the Font property may exist getFont(java.util.Map)
. For more information, see TextAttribute.FONT
.
Some properties bring additional rendering overhead and may call the layout. If one Font
has such a property, then the hasLayoutAttributes
method returns True.
Note: Font rotation can cause text baselines to rotate as well. To deal with this (very rare) possibility, you can specify that the font API return font specifications and make the parameter "in coordinates relative to the baseline". This maps the ' x ' coordinates to a certain distance along the baseline (positive x represents a square direction along the baseline), and the ' y ' coordinates to a distance at the vertical of the baseline in the ' x ' coordinate (positive y means 90 degrees from the baseline Shang). The APIs used to implement these are particularly important, and they are paged out as if they had "coordinates relative to the baseline".
Java Font class details (font)-Excerpt from Java API documentation