/** * Sets the kerning between two Unicode chars. * * @param char1 the first char * @param char2 the second char * @param kern the kerning to apply in normalized 1000 units * @return <code>true</code> if the kerning was applied, <code>false</code> otherwise */ public boolean setKerning(char char1, char char2, int kern) { String first = GlyphList.unicodeToName((int) char1); if (first == null) return false; String second = GlyphList.unicodeToName((int) char2); if (second == null) return false; Object obj[] = (Object[]) KernPairs.get(first); if (obj == null) { obj = new Object[] {second, new Integer(kern)}; KernPairs.put(first, obj); return true; } for (int k = 0; k < obj.length; k += 2) { if (second.equals(obj[k])) { obj[k + 1] = new Integer(kern); return true; } } int size = obj.length; Object obj2[] = new Object[size + 2]; System.arraycopy(obj, 0, obj2, 0, size); obj2[size] = second; obj2[size + 1] = new Integer(kern); KernPairs.put(first, obj2); return true; }
/* */ public XRGlyphCacheEntry[] cacheGlyphs(GlyphList paramGlyphList) { /* 108 */ this.time += 1; /* */ /* 110 */ XRGlyphCacheEntry[] arrayOfXRGlyphCacheEntry = new XRGlyphCacheEntry[paramGlyphList.getNumGlyphs()]; /* 111 */ long[] arrayOfLong = paramGlyphList.getImages(); /* 112 */ ArrayList localArrayList = null; /* */ /* 114 */ for (int i = 0; i < paramGlyphList.getNumGlyphs(); i++) /* */ { /* */ XRGlyphCacheEntry localXRGlyphCacheEntry; /* 118 */ if ((localXRGlyphCacheEntry = getEntryForPointer(arrayOfLong[i])) == null) { /* 119 */ localXRGlyphCacheEntry = new XRGlyphCacheEntry(arrayOfLong[i], paramGlyphList); /* 120 */ localXRGlyphCacheEntry.setGlyphID(getFreeGlyphID()); /* 121 */ this.cacheMap.put(new MutableInteger(localXRGlyphCacheEntry.getGlyphID()), localXRGlyphCacheEntry); /* */ /* 123 */ if (localArrayList == null) { /* 124 */ localArrayList = new ArrayList(); /* */ } /* 126 */ localArrayList.add(localXRGlyphCacheEntry); /* */ } /* 128 */ localXRGlyphCacheEntry.setLastUsed(this.time); /* 129 */ arrayOfXRGlyphCacheEntry[i] = localXRGlyphCacheEntry; /* */ } /* */ /* 133 */ if (localArrayList != null) { /* 134 */ uploadGlyphs(arrayOfXRGlyphCacheEntry, localArrayList, paramGlyphList, null); /* */ } /* */ /* 137 */ return arrayOfXRGlyphCacheEntry; /* */ }
/** * Gets the kerning between two Unicode characters. The characters are converted to names and this * names are used to find the kerning pairs in the <CODE>HashMap</CODE> <CODE>KernPairs</CODE>. * * @param char1 the first char * @param char2 the second char * @return the kerning to be applied */ public int getKerning(char char1, char char2) { String first = GlyphList.unicodeToName((int) char1); if (first == null) return 0; String second = GlyphList.unicodeToName((int) char2); if (second == null) return 0; Object obj[] = (Object[]) KernPairs.get(first); if (obj == null) return 0; for (int k = 0; k < obj.length; k += 2) { if (second.equals(obj[k])) return ((Integer) obj[k + 1]).intValue(); } return 0; }
private void doType1TT() { CMapToUnicode toUnicode = null; PdfObject enc = PdfReader.getPdfObject(font.get(PdfName.ENCODING)); if (enc == null) { fillEncoding(null); try { toUnicode = processToUnicode(); if (toUnicode != null) { Map<Integer, Integer> rm = toUnicode.createReverseMapping(); for (Map.Entry<Integer, Integer> kv : rm.entrySet()) { uni2byte.put(kv.getKey().intValue(), kv.getValue().intValue()); } } } catch (Exception ex) { throw new ExceptionConverter(ex); } } else { if (enc.isName()) fillEncoding((PdfName) enc); else if (enc.isDictionary()) { PdfDictionary encDic = (PdfDictionary) enc; enc = PdfReader.getPdfObject(encDic.get(PdfName.BASEENCODING)); if (enc == null) fillEncoding(null); else fillEncoding((PdfName) enc); PdfArray diffs = encDic.getAsArray(PdfName.DIFFERENCES); if (diffs != null) { diffmap = new IntHashtable(); int currentNumber = 0; for (int k = 0; k < diffs.size(); ++k) { PdfObject obj = diffs.getPdfObject(k); if (obj.isNumber()) currentNumber = ((PdfNumber) obj).intValue(); else { int c[] = GlyphList.nameToUnicode(PdfName.decodeName(((PdfName) obj).toString())); if (c != null && c.length > 0) { uni2byte.put(c[0], currentNumber); diffmap.put(c[0], currentNumber); } else { if (toUnicode == null) { toUnicode = processToUnicode(); if (toUnicode == null) { toUnicode = new CMapToUnicode(); } } final String unicode = toUnicode.lookup(new byte[] {(byte) currentNumber}, 0, 1); if ((unicode != null) && (unicode.length() == 1)) { this.uni2byte.put(unicode.charAt(0), currentNumber); this.diffmap.put(unicode.charAt(0), currentNumber); } } ++currentNumber; } } } } } PdfArray newWidths = font.getAsArray(PdfName.WIDTHS); PdfNumber first = font.getAsNumber(PdfName.FIRSTCHAR); PdfNumber last = font.getAsNumber(PdfName.LASTCHAR); if (BuiltinFonts14.containsKey(fontName)) { BaseFont bf; try { bf = BaseFont.createFont(fontName, WINANSI, false); } catch (Exception e) { throw new ExceptionConverter(e); } int e[] = uni2byte.toOrderedKeys(); for (int k = 0; k < e.length; ++k) { int n = uni2byte.get(e[k]); widths[n] = bf.getRawWidth(n, GlyphList.unicodeToName(e[k])); } if (diffmap != null) { // widths for diffmap must override existing ones e = diffmap.toOrderedKeys(); for (int k = 0; k < e.length; ++k) { int n = diffmap.get(e[k]); widths[n] = bf.getRawWidth(n, GlyphList.unicodeToName(e[k])); } diffmap = null; } ascender = bf.getFontDescriptor(ASCENT, 1000); capHeight = bf.getFontDescriptor(CAPHEIGHT, 1000); descender = bf.getFontDescriptor(DESCENT, 1000); italicAngle = bf.getFontDescriptor(ITALICANGLE, 1000); fontWeight = bf.getFontDescriptor(FONT_WEIGHT, 1000); llx = bf.getFontDescriptor(BBOXLLX, 1000); lly = bf.getFontDescriptor(BBOXLLY, 1000); urx = bf.getFontDescriptor(BBOXURX, 1000); ury = bf.getFontDescriptor(BBOXURY, 1000); } if (first != null && last != null && newWidths != null) { int f = first.intValue(); int nSize = f + newWidths.size(); if (widths.length < nSize) { int[] tmp = new int[nSize]; System.arraycopy(widths, 0, tmp, 0, f); widths = tmp; } for (int k = 0; k < newWidths.size(); ++k) { widths[f + k] = newWidths.getAsNumber(k).intValue(); } } fillFontDesc(font.getAsDict(PdfName.FONTDESCRIPTOR)); }