1 18 package org.apache.batik.svggen.font.table; 19 20 import java.io.IOException ; 21 import java.io.RandomAccessFile ; 22 23 27 public class CmapFormat4 extends CmapFormat { 28 29 public int language; 30 private int segCountX2; 31 private int searchRange; 32 private int entrySelector; 33 private int rangeShift; 34 private int[] endCode; 35 private int[] startCode; 36 private int[] idDelta; 37 private int[] idRangeOffset; 38 private int[] glyphIdArray; 39 private int segCount; 40 private int first, last; 41 42 protected CmapFormat4(RandomAccessFile raf) throws IOException { 43 super(raf); 44 format = 4; 45 segCountX2 = raf.readUnsignedShort(); 46 segCount = segCountX2 / 2; 47 endCode = new int[segCount]; 48 startCode = new int[segCount]; 49 idDelta = new int[segCount]; 50 idRangeOffset = new int[segCount]; 51 searchRange = raf.readUnsignedShort(); 52 entrySelector = raf.readUnsignedShort(); 53 rangeShift = raf.readUnsignedShort(); 54 last = -1; 55 for (int i = 0; i < segCount; i++) { 56 endCode[i] = raf.readUnsignedShort(); 57 if (endCode[i] > last) last = endCode[i]; 58 } 59 raf.readUnsignedShort(); for (int i = 0; i < segCount; i++) { 61 startCode[i] = raf.readUnsignedShort(); 62 if ((i==0 ) || (startCode[i] < first)) first = startCode[i]; 63 } 64 for (int i = 0; i < segCount; i++) { 65 idDelta[i] = raf.readUnsignedShort(); 66 } 67 for (int i = 0; i < segCount; i++) { 68 idRangeOffset[i] = raf.readUnsignedShort(); 69 } 70 71 int count = (length - 16 - (segCount*8)) / 2; 73 glyphIdArray = new int[count]; 74 for (int i = 0; i < count; i++) { 75 glyphIdArray[i] = raf.readUnsignedShort(); 76 } 77 } 78 79 public int getFirst() { return first; } 80 public int getLast() { return last; } 81 82 public int mapCharCode(int charCode) { 83 try { 84 99 if ((charCode < 0) || (charCode >= 0xFFFE)) 100 return 0; 101 102 for (int i = 0; i < segCount; i++) { 103 if (endCode[i] >= charCode) { 104 if (startCode[i] <= charCode) { 105 if (idRangeOffset[i] > 0) { 106 return glyphIdArray[idRangeOffset[i]/2 + 107 (charCode - startCode[i]) - 108 (segCount - i)]; 109 } else { 110 return (idDelta[i] + charCode) % 65536; 111 } 112 } else { 113 break; 114 } 115 } 116 } 117 } catch (ArrayIndexOutOfBoundsException e) { 118 System.err.println("error: Array out of bounds - " + e.getMessage()); 119 } 120 return 0; 121 } 122 123 public String toString() { 124 return new StringBuffer () 125 .append(super.toString()) 126 .append(", segCountX2: ") 127 .append(segCountX2) 128 .append(", searchRange: ") 129 .append(searchRange) 130 .append(", entrySelector: ") 131 .append(entrySelector) 132 .append(", rangeShift: ") 133 .append(rangeShift) 134 .append(", endCode: ") 135 .append(endCode) 136 .append(", startCode: ") 137 .append(endCode) 138 .append(", idDelta: ") 139 .append(idDelta) 140 .append(", idRangeOffset: ") 141 .append(idRangeOffset).toString(); 142 } 143 } 144 | Popular Tags |