Frames | No Frames |
1: /* Scaler.java -- Common superclass for font scalers. 2: Copyright (C) 2006 Free Software Foundation, Inc. 3: 4: This file is part of GNU Classpath. 5: 6: GNU Classpath is free software; you can redistribute it and/or modify 7: it under the terms of the GNU General Public License as published by 8: the Free Software Foundation; either version 2, or (at your option) 9: any later version. 10: 11: GNU Classpath is distributed in the hope that it will be useful, but 12: WITHOUT ANY WARRANTY; without even the implied warranty of 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14: General Public License for more details. 15: 16: You should have received a copy of the GNU General Public License 17: along with GNU Classpath; see the file COPYING. If not, write to the 18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19: 02110-1301 USA. 20: 21: Linking this library statically or dynamically with other modules is 22: making a combined work based on this library. Thus, the terms and 23: conditions of the GNU General Public License cover the whole 24: combination. 25: 26: As a special exception, the copyright holders of this library give you 27: permission to link this library with independent modules to produce an 28: executable, regardless of the license terms of these independent 29: modules, and to copy and distribute the resulting executable under 30: terms of your choice, provided that you also meet, for each linked 31: independent module, the terms and conditions of the license of that 32: module. An independent module is a module which is not derived from 33: or based on this library. If you modify this library, you may extend 34: this exception to your version of the library, but you are not 35: obligated to do so. If you do not wish to do so, delete this 36: exception statement from your version. */ 37: 38: package gnu.java.awt.font.opentype; 39: 40: import gnu.java.awt.font.opentype.truetype.Zone; 41: 42: import java.awt.geom.AffineTransform; 43: import java.awt.geom.GeneralPath; 44: import java.awt.geom.Point2D; 45: 46: 47: /** 48: * An common superclass for all font scalers. The main task of font 49: * scaler is to retrieve a scaled and hinted outline for a glyph. 50: * 51: * <p>To make text more legible, high-quality fonts contain 52: * instructions (sometimes also called “hints”) for 53: * moving the scaled control points towards the coordinate grid of the 54: * display device. 55: * 56: * <p><b>Lack of Thread Safety:</b> Font scalers are intentionally 57: * <i>not</i> safe to access from multiple concurrent 58: * threads. Synchronization needs to be performed externally. Usually, 59: * the font that uses this scaler already has obtained a lock before 60: * calling the scaler. 61: * 62: * @author Sascha Brawer (brawer@dandelis.ch) 63: */ 64: public abstract class Scaler 65: { 66: /** 67: * Retrieves the scaled outline of a glyph, adjusting control points 68: * to the raster grid if necessary. 69: * 70: * @param glyph the glyph number whose outline is retrieved. 71: * 72: * @param pointSize the point size of the font. 73: * 74: * @param transform a transform that is applied in addition to 75: * scaling to the specified point size. This is often used for 76: * scaling according to the device resolution. Those who lack any 77: * aesthetic sense may also use the transform to slant or stretch 78: * glyphs. 79: * 80: * @param antialias whether or not the rasterizer will perform 81: * anti-aliasing on the returned path. 82: * 83: * @param fractionalMetrics <code>false</code> for adjusting glyph 84: * positions to the raster grid of device space. 85: * 86: * @return the scaled and grid-fitted outline of the specified 87: * glyph, or <code>null</code> for bitmap fonts. 88: */ 89: public abstract GeneralPath getOutline(int glyph, 90: float pointSize, 91: AffineTransform transform, 92: boolean antialias, 93: boolean fractionalMetrics, 94: Hinter hinter, int type); 95: 96: 97: /** 98: * Determines the advance width and height for a glyph. 99: * 100: * @param glyphIndex the glyph whose advance width is to be 101: * determined. 102: * 103: * @param pointSize the point size of the font. 104: * 105: * @param transform a transform that is applied in addition to 106: * scaling to the specified point size. This is often used for 107: * scaling according to the device resolution. Those who lack any 108: * aesthetic sense may also use the transform to slant or stretch 109: * glyphs. 110: * 111: * @param antialias <code>true</code> for anti-aliased rendering, 112: * <code>false</code> for normal rendering. For hinted fonts, 113: * this parameter may indeed affect the result. 114: * 115: * @param fractionalMetrics <code>true</code> for fractional metrics, 116: * <code>false</code> for rounding the result to a pixel boundary. 117: * 118: * @param horizontal <code>true</code> for horizontal line layout, 119: * <code>false</code> for vertical line layout. 120: * 121: * @param advance a point whose <code>x</code> and <code>y</code> 122: * fields will hold the advance in each direction. It is well 123: * possible that both values are non-zero, for example for rotated 124: * text or for Urdu fonts. 125: */ 126: public abstract void getAdvance(int glyphIndex, 127: float pointSize, 128: AffineTransform transform, 129: boolean antialias, 130: boolean fractionalMetrics, 131: boolean horizontal, 132: Point2D advance); 133: 134: 135: /** 136: * Determines the distance between the base line and the highest 137: * ascender. 138: * 139: * @param pointSize the point size of the font. 140: * 141: * @param transform a transform that is applied in addition to 142: * scaling to the specified point size. This is often used for 143: * scaling according to the device resolution. Those who lack any 144: * aesthetic sense may also use the transform to slant or stretch 145: * glyphs. 146: * 147: * @param antialias <code>true</code> for anti-aliased rendering, 148: * <code>false</code> for normal rendering. For hinted fonts, 149: * this parameter may indeed affect the result. 150: * 151: * @param fractionalMetrics <code>true</code> for fractional metrics, 152: * <code>false</code> for rounding the result to a pixel boundary. 153: * 154: * @param horizontal <code>true</code> for horizontal line layout, 155: * <code>false</code> for vertical line layout. 156: * 157: * @return the ascent, which usually is a positive number. 158: */ 159: public abstract float getAscent(float pointSize, 160: AffineTransform transform, 161: boolean antialias, 162: boolean fractionalMetrics, 163: boolean horizontal); 164: 165: 166: /** 167: * Determines the distance between the base line and the lowest 168: * descender. 169: * 170: * @param pointSize the point size of the font. 171: * 172: * @param transform a transform that is applied in addition to 173: * scaling to the specified point size. This is often used for 174: * scaling according to the device resolution. Those who lack any 175: * aesthetic sense may also use the transform to slant or stretch 176: * glyphs. 177: * 178: * @param antialiased <code>true</code> for anti-aliased rendering, 179: * <code>false</code> for normal rendering. For hinted fonts, 180: * this parameter may indeed affect the result. 181: * 182: * @param fractionalMetrics <code>true</code> for fractional metrics, 183: * <code>false</code> for rounding the result to a pixel boundary. 184: * 185: * @param horizontal <code>true</code> for horizontal line layout, 186: * <code>false</code> for vertical line layout. 187: * 188: * @return the descent, which usually is a nagative number. 189: */ 190: public abstract float getDescent(float pointSize, 191: AffineTransform transform, 192: boolean antialiased, 193: boolean fractionalMetrics, 194: boolean horizontal); 195: 196: /** 197: * Returns the raw outline data. This is used for the autofitter atm. 198: * 199: * @param glyph the glyph index 200: * @param transform the transform to apply 201: * 202: * @return the raw glyph outline 203: */ 204: public abstract Zone getRawOutline(int glyph, AffineTransform transform); 205: }