所有类


java.awt
类 FontMetrics

java.lang.Object
  继承者 java.awt.FontMetrics
所有已实现的接口:
Serializable

public abstract class FontMetrics
   
   
   
   
   
extends Object
implements Serializable

FontMetrics 类定义了字体规格对象,该对象封装了有关在特定屏幕上呈现特定字体的信息。

关于 subclasser 的注意事项:由于很多这样的格式关闭 (form closed) 方法相互进行递归循环,所以必须注意,在每个这样的循环中至少要实现其中一个方法,以防止在使用子类时产生无穷递归。特别建议,最少要重写以下方法集合,以确保正确性,并防止无穷递归(虽然其他子集也有此功效)。

字母 'p' 显示其“引用点” 注意,这些方法的实现效率低下,因此通常利用更高效的特定于工具包的实现重写它们。

当应用程序要求 AWT 将字符放置在 (x, y) 处时,该字符的放置会使得其引用点(显示为附图中的点)也放置在该位置。引用点指定一条水平线,称为字符的 baseline(基线)。在正常的打印中,字符的 baseline 应该对齐。

此外,字体中的每个字符都具有 ascentdescentadvance width 属性。ascent 是字符超出 baseline 之上的距离。descent 是字符超出 baseline 以下的距离。advance width 指示 AWT 应该放置下一个字符的位置。

字符数组或字符串也可以具有 ascent、descent 和 advance width 属性。数组的 ascent 是数组中所有字符的最大 ascent。descent 是数组中所有字符的最大 descent。advance width 是字符数组中每个字符的 advance width 之和。String 的 advance 是 String 沿 baseline 的距离。此距离是 String 居中或右对齐应该使用的 width。注意,String 的 advance 不一定是所有单独测量的字符的 advance 之和,因为字符的 width 可能随上下文的不同而不同。例如,在 Arabic 文本中,可以更改一个字符的形状,以连接到其他字符。而在有些脚本中,某些字符序列可以由单个形状(称为连字)表示。单独测量的字符并不能说明这些转换。

从以下版本开始:
JDK1.0
另请参见:
Font, 序列化表格

字段摘要
protected  Fontfont
          实际的 Font,字体规格是由此创建的。
 
构造方法摘要
protected FontMetrics(Font font)
          创建一个新 FontMetrics 对象,用于查找该 Font 中关于指定 Font 和特定字符字形的 height 和 width 信息。
 
方法摘要
 intbytesWidth(byte[] data, int off, int len)
          返回显示此 Font 中指定字节数组的总 advance width。
 intcharsWidth(char[] data, int off, int len)
          返回显示此 Font 中指定字符数组的总 advance width。
 intcharWidth(char ch)
          返回此 Font 中指定字符的 advance width。
 intcharWidth(int codePoint)
          返回此 Font 中指定字符的 advance width。
 intgetAscent()
          确定由此 FontMetrics 对象所描述的 Fontfont ascent
 intgetDescent()
          确定由此 FontMetrics 对象所描述的 Fontfont descent
 FontgetFont()
          获得由此 FontMetrics 对象所描述的 Font
 intgetHeight()
          获取此 font 中文本行的标准 height。
 intgetLeading()
          确定由此 FontMetrics 对象所描述的 Font标准行间距
 LineMetricsgetLineMetrics(char[] chars, int beginIndex, int limit, Graphics context)
          返回指定 Graphics 上下文中指定字符数组的 LineMetrics 对象。
 LineMetricsgetLineMetrics(CharacterIterator ci, int beginIndex, int limit, Graphics context)
          返回指定 Graphics 上下文中指定 CharacterIteratorLineMetrics 对象。
 LineMetricsgetLineMetrics(String str, Graphics context)
          返回指定 Graphics 上下文中指定 StringLineMetrics 对象。
 LineMetricsgetLineMetrics(String str, int beginIndex, int limit, Graphics context)
          返回指定 Graphics 上下文中指定 StringLineMetrics 对象。
 intgetMaxAdvance()
          获取此 Font 中所有字符的最大 advance width。
 intgetMaxAscent()
          确定由此 FontMetrics 对象所描述的 Font 的最大 ascent。
 Rectangle2DgetMaxCharBounds(Graphics context)
          返回指定 Graphics 上下文中具有最大边界的字符的边界。
 intgetMaxDecent()
          已过时。 从 JDK version 1.1.1 开始,由 getMaxDescent() 取代。
 intgetMaxDescent()
          确定由此 FontMetrics 对象所描述的 Font 的最大 descent。
 Rectangle2DgetStringBounds(char[] chars, int beginIndex, int limit, Graphics context)
          返回指定 Graphics 上下文中指定字符数组的边界。
 Rectangle2DgetStringBounds(CharacterIterator ci, int beginIndex, int limit, Graphics context)
          返回用指定 Graphics 上下文中的指定 CharacterIterator 进行索引的字符的边界。
 Rectangle2DgetStringBounds(String str, Graphics context)
          返回指定 Graphics 上下文中指定 String 的边界。
 Rectangle2DgetStringBounds(String str, int beginIndex, int limit, Graphics context)
          返回指定 Graphics 上下文中指定 String 的边界。
 int[]getWidths()
          获取此 Font 中前 256 个字符的 advance width。
 booleanhasUniformLineMetrics()
          检查 Font 是否具有统一的行规格。
 intstringWidth(String str)
          返回此 Font 中指定 String 的总 advance width。
 StringtoString()
          返回此 FontMetrics 对象的值的 String 表示形式。
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

字段详细信息

font

protected Font font
实际的 Font,字体规格是由此创建的。它不能为 null。

另请参见:
getFont()
构造方法详细信息

FontMetrics

protected FontMetrics(Font font)
创建一个新 FontMetrics 对象,用于查找该 Font 中关于指定 Font 和特定字符字形的 height 和 width 信息。

参数:
font - the Font
另请参见:
Font
方法详细信息

getFont

public Font getFont()
获得由此 FontMetrics 对象所描述的 Font

返回:
由此 FontMetrics 对象所描述的 Font

getLeading

public int getLeading()
确定由此 FontMetrics 对象所描述的 Font标准行间距。标准行间距(或行间间隔)是保留在一个文本行的 descent 和下一个文本行的 ascent 之间的逻辑间隔量。计算 height 规格时要包括此额外的间隔。

返回:
Font 的标准行间距。
另请参见:
getHeight(), getAscent(), getDescent()

getAscent

public int getAscent()
确定由此 FontMetrics 对象所描述的 Fontfont ascent。font ascent 是字体的 baseline 到大多数字母数字字符顶部的距离。在 Font 中,有些字符可能扩展超过 font ascent 线。

返回:
Font 的 font ascent。
另请参见:
getMaxAscent()

getDescent

public int getDescent()
确定由此 FontMetrics 对象所描述的 Fontfont descent。font descent 是字体的 baseline 到大多数字母数字字符底部的距离。在 Font 中,有些字符可能扩展到 font descent 线之下。

返回:
Font 的 font descent。
另请参见:
getMaxDescent()

getHeight

public int getHeight()
获取此 font 中文本行的标准 height。它是相邻文本行的 baseline 之间的距离。它是 leading、ascent、descent 的总和。由于采用了舍入方法,它可能不同于 getAscent()、getDescent()、getLeading() 的总和。这并不能保证以此距离间隔的文本行是不相交的;如果有些字符超出了标准 ascent 或标准 descent,则这些文本行可能出现重叠部分。

返回:
font 的标准 height。
另请参见:
getLeading(), getAscent(), getDescent()

getMaxAscent

public int getMaxAscent()
确定由此 FontMetrics 对象所描述的 Font 的最大 ascent。字符超出字体的 baseline 的距离不会大于此 height。

返回:
Font 中所有字符的最大 ascent。
另请参见:
getAscent()

getMaxDescent

public int getMaxDescent()
确定由此 FontMetrics 对象所描述的 Font 的最大 descent。字符低于字体的 baseline 的距离不会大于此 height。

返回:
Font 中所有字符的最大 descent。
另请参见:
getDescent()