OSDN Git Service

Merged gcj-eclipse branch to trunk.
[pf3gnuchains/gcc-fork.git] / libjava / classpath / gnu / java / awt / font / autofit / Latin.java
1 /* Latin.java -- Latin specific glyph handling
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
39 package gnu.java.awt.font.autofit;
40
41 import java.awt.geom.AffineTransform;
42
43 import gnu.java.awt.font.opentype.OpenTypeFont;
44 import gnu.java.awt.font.opentype.truetype.Zone;
45
46 /**
47  * Implements Latin specific glyph handling.
48  */
49 class Latin
50   implements Script, Constants
51 {
52
53   private static final int MAX_WIDTHS = 16;
54
55   public void applyHints(GlyphHints hints, ScriptMetrics metrics)
56   {
57     // TODO Auto-generated method stub
58
59   }
60
61   public void doneMetrics(ScriptMetrics metrics)
62   {
63     // TODO Auto-generated method stub
64
65   }
66
67   /**
68    * Initializes the <code>hints</code> object.
69    *
70    * @param hints the hints to initialize
71    * @param metrics the metrics to use
72    */
73   public void initHints(GlyphHints hints, ScriptMetrics metrics)
74   {
75     hints.rescale(metrics);
76     LatinMetrics lm = (LatinMetrics) metrics;
77     hints.xScale = lm.axis[DIMENSION_HORZ].scale;
78     hints.xDelta = lm.axis[DIMENSION_HORZ].delta;
79     hints.yScale = lm.axis[DIMENSION_VERT].scale;
80     hints.yDelta = lm.axis[DIMENSION_VERT].delta;
81     // TODO: Set the scaler and other flags.
82   }
83
84   /**
85    * Initializes the script metrics.
86    *
87    * @param metrics the script metrics to initialize
88    * @param face the font
89    */
90   public void initMetrics(ScriptMetrics metrics, OpenTypeFont face)
91   {
92     assert metrics instanceof LatinMetrics;
93     LatinMetrics lm = (LatinMetrics) metrics;
94     lm.unitsPerEm = face.unitsPerEm;
95
96     // TODO: Check for latin charmap.
97
98     initWidths(lm, face, 'o');
99     initBlues(lm, face);
100   }
101
102   public void scaleMetrics(ScriptMetrics metrics)
103   {
104     // TODO Auto-generated method stub
105
106   }
107
108   /**
109    * Determines the standard stem widths.
110    *
111    * @param metrics the metrics to use
112    * @param face the font face
113    * @param ch the character that is used for getting the widths
114    */
115   private void initWidths(LatinMetrics metrics, OpenTypeFont face, char ch)
116   {
117     GlyphHints hints = new GlyphHints();
118     metrics.axis[DIMENSION_HORZ].widthCount = 0;
119     metrics.axis[DIMENSION_VERT].widthCount = 0;
120     int glyphIndex = face.getGlyph(ch);
121     // TODO: Avoid that AffineTransform constructor and change
122     // getRawGlyphOutline() to accept null or remove that parameter altogether.
123     // Consider this when the thing is done and we know what we need that for.
124     Zone outline = face.getRawGlyphOutline(glyphIndex, new AffineTransform());
125     LatinMetrics dummy = new LatinMetrics();
126     Scaler scaler = dummy.scaler;
127     dummy.unitsPerEm = metrics.unitsPerEm;
128     scaler.xScale = scaler.yScale = 10000;
129     scaler.xDelta = scaler.yDelta = 0;
130     scaler.face = face;
131     hints.rescale(dummy);
132     hints.reload(outline);
133     for (int dim = 0; dim < DIMENSION_MAX; dim++)
134       {
135         LatinAxis axis = metrics.axis[dim];
136         AxisHints axHints = hints.axis[dim];
137         int numWidths = 0;
138         hints.computeSegments(dim);
139         hints.linkSegments(dim);
140         Segment[] segs = axHints.segments;
141         for (int i = 0; i < segs.length; i++)
142           {
143             Segment seg = segs[i];
144             Segment link = seg.link;
145             if (link != null && link.link == seg && link.index > i)
146               {
147                 int dist = Math.abs(seg.pos - link.pos);
148                 if (numWidths < MAX_WIDTHS)
149                   axis.widths[numWidths++].org = dist;
150               }
151           }
152       }
153     for (int dim = 0; dim < DIMENSION_MAX; dim++)
154       {
155         LatinAxis axis = metrics.axis[dim];
156         int stdw = axis.widthCount > 0 ? axis.widths[0].org
157                                        : constant(metrics, 50);
158         axis.edgeDistanceTreshold= stdw / 5;
159       }
160   }
161
162   /**
163    * Initializes the blue zones of the font.
164    *
165    * @param metrics the metrics to use
166    * @param face the font face to analyze
167    */
168   private void initBlues(LatinMetrics metrics, OpenTypeFont face)
169   {
170     // TODO: Implement.
171   }
172
173   private int constant(LatinMetrics metrics, int c)
174   {
175     return c * (metrics.unitsPerEm / 2048);
176   }
177 }