Apache FOP | 自定义字体 | 相对URL无法使用

7
我已经获得了配置文件,用于加载Apache FOP的自定义字体。我正在努力在服务器上配置embed-url,以便字体URL根据服务器域更改。
我尝试了以下embed-url属性值:
非工作的embed-urls:
- embed-url="context:/etc/designs/projectName/clientlibs/pdffonts/Batang.ttf" - embed-url="file:/etc/designs/projectName/clientlibs/pdffonts/Batang.ttf"
工作的embed-url:
- 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配置文件。这满足了我的需求,但我想肯定有更好的方法来做到这一点。 - Rupesh
能否将一个配置导入另一个配置?我需要在每个配置中使用相同的字体,但是不同的PDF-X模式设置。有什么想法吗? - Entara
3个回答

6

相对路径的起点:

  • 如果配置文件中有font-base元素(作为文档根元素的直接子元素),则使用其值来解析相对字体路径。
  • 否则,将使用base元素的值代替。
  • 分发包中包含的默认配置文件具有元素<base>.</base>,这意味着应将相对路径解释为相对于配置文件的位置。

请注意,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>

相对路径语法:

  • you don't need context: or file:
  • if the embed-url starts with / it's an absolute path, otherwise it's a relative one referring to the "starting point" defined before
  • relative paths can contain ../ to go back up in the folder hierarchy, if needed

    <!-- 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开发人员,尽管现在不太活跃)


1
但这不是相对路径,而是硬编码路径。相对路径是当您使用整个应用程序的contextPath时。你的解决方案“与可移植性冲突”。 - zond

1

我通过在代码中添加应用程序的完整路径解决了这个问题,并从配置文件中添加了后续路径。

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

在配置中。

embed-url="fonts/newfont.ttf"


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接