模块 java.desktop

类 GraphicAttribute

java.lang.Object
java.awt.font.GraphicAttribute
已知子类:
ImageGraphicAttribute , ShapeGraphicAttribute

public abstract class GraphicAttribute extends Object
此类与 CHAR_REPLACEMENT 属性一起使用。

GraphicAttribute 类表示嵌入在文本中的图形。客户子类化这个类来实现他们自己的字符替换图形。希望在文本中嵌入形状和图像的客户不需要继承此类。相反,客户端可以使用 ShapeGraphicAttribute ImageGraphicAttribute 类。

子类必须确保它们的对象在构造后是不可变的。突变 TextLayout 中使用的 GraphicAttribute 会导致 TextLayout 出现未定义的行为。

  • 字段详细信息

    • TOP_ALIGNMENT

      public static final int TOP_ALIGNMENT
      将图形顶部与行顶部对齐。
      参见:
    • BOTTOM_ALIGNMENT

      public static final int BOTTOM_ALIGNMENT
      将图形的底部与行的底部对齐。
      参见:
    • ROMAN_BASELINE

      public static final int ROMAN_BASELINE
      将图形原点与线条的罗马基线对齐。
      参见:
    • CENTER_BASELINE

      public static final int CENTER_BASELINE
      将图形的原点与线的中心基线对齐。
      参见:
    • HANGING_BASELINE

      public static final int HANGING_BASELINE
      将图形的原点与悬挂的直线基线对齐。
      参见:
  • 构造方法详细信息

    • GraphicAttribute

      protected GraphicAttribute(int alignment)
      构造一个 GraphicAttribute 。子类使用它来定义图形的对齐方式。
      参数:
      alignment - 表示 GraphicAttribute 对齐字段之一的 int
      抛出:
      IllegalArgumentException - 如果对齐方式不是五个定义值之一。
  • 方法详情

    • getAscent

      public abstract float getAscent()
      返回此 GraphicAttribute 的上升。图形可以呈现在其上升之上。
      返回:
      这个GraphicAttribute的上升。
      参见:
    • getDescent

      public abstract float getDescent()
      返回此 GraphicAttribute 的血统。图形可以在其下降以下呈现。
      返回:
      这个 GraphicAttribute 的血统。
      参见:
    • getAdvance

      public abstract float getAdvance()
      返回此 GraphicAttribute 的预付款。 GraphicAttribute对象的advance是图形渲染点到下一个字符或图形渲染点的距离。图形可以超出其进度进行渲染
      返回:
      这个 GraphicAttribute 的进步。
      参见:
    • getBounds

      public Rectangle2D  getBounds()
      返回一个 Rectangle2D ,它包含此 GraphicAttribute 相对于渲染位置绘制的所有位。图形可以在其起源、上升、下降或前进之外呈现;但如果是,则此方法的实现必须指明图形的呈现位置。默认边界是矩形 (0, -ascent, advance, ascent+descent)。
      返回:
      一个 Rectangle2D 包含了这个 GraphicAttribute 呈现的所有位。
    • getOutline

      public Shape  getOutline(AffineTransform  tx)
      返回代表此 GraphicAttribute 呈现的区域的 Shape 。这在请求 TextLayout 返回文本大纲时使用。 (未转换的)形状不得延伸到 getBounds 返回的矩形边界之外。默认实现返回由 getBounds() 返回的矩形,由提供的 AffineTransform (如果存在)转换。
      参数:
      tx - 一个可选的 AffineTransform 应用于这个 GraphicAttribute 的大纲。这可以为空。
      返回:
      a Shape 表示此图形属性,适合描边或填充。
      自从:
      1.6
    • draw

      public abstract void draw(Graphics2D  graphics, float x, float y)
      在指定位置呈现此 GraphicAttribute
      参数:
      graphics - 渲染图形的 Graphics2D
      x - 渲染图形的用户空间 X 坐标
      y - 渲染图形的用户空间 Y 坐标
    • getAlignment

      public final int getAlignment()
      返回此 GraphicAttribute 的对齐方式。对齐可以是特定基线,也可以是行的绝对顶部或底部。
      返回:
      这个 GraphicAttribute 的对齐方式。
    • getJustificationInfo

      public GlyphJustificationInfo  getJustificationInfo()
      返回此 GraphicAttribute 的理由信息。子类可以覆盖此方法以提供不同的理由信息。
      返回:
      一个 GlyphJustificationInfo 对象,其中包含此 GraphicAttribute 的理由信息。