001: /*
002: * $Id: CMap.java,v 1.2 2007/12/20 18:33:31 rbair Exp $
003: *
004: * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
005: * Santa Clara, California 95054, U.S.A. All rights reserved.
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
020: */
021:
022: package com.sun.pdfview.font.ttf;
023:
024: import java.nio.ByteBuffer;
025:
026: /**
027: *
028: * @author jkaplan
029: */
030: public abstract class CMap {
031: /**
032: * The format of this map
033: */
034: private short format;
035:
036: /**
037: * The language of this map, or 0 for language-independent
038: */
039: private short language;
040:
041: /** Creates a new instance of CMap
042: * Don't use this directly, use <code>CMap.createMap()</code>
043: */
044: protected CMap(short format, short language) {
045: this .format = format;
046: this .language = language;
047: }
048:
049: /**
050: * Create a map for the given format and language
051: */
052: public static CMap createMap(short format, short language) {
053: CMap outMap = null;
054:
055: switch (format) {
056: case 0: // CMap format 0
057: outMap = new CMapFormat0(language);
058: break;
059: case 4: // CMap format 4
060: outMap = new CMapFormat4(language);
061: break;
062: default:
063: System.out.println("Unsupport CMap format: " + format);
064: return null;
065: }
066:
067: return outMap;
068: }
069:
070: /**
071: * Get a map from the given data
072: *
073: * This method reads the format, data and length variables of
074: * the map.
075: */
076: public static CMap getMap(ByteBuffer data) {
077: short format = data.getShort();
078: short length = data.getShort();
079:
080: // make sure our slice of the data only contains up to the length
081: // of this table
082: data.limit((int) length);
083:
084: short language = data.getShort();
085:
086: CMap outMap = createMap(format, language);
087: if (outMap == null) {
088: return null;
089: }
090:
091: outMap.setData(length, data);
092:
093: return outMap;
094: }
095:
096: /**
097: * Get the format of this map
098: */
099: public short getFormat() {
100: return format;
101: }
102:
103: /**
104: * Get the language of this map
105: */
106: public short getLanguage() {
107: return language;
108: }
109:
110: /**
111: * Set the data for this map
112: */
113: public abstract void setData(int length, ByteBuffer data);
114:
115: /**
116: * Get the data in this map as a byte buffer
117: */
118: public abstract ByteBuffer getData();
119:
120: /**
121: * Get the length of this map
122: */
123: public abstract short getLength();
124:
125: /**
126: * Map an 8 bit value to another 8 bit value
127: */
128: public abstract byte map(byte src);
129:
130: /**
131: * Map a 16 bit value to another 16 but value
132: */
133: public abstract char map(char src);
134:
135: /**
136: * Get the src code which maps to the given glyphID
137: */
138: public abstract char reverseMap(short glyphID);
139:
140: /** Print a pretty string */
141: @Override
142: public String toString() {
143: String indent = " ";
144:
145: return indent + " format: " + getFormat() + " length: "
146: + getLength() + " language: " + getLanguage() + "\n";
147: }
148: }
|