Patch for the PDF backend when setting pdf.use14corefonts=True is used

Nicolas Grilly <nicolas.grilly@...475...> writes:

The PDF backend breaks when the setting pdf.use14corefonts=True is
used. You'll find a test case reproducing this bug in the attached
file 'test_pdf_use14corefonts.py'.

You're right. I committed your patch, but there is another bug that
makes this a little difficult to test: the font cache doesn't record
whether it was build with pdf.use14corefonts enabled or not, and the
font name "Helvetica" happens to match "Helvetica Narrow", whose metrics
are included with matplotlib, and using that afm file without including
the font itself breaks the output. I'm too busy with other things to fix
this now, but patches are welcome. As a workaround, deleting
~/.matplotlib/fontList.cache helps if anyone wants to alternate between
enabling and disabling use14corefonts.

This setting is very useful because it produces very lightweight PDF
files. The files are lightweight because they only use the 14 core
fonts built in every PDF viewers (like Helvetica and Times).

Unfortunately, this functionality is deprecated in the PDF standard as
of PDF 1.5, and many publishers require embedding all fonts in PDF
files. Apparently not all substitutes for the standard fonts are similar
enough. (The real fonts need to be licensed, so many Linux distributions
ship with free look-alike substitutes, and who knows what fonts are
installed on some publisher's systems.)

Thanks for the patch!

···

--
Jouni K. Sepp�nen
http://www.iki.fi/jks

You're right. I committed your patch, but there is another bug that
makes this a little difficult to test: the font cache doesn't record
whether it was build with pdf.use14corefonts enabled or not, and the
font name "Helvetica" happens to match "Helvetica Narrow", whose metrics
are included with matplotlib, and using that afm file without including
the font itself breaks the output. I'm too busy with other things to fix
this now, but patches are welcome. As a workaround, deleting
~/.matplotlib/fontList.cache helps if anyone wants to alternate between
enabling and disabling use14corefonts.

Thanks for committing my patch! I've reproduced the font cache bug on
my machine too. Thanks for your detailed explanation. I've updated the
test case to acknowledge this issue and to set use14corefonts to True
*before* importing pylab (because importimg pylab seems to refresh the
font cache).

Those changes are in the attached patch. It's certainly not a
definitive workaround, but it's better than nothing :wink:

Unfortunately, this functionality is deprecated in the PDF standard as
of PDF 1.5, and many publishers require embedding all fonts in PDF
files. Apparently not all substitutes for the standard fonts are similar
enough. (The real fonts need to be licensed, so many Linux distributions
ship with free look-alike substitutes, and who knows what fonts are
installed on some publisher's systems.)

I'm aware of that deprecation. I agree we'll need to drop that feature
in a not so distant future...

test_pdf_use14corefonts.patch (1.17 KB)

···

Jouni K. Seppänen <jks@...278...> wrote:

--
Nicolas Grilly