@@ -994,7 +994,6 @@ def _normalize_font_family(family):
994994 return family
995995
996996
997- @cbook .deprecated ("2.2" )
998997class TempCache (object ):
999998 """
1000999 A class to store temporary caches that are (a) not saved to disk
@@ -1279,20 +1278,6 @@ def findfont(self, prop, fontext='ttf', directory=None,
12791278 <http://www.w3.org/TR/1998/REC-CSS2-19980512/>`_ documentation
12801279 for a description of the font finding algorithm.
12811280 """
1282- # Pass the relevant rcParams (and the font manager, as `self`) to
1283- # _findfont_cached so to prevent using a stale cache entry after an
1284- # rcParam was changed.
1285- rc_params = tuple (tuple (rcParams [key ]) for key in [
1286- "font.serif" , "font.sans-serif" , "font.cursive" , "font.fantasy" ,
1287- "font.monospace" ])
1288- return self ._findfont_cached (
1289- prop , fontext , directory , fallback_to_default , rebuild_if_missing ,
1290- rc_params )
1291-
1292- @lru_cache ()
1293- def _findfont_cached (self , prop , fontext , directory , fallback_to_default ,
1294- rebuild_if_missing , rc_params ):
1295-
12961281 if not isinstance (prop , FontProperties ):
12971282 prop = FontProperties (prop )
12981283 fname = prop .get_file ()
@@ -1306,7 +1291,11 @@ def _findfont_cached(self, prop, fontext, directory, fallback_to_default,
13061291 else :
13071292 fontlist = self .ttflist
13081293
1309- if directory is not None :
1294+ if directory is None :
1295+ cached = _lookup_cache [fontext ].get (prop )
1296+ if cached is not None :
1297+ return cached
1298+ else :
13101299 directory = os .path .normcase (directory )
13111300
13121301 best_score = 1e64
@@ -1364,20 +1353,26 @@ def _findfont_cached(self, prop, fontext, directory, fallback_to_default,
13641353 else :
13651354 raise ValueError ("No valid font could be found" )
13661355
1356+ if directory is None :
1357+ _lookup_cache [fontext ].set (prop , result )
13671358 return result
13681359
1369- @ lru_cache ()
1360+ _is_opentype_cff_font_cache = {}
13701361def is_opentype_cff_font (filename ):
13711362 """
13721363 Returns True if the given font is a Postscript Compact Font Format
13731364 Font embedded in an OpenType wrapper. Used by the PostScript and
13741365 PDF backends that can not subset these fonts.
13751366 """
13761367 if os .path .splitext (filename )[1 ].lower () == '.otf' :
1377- with open (filename , 'rb' ) as fd :
1378- return fd .read (4 ) == b"OTTO"
1379- else :
1380- return False
1368+ result = _is_opentype_cff_font_cache .get (filename )
1369+ if result is None :
1370+ with open (filename , 'rb' ) as fd :
1371+ tag = fd .read (4 )
1372+ result = (tag == b'OTTO' )
1373+ _is_opentype_cff_font_cache [filename ] = result
1374+ return result
1375+ return False
13811376
13821377fontManager = None
13831378_fmcache = None
@@ -1444,6 +1439,11 @@ def findfont(prop, fontext='ttf'):
14441439
14451440 fontManager = None
14461441
1442+ _lookup_cache = {
1443+ 'ttf' : TempCache (),
1444+ 'afm' : TempCache ()
1445+ }
1446+
14471447 def _rebuild ():
14481448 global fontManager
14491449
0 commit comments