Font installation stuff

I just finished writing code to support scalable mathtext with the Cairo
backend. (The old version rendered the mathtext to bitmaps first).

Mostly straightforward, but I ran into one small snag. It *seems* that
pycairo requires that the fonts it uses are installed and accessible
through fontconfig, i.e. you can not load a font by filename. Not a big
deal, but there is also no way to tell if a particular font family
matched exactly, and thus no way to warn a user that they need to
install the Bakoma fonts.

There are some ways out of this. It appears possible to load a font
from a file for Cairo in C (though apparently different for each
platform). I would hate to have to support another extension in
matplotlib, but maybe the pycairo folks would be amenable to adding
this. Probably worth dropping a note to the pycairo list either way.

Or, we could find some way to install fonts automatically. That's
fundamentally a packaging/distribution issue.

All this raises a much larger question of whether we want to replace
font_manager.py with something like fontconfig. There don't appear to
be Python wrappers for it, but it would eliminate a number of issues
with font_manager.py : a) it would look up fonts in the same way as many
other apps in the OS (rather than from hard-coded folders), and b) seems
a little more correct in how it looks up fonts and substitutes for
missing fonts etc. For instance, if font_manager.py doesn't find an exact match, it always returns Vera Sans, rather than returning something with the same slant and weight as what you requested. There would be no need to manually flush the matplotlib font cache, since fontconfig would deal with all of that.

[The Python wrappers are probably a non-issue on Unix-like systems, since you can call out to the "fc-match" command for lookup.]

This may be more effort than it's worth -- but I wanted to get opinions from others on this list.

Cheers,
Mike

Michael Droettboom wrote:
[...]

All this raises a much larger question of whether we want to replace
font_manager.py with something like fontconfig. There don't appear to
be Python wrappers for it, but it would eliminate a number of issues
with font_manager.py : a) it would look up fonts in the same way as many
other apps in the OS (rather than from hard-coded folders), and b) seems
a little more correct in how it looks up fonts and substitutes for
missing fonts etc. For instance, if font_manager.py doesn't find an exact match, it always returns Vera Sans, rather than returning something with the same slant and weight as what you requested. There would be no need to manually flush the matplotlib font cache, since fontconfig would deal with all of that.

[The Python wrappers are probably a non-issue on Unix-like systems, since you can call out to the "fc-match" command for lookup.]

This may be more effort than it's worth -- but I wanted to get opinions from others on this list.

I find the fontconfig web site inscrutable; I don't understand how the library would be used by mpl in practice. I get the impression that it needs to be installed and configured at a system level--is this correct? How would it work on OSX and Win?

Eric

ยทยทยท

Cheers,
Mike