home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-20 | 4.6 KB | 134 lines |
- /*
- * @(#)GraphicAttribute.java 1.5 98/03/18
- *
- * Copyright 1998 by Sun Microsystems, Inc.,
- * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
- * All rights reserved.
- *
- * This software is the confidential and proprietary information
- * of Sun Microsystems, Inc. ("Confidential Information"). You
- * shall not disclose such Confidential Information and shall use
- * it only in accordance with the terms of the license agreement
- * you entered into with Sun.
- */
-
- /*
- * (C) Copyright Taligent, Inc. 1996 - 1997, All Rights Reserved
- * (C) Copyright IBM Corp. 1996 - 1998, All Rights Reserved
- *
- * The original version of this source code and documentation is
- * copyrighted and owned by Taligent, Inc., a wholly-owned subsidiary
- * of IBM. These materials are provided under terms of a License
- * Agreement between Taligent and Sun. This technology is protected
- * by multiple US and International patents.
- *
- * This notice and attribution to Taligent may not be removed.
- * Taligent is a registered trademark of Taligent, Inc.
- *
- */
-
- package java.awt.font;
-
- import java.awt.geom.Rectangle2D;
- import java.awt.Graphics2D;
- import java.awt.Font;
-
- /**
- * This is the base class for the attribute which indicates a
- * graphic embedded in text. Clients can subclass this class
- * to implement their own graphics. Clients wishing to embed
- * Shapes and Images in text need not subclass this class;
- * they can use the ShapeGraphicAttribute
- * and ImageGraphicAttribute classes instead.
- *
- * Subclasses should ensure that their subclasses are immutable
- * (that is, that the class does not change once it has been
- * constructed). Mutating a GraphicAttribute which is used in
- * a TextLayout results in undefined behavior from the TextLayout.
- */
-
- public abstract class GraphicAttribute {
-
- public static final int TOP_ALIGNMENT = -1;
- public static final int BOTTOM_ALIGNMENT = -2;
- public static final int ROMAN_BASELINE = Font.ROMAN_BASELINE;
- public static final int CENTER_BASELINE = Font.CENTER_BASELINE;
- public static final int HANGING_BASELINE = Font.HANGING_BASELINE;
-
- private /*final*/ int fAlignment;
-
- protected GraphicAttribute(int alignment) {
-
- fAlignment = alignment;
- }
-
- /**
- * Return the ascent of this graphic. A graphic can draw above its ascent
- * (see getBounds).
- */
- public abstract float getAscent();
-
- /**
- * Return the descent of this graphic. A graphic can draw below its descent
- * (see getBounds).
- */
- public abstract float getDescent();
-
- /**
- * Return the advance of this graphic. A graphic can draw beyond its advance
- * (see getBounds).
- */
- public abstract float getAdvance();
-
- /**
- * The rectangle returned from this method should enclose all of the
- * bits drawn by this graphic (relative to the drawing position, of
- * course). A graphic may draw beyond its ascent, descent, or advance;
- * but if it does, this method's implementation should indicate where
- * the graphic draws.
- * Default bounds is the rectangle (0, -ascent, advance, ascent+descent).
- */
- // is this default worth it?
- public Rectangle2D getBounds() {
- float ascent = getAscent();
- return new Rectangle2D.Float(0, -ascent,
- getAdvance(), ascent+getDescent());
- }
-
- /**
- * Draw the graphic at the given location.
- */
- public abstract void draw(Graphics2D graphics, float x, float y);
-
- /**
- * Return the alignment of this graphic. Alignment can be to a particular
- * baseline, or to the absolute top or bottom of a TextLayout.
- */
- // Should we let subclasses override this?
- public final int getAlignment() {
-
- return fAlignment;
- }
-
- /**
- * Return the justification information for this graphic. Subclasses
- * can override to provide different justification information.
- */
- public GlyphJustificationInfo getJustificationInfo() {
-
- // 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
- }
- }
-