Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#31 Bugfix for width-array of TrueType and AFM-Fonts

closed-accepted
nobody
None
5
2008-05-23
2008-05-20
No

Hi folks,

I've experienced some problems with embedding TrueType and AFM/PFB fonts. In both cases the array with the widths of the characters was incomplete concerning some special characters. The array for afm-fonts has some gaps whenever a character wasn't defined which leads to an Exception when the pdf-document was displayed with PDFReader. And finally there was a problem with german umlauts which weren't defined in the afm-file but were part of the font. Btw. if I use this fonts with postscript everything works fine. So I've added a hack (?!?) based on a code-fragment written by V0JT4 in the pdf-forum (see also https://sourceforge.net/forum/message.php?msg_id=4705274\) for the encoding of AFM-fonts.

I've attached the latest versions of the sorce code

org.pdfbox.pdmodel.font.PDTrueTypeFont (1.17)
org.pdfbox.pdmodel.font.PDType1AfmPfbFont (1.5)

Lehmi

Discussion

  • Daniel Wilson
    Daniel Wilson
    2008-05-21

    Logged In: YES
    user_id=1737686
    Originator: NO

    Andreas, would you please upload one or more PDF's for which your code is the solution?

    I need to see what changes with the inclusion of your code.

    Thanks.

     
  • Logged In: YES
    user_id=2069622
    Originator: YES

    Hi Daniel,

    I'll send you an example on friday, because I'm out of office.

     
  • Samplefiles to demonstrate the problem

     
  • Logged In: YES
    user_id=2069622
    Originator: YES

    File Added: samplefiles_fontpatch.zip

     
  • Logged In: YES
    user_id=2069622
    Originator: YES

    Hi Daniel,

    I've attached the files you asked for.

    n019043l.* : the font I'm using (part of ghostscript)
    test-font_not_patched.pdf : generated without my patch
    test-font_patched.pdf : generated with my patch
    org\pdfbox\examples\pdmodel\AFMPFBFontTest.java : testprogam to generate the pdfs above

    Without my patch:
    - due to the incomplete width-array (it's defined from char 32 to 251, but there are only 149 values) org.pdfbox.PDFReader crashes with the following exception
    Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 196, Size: 149
    at java.util.ArrayList.RangeCheck(ArrayList.java:547)
    at java.util.ArrayList.get(ArrayList.java:322)
    at org.pdfbox.cos.COSArray.getObject(COSArray.java:204)
    at org.pdfbox.pdmodel.font.PDSimpleFont.getFontWidth(PDSimpleFont.java:180)
    at org.pdfbox.util.PDFStreamEngine.showString(PDFStreamEngine.java:352)
    at org.pdfbox.util.operator.ShowText.process(ShowText.java:64)
    at org.pdfbox.util.PDFStreamEngine.processOperator(PDFStreamEngine.java:497)
    at org.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java:218)
    at org.pdfbox.util.PDFStreamEngine.processStream(PDFStreamEngine.java:177)
    at org.pdfbox.pdfviewer.PageDrawer.drawPage(PageDrawer.java:103)
    at org.pdfbox.pdfviewer.PDFPagePanel.paint(PDFPagePanel.java:95)
    ....
    - PDPage.convertToImage throws an exception
    - AcrobatReader works but it doesn' show the german umlauts, due to the missing encoding in the pdf

    With my patch
    - the width-array is defined from 0 to 255, of cause with 256 values. Undefined characters have a width of 250 -> PDFReader now works without an exception
    - the additional DictionaryEncoding leads to an additonal encoding table within the pdf
    - the additional definition of german umlauts in the dictionary solves the problem with the missing umlauts in the Acrobat- and the PDFReader (as it does solve V0JT4's problem with specialcharactes from czech)

    Espacially the part with german umlauts seems to be some kind of dirty hack, but perhaps it'll be usable to fix the problem more globally.

    Hope this helps,
    Andreas

     
  • Daniel Wilson
    Daniel Wilson
    2008-05-23

    Logged In: YES
    user_id=1737686
    Originator: NO

    Pardon a dumb question, but where should I put the n0190431.* files?

    Thanks, Andreas.

    Daniel

     
  • Logged In: YES
    user_id=2069622
    Originator: YES

    There are no dumb questions, only dumb answers. ;-)

    You'll need the font-files if you want to use the little testprogram. It has 2 parameters on the commandline:
    - name incl. path of the pdf-file which is written
    - name incl. path of the afm-fontfile

    Just have a look at the source-code of the testprogram, it's quite simple

    Andreas

     
  • Daniel Wilson
    Daniel Wilson
    2008-05-23

    Logged In: YES
    user_id=1737686
    Originator: NO

    OK ...
    java {all my classpath flags & stuff} org.pdfbox.examples.AFMPFBFontTest c:\Test1.PDF c:\n0190431

    java.io.FileNotFoundException: c:\n0190431

    If I try using an extension:

    java {all my classpath flags & stuff} org.pdfbox.examples.AFMPFBFontTest c:\Test1.PDF c:\n0190431.pfb

    java.io.FileNotFoundException: c:\n0190431.pfb.pfb

    You had it working ... so I must be doing something simple wrong! Can you tell what?

    Thanks.

     
  • Logged In: YES
    user_id=2069622
    Originator: YES

    Hey, Daniel,

    you've tried nearly any iterations, but the right one is the following

    ... org.pdfbox.examples.AFMPFBFontTest c:\Test1.PDF c:\n0190431.afm

    Andreas

     
  • Daniel Wilson
    Daniel Wilson
    2008-05-23

    Logged In: YES
    user_id=1737686
    Originator: NO

    Thanks!

    Works as advertised ... with no adverse effect on tests ...

    Thanks!

     
  • Daniel Wilson
    Daniel Wilson
    2008-05-23

    • status: open --> closed-accepted