/** * Loads a TTF to be embedded into a document as a Type 0 font. * * @param doc The PDF document that will hold the embedded font. * @param file A TrueType font. * @return A Type0 font with a CIDFontType2 descendant. * @throws IOException If there is an error reading the font file. */ public static PDType0Font load(PDDocument doc, File file) throws IOException { return new PDType0Font(doc, new TTFParser().parse(file), true, true, false); }
TrueTypeFont font = newFont(raf); font.setVersion(raf.read32Fixed()); int numberOfTables = raf.readUnsignedShort(); for (int i = 0; i < numberOfTables; i++) TTFTable table = readTableDirectory(font, raf); parseTables(font);
@Override protected TTFTable readTable(TrueTypeFont font, String tag) { // todo: this is a stub, a full implementation is needed switch (tag) { case "BASE": case "GDEF": case "GPOS": case "GSUB": case "JSTF": return new OTLTable(font); case "CFF ": return new CFFTable(font); default: return super.readTable(font, tag); } }
@Override public OpenTypeFont parse(String file) throws IOException { return (OpenTypeFont)super.parse(file); }
public final void buildFontFile2(InputStream ttfStream) throws IOException { PDStream stream = new PDStream(document, ttfStream, COSName.FLATE_DECODE); // as the stream was closed within the PDStream constructor, we have to recreate it try (InputStream input = stream.createInputStream()) { ttf = new TTFParser().parseEmbedded(input); if (!isEmbeddingPermitted(ttf)) { throw new IOException("This font does not permit embedding"); } if (fontDescriptor == null) { fontDescriptor = createFontDescriptor(ttf); } } stream.getCOSObject().setLong(COSName.LENGTH1, ttf.getOriginalDataSize()); fontDescriptor.setFontFile2(stream); }
boolean isPostScript = allowCFF() && font.tables.containsKey(CFFTable.TAG);
@Override public OpenTypeFont parse(InputStream data) throws IOException { return (OpenTypeFont)super.parse(data); }
public final void buildFontFile2(InputStream ttfStream) throws IOException { PDStream stream = new PDStream(document, ttfStream, COSName.FLATE_DECODE); // as the stream was closed within the PDStream constructor, we have to recreate it try (InputStream input = stream.createInputStream()) { ttf = new TTFParser().parseEmbedded(input); if (!isEmbeddingPermitted(ttf)) { throw new IOException("This font does not permit embedding"); } if (fontDescriptor == null) { fontDescriptor = createFontDescriptor(ttf); } } stream.getCOSObject().setLong(COSName.LENGTH1, ttf.getOriginalDataSize()); fontDescriptor.setFontFile2(stream); }
boolean isPostScript = allowCFF() && font.tables.containsKey(CFFTable.TAG);
/** * Loads a TTF to be embedded into a document as a Type 0 font. * * @param doc The PDF document that will hold the embedded font. * @param input A TrueType font. * @return A Type0 font with a CIDFontType2 descendant. * @throws IOException If there is an error reading the font stream. */ public static PDType0Font load(PDDocument doc, InputStream input) throws IOException { return new PDType0Font(doc, new TTFParser().parse(input), true, true, false); }
@Override OpenTypeFont parse(TTFDataStream raf) throws IOException { return (OpenTypeFont)super.parse(raf); }
public void buildFontFile2(InputStream ttfStream) throws IOException { PDStream stream = new PDStream(document, ttfStream, COSName.FLATE_DECODE); // as the stream was closed within the PDStream constructor, we have to recreate it InputStream input = null; try { input = stream.createInputStream(); ttf = new TTFParser().parseEmbedded(input); if (!isEmbeddingPermitted(ttf)) { throw new IOException("This font does not permit embedding"); } if (fontDescriptor == null) { fontDescriptor = createFontDescriptor(ttf); } } finally { IOUtils.closeQuietly(input); } stream.getCOSObject().setLong(COSName.LENGTH1, ttf.getOriginalDataSize()); fontDescriptor.setFontFile2(stream); }
TrueTypeFont font = newFont(raf); font.setVersion(raf.read32Fixed()); int numberOfTables = raf.readUnsignedShort(); for (int i = 0; i < numberOfTables; i++) TTFTable table = readTableDirectory(font, raf); parseTables(font);
@Override protected TTFTable readTable(TrueTypeFont font, String tag) { // todo: this is a stub, a full implementation is needed if (tag.equals("BASE") || tag.equals("GDEF") || tag.equals("GPOS") || tag.equals("GSUB") || tag.equals("JSTF")) { return new OTLTable(font); } else if (tag.equals("CFF ")) { return new CFFTable(font); } else { return super.readTable(font, tag); } }
boolean isPostScript = allowCFF() && font.tables.containsKey(CFFTable.TAG);
/** * Loads a TTF to be embedded into a document as a vertical Type 0 font. * * @param doc The PDF document that will hold the embedded font. * @param file A TrueType font. * @return A Type0 font with a CIDFontType2 descendant. * @throws IOException If there is an error reading the font file. */ public static PDType0Font loadVertical(PDDocument doc, File file) throws IOException { return new PDType0Font(doc, new TTFParser().parse(file), true, true, true); }
@Override public OpenTypeFont parse(File file) throws IOException { return (OpenTypeFont)super.parse(file); }
TrueTypeFont font = newFont(raf); font.setVersion(raf.read32Fixed()); int numberOfTables = raf.readUnsignedShort(); for (int i = 0; i < numberOfTables; i++) TTFTable table = readTableDirectory(font, raf); parseTables(font);
break; default: table = readTable(font, tag); break;
/** * Loads a TTF to be embedded into a document as a vertical Type 0 font. * * @param doc The PDF document that will hold the embedded font. * @param input A TrueType font. * @return A Type0 font with a CIDFontType2 descendant. * @throws IOException If there is an error reading the font stream. */ public static PDType0Font loadVertical(PDDocument doc, InputStream input) throws IOException { return new PDType0Font(doc, new TTFParser().parse(input), true, true, true); }