@@ -614,31 +614,30 @@ def best_fam(self, word):
614614 if word in self ._fams :
615615 return word
616616
617+ # do a case-insensitive, no-whitespace comparison
617618 if word not in self ._fuzzy :
618- # do a case-insensitive, no-whitespace comparison
619619 q = sanitized (word )
620620 corpus = sanitized (self ._fams )
621621 if q in corpus :
622+ # full-name match
622623 self ._fuzzy [word ] = self ._fams [corpus .index (q )]
623- elif q :
624- # if still no match, compare against a list of names with all the noise words taken out
625- corpus = debranded (self ._fams , keep = branding (word ))
626- if word in corpus :
627- self ._fuzzy [word ] = self ._fams [corpus .index (word )]
628- elif q in sanitized (corpus ):
629- # case-insensitive with the de-noised names
630- self ._fuzzy [word ] = self ._fams [sanitized (corpus ).index (q )]
631-
632- if word not in self ._fuzzy :
633- # give up but first do a broad search and suggest other names in the exception
634- in_corpus = difflib .get_close_matches (q , corpus , 4 , cutoff = 0 )
635- matches = [self ._fams [corpus .index (m )] for m in in_corpus ]
636- nomatch = "ambiguous font family name \" %s\" " % word
637- if matches :
638- nomatch += '.\n Did you mean: %s' % [m .encode ('utf-8' ) for m in matches ]
639- self ._fuzzy [word ] = DeviceError (nomatch )
640-
641- return self ._fuzzy [word ]
624+ else :
625+ # accept substrings that unambiguously identify a single family
626+ contains = [fam for fam in corpus if q in fam ]
627+ if len (contains )== 1 :
628+ self ._fuzzy [word ] = self ._fams [corpus .index (contains [0 ])]
629+
630+ try :
631+ return self ._fuzzy [word ]
632+ except KeyError :
633+ # give up but first do a broad search and suggest other names in the exception
634+ in_corpus = difflib .get_close_matches (q , corpus , 4 , cutoff = 0 )
635+ matches = [self ._fams [corpus .index (m )] for m in in_corpus ]
636+ nomatch = "ambiguous font family name \" %s\" " % word
637+ if matches :
638+ nomatch += '.\n Did you mean: %s' % [m .encode ('utf-8' ) for m in matches ]
639+ return DeviceError (nomatch )
640+
642641
643642 def list_fam (self , famname , names = False ):
644643 """Returns a sorted list of Face tuples for the fonts in a family"""
0 commit comments