作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在我的 PDFBox 实现中,我创建了通过测试不同字体以多种语言编写字符串的方法。
PDFont currentFont = PDType0Font.load(pdfDocument, new File("path/to/font/font.ttf"));
for (int offset = 0; offset < sValue.length();) {
int iCodePoint = sValue.codePointAt(offset);
boolean isEncodable = isCodePointEncodable(currentFont, iCodePoint);
//-Further logic here, etc.
offset += Character.charCount(iCodePoint);
}
private boolean isCodePointEncodable (PDFont currentFont, int iCodePoint) throws IOException {
StringBuilder st = new StringBuilder();
st.appendCodePoint(iCodePoint);
try {
currentFont.encode(st.toString());
return true;
} catch (IllegalArgumentException iae) {
return false;
}
}
虽然这适用于基本多语言平面 (BMP) 中的任何内容,但涉及 BMP 之外的 unicode 的任何内容都将无效。我已经下载并使用字形图表广泛查看了涉及的字体,并记录了每个代码。例如,当尝试对 🚁 进行编码时,它是 U+1F681(或十进制的 128641),我跟踪了日志记录,发现它专门尝试在 NotoEmoji-Regular.ttf 中对这个字符进行编码。 ,这是正确的匹配,确实有这个字符。不幸的是,它仍然返回 false。
具体来说,我的日志服务器返回了这个:
Code Point 128641 (🚁) cannot be encoded in font NotoEmoji
是否有任何解决方法或解决方案?谢谢。
最佳答案
我已经创建并解决了问题 PDFBOX-3997 .原因是我们没有使用最好的 cmap 子表。
没有解决方法,但该错误将在几个月后发布的 2.0.9 版中得到修复。但是您不必等待那么久 - 您可以使用 snapshot build 进行测试.
关于java - PDFBox - 无法编码由代理项对组成的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47141783/
我有一个项目存储在 HttpContext 中: HttpContext.Current.Items["myItem"] = "123"; 我可以从任何页面的方法访问这个没有问题。例如: protec
我是一名优秀的程序员,十分优秀!