KickJava   Java API By Example, From Geeks To Geeks.

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


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

27 public class TableDirectory {
28
29     private int version = 0;
30     private short numTables = 0;
31     private short searchRange = 0;
32     private short entrySelector = 0;
33     private short rangeShift = 0;
34     private DirectoryEntry[] entries;
35
36     public TableDirectory(RandomAccessFile JavaDoc raf) throws IOException JavaDoc {
37         version = raf.readInt();
38         numTables = raf.readShort();
39         searchRange = raf.readShort();
40         entrySelector = raf.readShort();
41         rangeShift = raf.readShort();
42         entries = new DirectoryEntry[numTables];
43         for (int i = 0; i < numTables; i++) {
44             entries[i] = new DirectoryEntry(raf);
45         }
46
47         // Sort them into file order (simple bubble sort)
48
boolean modified = true;
49         while (modified) {
50             modified = false;
51             for (int i = 0; i < numTables - 1; i++) {
52                 if (entries[i].getOffset() > entries[i+1].getOffset()) {
53                     DirectoryEntry temp = entries[i];
54                     entries[i] = entries[i+1];
55                     entries[i+1] = temp;
56                     modified = true;
57                 }
58             }
59         }
60     }
61
62     public DirectoryEntry getEntry(int index) {
63         return entries[index];
64     }
65
66     public DirectoryEntry getEntryByTag(int tag) {
67         for (int i = 0; i < numTables; i++) {
68             if (entries[i].getTag() == tag) {
69                 return entries[i];
70             }
71         }
72         return null;
73     }
74
75     public short getEntrySelector() {
76         return entrySelector;
77     }
78
79     public short getNumTables() {
80         return numTables;
81     }
82
83     public short getRangeShift() {
84         return rangeShift;
85     }
86
87     public short getSearchRange() {
88         return searchRange;
89     }
90
91     public int getVersion() {
92         return version;
93     }
94 }
95
Popular Tags