You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Jukka Zitting (JIRA)" <ji...@apache.org> on 2008/08/04 20:08:44 UTC

[jira] Updated: (PDFBOX-355) Bugfix for width-array of TrueType and AFM-Fonts

     [ https://issues.apache.org/jira/browse/PDFBOX-355?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jukka Zitting updated PDFBOX-355:
---------------------------------

    Description: 
[Issue from SourceForge]
http://sourceforge.net/tracker/index.php?func=detail&aid=1967941&group_id=78314&atid=552834

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

http://sourceforge.net/tracker/download.php?group_id=78314&atid=552834&file_id=278416&aid=1967879

[Comment on SourceForge]
Date: 2008-05-21 14:16
Sender: danielwilson
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.
							
[Comment on SourceForge]
Date: 2008-05-21 16:25
Sender: lehmialk
Logged In: YES 
user_id=2069622
Originator: YES

Hi Daniel,

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

[Comment on SourceForge]
Date: 2008-05-23 06:52
Sender: lehmialk
Logged In: YES 
user_id=2069622
Originator: YES

File Added: samplefiles_fontpatch.zip
http://sourceforge.net/tracker/download.php?group_id=78314&atid=552834&file_id=278755&aid=1967941

[Comment on SourceForge]
Date: 2008-05-23 07:12
Sender: lehmialk
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

[Comment on SourceForge]
Date: 2008-05-23 14:09
Sender: danielwilson
Logged In: YES 
user_id=1737686
Originator: NO

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

Thanks, Andreas.

Daniel
							
[Comment on SourceForge]
Date: 2008-05-23 14:27
Sender: lehmialk
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

[Comment on SourceForge]
Date: 2008-05-23 15:03
Sender: danielwilson
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.

[Comment on SourceForge]
Date: 2008-05-23 15:11
Sender: lehmialk
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


  was:
[Issue from SourceForge]
http://sourceforge.net/tracker/index.php?func=detail&aid=1967941&group_id=78314&atid=552834

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

http://sourceforge.net/tracker/download.php?group_id=78314&atid=552834&file_id=278416&aid=1967879




> Bugfix for width-array of TrueType and AFM-Fonts
> ------------------------------------------------
>
>                 Key: PDFBOX-355
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-355
>             Project: PDFBox
>          Issue Type: Bug
>            Reporter: Jukka Zitting
>
> [Issue from SourceForge]
> http://sourceforge.net/tracker/index.php?func=detail&aid=1967941&group_id=78314&atid=552834
> 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
> http://sourceforge.net/tracker/download.php?group_id=78314&atid=552834&file_id=278416&aid=1967879
> [Comment on SourceForge]
> Date: 2008-05-21 14:16
> Sender: danielwilson
> 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.
> 							
> [Comment on SourceForge]
> Date: 2008-05-21 16:25
> Sender: lehmialk
> Logged In: YES 
> user_id=2069622
> Originator: YES
> Hi Daniel,
> I'll send you an example on friday, because I'm out of office.
> [Comment on SourceForge]
> Date: 2008-05-23 06:52
> Sender: lehmialk
> Logged In: YES 
> user_id=2069622
> Originator: YES
> File Added: samplefiles_fontpatch.zip
> http://sourceforge.net/tracker/download.php?group_id=78314&atid=552834&file_id=278755&aid=1967941
> [Comment on SourceForge]
> Date: 2008-05-23 07:12
> Sender: lehmialk
> 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
> [Comment on SourceForge]
> Date: 2008-05-23 14:09
> Sender: danielwilson
> Logged In: YES 
> user_id=1737686
> Originator: NO
> Pardon a dumb question, but where should I put the n0190431.* files?
> Thanks, Andreas.
> Daniel
> 							
> [Comment on SourceForge]
> Date: 2008-05-23 14:27
> Sender: lehmialk
> 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
> [Comment on SourceForge]
> Date: 2008-05-23 15:03
> Sender: danielwilson
> 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.
> [Comment on SourceForge]
> Date: 2008-05-23 15:11
> Sender: lehmialk
> 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

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.