FOP TTFReader - Build Font Definitions

Q

How to build font definition file with FOP? I have the font file for my favorite font in TTF format.

✍: FYIcenter.com

A

If you the font file in TTF format, you can build the font definition file with the FOP TTFReader program.

For example, you see "Calibri" and "Gothic" font files located in \windows\fonts folder:

   813,876 calibri.ttf
   137,568 gothic.ttf

You can run FOP TTFReader program to build the "Calibri" font definition file:

\local\fop-2.2\fop>java -cp %FOP_PATH%\build\fop.jar;
   %FOP_PATH%\lib\xercesImpl-2.9.1.jar;
   %FOP_PATH%\lib\xalan-2.7.2.jar;
   %FOP_PATH%\lib\avalon-framework-4.3.1.jar;
   %FOP_PATH%\lib\commons-logging-1.0.4.jar;
   %FOP_PATH%\lib\commons-io-1.3.1.jar;
   %FOP_PATH%\lib\serializer-2.7.2.jar;
   %FOP_PATH%\lib\xmlgraphics-commons-2.2.jar 
   org.apache.fop.fonts.apps.TTFReader 
   -d \windows\calibri.ttf \fyicenter\calibri.xml

org.apache.fop.fonts.apps.TTFReader main
INFO: TTF Reader for Apache FOP 2.2

org.apache.fop.fonts.apps.TTFReader main
INFO: Parsing font...
org.apache.fop.fonts.apps.TTFReader loadTTF
INFO: Reading C:\windows\fonts\calibri.ttf...
org.apache.fop.fonts.apps.TTFReader loadTTF
INFO: Font Family: [Calibri]
org.apache.fop.fonts.apps.TTFReader constructFontXML
INFO: Creating xml font file...
org.apache.fop.fonts.apps.TTFReader main
INFO: Creating CID encoded metrics...
org.apache.fop.fonts.apps.AbstractFontReader writeFontXML
INFO: Writing xml font file calibri.xml...
org.apache.fop.fonts.apps.TTFReader main
INFO: This font contains no embedding license restrictions.
INFO: XML font metrics file successfully created.

Run FOP TTFReader program again to build the "Gothic" font definition file.

Open the \fyicenter\calibri.xml to see details of a font definition file:

<font-metrics metrics-version="2" type="TYPE0">
    <font-name>Calibri</font-name>
    <full-name>Calibri</full-name>
    <family-name>Calibri</family-name>
    <embed/>
    <cap-height>634</cap-height>
    <x-height>466</x-height>
    <ascender>750</ascender>
    <descender>-250</descender>
    <bbox>
        <left>-502</left>
        <bottom>-307</bottom>
        <right>1240</right>
        <top>963</top>
    </bbox>
    <flags>33</flags>
    <stemv>0</stemv>
    <italicangle>0</italicangle>
    <subtype>TYPE0</subtype>
    <multibyte-extras>

This tutorial is valid in FOP 2.2, 2.1, and 2.0.

 

Define Your Own Font in FOP cfg.xml

FOP Missing Font Error for PDF

Managing Fonts in FOP PDF Output

⇑⇑ FAQ for FOP (Formatting Object Processor)

2018-04-12, 1734🔥, 0💬