Apache FOP 中的印度语字体支持 [英] Indic font support in 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>
结果:से 显示为这样 स े,如此屏幕截图所示
情况 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>
结果:案例 1 中列出的问题已解决,但我面临另一个问题,如下面的屏幕截图所示
<小时>您可以在链接
如果我理解正确的话,您要实现的输出是带有 script="deva"
的输出.
请注意,您的配置中不需要 metrics-url
属性.
此外,将 <complex-scripts disabled="true"/>
放在您的配置中具有禁用复杂脚本"支持的效果,所以我预计这会产生错误输出.
这个配置
<fop version="1.0"><complex-scripts disabled="true"/><渲染器><renderer mime="application/pdf"><字体><font kerning="yes" embed-url="Amiko/Amiko-Regular.ttf"><font-triplet name="Amiko" style="normal" weight="normal"/></字体></渲染器></渲染器></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屋!