123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- package com.sun.pdfview.font.ttf;
- import net.sf.andpdf.pdfviewer.ByteBuffer;
- import java.util.*;
- public class CMapFormat6 extends CMap {
-
- private short firstCode;
-
- private short entryCount;
-
- private short [] glyphIndexArray;
-
- private HashMap<Short,Short> glyphLookup = new HashMap<Short,Short>();
-
- protected CMapFormat6(short language) {
- super((short) 6, language);
- }
-
- public short getLength() {
-
- short size = 5 * 2;
-
- size += entryCount * 2;
- return size;
- }
-
- public byte map(byte src) {
- char c = map((char) src);
- if (c < Byte.MIN_VALUE || c > Byte.MAX_VALUE) {
-
- return 0;
- }
- return (byte) c;
- }
-
- public char map(char src) {
-
- if (src < firstCode || src > (firstCode + entryCount)) {
-
-
- return '\000';
- }
- return (char) glyphIndexArray[src - firstCode];
- }
-
- public char reverseMap(short glyphID) {
- Short result = glyphLookup.get(new Short(glyphID));
- if (result == null) {
- return '\000';
- }
- return (char) result.shortValue();
- }
-
- public void setData(int length, ByteBuffer data) {
-
- firstCode = data.getShort();
- entryCount = data.getShort();
- glyphIndexArray = new short [entryCount];
- for (int i = 0; i < glyphIndexArray.length; i++) {
- glyphIndexArray[i] = data.getShort();
- glyphLookup.put(new Short(glyphIndexArray[i]),
- new Short((short) (i + firstCode)));
- }
- }
-
- public ByteBuffer getData() {
- ByteBuffer buf = ByteBuffer.allocate(getLength());
-
- buf.putShort(getFormat());
- buf.putShort((short) getLength());
- buf.putShort(getLanguage());
-
- buf.putShort(firstCode);
- buf.putShort(entryCount);
-
- for (int i = 0; i < glyphIndexArray.length; i++) {
- buf.putShort(glyphIndexArray[i]);
- }
-
- buf.flip();
- return buf;
- }
- }
|