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: CmapTable.java 476924 2006-11-19 21:13:26Z dvholten $
26: * @author <a href="mailto:david@steadystate.co.uk">David Schweinsberg</a>
27: */
28: public class CmapTable implements Table {
29:
30: private int version;
31: private int numTables;
32: private CmapIndexEntry[] entries;
33: private CmapFormat[] formats;
34:
35: protected CmapTable(DirectoryEntry de, RandomAccessFile raf)
36: throws IOException {
37: raf.seek(de.getOffset());
38: long fp = raf.getFilePointer();
39: version = raf.readUnsignedShort();
40: numTables = raf.readUnsignedShort();
41: entries = new CmapIndexEntry[numTables];
42: formats = new CmapFormat[numTables];
43:
44: // Get each of the index entries
45: for (int i = 0; i < numTables; i++) {
46: entries[i] = new CmapIndexEntry(raf);
47: }
48:
49: // Get each of the tables
50: for (int i = 0; i < numTables; i++) {
51: raf.seek(fp + entries[i].getOffset());
52: int format = raf.readUnsignedShort();
53: formats[i] = CmapFormat.create(format, raf);
54: }
55: }
56:
57: public CmapFormat getCmapFormat(short platformId, short encodingId) {
58:
59: // Find the requested format
60: for (int i = 0; i < numTables; i++) {
61: if (entries[i].getPlatformId() == platformId
62: && entries[i].getEncodingId() == encodingId) {
63: return formats[i];
64: }
65: }
66: return null;
67: }
68:
69: public int getType() {
70: return cmap;
71: }
72:
73: public String toString() {
74: StringBuffer sb = new StringBuffer(numTables * 8)
75: .append("cmap\n");
76:
77: // Get each of the index entries
78: for (int i = 0; i < numTables; i++) {
79: sb.append('\t').append(entries[i].toString()).append('\n');
80: }
81:
82: // Get each of the tables
83: for (int i = 0; i < numTables; i++) {
84: sb.append('\t').append(formats[i].toString()).append('\n');
85: }
86: return sb.toString();
87: }
88: }
|