gpt4 book ai didi

java - PDFBox - 无法编码由代理项对组成的字符串

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:48:54 24 4
gpt4 key购买 nike

在我的 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/

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