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 {
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);