14
14
15
15
from functools import lru_cache
16
16
import re
17
-
17
+ import numpy as np
18
18
from pyparsing import (Literal , ZeroOrMore , Optional , Regex , StringEnd ,
19
19
ParseException , Suppress )
20
20
@@ -183,14 +183,11 @@ def _escape_val(val, escape_func):
183
183
the input escape function to make the values into legal font config
184
184
strings. The result is returned as a string.
185
185
"""
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 ]
192
188
193
- return val
189
+ return ',' .join (escape_func (r'\\\1' , str (x )) for x in val
190
+ if x is not None )
194
191
195
192
196
193
def generate_fontconfig_pattern (d ):
@@ -208,6 +205,7 @@ def generate_fontconfig_pattern(d):
208
205
# The other keys are added as key=value
209
206
for key in ['style' , 'variant' , 'weight' , 'stretch' , 'file' , 'size' ]:
210
207
val = getattr (d , 'get_' + key )()
208
+ # Don't use 'if not val' because 0 is a valid input.
211
209
if val is not None and val != []:
212
210
props .append (":%s=%s" % (key , _escape_val (val , value_escape )))
213
211
0 commit comments