1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17/** 18 * @author Ilya S. Okomin 19 * @version $Revision$ 20 */ 21package org.apache.harmony.awt.gl.font; 22 23import java.awt.Shape; 24import java.awt.font.GlyphJustificationInfo; 25import java.awt.font.GlyphMetrics; 26import java.awt.image.BufferedImage; 27 28public abstract class Glyph{ 29 30 // character of the glyph 31 char glChar; 32 33 // precise glyph metrics 34 GlyphMetrics glMetrics; 35 36 // glyph metrics in pixels 37 GlyphMetrics glPointMetrics; 38 39 // glyph code of this Glyph 40 int glCode; 41 42 // justification info of this glyph 43 GlyphJustificationInfo glJustInfo; 44 45 // native font handle of the font corresponding to this glyph 46 long pFont; 47 48 // size of the font corresponding to this glyph 49 int fontSize; 50 51 // bitmap representation of the glyph 52 byte[] bitmap = null; 53 54 // Buffered image representation of the glyph 55 BufferedImage image; 56 57 // shape that representing the outline of this glyph 58 Shape glOutline = null; 59 60 /** 61 * image bitmap parameters 62 */ 63 64 // top side bearing 65 public int bmp_top = 0; 66 67 // left side bearing 68 public int bmp_left = 0; 69 70 // number of bytes in row 71 public int bmp_pitch; 72 73 // number of rows 74 public int bmp_rows; 75 76 // width of the row 77 public int bmp_width; 78 79 /** 80 * Retruns handle to Native Font object 81 */ 82 public long getPFont(){ 83 return this.pFont; 84 } 85 86 /** 87 * Retruns char value of this glyph object 88 */ 89 public char getChar(){ 90 return glChar; 91 } 92 93 /** 94 * Retruns precise width of this glyph object 95 */ 96 public int getWidth(){ 97 return Math.round((float)glMetrics.getBounds2D().getWidth()); 98 } 99 100 /** 101 * Retruns precise height of this glyph object 102 */ 103 public int getHeight(){ 104 return Math.round((float)glMetrics.getBounds2D().getHeight()); 105 } 106 107 /** 108 * Retruns glyph code of this glyph object 109 */ 110 public int getGlyphCode(){ 111 return glCode; 112 } 113 114 /** 115 * Retruns GlyphMetrics of this glyph object with precise metrics. 116 */ 117 public GlyphMetrics getGlyphMetrics(){ 118 return glMetrics; 119 } 120 121 /** 122 * Retruns GlyphMetrics of this glyph object in pixels. 123 */ 124 public GlyphMetrics getGlyphPointMetrics(){ 125 return glPointMetrics; 126 } 127 128 /** 129 * Retruns GlyphJustificationInfo of this glyph object 130 */ 131 public GlyphJustificationInfo getGlyphJustificationInfo(){ 132 return glJustInfo; 133 } 134 135 /** 136 * Sets JustificationInfo of this glyph object 137 * 138 * @param newJustInfo GlyphJustificationInfo object to set to the Glyph object 139 */ 140 public void setGlyphJustificationInfo(GlyphJustificationInfo newJustInfo){ 141 this.glJustInfo = newJustInfo; 142 } 143 144 /** 145 * Returns an int array of 3 elements, so-called ABC structure that contains 146 * the width of the character: 147 * 1st element = left side bearing of the glyph 148 * 2nd element = width of the glyph 149 * 3d element = right side bearing of the glyph 150 */ 151 public int[] getABC(){ 152 int[] abc = new int[3]; 153 abc[0] = (int)glMetrics.getLSB(); 154 abc[1] = (int)glMetrics.getBounds2D().getWidth(); 155 abc[2] = (int)glMetrics.getRSB(); 156 157 return abc; 158 } 159 160 /** 161 * Sets BufferedImage representation of this glyph to the specified parameter. 162 * 163 * @param newImage new BufferedImage object to be set as BufferedImage 164 * representation. 165 */ 166 public void setImage(BufferedImage newImage){ 167 this.image = newImage; 168 } 169 170 /** 171 * Returns true if this Glyph and specified object are equal. 172 */ 173 @Override 174 public boolean equals(Object obj){ 175 if (obj == this) { 176 return true; 177 } 178 179 if (obj != null) { 180 try { 181 Glyph gl = (Glyph)obj; 182 183 return ((this.getChar() == gl.getChar()) 184 && (this.getGlyphMetrics().equals(gl.getGlyphMetrics())) 185 && (this.getGlyphCode() == gl.getGlyphCode())); 186 } catch (ClassCastException e) { 187 } 188 } 189 190 return false; 191 } 192 193 /** 194 * Returns height of the glyph in points. 195 */ 196 public int getPointHeight(){ 197 return (int)glPointMetrics.getBounds2D().getHeight(); 198 } 199 200 /** 201 * Returns width of the glyph in points. 202 */ 203 public int getPointWidth(){ 204 return (int)glPointMetrics.getBounds2D().getWidth(); 205 } 206 207 public Shape getShape(){ 208 if (glOutline == null){ 209 glOutline = initOutline(this.glChar); 210 } 211 return glOutline; 212 } 213 214 /** 215 * Sets BufferedImage representation of this glyph. 216 */ 217 public BufferedImage getImage(){ 218 //!! Implementation classes must override this method 219 return null; 220 } 221 222 /** 223 * Returns array of bytes, representing image of this glyph 224 */ 225 public abstract byte[] getBitmap(); 226 227 /** 228 * Returns shape that represents outline of the specified character. 229 * 230 * @param c specified character 231 */ 232 public abstract Shape initOutline(char c); 233 234} 235 236 237