1 /* Scaler.java -- Common superclass for font scalers.
2 Copyright (C) 2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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)
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.
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
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
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. */
38 package gnu.java.awt.font.opentype;
40 import gnu.java.awt.font.opentype.truetype.Zone;
42 import java.awt.geom.AffineTransform;
43 import java.awt.geom.GeneralPath;
44 import java.awt.geom.Point2D;
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.
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
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
62 * @author Sascha Brawer (brawer@dandelis.ch)
64 public abstract class Scaler
67 * Retrieves the scaled outline of a glyph, adjusting control points
68 * to the raster grid if necessary.
70 * @param glyph the glyph number whose outline is retrieved.
72 * @param pointSize the point size of the font.
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
80 * @param antialias whether or not the rasterizer will perform
81 * anti-aliasing on the returned path.
83 * @param fractionalMetrics <code>false</code> for adjusting glyph
84 * positions to the raster grid of device space.
86 * @return the scaled and grid-fitted outline of the specified
87 * glyph, or <code>null</code> for bitmap fonts.
89 public abstract GeneralPath getOutline(int glyph,
91 AffineTransform transform,
93 boolean fractionalMetrics);
97 * Determines the advance width and height for a glyph.
99 * @param glyphIndex the glyph whose advance width is to be
102 * @param pointSize the point size of the font.
104 * @param transform a transform that is applied in addition to
105 * scaling to the specified point size. This is often used for
106 * scaling according to the device resolution. Those who lack any
107 * aesthetic sense may also use the transform to slant or stretch
110 * @param antialias <code>true</code> for anti-aliased rendering,
111 * <code>false</code> for normal rendering. For hinted fonts,
112 * this parameter may indeed affect the result.
114 * @param fractionalMetrics <code>true</code> for fractional metrics,
115 * <code>false</code> for rounding the result to a pixel boundary.
117 * @param horizontal <code>true</code> for horizontal line layout,
118 * <code>false</code> for vertical line layout.
120 * @param advance a point whose <code>x</code> and <code>y</code>
121 * fields will hold the advance in each direction. It is well
122 * possible that both values are non-zero, for example for rotated
123 * text or for Urdu fonts.
125 public abstract void getAdvance(int glyphIndex,
127 AffineTransform transform,
129 boolean fractionalMetrics,
135 * Determines the distance between the base line and the highest
138 * @param pointSize the point size of the font.
140 * @param transform a transform that is applied in addition to
141 * scaling to the specified point size. This is often used for
142 * scaling according to the device resolution. Those who lack any
143 * aesthetic sense may also use the transform to slant or stretch
146 * @param antialias <code>true</code> for anti-aliased rendering,
147 * <code>false</code> for normal rendering. For hinted fonts,
148 * this parameter may indeed affect the result.
150 * @param fractionalMetrics <code>true</code> for fractional metrics,
151 * <code>false</code> for rounding the result to a pixel boundary.
153 * @param horizontal <code>true</code> for horizontal line layout,
154 * <code>false</code> for vertical line layout.
156 * @return the ascent, which usually is a positive number.
158 public abstract float getAscent(float pointSize,
159 AffineTransform transform,
161 boolean fractionalMetrics,
166 * Determines the distance between the base line and the lowest
169 * @param pointSize the point size of the font.
171 * @param transform a transform that is applied in addition to
172 * scaling to the specified point size. This is often used for
173 * scaling according to the device resolution. Those who lack any
174 * aesthetic sense may also use the transform to slant or stretch
177 * @param antialiased <code>true</code> for anti-aliased rendering,
178 * <code>false</code> for normal rendering. For hinted fonts,
179 * this parameter may indeed affect the result.
181 * @param fractionalMetrics <code>true</code> for fractional metrics,
182 * <code>false</code> for rounding the result to a pixel boundary.
184 * @param horizontal <code>true</code> for horizontal line layout,
185 * <code>false</code> for vertical line layout.
187 * @return the descent, which usually is a nagative number.
189 public abstract float getDescent(float pointSize,
190 AffineTransform transform,
192 boolean fractionalMetrics,
196 * Returns the raw outline data. This is used for the autofitter atm.
198 * @param glyph the glyph index
199 * @param transform the transform to apply
201 * @return the raw glyph outline
203 public abstract Zone getRawOutline(int glyph, AffineTransform transform);