Embedding web fonts in HTML output Embedding web fonts A custom plug-in can be created to generate HTML output that uses custom fonts for enhanced typographic features, extended character sets or a unique corporate identity. require link head HTMLcustom plug-in HTMLfonts CSSweb fonts fontsHTML web fontsfonts custom.css build_html5-webfont.xml plugin.xml org.dita.html5

This scenario walks through the process of creating a very simple plug-in (com.example.html5-webfont) that creates a new transformation type: .

The transformation includes a custom CSS file and sets five parameters to integrate font links and a custom stylesheet in the generated HTML5 output. These parameter settings make the following changes:

  • Specify a file that links to the font from the document head with args.hdf.

  • Specify the css subfolder of the plug-in as the source directory for custom CSS with args.cssroot.

  • Specify the name of the custom CSS file with args.css.

    The value of this parameter tells DITA-OT to use the custom.css file provided by the plug-in.

  • Ensure that the CSS file is copied to the output directory by setting args.copycss to .

  • Set the destination path for CSS files in the output folder with args.csspath.

    CSS files are copied to the root level of the output folder by default. Setting this parameter places CSS files in a dedicated css subfolder.

All five parameters are set in the Ant script (build_html5-webfont.xml).

In the plugins directory, create a directory named com.example.html5-webfont. In the new com.example.html5-webfont directory, create a plug-in configuration file (plugin.xml) that declares the new transformation and its dependencies. Sample <filepath>plugin.xml</filepath> file This plug-in will extend the default HTML5 transformation, so the require element explicitly defines org.dita.html5 as a dependency. In the com.example.html5-webfont directory, create a subdirectory named include. In the new include subdirectory, create a file named webfont.hdf.xml with your custom font links. Sample <filepath>webfont.hdf.xml</filepath> file

This example uses the font. You can use multiple fonts by creating additional link references in this file. The division wrapper will be discarded when generating HTML files, and the contents will be inserted into the head element of each page.

In the com.example.html5-webfont directory, create a subdirectory named css. In the new css subdirectory, create a file named custom.css with the stylesheet rules that apply the custom font-family to the desired elements. Sample <filepath>custom.css</filepath> file

This example uses for all body content. In practice, you would normally use different fonts for headings, body content, tables, etc. by creating additional rules in your CSS file.

In the com.example.html5-webfont root directory, add an Ant script (build_html5-webfont.xml) to define the transformation type. Sample build file: <filepath>build_html5-webfont.xml</filepath>
The files for this sample plug-in are included in the DITA-OT installation directory under docsrc/samples/plugins/com.example.html5-webfont/ and on GitHub.

The plug-in directory has the following layout and files:

com.example.html5-webfont ├── build_html5-webfont.xml ├── css │   └── custom.css ├── include │   └── webfont.hdf.xml └── plugin.xml
  1. Run --install to install the plug-in and make the transformation available.
  2. Build output with the new transformation type to verify that the plug-in works as intended. --input=my.ditamap --format=
  3. Refine the styles in your custom.css file to adjust the font usage as necessary.