Bug 689763 - Problem reading PDF file with CID font
Summary: Problem reading PDF file with CID font
Status: NOTIFIED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: Text (show other bugs)
Version: master
Hardware: All All
: P1 normal
Assignee: Alex Cherepanov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-03-25 10:39 UTC by Marcos H. Woehrmann
Modified: 2008-12-19 08:31 UTC (History)
0 users

See Also:
Customer: 531 850
Word Size: ---


Attachments
002_simple.pdf (26.52 KB, application/pdf)
2008-03-25 11:07 UTC, Marcos H. Woehrmann
Details
experimental patch - uses wrong encoding (2.93 KB, patch)
2008-03-30 19:38 UTC, Alex Cherepanov
Details | Diff
patch (6.71 KB, patch)
2008-04-17 22:26 UTC, Alex Cherepanov
Details | Diff
patch (7.11 KB, patch)
2008-04-18 20:34 UTC, Alex Cherepanov
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Marcos H. Woehrmann 2008-03-25 10:39:40 UTC
The customer reports and I've verified that the attached PDF files cannot be read by Ghostscript 8.62 
nor head (r8604).  The customer suspects the issue is related to the embedded CID fonts.

The command line I'm using for testing:

  bin/gs -sDEVICE=tiff24nc -o test.tif ./002_untergeschoss.pdf

Here is the Ghostscript output:

GPL Ghostscript SVN PRE-RELEASE 8.63 (2008-03-01)
Copyright (C) 2008 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
Error: /undefined in --run--
Operand stack:
   --nostringval--   --dict:6/15(L)--   F4   8.24651   --dict:6/6(L)--   --dict:6/6(L)--   OfficinaSans-
Book   --dict:11/12(ro)(G)--   --nostringval--   --dict:8/8(L)--   --dict:17/17(L)--   --dict:17/17(L)-
-   CIDFontName
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   -
-nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1905   1   3   
%oparray_pop   1904   1   3   %oparray_pop   1888   1   3   %oparray_pop   --nostringval--   --
nostringval--   2   1   1   --nostringval--   %for_pos_int_continue   --nostringval--   --nostringval--   -
-nostringval--   --nostringval--   %array_continue   --nostringval--   false   1   %stopped_push   --
nostringval--   %loop_continue   --nostringval--   --nostringval--   --nostringval--   --nostringval--   
--nostringval--   --nostringval--   %array_continue   --nostringval--   --nostringval--   --
nostringval--
Dictionary stack:
   --dict:1148/1684(ro)(G)--   --dict:1/20(G)--   --dict:75/200(L)--   --dict:75/200(L)--   --
dict:108/127(ro)(G)--   --dict:275/300(ro)(G)--   --dict:22/25(L)--   --dict:4/6(L)--   --
dict:21/40(L)--   --dict:1/1(ro)(G)--   --dict:1/1(ro)(G)--   --dict:1/1(ro)(G)--   --dict:1/1(ro)(G)--   -
-dict:1/1(ro)(G)--   --dict:1/1(ro)(G)--   --dict:1/1(ro)(G)--   --dict:1/1(ro)(G)--   --dict:1/1(ro)(G)--   
--dict:1/1(ro)(G)--   --dict:1/1(ro)(G)--   --dict:1/1(ro)(G)--   --dict:9/13(L)--
Current allocation mode is local
Last OS error: 2
GPL Ghostscript SVN PRE-RELEASE 8.63: Unrecoverable error, exit code 1
Comment 1 Marcos H. Woehrmann 2008-03-25 10:40:43 UTC
Created attachment 3887 [details]
002_untergeschoss.pdf
Comment 2 Marcos H. Woehrmann 2008-03-25 10:41:10 UTC
Created attachment 3888 [details]
001_übersicht_200.pdf
Comment 3 Marcos H. Woehrmann 2008-03-25 11:07:04 UTC
Created attachment 3890 [details]
002_simple.pdf

Much simplified version of the 002_untergeschoss.pdf file.  I believe this file
does not need to marked as private.
Comment 4 Alex Cherepanov 2008-03-25 20:29:36 UTC
The PDF file is invalid. 
The font descriptor for OfficinaSans-Book has /Subtype /CIDFontType2 i.e.
declared CIDFont object but refers to an OpenType file that contains
a simple CFF font. We cannot recover from this error.

If I do:

--- pdf_font.ps.old        2008-03-25 11:23:15.000000000 -0500
+++ pdf_font.ps 2008-03-25 21:58:38.000000000 -0500
@@ -1432,7 +1432,7 @@
   /MMType1 //adjustfont
   /TrueType //adjustfont
   /CIDFontType0 //adjustCIDType0
-  /CIDFontType2 //adjustCIDType2
+  /CIDFontType2 //adjustfont % //adjustCIDType2
 .dicttomark readonly def

 % Bind a proc and define n names

The simplified sample proceeds to completion but renders incorrectly.

According to the PDF spec, the descendant font must be CIDFont, not a simple
font.
Comment 5 leonardo 2008-03-28 01:50:23 UTC
Passing to Alex who handles PDF interpreter.
Comment 6 Marcos H. Woehrmann 2008-03-28 08:20:55 UTC
A second customer has reported the same problem; I've attached their test file.
Comment 7 Marcos H. Woehrmann 2008-03-28 08:21:22 UTC
Created attachment 3901 [details]
12619.pdf
Comment 8 Alex Cherepanov 2008-03-30 19:38:04 UTC
Created attachment 3904 [details]
experimental patch - uses wrong encoding

This patch creates a CIDFont resource from a simple font. It fixes the
PostScript error but uses wrong encoding - some of the characters may be
swapped or missing. 

The correct fix should be a part of ReadData procedure and use CharString INDEX
for glyph numbers.
Comment 9 Alex Cherepanov 2008-04-17 22:26:30 UTC
Created attachment 3948 [details]
patch

This patch appears to work.
Comment 10 Alex Cherepanov 2008-04-18 20:34:02 UTC
Created attachment 3951 [details]
patch

PDF can use OpenType font with ordinary CFF data as a CIDFont. Such a font is
referenced by /CIDFontType2 and may have /CIDToGIDMap table. The following
changes have been done to support this usage.

- A flag that forces CIDFont generation was added to CFF font loader.
- When the flag is on, CFF font is converted to a Type 9 CIDFont.
- The FontSet resource is returned by the value from the font loader
  because it can be of either Font or CIDFont type,
- Since CIDMap has no effect on CIDFont Type 9, CIDToGIDMap is interpreted
  by PDF reader to modify GlyphDirectory to the same effect.
- Unused CIDMap is no longer generated for CIDFontType2 objects that are nor
  TrueType CIDFont resources.

Regression testing shows no differences.
Comment 11 Alex Cherepanov 2008-04-18 20:45:08 UTC
The last path is committed as a rev. 8646.