public byte[] getCmapBytes(int cid) { int length = getCmapBytesLength(cid); byte[] result = new byte[length]; fillCmapBytes(cid, result, 0); return result; }
public String getOrdering() { if (isDirect()) { return "Identity"; } else { return cid2Code.getOrdering(); } }
private static CMapEncoding createCMap(PdfObject cmap, String uniMap) { if (cmap.isStream()) { PdfStream cmapStream = (PdfStream) cmap; byte[] cmapBytes = cmapStream.getBytes(); return new CMapEncoding(cmapStream.getAsName(PdfName.CMapName).getValue(), cmapBytes); } else { String cmapName = ((PdfName) cmap).getValue(); if (PdfEncodings.IDENTITY_H.equals(cmapName) || PdfEncodings.IDENTITY_V.equals(cmapName)) { return new CMapEncoding(cmapName); } else { return new CMapEncoding(cmapName, uniMap); } } }
cidInfo.put(PdfName.Registry, new PdfString(cmapEncoding.getRegistry())); cidInfo.put(PdfName.Ordering, new PdfString(cmapEncoding.getOrdering())); cidInfo.put(PdfName.Supplement, new PdfNumber(cmapEncoding.getSupplement())); cidFont.put(PdfName.CIDSystemInfo, cidInfo); if (!vertical) {
private void convertToBytes(Glyph glyph, ByteBuffer result) { int code = glyph.getCode(); longTag.add(code); cmapEncoding.fillCmapBytes(code, result); }
for (int codeLength = 1; codeLength <= 4 && i + codeLength <= cids.length(); codeLength++) { code = (code << 8) + cids.charAt(i + codeLength - 1); if (!cmapEncoding.containsCodeInCodeSpaceRange(code, codeLength)) { continue; } else { codeSpaceMatchedLength = codeLength; int glyphCode = cmapEncoding.getCidCode(code); glyph = fontProgram.getGlyphByCode(glyphCode); if (glyph != null) {
@Override public byte[] convertToBytes(Glyph glyph) { longTag.add(glyph.getCode()); return cmapEncoding.getCmapBytes(glyph.getCode()); }
} else { int nullCode = cmapEncoding.getCmapCode(0); buffer.append(nullCode >> 8); buffer.append(nullCode);
name += "-" + style; getPdfObject().put(PdfName.BaseFont, new PdfName(MessageFormatUtil.format("{0}-{1}", name, cmapEncoding.getCmapName()))); getPdfObject().put(PdfName.Encoding, new PdfName(cmapEncoding.getCmapName())); PdfDictionary fontDescriptor = getFontDescriptor(name); int[] metrics = hashSetToArray(longTag); new PdfName(MessageFormatUtil.format("{0}-{1}", fontName, cmapEncoding.getCmapName()))); fontDescriptor.put(PdfName.FontFile3, fontStream); } else { getPdfObject().put(PdfName.Encoding, new PdfName(cmapEncoding.getCmapName())); getPdfObject().put(PdfName.DescendantFonts, new PdfArray(cidFont));
cidInfo.put(PdfName.Registry, new PdfString(cmapEncoding.getRegistry())); cidInfo.put(PdfName.Ordering, new PdfString(cmapEncoding.getOrdering())); cidInfo.put(PdfName.Supplement, new PdfNumber(cmapEncoding.getSupplement())); cidFont.put(PdfName.CIDSystemInfo, cidInfo); if (!vertical) {
public byte[] getCmapBytes(int cid) { int length = getCmapBytesLength(cid); byte[] result = new byte[length]; fillCmapBytes(cid, result, 0); return result; }
public int getSupplement() { if (isDirect()) { return 0; } else { return cid2Code.getSupplement(); } }
PdfType0Font(TrueTypeFont ttf, String cmap) { super(); if (!cmap.equals(PdfEncodings.IDENTITY_H) && !cmap.equals(PdfEncodings.IDENTITY_V)) { throw new PdfException(PdfException.OnlyIdentityCMapsSupportsWithTrueType); } if (!ttf.getFontNames().allowEmbedding()) { throw new PdfException(PdfException.CannotBeEmbeddedDueToLicensingRestrictions) .setMessageParams(ttf.getFontNames().getFontName() + ttf.getFontNames().getStyle()); } this.fontProgram = ttf; this.embedded = true; vertical = cmap.endsWith("V"); cmapEncoding = new CMapEncoding(cmap); longTag = new HashSet<>(); cidFontType = CID_FONT_TYPE_2; if (ttf.isFontSpecific()) { specificUnicodeDifferences = new char[256]; byte[] bytes = new byte[1]; for (int k = 0; k < 256; ++k) { bytes[0] = (byte) k; String s = PdfEncodings.convertToString(bytes, null); char ch = s.length() > 0 ? s.charAt(0) : '?'; specificUnicodeDifferences[k] = ch; } } }
@Override public byte[] convertToBytes(GlyphLine glyphLine) { if (glyphLine != null) { // prepare and count total length in bytes int totalByteCount = 0; for (int i = glyphLine.start; i < glyphLine.end; i++) { totalByteCount += cmapEncoding.getCmapBytesLength(glyphLine.get(i).getCode()); } // perform actual conversion byte[] bytes = new byte[totalByteCount]; int offset = 0; for (int i = glyphLine.start; i < glyphLine.end; i++) { longTag.add(glyphLine.get(i).getCode()); offset = cmapEncoding.fillCmapBytes(glyphLine.get(i).getCode(), bytes, offset); } return bytes; } else { return null; } }
public String getRegistry() { if (isDirect()) { return "Adobe"; } else { return cid2Code.getRegistry(); } }
PdfType0Font(CidFont font, String cmap) { super(); if (!CidFontProperties.isCidFont(font.getFontNames().getFontName(), cmap)) { throw new PdfException("Font {0} with {1} encoding is not a cjk font.") .setMessageParams(font.getFontNames().getFontName(), cmap); } this.fontProgram = font; vertical = cmap.endsWith("V"); String uniMap = getCompatibleUniMap(fontProgram.getRegistry()); cmapEncoding = new CMapEncoding(cmap, uniMap); longTag = new HashSet<>(); cidFontType = CID_FONT_TYPE_0; }
public String getOrdering() { if (isDirect()) { return "Identity"; } else { return cid2Code.getOrdering(); } }
public String getRegistry() { if (isDirect()) { return "Adobe"; } else { return cid2Code.getRegistry(); } }
public int getSupplement() { if (isDirect()) { return 0; } else { return cid2Code.getSupplement(); } }
if (cidFontType == CID_FONT_TYPE_0) { int len = content.length(); if (cmapEncoding.isDirect()) { for (int k = 0; k < len; ++k) { Glyph glyph = fontProgram.getGlyphByCode((int) content.charAt(k));