Patch for enhancement of PDF backend

Here is a patch I promised some time ago, to improve the PDF backend.

I use it to produce charts and integrate them in documents generated
by pdfTeX and ConTeXt. It's very handy because pdfTeX natively handles
PDF graphics, without any conversion.

The patched backend is able to use the 14 PDF core fonts. These fonts
are embedded in every PDF viewing applications. So you can produce
charts contained in very small PDF files, easy to integrate in LaTeX
or ConTeXt through pdfTeX.

My patch is the attached file mpl_pdf_backend_patch.patch.

You also need to untar the attached file pdfcorefonts.tar in
lib/matplotlib/mpl-data/fonts in order to create a directory
pdfcorefonts holdings AFM files for the 14 PDF core fonts.

Does this patch work for you? Do you agree to commit it in SVN?

Thanks,

Nicolas Grilly

A summary of changes:

- Created a directory lib/matplotlib/mpl-data/fonts/pdfcorefonts,
  holding AFM files for the 14 PDF core fonts. These fonts are
  embedded in every PDF viewing applications.

- setup.py: Added the directory pdfcorefonts to package_data.

- lib/matplotlib/__init__.py: Added the default parameter
  'pdf.use14corefonts'. When True, the PDF backend use only
  the 14 PDF core fonts.

- lib/matplotlib/afm.py: Added some keywords found in recent
  AFM files. Added a little workaround to handle Euro symbol.

- lib/matplotlib/fontmanager.py: Added support for 14 PDF
  core fonts. These fonts have a dedicated cache (file
  pdfcorefont.cache), not the same as for other AFM files
  (file .afmfont.cache). Also cleaned comments to conform to
  CODING_GUIDE.

- lib/matplotlib/backends/backend_pdf.py:
  Added support for 14 PDF core fonts.
  Fixed some issues with incorrect character widths and
  encodings (works only for the most common encoding,
  WinAnsiEncoding, defined by the official PDF Reference).
  Removed parameter 'dpi' because it causes alignment issues
  (the notion of DPI seems useless in a vectorial format, unless
  we use it for image magnification, like in backend_ps.py).

mpl_pdf_backend_patch.patch (54.2 KB)

pdfcorefonts.tar (640 KB)

Jouni,

I'm going to leave this up to you, but Nicolas this looks very nice. Thanks!

JDH

···

On 2/13/07, Nicolas Grilly <nicolas.grilly@...475...> wrote:

Here is a patch I promised some time ago, to improve the PDF backend.