KickJava   Java API By Example, From Geeks To Geeks.

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


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: NameTable.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 NameTable implements Table {
28
29     private short formatSelector;
30     private short numberOfNameRecords;
31     private short stringStorageOffset;
32     private NameRecord[] records;
33
34     protected NameTable(DirectoryEntry de,RandomAccessFile JavaDoc raf) throws IOException JavaDoc {
35         raf.seek(de.getOffset());
36         formatSelector = raf.readShort();
37         numberOfNameRecords = raf.readShort();
38         stringStorageOffset = raf.readShort();
39         records = new NameRecord[numberOfNameRecords];
40         
41         // Load the records, which contain the encoding information and string offsets
42
for (int i = 0; i < numberOfNameRecords; i++) {
43             records[i] = new NameRecord(raf);
44         }
45         
46         // Now load the strings
47
for (int i = 0; i < numberOfNameRecords; i++) {
48             records[i].loadString(raf, de.getOffset() + stringStorageOffset);
49         }
50     }
51
52     public String JavaDoc getRecord(short nameId) {
53
54         // Search for the first instance of this name ID
55
for (int i = 0; i < numberOfNameRecords; i++) {
56             if (records[i].getNameId() == nameId) {
57                 return records[i].getRecordString();
58             }
59         }
60         return "";
61     }
62
63     public int getType() {
64         return name;
65     }
66 }
67
Popular Tags