Fonts and FOP

Jean-François Perrot

with the expert help of Marie-Anne Moreaux (INaLCO)
  1. Motivation

  2. About the standard fonts
    1. Definition
    2. Typefaces with the same names...

  3. FOP configuration files
    1. Option of the fop command
    2. .xconf files

  4. A complete solution
    1. Configuration file
    2. XSL transform
    3. Result


  1. Motivation

    Apache FOP is equipped with standard fonts, which are able to cope with the most frequent situations (from a Western point of view).
    If for some reason you need any other font, then you have to register it thanks to a configuration file for FOP.
    This may happen on two different grounds:
    The present document takes the second point of view.

    Our starting point is the experience of Zuzana Lietavcová, whose DocBook report is in Czech: while written with the Latin alphabet, the language requires a number of accented letters (such as 'ř' which appears in the name of the famous musician Antonín Dvořák), some of which are not served by the standard fonts. As a consequence, the missing characters are rendered by FOP as '#'.
    For instance, the first sentence of her report, which should read
    Při ohlášení projektů do předmětu ITU došlo mezi studenty k silné debatě a obecnému nadšení.
    appears as
    P#i ohlášení projekt# do p#edm#tu ITU došlo mezi studenty k silné debat# a obecnému nadšení.

    Our aim is to solve this problem.
  2. About the standard fonts


  3. FOP configuration files

  4. A complete solution

    This time we import the 3 usual typefaces (Helvetica, Times, Courier for sans-serif, serif and monospace),
    and for each the 3 font files (normal, bold, italic) that are available.
    They are enough for the traditional rendering, bold italic being synthetized from bold and italic.

    Note that on some systems these typefaces are bundled as dfont files, which are not suitable for importing.
    You must unpack them to get hold of the individual .ttf files, e.g. via Transfonter : http://transfonter.org/ttc-unpack
    1. Configuration file

      Conf-HTC.xconf

      <?xml version="1.0"?>
      <!-- Helvetica, Times, Courier  -->
      <fop version="1.0">

        <!-- Base URL for resolving relative URLs -->
        <base>.</base>
       
        <!-- Information for specific renderers -->
        <!-- Uses renderer mime type for renderers -->
        <renderers>
          <renderer mime="application/pdf">
            <fonts>
              <font embed-url="/users/jfp/Library.new/Fonts/Helvetica.ttf">
                <font-triplet name="Helvetica" style="normal" weight="normal"/>
              </font>
              <font embed-url="/users/jfp/Library.new/Fonts/Helvetica-Bold.ttf">
                <font-triplet name="Helvetica" style="normal" weight="bold"/>
              </font>
              <font embed-url="/users/jfp/Library.new/Fonts/Helvetica-Oblique.ttf">
                <font-triplet name="Helvetica" style="italic" weight="normal"/>
              </font>   
                 
              <font embed-url="/users/jfp/Library.new/Fonts/Times-Roman.ttf">
                <font-triplet name="Times" style="normal" weight="normal"/>
              </font>
              <font embed-url="/users/jfp/Library.new/Fonts/Times-Bold.ttf">
                <font-triplet name="Times" style="normal" weight="bold"/>
              </font>
              <font embed-url="/users/jfp/Library.new/Fonts/Times-Italic.ttf">
                <font-triplet name="Times" style="italic" weight="normal"/>
              </font>   

              <font embed-url="/users/jfp/Library.new/Fonts/Courier.ttf">
                <font-triplet name="Courier" style="normal" weight="normal"/>
              </font>
              <font embed-url="/users/jfp/Library.new/Fonts/Courier-Bold.ttf">
                <font-triplet name="Courier" style="normal" weight="bold"/>
              </font>
              <font embed-url="/users/jfp/Library.new/Fonts/Courier-Oblique.ttf">
                <font-triplet name="Courier" style="italic" weight="normal"/>
              </font>   
            </fonts>
          </renderer>
        </renderers>

      </fop>



    2. XSL transform

      We try to make it a bit more elaborate, in order to make full use of our fonts...
      For technical details, see the Cookbook.

      doc2foHTC.xsl

      <?xml version='1.0'?>
      <!DOCTYPE stylesheet [
          <!ENTITY dbdir "
      /Path/to/.../DocBook/docbook-xsl-ns-1.78.1">
      ]>
      <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                      version="1.0"
                      xmlns:d="http://docbook.org/ns/docbook"
                      xmlns:fo="http://www.w3.org/1999/XSL/Format">

        <xsl:import href= "&dbdir;/fo/docbook.xsl"/>

        <xsl:output method="xml" indent="yes"/>
       
      <!-- setting paper size -->
        <xsl:param name="paper.type" select="'A4'"/>

      <!-- fonts -->
      <xsl:param name="body.font.family" select="'Helvetica'"/>
      <xsl:param name="title.font.family" select="'Times'"/>

      <!-- automatic numbering of sections -->
      <xsl:param name="section.autolabel" select="1" />

      <!-- do not print URL after link texts -->
      <xsl:param name="ulink.show" select="0"/>

      <!-- ensuring a 30pt space before first-level sections -->
        <xsl:attribute-set name="section.level1.properties">
            <xsl:attribute name="space-before">30pt</xsl:attribute>
        </xsl:attribute-set>
       
      <!-- ensuring a 15pt space before second-level sections -->
        <xsl:attribute-set name="section.level2.properties">
            <xsl:attribute name="space-before">15pt</xsl:attribute>
        </xsl:attribute-set>
       
       <!-- hypertext links as in traditional HTML -->
      <xsl:attribute-set name="xref.properties">
        <xsl:attribute name="color">blue</xsl:attribute>
        <xsl:attribute name="text-decoration">underline</xsl:attribute>
      </xsl:attribute-set>

      <!-- special rule for captions -->
        <xsl:template match="d:caption/d:para">
            <fo:block font-family="Courier" space-after="30pt">
                <xsl:apply-imports />
            </fo:block>
        </xsl:template>

      </xsl:stylesheet>



    3. Result

      snippet-2
      Showing that bold is taken care of...

      snippet-3
      ...as well as bold+italic.