为什么使用 Arial Unicode MS 无法正确呈现古吉拉特语-印度文本?
Why is the Gujarati-Indian text not rendered correctly using Arial Unicode MS?
这是这个问题 How to export fonts in Gujarati-Indian Language to pdf?, @amedee-van-gasse, QA Engineer at iText asked me 到 post 一个特定于具有相关 mcve 的 itext 的问题的跟进。
为什么这个 unicode 序列 \u0ab9\u0abf\u0aaa\u0acd\u0ab8
没有正确呈现?
应该这样渲染:
હિપ્સ ,也用 unicode-converter
进行了测试
然而此代码(示例改编形式iText: Chapter 11: Choosing the right font)
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);
}
}
生成这个结果:
看起来和
不一样
હિપ્સ
我用 itextpdf-5.5.4.jar
、itextpdf-5.5.9.jar
和 itext-2.1.7.js3.jar
进行了测试(与 jasper-reports 一起分发)
使用它的字体与 MS Office ARIALUNI.TTF
一起分发,可以从这里下载 Arial Unicode MS *下载时可能存在一些法律问题,请参阅 Mike 'Pomax' 卡默曼的评论
iText5 和 iText2(顺便说一句,这是一个非常过时的版本)都不支持印度文字的呈现,无论您使用哪种字体 select。
呈现印度语脚本与任何拉丁语脚本都不相似,因为需要采取一系列额外的操作才能获得正确的结果,例如根据语言规则,部分字符需要先重新排序。
这是 iText 公司的已知问题。
在 iText5 中有一个名为 GujaratiLigaturizer 的 Gujaranti 存根实现,但该实现非常差,您不能指望用它获得正确的结果。
您可以尝试使用此连字器处理您的字符串,然后按以下方式输出结果字符串:
IndicLigaturizer g = new GujaratiLigaturizer();
String processed = g.process(inputString);
// proceed with the processed string
使用最新的排版 jar 文件构建您的应用程序
将解决您在 pdf 中呈现古吉拉特语字体的问题
在 itext.
这是这个问题 How to export fonts in Gujarati-Indian Language to pdf?, @amedee-van-gasse, QA Engineer at iText asked me 到 post 一个特定于具有相关 mcve 的 itext 的问题的跟进。
为什么这个 unicode 序列 \u0ab9\u0abf\u0aaa\u0acd\u0ab8
没有正确呈现?
应该这样渲染:
હિપ્સ ,也用 unicode-converter
进行了测试然而此代码(示例改编形式iText: Chapter 11: Choosing the right font)
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);
}
}
生成这个结果:
看起来和
不一样હિપ્સ
我用 itextpdf-5.5.4.jar
、itextpdf-5.5.9.jar
和 itext-2.1.7.js3.jar
进行了测试(与 jasper-reports 一起分发)
使用它的字体与 MS Office ARIALUNI.TTF
一起分发,可以从这里下载 Arial Unicode MS *下载时可能存在一些法律问题,请参阅 Mike 'Pomax' 卡默曼的评论
iText5 和 iText2(顺便说一句,这是一个非常过时的版本)都不支持印度文字的呈现,无论您使用哪种字体 select。
呈现印度语脚本与任何拉丁语脚本都不相似,因为需要采取一系列额外的操作才能获得正确的结果,例如根据语言规则,部分字符需要先重新排序。
这是 iText 公司的已知问题。
在 iText5 中有一个名为 GujaratiLigaturizer 的 Gujaranti 存根实现,但该实现非常差,您不能指望用它获得正确的结果。
您可以尝试使用此连字器处理您的字符串,然后按以下方式输出结果字符串:
IndicLigaturizer g = new GujaratiLigaturizer();
String processed = g.process(inputString);
// proceed with the processed string
使用最新的排版 jar 文件构建您的应用程序 将解决您在 pdf 中呈现古吉拉特语字体的问题 在 itext.