Parse a fontconfig *pattern* into a dict that can initialize a `.font_manager.FontProperties` object.
(pattern)
| 76 | # during the test suite. |
| 77 | @lru_cache |
| 78 | def parse_fontconfig_pattern(pattern): |
| 79 | """ |
| 80 | Parse a fontconfig *pattern* into a dict that can initialize a |
| 81 | `.font_manager.FontProperties` object. |
| 82 | """ |
| 83 | parser = _make_fontconfig_parser() |
| 84 | try: |
| 85 | parse = parser.parse_string(pattern) |
| 86 | except ParseException as err: |
| 87 | # explain becomes a plain method on pyparsing 3 (err.explain(0)). |
| 88 | raise ValueError("\n" + ParseException.explain(err, 0)) from None |
| 89 | parser.reset_cache() |
| 90 | props = {} |
| 91 | if "families" in parse: |
| 92 | props["family"] = [*map(_family_unescape, parse["families"])] |
| 93 | if "sizes" in parse: |
| 94 | props["size"] = [*parse["sizes"]] |
| 95 | for prop in parse.get("properties", []): |
| 96 | if len(prop) == 1: |
| 97 | prop = _CONSTANTS[prop[0]] |
| 98 | k, *v = prop |
| 99 | props.setdefault(k, []).extend(map(_value_unescape, v)) |
| 100 | return props |
| 101 | |
| 102 | |
| 103 | def generate_fontconfig_pattern(d): |
no test coverage detected
searching dependent graphs…