Top Description Fields Constructors Methods
java.awt.font

public abstract Class GraphicAttribute

extends Object
Class Inheritance
Known Direct Subclasses
java.awt.font.ImageGraphicAttribute, java.awt.font.ShapeGraphicAttribute
Imports
java.awt.Graphics2D, .Font, .Shape, java.awt.geom.AffineTransform, .Rectangle2D

This class is used with the CHAR_REPLACEMENT attribute.

The GraphicAttribute class represents a graphic embedded in text. Clients subclass this class to implement their own char replacement graphics. Clients wishing to embed shapes and images in text need not subclass this class. Instead, clients can use the ShapeGraphicAttribute and ImageGraphicAttribute classes.

Subclasses must ensure that their objects are immutable once they are constructed. Mutating a GraphicAttribute that is used in a TextLayout results in undefined behavior from the TextLayout.

Field Summary

Modifier and TypeField and Description
public static final int
BOTTOM_ALIGNMENT

Aligns bottom of graphic to bottom of line.

public static final int
CENTER_BASELINE

Aligns origin of graphic to center baseline of line.

private int
public static final int
HANGING_BASELINE

Aligns origin of graphic to hanging baseline of line.

public static final int
ROMAN_BASELINE

Aligns origin of graphic to roman baseline of line.

public static final int
TOP_ALIGNMENT

Aligns top of graphic to top of line.

Constructor Summary

AccessConstructor and Description
protected
GraphicAttribute(int
an int representing one of the GraphicAttribute alignment fields
alignment
)

Constructs a GraphicAttribute.

Method Summary

Modifier and TypeMethod and Description
public abstract void
draw(Graphics2D
the Graphics2D into which to render the graphic
graphics
,
float
the user-space X coordinate where the graphic is rendered
x
,
float
the user-space Y coordinate where the graphic is rendered
y
)

Renders this GraphicAttribute at the specified location.

public abstract float

Returns:

the advance of this GraphicAttribute.
getAdvance
()

Returns the advance of this GraphicAttribute.

public final int

Returns:

the alignment of this GraphicAttribute.
getAlignment
()

Returns the alignment of this GraphicAttribute.

public abstract float

Returns:

the ascent of this GraphicAttribute.
getAscent
()

Returns the ascent of this GraphicAttribute.

public Rectangle2D

Returns:

a Rectangle2D that encloses all of the bits rendered by this GraphicAttribute.
getBounds
()

Returns a Rectangle2D that encloses all of the bits drawn by this GraphicAttribute relative to the rendering position.

public abstract float

Returns:

the descent of this GraphicAttribute.
getDescent
()

Returns the descent of this GraphicAttribute.

public GlyphJustificationInfo

Returns:

a GlyphJustificationInfo object that contains the justification information for this GraphicAttribute.
getJustificationInfo
()

Returns the justification information for this GraphicAttribute.

public Shape

Returns:

a Shape representing this graphic attribute, suitable for stroking or filling.
getOutline
(AffineTransform
an optional AffineTransform to apply to the outline of this GraphicAttribute. This can be null.
tx
)

Return a java.awt.Shape that represents the region that this GraphicAttribute renders.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BOTTOM_ALIGNMENTback to summary
public static final int BOTTOM_ALIGNMENT

Aligns bottom of graphic to bottom of line.

CENTER_BASELINEback to summary
public static final int CENTER_BASELINE

Aligns origin of graphic to center baseline of line.

fAlignmentback to summary
private int fAlignment
HANGING_BASELINEback to summary
public static final int HANGING_BASELINE

Aligns origin of graphic to hanging baseline of line.

ROMAN_BASELINEback to summary
public static final int ROMAN_BASELINE

Aligns origin of graphic to roman baseline of line.

TOP_ALIGNMENTback to summary
public static final int TOP_ALIGNMENT

Aligns top of graphic to top of line.

Constructor Detail

GraphicAttributeback to summary
protected GraphicAttribute(int alignment)

Constructs a GraphicAttribute. Subclasses use this to define the alignment of the graphic.

Parameters
alignment:int

an int representing one of the GraphicAttribute alignment fields

Exceptions
IllegalArgumentException:
if alignment is not one of the five defined values.

Method Detail

drawback to summary
public abstract void draw(Graphics2D graphics, float x, float y)

Renders this GraphicAttribute at the specified location.

Parameters
graphics:Graphics2D

the Graphics2D into which to render the graphic

x:float

the user-space X coordinate where the graphic is rendered

y:float

the user-space Y coordinate where the graphic is rendered

getAdvanceback to summary
public abstract float getAdvance()

Returns the advance of this GraphicAttribute. The GraphicAttribute object's advance is the distance from the point at which the graphic is rendered and the point where the next character or graphic is rendered. A graphic can be rendered beyond its advance

Returns:float

the advance of this GraphicAttribute.

See Also
getBounds()
getAlignmentback to summary
public final int getAlignment()

Returns the alignment of this GraphicAttribute. Alignment can be to a particular baseline, or to the absolute top or bottom of a line.

Returns:int

the alignment of this GraphicAttribute.

getAscentback to summary
public abstract float getAscent()

Returns the ascent of this GraphicAttribute. A graphic can be rendered above its ascent.

Returns:float

the ascent of this GraphicAttribute.

See Also
getBounds()
getBoundsback to summary
public Rectangle2D getBounds()

Returns a Rectangle2D that encloses all of the bits drawn by this GraphicAttribute relative to the rendering position. A graphic may be rendered beyond its origin, ascent, descent, or advance; but if it is, this method's implementation must indicate where the graphic is rendered. Default bounds is the rectangle (0, -ascent, advance, ascent+descent).

Returns:Rectangle2D

a Rectangle2D that encloses all of the bits rendered by this GraphicAttribute.

getDescentback to summary
public abstract float getDescent()

Returns the descent of this GraphicAttribute. A graphic can be rendered below its descent.

Returns:float

the descent of this GraphicAttribute.

See Also
getBounds()
getJustificationInfoback to summary
public GlyphJustificationInfo getJustificationInfo()

Returns the justification information for this GraphicAttribute. Subclasses can override this method to provide different justification information.

Returns:GlyphJustificationInfo

a GlyphJustificationInfo object that contains the justification information for this GraphicAttribute.

getOutlineback to summary
public Shape getOutline(AffineTransform tx)

Return a java.awt.Shape that represents the region that this GraphicAttribute renders. This is used when a TextLayout is requested to return the outline of the text. The (untransformed) shape must not extend outside the rectangular bounds returned by getBounds. The default implementation returns the rectangle returned by getBounds, transformed by the provided AffineTransform if present.

Parameters
tx:AffineTransform

an optional AffineTransform to apply to the outline of this GraphicAttribute. This can be null.

Returns:Shape

a Shape representing this graphic attribute, suitable for stroking or filling.

Since
1.6