public static List buildFontListFromConfiguration(Configuration cfg,
String fontBaseURL, FontResolver fontResolver,
boolean strict, FontCache fontCache) throws FOPException {
List fontInfoList = new java.util.ArrayList();
Configuration fonts = cfg.getChild("fonts");
if (fonts != null) {
long start = 0;
if (log.isDebugEnabled()) {
log.debug("Starting font configuration...");
start = System.currentTimeMillis();
}
// native o/s search (autodetect) configuration
boolean autodetectFonts = (fonts.getChild("auto-detect", false) != null);
if (!autodetectedFonts && autodetectFonts) {
// search in font base if it is defined and
// is a directory but don't recurse
FontFileFinder fontFileFinder = new FontFileFinder();
if (fontBaseURL != null) {
try {
File fontBase = FileUtils.toFile(new URL(fontBaseURL));
if (fontBase != null) {
//Can only use the font base URL if it's a file URL
addFontInfoListFromFileList(
fontFileFinder.find(fontBase.getAbsolutePath()),
fontInfoList,
fontResolver,
fontCache
);
}
} catch (IOException e) {
LogUtil.handleException(log, e, strict);
}
}
// native o/s font directory finder
try {
addFontInfoListFromFileList(
fontFileFinder.find(),
fontInfoList,
fontResolver,
fontCache
);
} catch (IOException e) {
LogUtil.handleException(log, e, strict);
}
autodetectedFonts = true;
}
// directory (multiple font) configuration
Configuration[] directories = fonts.getChildren("directory");
for (int i = 0; i < directories.length; i++) {
boolean recursive = directories[i].getAttributeAsBoolean("recursive", false);
String directory = null;
try {
directory = directories[i].getValue();
} catch (ConfigurationException e) {
LogUtil.handleException(log, e, strict);
continue;
}
if (directory == null) {
LogUtil.handleException(log,
new FOPException("directory defined without value"), strict);
continue;
}
FontFileFinder fontFileFinder = new FontFileFinder(recursive ? -1 : 1);
try {
addFontInfoListFromFileList(
fontFileFinder.find(directory),
fontInfoList,
fontResolver,
fontCache
);
} catch (IOException e) {
LogUtil.handleException(log, e, strict);
}
}
// font file (singular) configuration
Configuration[] font = fonts.getChildren("font");
for (int i = 0; i < font.length; i++) {
EmbedFontInfo fontInfo = getFontInfoFromConfiguration(
font[i], fontResolver, strict, fontCache);
if (fontInfo != null) {
fontInfoList.add(fontInfo);