2016-02-04 54 views
4

我有配置文件来为Apache FOP加载自定义字体。我很努力在服务器上配置embed-url,以便根据服务器域改变字体url。Apache FOP |自定义字体|相对URL不起作用

我试图嵌入的URL属性值:

非工作嵌入的URL:

  • 嵌入的URL =“背景:在/ etc /设计/项目名称/ clientlibs/pdffonts/Batang.ttf”
  • 嵌入的URL = “文件:/etc/designs/projectName/clientlibs/pdffonts/Batang.ttf”

义和王嵌入的URL:

  • 嵌入的URL = “HTTP://本地主机:4503的/ etc /设计/项目名称/ clientlibs/pdffonts/Batang.ttf”

不知怎的,我不能似乎在这里找到合适的语法。我正在使用AOP 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> 
+0

正如我在使用AEM时,我最终为Apache FOP的每个运行模式创建了多个配置文件。这符合我的要求,但我想一定有更好的方法来做到这一点。 – Rupesh

回答

3

“起点”为相对路径:

  • 如果配置文件具有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> 

相对路径语法:

  • 你不需要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显影剂,虽然现在不是很活跃)

+0

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