私の 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;
}
}
これは、Basic Multilingual Plane (BMP) 内のすべてに対して正常に機能しますが、BMP を超える Unicode を含むものはすべて機能しません。関連するフォントをダウンロードして、グリフ チャートを使用して広範囲に調べ、各コードをログに記録しました。たとえば、 U+1F681 (または 10 進数の 128641) である をエンコードしようとすると、ロギングを追跡したところ、特にこの文字をNotoEmoji-Regular.ttfでエンコードしようとしていることがわかりました。このキャラクター。残念ながら、それでも false が返されました。
具体的には、私のログ サーバーはこれを返しました。
Code Point 128641 () cannot be encoded in font NotoEmoji
これに対する回避策や解決策はありますか? ありがとうございました。