|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjava.awt.FontMetrics
public abstract class FontMetrics
FontMetrics 类定义字体规格对象,该对象封装将在特定屏幕上呈现特定字体的有关信息。
子类注意事项:由于当中很多方法都形成关闭的、相互递归的循环,所以必须注意,在每个这样的循环中至少要实现其中一个方法,以防止在使用子类时产生无穷递归。特别建议,至少要重写以下方法集合以确保正确性,并防止无穷递归(虽然其他子集也可以)。
注意,这些方法的实现效率低下,因此通常利用更高效的特定于工具包的实现重写它们。
当应用程序要求将字符放置在 (x, y) 位置时,放置字符的方式是使其引用点(附图中显示的点)放置在该位置。引用点指定一条水平线,称为字符的基线 (baseline)。在正常的打印中,字符的基线应该对齐。
此外,字体中的每个字符都具有 ascent、descent 和 advance width 属性。ascent 是字符超出基线之上的距离。descent 是字符超出基线以下的距离。advance width 指示 AWT 应该放置下一个字符的位置。
字符数组或字符串也可以具有 ascent、descent 和 advance width 属性。数组的 ascent 是数组中所有字符的最大 ascent。descent 是数组中所有字符的最大 descent。advance width 是字符数组中每个字符的 advance width 之和。String 的 advance 是 String 沿基线的距离。此距离是 String 居中或右对齐应该使用的 width。
注意,String 的 advance 不一定是每个字符单独测量的 advance 之和,因为字符的 width 可随上下文变动。例如,在 Arabic 文本中,可以更改一个字符的形状,以连接到其他字符。而在有些脚本中,某些字符序列可以由单个形状(称为连字)表示。单独测量的字符并不能说明这些转换。
字体规格是基线相关的,意味着它们通常是独立应用于该字体的循环(模可能的网格提示作用)。请参阅 Font。
Font,
序列化表格| 字段摘要 | |
|---|---|
protected Font |
font
实际的 Font,字体规格是由此创建的。 |
| 构造方法摘要 | |
|---|---|
protected |
FontMetrics(Font font)
创建一个新 FontMetrics 对象,用于查找该 Font 中关于指定 Font 和特定字符字形的 height 和 width 信息。 |
| 方法摘要 | |
|---|---|
int |
bytesWidth(byte[] data,
int off,
int len)
返回显示此 Font 中指定字节数组的总 advance width。 |
int |
charsWidth(char[] data,
int off,
int len)
返回显示此 Font 中指定字符数组的总 advance width。 |
int |
charWidth(char ch)
返回此 Font 中指定字符的 advance width。 |
int |
charWidth(int codePoint)
返回此 Font 中指定字符的 advance width。 |
int |
getAscent()
确定此 FontMetrics 对象所描述的 Font 的 font ascent。 |
int |
getDescent()
确定此 FontMetrics 对象所描述的 Font 的 font descent。 |
Font |
getFont()
获取此 FontMetrics 对象所描述的 Font。 |
FontRenderContext |
getFontRenderContext()
获取此 FontMetrics 对象用来测量文本的 FontRenderContext。 |
int |
getHeight()
获取此 Font 中文本行的标准 height。 |
int |
getLeading()
确定此 FontMetrics 对象所描述的 Font 的标准行间距。 |
LineMetrics |
getLineMetrics(char[] chars,
int beginIndex,
int limit,
Graphics context)
返回指定 Graphics 上下文中指定字符数组的 LineMetrics 对象。 |
LineMetrics |
getLineMetrics(CharacterIterator ci,
int beginIndex,
int limit,
Graphics context)
返回指定 Graphics 上下文中指定 CharacterIterator 的 LineMetrics 对象。 |
LineMetrics |
getLineMetrics(String str,
Graphics context)
返回指定 Graphics 上下文中指定 String 的 LineMetrics 对象。 |
LineMetrics |
getLineMetrics(String str,
int beginIndex,
int limit,
Graphics context)
返回指定 Graphics 上下文中指定 String 的 LineMetrics 对象。 |
int |
getMaxAdvance()
获取此 Font 中所有字符的最大 advance width。 |
int |
getMaxAscent()
确定此 FontMetrics 对象所描述的 Font 的最大 ascent。 |
Rectangle2D |
getMaxCharBounds(Graphics context)
返回指定 Graphics 上下文中具有最大边界的字符的边界。 |
int |
getMaxDecent()
已过时。 从 JDK version 1.1.1 开始,由 getMaxDescent() 取代。 |
int |
getMaxDescent()
确定此 FontMetrics 对象所描述的 Font 的最大 descent。 |
Rectangle2D |
getStringBounds(char[] chars,
int beginIndex,
int limit,
Graphics context)
返回指定 Graphics 上下文中指定字符数组的边界。 |
Rectangle2D |
getStringBounds(CharacterIterator ci,
int beginIndex,
int limit,
Graphics context)
返回用指定 Graphics 上下文中指定 CharacterIterator 进行索引的字符的边界。 |
Rectangle2D |
getStringBounds(String str,
Graphics context)
返回指定 Graphics 上下文中指定 String 的边界。 |
Rectangle2D |
getStringBounds(String str,
int beginIndex,
int limit,
Graphics context)
返回指定 Graphics 上下文中指定 String 的边界。 |
int[] |
getWidths()
获取此 Font 中前 256 个字符的 advance width。 |
boolean |
hasUniformLineMetrics()
检查 Font 是否具有统一的行规格。 |
int |
stringWidth(String str)
返回此 Font 中指定 String 的总 advance width。 |
String |
toString()
返回此 FontMetrics 对象的值的 String 表示形式。 |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| 字段详细信息 |
|---|
protected Font font
Font,字体规格是由此创建的。它不能为 null。
getFont()| 构造方法详细信息 |
|---|
protected FontMetrics(Font font)
FontMetrics 对象,用于查找该 Font 中关于指定 Font 和特定字符字形的 height 和 width 信息。
font - FontFont| 方法详细信息 |
|---|
public Font getFont()
FontMetrics 对象所描述的 Font。
FontMetrics 对象所描述的 Font。public FontRenderContext getFontRenderContext()
FontMetrics 对象用来测量文本的 FontRenderContext。
注意,此类中带有 Graphics 参数的方法测量使用该 Graphics 对象的 FontRenderContext 文本,而非此 FontRenderContext。
FontMetrics 对象使用的 FontRenderContext。public int getLeading()
FontMetrics 对象所描述的 Font 的标准行间距。标准行间距(或行间间隔)是保留在一个文本行的 descent 和下一个文本行的 ascent 之间的逻辑间隔量。计算 height 规格时要包括这一额外间隔。
Font 的标准行间距。getHeight(),
getAscent(),
getDescent()public int getAscent()
FontMetrics 对象所描述的 Font 的 font ascent。font ascent 是字体基线到大多数字母数字字符顶部的距离。在 Font 中,有些字符可能扩展超过 font ascent 线。
Font 的 font ascent。getMaxAscent()public int getDescent()
FontMetrics 对象所描述的 Font 的 font descent。font descent 是字体基线到大多数字母数字字符底部的距离。在 Font 中,有些字符可能扩展到 font descent 线之下。
Font 的 font descent。getMaxDescent()public int getHeight()
getLeading(),
getAscent(),
getDescent()public int getMaxAscent()
FontMetrics 对象所描述的 Font 的最大 ascent。字符超出字体基线的距离不会大于此 height。
Font 中所有字符的最大 ascent。getAscent()public int getMaxDescent()
FontMetrics 对象所描述的 Font 的最大 descent。字符低于字体基线的距离不会大于此 height。
Font 中所有字符的最大 descent。getDescent()@Deprecated public int getMaxDecent()
getMaxDescent() 取代。
Font 中所有字符的最大 descent。getMaxDescent()public int getMaxAdvance()
Font 中所有字符的最大 advance width。advance 是字符串基线上最左边的点到最右边的点之间的距离。String 的 advance 不一定是它所有字符的 advance 之和。
Font 中所有字符的最大 advance width;如果最大 advance width 未知,则返回 -1。public int charWidth(int codePoint)
Font 中指定字符的 advance width。advance 是字符基线上最左边的点到最右边的点之间的距离。注意,String 的 advance 不一定是它所有字符的 advance 之和。
此方法没有验证指定的字符是否为一个有效的 Unicode 代码点。如有必要,调用者必须使用 Character.isValidCodePoint 验证字符值。
codePoint - 要测量的字符(Unicode 代码点)
FontMetrics 对象所描述的 Font 中指定字符的 advance width。charsWidth(char[], int, int),
stringWidth(String)public int charWidth(char ch)
Font 中指定字符的 advance width。advance 是字符基线上最左边的点到最右边的点之间的距离。注意,String 的 advance 不一定是它所有字符的 advance 之和。
注: 此方法无法处理增补字符。要支持包括增补字符在内的所有 Unicode 字符,请使用 charWidth(int) 方法。
ch - 要测量的字符
FontMetrics 对象所描述的 Font 中指定字符的 advance width。charsWidth(char[], int, int),
stringWidth(String)public int stringWidth(String str)
Font 中指定 String 的总 advance width。advance 是字符串基线上最左边的点到最右边的点之间的距离。
注意,code>String 的 advance 不一定是它所有字符的 advance 之和。
str - 要测量的 String
FontMetrics 描述的 Font 中指定 String 的 advance width。
NullPointerException - 如果 str 为 null。bytesWidth(byte[], int, int),
charsWidth(char[], int, int),
getStringBounds(String, Graphics)
public int charsWidth(char[] data,
int off,
int len)
Font 中指定字符数组的总 advance width。advance 是字符串基线上最左边的点到最右边的点之间的距离。String 的 advance 不一定是它所有字符的 advance 之和。这等同于测量 String 指定范围内的字符。
data - 要测量的字符数组off - 数组中字符的起始偏移量len - 数组中要测量的字符数
FontMetrics 对象所描述的字体中指定 char 数组子数组的 advance width。
NullPointerException - 如果 data 为 null。
IndexOutOfBoundsException - 如果 off 和 len 参数索引字符超出 data 数组范围。charWidth(int),
charWidth(char),
bytesWidth(byte[], int, int),
stringWidth(String)
public int bytesWidth(byte[] data,
int off,
int len)
Font 中指定字节数组的总 advance width。advance 是字符串基线上最左边的点到最右边的点之间的距离。String 的 advance 不一定是它所有字符的 advance 之和。这等同于测量 String 指定范围内的字符。
data - 要测量的字节数组off - 数组中字节的起始偏移量len - 数组中要测量的字节数
FontMetrics 对象所描述的 Font 中指定 byte 数组的子数组的 advance width。
NullPointerException - 如果 data 为 null。
IndexOutOfBoundsException - 如果 off 和 len 参数索引字节超出 data 数组范围。charsWidth(char[], int, int),
stringWidth(String)public int[] getWidths()
Font 中前 256 个字符的 advance width。advance 是字符基线上最左边的点到最右边的点之间的距离。注意,String 的 advance 不一定是它所有字符的 advance 之和。
FontMetrics 对象所描述的 Font 中字符的 advance width。public boolean hasUniformLineMetrics()
Font 是否具有统一的行规格。复合字体可能由几种不同的字体组成,涉及到各种字符集。在此情况下,FontLineMetrics 对象是不统一的。不同的字体可能有不同的 ascent、descent、metrics 等等。对于行测量和行断开来说,此信息有时是必需的。
true;否则返回 false。Font.hasUniformLineMetrics()
public LineMetrics getLineMetrics(String str,
Graphics context)
Graphics 上下文中指定 String 的 LineMetrics 对象。
str - 指定的 Stringcontext - 指定的 Graphics 上下文
String 和 Graphics 上下文创建的 LineMetrics 对象。Font.getLineMetrics(String, FontRenderContext)
public LineMetrics getLineMetrics(String str,
int beginIndex,
int limit,
Graphics context)
Graphics 上下文中指定 String 的 LineMetrics 对象。
str - 指定的 StringbeginIndex - str 的初始偏移量limit - str 的结束偏移量context - 指定的 Graphics 上下文
String 和 Graphics 上下文创建的 LineMetrics 对象。Font.getLineMetrics(String, int, int, FontRenderContext)
public LineMetrics getLineMetrics(char[] chars,
int beginIndex,
int limit,
Graphics context)
Graphics 上下文中指定字符数组的 LineMetrics 对象。
chars - 指定的字符数组beginIndex - chars 的初始偏移量limit - chars 的结束偏移量context - 指定的 Graphics 上下文
Graphics 上下文创建的 LineMetrics 对象。Font.getLineMetrics(char[], int, int, FontRenderContext)
public LineMetrics getLineMetrics(CharacterIterator ci,
int beginIndex,
int limit,
Graphics context)
Graphics 上下文中指定 CharacterIterator 的 LineMetrics 对象。
ci - 指定的 CharacterIteratorbeginIndex - ci 中的初始偏移量limit - ci 的结束索引context - 指定的 Graphics 上下文
LineMetrics 对象。Font.getLineMetrics(CharacterIterator, int, int, FontRenderContext)
public Rectangle2D getStringBounds(String str,
Graphics context)
Graphics 上下文中指定 String 的边界。边界用来对 String 进行布局。
注意:返回的边界在基线相关的坐标内
(请参阅类注释)。
str - 指定的 Stringcontext - 指定的 Graphics 上下文
Rectangle2D,它是指定 Graphics 上下文中指定 String 的边界框。Font.getStringBounds(String, FontRenderContext)
public Rectangle2D getStringBounds(String str,
int beginIndex,
int limit,
Graphics context)
Graphics 上下文中指定 String 的边界。边界用来对 String 进行布局。
注意:返回的边界在基线相关的坐标内
(请参阅类注释)。
str - 指定的 StringbeginIndex - str 的起始偏移量limit - str 的结束偏移量context - 指定的 Graphics 上下文
Rectangle2D,它是指定 String 上下文中指定 Graphics 的边界框。Font.getStringBounds(String, int, int, FontRenderContext)
public Rectangle2D getStringBounds(char[] chars,
int beginIndex,
int limit,
Graphics context)
Graphics 上下文中指定字符数组的边界。边界用来对 String 进行布局,String 是使用指定的字符数组、beginIndex 和 limit 创建的。
注意:返回的边界在基线相关的坐标内
(请参阅类注释)。
chars - 字符数组beginIndex - 字符数组的初始偏移量limit - 字符数组的结束偏移量context - 指定的 Graphics 上下文
Rectangle2D,它是指定 Graphics 上下文中指定字符数组的边界框。Font.getStringBounds(char[], int, int, FontRenderContext)
public Rectangle2D getStringBounds(CharacterIterator ci,
int beginIndex,
int limit,
Graphics context)
Graphics 上下文中指定 CharacterIterator 进行索引的字符的边界。
注意:返回的边界在基线相关的坐标内(请参阅类注释)。
ci - 指定的 CharacterIteratorbeginIndex - ci 中的初始偏移量limit - ci 的结束索引context - 指定的 Graphics 上下文
Rectangle2D,它是用指定 Graphics 上下文中的指定 CharacterIterator 进行索引的字符的边界框。Font.getStringBounds(CharacterIterator, int, int, FontRenderContext)public Rectangle2D getMaxCharBounds(Graphics context)
Graphics 上下文中具有最大边界的字符的边界。
context - 指定的 Graphics 上下文
Rectangle2D,它是具有最大边界的字符的边界框。Font.getMaxCharBounds(FontRenderContext)public String toString()
FontMetrics 对象的值的 String 表示形式。
Object 中的 toStringFontMetrics 对象的 String 表示形式。
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。