使用fop

时间:2017-12-28 12:18:51

标签: fonts xsl-fo apache-fop

我在.fonts/Dinarra/文件夹中有文件Dinarra LT Std-Roman.otfDinarra LT Std-Italic.otf

fop.xconf中的字体配置如下:

<renderer mime="application/pdf">
  ...
  <fonts>
    ...
    <font kerning="yes" embed-url="'~/.fonts/Dinarra/DinarraLTStd-Roman.otf'" embedding-mode="subset">
      <font-triplet name="'Dinarra LT Std'" style="normal" weight="normal"/>
    </font>

    <font kerning="yes" embed-url="'~/.fonts/Dinarra/DinarraLTStd-Roman.otf'" embedding-mode="subset">
      <font-triplet name="'Dinarra LT Std'" style="normal" weight="bold"/>
    </font>

    <font kerning="yes" embed-url="'~/.fonts/Dinarra/DinarraLTStd-Italic.otf'" embedding-mode="subset">
      <font-triplet name="'Dinarra LT Std'" style="italic" weight="normal"/>
    </font>

    <font kerning="yes" embed-url="'~/.fonts/Dinarra/DinarraLTStd-Italic.otf'" embedding-mode="subset">
      <font-triplet name="'Dinarra LT Std'" style="italic" weight="bold"/>
    </font>

    <auto-detect/>
  </fonts>
</renderer>

我已使用fop -c ~/.fop/fop.xconf在fop中注册了字体。

现在我在文件test.fob中有以下XSL-FO代码:

<fo:static-content flow-name="first-page-before">
  <fo:block font-family="'Dinarra LT Std'" font-size="28pt"
      font-style="normal" font-variant="small-caps">
    <fo:block>S.E. Reverendo</fo:block>
    <fo:block>Gabriele Asperso</fo:block>
  </fo:block>
</fo:static-content>

使用fop -c ~/.fop/fop.xconf -r test.fob test.pdf编译,输出如下:

rev@asp-erso ~/repos/f5qg16 $ fop -c ~/.fop/fop.xconf -r test.fob test.pdf
[warning] /usr/bin/fop: No java runtime was found
[warning] /usr/bin/fop: No java runtime was found
[warning] /usr/bin/fop: No JAVA_CMD set for run_java, falling back to JAVA_CMD = java
[INFO] FopConfParser - Default page-height set to: 11.00in
[INFO] FopConfParser - Default page-width set to: 8.50in
[WARN] FOUserAgent - Border and padding for fo:region-before "first-page-before" should be '0' (See 6.4.14 in XSL 1.1); non-standard values are allowed if relaxed validation is enabled.  (See position 23:68)
[WARN] FOUserAgent - Border and padding for fo:region-after "first-page-after" should be '0' (See 6.4.14 in XSL 1.1); non-standard values are allowed if relaxed validation is enabled.  (See position 25:62)
[INFO] FOUserAgent - Rendered page #1.
[INFO] FOUserAgent - Rendered page #2.

问题是这些块是用斜体字体渲染的,而不是普通字体,而不是小字体。

如果我从字体文件夹中删除文件Dinarra LT Std-Italic.otf,则会按预期呈现块(但不是小型上限),但这样我就不能再使用斜体了。

我的问题是:

  1. 如何在XSL-FO声明中正确设置字体,以便我可以使用普通样式而不删除斜体文件?

  2. 如何设置字体以便获取小型广告代码?

  3. 第2部分:一些实验

    我已经仔细检查过,在任何地方都没有“italic”这个词 宣布static-content;

    之前的测试文件

    我已经三次检查了字体文件路径中的exacteness 档案~/.fop/fop.xconf;

    我删除了文件~/.fop/fop-fonts.cache并修改了文件 ~/.fop/fop.xconf这样:

    <!-- ### deleted some 'font' element -->
    <font kerning="yes"
          embed-url="'~/.fonts/Dinarra/DinarraLTStd-Roman.otf'"
          embedding-mode="subset">
      <font-triplet name="'Dinarra LT Std'"
                    style="normal"
                    weight="normal"/>
    </font>
    
    <font kerning="yes"
          embed-url="'~/.fonts/Dinarra/DinarraLTStd-Italic.otf'"
          embedding-mode="subset">
      <font-triplet name="'Dinarra LT Std'"
                    style="italic"
                    weight="normal"/>
    </font>
    
    <!-- ### commented-out auto-detect-->
    <!-- <auto-detect/> -->
    

    我编译了测试文档,用

    重新注册字体
    fop -c ~/.fop/fop.xconf -r test.fob test.pdf
    

    输出是:

    [warning] /usr/bin/fop: No java runtime was found
    [warning] /usr/bin/fop: No java runtime was found
    [warning] /usr/bin/fop: No JAVA_CMD set for run_java, falling back to JAVA_CMD = java
    [INFO] FopConfParser - Default page-height set to: 11.00in
    [INFO] FopConfParser - Default page-width set to: 8.50in
    [WARN] FOUserAgent - Border and padding for fo:region-before "first-page-before" should be '0' (See 6.4.14 in XSL 1.1); non-standard values are allowed if relaxed validation is enabled.  (See position 23:68)
    [WARN] FOUserAgent - Border and padding for fo:region-after "first-page-after" should be '0' (See 6.4.14 in XSL 1.1); non-standard values are allowed if relaxed validation is enabled.  (See position 25:62)
    [WARN] FOUserAgent - Font "Dinarra LT Std,normal,400" not found. Substituting with "any,normal,400".
    [INFO] FOUserAgent - Rendered page #1.
    [INFO] FOUserAgent - Rendered page #2.
    

    所以(第8行)fop不会伪造字体(!)。

    然后我新删除了文件~/.fop/fop-fonts.cache和 重新启用auto-detect指令,最后重新编译 测试文件。输出为23,175行,其中没有一行包含 单词'Dinarra',也不是'otf'。

    fo:static-content元素的内容仍然是由组成的 用斜体。

    我不知道该怎么想。

1 个答案:

答案 0 :(得分:0)

  

问题是这些块是用斜体字体渲染的,而不是正常的

这可能是字体注册中复制粘贴错误或拼写错误的简单情况。

检查输出中的警告或错误,通知您字体替换;如果没有,请仔细检查您是否将斜体字体文件与斜体样式相关联,并将普通字体文件与正常样式相关联。

  

不是小型的

这个问题既简单又严重:不幸的是FOP does not support font-variant yet