1414
1515from functools import lru_cache
1616import re
17-
17+ import numpy as np
1818from pyparsing import (Literal , ZeroOrMore , Optional , Regex , StringEnd ,
1919 ParseException , Suppress )
2020
@@ -183,14 +183,11 @@ def _escape_val(val, escape_func):
183183 the input escape function to make the values into legal font config
184184 strings. The result is returned as a string.
185185 """
186- if isinstance (val , list ):
187- val = [escape_func (r'\\\1' , str (x )) for x in val
188- if x is not None ]
189- val = ',' .join (val )
190- else :
191- val = escape_func (r'\\\1' , str (val ))
186+ if not np .iterable (val ) or isinstance (val , str ):
187+ val = [val ]
192188
193- return val
189+ return ',' .join (escape_func (r'\\\1' , str (x )) for x in val
190+ if x is not None )
194191
195192
196193def generate_fontconfig_pattern (d ):
@@ -208,6 +205,7 @@ def generate_fontconfig_pattern(d):
208205 # The other keys are added as key=value
209206 for key in ['style' , 'variant' , 'weight' , 'stretch' , 'file' , 'size' ]:
210207 val = getattr (d , 'get_' + key )()
208+ # Don't use 'if not val' because 0 is a valid input.
211209 if val is not None and val != []:
212210 props .append (":%s=%s" % (key , _escape_val (val , value_escape )))
213211
0 commit comments