Bug 23030

Summary: patch to disable font substitution in pdftops
Product: poppler Reporter: William Bader <williambader>
Component: generalAssignee: poppler-bugs <poppler-bugs>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: medium CC: williambader
Version: unspecified   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments: the patches to add -nosubst to pdftops
pdf file
screen capture showing good and bad renderings
alternate patch to make the default not substituting fonts
revised font substitution patches
patch for the manual page
revised revised patches

Description William Bader 2009-07-29 18:15:03 UTC
I have a large number of small PDF files to convert to eps.  The system that generated the PDF files is out of my control.  To save space, PDF files do not contain any embedded fonts.  Instead, I have the postscript fonts on my system.  When pdftops finds a reference to a non-embedded font, it changes the font to Helvetica, Times-Roman, or Courier from a list in psSubstFonts[] in PSOutputDev.cc.  My patches add a -nosubst flag to pdftops that tells PSOutputDev::setupFont() to pass the original font in the postscript output instead of substituting it.  This way, pdftops does not lose any information, and the postscript file will still view or print correctly if you have the postscript font available.
Comment 1 William Bader 2009-07-29 18:16:09 UTC
Created attachment 28176 [details] [review]
the patches to add -nosubst to pdftops
Comment 2 William Bader 2009-07-29 18:17:49 UTC
Created attachment 28177 [details]
pdf file

pdf file that contains a reference to Spartan-HeavyClassified without embedding it.
Comment 3 William Bader 2009-07-29 18:20:56 UTC
Created attachment 28178 [details]
screen capture showing good and bad renderings

A screen capture showing renderings with gv of the pdf, the default eps with font substitution, and the eps without font substitution (using -nosubst).  I have the required font file on my system in a place where ghostscript can find it.
Comment 4 William Bader 2009-07-30 06:22:35 UTC
Created attachment 28192 [details] [review]
alternate patch to make the default not substituting fonts

This patch differs from the first patch by adding preprocessor macro SUBST_FONTS to pdftops.cc.  If it is set non-zero, the default is substituting fonts.  If it is not defined or set to 0, the default is passing fonts.

Is there any reason to substitute fonts?  Once pdftops substitutes a font, information is lost, and the resulting postscript will never print correctly.  If pdftops passes non-embedded fonts unchanged, you still have a chance to view or print the file correctly if you have the fonts, and if you don't have the fonts, the worst that will happen is that the viewer or printer substitutes the fonts, and then you are in the same place as if pdftops did the substitution.  I have seen systems that reject postscript files with missing fonts, but if pdftops substitutes missing fonts to keep files from being rejected, it defeats the purpose of checking for missing fonts.
Comment 5 Albert Astals Cid 2009-07-30 14:05:30 UTC
The patch doesn't seem much clean to me, for example the value of xs is calculated using psSubstFonts[i].mWidth that is not really "right" since you are not substituting the font.

Also i don't see why you need GBool substFonts; in PSOutputDev.h if the variable is just used in a function
Comment 6 William Bader 2009-07-30 14:59:12 UTC
> The patch doesn't seem much clean to me, for example the value of xs is
> calculated using psSubstFonts[i].mWidth that is not really "right" since you
> are not substituting the font.

I tried to make the smallest possible change.  The value of i is still a valid index.  When not substituting, I let it continue to calculate everything as before, but then at the end, I set xs = 1.  If you want me change the entire sequence to
if (substFonts) {
  calculate w1, w2, and xs as before
} else {
  xs = 1;
}
I can make a new set of patches.

> Also i don't see why you need GBool substFonts; in PSOutputDev.h if the variable is just used in a function

I followed the examples of the other command line parameters.  I think that the variable must be stored in PSOutputDev.h so that PSOutputDev.cc does not need to know the internals of pdftops.cc.
Comment 7 Albert Astals Cid 2009-07-30 15:18:42 UTC
> I can make a new set of patches.
Please do.

> I followed the examples of the other command line parameters.  I think that
> the variable must be stored in PSOutputDev.h so that PSOutputDev.cc does not need
> to know the internals of pdftops.cc.
Ignore my comment, i thought
 substFonts = globalParams->getPSSubstFonts();
and 
 if (substFonts) {
happened inside the same function, but they do not.
Comment 8 William Bader 2009-07-30 20:42:53 UTC
Created attachment 28209 [details] [review]
revised font substitution patches

Here are revised patches with a cleaner version of PSOutputDev::setupFont() that does no extra work with psSubstFonts[i], w1 and w2 when not substituting fonts.
Comment 9 Albert Astals Cid 2009-07-31 13:02:16 UTC
Can you please update the man page file too?
Comment 10 William Bader 2009-07-31 14:05:23 UTC
Created attachment 28227 [details] [review]
patch for the manual page

Here is a patch for utils/pdftops.1 assuming that pdftops is set to pass fonts by default and has a -subst option to substitute fonts (corresponding to the revised patches 28209).  I changed the date but did not touch the copyright or the .NAME or .SH AUTHOR sections.
Comment 11 Albert Astals Cid 2009-07-31 14:15:32 UTC
No, sorry, the behaviour change is not going to be accepted. Code it the way the default behaviour stays.
Comment 12 William Bader 2009-07-31 15:00:27 UTC
Created attachment 28228 [details] [review]
revised revised patches

These patches add a -passfonts option to pdftops to pass missing fonts through to the postscript without substituting them.  By default, without the -passfonts option, pdftops substitutes missing fonts as before.  These patches also update the man page.  I removed the #ifdef part in the previous patches to make the default configurable.
Comment 13 Albert Astals Cid 2009-08-01 06:23:33 UTC
Commited

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.