}
private AFPFontInfo buildFont(Configuration fontCfg, String fontPath)
throws ConfigurationException {
FontManager fontManager = this.userAgent.getFactory().getFontManager();
Configuration[] triple = fontCfg.getChildren("font-triplet");
List/*<FontTriplet>*/ tripletList = new java.util.ArrayList/*<FontTriplet>*/();
if (triple.length == 0) {
log.error("Mandatory font configuration element '<font-triplet...' is missing");
return null;
}
for (int j = 0; j < triple.length; j++) {
int weight = FontUtil.parseCSS2FontWeight(triple[j].getAttribute("weight"));
FontTriplet triplet = new FontTriplet(triple[j].getAttribute("name"),
triple[j].getAttribute("style"),
weight);
tripletList.add(triplet);
}
//build the fonts
Configuration afpFontCfg = fontCfg.getChild("afp-font");
if (afpFontCfg == null) {
log.error("Mandatory font configuration element '<afp-font...' is missing");
return null;
}
URI baseURI = null;
String uri = afpFontCfg.getAttribute("base-uri", fontPath);
if (uri == null) {
//Fallback for old attribute which only supports local filenames
String path = afpFontCfg.getAttribute("path", fontPath);
if (path != null) {
File f = new File(path);
baseURI = f.toURI();
}
} else {
try {
baseURI = new URI(uri);
} catch (URISyntaxException e) {
log.error("Invalid URI: " + e.getMessage());
return null;
}
}
ResourceAccessor accessor = new DefaultFOPResourceAccessor(
this.userAgent,
fontManager.getFontBaseURL(),
baseURI);
String type = afpFontCfg.getAttribute("type");
if (type == null) {
log.error("Mandatory afp-font configuration attribute 'type=' is missing");