PhysicalFont pf;
// for (Iterator iterIn = fontInfo.getFontTriplets().iterator() ; iterIn.hasNext();) {
// FontTriplet triplet = (FontTriplet)iterIn.next();
FontTriplet triplet = (FontTriplet)fontInfo.getFontTriplets().get(0);
// There is one triplet for each of the font family names
// this font has, and we create a PhysicalFont object
// for each of them. For our purposes though, each of
// these physical font objects contains the same info
String lower = fontInfo.getEmbedFile().toLowerCase();
log.debug("Processing physical font: " + lower);
debug.append(".. triplet " + triplet.getName()
+ " (priority " + triplet.getPriority() +"\n" );
pf = null;
// xhtmlrenderer's org.xhtmlrenderer.pdf.ITextFontResolver.addFont
// can handle
// .otf, .ttf, .ttc, .pfb
if (lower.endsWith(".otf") || lower.endsWith(".ttf") || lower.endsWith(".ttc") ) {
pf = new PhysicalFont(triplet.getName(), fontInfo, fontResolver);
} else if (lower.endsWith(".pfb") ) {
// See whether we have everything org.xhtmlrenderer.pdf.ITextFontResolver.addFont
// will need - for a .pfb file, it needs a corresponding .afm or .pfm
String afm = FontUtils.pathFromURL(lower);
afm = afm.substring(0, afm.length()-4 ) + ".afm"; // drop the 'file:'
log.debug("Looking for: " + afm);
File f = new File(afm);
if (f.exists()) {
log.debug(".. found");
// Uncomment if you want to use the iText stuff in docx4j-extras
// // We're only interested if this font supports UTF-8 encoding
// // since otherwise iText can't use it (at least on a
// // UTF8 encoded XHTML document)
// try {
// BaseFont bf = BaseFont.createFont(afm,
// BaseFont.IDENTITY_H,
// BaseFont.NOT_EMBEDDED);
// } catch (java.io.UnsupportedEncodingException uee) {
// log.error(afm + " does not support UTF encoding, so ignoring");
// continue;
// } catch (Exception e) {
// log.error(e.getMessage(), e);
// continue;
// }
pf = new PhysicalFont(triplet.getName(),fontInfo, fontResolver);
} else {
// Should we be doing afm first, or pfm?
String pfm = FontUtils.pathFromURL(lower);
pfm = pfm.substring(0, pfm.length()-4 ) + ".pfm"; // drop the 'file:'
log.debug("Looking for: " + pfm);
f = new File(pfm);
if (f.exists()) {
log.debug(".. found");
// Uncomment if you want to use the iText stuff in docx4j-extras
// // We're only interested if this font supports UTF-8 encoding
// try {
// BaseFont bf = BaseFont.createFont(pfm,
// BaseFont.IDENTITY_H,
// BaseFont.NOT_EMBEDDED);
// } catch (java.io.UnsupportedEncodingException uee) {
// log.error(pfm + " does not support UTF encoding, so ignoring");
// continue;
// } catch (Exception e) {
// log.error(e.getMessage(), e);
// continue;
// }
pf = new PhysicalFont(triplet.getName(), fontInfo, fontResolver);
} else {
log.warn("Skipping " + triplet.getName() + "; couldn't find .afm or .pfm for : " + fontInfo.getEmbedFile());
}
}
} else {
log.warn("Skipping " + triplet.getName() + "; unsupported type: " + fontInfo.getEmbedFile());
}
if (pf!=null) {