FileDocCategorySizeDatePackage
GraphicAttribute.javaAPI DocJava SE 6 API7528Tue Jun 10 00:25:24 BST 2008java.awt.font

GraphicAttribute

public abstract class GraphicAttribute extends Object
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 {@link ShapeGraphicAttribute} and {@link ImageGraphicAttribute} classes.

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

Fields Summary
private int
fAlignment
public static final int
TOP_ALIGNMENT
Aligns top of graphic to top of line.
public static final int
BOTTOM_ALIGNMENT
Aligns bottom of graphic to bottom of line.
public static final int
ROMAN_BASELINE
Aligns origin of graphic to roman baseline of line.
public static final int
CENTER_BASELINE
Aligns origin of graphic to center baseline of line.
public static final int
HANGING_BASELINE
Aligns origin of graphic to hanging baseline of line.
Constructors Summary
protected GraphicAttribute(int alignment)
Constructs a GraphicAttribute. Subclasses use this to define the alignment of the graphic.

param
alignment an int representing one of the GraphicAttribute alignment fields
throws
IllegalArgumentException if alignment is not one of the five defined values.


                                              
       
        if (alignment < BOTTOM_ALIGNMENT || alignment > HANGING_BASELINE) {
	  throw new IllegalArgumentException("bad alignment");
        }
        fAlignment = alignment;
    
Methods Summary
public abstract voiddraw(java.awt.Graphics2D graphics, float x, float y)
Renders this GraphicAttribute at the specified location.

param
graphics the {@link Graphics2D} into which to render the graphic
param
x the user-space X coordinate where the graphic is rendered
param
y the user-space Y coordinate where the graphic is rendered

public abstract floatgetAdvance()
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

return
the advance of this GraphicAttribute.
see
#getBounds()

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

return
the alignment of this GraphicAttribute.


        return fAlignment;
    
public abstract floatgetAscent()
Returns the ascent of this GraphicAttribute. A graphic can be rendered above its ascent.

return
the ascent of this GraphicAttribute.
see
#getBounds()

public java.awt.geom.Rectangle2DgetBounds()
Returns a {@link 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).

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

        float ascent = getAscent();
        return new Rectangle2D.Float(0, -ascent,
                                        getAdvance(), ascent+getDescent());
    
public abstract floatgetDescent()
Returns the descent of this GraphicAttribute. A graphic can be rendered below its descent.

return
the descent of this GraphicAttribute.
see
#getBounds()

public java.awt.font.GlyphJustificationInfogetJustificationInfo()
Returns the justification information for this GraphicAttribute. Subclasses can override this method to provide different justification information.

return
a {@link GlyphJustificationInfo} object that contains the justification information for this GraphicAttribute.


        // should we cache this?
        float advance = getAdvance();

        return new GlyphJustificationInfo(
                                     advance,   // weight
                                     false,     // growAbsorb
                                     2,         // growPriority
                                     advance/3, // growLeftLimit
                                     advance/3, // growRightLimit
                                     false,     // shrinkAbsorb
                                     1,         // shrinkPriority
                                     0,         // shrinkLeftLimit
                                     0);        // shrinkRightLimit
    
public java.awt.ShapegetOutline(java.awt.geom.AffineTransform tx)
Return a {@link java.awt.Shape} that represents the region that this GraphicAttribute renders. This is used when a {@link 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 {@link #getBounds}, transformed by the provided {@link AffineTransform} if present.

param
tx an optional {@link AffineTransform} to apply to the outline of this GraphicAttribute. This can be null.
return
a Shape representing this graphic attribute, suitable for stroking or filling.
since
1.6

        Shape b = getBounds();
        if (tx != null) {
            b = tx.createTransformedShape(b);
        }
        return b;