List of usage examples for com.lowagie.text.pdf BaseFont enumerateTTCNames
public static String[] enumerateTTCNames(byte ttcArray[]) throws DocumentException, IOException
From source file:jdbreport.model.io.pdf.itext2.ReportFontMapper.java
License:Apache License
public int insertDirectory(String dir) { File file = new File(dir); if (!file.exists() || !file.isDirectory()) return 0; File files[] = file.listFiles(); if (files == null) return 0; int count = 0; for (File file1 : files) { file = file1;//www . j a v a 2 s .c o m if (file.isDirectory()) { count += insertDirectory(file.getPath()); } else { String name = file.getPath().toLowerCase(); try { if (name.endsWith(".ttf") || name.endsWith(".otf") || name.endsWith(".afm")) { Object allNames[] = BaseFont.getAllFontNames(file.getPath(), BaseFont.IDENTITY_H, null); insertNames(allNames, file.getPath()); ++count; } else if (name.endsWith(".ttc")) { String ttcs[] = BaseFont.enumerateTTCNames(file.getPath()); for (int j = 0; j < ttcs.length; ++j) { String nt = file.getPath() + "," + j; Object allNames[] = BaseFont.getAllFontNames(nt, BaseFont.IDENTITY_H, null); insertNames(allNames, nt); } ++count; } } catch (Exception ignored) { } } } return count; }
From source file:jgnash.ui.report.FontRegistry.java
License:Open Source License
private void registerFont(final String path) { try {/*from www . j av a 2s. com*/ if (path.toLowerCase().endsWith(".ttf") || path.toLowerCase().endsWith(".otf") || path.toLowerCase().indexOf(".ttc,") > 0) { Object allNames[] = BaseFont.getAllFontNames(path, BaseFont.WINANSI, null); String[][] names = (String[][]) allNames[2]; //full name for (String[] name : names) { registeredFontMap.put(name[3].toLowerCase(), path); } } else if (path.toLowerCase().endsWith(".ttc")) { String[] names = BaseFont.enumerateTTCNames(path); for (int i = 0; i < names.length; i++) { registerFont(path + "," + i); } } else if (path.toLowerCase().endsWith(".afm") || path.toLowerCase().endsWith(".pfm")) { BaseFont bf = BaseFont.createFont(path, BaseFont.CP1252, false); String fullName = bf.getFullFontName()[0][3].toLowerCase(); registeredFontMap.put(fullName, path); } } catch (DocumentException | IOException e) { throw new RuntimeException(e); } }
From source file:nl.dykema.jxmlnote.report.pdf.MyDefaultFontMapper.java
License:Open Source License
public int insertFile(File file, int count) { String name = file.getPath().toLowerCase(); try {/*from w w w. j a v a 2 s .c om*/ if (name.endsWith(".ttf") || name.endsWith(".otf") || name.endsWith(".afm")) { Object allNames[] = BaseFont.getAllFontNames(file.getPath(), BaseFont.CP1252, null); insertNames(allNames, file.getPath()); ++count; } else if (name.endsWith(".ttc")) { String ttcs[] = BaseFont.enumerateTTCNames(file.getPath()); for (int j = 0; j < ttcs.length; ++j) { String nt = file.getPath() + "," + j; Object allNames[] = BaseFont.getAllFontNames(nt, BaseFont.CP1252, null); insertNames(allNames, nt); } ++count; } } catch (Exception e) { } return count; }
From source file:org.pz.platypus.plugin.pdf.PdfFontFactory.java
License:Open Source License
/** * Actual font registration. Takes care of specious warning emitted by iText registering * a TrueType collection (.ttc) file/*from ww w . j ava 2 s.c o m*/ * * called from RegisterOneFont() * * @param fontFile the complete filename including the path */ private void registerFont(String fontFile) { if (!fontFile.toLowerCase().endsWith(".ttc")) { FontFactory.register(fontFile); return; } // if the file is a TrueTypeCollection (.ttc), iText generates an error message // which it writes to stderr, and then registers the fonts. Since, there's no way // to prevent this unneeded message, we do the registration manually here to avoid // printing out the error message (about which the user can do nothing). String[] names; try { names = BaseFont.enumerateTTCNames(fontFile); if (names == null) { errTtcFileHandling(fontFile); return; } } catch (DocumentException de) { errTtcFileHandling(fontFile); return; } catch (IOException ioe) { errTtcFileHandling(fontFile); return; } for (int i = 0; i < names.length; i++) { FontFactory.register(fontFile + "," + i); } }
From source file:org.pz.platypus.TypefaceMap.java
License:Open Source License
/** * Uses iText to extract the family name (or in case of .ttc the names) of the font family. * * @param fontFilename font file//from w ww. j a va 2 s . c o m * @param bf base font we create to get the family font name * * @return the font's family name(s) or an empty array if an error occurred. * * For explanation of .ttc handling, see: * http://itextdocs.lowagie.com/tutorial/fonts/getting/index.php * */ public String[] extractFamilyNames(String fontFilename, BaseFont bf) { String familyName[] = new String[1]; String names[][]; File f = new File(fontFilename); if (f.exists() || !f.isDirectory()) { try { if (fontFilename.toLowerCase().endsWith(".ttc")) { return (BaseFont.enumerateTTCNames(fontFilename)); } bf = BaseFont.createFont(fontFilename, "winansi", BaseFont.NOT_EMBEDDED); names = bf.getFamilyFontName(); } catch (IOException ioe) { gdd.logInfo("IOException loading " + fontFilename + " into font-family map"); return (new String[0]); } catch (DocumentException de) { gdd.logInfo("Document Exception loading " + fontFilename + " into font-family map"); return (new String[0]); } if (names != null && names[0] != null) { familyName[0] = names[0][3]; return familyName; } else { return (new String[0]); } } return (new String[0]); }
From source file:org.xhtmlrenderer.pdf.ITextFontResolver.java
License:Open Source License
public void addFont(String path, String fontFamilyNameOverride, String encoding, boolean embedded, String pathToPFB) throws DocumentException, IOException { String lower = path.toLowerCase(); if (lower.endsWith(".otf") || lower.endsWith(".ttf") || lower.indexOf(".ttc,") != -1) { BaseFont font = BaseFont.createFont(path, encoding, embedded); String[] fontFamilyNames; if (fontFamilyNameOverride != null) { fontFamilyNames = new String[] { fontFamilyNameOverride }; } else {//from ww w .j a va 2 s. c o m fontFamilyNames = TrueTypeUtil.getFamilyNames(font); } for (int i = 0; i < fontFamilyNames.length; i++) { String fontFamilyName = fontFamilyNames[i]; FontFamily fontFamily = getFontFamily(fontFamilyName); FontDescription descr = new FontDescription(font); try { TrueTypeUtil.populateDescription(path, font, descr); } catch (Exception e) { throw new XRRuntimeException(e.getMessage(), e); } fontFamily.addFontDescription(descr); } } else if (lower.endsWith(".ttc")) { String[] names = BaseFont.enumerateTTCNames(path); for (int i = 0; i < names.length; i++) { addFont(path + "," + i, fontFamilyNameOverride, encoding, embedded, null); } } else if (lower.endsWith(".afm") || lower.endsWith(".pfm")) { if (embedded && pathToPFB == null) { throw new IOException("When embedding a font, path to PFB/PFA file must be specified"); } BaseFont font = BaseFont.createFont(path, encoding, embedded, false, null, readFile(pathToPFB)); String fontFamilyName; if (fontFamilyNameOverride != null) { fontFamilyName = fontFamilyNameOverride; } else { fontFamilyName = font.getFamilyFontName()[0][3]; } FontFamily fontFamily = getFontFamily(fontFamilyName); FontDescription descr = new FontDescription(font); // XXX Need to set weight, underline position, etc. This information // is contained in the AFM file (and even parsed by Type1Font), but // unfortunately it isn't exposed to the caller. fontFamily.addFontDescription(descr); } else { throw new IOException("Unsupported font type"); } }