I am new to this list, but a real fan of matplotlib, so I thought I would post this here. I am not sure if a bug report is more appropriate - please let me know!
I have recently come across some font loading errors when using matplotlib 0.87.7-2 (and previous versions). I have tracked these errors down to font_manager.py in the matplotlib distribution, which is why I am emailing you guys (I saw your email addresses in the file).
My installation details are as follows: I am using python 2.5 with matplotlib 0.87.7-2 on OSX 10.4 both installed with fink (http://fink.sourceforge.net). I also encountered the same errors I will describe with python 2.3 and an earlier version of matplotlib. I have 2 font path environment variables set TTFPATH=/sw/lib/X11/fonts/applettf, and AFMPATH=/sw/share/texmf-dist/fonts/afm (/sw is where fink installs all files).
The crux of the matter is that my TTFPATH directory contains a bunch of .ttf files, while my AFMPATH directory contains subdirectories that themselves contain .afm files. The existing version of font_manager.py does not step through these subdirectories, and thus none of my afm fonts were being included in the search for fonts. Furthermore, there was a problem in parsing binary .ttf files when I was trying to load only ascii-encoded afm files.
I tracked this down to the findSystemFonts(fontpaths,fontext) method in font_manager.py and modified it in 2 places to step through subdirectories (with os.walk), and to make sure it only loads the correct font with extension fontext. Below I give a diff of my modifications (each commented with a #JBL), and the existing file:
diff font_manager.py font_manager_broken.py
< #JBL import re to match to file extension
< import re
< #JBL ONLY load if the proper fontext extension
< if re.match(fontext,f):
< fontfiles[f] = 1
fontfiles[f] = 1
< #Supposed to be searching recursively here
< # for path in fontpaths:
< # use os.walk to walk through any directories listed
< for root_path in fontpaths:
< for path, dirs, file_names in os.walk(root_path):
< files = glob.glob(os.path.join(path, ‘.'+fontext))
< files.extend(glob.glob(os.path.join(path, '.’+fontext.upper())))
< for fname in files:
(fname)] = 1
for path in fontpaths: files = glob.glob(os.path.join(path, '*.'+fontext)) files.extend(glob.glob(os.path.join(path, '*.'+fontext.upper()))) for fname in files: fontfiles[os.path.abspath(fname)] = 1
These changes fix all the font loading problems I noticed. I think this is an important fix for those users that have installed fonts in non-standard ways and who use the environment variables to point to them. Do you recommend me contributing this fix to the matplotlib project? Should I make a patch, or contribute via svn?
I hope this is helpful, and appreciate any feedback anyone can give.
Julius B. Lucks