protected void addRangeUni(TrueTypeFont ttf, Set<Integer> longTag) { if (!subset && (subsetRanges != null || ttf.getDirectoryOffset() > 0)) { int[] rg = subsetRanges == null && ttf.getDirectoryOffset() > 0 ? new int[]{0, 0xffff} : compactRanges(subsetRanges); Map<Integer, int[]> usemap = ttf.getActiveCmap(); assert usemap != null; for (Map.Entry<Integer, int[]> e : usemap.entrySet()) { int[] v = e.getValue(); int gi = v[0]; if (longTag.contains(v[0])) { continue; } int c = e.getKey(); boolean skip = true; for (int k = 0; k < rg.length; k += 2) { if (c >= rg[k] && c <= rg[k + 1]) { skip = false; break; } } if (!skip) { longTag.add(gi); } } } }
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; } } }
TrueTypeFont(byte[] ttc, int ttcIndex) throws java.io.IOException { fontParser = new OpenTypeParser(ttc, ttcIndex); fontParser.loadTables(true); initializeFontProperties(); }
fontIdentification.setPanose(pdfPanose); Map<Integer, int[]> cmap = getActiveCmap(); int[] glyphWidths = fontParser.getGlyphWidthsByIndex(); int numOfGlyphs = fontMetrics.getNumberOfGlyphs(); if (index >= numOfGlyphs) { Logger LOGGER = LoggerFactory.getLogger(TrueTypeFont.class); LOGGER.warn(MessageFormatUtil.format(LogMessageConstant.FONT_HAS_INVALID_GLYPH, getFontNames().getFontName(), index)); continue; fixSpaceIssue(); for (int index = 0; index < glyphWidths.length; index++) { if (codeToGlyph.containsKey(index)) { readGdefTable(); readGsubTable(); readGposTable();
Arrays.sort(metrics); PdfStream fontStream; String fontName = updateSubsetPrefix(ttf.getFontNames().getFontName(), subset, embedded); PdfDictionary fontDescriptor = getFontDescriptor(fontName); if (ttf.isCff()) { byte[] cffBytes = ttf.getFontStreamBytes(); if (subset || subsetRanges != null) { CFFFontSubset cff = new CFFFontSubset(ttf.getFontStreamBytes(), longTag); cffBytes = cff.Process(cff.getNames()[0]); } else { byte[] ttfBytes = null; if (subset || ttf.getDirectoryOffset() != 0) { try { ttfBytes = ttf.getSubset(new HashSet<>(longTag), true); } catch (com.itextpdf.io.IOException e) { Logger logger = LoggerFactory.getLogger(PdfType0Font.class); ttfBytes = ttf.getFontStreamBytes(); int numOfGlyphs = ttf.getFontMetrics().getNumberOfGlyphs(); byte[] cidSetBytes = new byte[ttf.getFontMetrics().getNumberOfGlyphs() / 8 + 1]; for (int i = 0; i < numOfGlyphs / 8; i++) { cidSetBytes[i] |= 0xff;
fontFileName = ((IDocFontProgram) fontProgram).getFontFileName(); fontStream = ((IDocFontProgram) fontProgram).getFontFile(); } else if (((TrueTypeFont) getFontProgram()).isCff()) { fontFileName = PdfName.FontFile3; try { byte[] fontStreamBytes = ((TrueTypeFont) getFontProgram()).getFontStreamBytes(); fontStream = getPdfFontStream(fontStreamBytes, new int[]{fontStreamBytes.length}); fontStream.put(PdfName.Subtype, new PdfName("Type1C")); try { byte[] fontStreamBytes; if (subset || ((TrueTypeFont) getFontProgram()).getDirectoryOffset() != 0 || subsetRanges != null) { fontStreamBytes = ((TrueTypeFont) getFontProgram()).getSubset(new HashSet<>(glyphs), subset); } else { fontStreamBytes = ((TrueTypeFont) getFontProgram()).getFontStreamBytes();
@Override public int getPdfFontFlags() { int flags = 0; if (fontMetrics.isFixedPitch()) { flags |= 1; } flags |= isFontSpecific() ? 4 : 32; if (fontNames.isItalic()) { flags |= 64; } if (fontNames.isBold() || fontNames.getFontWeight() > 500) { flags |= 262144; } return flags; }
/** * Creates a new TrueType font program from ttc (TrueType Collection) file. * * @param ttc location of TrueType Collection file (*.ttc) * @param ttcIndex the index of the font file from the collection to be read * @param cached true if the font comes from the cache or is added to * the cache if new, false if the font is always created new * @return returns a new {@link FontProgram} instance. This font may come from the cache but only if cached * is true, otherwise it will always be created new */ public static FontProgram createFont(String ttc, int ttcIndex, boolean cached) throws java.io.IOException { FontCacheKey fontCacheKey = FontCacheKey.create(ttc, ttcIndex); if (cached) { FontProgram fontFound = FontCache.getFont(fontCacheKey); if (fontFound != null) { return fontFound; } } FontProgram fontBuilt = new TrueTypeFont(ttc, ttcIndex); return cached ? FontCache.saveFont(fontBuilt, fontCacheKey) : fontBuilt; }
fontIdentification.setPanose(pdfPanose); Map<Integer, int[]> cmap = getActiveCmap(); int[] glyphWidths = fontParser.getGlyphWidthsByIndex(); int numOfGlyphs = fontMetrics.getNumberOfGlyphs(); if (index >= numOfGlyphs) { Logger LOGGER = LoggerFactory.getLogger(TrueTypeFont.class); LOGGER.warn(MessageFormatUtil.format(LogMessageConstant.FONT_HAS_INVALID_GLYPH, getFontNames().getFontName(), index)); continue; fixSpaceIssue(); for (int index = 0; index < glyphWidths.length; index++) { if (codeToGlyph.containsKey(index)) { readGdefTable(); readGsubTable(); readGposTable();
@Override public int getPdfFontFlags() { int flags = 0; if (fontMetrics.isFixedPitch()) { flags |= 1; } flags |= isFontSpecific() ? 4 : 32; if (fontNames.isItalic()) { flags |= 64; } if (fontNames.isBold() || fontNames.getFontWeight() > 500) { flags |= 262144; } return flags; }
/** * Creates a new TrueType font program from ttc (TrueType Collection) file bytes. * * @param ttc the content of a TrueType Collection file (*.ttc) * @param ttcIndex the index of the font file from the collection to be read * @param cached true if the font comes from the cache or is added to * the cache if new, false if the font is always created new * @return returns a new {@link FontProgram} instance. This font may come from the cache but only if cached * is true, otherwise it will always be created new */ public static FontProgram createFont(byte[] ttc, int ttcIndex, boolean cached) throws java.io.IOException { FontCacheKey fontKey = FontCacheKey.create(ttc, ttcIndex); if (cached) { FontProgram fontFound = FontCache.getFont(fontKey); if (fontFound != null) { return fontFound; } } FontProgram fontBuilt = new TrueTypeFont(ttc, ttcIndex); return cached ? FontCache.saveFont(fontBuilt, fontKey) : fontBuilt; }
PdfTrueTypeFont(TrueTypeFont ttf, String encoding, boolean embedded) { super(); setFontProgram(ttf); this.embedded = embedded; FontNames fontNames = ttf.getFontNames(); if (embedded && !fontNames.allowEmbedding()) { throw new PdfException("{0} cannot be embedded due to licensing restrictions.") .setMessageParams(fontNames.getFontName()); } if ((encoding == null || encoding.length() == 0) && ttf.isFontSpecific()) { encoding = FontEncoding.FONT_SPECIFIC; } if (encoding != null && FontEncoding.FONT_SPECIFIC.toLowerCase().equals(encoding.toLowerCase())) { fontEncoding = FontEncoding.createFontSpecificEncoding(); } else { fontEncoding = FontEncoding.createFontEncoding(encoding); } }
@Deprecated /** * @deprecated will be removed in 7.2 */ protected void addRangeUni(TrueTypeFont ttf, Map<Integer, int[]> longTag, boolean includeMetrics) { if (!subset && (subsetRanges != null || ttf.getDirectoryOffset() > 0)) { int[] rg = subsetRanges == null && ttf.getDirectoryOffset() > 0 ? new int[]{0, 0xffff} : compactRanges(subsetRanges); Map<Integer, int[]> usemap = ttf.getActiveCmap(); assert usemap != null; for (Map.Entry<Integer, int[]> e : usemap.entrySet()) { int[] v = e.getValue(); int gi = v[0]; if (longTag.containsKey(v[0])) { continue; } int c = e.getKey(); boolean skip = true; for (int k = 0; k < rg.length; k += 2) { if (c >= rg[k] && c <= rg[k + 1]) { skip = false; break; } } if (!skip) { longTag.put(gi, includeMetrics ? new int[]{v[0], v[1], c} : null); } } } }
if (ttf.isFontSpecific()) { byte[] b = PdfEncodings.convertToBytes(text, "symboltt"); if (b.length > 0) {
TrueTypeFont(byte[] ttc, int ttcIndex) throws java.io.IOException { fontParser = new OpenTypeParser(ttc, ttcIndex); fontParser.loadTables(true); initializeFontProperties(); }
/** * Creates a new TrueType font program from ttc (TrueType Collection) file. * * @param ttc location of TrueType Collection file (*.ttc) * @param ttcIndex the index of the font file from the collection to be read * @param cached true if the font comes from the cache or is added to * the cache if new, false if the font is always created new * @return returns a new {@link FontProgram} instance. This font may come from the cache but only if cached * is true, otherwise it will always be created new */ public static FontProgram createFont(String ttc, int ttcIndex, boolean cached) throws java.io.IOException { FontCacheKey fontCacheKey = FontCacheKey.create(ttc, ttcIndex); if (cached) { FontProgram fontFound = FontCache.getFont(fontCacheKey); if (fontFound != null) { return fontFound; } } FontProgram fontBuilt = new TrueTypeFont(ttc, ttcIndex); return cached ? FontCache.saveFont(fontBuilt, fontCacheKey) : fontBuilt; }
protected void addRangeUni(Set<Integer> longTag) { if (!subset && (subsetRanges != null || ((TrueTypeFont) getFontProgram()).getDirectoryOffset() > 0)) { int[] rg = subsetRanges == null && ((TrueTypeFont) getFontProgram()).getDirectoryOffset() > 0 ? new int[]{0, 0xffff} : compactRanges(subsetRanges); Map<Integer, int[]> usemap = ((TrueTypeFont) getFontProgram()).getActiveCmap(); assert usemap != null; for (Map.Entry<Integer, int[]> e : usemap.entrySet()) { int[] v = e.getValue(); int gi = v[0]; if (longTag.contains(gi)) { continue; } int c = (int) e.getKey(); boolean skip = true; for (int k = 0; k < rg.length; k += 2) { if (c >= rg[k] && c <= rg[k + 1]) { skip = false; break; } } if (!skip) { longTag.add(gi); } } } }
public TrueTypeFont(byte[] ttf) throws java.io.IOException { fontParser = new OpenTypeParser(ttf); fontParser.loadTables(true); initializeFontProperties(); }
/** * Creates a new TrueType font program from ttc (TrueType Collection) file bytes. * * @param ttc the content of a TrueType Collection file (*.ttc) * @param ttcIndex the index of the font file from the collection to be read * @param cached true if the font comes from the cache or is added to * the cache if new, false if the font is always created new * @return returns a new {@link FontProgram} instance. This font may come from the cache but only if cached * is true, otherwise it will always be created new */ public static FontProgram createFont(byte[] ttc, int ttcIndex, boolean cached) throws java.io.IOException { FontCacheKey fontKey = FontCacheKey.create(ttc, ttcIndex); if (cached) { FontProgram fontFound = FontCache.getFont(fontKey); if (fontFound != null) { return fontFound; } } FontProgram fontBuilt = new TrueTypeFont(ttc, ttcIndex); return cached ? FontCache.saveFont(fontBuilt, fontKey) : fontBuilt; }
TrueTypeFont(String ttcPath, int ttcIndex) throws java.io.IOException { fontParser = new OpenTypeParser(ttcPath, ttcIndex); fontParser.loadTables(true); initializeFontProperties(); }