Bug 691103

Summary: CIDFont with atypical FontMatrix get wrong spacing after distilled by pdfwrite
Product: Ghostscript Reporter: Masaki Ushizaka <masaki.ushizaka>
Component: PDF WriterAssignee: Masaki Ushizaka <masaki.ushizaka>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P4    
Version: master   
Hardware: All   
OS: All   
Customer: Word Size: ---
Attachments: Bug691103.ps
Bug691103_2.ps
b691103_b2.patch

Description Masaki Ushizaka 2010-02-11 01:18:03 UTC
Ralph found this during 8.71 release test using Bug687832.pdf.

Procedure:
$ bin/gs -sDEVICE=pdfwrite -o Bug687832.pdf.pdf Bug687832.pdf
$ bin/gs -sDEVICE=png16m -o Bug687832.pdf.pdf.png Bug687832.pdf.pdf

This results large spaced letters in Bug687832.pdf.pdf.png.  Acrobat 9 renders Bug687832.pdf.pdf same 
as gs.
With gs 8.70, this doesn't make wrong output.  With r10602, this resulted 4 times larger spacing, and with 
r10603 (which was a fix for bug #687832), this resulted double spaced letters (same as current).

I am working on reduced and openable test code.
Comment 1 Masaki Ushizaka 2010-02-12 00:33:42 UTC
Fist of all, please forget what I said about r10602 yesterday.  Today r10602 renders exactly same image 
with r10603.   I must have done something wrong yesterday.

Second, I wrote a test code about what I believe the cause of this isssue, which is 2048x2048 grid designed 
CIDFont.  It displayed similar symptom with current head, while it also went wrong even with gs 8.70.  I 
think my code might have discovered another issue.  I will attach that code later, or I may open another bug 
about it.

Last, search-svn-revs (what a nice tool!) told me that this symptom first introduced with r10476.  I will look 
further to find the cause of this issue.
Comment 2 Masaki Ushizaka 2010-02-12 03:10:30 UTC
Created attachment 5947 [details]
Bug691103.ps

Before r10476, pdfwrite converted CIDFont letters in Bug687832.pdf into graphic
objects (not a font).  I think the change in r10476 fixed a problem that had
been covering this problem which have been there for a long time.

So I consider this file must be the simplest case to exhibit this issue.

Procedure to reproduce:
$ bin/gs -sDEVICE=pdfwrite -o Bug691103.ps.pdf Bug691103.ps
$ bin/gs -sDEVICE=pngmono -o Bug691103.ps.pdf.png Bug691103.ps.pdf
Comment 3 Masaki Ushizaka 2010-02-14 19:17:08 UTC
Bug691103.ps.pdf generated in above command line contains a 'W' array which says:

/W [0 [2048]]

The number 2048 is in glyph space (this is a CIDFont with 2048x2048 glyph space) and this is wrong.
It should be 1000, which is in 1000th of text space.
Comment 4 Masaki Ushizaka 2010-02-17 17:12:07 UTC
The problem is not just that pdfwrite is ignoring FDArray font's FontMatrix,
but also that orig_FontMatrix is not working for CIDFont at all.
I need to fix that too.
Comment 5 Masaki Ushizaka 2010-02-23 03:59:49 UTC
Created attachment 5979 [details]
Bug691103_2.ps

A new test file.  First line is with same CIDFont with minor fix,  second line
is a Type 1 Font with 2048x2048 glyph space.  I found it useful while
debugging.
Comment 6 Masaki Ushizaka 2010-02-24 03:43:04 UTC
Created attachment 5986 [details]
b691103_b2.patch

A patch.
Bug687832.pdf and Bug690834.ps show differences but those are improvements.
Comment 7 Ken Sharp 2010-02-24 05:53:38 UTC
The patch looks good to me, you've obviously done regression tests so I think
you should go ahead and commit it. Thanks for working on this one!
Comment 8 Masaki Ushizaka 2010-03-10 02:29:52 UTC
The patch had been committed r10810 at Feb 25.  Closing this bug as fixed.

---
r10810 | masaki | 2010-02-25 17:21:46 +0900 (Thu, 25 Feb 2010) | 3 lines

Fix for bug 691103.  The pdfwrite device now considers FDArray fonts' FontMatrix and writes correct W/W2/DW/DW2 widths for CIDFont with unusual FontMatrix.  This also fixes a problem gs_font::orig_FontMatrix not being initialized for CIDFont.
Bug687832.pdf and Bug690834.ps will show differences which are improvements.