【问题标题】:Apache FOP | custom fonts | relative URL not working阿帕奇 FOP |自定义字体 |相对 URL 不起作用
【发布时间】:2016-02-04 08:14:41
【问题描述】:

我有配置文件来为 Apache FOP 加载自定义字体。我正在努力在服务器上配置 embed-url,以便字体 url 根据服务器域进行更改。

我已尝试将 embed-url 属性值设为:

嵌入网址无效:

  • embed-url="context:/etc/designs/projectName/clientlibs/pdffonts/Batang.ttf"
  • embed-url="file:/etc/designs/projectName/clientlibs/pdffonts/Batang.ttf"

工作嵌入网址:

  • embed-url="http://localhost:4503/etc/designs/projectName/clientlibs/pdffonts/Batang.ttf"

不知何故,我似乎在这里找不到合适的语法。我在 AEM 6.0 中使用 FOP。

<?xml version="1.0"?>
<fop version="1.0">
    <renderers>
        <renderer mime="application/pdf">
            <fonts>
                <font kerning="yes"
                    embed-url="context:/etc/designs/projectName/clientlibs/pdffonts/Batang.ttf" -- this doesn't
                    embedding-mode="subset">
                    <font-triplet name="SimSun" style="normal" weight="normal" />
                </font>
                <font kerning="yes"
                    embed-url="file:/etc/designs/projectName/clientlibs/pdffonts/Batang.ttf" -- this doesn't
                    embedding-mode="subset">
                    <font-triplet name="Batang" style="normal" weight="normal" />
                </font>
                <font kerning="yes"
                    embed-url="http://localhost:4503/etc/designs/projectName/clientlibs/pdffonts/Batang.ttf" -- this works
                    embedding-mode="subset">
                    <font-triplet name="Batang" style="normal" weight="normal" />
                </font>
            </fonts>
        </renderer>
    </renderers>
</fop>

【问题讨论】:

  • 在使用 AEM 时,我最终会为每个运行模式的 Apache FOP 创建多个配置文件。这符合我的要求,但我想必须有更好的方法来做到这一点。
  • 是否可以将一个配置导入另一个?我需要在每个配置中使用相同的字体,但需要不同的 pdf-x-mode 设置。有什么想法吗?

标签: aem apache-fop


【解决方案1】:

相对路径的“起点”:

  • 如果配置文件有 font-base 元素(作为文档根元素的直接子元素),则其值用于解析相对字体路径
  • 否则,将使用 base 元素的值
  • 发行版中包含的默认配置文件具有元素&lt;base&gt;.&lt;/base&gt;,这意味着必须将相对路径解释为相对于配置文件的位置

注意font-basebase 的值也可以是相对的,在这种情况下它们指的是配置文件路径。

<?xml version="1.0"?>
<fop version="1.0">

  <base>.</base>

  <font-base>/Users/lfurini/Library/Fonts</font-base>
  <!-- other possible examples:
  <font-base>.</font-base>
  <font-base>../fonts</font-base>
  --> 

  <!-- ... -->
</fop>

相对路径语法:

  • 你不需要context:file:
  • 如果embed-url/ 开头,则为绝对路径,否则为相对路径,指的是之前定义的“起点”
  • 如果需要,相对路径可以包含 ../ 以返回文件夹层次结构

    <!-- directly in the base folder -->
    <font kerning="yes" embed-url="font1.ttf">
      <font-triplet name="font1" style="normal" weight="normal"/>
    </font>
    
    <!-- in a "sister" folder -->
    <font kerning="yes" embed-url="../otherFonts/font2.ttf">
      <font-triplet name="font2" style="normal" weight="normal"/>
    </font>
    
    <!-- in a sub-folder -->
    <font kerning="yes" embed-url="specialFonts/font3.ttf">
      <font-triplet name="font3" style="normal" weight="normal"/>
    </font>
    
    <!-- absolute path -->
    <font kerning="yes" embed-url="/Users/lfurini/Library/Fonts/font4.ttf" embedding-mode="subset">
      <font-triplet name="font4" style="normal" weight="normal"/>
    </font>
    

(使用 FOP 1.1、2.0 和 2.1 测试)

(披露:我是一名 FOP 开发人员,虽然现在不是很活跃)

【讨论】:

  • 但它不是相对路径,而是硬编码路径。相对是当您使用整个应用程序的 contextPath 时。您的解决方案“与可移植性冲突”。
【解决方案2】:

我通过从代码添加到应用程序的完整路径来解决它。并从配置文件中添加了以后的 patr。

fopFactory.setBaseURL(this.getServletContext().getInitParameter("my_path"));

在配置中

embed-url="fonts/newfont.ttf"

【讨论】:

    【解决方案3】:

    对于 FOP-2.1,https://issues.apache.org/jira/browse/FOP-2627 有一个“允许字体文件/目录的相对路径”补丁。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-16
      • 2016-11-03
      • 2015-04-05
      • 1970-01-01
      • 2012-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多