为什么使用Arial Unicode MS无法正确呈现Gujarati-Indian文本?

这是关于如何将古吉拉特语 – 印度语中的字体导出为pdf的后续问题? , @ amedee-van-gasse ,iText的质量保证工程师让我用相关的mcve发布一个特定于itext的问题。

为什么这个unicode序列\u0ab9\u0abf\u0aaa\u0acd\u0ab8无法正确呈现?

它应该像这样呈现:

હિપ્સ,也用unicode转换器测试过

但是这段代码 (示例改编自iText:第11章:选择正确的字体 )

 public class FontTest { /** The resulting PDF file. */ public static final String RESULT = "fontTest.pdf"; /** the text to render. */ public static final String TEST = "\u0ab9\u0abf\u0aaa\u0acd\u0ab8"; public void createPdf(String filename) throws IOException, DocumentException { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); document.open(); BaseFont bf = BaseFont.createFont( "ARIALUNI.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font font = new Font(bf, 20); ColumnText column = new ColumnText(writer.getDirectContent()); column.setSimpleColumn(36, 730, 569, 36); column.addElement(new Paragraph(TEST, font)); column.go(); document.close(); System.out.println("DONE"); } public static void main(String[] args) throws IOException, DocumentException { new FontTest().createPdf(RESULT); } } 

生成此结果

pdf输出

那看起来与众不同

હિપ્સ

我测试了itextpdf-5.5.4.jaritextpdf-5.5.9.jar以及itext-2.1.7.js3.jar (与jasper-reports一起发布)

使用它的字体与MS Office ARIALUNI.TTF分发,可以从这里下载Arial Unicode MS *也许有一些法律问题下载看Mike’Pomax’Kamermans评论

无论您选择哪种字体,iText5和iText2(顺便说一下,它都是非常过时的版本)都不支持Matrix脚本的渲染。

渲染印度语脚本与任何拉丁文脚本都不相似,因为应该采取一系列额外的操作来获得正确的结果,例如,某些字符需要首先根据语言规则重新排序。

这是iText公司的一个已知问题。

在iText5中有一个名为GujaratiLigaturizer的Gujaranti的存根实现,但实现真的很差,你不能指望用它获得正确的结果。

您可以尝试使用此ligaturizer处理字符串,然后按以下方式输出结果字符串:

 IndicLigaturizer g = new GujaratiLigaturizer(); String processed = g.process(inputString); // proceed with the processed string