KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > svggen > font > table > GlyfCompositeDescript


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.table;
19
20 import java.io.ByteArrayInputStream JavaDoc;
21 import java.util.Vector JavaDoc;
22
23 /**
24  * Glyph description for composite glyphs. Composite glyphs are made up of one
25  * or more simple glyphs, usually with some sort of transformation applied to
26  * each.
27  *
28  * @version $Id: GlyfCompositeDescript.java,v 1.5 2004/08/18 07:15:20 vhardy Exp $
29  * @author <a HREF="mailto:david@steadystate.co.uk">David Schweinsberg</a>
30  */

31 public class GlyfCompositeDescript extends GlyfDescript {
32
33     private Vector JavaDoc components = new Vector JavaDoc();
34
35     public GlyfCompositeDescript(GlyfTable parentTable,
36                                  ByteArrayInputStream JavaDoc bais) {
37         super(parentTable, (short) -1, bais);
38         
39         // Get all of the composite components
40
GlyfCompositeComp comp;
41         int firstIndex = 0;
42         int firstContour = 0;
43         do {
44             comp = new GlyfCompositeComp(firstIndex, firstContour, bais);
45             components.addElement(comp);
46
47             GlyphDescription desc;
48             desc = parentTable.getDescription(comp.getGlyphIndex());
49             if (desc != null) {
50                 firstIndex += desc.getPointCount();
51                 firstContour += desc.getContourCount();
52             }
53         } while ((comp.getFlags() & GlyfCompositeComp.MORE_COMPONENTS) != 0);
54
55         // Are there hinting intructions to read?
56
if ((comp.getFlags() & GlyfCompositeComp.WE_HAVE_INSTRUCTIONS) != 0) {
57             readInstructions(bais, (bais.read()<<8 | bais.read()));
58         }
59     }
60
61     public int getEndPtOfContours(int i) {
62         GlyfCompositeComp c = getCompositeCompEndPt(i);
63         if (c != null) {
64             GlyphDescription gd = parentTable.getDescription(c.getGlyphIndex());
65             return gd.getEndPtOfContours(i - c.getFirstContour()) + c.getFirstIndex();
66         }
67         return 0;
68     }
69
70     public byte getFlags(int i) {
71         GlyfCompositeComp c = getCompositeComp(i);
72         if (c != null) {
73             GlyphDescription gd = parentTable.getDescription(c.getGlyphIndex());
74             return gd.getFlags(i - c.getFirstIndex());
75         }
76         return 0;
77     }
78
79     public short getXCoordinate(int i) {
80         GlyfCompositeComp c = getCompositeComp(i);
81         if (c != null) {
82             GlyphDescription gd = parentTable.getDescription(c.getGlyphIndex());
83             int n = i - c.getFirstIndex();
84             int x = gd.getXCoordinate(n);
85             int y = gd.getYCoordinate(n);
86             short x1 = (short) c.scaleX(x, y);
87             x1 += c.getXTranslate();
88             return x1;
89         }
90         return 0;
91     }
92
93     public short getYCoordinate(int i) {
94         GlyfCompositeComp c = getCompositeComp(i);
95         if (c != null) {
96             GlyphDescription gd = parentTable.getDescription(c.getGlyphIndex());
97             int n = i - c.getFirstIndex();
98             int x = gd.getXCoordinate(n);
99             int y = gd.getYCoordinate(n);
100             short y1 = (short) c.scaleY(x, y);
101             y1 += c.getYTranslate();
102             return y1;
103         }
104         return 0;
105     }
106
107     public boolean isComposite() {
108         return true;
109     }
110
111     public int getPointCount() {
112         GlyfCompositeComp c = (GlyfCompositeComp) components.elementAt(components.size()-1);
113         return c.getFirstIndex() + parentTable.getDescription(c.getGlyphIndex()).getPointCount();
114     }
115
116     public int getContourCount() {
117         GlyfCompositeComp c = (GlyfCompositeComp) components.elementAt(components.size()-1);
118         return c.getFirstContour() + parentTable.getDescription(c.getGlyphIndex()).getContourCount();
119     }
120
121     public int getComponentIndex(int i) {
122         return ((GlyfCompositeComp)components.elementAt(i)).getFirstIndex();
123     }
124
125     public int getComponentCount() {
126         return components.size();
127     }
128
129     protected GlyfCompositeComp getCompositeComp(int i) {
130         GlyfCompositeComp c;
131         for (int n = 0; n < components.size(); n++) {
132             c = (GlyfCompositeComp) components.elementAt(n);
133             GlyphDescription gd = parentTable.getDescription(c.getGlyphIndex());
134             if (c.getFirstIndex() <= i && i < (c.getFirstIndex() + gd.getPointCount())) {
135                 return c;
136             }
137         }
138         return null;
139     }
140
141     protected GlyfCompositeComp getCompositeCompEndPt(int i) {
142         GlyfCompositeComp c;
143         for (int j = 0; j < components.size(); j++) {
144             c = (GlyfCompositeComp) components.elementAt(j);
145             GlyphDescription gd = parentTable.getDescription(c.getGlyphIndex());
146             if (c.getFirstContour() <= i && i < (c.getFirstContour() + gd.getContourCount())) {
147                 return c;
148             }
149         }
150         return null;
151     }
152 }
153
Popular Tags