More Resources
Table of Contents
More Resources
Compiling Custom Fonts for Plugin
Creating the XML Font Metric File
Create the XML font metric file to compile a font with your plugin.
Creating a Custom fop Configuration
Create a custom fop configuration file to package custom fonts within your plugin.
Creating the XML Font Metric File

Create the XML font metric file to compile a font with your plugin.
You built a plugin and installed a font locally on your computer using the procedures in Plugin Components and Adding Fonts Locally.

You want to create the XML font metrics file to compile the fonts with your plugin to use in easyDITA.

  1. Open the DITA Open Toolkit in the Command Line.
  2. We need to create the file that will generate the metric file. If you have already created this file, you just need to update the last line to point to the new font. This file should be saved in your root DITA OT directory.

    1. For OS X and Linux create a text file called “ttfConvert.sh” with the following contents:

      Step Information
      #!/bin/sh 
      
      export LIB=plugins/org.dita.pdf2/fop/lib
      export CP=plugins/org.dita.pdf2/fop/build/fop.jar
      export CP=$CP:$LIB/avalon-framework-4.2.0.jar
      export CP=$CP:$LIB/xercesImpl-2.7.1.jar
      export CP=$CP:$LIB/commons-logging-1.0.4.jar
      export CP=$CP:$LIB/commons-io-1.3.1.jar
      export CP=$CP:$LIB/xmlgraphics-commons-1.5.jar
      export CP=$CP:$LIB/xml-apis-1.3.04.jar
      export CMD="java -cp $CP org.apache.fop.fonts.apps.TTFReader"
      
      $CMD {path_to_font}{font_name}.xml

      You should set the {path_to_font} variable to be the path to the .TTF font file locally on your computer. For example: /Users/slucchini/Library/Fonts/Arialuni.ttf
      Then fill in the {font_name} with the name of the font. For example: Arialuni

    2. For Windows create a text file called “ttfConvert.bat” with the following contents:

      Step Information
      @echo off
      set LIB=plugins\org.dita.pdf2\fop\lib
      set CP=plugins\org.dita.pdf2\fop\build\fop.jar
      set CP=%CP%;%LIB%\avalon-framework-4.2.0.jar
      set CP=%CP%;%LIB%\xercesImpl-2.7.1.jar
      set CP=%CP%;%LIB%\commons-logging-1.0.4.jar
      set CP=%CP%;%LIB%\commons-io-1.3.1.jar
      set CP=%CP%;%LIB%\xmlgraphics-commons-1.5.jar
      set CP=%CP%;%LIB%\xml-apis-1.3.04.jar
      set CMD=java -cp "%CP%" org.apache.fop.fonts.apps.TTFReader
      
      %CMD% {path_to_font}{font_name}.xml

      You should set the {path_to_font} variable to be the path to the .TTF font file locally on your computer. For example: C:\Windows\Fonts\Arialuni.ttf
      Then fill in the {font_name} with the name of the font. For example: Arialuni

    3. If you want to convert multiple fonts at once (for example, if a font has a bold and/or italic variant), you can just copy the last line in the script and paste it again below with a different font path and name.
  3. In the DITA Open Toolkit command line that you opened in Step 1, run the file you just created using one of the two commands below. And you should be in the root directory of the toolkit (where you saved the script in Step 2).

    Step Information
    For OS X and Linux:

    sh ttfConvert.sh
    For Windows:

    ttfConvert.bat
    Important:If you get an error look in the plugins/org.dita.pdf2/fop/lib folder, check that each of the .jar files are there. Your version of the DITA Open Toolkit may have different versions of some of the files (commons-logging-1.1.1.jar instead of commons-logging.1.0.4).

  4. You should now see the XML metric files in the root folder of the DITA Open Toolkit. You’ll need to move these into your custom plugin.

    Expected Result
    {plugin_name}/lib/Arialuni.xml

  5. Create a folder named “lib” in the root of your plugin directory.

    Step Information
    plugins/{plugin_name}/lib/

  6. Move the XML font metric files and the original .TTF font file that you used to create the XML font metric (the {path_to_font} from Step 2) into the lib folder.
You created the XML font metrics files for your fonts. See Creating a Custom fop Configuration to create a customized fop configuration file to allow custom fonts within your plugin.

Creating a Custom fop Configuration

Create a custom fop configuration file to package custom fonts within your plugin.
You created the XML font metric file using the procedure in Creating the XML Font Metric File.

You want to create a custom fop configuration file to allow custom fonts within your plugin.

  1. First, you have to copy the default fop.xconf file from the PDF2 plugin. Copy it from plugins/org.dita.pdf2/fop/conf/fop.xconf to plugins/{plugin_name}/fop/conf/
  2. Locate the < fonts> tag (around line 50).
  3. You should see < auto-detect/> along with a bunch of commented out code.

    Step Information
    Auto-detect means that the DITA Open Toolkit will look for fonts that have been installed on the operating system.

  4. You need to add a line that specifically adds the custom font. Below < auto-detect/> (but before the closing < /fonts> tag), add the following code:

    Step Information
    < font metrics-url="plugins/{plugin_name}/lib/{font_name_xml}" kerning="yes" embed-url="file:plugins/{plugin_name}/lib/{font_name_ttf}"> 
    	< font-triplet name="{font-face_name}" style="{style}" weight="{weight}"/> 
    < /font> 

    {plugin_name} is the name of your plugin folder
    {font_name_xml} is the name of your font’s XML metric file (created in Creating the XML Font Metric File).
    {font_name_ttf} is the name of the .TTF file for your font
    {font-face_name} is the base name of your font. For example, if {font_name_ttf} is Arialuni-Bold.ttf, {font-face_name} would simply be Arialuni.
    {style} can either be “normal” or “italic” based on the .TTF file
    {weight} can either be “normal” or “bold” based on the .TTF file

    Expected Result
    An example for Arialuni-Bold in the com.jorsek.custom.pdf plugin: 

    < font metrics-url="plugins/com.jorsek.custom.pdf/lib/Arialuni-Bold.xml" kerning="yes" embed-url="file:plugins/com.jorsek.custom.pdf/lib/Arialuni-Bold.ttf"> 
    	< font-triplet name="Arialuni" style="normal" weight="bold"/> 
    < /font> 
    Note:If you have multiple fonts (even multiple variants of the same font: bold, italic, etc) you need a separate < font> tag for each one.

  5. Save your custom fop configuration file.
  6. Now, you need to add a parameter to the ant build script to tell the processor where to look for your customized fop configuration file. Open your build template file (build_custom.pdf_template.xml).
  7. Right above the final antcall to dita2pdf, add the following property to your custom target:

    Step Information
    < property name="args.fo.userconfig" value="${dita.dir}/plugins/[plugin_name]/fop/conf/fop.xconf"/> 

You set up your custom fop configuration to include your custom fonts. Next, you’ll need to look at Adding Custom Fonts to the XML.