6666 "/usr/lib/openoffice/share/fonts/truetype/" ,
6767 # documented as a good place to install new fonts...
6868 "/usr/share/fonts/" ]
69-
69+
7070OSXFontDirectories = [
7171 "/Library/Fonts/" ,
7272 "/Network/Library/Fonts/" ,
@@ -127,7 +127,7 @@ def win32InstalledFonts(directory=None, fontext='ttf'):
127127 continue
128128 except WindowsError :
129129 continue
130-
130+
131131 return items .keys ()
132132 finally :
133133 _winreg .CloseKey (local )
@@ -151,7 +151,7 @@ def OSXInstalledFonts(directory=None, fontext=None):
151151 """Get list of font files on OS X - ignores font suffix by default"""
152152 if directory is None :
153153 directory = OSXFontDirectory ()
154-
154+
155155 files = []
156156 for path in directory :
157157 if fontext is None :
@@ -193,7 +193,7 @@ def findSystemFonts(fontpaths=None, fontext='ttf'):
193193 fontfiles = {}
194194
195195 if fontpaths is None :
196-
196+
197197 if sys .platform == 'win32' :
198198 fontdir = win32FontDirectory ()
199199
@@ -212,12 +212,13 @@ def findSystemFonts(fontpaths=None, fontext='ttf'):
212212
213213 elif isinstance (fontpaths , (str , unicode )):
214214 fontpaths = [fontpaths ]
215+
215216 for path in fontpaths :
216217 files = glob .glob (os .path .join (path , '*.' + fontext ))
217218 files .extend (glob .glob (os .path .join (path , '*.' + fontext .upper ())))
218219 for fname in files :
219-
220220 fontfiles [os .path .abspath (fname )] = 1
221+
221222 return [fname for fname in fontfiles .keys () if os .path .exists (fname )]
222223
223224def weight_as_number (weight ):
@@ -291,7 +292,7 @@ def ttfFontProperty(font):
291292 else :
292293 style = 'normal'
293294
294-
295+
295296 # Variants are: small-caps and normal (default)
296297
297298 # !!!! Untested
@@ -333,7 +334,7 @@ def ttfFontProperty(font):
333334 stretch = 'expanded'
334335 else :
335336 stretch = 'normal'
336-
337+
337338 # Sizes can be absolute and relative.
338339 # Absolute sizes are: xx-small, x-small, small, medium, large, x-large,
339340 # and xx-large.
@@ -346,7 +347,7 @@ def ttfFontProperty(font):
346347 size = 'scalable'
347348 else :
348349 size = str (float (font .get_fontsize ()))
349-
350+
350351 # !!!! Incomplete
351352 size_adjust = None
352353
@@ -459,7 +460,7 @@ def createFontDict(fontfiles, fontext='ttf'):
459460 continue
460461 try : prop = ttfFontProperty (font )
461462 except : continue
462-
463+
463464 add_filename (fontdict , prop , fpath )
464465
465466 # !!!! Default font algorithm needs improvement
@@ -476,7 +477,7 @@ def createFontDict(fontfiles, fontext='ttf'):
476477 prop .name = 'fantasy'
477478 add_filename (fontdict , prop , fpath )
478479 elif prop .name .lower () in ['bitstream vera sans mono' , 'courier' ]:
479- prop .name = 'monospace'
480+ prop .name = 'monospace'
480481 add_filename (fontdict , prop , fpath )
481482
482483 return fontdict
@@ -611,7 +612,7 @@ def __init__(self,
611612 self .__size = size
612613 self .__parent_size = fontManager .get_default_size ()
613614 self .fname = fname
614-
615+
615616 def __hash__ (self ):
616617 return hash ( (
617618 tuple (self .__family ), self .__style , self .__variant ,
@@ -682,7 +683,7 @@ def set_name(self, names):
682683 msg = "Font name '%s' is a font family. It is being deleted from the list."
683684 font_family = ['serif' , 'sans-serif' , 'cursive' , 'fantasy' ,
684685 'monospace' ]
685-
686+
686687 if isinstance (names , str ):
687688 names = [names ]
688689
@@ -794,7 +795,7 @@ def __init__(self, size=12.0, weight='normal'):
794795
795796 verbose .report ('font search path %s' % (str (paths )))
796797 # Load TrueType fonts and create font dictionary.
797-
798+
798799 self .ttffiles = findSystemFonts (paths ) + findSystemFonts ()
799800
800801 for fname in self .ttffiles :
@@ -805,20 +806,20 @@ def __init__(self, size=12.0, weight='normal'):
805806 else :
806807 # use anything
807808 self .defaultFont = self .ttffiles [0 ]
808-
809+
809810 cache_message = \
810811"""Saving TTF font cache for non-PS backends to %s.
811812Delete this file to have matplotlib rebuild the cache."""
812813
813-
814+
814815
815816 oldcache = os .path .join (get_home (), 'ttffont.cache' )
816817 ttfcache = os .path .join (get_configdir (), 'ttffont.cache' )
817- if os .path .exists (oldcache ):
818+ if os .path .exists (oldcache ):
818819 print >> sys .stderr , 'Moving old ttfcache location "%s" to new location "%s"' % (oldcache , ttfcache )
819820 os .rename (oldcache , ttfcache )
820821
821-
822+
822823
823824 try :
824825 import cPickle as pickle
@@ -830,7 +831,7 @@ def rebuild():
830831 self .ttfdict = createFontDict (self .ttffiles )
831832 pickle .dump (self .ttfdict , file (ttfcache , 'w' ))
832833 verbose .report (cache_message % ttfcache )
833-
834+
834835 try :
835836 self .ttfdict = pickle .load (file (ttfcache ))
836837 except :
@@ -842,7 +843,7 @@ def rebuild():
842843 rebuild ()
843844 break
844845 verbose .report ('loaded ttfcache file %s' % ttfcache )
845-
846+
846847
847848
848849 #self.ttfdict = createFontDict(self.ttffiles)
@@ -877,7 +878,7 @@ def update_fonts(self, filenames):
877878 # !!!! Needs implementing
878879 raise NotImplementedError
879880
880-
881+
881882 def findfont (self , prop , fontext = 'ttf' ):
882883
883884 """Search the font dictionary for a font that exactly or closely
@@ -901,7 +902,7 @@ def findfont(self, prop, fontext='ttf'):
901902 fname = prop .fname
902903 verbose .report ('findfont returning %s' % fname , 'debug' )
903904 return fname
904-
905+
905906 if fontext == 'afm' :
906907 if len (self .afmdict ) == 0 :
907908 afmpath = os .environ .get ('HOME' , get_data_path ())
@@ -943,7 +944,7 @@ def findfont(self, prop, fontext='ttf'):
943944 else :
944945 verbose .report ('\t findfont failed %(name)s' % locals (), 'debug' )
945946 continue
946-
947+
947948 if font .has_key (style ):
948949 font = font [style ]
949950 elif style == 'italics' and font .has_key ('oblique' ):
@@ -961,7 +962,7 @@ def findfont(self, prop, fontext='ttf'):
961962 if not font .has_key (weight ):
962963 setWeights (font )
963964 font = font [weight ]
964-
965+
965966 # !!!! need improvement
966967 if font .has_key (stretch ):
967968 font = font [stretch ]
@@ -974,14 +975,14 @@ def findfont(self, prop, fontext='ttf'):
974975 elif font .has_key (size ):
975976 fname = font [size ]
976977 else :
977- verbose .report ('\t findfont failed %(name)s, %(style)s, %(variant)s %(weight)s, %(stretch)s, %(size)s' % locals (), 'debug' )
978+ verbose .report ('\t findfont failed %(name)s, %(style)s, %(variant)s %(weight)s, %(stretch)s, %(size)s' % locals (), 'debug' )
978979 continue
979980
980981 fontkey = FontKey (name , style , variant , weight , stretch , size )
981982 add_filename (fontdict , fontkey , fname )
982983 verbose .report ('\t findfont found %(name)s, %(style)s, %(variant)s %(weight)s, %(stretch)s, %(size)s' % locals (), 'debug' )
983984 verbose .report ('findfont returning %s' % fname , 'debug' )
984-
985+
985986 return fname
986987
987988 fontkey = FontKey (name , style , variant , weight , stretch , size )
0 commit comments