KickJava   Java API By Example, From Geeks To Geeks.

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


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: LocaTable.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 LocaTable implements Table {
29
30     private byte[] buf = null;
31     private int[] offsets = null;
32     private short factor = 0;
33
34     protected LocaTable(DirectoryEntry de, RandomAccessFile JavaDoc raf) throws IOException JavaDoc {
35         raf.seek(de.getOffset());
36         buf = new byte[de.getLength()];
37         raf.read(buf);
38     }
39
40     public void init(int numGlyphs, boolean shortEntries) {
41         if (buf == null) {
42             return;
43         }
44         offsets = new int[numGlyphs + 1];
45         ByteArrayInputStream JavaDoc bais = new ByteArrayInputStream JavaDoc(buf);
46         if (shortEntries) {
47             factor = 2;
48             for (int i = 0; i <= numGlyphs; i++) {
49                 offsets[i] = (bais.read()<<8 | bais.read());
50             }
51         } else {
52             factor = 1;
53             for (int i = 0; i <= numGlyphs; i++) {
54                 offsets[i] = (bais.read()<<24 | bais.read()<<16 |
55                               bais.read()<< 8 | bais.read());
56             }
57         }
58         buf = null;
59     }
60     
61     public int getOffset(int i) {
62         if (offsets == null) {
63             return 0;
64         }
65         return offsets[i] * factor;
66     }
67
68     public int getType() {
69         return loca;
70     }
71 }
72
Popular Tags