valerybokov opened a new pull request, #535: URL: https://github.com/apache/pdfbox/pull/535
**Problem** Filled-in AcroForm field values (account numbers, amounts, names) rendered as garbled or blank CJK text in a real-world bank-receipt PDF where NeedAppearances is set and the AcroForm/DR font (SimSun) is: - not embedded (substituted from the OS), and - declared with a predefined, non-Identity encoding (UniGB-UTF16-H), instead of the usual Identity-H. **Root cause** PDCIDFontType2.encode()'s non-embedded branch always wrote the substituted font's own glyph index as the content-stream code, regardless of the font's declared /Encoding. That's only correct for Identity-H/V, where code == GID by convention. For a Uni...-UTF16-H/Uni...-UCS2-H encoding, the codespace is the raw UTF-16BE Unicode value (verified directly against the UniGB-UTF16-H CMap resource, e.g. <00a4> 167). Writing the substitute font's glyph index there instead produces a code that, once decoded again through the normal CID/Unicode round trip (PDCIDFontType2#codeToGID / PDType0Font#toUnicode), resolves to an unrelated, essentially arbitrary character — hence the garbled/blank text. **Fix** In the non-embedded branch of PDCIDFontType2.encode(), when the font's encoding is a predefined Uni... CMap (and not Identity-*), write the raw Unicode value as the code instead of the substitute font's glyph index, matching what that encoding's codespace actually expects. **Testing** - Reproduced with the two PDFs attached to the JIRA issue; before the fix, filled-in field values render as garbled/wrong CJK characters (or blank, matching the original report on an older PDFBox version). After the fix, both render correctly. - Added PDCIDFontType2SubstituteTest, which encodes a known GB1 character through the actual non-embedded SimSun font from the JIRA fixture and asserts the round trip resolves to the same glyph the substitute font's own Unicode cmap would give directly. Skips (via assumeTrue) if the environment has no suitable CJK substitute font installed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
