假设我正在使用Apache FOP创建PDF文件。 PDF中的所有字符均应为Times New Roman Italic。由于我的系统中没有这样的字体,因此Apache FOP将尝试在/ data / fonts中查找由fop.xconf设置的字体。

<directory>/data/fonts</directory>


但是,/ data / fonts中只有一个文件,即Times New Roman Regular.ttf。是的,没有Times New Roman Italic.ttf,也没有Times New Roman Bold.ttf

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


在这种情况下,Apache FOP报告它找不到Times New Roman Italic字体,并且回退到默认字体,该字体也不是Times New Roman也不是斜体。

我可以通过将Times New Roman Italic.ttf放在/ data / fonts中来解决该问题,但是如果我没有该字体的特定斜体/粗体字体怎么办? AFAIK有些字体根本没有特定的粗体/斜体版本。即使结果不如特定的斜体/粗体字样,Apache FOP是否可以从常规字体自动创建斜体/粗体字样?

最佳答案

如果使用的是FOP 2.2版,则有一个配置选项可以自动创建模拟的斜体和粗体字形:simulate-style

本示例将styleweight的四种组合映射到相同的TrueType字体,并在需要时加粗和倾斜字形:

<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>


注意,注册所有不同的font-triplet元素很重要;如果只有<font-triplet name="Times" style="normal" weight="normal"/>,则字体替换机制将首先将粗体,斜体和粗斜体映射到已注册的普通变体,然后FOP将模拟样式(不执行任何操作)。

09-05 15:15
查看更多