|
38 | 38 | - line-width: 1.5; (Default 1.0) |
39 | 39 | - line-dash: 2,4; (Default none) |
40 | 40 | - font-color: #01234567; (Default none) |
41 | | - - font-face: name; (Default Consolas,sans) |
| 41 | + - font-face: name; (Default Consolas,monospace) |
42 | 42 | - font-size: 11; (Default 10) |
43 | 43 |
|
44 | 44 | Colors can be RGB or RGBA, but note that transparent colors are much more |
@@ -180,6 +180,17 @@ class CSSStylesheet(dict): |
180 | 180 | re.VERBOSE |
181 | 181 | ) |
182 | 182 |
|
| 183 | + re_str_decl = re.compile( |
| 184 | + r''' |
| 185 | + ^\s* # Start a new line ignore whitespace |
| 186 | + (font-face):\s* # Mandatory name |
| 187 | + "(.*?)" # Double-quoted string |
| 188 | + ;\s* # Closing ; immediately afterwards |
| 189 | + $ |
| 190 | + ''', |
| 191 | + re.VERBOSE |
| 192 | + ) |
| 193 | + |
183 | 194 | def __init__( |
184 | 195 | self, css_file: Optional[str] = None, |
185 | 196 | css_string: Optional[str] = None): |
@@ -279,6 +290,13 @@ def parse_string(self, css_string: str, file_name: Optional[str]): |
279 | 290 | node[key] = dash_value |
280 | 291 | continue |
281 | 292 |
|
| 293 | + # Handle node field declarations for strings |
| 294 | + if match := self.re_str_decl.match(line): |
| 295 | + key = match.group(1) |
| 296 | + for node in current_nodes: |
| 297 | + node[key] = CSSFont(match.group(2)) |
| 298 | + continue |
| 299 | + |
282 | 300 | # If we get here this line is an unknown so raise an error |
283 | 301 | raise ValueError() |
284 | 302 |
|
@@ -370,7 +388,7 @@ class CSSFont(tuple): |
370 | 388 | tuples. Created instances will not be instances of CSSFont. |
371 | 389 | ''' |
372 | 390 |
|
373 | | - def __new__(cls, face: str = 'sans'): |
| 391 | + def __new__(cls, face: str): |
374 | 392 | ''' |
375 | 393 | Create a new CSSFont tuple. |
376 | 394 |
|
@@ -422,7 +440,7 @@ class CSSNode(dict): |
422 | 440 | if os.name == 'nt': |
423 | 441 | DEFAULT_FONT = 'Consolas' |
424 | 442 | else: |
425 | | - DEFAULT_FONT = 'sans' |
| 443 | + DEFAULT_FONT = 'monospace' |
426 | 444 |
|
427 | 445 | DEFAULT_STYLES = { |
428 | 446 | 'fill-color': CSSColor('none'), |
|
0 commit comments