Revision: 4107 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4107&view=rev Author: mdboom Date: 2007-11-05 07:45:00 -0800 (Mon, 05 Nov 2007)
Log Message: ----------- First pass at getting STIX fonts to work. Support .otf fonts in font_manager.py Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/_mathtext_data.py trunk/matplotlib/lib/matplotlib/font_manager.py trunk/matplotlib/lib/matplotlib/mathtext.py Modified: trunk/matplotlib/lib/matplotlib/_mathtext_data.py =================================================================== --- trunk/matplotlib/lib/matplotlib/_mathtext_data.py 2007-11-05 02:36:20 UTC (rev 4106) +++ trunk/matplotlib/lib/matplotlib/_mathtext_data.py 2007-11-05 15:45:00 UTC (rev 4107) @@ -1885,7 +1885,7 @@ 'measeq': 8798, 'upharpoonleft': 8639, 'lq': 8216, -'Upsilon': 978, +'Upsilon': 933, 'subsetneq': 8842, 'greater': 62, 'supsetneq': 8843, @@ -2238,7 +2238,7 @@ 'combiningbreve' : 774, 'combiningoverline' : 772, 'combininggraveaccent' : 768, -'combiningacuteaccent' : 714, +'combiningacuteaccent' : 769, 'combiningdiaeresis' : 776, 'combiningtilde' : 771, 'combiningrightarrowabove' : 8407, Modified: trunk/matplotlib/lib/matplotlib/font_manager.py =================================================================== --- trunk/matplotlib/lib/matplotlib/font_manager.py 2007-11-05 02:36:20 UTC (rev 4106) +++ trunk/matplotlib/lib/matplotlib/font_manager.py 2007-11-05 15:45:00 UTC (rev 4107) @@ -36,7 +36,7 @@ import os, sys, glob, shutil from sets import Set import matplotlib -from matplotlib import afm +from matplotlib import afm from matplotlib import ft2font from matplotlib import rcParams, get_home, get_configdir from matplotlib.cbook import is_string_like @@ -95,6 +95,10 @@ path = os.path.join(home, '.fonts') X11FontDirectories.append(path) +def get_fontext_synonyms(fontext): + return {'ttf': ('ttf', 'otf'), + 'afm': ('afm',)}[fontext] + def win32FontDirectory(): """Return the user-specified font directory for Win32.""" @@ -121,6 +125,8 @@ if directory is None: directory = win32FontDirectory() + fontext = get_fontext_synonyms(fontext) + key, items = None, {} for fontdir in MSFontDirectories: try: @@ -129,7 +135,10 @@ continue if not local: - return glob.glob(os.path.join(directory, '*.'+fontext)) + files = [] + for ext in fontext: + files.extend(glob.glob(os.path.join(directory, '*.'+ext))) + return files try: for j in range(_winreg.QueryInfoKey(local)[1]): try: @@ -137,7 +146,7 @@ if not os.path.dirname(direc): direc = os.path.join(directory, direc) direc = os.path.abspath(direc).lower() - if direc[-4:] == '.'+fontext: + if os.path.splitext(direc)[1][1:] in fontext: items[direc] = 1 except EnvironmentError: continue @@ -168,13 +177,16 @@ if directory is None: directory = OSXFontDirectory() + fontext = get_fontext_synonyms(fontext) + files = [] for path in directory: if fontext is None: files.extend(glob.glob(os.path.join(path,'*'))) else: - files.extend(glob.glob(os.path.join(path, '*.'+fontext))) - files.extend(glob.glob(os.path.join(path, '*.'+fontext.upper()))) + for ext in fontext: + files.extend(glob.glob(os.path.join(path, '*.'+ext))) + files.extend(glob.glob(os.path.join(path, '*.'+ext.upper()))) return files @@ -201,12 +213,14 @@ except ImportError: return {} + fontext = get_fontext_synonyms(fontext) + fontfiles = {} status, output = commands.getstatusoutput("fc-list file") if status == 0: for line in output.split('\n'): fname = line.split(':')[0] - if (os.path.splitext(fname)[1] == "." + fontext and + if (os.path.splitext(fname)[1][1:] in fontext and os.path.exists(fname)): fontfiles[fname] = 1 @@ -221,7 +235,8 @@ AFM fonts as an option. """ fontfiles = {} - + fontexts = get_fontext_synonyms(fontext) + if fontpaths is None: if sys.platform == 'win32': fontdir = win32FontDirectory() @@ -230,7 +245,7 @@ # now get all installed fonts directly... for f in win32InstalledFonts(fontdir): base, ext = os.path.splitext(f) - if len(ext)>1 and ext[1:].lower()==fontext: + if len(ext)>1 and ext[1:].lower() in fontexts: fontfiles[f] = 1 else: fontpaths = x11FontDirectory() @@ -246,8 +261,10 @@ fontpaths = [fontpaths] for path in fontpaths: - files = glob.glob(os.path.join(path, '*.'+fontext)) - files.extend(glob.glob(os.path.join(path, '*.'+fontext.upper()))) + files = [] + for ext in fontexts: + files.extend(glob.glob(os.path.join(path, '*.'+ext))) + files.extend(glob.glob(os.path.join(path, '*.'+ext.upper()))) for fname in files: fontfiles[os.path.abspath(fname)] = 1 @@ -1047,16 +1064,17 @@ def fc_match(pattern, fontext): import commands + fontexts = get_fontext_synonyms(fontext) ext = "." + fontext status, output = commands.getstatusoutput('fc-match -sv "%s"' % pattern) if status == 0: for match in _fc_match_regex.finditer(output): file = match.group(1) - if os.path.splitext(file)[1] == ext: + if os.path.splitext(file)[1][1:] in fontexts: return file return None - _fc_match_regex = re.compile(r'\sfile:\s+"(.*)"') + _fc_match_regex = re.compile(r'\sfile:\s+"([^"]*)"') _fc_match_cache = {} def findfont(prop, fontext='ttf'): Modified: trunk/matplotlib/lib/matplotlib/mathtext.py =================================================================== --- trunk/matplotlib/lib/matplotlib/mathtext.py 2007-11-05 02:36:20 UTC (rev 4106) +++ trunk/matplotlib/lib/matplotlib/mathtext.py 2007-11-05 15:45:00 UTC (rev 4107) @@ -814,6 +814,7 @@ MathTextWarning) return self.cm_fallback._get_glyph(fontname, sym, fontsize) else: + warn("Substituting with a dummy symbol.", MathTextWarning) new_fontname = fontname cached_font = self._get_font(fontname) uniindex = 0xA4 # currency character, for lack of anything better This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ Matplotlib-checkins mailing list Matplotlib-checkins@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins