Revision: 8712 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8712&view=rev Author: mdboom Date: 2010-09-21 20:13:25 +0000 (Tue, 21 Sep 2010)
Log Message: ----------- If a font file is looked up in the cache, but that font file no longer exists on disk, rebuild the cache. Modified Paths: -------------- branches/v1_0_maint/lib/matplotlib/font_manager.py Modified: branches/v1_0_maint/lib/matplotlib/font_manager.py =================================================================== --- branches/v1_0_maint/lib/matplotlib/font_manager.py 2010-09-20 16:58:14 UTC (rev 8711) +++ branches/v1_0_maint/lib/matplotlib/font_manager.py 2010-09-21 20:13:25 UTC (rev 8712) @@ -1169,7 +1169,7 @@ return abs(sizeval1 - sizeval2) / 72.0 def findfont(self, prop, fontext='ttf', directory=None, - fallback_to_default=True): + fallback_to_default=True, rebuild_if_missing=True): """ Search the font list for the font that most closely matches the :class:`FontProperties` *prop*. @@ -1257,6 +1257,16 @@ (prop, best_font.name, best_font.fname, best_score)) result = best_font.fname + if not os.path.isfile(result): + if rebuild_if_missing: + verbose.report( + 'findfont: Found a missing font file. Rebuilding cache.') + _rebuild() + return fontManager.findfont( + prop, fontext, directory, True, False) + else: + raise ValueError("No valid font could be found") + if directory is None: font_cache[hash(prop)] = result return result @@ -1280,6 +1290,16 @@ return result return False +fontManager = None + +_fmcache = os.path.join(get_configdir(), 'fontList.cache') + +def _rebuild(): + global fontManager + fontManager = FontManager() + pickle_dump(fontManager, _fmcache) + verbose.report("generated new fontManager") + # The experimental fontconfig-based backend. if USE_FONTCONFIG and sys.platform != 'win32': import re @@ -1317,16 +1337,6 @@ return result else: - _fmcache = os.path.join(get_configdir(), 'fontList.cache') - - fontManager = None - - def _rebuild(): - global fontManager - fontManager = FontManager() - pickle_dump(fontManager, _fmcache) - verbose.report("generated new fontManager") - try: fontManager = pickle_load(_fmcache) if (not hasattr(fontManager, '_version') or This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev _______________________________________________ Matplotlib-checkins mailing list Matplotlib-checkins@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins