FOP TTFReader - Build Italic and Bold Fonts

Q

How to build Italic, Bold and Italic-Bold fonts with FOP?

✍: FYIcenter.com

A

To build Italic, Bold and Italic-Bold fonts with FOP, we need to find their fond files in TTF format.

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

    813,876 calibri.ttf   > for Calibri,normal,400
    851,480 calibrib.ttf  > for Calibri,normal,700
    856,212 calibrii.ttf  > for Calibri,italic,400
    902,380 calibriz.ttf  > for Calibri,italic,700

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

\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

INFO: XML font metrics file successfully created.

Run FOP TTFReader program again to build the "Calibri" Bold, Italic and Italic-Bold font definition files.

Create a new FOP configuration file, cfg-calibri.xml, to all 4 fonts in the same family:

<?xml version="1.0"?>
<!-- cfg-calibri.xml
     Copyright (c) 2018 FYIcenter.com
-->
<fop version="1.0">
  <renderers>
    <renderer mime="application/pdf">
      <fonts>
        <font 
        ="\fyicenter\calibri.xml" kerning="no" 
          embed-url="\windows\fonts\calibri.ttf">
          <font-triplet name="Calibri" style="normal" weight="normal"/>
        </font>
        <font metrics-url="\fyicenter\calibrii.xml" kerning="no" 
          embed-url="\windows\fonts\calibrii.ttf">
          <font-triplet name="Calibri" style="italic" weight="normal"/>
        </font>
        <font metrics-url="\fyicenter\calibrib.xml" kerning="no" 
          embed-url="\windows\fonts\calibrib.ttf">
          <font-triplet name="Calibri" style="normal" weight="bold"/>
        </font>
        <font metrics-url="\fyicenter\calibriz.xml" kerning="no" 
          embed-url="\windows\fonts\calibriz.ttf">
          <font-triplet name="Calibri" style="italic" weight="bold"/>
        </font>
      </fonts>
    </renderer>
  </renderers>
</fop>

Generate the PDF output again from the FO file, calibri-bold-italic.fo. You will see no font missing error:

\local\fop-2.2\fop>fop \fyicenter\calibri-bold-italic.fo \temp\calibri-bold-italic.pdf
   -c \fyicenter\cfg-calibri.xml

org.apache.fop.events.LoggingEventListener processEvent
INFO: Rendered page #1.

Open the PDF output file, calibri-bold-italic.pdf in Acrobat Reader. You see all 4 fonts are working correctly now:
FOP Font Family, Bold and Italic, for PDF

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

 

FontView.exe - Preview Font Glyphs on Windows

FOP Missing Italic and Bold Fonts for PDF

Managing Fonts in FOP PDF Output

⇑⇑ FAQ for FOP (Formatting Object Processor)

2018-04-12, 193👍, 0💬