The Java Tutorials have been written for JDK 8.Java教程是为JDK 8编写的。Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.本页中描述的示例和实践没有利用后续版本中引入的改进,并且可能使用不再可用的技术。See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
This section introduces you to the 本节向您介绍Font
class, which supports the specification of detailed font information and the use of sophisticated typographic features.Font
类,该类支持详细字体信息的规范和复杂排版功能的使用。
A Font
object represents an instance of a font face from the collection of font faces available on the system. Font
对象表示系统上可用字体集合中的字体实例。Examples of common font faces include Helvetica Bold and Courier Bold Italic. 常见字体包括Helvetica粗体和Courier粗体斜体。Three names are associated with a Font
object: its logical name, family name, and font face name:Font
对象关联了三个名称:逻辑名称、字体系列名称和字体名称:
A Font
object's logical name is a name mapped onto a physical font, which is one of the specific fonts available on the system. Font
对象的逻辑名称是映射到物理字体的名称,物理字体是系统上可用的特定字体之一。When specifying a 在Java中指定Font
in Java, use the font face name instead of the logical name. Font
时,请使用字体名称而不是逻辑名称。You can get the logical name from the 您可以通过调用Font
by calling the getName
method. getName
方法从Font
中获取逻辑名称。To get a list of the logical names that are mapped onto the specific fonts available on a system, call the java.awt.GraphicsEnvironment.getAvailableFontFamilyNames method.要获取映射到系统上可用的特定字体的逻辑名称列表,请调用java.awt.GraphicsEnvironment.getAvailableFontFamilyNames
方法。
See Physical and Logical Fonts for more information.有关详细信息,请参阅物理字体和逻辑字体。
A Font
object's family name is the name of the font family that determines the typographic design across several faces, such as Helvetica. Font
对象的系列名称是字体族的名称,用于确定多个面(如Helvetica)的印刷设计。Retrieve the family name through the 通过getFamily
method.getFamily
方法检索系列名称。
A Font
object's font face name refers to an actual font installed on a system. Font
对象的字体名称是指安装在系统上的实际字体。This is the name you should use when specifying a font. 这是指定字体时应使用的名称。It's often referred to as just the font name. 它通常被称为字体名称。Retrieve the font name by calling 通过调用getFontName
. getFontName
检索字体名称。To determine which font faces are available on the system, call the 要确定系统上可用的字体,请调用java.awt.GraphicsEnvironment.getAllFonts
method.java.awt.GraphicsEnvironment.getAllFonts
方法。
You can access information about a 您可以通过Font
through the getAttributes
method. getAttributes
方法访问有关Font
的信息。A Font
object's attributes include its name, size, transform, and font features such as weight and posture.Font
对象的属性包括其名称、大小、变换以及字体特征(如重量和姿势)。
A LineMetrics
object encapsulates the measurement information associated with a Font
, such as its ascent, descent, and leading:LineMetrics
对象封装与字体相关联的度量信息,例如Font
的上升、下降和前导:
The following figure shows the position of the ascender line, baseline, and descender line:下图显示了上升线、基线和下降线的位置:
This information is used to properly position characters along a line, and to position lines relative to one another. 此信息用于沿一行正确定位字符,以及相对于另一行定位行。You can access these line metrics through the 您可以通过getAscent
, getDescent
, and getLeading
methods. getAscent
、getDescent
和getLeading
方法访问这些行度量。You can also access information about a 您还可以通过Font
object's height, baseline, and underline and strikethrough characteristics through the LineMetrics
class.LineMetrics
类访问有关Font
对象的高度、基线、下划线和删除线特征的信息。