@@ -346,6 +346,7 @@ def findSystemFonts(fontpaths=None, fontext='ttf'):
346
346
return [fname for fname in fontfiles if os .path .exists (fname )]
347
347
348
348
349
+ @cbook .deprecated ("2.1" )
349
350
def weight_as_number (weight ):
350
351
"""
351
352
Return the weight property as a numeric value. String values
@@ -435,17 +436,12 @@ def ttfFontProperty(font):
435
436
else :
436
437
variant = 'normal'
437
438
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
-
442
439
weight = next ((w for w in weight_dict if sfnt4 .find (w ) >= 0 ), None )
443
440
if not weight :
444
441
if font .style_flags & ft2font .BOLD :
445
- weight = 700
442
+ weight = "bold"
446
443
else :
447
- weight = 400
448
- weight = weight_as_number (weight )
444
+ weight = "normal"
449
445
450
446
# Stretch can be absolute and relative
451
447
# Absolute stretches are: ultra-condensed, extra-condensed, condensed,
@@ -511,11 +507,7 @@ def afmFontProperty(fontpath, font):
511
507
else :
512
508
variant = 'normal'
513
509
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 ()
519
511
520
512
# Stretch can be absolute and relative
521
513
# Absolute stretches are: ultra-condensed, extra-condensed, condensed,
@@ -855,7 +847,6 @@ def set_weight(self, weight):
855
847
except ValueError :
856
848
if weight not in weight_dict :
857
849
raise ValueError ("weight is invalid" )
858
- weight = weight_dict [weight ]
859
850
self ._weight = weight
860
851
861
852
def set_stretch (self , stretch ):
@@ -1203,10 +1194,19 @@ def score_weight(self, weight1, weight2):
1203
1194
"""
1204
1195
Returns a match score between *weight1* and *weight2*.
1205
1196
1206
- The result is the absolute value of the difference between the
1197
+ The result is 0.0 if both weight1 and weight 2 are given as strings
1198
+ and have the same value.
1199
+
1200
+ Otherwise, the result is the absolute value of the difference between the
1207
1201
CSS numeric values of *weight1* and *weight2*, normalized
1208
- between 0.0 and 1.0.
1202
+ between 0.05 and 1.0.
1209
1203
"""
1204
+
1205
+ # exact match of the weight names (e.g. weight1 == weight2 == "regular")
1206
+ if (isinstance (weight1 , six .string_types ) and
1207
+ isinstance (weight2 , six .string_types ) and
1208
+ weight1 == weight2 ):
1209
+ return 0.0
1210
1210
try :
1211
1211
weightval1 = int (weight1 )
1212
1212
except ValueError :
@@ -1215,7 +1215,7 @@ def score_weight(self, weight1, weight2):
1215
1215
weightval2 = int (weight2 )
1216
1216
except ValueError :
1217
1217
weightval2 = weight_dict .get (weight2 , 500 )
1218
- return abs (weightval1 - weightval2 ) / 1000.0
1218
+ return 0.95 * ( abs (weightval1 - weightval2 ) / 1000.0 ) + 0.05
1219
1219
1220
1220
def score_size (self , size1 , size2 ):
1221
1221
"""
0 commit comments