@@ -387,6 +387,20 @@ def validate_fontweight(s):
387
387
raise ValueError (f'{ s } is not a valid font weight.' ) from e
388
388
389
389
390
+ def validate_fontstretch (s ):
391
+ stretchvalues = [
392
+ 'ultra-condensed' , 'extra-condensed' , 'condensed' , 'semi-condensed' ,
393
+ 'normal' , 'semi-expanded' , 'expanded' , 'extra-expanded' ,
394
+ 'ultra-expanded' ]
395
+ # Note: Historically, stretchvalues have been case-sensitive in Matplotlib
396
+ if s in stretchvalues :
397
+ return s
398
+ try :
399
+ return int (s )
400
+ except (ValueError , TypeError ) as e :
401
+ raise ValueError (f'{ s } is not a valid font stretch.' ) from e
402
+
403
+
390
404
def validate_font_properties (s ):
391
405
parse_fontconfig_pattern (s )
392
406
return s
@@ -900,7 +914,7 @@ def _convert_validator_spec(key, conv):
900
914
"font.family" : validate_stringlist , # used by text object
901
915
"font.style" : validate_string ,
902
916
"font.variant" : validate_string ,
903
- "font.stretch" : validate_string ,
917
+ "font.stretch" : validate_fontstretch ,
904
918
"font.weight" : validate_fontweight ,
905
919
"font.size" : validate_float , # Base font size in points
906
920
"font.serif" : validate_stringlist ,
0 commit comments