Description
I would like to request support for OpenType fonts. I have the main text written with Lucida and I'm unable to get the font on the graphs match the ones in the text.
I'm using the latest matplotlib with Python 3.3 on Mac OS X 10.7. When I try to use any give OpenType font
matplotlib.rcParams['font.family'] = 'Any Name Of OpenType Font'
this is what I get:
Traceback (most recent call last):
File "test.py", line 26, in <module>
plt.savefig('test.pdf')
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/matplotlib/pyplot.py", line 571, in savefig
res = fig.savefig(*args, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/matplotlib/figure.py", line 1448, in savefig
self.canvas.print_figure(*args, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/matplotlib/backend_bases.py", line 2192, in print_figure
**kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/matplotlib/backends/backend_pdf.py", line 2476, in print_pdf
file.close()
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/matplotlib/backends/backend_pdf.py", line 528, in close
self.writeFonts()
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/matplotlib/backends/backend_pdf.py", line 631, in writeFonts
fonts[Fx] = self.embedTTF(realpath, chars[1])
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/matplotlib/backends/backend_pdf.py", line 1106, in embedTTF
return embedTTFType3(font, characters, descriptor)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/matplotlib/backends/backend_pdf.py", line 892, in embedTTFType3
filename.encode(sys.getfilesystemencoding()), glyph_ids)
RuntimeError: TrueType font is missing table
The weird thing is that my colleagues get a different warning (complaining that font substitution isn't supported and then some garbled output).
The problem is that apparently backend_pdf.py is only taking
into account:
- *.afm fonts
- something with dvi info (which came from TeX)
- everything else is treated as TTF, so it goes though ttconv which apparently isn't able to handle PostScript-flavoured fonts
The interactive display and PNG work just fine, but I would like to have vector graphics.
I then tried to fetch a TrueType version of Lucida from Java, but that one behaves weird enough that I'm unable to use it (I'll open a new issue for that). I also experienced something very very odd – fonts from those fonts are rendered on our high end laser printer as if they were high resolution bitmap images, somewhat fuzzy. Fonts from gnuplot graphics and the rest of text is crisp clear, while text from pyplot graphs is somewhat smoothed at the edges, it looks like rasterized or weirdly hinted font.
An alternative would be to render the text labels through TeX, but I don't know how to set it up for (OpenType) Lucida fonts. (I know how to set it up outside of matplotlib.)
A slightly related issue is #1366. It would be great if pyplot supported OpenType Math fonts indeed, like Latin Modern Math, XITS Math, TeX Gyre Math (basically Helvetica, Times, Palatino, Bookman), Lucida Bright Math, Cambria, ...