【问题标题】:OpenType font kerning with itext带有 itext 的 OpenType 字体字距调整
【发布时间】:2011-12-14 09:47:29
【问题描述】:

我正在使用 itext 和 ColdFusion (java) 将文本字符串写入 PDF 文档。我有需要使用的 trueType 和 openType 字体。 Truetype 字体似乎工作正常,但字距调整未用于任何以 .otf 结尾的字体文件。下面的代码在 Airstream (OpenType) 中写入“Line 1 of Text”,但缺少“T”和“e”之间的字距。当在其他程序中使用相同的字体时,它具有字距调整。我还下载了更新版本的 itext,但字距调整仍然不起作用。有谁知道如何在 itext 中使用 otf 字体进行字距调整?

<cfscript>
pdfContentByte = createObject("java","com.lowagie.text.pdf.PdfContentByte");
BaseFont= createObject("java","com.lowagie.text.pdf.BaseFont");
bf = BaseFont.createFont("c:\windows\fonts\AirstreamITCStd.otf", "" , BaseFont.EMBEDDED);
document = createobject("java","com.lowagie.text.Document").init();
fileOutput = createObject("java","java.io.FileOutputStream").init("c:\inetpub\test.pdf");
writer = createobject("java","com.lowagie.text.pdf.PdfWriter").getInstance(document,fileOutput);
document.open();    
cb = writer.getDirectContent(); 
cb.beginText();
cb.setFontAndSize(bf, 72);
cb.showTextAlignedKerned(PdfContentByte.ALIGN_LEFT,"Line 1 of Text",0,72,0);
cb.endText();
document.close();

bf.hasKernPairs(); //returns NO
bf.getClass().getName(); //returns "com.lowagie.text.pdf.TrueTypeFont"
</cfscript>

【问题讨论】:

    标签: java coldfusion itext opentype kerning


    【解决方案1】:

    看看这个关于How to use Open Type Fonts in Java 的帖子。 这里声明 java 不支持 otf(甚至 iText 也不支持)。 otf 支持取决于 sdk 版本和操作系统。

    您也可以使用 FontForge 将 otf 转换为 ttf。

    【讨论】:

      【解决方案2】:

      根据所谓的规范:http://www.microsoft.com/typography/otspec/kern.htm “kern”表不支持包含 CFF 轮廓的 OpenType™ 字体,必须使用“GPOS”OpenType 布局表。

      我查看了源码,IText实现只检查了truetype字体的紧缩,根本没有读取GPOS表,所以内部紧缩必须为空,hasKernPairs必须返回false。

      所以,有两种方法可以解决:

      • 摆脱你使用的otf:)
      • 通过读取 GPosition 表来修补 truetypefont
      • 等一下,我正在处理 cff 内容,但 PDF 是我的可选内容:) 但不排除这种可能性:)

      【讨论】:

        猜你喜欢
        • 2016-02-18
        • 2017-01-10
        • 2016-03-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-31
        • 2020-09-16
        • 1970-01-01
        相关资源
        最近更新 更多