Apache FOP中的印度字体支持 [英] Indic font support in Apache FOP

查看:194
本文介绍了Apache FOP中的印度字体支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Java应用程序中使用Apache FOP 2.2通过使用mangal.ttf打印PDF中的印地语字符串时,某些印地语字符未正确显示.
我正在使用JDK 1.8和spring MVC.

我尝试过lohit.ttf,devanagari.ttf,aparajita.ttf和kokila.ttf,但都遇到相同的问题.

情况1:

按如下所示设置fop-conf.xml时:

<font kerning="yes"    embed-url="classpath:/mangal.ttf"   >
<font-triplet name="Mangal" style="normal" weight="normal"></font-triplet>
</font>   

结果:screenshot像这样显示से,如屏幕截图所示

情况2:

按如下所示设置fop-conf.xml时:

<font kerning="yes"   metrics-url="classpath:/mangal.xml" embed-url="classpath:/mangal.ttf"   >
<font-triplet name="Mangal" style="normal" weight="normal"></font-triplet>
</font>

结果:案例1中列出的问题已解决,但我正面临另一个问题,如以下屏幕截图所示


您可以在链接 https://www.fonts上看到预期的输出. com/font/microsoft-corporation/aparajita ),使用以下示例文本:

से and ग्रामीण should be printed in pdf

我尝试过的其他事情:

  • 我尝试了 PDFOne 来生成PDF.还是同样的问题. Windows似乎可以正确显示它.
  • 配置复杂脚本:<fop version="1.0"> <complex-scripts disabled="true"/> ... </fop>
  • 使用script属性:<fo:block font-family="ARIALUNI" script="dev2" > देवी ग्रामीण</fo:block>

我缺少FOP中的任何配置设置吗?

解决方案

更粗略的回答:

如果配置了字体但输出不正确,则可能是FOP错误地确定要使用哪种脚本模式.

解决方案:明确设置使用 standard 扩展脚本代码.
请注意,印度脚本同时具有标准代码和扩展代码(例如,对于Devanagari,为devadev2),并且结果输出是不同的,因此您可能需要尝试两者并选择合适的人.

更长的答案:

我没有您提到的字体,因此我使用了 Amiko 进行了测试. Google Open字体.
更重要的是,我对devanagari脚本一无所知,所以我真的不能说输出是正确还是错误,我只能将其与您的图像进行比较.

这是我使用的完整的输入文件,其中的句子是从您的问题中复制来的:

<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="simpleA4" page-height="29.7cm" page-width="21cm" margin-top="2cm" margin-bottom="2cm" margin-left="2cm" margin-right="2cm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="simpleA4">
    <fo:flow flow-name="xsl-region-body">
      <fo:block font-family="Amiko" script="deva">deva: से and ग्रामीण should be printed in pdf</fo:block>
      <fo:block font-family="Amiko" script="dev2">dev2: से and ग्रामीण should be printed in pdf</fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>

这是最小的配置:

<?xml version="1.0"?>
<fop version="1.0">
  <renderers>
    <renderer mime="application/pdf">
      <fonts>
        <font kerning="yes" embed-url="Amiko/Amiko-Regular.ttf">
          <font-triplet name="Amiko" style="normal" weight="normal"/>
        </font>
      </fonts>
    </renderer>
  </renderers>
</fop>

产生此输出:

如果我理解正确,那么您尝试实现的输出就是使用script="deva"的输出.


请注意,您的配置中不需要metrics-url属性.

此外,将<complex-scripts disabled="true"/>放入您的配置中会导致禁用复杂脚本"支持,因此我希望这会产生错误输出.

配置

<?xml version="1.0"?>
<fop version="1.0">
  <complex-scripts disabled="true"/>
  <renderers>
    <renderer mime="application/pdf">
      <fonts>
        <font kerning="yes" embed-url="Amiko/Amiko-Regular.ttf">
          <font-triplet name="Amiko" style="normal" weight="normal"/>
        </font>
      </fonts>
    </renderer>
  </renderers>
</fop>

产生以下输出:

While using Apache FOP 2.2 from my Java application to print Hindi strings in PDF by using mangal.ttf, some Hindi characters are not displayed correctly.
I am Using JDK 1.8 and spring MVC.

I tried lohit.ttf, devanagari.ttf, aparajita.ttf and kokila.ttf but all have the same issue.

case 1:

When fop-conf.xml is set as below:

<font kerning="yes"    embed-url="classpath:/mangal.ttf"   >
<font-triplet name="Mangal" style="normal" weight="normal"></font-triplet>
</font>   

Result: से is shown like this स े, as shown in this screenshot

case 2:

When fop-conf.xml is set as below:

<font kerning="yes"   metrics-url="classpath:/mangal.xml" embed-url="classpath:/mangal.ttf"   >
<font-triplet name="Mangal" style="normal" weight="normal"></font-triplet>
</font>

Result: problem listed in case 1 is resolved but I am facing another issue attached as shown in the following screenshot


You can see the expected output at the link https://www.fonts.com/font/microsoft-corporation/aparajita) using this sample text:

से and ग्रामीण should be printed in pdf

Other things I tried:

  • I tried PDFOne to generate the PDF. Yet the same issue. Windows however seems to show it correctly.
  • configuring complex-script: <fop version="1.0"> <complex-scripts disabled="true"/> ... </fop>
  • using the script attribute: <fo:block font-family="ARIALUNI" script="dev2" > देवी ग्रामीण</fo:block>

Is there any configuration setting in FOP that I am missing?

解决方案

Shorter, general answer:

If the font is configured but the output is not correct, the problem could be FOP incorrectly determining which script mode to use.

Solution: explicitly set the script property in the FO file, using either a standard or an extended script code.
Note that Indic scripts have both a standard code and an extended one (for example deva and dev2 for Devanagari) and the resulting output is different, so you may need to try them both and choose the appropriate one.

Longer answer:

I don't have the fonts you mention available, so I tested using the Amiko Google Open Font.
More importantly, I know nothing about devanagari script, so I really cannot say whether the output is right or wrong, I can only compare it with your images.

This is the complete input file I used, with the sentence copied from your question:

<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="simpleA4" page-height="29.7cm" page-width="21cm" margin-top="2cm" margin-bottom="2cm" margin-left="2cm" margin-right="2cm">
      <fo:region-body/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="simpleA4">
    <fo:flow flow-name="xsl-region-body">
      <fo:block font-family="Amiko" script="deva">deva: से and ग्रामीण should be printed in pdf</fo:block>
      <fo:block font-family="Amiko" script="dev2">dev2: से and ग्रामीण should be printed in pdf</fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>

Here is a minimal configuration:

<?xml version="1.0"?>
<fop version="1.0">
  <renderers>
    <renderer mime="application/pdf">
      <fonts>
        <font kerning="yes" embed-url="Amiko/Amiko-Regular.ttf">
          <font-triplet name="Amiko" style="normal" weight="normal"/>
        </font>
      </fonts>
    </renderer>
  </renderers>
</fop>

which produces this output:

If I understand correctly, the output you are trying to achieve is the one with script="deva".


Note that the metrics-url attribute in your configuration is not needed.

Moreover, putting <complex-scripts disabled="true"/> in your configuration has the effect of disabling the "complex script" support, so I expect this to produce the wrong output.

This configuration

<?xml version="1.0"?>
<fop version="1.0">
  <complex-scripts disabled="true"/>
  <renderers>
    <renderer mime="application/pdf">
      <fonts>
        <font kerning="yes" embed-url="Amiko/Amiko-Regular.ttf">
          <font-triplet name="Amiko" style="normal" weight="normal"/>
        </font>
      </fonts>
    </renderer>
  </renderers>
</fop>

produces the following output:

这篇关于Apache FOP中的印度字体支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆