KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.IOException JavaDoc;
22 import java.io.RandomAccessFile JavaDoc;
23
24 /**
25  * @version $Id: GlyfTable.java,v 1.4 2004/08/18 07:15:21 vhardy Exp $
26  * @author <a HREF="mailto:david@steadystate.co.uk">David Schweinsberg</a>
27  */

28 public class GlyfTable implements Table {
29
30     private byte[] buf = null;
31     private GlyfDescript[] descript;
32
33     protected GlyfTable(DirectoryEntry de, RandomAccessFile JavaDoc raf) throws IOException JavaDoc {
34         raf.seek(de.getOffset());
35         buf = new byte[de.getLength()];
36         raf.read(buf);
37 /*
38         TableMaxp t_maxp = (TableMaxp) td.getEntryByTag(maxp).getTable();
39         TableLoca t_loca = (TableLoca) td.getEntryByTag(loca).getTable();
40         descript = new TableGlyfDescript[t_maxp.getNumGlyphs()];
41         for (int i = 0; i < t_maxp.getNumGlyphs(); i++) {
42             raf.seek(tde.getOffset() + t_loca.getOffset(i));
43             int len = t_loca.getOffset((short)(i + 1)) - t_loca.getOffset(i);
44             if (len > 0) {
45                 short numberOfContours = raf.readShort();
46                 if (numberOfContours < 0) {
47                     // descript[i] = new TableGlyfCompositeDescript(this, raf);
48                 } else {
49                     descript[i] = new TableGlyfSimpleDescript(this, numberOfContours, raf);
50                 }
51             } else {
52                 descript[i] = null;
53             }
54         }
55
56         for (int i = 0; i < t_maxp.getNumGlyphs(); i++) {
57             raf.seek(tde.getOffset() + t_loca.getOffset(i));
58             int len = t_loca.getOffset((short)(i + 1)) - t_loca.getOffset(i);
59             if (len > 0) {
60                 short numberOfContours = raf.readShort();
61                 if (numberOfContours < 0) {
62                     descript[i] = new TableGlyfCompositeDescript(this, raf);
63                 }
64             }
65         }
66 */

67     }
68
69     public void init(int numGlyphs, LocaTable loca) {
70         if (buf == null) {
71             return;
72         }
73         descript = new GlyfDescript[numGlyphs];
74         ByteArrayInputStream JavaDoc bais = new ByteArrayInputStream JavaDoc(buf);
75         for (int i = 0; i < numGlyphs; i++) {
76             int len = loca.getOffset((short)(i + 1)) - loca.getOffset(i);
77             if (len > 0) {
78                 bais.reset();
79                 bais.skip(loca.getOffset(i));
80                 short numberOfContours = (short)(bais.read()<<8 | bais.read());
81                 if (numberOfContours >= 0) {
82                     descript[i] = new GlyfSimpleDescript(this, numberOfContours, bais);
83                 }
84             } else {
85                 descript[i] = null;
86             }
87         }
88
89         for (int i = 0; i < numGlyphs; i++) {
90             int len = loca.getOffset((short)(i + 1)) - loca.getOffset(i);
91             if (len > 0) {
92                 bais.reset();
93                 bais.skip(loca.getOffset(i));
94                 short numberOfContours = (short)(bais.read()<<8 | bais.read());
95                 if (numberOfContours < 0) {
96                     descript[i] = new GlyfCompositeDescript(this, bais);
97                 }
98             }
99         }
100         buf = null;
101     }
102
103     public GlyfDescript getDescription(int i) {
104         return descript[i];
105     }
106
107     public int getType() {
108         return glyf;
109     }
110 }
111
Popular Tags