pdfbox-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Philip Helger (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (PDFBOX-3150) IllegalArgumentException in getStringWidth/showText
Date Thu, 03 Dec 2015 21:07:11 GMT

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

Philip Helger commented on PDFBOX-3150:
---------------------------------------

I fully agree with you, that \n is the worst example. In my case I had it with \u2193 in font
OpenSans (I think it was the down arrow). But questioning each character before printing is
very time consuming.... Especially since PDFBox 2 is already in certain cases much slower
than 1.8.x (see e.g. PDFBOX-3151).

> IllegalArgumentException in getStringWidth/showText
> ---------------------------------------------------
>
>                 Key: PDFBOX-3150
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-3150
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 2.0.0
>         Environment: 2.0.0-RC2
>            Reporter: Philip Helger
>            Assignee: John Hewson
>
> I want to get the string width using a Type0 font. Because I'm using a character not
in the font (e.g. '\n') I'm getting the following exception:
> {code}
> Exception in thread "main" java.lang.IllegalArgumentException: No glyph for U+000A in
font OpenSans
> 	at org.apache.pdfbox.pdmodel.font.PDCIDFontType2.encode(PDCIDFontType2.java:401)
> 	at org.apache.pdfbox.pdmodel.font.PDType0Font.encode(PDType0Font.java:351)
> 	at org.apache.pdfbox.pdmodel.font.PDFont.encode(PDFont.java:283)
> 	at org.apache.pdfbox.pdmodel.font.PDFont.getStringWidth(PDFont.java:312)
> {code}
> As this is a quite common scenario, I suggest you provide a possibility to provide a
fallback codepoint that can be used for all non-printable characters.
> A similiar exception happens when trying to print the text via the PDPageContentStream:
> {code}
> Exception in thread "main" java.lang.IllegalArgumentException: No glyph for U+000A in
font OpenSans
> 	at org.apache.pdfbox.pdmodel.font.PDCIDFontType2.encode(PDCIDFontType2.java:401)
> 	at org.apache.pdfbox.pdmodel.font.PDType0Font.encode(PDType0Font.java:351)
> 	at org.apache.pdfbox.pdmodel.font.PDFont.encode(PDFont.java:283)
> 	at org.apache.pdfbox.pdmodel.PDPageContentStream.showText(PDPageContentStream.java:341)
> {code}
> I finally ended up creating my own "font.encode" method (with a lot of other hacks) that
basically does the following:
> {code}
>    final byte [] aFallbackBytes = aFont.encode (nFallbackCodepoint);
>        byte [] aCPBytes;
>       try
>       {
>         // This method is package private
>         aCPBytes = aFont.encode (nCP);
>       }
>       catch (final IllegalArgumentException ex) {
>         aCPBytes = aFallbackBytes;
>       }
> {code}
> -> another issue is, that "PDFont.encode (int)" is not public - it would help to change
this as well. Shall I create a separate issue?



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org


Mime
View raw message