KickJava   Java API By Example, From Geeks To Geeks.

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


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: CmapTable.java,v 1.3 2004/08/18 07:15:20 vhardy Exp $
25  * @author <a HREF="mailto:david@steadystate.co.uk">David Schweinsberg</a>
26  */

27 public class CmapTable implements Table {
28
29     private int version;
30     private int numTables;
31     private CmapIndexEntry[] entries;
32     private CmapFormat[] formats;
33
34     protected CmapTable(DirectoryEntry de, RandomAccessFile JavaDoc raf) throws IOException JavaDoc {
35         raf.seek(de.getOffset());
36         long fp = raf.getFilePointer();
37         version = raf.readUnsignedShort();
38         numTables = raf.readUnsignedShort();
39         entries = new CmapIndexEntry[numTables];
40         formats = new CmapFormat[numTables];
41
42         // Get each of the index entries
43
for (int i = 0; i < numTables; i++) {
44             entries[i] = new CmapIndexEntry(raf);
45         }
46
47         // Get each of the tables
48
for (int i = 0; i < numTables; i++) {
49             raf.seek(fp + entries[i].getOffset());
50             int format = raf.readUnsignedShort();
51             formats[i] = CmapFormat.create(format, raf);
52         }
53     }
54
55     public CmapFormat getCmapFormat(short platformId, short encodingId) {
56
57         // Find the requested format
58
for (int i = 0; i < numTables; i++) {
59             if (entries[i].getPlatformId() == platformId
60                     && entries[i].getEncodingId() == encodingId) {
61                 return formats[i];
62             }
63         }
64         return null;
65     }
66
67     public int getType() {
68         return cmap;
69     }
70
71     public String JavaDoc toString() {
72         StringBuffer JavaDoc sb = new StringBuffer JavaDoc().append("cmap\n");
73
74         // Get each of the index entries
75
for (int i = 0; i < numTables; i++) {
76             sb.append("\t").append(entries[i].toString()).append("\n");
77         }
78
79         // Get each of the tables
80
for (int i = 0; i < numTables; i++) {
81             sb.append("\t").append(formats[i].toString()).append("\n");
82         }
83         return sb.toString();
84     }
85 }
86
Popular Tags