/** * Returns the best Unicode from the font (the most general). The PDF spec says that "The means * by which this is accomplished are implementation-dependent." * * @throws IOException if the font could not be read * @deprecated Use {@link #getUnicodeCmapLookup()} instead */ @Deprecated public CmapSubtable getUnicodeCmap() throws IOException { return getUnicodeCmap(true); }
/** * Creates a new TrueType font for embedding. */ TrueTypeEmbedder(PDDocument document, COSDictionary dict, TrueTypeFont ttf, boolean embedSubset) throws IOException { this.document = document; this.embedSubset = embedSubset; this.ttf = ttf; fontDescriptor = createFontDescriptor(ttf); if (!isEmbeddingPermitted(ttf)) { throw new IOException("This font does not permit embedding"); } if (!embedSubset) { // full embedding PDStream stream = new PDStream(document, ttf.getOriginalData(), COSName.FLATE_DECODE); stream.getCOSObject().setLong(COSName.LENGTH1, ttf.getOriginalDataSize()); fontDescriptor.setFontFile2(stream); } dict.setName(COSName.BASE_FONT, ttf.getName()); // choose a Unicode "cmap" cmap = ttf.getUnicodeCmap(); cmapLookup = ttf.getUnicodeCmapLookup(); }
/** * Returns the best Unicode from the font (the most general). The PDF spec says that "The means * by which this is accomplished are implementation-dependent." * * @throws IOException if the font could not be read */ public CmapSubtable getUnicodeCmap() throws IOException { return getUnicodeCmap(true); }
/** * Creates a new TrueType font for embedding. */ TrueTypeEmbedder(PDDocument document, COSDictionary dict, TrueTypeFont ttf, boolean embedSubset) throws IOException { this.document = document; this.embedSubset = embedSubset; this.ttf = ttf; fontDescriptor = createFontDescriptor(ttf); if (!isEmbeddingPermitted(ttf)) { throw new IOException("This font does not permit embedding"); } if (!embedSubset) { // full embedding PDStream stream = new PDStream(document, ttf.getOriginalData(), COSName.FLATE_DECODE); stream.getCOSObject().setLong(COSName.LENGTH1, ttf.getOriginalDataSize()); fontDescriptor.setFontFile2(stream); } dict.setName(COSName.BASE_FONT, ttf.getName()); // choose a Unicode "cmap" cmap = ttf.getUnicodeCmap(); cmapLookup = ttf.getUnicodeCmapLookup(); }
/** * Returns the best Unicode from the font (the most general). The PDF spec says that "The means * by which this is accomplished are implementation-dependent." * * @throws IOException if the font could not be read * @deprecated Use {@link #getUnicodeCmapLookup()} instead */ @Deprecated public CmapSubtable getUnicodeCmap() throws IOException { return getUnicodeCmap(true); }
/** * Creates a subsetter for the given font. * * @param ttf the font to be subset * @param tables optional tables to keep if present */ public TTFSubsetter(TrueTypeFont ttf, List<String> tables) throws IOException { this.ttf = ttf; this.keepTables = tables; uniToGID = new TreeMap<>(); glyphIds = new TreeSet<>(); // find the best Unicode cmap this.unicodeCmap = ttf.getUnicodeCmap(); // always copy GID 0 glyphIds.add(0); }
/** * Returns the GID for the given PostScript name, if the "post" table is present. * @param name the PostScript name. */ public int nameToGID(String name) throws IOException { // look up in 'post' table readPostScriptNames(); if (postScriptNames != null) { Integer gid = postScriptNames.get(name); if (gid != null && gid > 0 && gid < getMaximumProfile().getNumGlyphs()) { return gid; } } // look up in 'cmap' int uni = parseUniName(name); if (uni > -1) { CmapSubtable cmap = getUnicodeCmap(false); return cmap.getGlyphId(uni); } return 0; }
/** * Creates a new TrueType font for embedding. */ TrueTypeEmbedder(PDDocument document, COSDictionary dict, TrueTypeFont ttf, boolean embedSubset) throws IOException { this.document = document; this.embedSubset = embedSubset; this.ttf = ttf; fontDescriptor = createFontDescriptor(ttf); if (!isEmbeddingPermitted(ttf)) { throw new IOException("This font does not permit embedding"); } if (!embedSubset) { // full embedding PDStream stream = new PDStream(document, ttf.getOriginalData(), COSName.FLATE_DECODE); stream.getCOSObject().setLong(COSName.LENGTH1, ttf.getOriginalDataSize()); fontDescriptor.setFontFile2(stream); } dict.setName(COSName.BASE_FONT, ttf.getName()); // choose a Unicode "cmap" cmap = ttf.getUnicodeCmap(); }
cmap = ttf.getUnicodeCmap(false); cid2gid = readCIDToGIDMap();