有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在ApacheFop中自动创建斜体/粗体字体?

假设我正在使用ApacheFop创建一个PDF文件。PDF中的所有字符都应该是Times New Roman Italic。由于我的系统中没有这样的字体,ApacheFop将尝试在/data/fonts中查找由FOP设置的字体。xconf

<directory>/data/fonts</directory>

但是,/data/font中只有一个文件,即Times New Roman Regular.ttf。是,否Times New Roman Italic.ttf和否Times New Roman Bold.ttf

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

在本例中,ApacheFop报告说它找不到Times New Roman Italic字体,并返回到默认字体,即不是Times New Roman也不是斜体

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


共 (1) 个答案

  1. # 1 楼答案

    如果您使用的是FOP版本2.2,那么有一个配置选项可以自动创建模拟的斜体和粗体字形:^{}

    此示例将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将模拟样式(不做任何操作)