{
LibFontBoot.getInstance().start();
LibXmlBoot.getInstance().start();
final TrueTypeFontRegistry registry = new TrueTypeFontRegistry();
final ITextFontRegistry itextRegistry = new ITextFontRegistry();
registry.initialize();
itextRegistry.initialize();
final DefaultTagDescription defaultTagDescription = new DefaultTagDescription();
defaultTagDescription.setNamespaceHasCData(null, false);
final XmlWriter writer = new XmlWriter(new OutputStreamWriter(new FileOutputStream("/Users/user/fonts.xml"), "UTF-8"), defaultTagDescription);
writer.writeXmlDeclaration("UTF-8");
writer.writeTag(null, "font-spec", "fallback-font", "Arial", false);
final Map<String, FontRecord> records = new HashMap<String, FontRecord>();
final String[] families = registry.getAllRegisteredFamilies();
// final String[] families = new String[]{"Arial"};
Arrays.sort(families);
for (int i = 0; i < families.length; i++)
{
final String family = families[i];
writer.writeTag(null, "font-family", "name", family, false);
final FontFamily fontFamily = registry.getFontFamily(family);
writeRecord(writer, false, false, fontFamily.getFontRecord(false, false), records);
writeRecord(writer, true, false, fontFamily.getFontRecord(true, false), records);
writeRecord(writer, false, true, fontFamily.getFontRecord(false, true), records);
writeRecord(writer, true, true, fontFamily.getFontRecord(true, true), records);
writer.writeCloseTag();
}
final FontContext context = new DefaultFontContext(1000, false, true, false, "Identity-H");
final FontMetricsFactory metricsFactory = itextRegistry.createMetricsFactory();
final String[] sourceFiles = records.keySet().toArray(new String[records.size()]);
Arrays.sort(sourceFiles);
for (int i = 0; i < sourceFiles.length; i++)
{
final String sourceFile = sourceFiles[i];