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.Font;
023: import java.awt.font.FontRenderContext;
024: import java.awt.font.GlyphJustificationInfo;
025: import java.awt.font.GlyphMetrics;
026:
027: import java.awt.Rectangle;
028: import java.awt.Shape;
029: import java.awt.geom.AffineTransform;
030: import java.awt.geom.Point2D;
031: import java.awt.geom.Rectangle2D;
032:
033: public abstract class GlyphVector implements Cloneable {
034:
035: public static final int FLAG_HAS_TRANSFORMS = 1;
036:
037: public static final int FLAG_HAS_POSITION_ADJUSTMENTS = 2;
038:
039: public static final int FLAG_RUN_RTL = 4;
040:
041: public static final int FLAG_COMPLEX_GLYPHS = 8;
042:
043: public static final int FLAG_MASK = 15; // (|) mask of other flags
044:
045: public GlyphVector() {
046: }
047:
048: public Rectangle getPixelBounds(FontRenderContext frc, float x,
049: float y) {
050: // default implementation - integer Rectangle, that encloses visual
051: // bounds rectangle
052: Rectangle2D visualRect = getVisualBounds();
053:
054: int minX = (int) Math.floor(visualRect.getMinX() + x);
055: int minY = (int) Math.floor(visualRect.getMinY() + y);
056: int width = (int) Math.ceil(visualRect.getMaxX() + x) - minX;
057: int height = (int) Math.ceil(visualRect.getMaxY() + y) - minY;
058:
059: return new Rectangle(minX, minY, width, height);
060: }
061:
062: public Rectangle getGlyphPixelBounds(int index,
063: FontRenderContext frc, float x, float y) {
064: Rectangle2D visualRect = getGlyphVisualBounds(index)
065: .getBounds2D();
066:
067: int minX = (int) Math.floor(visualRect.getMinX() + x);
068: int minY = (int) Math.floor(visualRect.getMinY() + y);
069: int width = (int) Math.ceil(visualRect.getMaxX() + x) - minX;
070: int height = (int) Math.ceil(visualRect.getMaxY() + y) - minY;
071:
072: return new Rectangle(minX, minY, width, height);
073: }
074:
075: public abstract Rectangle2D getVisualBounds();
076:
077: public abstract Rectangle2D getLogicalBounds();
078:
079: public abstract void setGlyphPosition(int glyphIndex, Point2D newPos);
080:
081: public abstract Point2D getGlyphPosition(int glyphIndex);
082:
083: public abstract void setGlyphTransform(int glyphIndex,
084: AffineTransform trans);
085:
086: public abstract AffineTransform getGlyphTransform(int glyphIndex);
087:
088: public abstract boolean equals(GlyphVector glyphVector);
089:
090: public abstract GlyphMetrics getGlyphMetrics(int glyphIndex);
091:
092: public abstract GlyphJustificationInfo getGlyphJustificationInfo(
093: int glyphIndex);
094:
095: public abstract FontRenderContext getFontRenderContext();
096:
097: public Shape getGlyphOutline(int glyphIndex, float x, float y) {
098: Shape initialShape = getGlyphOutline(glyphIndex);
099: AffineTransform trans = AffineTransform.getTranslateInstance(x,
100: y);
101: return trans.createTransformedShape(initialShape);
102: }
103:
104: public abstract Shape getGlyphVisualBounds(int glyphIndex);
105:
106: public abstract Shape getGlyphOutline(int glyphIndex);
107:
108: public abstract Shape getGlyphLogicalBounds(int glyphIndex);
109:
110: public abstract Shape getOutline(float x, float y);
111:
112: public abstract Shape getOutline();
113:
114: public abstract Font getFont();
115:
116: public abstract int[] getGlyphCodes(int beginGlyphIndex,
117: int numEntries, int[] codeReturn);
118:
119: public int[] getGlyphCharIndices(int beginGlyphIndex,
120: int numEntries, int[] codeReturn) {
121: if (codeReturn == null) {
122: codeReturn = new int[numEntries];
123: }
124:
125: for (int i = 0; i < numEntries; i++) {
126: codeReturn[i] = getGlyphCharIndex(i + beginGlyphIndex);
127: }
128: return codeReturn;
129: }
130:
131: public abstract float[] getGlyphPositions(int beginGlyphIndex,
132: int numEntries, float[] positionReturn);
133:
134: public abstract int getGlyphCode(int glyphIndex);
135:
136: public int getGlyphCharIndex(int glyphIndex) {
137: // default implemetation one-to-one
138: return glyphIndex;
139: }
140:
141: public abstract void performDefaultLayout();
142:
143: public abstract int getNumGlyphs();
144:
145: public int getLayoutFlags() {
146: // default implementation - returned value is 0
147: return 0;
148: }
149:
150: }
|