001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Ilya S. Okomin
019: * @version $Revision$
020: */package java.awt.font;
021:
022: import java.awt.Graphics2D;
023: import java.awt.geom.Rectangle2D;
024:
025: import org.apache.harmony.awt.internal.nls.Messages;
026:
027: public abstract class GraphicAttribute {
028:
029: public static final int TOP_ALIGNMENT = -1;
030:
031: public static final int BOTTOM_ALIGNMENT = -2;
032:
033: public static final int ROMAN_BASELINE = 0;
034:
035: public static final int CENTER_BASELINE = 1;
036:
037: public static final int HANGING_BASELINE = 2;
038:
039: // the alignment of this GraphicAttribute
040: private int alignment;
041:
042: protected GraphicAttribute(int align) {
043: if ((align < BOTTOM_ALIGNMENT) || (align > HANGING_BASELINE)) {
044: // awt.198=Illegal alignment argument
045: throw new IllegalArgumentException(Messages
046: .getString("awt.198")); //$NON-NLS-1$
047: }
048: this .alignment = align;
049: }
050:
051: public abstract void draw(Graphics2D graphics, float x, float y);
052:
053: public abstract float getAdvance();
054:
055: public final int getAlignment() {
056: return this .alignment;
057: }
058:
059: public abstract float getAscent();
060:
061: public Rectangle2D getBounds() {
062: float ascent = getAscent();
063: float advance = getAdvance();
064: float descent = getDescent();
065:
066: // Default implementation - see API documentation.
067: return new Rectangle2D.Float(0, -ascent, advance, ascent
068: + descent);
069: }
070:
071: public abstract float getDescent();
072:
073: public GlyphJustificationInfo getJustificationInfo() {
074:
075: /* Default implementation.
076: * Since documentation doesn't describe default values,
077: * they were calculated based on 1.5 release
078: * behavior and can be obtained using next test sample:
079: *
080: * // Create GraphicAttribute class implementation
081: * public class MyGraphicAttribute extends GraphicAttribute {
082: * protected MyGraphicAttribute(int align) {
083: * super(align);
084: * }
085: *
086: * public float getDescent() {
087: * return 0;
088: * }
089: *
090: * public float getAdvance() {
091: * return 1;
092: * }
093: *
094: * public void draw(Graphics2D g2, float x, float y) {
095: * }
096: *
097: * public float getAscent() {
098: * return 0;
099: * }
100: * }
101: *
102: * MyGraphicAttribute myGA = gat.new MyGraphicAttribute(0);
103: * // print justification parameters
104: * System.out.println(myGA.getJustificationInfo().growAbsorb);
105: * System.out.println(myGA.getJustificationInfo().shrinkAbsorb);
106: * System.out.println(myGA.getJustificationInfo().growLeftLimit);
107: * System.out.println(myGA.getJustificationInfo().growPriority);
108: * System.out.println(myGA.getJustificationInfo().growRightLimit);
109: * System.out.println(myGA.getJustificationInfo().shrinkLeftLimit);
110: * System.out.println(myGA.getJustificationInfo().shrinkPriority);
111: * System.out.println(myGA.getJustificationInfo().shrinkRightLimit);
112: * System.out.println(myGA.getJustificationInfo().weight);
113: */
114: float advance = getAdvance();
115: return new GlyphJustificationInfo(advance, false,
116: GlyphJustificationInfo.PRIORITY_INTERCHAR, advance / 3,
117: advance / 3, false,
118: GlyphJustificationInfo.PRIORITY_WHITESPACE, 0, 0);
119: }
120:
121: }
|