Search code examples
javaapachefontsapache-fop

Apache FOP 2.0: .ttf to .xml conversion


I'm trying to obtain .xml from .ttf in order to embed fonts in Apache FOP for PDF/a conversion (PDF conversion work with without the .xml). Can you please help me to do this conversion. Below comes what I tried so far:

I found several website explaining that the conversion shall be done by inputing the folowing line in a CLI open on the directory that contain my .ttf:

java -cp PATH ; PATH\avalon-framework.jar org.apache.fop.fonts.apps.TTFReader arial.ttf arial.xml

with PATH the path to my fop.jar. It didn't work and return me: ERROR: Impossible to find the main class

So I tried to use TTFReader:

     TTFReader read=new TTFReader();
     read.constructFontXML(read.loadTTF(chemin+"Fonts/ttf/arial.ttf", "Arial",true,true), "Arial", "Arial", "C:/Fonts/arial.ttf"  ,chemin+"Fonts/ttf/arial.ttf", true, "Arial");

But I didn't understood all the input needed:

constructFontXML(TTFFile ttf,String fontName, String className, String resource, String file,boolean isCid, String ttcName)
loadTTF(String fileName, String fontName, boolean useKerning, boolean useAdvanced)

I have no idea on how to get the information to set the boolean correctly, nor what is ClassName and what purpose serve ressource since path already exist. My code give me .xml but I don't think they are valid.


Solution

  • The issue was bypass by lfurini since I finally didn't needed those .xml but here is some code that render .xml even if I doubt they are configured the right way:

             String[] fonts={"Arial", "Courier", "Times New Roman"};
             String[] fontsR={"arial","courier","times"};
             String[] styles={""," Bold"," Italic"," Bold Italic"};
             String[] stylesR={"","bd","i","bi"};
             for (int i=0;i<fonts.length;i++){
                 for (int j=0;j<styles.length;j++){
                     String nameFont=fonts[i]+styles[j];
                     String nameTTF=fontsR[i]+stylesR[j];
                     TTFReader read=new TTFReader();
                     Document document=read.constructFontXML(read.loadTTF(chemin+"Fonts/ttf/"+nameTTF+".ttf", nameFont,true,true), nameFont, fonts[i], "C:/Fonts/ttf/"+nameTTF+".ttf"  ,"C:/Fonts/ttf/"+nameTTF+".ttf", true, fonts[i]);
                     Transformer transformer = TransformerFactory.newInstance().newTransformer();
                     Result output = new StreamResult(new File(chemin+"Fonts/xml/"+nameTTF+".xml"));
                     Source input = new DOMSource(document);
                     transformer.transform(input, output);