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); } }
/** * Adds a TTC or OTC to the file cache. To reduce memory, the parsed font is not cached. */ private void addTrueTypeCollection(final File ttcFile) throws IOException { try (TrueTypeCollection ttc = new TrueTypeCollection(ttcFile)) { ttc.processAllFonts(new TrueTypeFontProcessor() { @Override public void process(TrueTypeFont ttf) throws IOException { addTrueTypeFontImpl(ttf, ttcFile); } }); } catch (NullPointerException | IOException e) { // NPE due to TTF parser being buggy LOG.error("Could not load font file: " + ttcFile, e); } }
/** * Run the callback for each TT font in the collection. * * @param trueTypeFontProcessor the object with the callback method. * @throws IOException */ public void processAllFonts(TrueTypeFontProcessor trueTypeFontProcessor) throws IOException { for (int i = 0; i < numFonts; i++) { TrueTypeFont font = getFontAtIndex(i); trueTypeFontProcessor.process(font); } }
try ttc = new TrueTypeCollection(ttcFile); ttc.processAllFonts(new TrueTypeFontProcessor() ttc.close();
PDFont font = PDType0Font.load(document, new TrueTypeCollection(new File("c:/windows/fonts/MSGothic.ttc")).getFontByName().get("MS-Gothic"), true);
/** * Add fonts using a FontBox TrueTypeCollection. */ private void addFontCollection(TrueTypeCollection collection, final String fontFamilyNameOverride, final Integer fontWeightOverride, final IdentValue fontStyleOverride, final boolean subset) throws IOException { collection.processAllFonts(new TrueTypeFontProcessor() { @Override public void process(TrueTypeFont ttf) throws IOException { addFont(ttf, fontFamilyNameOverride, fontWeightOverride, fontStyleOverride, subset); } }); _collectionsToClose.add(collection); }
/** * Free all font resources (i.e. open files), the document should already be * closed. */ public void close() { _fontCache.clear(); // Close all still open TrueTypeCollections for (TrueTypeCollection collection : _collectionsToClose) { try { collection.close(); } catch (IOException e) { //e.printStackTrace(); } } _collectionsToClose.clear(); }
/** * Add fonts using a .ttc TrueTypeCollection */ public void addFontCollection(File file, final String fontFamilyNameOverride, final Integer fontWeightOverride, final IdentValue fontStyleOverride, final boolean subset) throws IOException { TrueTypeCollection collection = new TrueTypeCollection(file); addFontCollection(collection, fontFamilyNameOverride, fontWeightOverride, fontStyleOverride, subset); }
/** * Add fonts using a FontBox TrueTypeCollection. */ private void addFontCollection(TrueTypeCollection collection, final String fontFamilyNameOverride, final Integer fontWeightOverride, final IdentValue fontStyleOverride, final boolean subset) throws IOException { collection.processAllFonts(new TrueTypeFontProcessor() { @Override public void process(TrueTypeFont ttf) throws IOException { addFont(ttf, fontFamilyNameOverride, fontWeightOverride, fontStyleOverride, subset); } }); _collectionsToClose.add(collection); }
/** * Free all font resources (i.e. open files), the document should already be * closed. */ public void close() { _fontCache.clear(); // Close all still open TrueTypeCollections for (TrueTypeCollection collection : _collectionsToClose) { try { collection.close(); } catch (IOException e) { //e.printStackTrace(); } } _collectionsToClose.clear(); }
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); } }
/** * Adds a TTC or OTC to the file cache. To reduce memory, the parsed font is not cached. */ private void addTrueTypeCollection(final File ttcFile) throws IOException { try (TrueTypeCollection ttc = new TrueTypeCollection(ttcFile)) { ttc.processAllFonts(new TrueTypeFontProcessor() { @Override public void process(TrueTypeFont ttf) throws IOException { addTrueTypeFontImpl(ttf, ttcFile); } }); } catch (NullPointerException | IOException e) { // NPE due to TTF parser being buggy LOG.error("Could not load font file: " + ttcFile, e); } }
/** * Add fonts using a .ttc TrueTypeCollection */ public void addFontCollection(File file, final String fontFamilyNameOverride, final Integer fontWeightOverride, final IdentValue fontStyleOverride, final boolean subset) throws IOException { TrueTypeCollection collection = new TrueTypeCollection(file); addFontCollection(collection, fontFamilyNameOverride, fontWeightOverride, fontStyleOverride, subset); }
/** * Get a TT font from a collection. * * @param name The postscript name of the font. * @return The found font, nor null if none is found. * @throws IOException */ public TrueTypeFont getFontByName(String name) throws IOException { for (int i = 0; i < numFonts; i++) { TrueTypeFont font = getFontAtIndex(i); if (font.getName().equals(name)) { return font; } } return null; }
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); } }
TrueTypeCollection collection = new TrueTypeCollection(fontEntry.file); collection.processAllFonts(new TrueTypeCollection.TrueTypeFontProcessor() { @Override public void process(TrueTypeFont ttf) throws IOException {
/** * Add fonts using a .ttc TrueTypeCollection */ public void addFontCollection(FSSupplier<InputStream> supplier, final String fontFamilyNameOverride, final Integer fontWeightOverride, final IdentValue fontStyleOverride, final boolean subset) throws IOException { InputStream inputStream = supplier.supply(); try { TrueTypeCollection collection = new TrueTypeCollection(inputStream); addFontCollection(collection, fontFamilyNameOverride, fontWeightOverride, fontStyleOverride, subset); } finally { inputStream.close(); } }
/** * Run the callback for each TT font in the collection. * * @param trueTypeFontProcessor the object with the callback method. * @throws IOException */ public void processAllFonts(TrueTypeFontProcessor trueTypeFontProcessor) throws IOException { for (int i = 0; i < numFonts; i++) { TrueTypeFont font = getFontAtIndex(i); trueTypeFontProcessor.process(font); } }
/** * Add fonts using a .ttc TrueTypeCollection */ public void addFontCollection(FSSupplier<InputStream> supplier, final String fontFamilyNameOverride, final Integer fontWeightOverride, final IdentValue fontStyleOverride, final boolean subset) throws IOException { InputStream inputStream = supplier.supply(); try { TrueTypeCollection collection = new TrueTypeCollection(inputStream); addFontCollection(collection, fontFamilyNameOverride, fontWeightOverride, fontStyleOverride, subset); } finally { inputStream.close(); } }
/** * Run the callback for each TT font in the collection. * * @param trueTypeFontProcessor the object with the callback method. * @throws IOException */ public void processAllFonts(TrueTypeFontProcessor trueTypeFontProcessor) throws IOException { for (int i = 0; i < numFonts; i++) { TrueTypeFont font = getFontAtIndex(i); trueTypeFontProcessor.process(font); } }