@Override
public void addFont(String path, String encoding, boolean embedded, String pathToPFB) throws DocumentException, IOException {
try {
String lower = path.toLowerCase();
if (lower.endsWith(".otf") || lower.endsWith(".ttf") || lower.indexOf(".ttc,") != -1) {
BaseFont font = BaseFont.createFont(path, encoding, embedded);
String fontFamilyName = TrueTypeUtil.getFamilyName(font);
FontFamily fontFamily = getCustomFontFamily(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, encoding, embedded);
}
} 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 = font.getFamilyFontName()[0][3];
FontFamily fontFamily = getCustomFontFamily(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 {
BaseFont font = BaseFont.createFont(path, encoding, embedded);
String fontFamilyName = font.getFamilyFontName()[0][3];
FontFamily fontFamily = getCustomFontFamily(fontFamilyName);
FontDescription descr = new FontDescription(font);
fontFamily.addFontDescription(descr);
}