KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Simple Macintosh cmap table, mapping only the ASCII character set to glyphs.
25  *
26  * @version $Id: CmapFormat0.java,v 1.4 2004/09/01 09:35:23 deweese Exp $
27  * @author <a HREF="mailto:david@steadystate.co.uk">David Schweinsberg</a>
28  */

29 public class CmapFormat0 extends CmapFormat {
30
31     private int[] glyphIdArray = new int[256];
32     private int first, last;
33
34     protected CmapFormat0(RandomAccessFile JavaDoc raf) throws IOException JavaDoc {
35         super(raf);
36         format = 0;
37         first = -1;
38         for (int i = 0; i < 256; i++) {
39             glyphIdArray[i] = raf.readUnsignedByte();
40             if (glyphIdArray[i] > 0) {
41                 if (first == -1) first = i;
42                 last = i;
43             }
44         }
45     }
46
47     public int getFirst() { return first; }
48     public int getLast() { return last; }
49
50     public int mapCharCode(int charCode) {
51         if (0 <= charCode && charCode < 256) {
52             return glyphIdArray[charCode];
53         } else {
54             return 0;
55         }
56     }
57 }
58
Popular Tags