@Override public OpenTypeFont parse(String file) throws IOException { return (OpenTypeFont)super.parse(file); }
@Override public OpenTypeFont parse(File file) throws IOException { return (OpenTypeFont)super.parse(file); }
@Override public OpenTypeFont parse(InputStream data) throws IOException { return (OpenTypeFont)super.parse(data); }
@Override OpenTypeFont parse(TTFDataStream raf) throws IOException { return (OpenTypeFont)super.parse(raf); }
/** * Parse a file and return a TrueType font. * * @param ttfFile The TrueType font filename. * @return A TrueType font. * @throws IOException If there is an error parsing the TrueType font. */ public TrueTypeFont parse(String ttfFile) throws IOException { return parse(new File(ttfFile)); }
/** * Parse an input stream and return a TrueType font. * * @param inputStream The TTF data stream to parse from. It will be closed before returning. * @return A TrueType font. * @throws IOException If there is an error parsing the TrueType font. */ public TrueTypeFont parse(InputStream inputStream) throws IOException { return parse(new MemoryTTFDataStream(inputStream)); }
/** * Parse an input stream and return a TrueType font that is to be embedded. * * @param inputStream The TTF data stream to parse from. It will be closed before returning. * @return A TrueType font. * @throws IOException If there is an error parsing the TrueType font. */ public TrueTypeFont parseEmbedded(InputStream inputStream) throws IOException { this.isEmbedded = true; return parse(new MemoryTTFDataStream(inputStream)); }
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); } }
/** * Parse a file and return a TrueType font. * * @param ttfFile The TrueType font file. * @return A TrueType font. * @throws IOException If there is an error parsing the TrueType font. */ public TrueTypeFont parse(File ttfFile) throws IOException { RAFDataStream raf = new RAFDataStream(ttfFile, "r"); try { return parse(raf); } catch (IOException ex) { // close only on error (file is still being accessed later) raf.close(); throw ex; } }
/** * 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); }
/** * 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)); }
ttfFont = ttfParser.parse(ff2Stream.createInputStream());