/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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. * @param embedSubset True if the font will be subset before embedding * @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, boolean embedSubset) throws IOException { return new PDType0Font(doc, new TTFParser().parse(input), embedSubset, true, false); }
/** * 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. * @param embedSubset True if the font will be subset before embedding * @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, boolean embedSubset) throws IOException { return new PDType0Font(doc, new TTFParser().parse(input), embedSubset, true, true); }
/** * Loads a TTF to be embedded into a document as a simple font. * * <p><b>Note:</b> Simple fonts only support 256 characters. For Unicode support, use * {@link PDType0Font#load(PDDocument, File)} instead.</p> * * @param doc The PDF document that will hold the embedded font. * @param file A TTF file. * @param encoding The PostScript encoding vector to be used for embedding. * @return a PDTrueTypeFont instance. * @throws IOException If there is an error loading the data. */ public static PDTrueTypeFont load(PDDocument doc, File file, Encoding encoding) throws IOException { return new PDTrueTypeFont(doc, new TTFParser().parse(file), encoding, true); }
/** * Loads a TTF to be embedded into a document as a simple font. * * <p><b>Note:</b> Simple fonts only support 256 characters. For Unicode support, use * {@link PDType0Font#load(PDDocument, InputStream)} instead.</p> * * @param doc The PDF document that will hold the embedded font. * @param input A TTF file stream * @param encoding The PostScript encoding vector to be used for embedding. * @return a PDTrueTypeFont instance. * @throws IOException If there is an error loading the data. */ public static PDTrueTypeFont load(PDDocument doc, InputStream input, Encoding encoding) throws IOException { return new PDTrueTypeFont(doc, new TTFParser().parse(input), encoding, true); }
private TrueTypeFont readTrueTypeFont(String postScriptName, File file) throws IOException { if (file.getName().toLowerCase().endsWith(".ttc")) { TrueTypeCollection ttc = new TrueTypeCollection(file); TrueTypeFont ttf = ttc.getFontByName(postScriptName); if (ttf == null) { ttc.close(); throw new IOException("Font " + postScriptName + " not found in " + file); } return ttf; } else { TTFParser ttfParser = new TTFParser(false, true); return ttfParser.parse(file); } }
TTFParser ttfParser = new TTFParser(); lastResortFont = ttfParser.parse(ttfStream);
/** * Adds an OTF or TTF font to the file cache. To reduce memory, the parsed font is not cached. */ private void addTrueTypeFont(File ttfFile) throws IOException { try { if (ttfFile.getPath().endsWith(".otf")) { OTFParser parser = new OTFParser(false, true); OpenTypeFont otf = parser.parse(ttfFile); addTrueTypeFontImpl(otf, ttfFile); } else { TTFParser parser = new TTFParser(false, true); TrueTypeFont ttf = parser.parse(ttfFile); addTrueTypeFontImpl(ttf, ttfFile); } } catch (NullPointerException | IOException e) { // NPE due to TTF parser being buggy LOG.error("Could not load font file: " + ttfFile, e); } }
private TrueTypeFont getFontAtIndex(int idx) throws IOException { stream.seek(fontOffsets[idx]); TTFParser parser; if (stream.readTag().equals("OTTO")) { parser = new OTFParser(false, true); } else { parser = new TTFParser(false, true); } stream.seek(fontOffsets[idx]); return parser.parse(new TTCDataStream(stream)); }
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); }
TTFParser ttfParser = new TTFParser(true); ttfFont = ttfParser.parse(ff2Stream.createInputStream());
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
TrueTypeFont ttf = new TTFParser().parse(ipafont); PDType0Font vfont2 = PDType0Font.loadVertical(document, ttf, true); ttf.disableGsubFeature("vrt2");
TTFParser parser = new TTFParser(); if (tis != null && tis.hasFile()) { font = parser.parse(tis.getFile());