OSDN Git Service

83a31c576c7cc4da4fbd02fbf7d3e6b273745529
[pf3gnuchains/gcc-fork.git] / libjava / classpath / gnu / java / awt / font / opentype / Scaler.java
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 &#x201c;hints&#x201d;) 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
95
96   /**
97    * Determines the advance width and height for a glyph.
98    *
99    * @param glyphIndex the glyph whose advance width is to be
100    * determined.
101    *
102    * @param pointSize the point size of the font.
103    *
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
108    * glyphs.
109    *
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.
113    *
114    * @param fractionalMetrics <code>true</code> for fractional metrics,
115    * <code>false</code> for rounding the result to a pixel boundary.
116    *
117    * @param horizontal <code>true</code> for horizontal line layout,
118    * <code>false</code> for vertical line layout.
119    *
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.
124    */
125   public abstract void getAdvance(int glyphIndex,
126                                   float pointSize,
127                                   AffineTransform transform,
128                                   boolean antialias,
129                                   boolean fractionalMetrics,
130                                   boolean horizontal,
131                                   Point2D advance);
132
133
134   /**
135    * Determines the distance between the base line and the highest
136    * ascender.
137    *
138    * @param pointSize the point size of the font.
139    *
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
144    * glyphs.
145    *
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.
149    *
150    * @param fractionalMetrics <code>true</code> for fractional metrics,
151    * <code>false</code> for rounding the result to a pixel boundary.
152    *
153    * @param horizontal <code>true</code> for horizontal line layout,
154    * <code>false</code> for vertical line layout.
155    *
156    * @return the ascent, which usually is a positive number.
157    */
158   public abstract float getAscent(float pointSize,
159                                   AffineTransform transform,
160                                   boolean antialias,
161                                   boolean fractionalMetrics,
162                                   boolean horizontal);
163
164
165   /**
166    * Determines the distance between the base line and the lowest
167    * descender.
168    *
169    * @param pointSize the point size of the font.
170    *
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
175    * glyphs.
176    *
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.
180    *
181    * @param fractionalMetrics <code>true</code> for fractional metrics,
182    * <code>false</code> for rounding the result to a pixel boundary.
183    *
184    * @param horizontal <code>true</code> for horizontal line layout,
185    * <code>false</code> for vertical line layout.
186    *
187    * @return the descent, which usually is a nagative number.
188    */
189   public abstract float getDescent(float pointSize,
190                                    AffineTransform transform,
191                                    boolean antialiased,
192                                    boolean fractionalMetrics,
193                                    boolean horizontal);
194
195   /**
196    * Returns the raw outline data. This is used for the autofitter atm.
197    *
198    * @param glyph the glyph index
199    * @param transform the transform to apply
200    *
201    * @return the raw glyph outline
202    */
203   public abstract Zone getRawOutline(int glyph, AffineTransform transform);
204 }