KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > svggen > font > Glyph


1 /*
2
3    Copyright 2001,2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.svggen.font;
19
20 import org.apache.batik.svggen.font.table.GlyfDescript;
21 import org.apache.batik.svggen.font.table.GlyphDescription;
22
23 /**
24  * An individual glyph within a font.
25  * @version $Id: Glyph.java,v 1.4 2004/08/18 07:15:18 vhardy Exp $
26  * @author <a HREF="mailto:david@steadystate.co.uk">David Schweinsberg</a>
27  */

28 public class Glyph {
29
30     protected short leftSideBearing;
31     protected int advanceWidth;
32     private Point[] points;
33
34     public Glyph(GlyphDescription gd, short lsb, int advance) {
35         leftSideBearing = lsb;
36         advanceWidth = advance;
37         describe(gd);
38     }
39
40     public int getAdvanceWidth() {
41         return advanceWidth;
42     }
43
44     public short getLeftSideBearing() {
45         return leftSideBearing;
46     }
47
48     public Point getPoint(int i) {
49         return points[i];
50     }
51
52     public int getPointCount() {
53         return points.length;
54     }
55
56     /**
57      * Resets the glyph to the TrueType table settings
58      */

59     public void reset() {
60     }
61
62     /**
63      * @param factor a 16.16 fixed value
64      */

65     public void scale(int factor) {
66         for (int i = 0; i < points.length; i++) {
67             //points[i].x = ( points[i].x * factor ) >> 6;
68
//points[i].y = ( points[i].y * factor ) >> 6;
69
points[i].x = ((points[i].x<<10) * factor) >> 26;
70             points[i].y = ((points[i].y<<10) * factor) >> 26;
71         }
72         leftSideBearing = (short)(( leftSideBearing * factor) >> 6);
73         advanceWidth = (advanceWidth * factor) >> 6;
74     }
75
76     /**
77      * Set the points of a glyph from the GlyphDescription
78      */

79     private void describe(GlyphDescription gd) {
80         int endPtIndex = 0;
81         points = new Point[gd.getPointCount() + 2];
82         for (int i = 0; i < gd.getPointCount(); i++) {
83             boolean endPt = gd.getEndPtOfContours(endPtIndex) == i;
84             if (endPt) {
85                 endPtIndex++;
86             }
87             points[i] = new Point(
88                     gd.getXCoordinate(i),
89                     gd.getYCoordinate(i),
90                     (gd.getFlags(i) & GlyfDescript.onCurve) != 0,
91                     endPt);
92         }
93
94         // Append the origin and advanceWidth points (n & n+1)
95
points[gd.getPointCount()] = new Point(0, 0, true, true);
96         points[gd.getPointCount()+1] = new Point(advanceWidth, 0, true, true);
97     }
98 }
99
Popular Tags