XSL-FO stylesheets and FOP-registered fonts
With the FOP user configuration file configured and integrated with the OT, your document comes out looking pretty much the way it did before you started.You need to update the XSL-FO stylesheets to use font-family, font-style, and font-weight attribute values that correspond to the values of the name, weight, and style in the font-triplet in the configuration file. I have already pointed out one consideration in the stylesheets for matching the font-family name, font-weight, and font-style values in Individual registration of fonts.
Many of the font settings are established using <attribute-set> elements in the dita2fo-parms.xsl file. The <attribute-set> element defines a group of style attributes that can be used by an element. The XSL-FO code that handles a given element then refers to the <attribute-set> to apply those styles. The following example clarifies this arrangement.
In the fop.xconf file, the Eras-Bold ITF font is defined with this code:
<font metrics-url="ttferasbd.xml" kerning="yes"
embed-url="file:///C:/Windows/Fonts/erasbd.ttf">
<font-triplet
name="Eras" style="normal" weight="bold"/>
</font>
In the dita2fo-parms.xsl file, I modified the “topictitle1” attribute set to change first-level headings as follows:
<xsl:attribute-set name="topictitle1" >
<xsl:attribute
name="break-before">page</xsl:attribute>
<xsl:attribute name="margin-top">0.5pc</xsl:attribute>
<xsl:attribute
name="margin-bottom">0.5pc</xsl:attribute>
<xsl:attribute
name="font-size">18pt</xsl:attribute>
<xsl:attribute name="font-family">Eras</xsl:attribute>
<xsl:attribute
name="font-style">normal</xsl:attribute>
<xsl:attribute name="font-weight">bold</xsl:attribute>
<xsl:attribute
name="keep-with-next.within-page">always</xsl:attribute>
</xsl:attribute-set>
In the dita2fo_titles.xsl file, the following code already exists for processing first-level headings. It does not need to be modified because it already uses the “topictitle1” attribute set.
<!-- h1 -->
<xsl:template match="*[contains(@class,'
topic/topic ')]/*[contains(@class,' topic/title ')]"
priority="2">
<fo:block xsl:use-attribute-sets="topictitle1" padding-top="1.4pc">
<fo:block border-top-color="black" border-top-width="3pt" line-height="100%"
border-left-
width="0pt" border-right-width="0pt">
<xsl:call-template name="get-title"/>
</fo:block>
</fo:block>
</xsl:template>
With these values in place, the XSL-FO code will create the following XSL-FO code when it encounters a title in a top-level topic; the following example shows the top fo:block element only, because that is the only one relevant to this discussion. The attributes from the topictitle1 attribute-set have been substituted for the xsl:use-attribute-sets="topictitle1".
<fo:block break-before=”page”
margin-top="0.5pc"
margin-bottom="0.5pc"
font-size="18pt"
font-family="Eras"
font-style="normal"
font-weight="bold"
keep-with-next.within-page="always"
padding-top=
"1.6pc">
This is the XSL-FO code that FOP reads. FOP matches the font-family, font-style, and font-weight values in this <fo:block> element and finds the <font> element with a matching <font-triplet> value. When it finds a match, it uses the font file specified in the <font> element to create the PDF code.
Some PDF files may need to use 10pt Times New Roman for the <p> tag; others might call for 11pt Veljovic. You may have some sophisticated programming built into your stylesheets. If you made a separate DITA Open Toolkit for every type of PDF file you wanted to create, you would wind up with a lot of code duplication that would be difficult to maintain. To solve this problem, you can create a DITA Open Toolkit plug-in that contains the changes and add it to the DITA Open Toolkit’s plugins directory. For guidance in this work, I recommend Scriptorium’s white paper on hacking the DITA Open Toolkit.
Best wishes for implementing your fonts. And for encouragement, here’s a shot of the Taj Mahal after a few hours of work (Figure 2). Yes, there’s more to be done, but it appears that graceful order can indeed be imposed on the chaos.
Figure 2: Well on the way.
