001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.svggen.font.table;
020:
021: import java.io.IOException;
022: import java.io.RandomAccessFile;
023:
024: /**
025: * @version $Id: NameRecord.java 475477 2006-11-15 22:44:28Z cam $
026: * @author <a href="mailto:david@steadystate.co.uk">David Schweinsberg</a>
027: */
028: public class NameRecord {
029:
030: private short platformId;
031: private short encodingId;
032: private short languageId;
033: private short nameId;
034: private short stringLength;
035: private short stringOffset;
036: private String record;
037:
038: protected NameRecord(RandomAccessFile raf) throws IOException {
039: platformId = raf.readShort();
040: encodingId = raf.readShort();
041: languageId = raf.readShort();
042: nameId = raf.readShort();
043: stringLength = raf.readShort();
044: stringOffset = raf.readShort();
045: }
046:
047: public short getEncodingId() {
048: return encodingId;
049: }
050:
051: public short getLanguageId() {
052: return languageId;
053: }
054:
055: public short getNameId() {
056: return nameId;
057: }
058:
059: public short getPlatformId() {
060: return platformId;
061: }
062:
063: public String getRecordString() {
064: return record;
065: }
066:
067: protected void loadString(RandomAccessFile raf,
068: int stringStorageOffset) throws IOException {
069: StringBuffer sb = new StringBuffer();
070: raf.seek(stringStorageOffset + stringOffset);
071: if (platformId == Table.platformAppleUnicode) {
072:
073: // Unicode (big-endian)
074: for (int i = 0; i < stringLength / 2; i++) {
075: sb.append(raf.readChar());
076: }
077: } else if (platformId == Table.platformMacintosh) {
078:
079: // Macintosh encoding, ASCII
080: for (int i = 0; i < stringLength; i++) {
081: sb.append((char) raf.readByte());
082: }
083: } else if (platformId == Table.platformISO) {
084:
085: // ISO encoding, ASCII
086: for (int i = 0; i < stringLength; i++) {
087: sb.append((char) raf.readByte());
088: }
089: } else if (platformId == Table.platformMicrosoft) {
090:
091: // Microsoft encoding, Unicode
092: char c;
093: for (int i = 0; i < stringLength / 2; i++) {
094: c = raf.readChar();
095: sb.append(c);
096: }
097: }
098: record = sb.toString();
099: }
100: }
|