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.ByteArrayInputStream;
22: import java.io.IOException;
23: import java.io.RandomAccessFile;
24:
25: /**
26: * @version $Id: LocaTable.java 475477 2006-11-15 22:44:28Z cam $
27: * @author <a href="mailto:david@steadystate.co.uk">David Schweinsberg</a>
28: */
29: public class LocaTable implements Table {
30:
31: private byte[] buf = null;
32: private int[] offsets = null;
33: private short factor = 0;
34:
35: protected LocaTable(DirectoryEntry de, RandomAccessFile raf)
36: throws IOException {
37: raf.seek(de.getOffset());
38: buf = new byte[de.getLength()];
39: raf.read(buf);
40: }
41:
42: public void init(int numGlyphs, boolean shortEntries) {
43: if (buf == null) {
44: return;
45: }
46: offsets = new int[numGlyphs + 1];
47: ByteArrayInputStream bais = new ByteArrayInputStream(buf);
48: if (shortEntries) {
49: factor = 2;
50: for (int i = 0; i <= numGlyphs; i++) {
51: offsets[i] = (bais.read() << 8 | bais.read());
52: }
53: } else {
54: factor = 1;
55: for (int i = 0; i <= numGlyphs; i++) {
56: offsets[i] = (bais.read() << 24 | bais.read() << 16
57: | bais.read() << 8 | bais.read());
58: }
59: }
60: buf = null;
61: }
62:
63: public int getOffset(int i) {
64: if (offsets == null) {
65: return 0;
66: }
67: return offsets[i] * factor;
68: }
69:
70: public int getType() {
71: return loca;
72: }
73: }
|