Answers a list of Font instances where the pattern fits the font path. If pattern is a list, all parts should have a match. # TODO: make case insensitive
(pattern, lazy=True)
| 112 | return None |
| 113 | |
| 114 | def findFonts(pattern, lazy=True): |
| 115 | """Answers a list of Font instances where the pattern fits the font path. |
| 116 | If pattern is a list, all parts should have a match. |
| 117 | |
| 118 | |
| 119 | # TODO: make case insensitive |
| 120 | """ |
| 121 | """ |
| 122 | >>> findFonts('Roboto-Thi') |
| 123 | [<Font Roboto-Thin>, <Font Roboto-ThinItalic>] |
| 124 | >>> # Select on family and name parts. |
| 125 | >>> findFonts(('Robo', 'Ita', 'Thi')) |
| 126 | [<Font Roboto-ThinItalic>] |
| 127 | >>> # Select on style parts only. |
| 128 | >>> findFonts(('Ita', 'Bol', 'Con')) |
| 129 | [<Font RobotoCondensed-BoldItalic>] |
| 130 | """ |
| 131 | fontPaths = getFontPaths() |
| 132 | fonts = [] |
| 133 | |
| 134 | if not isinstance(pattern, (list, tuple)): |
| 135 | pattern = [pattern] |
| 136 | |
| 137 | for fontPath in fontPaths: |
| 138 | found = True |
| 139 | for match in pattern: |
| 140 | if not match in fontPath: |
| 141 | found = False |
| 142 | break |
| 143 | if found: |
| 144 | fonts.append(findFont(fontPath, lazy=lazy)) |
| 145 | return fonts |
| 146 | |
| 147 | def findFont(fontPath, default=None, lazy=True): |
| 148 | """Answers the font the has name fontName. |
nothing calls this directly
no test coverage detected