FOP and font embedding
Greg generated font-metrics files for all the DejaVu and Gentium files -- he's blogged that process elsewhere. It only worked on Lettuce; even with the same Cocoon jars, it fails on OSX and Windows.
Then I was able to create a fop-config.xml file, which I'll reproduce at the end of this message. That file was placed in [cocoon]/WEB-INF. Then the root sitemap, which is where the fo2pdf serializer is defined, was modified, to add the <user-config> tag here:
<map:serializer logger="sitemap.serializer.fo2pdf" mime-type="application/pdf" name="fo2pdf" src="org.apache.cocoon.serialization.FOPSerializer"> <user-config>context:/WEB-INF/fop-config.xml</user-config> </map:serializer>
We know this works, because FOP would fail when we got it slightly wrong, then succeed when it was able to find the file. The key here is that this file path is relative, so the Cocoon instance remains portable.
Next, I put the fonts themselves, along with the font-metrics files, in a subfolder of WEB-INF, [cocoon]/WEB-INF/fop-fonts.
But here's the big problem: FOP was not able to find and use the fonts unless the paths to them were absolute. We tried a number of variants of relative paths, including file:fop-fonts/..., file://fop-fonts/..., ./fop-fonts/... and so on. Every attempt required a restart of Cocoon, and every second attempt required a restart of Tomcat (Tomcat dies on the second attempt to restart one of its webapps). This is not a workable way to proceed, so I'll have to set up a working Tomcat stack on a local machine to play with this. It's possible that setting the <base> or <base-font> elements correctly will do it; and it's also possible that we're incorrectly assuming these paths need to be relative to the fop-config.xml file, when actually they should be relative to something else (such as the lib directory where the FOP jar file is).
For the record, here's our fop-config.xml file, with ./ relative paths that don't work.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<fonts>
<font metrics-file="./fop-fonts/DejaVuSans.xml"
kerning="yes" embed-file="./fop-fonts/DejaVuSans.ttf">
<font-triplet name="DejaVu Sans" style="normal" weight="normal"/>
<font-triplet name="DejaVuSans" style="normal" weight="normal"/>
</font>
<font metrics-file="./fop-fonts/DejaVuSans-Bold.xml"
kerning="yes" embed-file="./fop-fonts/DejaVuSans-Bold.ttf">
<font-triplet name="DejaVu Sans" style="normal" weight="bold"/>
<font-triplet name="DejaVuSans" style="normal" weight="bold"/>
</font>
<font metrics-file="./fop-fonts/DejaVuSans-BoldOblique.xml"
kerning="yes" embed-file="./fop-fonts/DejaVuSans-BoldOblique.ttf">
<font-triplet name="DejaVu Sans" style="italic" weight="bold"/>
<font-triplet name="DejaVuSans" style="italic" weight="bold"/>
</font>
<font metrics-file="./fop-fonts/DejaVuSans-Oblique.xml"
kerning="yes" embed-file="./fop-fonts/DejaVuSans-Oblique.ttf">
<font-triplet name="DejaVu Sans" style="italic" weight="normal"/>
<font-triplet name="DejaVuSans" style="italic" weight="normal"/>
</font>
<font metrics-file="./fop-fonts/DejaVuSansCondensed.xml"
kerning="yes" embed-file="./fop-fonts/DejaVuSansCondensed.ttf">
<font-triplet name="DejaVu Sans Condensed" style="normal" weight="normal"/>
<font-triplet name="DejaVuSansCondensed" style="normal" weight="normal"/>
</font>
<font metrics-file="./fop-fonts/DejaVuSansCondensed-Bold.xml"
kerning="yes" embed-file="./fop-fonts/DejaVuSansCondensed-Bold.ttf">
<font-triplet name="DejaVu Sans Condensed" style="normal" weight="bold"/>
<font-triplet name="DejaVuSansCondensed" style="normal" weight="bold"/>
</font>
<font metrics-file="./fop-fonts/DejaVuSansCondensed-BoldOblique.xml"
kerning="yes" embed-file="./fop-fonts/DejaVuSansCondensed-BoldOblique.ttf">
<font-triplet name="DejaVu Sans Condensed" style="italic" weight="bold"/>
<font-triplet name="DejaVuSansCondensed" style="italic" weight="bold"/>
</font>
<font metrics-file="./fop-fonts/DejaVuSansCondensed-Oblique.xml"
kerning="yes" embed-file="./fop-fonts/DejaVuSansCondensed-Oblique.ttf">
<font-triplet name="DejaVu Sans Condensed" style="italic" weight="normal"/>
<font-triplet name="DejaVuSansCondensed" style="italic" weight="normal"/>
</font>
<font metrics-file="./fop-fonts/DejaVuSansMono.xml"
kerning="yes" embed-file="./fop-fonts/DejaVuSansMono.ttf">
<font-triplet name="DejaVu Sans Mono" style="normal" weight="normal"/>
<font-triplet name="DejaVuSansMono" style="normal" weight="normal"/>
</font>
<font metrics-file="./fop-fonts/DejaVuSansMono-Bold.xml"
kerning="yes" embed-file="./fop-fonts/DejaVuSansMono-Bold.ttf">
<font-triplet name="DejaVu Sans Mono" style="normal" weight="bold"/>
<font-triplet name="DejaVuSansMono" style="normal" weight="bold"/>
</font>
<font metrics-file="./fop-fonts/DejaVuSansMono-BoldOblique.xml"
kerning="yes" embed-file="./fop-fonts/DejaVuSansMono-BoldOblique.ttf">
<font-triplet name="DejaVu Sans Mono" style="italic" weight="bold"/>
<font-triplet name="DejaVuSansMono" style="italic" weight="bold"/>
</font>
<font metrics-file="./fop-fonts/DejaVuSansMono-Oblique.xml"
kerning="yes" embed-file="./fop-fonts/DejaVuSansMono-Oblique.ttf">
<font-triplet name="DejaVu Sans Mono" style="italic" weight="normal"/>
<font-triplet name="DejaVuSansMono" style="italic" weight="normal"/>
</font>
<font metrics-file="./fop-fonts/DejaVuSans-ExtraLight.xml"
kerning="yes" embed-file="./fop-fonts/DejaVuSans-ExtraLight.ttf">
<font-triplet name="DejaVu Sans Condensed" style="normal" weight="400"/>
<font-triplet name="DejaVuSansCondensed" style="normal" weight="400"/>
</font>
<font metrics-file="./fop-fonts/DejaVuSerif.xml"
kerning="yes" embed-file="./fop-fonts/DejaVuSerif.ttf">
<font-triplet name="DejaVu Serif" style="normal" weight="normal"/>
<font-triplet name="DejaVuSerif" style="normal" weight="normal"/>
</font>
<font metrics-file="./fop-fonts/DejaVuSerif-Bold.xml"
kerning="yes" embed-file="./fop-fonts/DejaVuSerif-Bold.ttf">
<font-triplet name="DejaVu Serif" style="normal" weight="bold"/>
<font-triplet name="DejaVuSerif" style="normal" weight="bold"/>
</font>
<font metrics-file="./fop-fonts/DejaVuSerif-BoldItalic.xml"
kerning="yes" embed-file="./fop-fonts/DejaVuSerif-BoldItalic.ttf">
<font-triplet name="DejaVu Serif" style="italic" weight="bold"/>
<font-triplet name="DejaVuSerif" style="italic" weight="bold"/>
</font>
<font metrics-file="./fop-fonts/DejaVuSerif-Italic.xml"
kerning="yes" embed-file="./fop-fonts/DejaVuSerif-Italic.ttf">
<font-triplet name="DejaVu Serif" style="italic" weight="normal"/>
<font-triplet name="DejaVuSerif" style="italic" weight="normal"/>
</font>
<font metrics-file="./fop-fonts/DejaVuSerifCondensed.xml"
kerning="yes" embed-file="./fop-fonts/DejaVuSerifCondensed.ttf">
<font-triplet name="DejaVu Serif Condensed" style="normal" weight="normal"/>
<font-triplet name="DejaVuSerifCondensed" style="normal" weight="normal"/>
</font>
<font metrics-file="./fop-fonts/DejaVuSerifCondensed-Bold.xml"
kerning="yes" embed-file="./fop-fonts/DejaVuSerifCondensed-Bold.ttf">
<font-triplet name="DejaVu Serif Condensed" style="normal" weight="bold"/>
<font-triplet name="DejaVuSerifCondensed" style="normal" weight="bold"/>
</font>
<font metrics-file="./fop-fonts/DejaVuSerifCondensed-BoldItalic.xml"
kerning="yes" embed-file="./fop-fonts/DejaVuSerifCondensed-BoldItalic.ttf">
<font-triplet name="DejaVu Serif Condensed" style="italic" weight="bold"/>
<font-triplet name="DejaVuSerifCondensed" style="italic" weight="bold"/>
</font>
<font metrics-file="./fop-fonts/DejaVuSerifCondensed-Italic.xml"
kerning="yes" embed-file="./fop-fonts/DejaVuSerifCondensed-Italic.ttf">
<font-triplet name="DejaVu Serif Condensed" style="italic" weight="normal"/>
<font-triplet name="DejaVuSerifCondensed" style="italic" weight="normal"/>
</font>
<font metrics-file="./fop-fonts/GenI102-Italic.xml"
kerning="yes" embed-file="./fop-fonts/GenI102.ttf">
<font-triplet name="Gentium" style="italic" weight="normal"/>
</font>
<font metrics-file="./fop-fonts/GenR102.xml"
kerning="yes" embed-file="./fop-fonts/GenR102.ttf">
<font-triplet name="Gentium" style="normal" weight="normal"/>
</font>
<font metrics-file="./fop-fonts/GenAI102-Italic.xml"
kerning="yes" embed-file="./fop-fonts/GenAI102.ttf">
<font-triplet name="Gentium Alt" style="italic" weight="normal"/>
<font-triplet name="GentiumAlt" style="italic" weight="normal"/>
</font>
<font metrics-file="./fop-fonts/GenAR102.xml"
kerning="yes" embed-file="./fop-fonts/GenAR102.ttf">
<font-triplet name="Gentium Alt" style="normal" weight="normal"/>
<font-triplet name="GentiumAlt" style="normal" weight="normal"/>
</font>
</fonts>
</configuration>