1 /* Latin.java -- Latin specific glyph handling
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. */
39 package gnu.java.awt.font.autofit;
41 import java.awt.geom.AffineTransform;
43 import gnu.java.awt.font.opentype.OpenTypeFont;
44 import gnu.java.awt.font.opentype.truetype.Zone;
47 * Implements Latin specific glyph handling.
50 implements Script, Constants
53 private static final int MAX_WIDTHS = 16;
55 public void applyHints(GlyphHints hints, ScriptMetrics metrics)
57 // TODO Auto-generated method stub
61 public void doneMetrics(ScriptMetrics metrics)
63 // TODO Auto-generated method stub
68 * Initializes the <code>hints</code> object.
70 * @param hints the hints to initialize
71 * @param metrics the metrics to use
73 public void initHints(GlyphHints hints, ScriptMetrics metrics)
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.
85 * Initializes the script metrics.
87 * @param metrics the script metrics to initialize
88 * @param face the font
90 public void initMetrics(ScriptMetrics metrics, OpenTypeFont face)
92 assert metrics instanceof LatinMetrics;
93 LatinMetrics lm = (LatinMetrics) metrics;
94 lm.unitsPerEm = face.unitsPerEm;
96 // TODO: Check for latin charmap.
98 initWidths(lm, face, 'o');
102 public void scaleMetrics(ScriptMetrics metrics)
104 // TODO Auto-generated method stub
109 * Determines the standard stem widths.
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
115 private void initWidths(LatinMetrics metrics, OpenTypeFont face, char ch)
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;
131 hints.rescale(dummy);
132 hints.reload(outline);
133 for (int dim = 0; dim < DIMENSION_MAX; dim++)
135 LatinAxis axis = metrics.axis[dim];
136 AxisHints axHints = hints.axis[dim];
138 hints.computeSegments(dim);
139 hints.linkSegments(dim);
140 Segment[] segs = axHints.segments;
141 for (int i = 0; i < segs.length; i++)
143 Segment seg = segs[i];
144 Segment link = seg.link;
145 if (link != null && link.link == seg && link.index > i)
147 int dist = Math.abs(seg.pos - link.pos);
148 if (numWidths < MAX_WIDTHS)
149 axis.widths[numWidths++].org = dist;
153 for (int dim = 0; dim < DIMENSION_MAX; dim++)
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;
163 * Initializes the blue zones of the font.
165 * @param metrics the metrics to use
166 * @param face the font face to analyze
168 private void initBlues(LatinMetrics metrics, OpenTypeFont face)
173 private int constant(LatinMetrics metrics, int c)
175 return c * (metrics.unitsPerEm / 2048);