Module java.desktop
Package java.awt.font

Class GraphicAttribute

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

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

GraphicAttribute类表示嵌入文本中的图形。客户端子类化此类以实现自己的字符替换图形。希望在文本中嵌入形状和图像的客户端无需子类化此类。相反,客户端可以使用ShapeGraphicAttributeImageGraphicAttribute类。

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

  • Field Details

    • 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
      将图形的原点与行的悬挂基线对齐。
      参见:
  • Constructor Details

    • GraphicAttribute

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

    • getAscent

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

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

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

      public Rectangle2D getBounds()
      返回一个Rectangle2D,它包围由此GraphicAttribute相对于渲染位置绘制的所有位。图形可以超出其原点、上升、下降或前进;但如果是这样,此方法的实现必须指示图形的渲染位置。默认边界是矩形(0,-上升,前进,上升+下降)。
      返回:
      包围此GraphicAttribute绘制的所有位的Rectangle2D
    • getOutline

      public Shape getOutline(AffineTransform tx)
      返回一个Shape,表示此GraphicAttribute渲染的区域。当请求TextLayout返回文本轮廓时使用。 (未变换的)形状不能超出getBounds返回的矩形边界。默认实现返回由getBounds()返回的矩形,如果存在,则由提供的AffineTransform变换。
      参数:
      tx - 可选的AffineTransform,用于应用于此GraphicAttribute轮廓。这可以为null。
      返回:
      代表此图形属性的Shape,适合描边或填充。
      自1.6起:
      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的调整信息。子类可以重写此方法以提供不同的调整信息。
      返回:
      包含此GraphicAttribute的调整信息的GlyphJustificationInfo对象。