01: /*
02:
03: Licensed to the Apache Software Foundation (ASF) under one or more
04: contributor license agreements. See the NOTICE file distributed with
05: this work for additional information regarding copyright ownership.
06: The ASF licenses this file to You under the Apache License, Version 2.0
07: (the "License"); you may not use this file except in compliance with
08: the License. You may obtain a copy of the License at
09:
10: http://www.apache.org/licenses/LICENSE-2.0
11:
12: Unless required by applicable law or agreed to in writing, software
13: distributed under the License is distributed on an "AS IS" BASIS,
14: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: See the License for the specific language governing permissions and
16: limitations under the License.
17:
18: */
19: package org.apache.batik.svggen.font.table;
20:
21: import java.io.IOException;
22: import java.io.RandomAccessFile;
23:
24: /**
25: * @version $Id: TableDirectory.java 475477 2006-11-15 22:44:28Z cam $
26: * @author <a href="mailto:david@steadystate.co.uk">David Schweinsberg</a>
27: */
28: public class TableDirectory {
29:
30: private int version = 0;
31: private short numTables = 0;
32: private short searchRange = 0;
33: private short entrySelector = 0;
34: private short rangeShift = 0;
35: private DirectoryEntry[] entries;
36:
37: public TableDirectory(RandomAccessFile raf) throws IOException {
38: version = raf.readInt();
39: numTables = raf.readShort();
40: searchRange = raf.readShort();
41: entrySelector = raf.readShort();
42: rangeShift = raf.readShort();
43: entries = new DirectoryEntry[numTables];
44: for (int i = 0; i < numTables; i++) {
45: entries[i] = new DirectoryEntry(raf);
46: }
47:
48: // Sort them into file order (simple bubble sort)
49: boolean modified = true;
50: while (modified) {
51: modified = false;
52: for (int i = 0; i < numTables - 1; i++) {
53: if (entries[i].getOffset() > entries[i + 1].getOffset()) {
54: DirectoryEntry temp = entries[i];
55: entries[i] = entries[i + 1];
56: entries[i + 1] = temp;
57: modified = true;
58: }
59: }
60: }
61: }
62:
63: public DirectoryEntry getEntry(int index) {
64: return entries[index];
65: }
66:
67: public DirectoryEntry getEntryByTag(int tag) {
68: for (int i = 0; i < numTables; i++) {
69: if (entries[i].getTag() == tag) {
70: return entries[i];
71: }
72: }
73: return null;
74: }
75:
76: public short getEntrySelector() {
77: return entrySelector;
78: }
79:
80: public short getNumTables() {
81: return numTables;
82: }
83:
84: public short getRangeShift() {
85: return rangeShift;
86: }
87:
88: public short getSearchRange() {
89: return searchRange;
90: }
91:
92: public int getVersion() {
93: return version;
94: }
95: }
|