1
votes

Suppose I'm creating a PDF file using Apache FOP. All the characters in the PDF should be Times New Roman Italic. Since there are no such font in my system, Apache FOP will try to find the font in /data/fonts, which is set by fop.xconf.

<directory>/data/fonts</directory>

However, there's only one file in /data/fonts, which is Times New Roman Regular.ttf. Yes, no Times New Roman Italic.ttf and no Times New Roman Bold.ttf.

ls /data/fonts 
'Times New Roman Regular.ttf'

In this case, Apache FOP reported that it couldn't find Times New Roman Italic font, and it fell back to the default font, which was not Times New Roman and not italic either.

I can solve the problem by putting Times New Roman Italic.ttf in /data/fonts, but what if I don't have a specific italic/bold version of that font? AFAIK some fonts don't have specific bold/italic versions at all. Is it possible for Apache FOP to create the italic/bold style from the regular font automatically, even if the result is not as good as the specific italic/bold font?

1

1 Answers

2
votes

If you are using FOP version 2.2, there is a configuration option that enables the automatic creation of simulated italic and bold glyphs: simulate-style.

This example maps the four combinations of style and weight to the same TrueType font, emboldening and slanting the glyphs when needed:

<font kerning="yes" embed-url="Times.ttf" simulate-style="true">
  <font-triplet name="Times" style="normal" weight="normal"/>
  <font-triplet name="Times" style="italic" weight="normal"/>
  <font-triplet name="Times" style="normal" weight="bold"/>
  <font-triplet name="Times" style="italic" weight="bold"/>
</font>

Note that it's important to register all the different font-triplet elements; if you have only <font-triplet name="Times" style="normal" weight="normal"/> the font substitution mechanism will first map bold, italic and bold-italic to the registered normal variant, and then FOP will simulate the styles (doing nothing).