@@ -387,6 +387,20 @@ def validate_fontweight(s):
387387 raise ValueError (f'{ s } is not a valid font weight.' ) from e
388388
389389
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+
390404def validate_font_properties (s ):
391405 parse_fontconfig_pattern (s )
392406 return s
@@ -900,7 +914,7 @@ def _convert_validator_spec(key, conv):
900914 "font.family" : validate_stringlist , # used by text object
901915 "font.style" : validate_string ,
902916 "font.variant" : validate_string ,
903- "font.stretch" : validate_string ,
917+ "font.stretch" : validate_fontstretch ,
904918 "font.weight" : validate_fontweight ,
905919 "font.size" : validate_float , # Base font size in points
906920 "font.serif" : validate_stringlist ,
0 commit comments