Martin Mirchev created PDFBOX-6343:
--------------------------------------

             Summary: Text extraction turns supplementary characters into BMP 
characters when a Type0 font has no ToUnicode CMap
                 Key: PDFBOX-6343
                 URL: https://issues.apache.org/jira/browse/PDFBOX-6343
             Project: PDFBox
          Issue Type: Bug
          Components: PDModel, Text extraction
    Affects Versions: 4.0.0, 3.0.8 PDFBox
            Reporter: Martin Mirchev
         Attachments: nonbmp-no-tounicode.pdf, type0-tounicode-non-bmp.patch

Without a usable ToUnicode CMap, {{PDType0Font.toUnicode(int)}} gets the 
Unicode value from the embedded TrueType font's cmap (PDFBOX-5324), but casts 
it to {{char}}:
{code:java}
return Character.toString((char) (int) codes.get(0));
{code}
A cmap (format 12) can map a glyph to a supplementary character, which is then 
truncated to 16 bits. In the attached {{nonbmp-no-tounicode.pdf}} (DejaVu Sans, 
fully embedded, the text "A" U+1F600 "B", ToUnicode removed), 
{{PDFTextStripper}} returns U+0041 U+F600 U+0042 instead of U+0041 U+1F600 
U+0042. With the ToUnicode CMap still in place the text is extracted correctly.

{{new String(Character.toChars(codes.get(0)))}} fixes it (attached patch); the 
font and text tests pass with it.

This issue was found by an LLM-assisted tool and verified manually.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to