gpt4 book ai didi

java - 带有 itext 的 OpenType 字体字距调整

转载 作者:行者123 更新时间:2023-11-30 11:50:36 29 4
gpt4 key购买 nike

我正在使用 itext 和 ColdFusion (java) 将文本字符串写入 PDF 文档。我有需要使用的 trueType 和 openType 字体。 Truetype 字体似乎工作正常,但字距调整未用于任何以 .otf 结尾的字体文件。下面的代码在 Airstream (OpenType) 中写入“文本的第 1 行”,但缺少“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>

最佳答案

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

我查看了源代码,IText 实现仅检查 truetype 字体的紧排,根本不读取 GPOS 表,因此内部紧排必须为空,并且 hasKernPairs 必须返回 false。

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

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

关于java - 带有 itext 的 OpenType 字体字距调整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7880714/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com