KickJava   Java API By Example, From Geeks To Geeks.

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


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: NameRecord.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 NameRecord {
28
29     private short platformId;
30     private short encodingId;
31     private short languageId;
32     private short nameId;
33     private short stringLength;
34     private short stringOffset;
35     private String JavaDoc record;
36
37     protected NameRecord(RandomAccessFile JavaDoc raf) throws IOException JavaDoc {
38         platformId = raf.readShort();
39         encodingId = raf.readShort();
40         languageId = raf.readShort();
41         nameId = raf.readShort();
42         stringLength = raf.readShort();
43         stringOffset = raf.readShort();
44     }
45     
46     public short getEncodingId() {
47         return encodingId;
48     }
49     
50     public short getLanguageId() {
51         return languageId;
52     }
53     
54     public short getNameId() {
55         return nameId;
56     }
57     
58     public short getPlatformId() {
59         return platformId;
60     }
61
62     public String JavaDoc getRecordString() {
63         return record;
64     }
65
66     protected void loadString(RandomAccessFile JavaDoc raf, int stringStorageOffset) throws IOException JavaDoc {
67         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
68         raf.seek(stringStorageOffset + stringOffset);
69         if (platformId == Table.platformAppleUnicode) {
70             
71             // Unicode (big-endian)
72
for (int i = 0; i < stringLength/2; i++) {
73                 sb.append(raf.readChar());
74             }
75         } else if (platformId == Table.platformMacintosh) {
76
77             // Macintosh encoding, ASCII
78
for (int i = 0; i < stringLength; i++) {
79                 sb.append((char) raf.readByte());
80             }
81         } else if (platformId == Table.platformISO) {
82             
83             // ISO encoding, ASCII
84
for (int i = 0; i < stringLength; i++) {
85                 sb.append((char) raf.readByte());
86             }
87         } else if (platformId == Table.platformMicrosoft) {
88             
89             // Microsoft encoding, Unicode
90
char c;
91             for (int i = 0; i < stringLength/2; i++) {
92                 c = raf.readChar();
93                 sb.append(c);
94             }
95         }
96         record = sb.toString();
97     }
98 }
99
Popular Tags