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).
"Nicolas Grilly" <nic...@ga...> writes: > Here is a patch I promised some time ago, to improve the PDF backend. Thanks; on first look this seems really nice! So far I have one request to you and one to John: Nicolas: would it be easy for you to strip the ^M (carriage-return) characters from your files and then re-run diff? I see in your patch several parts where the only change seems to be an addition of ^M at the end of each line, but there could be significant changes hidden within these parts. (Perhaps just give the -b option to diff? Though that might backfire if some other whitespace changes are significant, e.g. if you have changed the indentation of some code blocks.) John: Is Adobe's licensing of the AFM files compatible with matplotlib's license? I think it is, but I'm no license expert. The readme file distributed with the files contains the following text: Font Metrics for the 14 PDF Core Fonts ====================================== This directory contains font metrics for the 14 PDF Core Fonts (files with .afm extension), downloaded from http://partners.adobe.com/public/developer/font/index.html. This file and the 14 PostScript(R) AFM files it accompanies may be used, copied, and distributed for any purpose and without charge, with or without modification, provided that all copyright notices are retained; that the AFM files are not distributed without this file; that all modifications to this file or any of the AFM files are prominently noted in the modified file(s); and that this paragraph is not modified. Adobe Systems has no responsibility or obligation to support the use of the AFM files. -- Jouni K. Seppänen http://www.iki.fi/jks
T24gMi8xNC8wNywgSm91bmkgSy4gU2VwcMOkbmVuIDxqa3NAaWtpLmZpPiB3cm90ZToKPiBUaGFu a3M7IG9uIGZpcnN0IGxvb2sgdGhpcyBzZWVtcyByZWFsbHkgbmljZSEgU28gZmFyIEkgaGF2ZSBv bmUKPiByZXF1ZXN0IHRvIHlvdSBhbmQgb25lIHRvIEpvaG46CgpZb3UncmUgd2VsY29tZTsgSSdt IGhhcHB5IHRvIGNvbnRyaWJ1dGUgdG8gbWF0cGxvdGxpYiB3aGVuIEkgY2FuISA6LSkKCj4gTmlj b2xhczogd291bGQgaXQgYmUgZWFzeSBmb3IgeW91IHRvIHN0cmlwIHRoZSBeTSAoY2FycmlhZ2Ut cmV0dXJuKQo+IGNoYXJhY3RlcnMgZnJvbSB5b3VyIGZpbGVzIGFuZCB0aGVuIHJlLXJ1biBkaWZm PyBJIHNlZSBpbiB5b3VyIHBhdGNoCj4gc2V2ZXJhbCBwYXJ0cyB3aGVyZSB0aGUgb25seSBjaGFu Z2Ugc2VlbXMgdG8gYmUgYW4gYWRkaXRpb24gb2YgXk0gYXQKPiB0aGUgZW5kIG9mIGVhY2ggbGlu ZSwgYnV0IHRoZXJlIGNvdWxkIGJlIHNpZ25pZmljYW50IGNoYW5nZXMgaGlkZGVuCj4gd2l0aGlu IHRoZXNlIHBhcnRzLiAoUGVyaGFwcyBqdXN0IGdpdmUgdGhlIC1iIG9wdGlvbiB0byBkaWZmPyBU aG91Z2gKPiB0aGF0IG1pZ2h0IGJhY2tmaXJlIGlmIHNvbWUgb3RoZXIgd2hpdGVzcGFjZSBjaGFu Z2VzIGFyZSBzaWduaWZpY2FudCwKPiBlLmcuIGlmIHlvdSBoYXZlIGNoYW5nZWQgdGhlIGluZGVu dGF0aW9uIG9mIHNvbWUgY29kZSBibG9ja3MuKQoKT2suIEkndmUgcmVtb3ZlZCB0aGUgY2Fycmlh Z2UtcmV0dXJuIGNoYXJhY3RlcnMgYW5kIGFkZGVkIHByb3BlcnR5CnN2bjplb2wtc3R5bGUgPSBu YXRpdmUgdG8gYmFja2VuZC5wZGYuIE5vdyB0aGUgcGF0Y2ggbG9va3MgcmlnaHQgKHNlZQp0aGUg YXR0YWNoZWQgZmlsZSkuCgpJIGhvcGUgdGhlcmUgaXMgbm8gbGljZW5zZSBpc3N1ZSB3aXRoIHRo ZSBBRk0gZmlsZXMuIEknbSBwcmV0dHkgc3VyZQpJJ3ZlIHNlZW4gdGhlbSBpbnRlZ3JhdGVkIGlu IHNvbWUgVGVYIGRpc3RyaWJ1dGlvbnMuCgotLSBOaWNvbGFzIEdyaWxseQo=
On 2/14/07, Nicolas Grilly <nic...@ga...> wrote: > I hope there is no license issue with the AFM files. I'm pretty sure > I've seen them integrated in some TeX distributions. Apparently all we have to do is include the README along with the licensing terms. You probably should do that in the the same directory the fonts live to ensure that they are always distributed together. We also have a licenses directory. JDH
On 2/14/07, John Hunter <jd...@gm...> wrote: > Apparently all we have to do is include the README along with the > licensing terms. You probably should do that in the the same > directory the fonts live to ensure that they are always distributed > together. We also have a licenses directory. In this purpose, I've provided a readme.txt file, located in the same directory as the AFM files, and containing this text: """ Font Metrics for the 14 PDF Core Fonts ====================================== This directory contains font metrics for the 14 PDF Core Fonts (files with .afm extension), downloaded from http://partners.adobe.com/public/developer/font/index.html. This file and the 14 PostScript(R) AFM files it accompanies may be used, copied, and distributed for any purpose and without charge, with or without modification, provided that all copyright notices are retained; that the AFM files are not distributed without this file; that all modifications to this file or any of the AFM files are prominently noted in the modified file(s); and that this paragraph is not modified. Adobe Systems has no responsibility or obligation to support the use of the AFM files. """ The original file from Adobe just contained the last paragraph; I added the first one to make clear the files origin. NG
Hello Jouni, Have you had time to look at my patch regarding the PDF backend? :-) Regards, Nicolas
"Nicolas Grilly" <nic...@ga...> writes: > Have you had time to look at my patch regarding the PDF backend? :-) A bit, and I couldn't quite get it to work. But what the heck, let's put it in the repository so we can all hack on it. It is quite an improvement to the backend, and it doesn't seem to break anything that used to work. (I ran the examples using backend_driver.py on both agg and pdf.) Your patch (slightly modified) is committed as of svn revision 3027. The problem I'm having is that if I set use14corefonts on, I have to make sure that Helvetica (or whatever) is chosen as the text font. I used to have the setting font.sans-serif : Bitstream Vera Sans because that font works, and some other fonts that mpl finds (on my OS X system) don't; but then setting use14corefonts on caused the afm header parser to be called on Vera.ttf, which it obviously couldn't make any sense of. I'm not sure I quite understand the Matplotlib font selection system, though. Replacing the setting by font.sans-serif : Helvetica, Bitstream Vera Sans helps, but it would be nice to put in some sanity checks so that we don't send the ttf file to the afm parser. On another note, the dpi setting was used for images. Removing it does make the code simpler, but then all images will be at a resolution of 72 dpi. Can you be more specific about the problems that the dpi setting was causing? Anyway, perhaps we should find a better interface for specifying image resolution for vectorial backends. Regards, -- Jouni K. Seppänen http://www.iki.fi/jks
T24gMi8yMS8wNywgSm91bmkgSy4gU2VwcMOkbmVuIDxqa3NAaWtpLmZpPiB3cm90ZToKPiA+IEhh dmUgeW91IGhhZCB0aW1lIHRvIGxvb2sgYXQgbXkgcGF0Y2ggcmVnYXJkaW5nIHRoZSBQREYgYmFj a2VuZD8gOi0pCj4KPiBBIGJpdCwgYW5kIEkgY291bGRuJ3QgcXVpdGUgZ2V0IGl0IHRvIHdvcmsu IEJ1dCB3aGF0IHRoZSBoZWNrLCBsZXQncwo+IHB1dCBpdCBpbiB0aGUgcmVwb3NpdG9yeSBzbyB3 ZSBjYW4gYWxsIGhhY2sgb24gaXQuIEl0IG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RvIGJlIGNhbGxlZCBvbiBWZXJhLnR0Ziwgd2hpY2ggaXQgb2J2 aW91c2x5IGNvdWxkbid0Cj4gbWFrZSBhbnkgc2Vuc2Ugb2YuIEknbSBub3Qgc3VyZSBJIHF1aXRl IHVuZGVyc3RhbmQgdGhlIE1hdHBsb3RsaWIgZm9udAo+IHNlbGVjdGlvbiBzeXN0ZW0sIHRob3Vn aC4KPgo+IFJlcGxhY2luZyB0aGUgc2V0dGluZyBieQo+Cj4gZm9udC5zYW5zLXNlcmlmICAgICA6 IEhlbHZldGljYSwgQml0c3RyZWFtIFZlcmEgU2Fucwo+Cj4gaGVscHMsIGJ1dCBpdCB3b3VsZCBi ZSBuaWNlIHRvIHB1dCBpbiBzb21lIHNhbml0eSBjaGVja3Mgc28gdGhhdCB3ZQo+IGRvbid0IHNl bmQgdGhlIHR0ZiBmaWxlIHRvIHRoZSBhZm0gcGFyc2VyLgo+Cj4gT24gYW5vdGhlciBub3RlLCB0 aGUgZHBpIHNldHRpbmcgd2FzIHVzZWQgZm9yIGltYWdlcy4gUmVtb3ZpbmcgaXQgZG9lcwo+IG1h a2UgdGhlIGNvZGUgc2ltcGxlciwgYnV0IHRoZW4gYWxsIGltYWdlcyB3aWxsIGJlIGF0IGEgcmVz b2x1dGlvbiBvZgo+IDcyIGRwaS4gQ2FuIHlvdSBiZSBtb3JlIHNwZWNpZmljIGFib3V0IHRoZSBw cm9ibGVtcyB0aGF0IHRoZSBkcGkKPiBzZXR0aW5nIHdhcyBjYXVzaW5nPyBBbnl3YXksIHBlcmhh cHMgd2Ugc2hvdWxkIGZpbmQgYSBiZXR0ZXIgaW50ZXJmYWNlCj4gZm9yIHNwZWNpZnlpbmcgaW1h Z2UgcmVzb2x1dGlvbiBmb3IgdmVjdG9yaWFsIGJhY2tlbmRzLgo=
On 2/13/07, Nicolas Grilly <nic...@ga...> wrote: > Here is a patch I promised some time ago, to improve the PDF backend. Jouni, I'm going to leave this up to you, but Nicolas this looks very nice. Thanks! JDH