[ 
https://issues.apache.org/jira/browse/PDFBOX-6360?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18154605#comment-18154605
 ] 

ASF subversion and git services commented on PDFBOX-6360:
---------------------------------------------------------

Commit 1941186 from Tilman Hausherr in branch 'pdfbox/branches/2.0'
[ https://svn.apache.org/r1941186 ]

PDFBOX-6360: try ISO-8859-1 fallback

> PDType3Font.getCharProc() no longer finds glyphs whose names are not UTF-8 
> (regression in 3.0.8)
> ------------------------------------------------------------------------------------------------
>
>                 Key: PDFBOX-6360
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-6360
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel, Rendering
>    Affects Versions: 3.0.8 PDFBox
>         Environment: PDFBox 3.0.8 (3.0.7 for comparison), OpenJDK 25.0.4.1, 
> macOS 26.6.2 arm64
>            Reporter: Ben Day
>            Priority: Minor
>         Attachments: Type3NonUtf8GlyphName.java, type3-non-utf8-glyph-name.pdf
>
>
> Also posted to the users list: 
> https://lists.apache.org/thread/jm8yhv58j9lm4w7zvvvd0z74ctd4l3hb. As there, 
> the report below was generated by Claude, and I've included it verbatim.
> Since 3.0.8, a Type 3 glyph whose name is not valid UTF-8 is no longer found: 
> {{PDType3Font.getCharProc(code)}} returns null, and the glyph is not 
> rendered. 3.0.7 found and drew the same glyph. It looks like a side effect of 
> PDFBOX-6178, after which {{COSName}} compares names as bytes.
> *Cause.* {{getCharProc}} turns the glyph name into a String and back:
> {code:java}
> String name = getEncoding().getName(code);
> COSStream stream = getCharProcs().getCOSStream(COSName.getPDFName(name));
> {code}
> For the name {{/g#E9}} (bytes 67 E9), {{COSName.getName()}} falls back to 
> ISO-8859-1 and gives "gé". {{COSName.getPDFName("gé")}} encodes that as 
> UTF-8, bytes 67 C3 A9, which is a different name now that names compare as 
> bytes. So the /CharProcs key {{/g#E9}} is never matched. A name that is valid 
> UTF-8 survives the round trip, which is why the control glyph below still 
> works.
> Such a name is valid PDF: ISO 32000 7.3.5 allows any bytes except null in a 
> name, and recommends UTF-8 only where a name is treated as text.
> The same two lines are in {{PDType3Font.getCharProc}} on the 3.0 branch, 
> trunk and the 2.0 branch today, and {{hasGlyph(String)}} looks names up 
> through {{COSName.getPDFName(String)}} in the same way. The 2.0 branch also 
> stores names as bytes, so 2.0.37 is probably affected too; I have not tested 
> it.
> *Reproduction.* Attached:
> * type3-non-utf8-glyph-name.pdf: hand-written, uncompressed, one page. It 
> draws code 65 from two Type 3 fonts, and each glyph is a filled 80 x 80 pt 
> square. F1 names the glyph {{/g#C3#A9}} (UTF-8, the control); F2 names it 
> {{/g#E9}} (not UTF-8). The font dictionaries are otherwise identical.
> * Type3NonUtf8GlyphName.java: uses PDFBox only. It writes 
> type3-non-utf8-glyph-name.pdf (the attached file, byte for byte) to the 
> current directory, then prints what the encoding returns for code 65, whether 
> /CharProcs holds {{COSName.getPDFName()}} of that, what {{getCharProc(65)}} 
> returns, and the dark pixels in each half of the page rendered at 72 dpi.
> {noformat}
> java -Djava.awt.headless=true -cp 
> pdfbox-3.0.8.jar:pdfbox-io-3.0.8.jar:fontbox-3.0.8.jar:commons-logging-1.4.0.jar
>  Type3NonUtf8GlyphName.java
> {noformat}
> On 3.0.7:
> {noformat}
> PDFBox 3.0.7
> F1: encoding names code 65 "g\u00E9"; CharProcs has COSName.getPDFName(that): 
> true; getCharProc(65): found
> F2: encoding names code 65 "g\u00E9"; CharProcs has COSName.getPDFName(that): 
> true; getCharProc(65): found
> rendered dark pixels: left (F1) 6400, right (F2) 6400 (each square is 6400)
> {noformat}
> On 3.0.8:
> {noformat}
> PDFBox 3.0.8
> F1: encoding names code 65 "g\u00E9"; CharProcs has COSName.getPDFName(that): 
> true; getCharProc(65): found
> F2: encoding names code 65 "g\u00E9"; CharProcs has COSName.getPDFName(that): 
> false; getCharProc(65): null
> rendered dark pixels: left (F1) 6400, right (F2) 0 (each square is 6400)
> {noformat}
> *Expected.* Both squares are drawn, as on 3.0.7.
> *Suggested fix.* Look the glyph up by the name object the font's /Encoding 
> /Differences array holds, rather than by its String form. One way would be 
> for {{DictionaryEncoding}} to keep the {{COSName}} for each code, so that 
> {{getCharProc}} can pass it straight to {{getCharProcs().getCOSStream(...)}}. 
> For now we work around it outside PDFBox: we read /Differences ourselves, 
> look the name up in /CharProcs by its bytes, and fall back to {{getCharProc}} 
> when /Differences has no entry for the code.



--
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