Bug 79897 - Bad PostScript out of not so bad PDF
Summary: Bad PostScript out of not so bad PDF
Status: RESOLVED FIXED
Alias: None
Product: cairo
Classification: Unclassified
Component: postscript backend (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: Adrian Johnson
QA Contact: cairo-bugs mailing list
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-06-10 21:25 UTC by Alex Korobkin
Modified: 2016-07-11 16:22 UTC (History)
2 users (show)

See Also:
i915 platform:
i915 features:


Attachments
79897-original.pdf (171.54 KB, application/pdf)
2014-06-10 21:30 UTC, Alex Korobkin
Details
79897-pdftops.ps (1.02 MB, application/postscript)
2014-06-10 21:30 UTC, Alex Korobkin
Details
79897-pdftocairo.ps (392.15 KB, application/postscript)
2014-06-10 21:31 UTC, Alex Korobkin
Details
79897-adobe.ps (1.71 MB, application/gzip)
2014-06-10 21:33 UTC, Alex Korobkin
Details
Test file of how cairo defines fonts in postscript (126.82 KB, application/postscript)
2014-06-11 22:22 UTC, James Cloos
Details
2nd test of cairo ps fonts (126.84 KB, application/postscript)
2014-06-12 22:31 UTC, James Cloos
Details
79897-adobe-ps3.ps (2.40 MB, text/plain)
2014-06-19 15:42 UTC, Alex Korobkin
Details
reduced test case (256.46 KB, application/pdf)
2016-07-09 09:12 UTC, Adrian Johnson
Details
PS output from reduced test case without cairo fix (25.06 KB, application/postscript)
2016-07-09 09:14 UTC, Adrian Johnson
Details
PS output from reduced test case with cairo fix (25.04 KB, application/postscript)
2016-07-09 09:16 UTC, Adrian Johnson
Details

Description Alex Korobkin 2014-06-10 21:25:30 UTC
Attached PDF with Vietnamese text is rendered nicely in Evince, GhostScript, and AcroRead. It seemingly has some errors in the way the fonts are embedded, but PDF viewers treat it nicely. 

However, I cannot produce printable level3 PostScript out of it: printer (Ricoh with embedded Distiller) says "invalidfont" and chokes on the first page right away.  

I'm attaching the output of 

pdftocairo -ps -level3 
pdftops -level3

I'm also attaching the output of Adobe Pro: after converting this file, it produces PostScript that is readable by printers (no wonder, same vendor for both engines). 

Could anything be done to improve the PostScript output with bad files like this one?
Comment 1 Alex Korobkin 2014-06-10 21:30:09 UTC
Created attachment 100844 [details]
79897-original.pdf
Comment 2 Alex Korobkin 2014-06-10 21:30:43 UTC
Created attachment 100845 [details]
79897-pdftops.ps

79897-pdftops.ps - converted by pdftops -level3
Comment 3 Alex Korobkin 2014-06-10 21:31:43 UTC
Created attachment 100846 [details]
79897-pdftocairo.ps

79897-pdftocairo.ps -- made with pdftocairo -ps -level3, but looks like pdftocairo produces level2 postscript with this file, ignoring level3 switch.
Comment 4 Alex Korobkin 2014-06-10 21:33:04 UTC
Created attachment 100847 [details]
79897-adobe.ps

79897-adobe.ps -- File produced with Adobe Pro, just for the reference. 
Gzipped.
Comment 5 James Cloos 2014-06-10 22:23:18 UTC
> However, I cannot produce printable level3 PostScript out of it:
> printer (Ricoh with embedded Distiller) says "invalidfont" and
> chokes on the first page right away.

Some PS printers have an option to print any errors encountered.

If your does, enabling it might help narrow down which font is does not
like.

The pdf does not embed the font it uses for the italic footer on each
page and for the initial M of the string «Mẫu M.01/LS» on the first page.

The other fonts are embeded subsets.

Perhaps the issue is how the CID fonts are defined in the ps?

Some printers which claim level3 support only support a subset of it,
usually just what adobe, ms or apple products generate, notwithstanding
that adobe documents more valid level3 ps.  You might need to force
level2 for that printer.
Comment 6 Alex Korobkin 2014-06-11 16:12:58 UTC
(In reply to comment #5)
> If your does, enabling it might help narrow down which font is does not
> like.
> 
> The pdf does not embed the font it uses for the italic footer on each
> page and for the initial M of the string «Mẫu M.01/LS» on the first page.

You're right, it is complaining about Times-Italic. Distiller complains about the same:
%%[ Error: Times-Italic not found. Font cannot be embedded. ]%%

> Some printers which claim level3 support only support a subset of it,
> usually just what adobe, ms or apple products generate, notwithstanding
> that adobe documents more valid level3 ps.  You might need to force
> level2 for that printer.

That would mean to use level2 for the whole fleet of Ricoh printers that I have, and level2 has its own issues with poppler. After reporting a few of them in the past I eventually switched to level3 and was mostly happy with level3 support in Ricoh and poppler.

What can be done to handle this undefined font properly, perhaps a substitution could be made? I see lots of documents like this one choking on "invalidfont" error when printed on a printer with embedded Adobe engine.
Comment 7 James Cloos 2014-06-11 18:20:18 UTC
>>>>> "b" == bugzilla-daemon  <bugzilla-daemon@freedesktop.org> writes:

>> The pdf does not embed the font it uses for the italic footer on each
>> page and for the initial M of the string «Mẫu M.01/LS» on the first page.

b> You're right, it is complaining about Times-Italic. Distiller
b> complains about the same: %%[ Error: Times-Italic not found. Font
b> cannot be embedded. ]%%

cairo embeds (replacements for) the missing fonts (as found via
fontconfig.  What error does the 79897-pdftocairo.ps generate?

Does this ps work on that printer:

%!
/Times-Italic 24 selectfont
200 200 moveto (Font is Times Italic) show
showpage
%eof

Of this:

%!
/pdfMakeFont {
  4 3 roll findfont
  4 2 roll matrix scale makefont
  dup length dict begin
    { 1 index /FID ne { def } { pop pop } ifelse } forall
    /Encoding exch def
    currentdict
  end
  definefont pop
} def
/F6_0 /Times-Italic 1 1
[ /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
  /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
  /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
  /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
  /space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quotesingle
  /parenleft/parenright/asterisk/plus/comma/hyphen/period/slash
  /zero/one/two/three/four/five/six/seven
  /eight/nine/colon/semicolon/less/equal/greater/question
  /at/A/B/C/D/E/F/G
  /H/I/J/K/L/M/N/O
  /P/Q/R/S/T/U/V/W
  /X/Y/Z/bracketleft/backslash/bracketright/asciicircum/underscore
  /grave/a/b/c/d/e/f/g
  /h/i/j/k/l/m/n/o
  /p/q/r/s/t/u/v/w
  /x/y/z/braceleft/bar/braceright/asciitilde/bullet
  /Euro/bullet/quotesinglbase/florin/quotedblbase/ellipsis/dagger/daggerdbl
  /circumflex/perthousand/Scaron/guilsinglleft/OE/bullet/Zcaron/bullet
  /bullet/quoteleft/quoteright/quotedblleft/quotedblright/bullet/endash/emdash
  /tilde/trademark/scaron/guilsinglright/oe/bullet/zcaron/Ydieresis
  /space/exclamdown/cent/sterling/currency/yen/brokenbar/section
  /dieresis/copyright/ordfeminine/guillemotleft/logicalnot/hyphen/registered/macron
  /degree/plusminus/twosuperior/threesuperior/acute/mu/paragraph/periodcentered
  /cedilla/onesuperior/ordmasculine/guillemotright/onequarter/onehalf/threequarters/questiondown
  /Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla
  /Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex/Idieresis
  /Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis/multiply
  /Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute/Thorn/germandbls
  /agrave/aacute/acircumflex/atilde/adieresis/aring/ae/ccedilla
  /egrave/eacute/ecircumflex/edieresis/igrave/iacute/icircumflex/idieresis
  /eth/ntilde/ograve/oacute/ocircumflex/otilde/odieresis/divide
  /oslash/ugrave/uacute/ucircumflex/udieresis/yacute/thorn/ydieresis]
pdfMakeFont
/F6_0 12 selectfont
200 200 moveto (Font is Times Italic) show
showpage
%eof
Comment 8 Alex Korobkin 2014-06-11 19:31:03 UTC
Both variants work with the printer and Adobe Distiller, producing a page with 
"Font is Times Italic" text in the middle. Second variant produces a slightly smaller text. 

I was wrong about 79897-pdftocairo.ps, printer seems to be unhappy about a different font: TimesNewRomanPSMT

Adobe Pro produces similar error: "Cannot extract embedded font TimesNewRomanPSMT"
Comment 9 James Cloos 2014-06-11 22:22:27 UTC
Created attachment 100905 [details]
Test file of how cairo defines fonts in postscript

The cairo output you attached turns out to be level2.

In it, /TimesNewRomanPSMT is separated into two fonts, /f-2-0 has the latin1 glyphs, and /f-2-1 has the other glyphs.

Both fonts specify /FontName /TimesNewRomanPSMT in their definitions.

I’m attachging a cut-down version of 79897-pdftocairo.ps which just defines those two fonts and displays some sample text in each.

The pdf did not embed a  TimesNewRomanPSMT glyph for f, so it is not an error that the strings /f-2-0 and /f-2-1 do correctly show the letter f.

Does this test file work on the printer or in distiller?
Comment 10 Alex Korobkin 2014-06-12 19:12:27 UTC
(In reply to comment #9)

> The cairo output you attached turns out to be level2.

Yes, I think I mentioned it somewhere. Regardless of -level3 switch pdftocairo produces level2 postscript. It produces level3 with other files, but not with this one. 

> In it, /TimesNewRomanPSMT is separated into two fonts, /f-2-0 has the latin1
> glyphs, and /f-2-1 has the other glyphs.
> 
> Both fonts specify /FontName /TimesNewRomanPSMT in their definitions.
> 
> I’m attachging a cut-down version of 79897-pdftocairo.ps which just defines
> those two fonts and displays some sample text in each.
> 
> The pdf did not embed a  TimesNewRomanPSMT glyph for f, so it is not an
> error that the strings /f-2-0 and /f-2-1 do correctly show the letter f.
> 
> Does this test file work on the printer or in distiller?

Printer prints "This" word and then invalidfont error. 
Distiller produces an empty PDF, no errors. 
Evince 0.24.5-2 shows empty page when opening this ps. 
GS 9.12 shows a page with "This is /[]-2-0, Above is /[]-2-1" line (f letter missing).
Comment 11 James Cloos 2014-06-12 22:02:58 UTC
That shows that adobe does not like the way cairo defines its fonts when generating ps.

I’ll open a bugz for cairo pointing here about that issue.
Comment 12 James Cloos 2014-06-12 22:05:29 UTC
Does pdftops -level2 work for this file?

The docs say the only difference is the use of CID fonts, and it may be how it generates the CID fonts which breaks distiller?
Comment 13 James Cloos 2014-06-12 22:07:03 UTC
Oh,

Since you have distiller, if you also have a support agreement with adobe, you may want to submit the cut down ps there and see whether they can/will explain what the software doesn’t like about it.
Comment 14 James Cloos 2014-06-12 22:31:08 UTC
Created attachment 100944 [details]
2nd test of cairo ps fonts

This version of the test file adds subset prefixes to the font names.

Does distiller or the printer handle it better than the first test?
Comment 15 Alex Korobkin 2014-06-13 15:28:06 UTC
(In reply to comment #11)
> I’ll open a bugz for cairo pointing here about that issue.

Thanks, please post a link to bug here when opened? 

> Does pdftops -level2 work for this file?

With pdftops -level2 Distiller cannot extract different font, TimesNewRoman,BoldOOEnc_00. 

> This version of the test file adds subset prefixes to the font names.
> Does distiller or the printer handle it better than the first test?

Unfortunately, no. It behaves similar to the first version of the file:
Printer prints "This" word and then "Error: invalidfont. Offending command: show"

Distiller produces an empty PDF, two warnings: 
%%[ Warning: Times-Italic not found, using Font Substitution. Font cannot be embedded. ]%%
%%[ Warning: Times-Roman not found, using Font Substitution. Font cannot be embedded. ]%%

Evince shows empty page when opening this PS file.
Comment 16 Alex Korobkin 2014-06-13 15:39:49 UTC
(In reply to comment #13)
> Since you have distiller, if you also have a support agreement with adobe,
> you may want to submit the cut down ps there and see whether they can/will
> explain what the software doesn’t like about it.

Support asked me to submit a bug report via their Bug Report/Feature Request form, which I did. I will share their reply if any.
Comment 17 James Cloos 2014-06-13 16:28:51 UTC
> Thanks, please post a link to bug here when opened? 

bug #79958
Comment 18 Alex Korobkin 2014-06-19 15:42:11 UTC
Created attachment 101367 [details]
79897-adobe-ps3.ps

79897-adobe-ps3.ps - PostScript Level 3 as generated by Adobe Pro for this file, just for the reference.
Comment 19 Doug Moore 2014-11-12 16:20:44 UTC
We are seeing the same issue on Kodak digimaster printers.
Comment 20 Adrian Johnson 2016-07-09 09:12:51 UTC
Created attachment 124964 [details]
reduced test case

Testing 79897-original.pdf on my printer (which has an Adobe PS interpreter), I get

ERROR: invalidfont
OFFENDING COMMAND: show

The problem is the space glyph in one of the embedded fonts has an entry in the glyf table with num_contours = 0. This is invalid according to the spec. Glyphs with no contours must not have a glyph defined in the glyf table (the entry in loca table should point to a 0 size glyph).

Attached is a stripped down version of 79897-original.pdf that just displays "test test".
Comment 21 Adrian Johnson 2016-07-09 09:14:46 UTC
Created attachment 124965 [details]
PS output from reduced test case without cairo fix

Attached is the "pdftocairo -ps" output from the reduced test case. It prints

ERROR: invalidfont
OFFENDING COMMAND: show

on my printer.
Comment 22 Adrian Johnson 2016-07-09 09:16:26 UTC
Created attachment 124966 [details]
PS output from reduced test case with cairo fix

I've pushed out a fix for this problem:

https://cgit.freedesktop.org/cairo/commit/?id=b73c082c7f412f53eb2e4b52689601128a5f06a0

Attached is the PS output from "pdftocairo -ps" with the above fix applied. It prints correctly on my printer.
Comment 23 Alex Korobkin 2016-07-11 16:22:10 UTC
I confirm that the patch works for me. Thank you, much appreciated!


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.