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 org.apache.harmony.awt.gl.font;
021:
022: import java.awt.Shape;
023: import java.awt.font.GlyphJustificationInfo;
024: import java.awt.font.GlyphMetrics;
025: import java.awt.image.BufferedImage;
026:
027: public abstract class Glyph {
028:
029: // character of the glyph
030: protected char glChar;
031:
032: // precise glyph metrics
033: protected GlyphMetrics glMetrics;
034:
035: // glyph metrics in pixels
036: protected GlyphMetrics glPointMetrics;
037:
038: // glyph code of this Glyph
039: int glCode;
040:
041: // justification info of this glyph
042: GlyphJustificationInfo glJustInfo;
043:
044: // native font handle of the font corresponding to this glyph
045: long pFont;
046:
047: // size of the font corresponding to this glyph
048: int fontSize;
049:
050: // bitmap representation of the glyph
051: byte[] bitmap = null;
052:
053: // Buffered image representation of the glyph
054: BufferedImage image;
055:
056: // shape that representing the outline of this glyph
057: protected Shape glOutline = null;
058:
059: /**
060: * image bitmap parameters
061: */
062:
063: // top side bearing
064: public int bmp_top = 0;
065:
066: // left side bearing
067: public int bmp_left = 0;
068:
069: // number of bytes in row
070: public int bmp_pitch;
071:
072: // number of rows
073: public int bmp_rows;
074:
075: // width of the row
076: public int bmp_width;
077:
078: /**
079: * Retruns handle to Native Font object
080: */
081: public long getPFont() {
082: return this .pFont;
083: }
084:
085: /**
086: * Retruns char value of this glyph object
087: */
088: public char getChar() {
089: return glChar;
090: }
091:
092: /**
093: * Retruns precise width of this glyph object
094: */
095: public int getWidth() {
096: return Math.round((float) getGlyphMetrics().getBounds2D()
097: .getWidth());
098: }
099:
100: /**
101: * Retruns precise height of this glyph object
102: */
103: public int getHeight() {
104: return Math.round((float) getGlyphMetrics().getBounds2D()
105: .getHeight());
106: }
107:
108: /**
109: * Retruns glyph code of this glyph object
110: */
111: public int getGlyphCode() {
112: return glCode;
113: }
114:
115: /**
116: * Retruns GlyphMetrics of this glyph object with precise metrics.
117: */
118: public GlyphMetrics getGlyphMetrics() {
119: return glMetrics;
120: }
121:
122: /**
123: * Retruns GlyphMetrics of this glyph object in pixels.
124: */
125: public GlyphMetrics getGlyphPointMetrics() {
126: return glPointMetrics;
127: }
128:
129: /**
130: * Retruns GlyphJustificationInfo of this glyph object
131: */
132: public GlyphJustificationInfo getGlyphJustificationInfo() {
133: return glJustInfo;
134: }
135:
136: /**
137: * Sets JustificationInfo of this glyph object
138: *
139: * @param newJustInfo GlyphJustificationInfo object to set to the Glyph object
140: */
141: public void setGlyphJustificationInfo(
142: GlyphJustificationInfo newJustInfo) {
143: this .glJustInfo = newJustInfo;
144: }
145:
146: /**
147: * Returns an int array of 3 elements, so-called ABC structure that contains
148: * the width of the character:
149: * 1st element = left side bearing of the glyph
150: * 2nd element = width of the glyph
151: * 3d element = right side bearing of the glyph
152: */
153: public int[] getABC() {
154: int[] abc = new int[3];
155: abc[0] = (int) getGlyphMetrics().getLSB();
156: abc[1] = (int) getGlyphMetrics().getBounds2D().getWidth();
157: abc[2] = (int) getGlyphMetrics().getRSB();
158:
159: return abc;
160: }
161:
162: /**
163: * Sets BufferedImage representation of this glyph to the specified parameter.
164: *
165: * @param newImage new BufferedImage object to be set as BufferedImage
166: * representation.
167: */
168: public void setImage(BufferedImage newImage) {
169: this .image = newImage;
170: }
171:
172: /**
173: * Returns true if this Glyph and specified object are equal.
174: */
175: @Override
176: public boolean equals(Object obj) {
177: if (obj == this ) {
178: return true;
179: }
180:
181: if (obj != null) {
182: try {
183: Glyph gl = (Glyph) obj;
184:
185: return ((this .getChar() == gl.getChar())
186: && (this .getGlyphMetrics().equals(gl
187: .getGlyphMetrics())) && (this
188: .getGlyphCode() == gl.getGlyphCode()));
189: } catch (ClassCastException e) {
190: }
191: }
192:
193: return false;
194: }
195:
196: /**
197: * Returns height of the glyph in points.
198: */
199: public int getPointHeight() {
200: return (int) getGlyphPointMetrics().getBounds2D().getHeight();
201: }
202:
203: /**
204: * Returns width of the glyph in points.
205: */
206: public int getPointWidth() {
207: return (int) getGlyphPointMetrics().getBounds2D().getWidth();
208: }
209:
210: public Shape getShape() {
211: if (glOutline == null) {
212: glOutline = initOutline(this .glChar);
213: }
214: return glOutline;
215: }
216:
217: /**
218: * Sets BufferedImage representation of this glyph.
219: */
220: public BufferedImage getImage() {
221: //!! Implementation classes must override this method
222: return null;
223: }
224:
225: /**
226: * Returns array of bytes, representing image of this glyph
227: */
228: public abstract byte[] getBitmap();
229:
230: /**
231: * Returns shape that represents outline of the specified character.
232: *
233: * @param c specified character
234: */
235: public abstract Shape initOutline(char c);
236:
237: }
|