@@ -346,6 +346,7 @@ def findSystemFonts(fontpaths=None, fontext='ttf'):
346346 return [fname for fname in fontfiles if os .path .exists (fname )]
347347
348348
349+ @cbook .deprecated ("2.1" )
349350def weight_as_number (weight ):
350351 """
351352 Return the weight property as a numeric value. String values
@@ -435,17 +436,12 @@ def ttfFontProperty(font):
435436 else :
436437 variant = 'normal'
437438
438- # Weights are: 100, 200, 300, 400 (normal: default), 500 (medium),
439- # 600 (semibold, demibold), 700 (bold), 800 (heavy), 900 (black)
440- # lighter and bolder are also allowed.
441-
442439 weight = next ((w for w in weight_dict if sfnt4 .find (w ) >= 0 ), None )
443440 if not weight :
444441 if font .style_flags & ft2font .BOLD :
445442 weight = 700
446443 else :
447444 weight = 400
448- weight = weight_as_number (weight )
449445
450446 # Stretch can be absolute and relative
451447 # Absolute stretches are: ultra-condensed, extra-condensed, condensed,
@@ -511,11 +507,7 @@ def afmFontProperty(fontpath, font):
511507 else :
512508 variant = 'normal'
513509
514- # Weights are: 100, 200, 300, 400 (normal: default), 500 (medium),
515- # 600 (semibold, demibold), 700 (bold), 800 (heavy), 900 (black)
516- # lighter and bolder are also allowed.
517-
518- weight = weight_as_number (font .get_weight ().lower ())
510+ weight = font .get_weight ().lower ()
519511
520512 # Stretch can be absolute and relative
521513 # Absolute stretches are: ultra-condensed, extra-condensed, condensed,
@@ -855,7 +847,6 @@ def set_weight(self, weight):
855847 except ValueError :
856848 if weight not in weight_dict :
857849 raise ValueError ("weight is invalid" )
858- weight = weight_dict [weight ]
859850 self ._weight = weight
860851
861852 def set_stretch (self , stretch ):
@@ -1204,10 +1195,19 @@ def score_weight(self, weight1, weight2):
12041195 """
12051196 Returns a match score between *weight1* and *weight2*.
12061197
1207- The result is the absolute value of the difference between the
1198+ The result is 0.0 if both weight1 and weight 2 are given as strings
1199+ and have the same value.
1200+
1201+ Otherwise, the result is the absolute value of the difference between the
12081202 CSS numeric values of *weight1* and *weight2*, normalized
1209- between 0.0 and 1.0.
1203+ between 0.05 and 1.0.
12101204 """
1205+
1206+ # exact match of the weight names (e.g. weight1 == weight2 == "regular")
1207+ if (isinstance (weight1 , six .string_types ) and
1208+ isinstance (weight2 , six .string_types ) and
1209+ weight1 == weight2 ):
1210+ return 0.0
12111211 try :
12121212 weightval1 = int (weight1 )
12131213 except ValueError :
@@ -1216,7 +1216,7 @@ def score_weight(self, weight1, weight2):
12161216 weightval2 = int (weight2 )
12171217 except ValueError :
12181218 weightval2 = weight_dict .get (weight2 , 500 )
1219- return abs (weightval1 - weightval2 ) / 1000.0
1219+ return 0.95 * ( abs (weightval1 - weightval2 ) / 1000.0 ) + 0.05
12201220
12211221 def score_size (self , size1 , size2 ):
12221222 """
0 commit comments