1 17 18 19 20 package org.apache.fop.fonts; 21 22 import java.util.Map ; 24 25 28 public class MultiByteFont extends CIDFont { 29 30 private static int uniqueCounter = 1; 31 32 33 private String ttcName = null; 34 private String encoding = "Identity-H"; 35 36 private int defaultWidth = 0; 37 private CIDFontType cidType = CIDFontType.CIDTYPE2; 38 39 private String namePrefix = null; 41 private BFEntry[] bfentries = null; 42 43 46 public MultiByteFont() { 47 usedGlyphs.put(new Integer (0), new Integer (0)); 49 usedGlyphsIndex.put(new Integer (0), new Integer (0)); 50 usedGlyphsCount++; 51 usedGlyphs.put(new Integer (1), new Integer (1)); 52 usedGlyphsIndex.put(new Integer (1), new Integer (1)); 53 usedGlyphsCount++; 54 usedGlyphs.put(new Integer (2), new Integer (2)); 55 usedGlyphsIndex.put(new Integer (2), new Integer (2)); 56 usedGlyphsCount++; 57 58 int cnt = 0; 60 synchronized (this.getClass()) { 61 cnt = uniqueCounter++; 62 } 63 int ctm = (int)(System.currentTimeMillis() & 0xffff); 64 namePrefix = new String (cnt + "E" + Integer.toHexString(ctm)); 65 66 setFontType(FontType.TYPE0); 67 } 68 69 72 public int getDefaultWidth() { 73 return defaultWidth; 74 } 75 76 79 public String getRegistry() { 80 return "Adobe"; 81 } 82 83 86 public String getOrdering() { 87 return "UCS"; 88 } 89 90 93 public int getSupplement() { 94 return 0; 95 } 96 97 100 public CIDFontType getCIDType() { 101 return cidType; 102 } 103 104 108 public void setCIDType(CIDFontType cidType) { 109 this.cidType = cidType; 110 } 111 112 115 public String getCidBaseFont() { 116 if (isEmbeddable()) { 117 return namePrefix + super.getFontName(); 118 } else { 119 return super.getFontName(); 120 } 121 } 122 123 126 public boolean isEmbeddable() { 127 return !(getEmbedFileName() == null && embedResourceName == null); 128 } 129 130 133 public String getEncoding() { 134 return encoding; 135 } 136 137 140 public String getFontName() { 141 if (isEmbeddable()) { 142 return namePrefix + super.getFontName(); 143 } else { 144 return super.getFontName(); 145 } 146 } 147 148 151 public int getWidth(int i, int size) { 152 if (isEmbeddable()) { 153 Integer idx = (Integer )usedGlyphsIndex.get(new Integer (i)); 154 return size * width[idx.intValue()]; 155 } else { 156 return size * width[i]; 157 } 158 } 159 160 163 public int[] getWidths() { 164 int[] arr = new int[width.length]; 165 System.arraycopy(width, 0, arr, 0, width.length - 1); 166 170 return arr; 171 } 172 173 178 192 193 private int findGlyphIndex(char c) { 194 int idx = (int)c; 195 int retIdx = 0; 196 197 for (int i = 0; (i < bfentries.length) && retIdx == 0; i++) { 198 if (bfentries[i].getUnicodeStart() <= idx 199 && bfentries[i].getUnicodeEnd() >= idx) { 200 201 retIdx = bfentries[i].getGlyphStartIndex() 202 + idx 203 - bfentries[i].getUnicodeStart(); 204 } 205 } 206 return retIdx; 207 } 208 209 212 public char mapChar(char c) { 213 int retIdx = findGlyphIndex(c); 214 215 if (isEmbeddable()) { 216 Integer newIdx = (Integer )usedGlyphs.get(new Integer (retIdx)); 219 if (newIdx == null) { 220 usedGlyphs.put(new Integer (retIdx), 221 new Integer (usedGlyphsCount)); 222 usedGlyphsIndex.put(new Integer (usedGlyphsCount), 223 new Integer (retIdx)); 224 usedCharsIndex.put(new Integer (usedGlyphsCount), 225 new Integer ((int) c)); 226 retIdx = usedGlyphsCount; 227 usedGlyphsCount++; 228 } else { 229 retIdx = newIdx.intValue(); 230 } 231 } 232 233 return (char)retIdx; 234 } 235 236 239 public boolean hasChar(char c) { 240 return (findGlyphIndex(c) > 0); 241 } 242 243 244 248 public void setBFEntries(BFEntry[] bfentries) { 249 this.bfentries = bfentries; 250 } 251 252 256 public void setDefaultWidth(int defaultWidth) { 257 this.defaultWidth = defaultWidth; 258 } 259 260 264 public String getTTCName() { 265 return ttcName; 266 } 267 268 272 public void setTTCName(String ttcName) { 273 this.ttcName = ttcName; 274 } 275 276 281 285 286 287 291 public void setWidthArray(int[] wds) { 292 this.width = wds; 293 } 294 295 299 public Map getUsedGlyphs() { 300 return usedGlyphs; 301 } 302 303 305 public static final char INVALID_UNICODE_CHAR = 0xFFFF; 306 307 308 public char[] getCharsUsed() { 309 if (!isEmbeddable()) { 310 return null; 311 } 312 char[] charArray = new char[usedGlyphsCount]; 313 for (int i = 0; i < usedGlyphsCount; i++) { 314 Integer mapValue = (Integer )usedCharsIndex.get(new Integer (i)); 315 if (mapValue != null) { 316 char arrayItem = (char) mapValue.intValue(); 317 charArray[i] = arrayItem; 318 } 319 else { 320 charArray[i] = INVALID_UNICODE_CHAR; 321 } 322 } 323 return charArray; 324 } 325 } 326 327 | Popular Tags |