2.4. FOP相关注意事项

2.4.1. FOP的字体设置

关于FOP的字体的设置,对于最新版本的1.0的FOP来说,其设置很简单,参考官网的解释:Apache™ FOP: Fonts - Custom Fonts,只需要在配置文件fop.xconf中的renderers→renderer→fonts中,添加如下内容即可。


        <directory recursive="true">file:///c:/windows/fonts/</directory>
        <auto-detect/>

            

而与此相比,之前旧版本的FOP对于字体的设置,则相对比较繁琐,因为除了要用对应的命令去生成字体文件所对应的Metric文件之外,还要把相关配置添加到上述fop.xconf中去。

打开windows下面的cmd,然后切换到对应的fop的根目录,执行下面的命令:

java -cp build\fop.jar;lib\avalon-framework-4.2.0.jar;lib\commons-logging-1.0.4.jar;lib\commons-io-1.3.1.jar;lib\xmlgraphics-commons-1.4.jar org.apache.fop.fonts.apps.TTFReader -ttcname SimHei C:\Windows\Fonts\simhei.ttf fonts\simhei.xml

java -cp build\fop.jar;lib\avalon-framework-4.2.0.jar;lib\commons-logging-1.0.4.jar;lib\commons-io-1.3.1.jar;lib\xmlgraphics-commons-1.4.jar org.apache.fop.fonts.apps.TTFReader -ttcname msyh C:\Windows\Fonts\msyh.ttf fonts\msyh.xml

java -cp build\fop.jar;lib\avalon-framework-4.2.0.jar;lib\commons-logging-1.0.4.jar;lib\commons-io-1.3.1.jar;lib\xmlgraphics-commons-1.4.jar org.apache.fop.fonts.apps.TTFReader -ttcname msyhbd C:\Windows\Fonts\msyhbd.ttf fonts\msyhbd.xml
            

就可以生成相应的字体的XML Metrics文件了,然后再把相应的如下的设置:


        <font metrics-url="E:\Dev_Root\docbook\dev\config\fop\fonts\simhei.xml" kerning="yes" embed-url="C:\Windows\Fonts\simhei.ttf">
            <font-triplet name="SimHei" style="normal" weight="normal"/>
            <font-triplet name="SimHei" style="normal" weight="bold"/>
            <font-triplet name="SimHei" style="italic" weight="normal"/>
            <font-triplet name="SimHei" style="italic" weight="bold"/>
        </font>

        <font metrics-url="E:\Dev_Root\docbook\dev\config\fop\fonts\msyh.xml" kerning="yes" embed-url="C:\Windows\Fonts\msyh.ttf">
          <font-triplet name="msyh" style="normal" weight="normal"/>
          <font-triplet name="msyh" style="normal" weight="bold"/>
          <font-triplet name="msyh" style="italic" weight="normal"/>
          <font-triplet name="msyh" style="italic" weight="bold"/>
        </font>
        
        <font metrics-url="E:\Dev_Root\docbook\dev\config\fop\fonts\msyhbd.xml" kerning="yes" embed-url="C:\Windows\Fonts\msyhbd.ttf">
          <font-triplet name="msyhbd" style="normal" weight="normal"/>
          <font-triplet name="msyhbd" style="normal" weight="bold"/>
          <font-triplet name="msyhbd" style="italic" weight="normal"/>
          <font-triplet name="msyhbd" style="italic" weight="bold"/>
        </font>

        <directory recursive="true">file:///c:/windows/fonts/</directory>
        <auto-detect/>

            

添加到fop.xconf中去。