Answers the font the has name fontName. >>> f = findFont('Roboto-Regular') >>> f >>> notSkiaFont = findFont('Skia-cannot-be-found') >>> notSkiaFont is None True >>> # Default is a font. >>> # Set RobotoFont as default. >>> notSkiaFont = find
(fontPath, default=None, lazy=True)
| 145 | return fonts |
| 146 | |
| 147 | def findFont(fontPath, default=None, lazy=True): |
| 148 | """Answers the font the has name fontName. |
| 149 | |
| 150 | >>> f = findFont('Roboto-Regular') |
| 151 | >>> f |
| 152 | <Font Roboto-Regular> |
| 153 | >>> notSkiaFont = findFont('Skia-cannot-be-found') |
| 154 | >>> notSkiaFont is None |
| 155 | True |
| 156 | >>> # Default is a font. |
| 157 | >>> # Set RobotoFont as default. |
| 158 | >>> notSkiaFont = findFont('Skia-cannot-be-found', default=f) |
| 159 | >>> notSkiaFont is f # Found robotoFont instead |
| 160 | True |
| 161 | >>> # Default is a name. |
| 162 | >>> f = findFont('Skia-cannot-be-found', default='Roboto-Regular') # Found default RobotoFont instead |
| 163 | >>> f |
| 164 | <Font Roboto-Regular> |
| 165 | """ |
| 166 | if isinstance(fontPath, Font): # It's already a Font instance, just answer it. |
| 167 | return fontPath |
| 168 | |
| 169 | fontPaths = getFontPaths() # Otherwise, let's see if we can find it by name. |
| 170 | if fontPath in fontPaths: |
| 171 | font = getFont(fontPaths[fontPath], lazy=lazy) |
| 172 | if font is not None: |
| 173 | return font |
| 174 | |
| 175 | font = getFont(fontPath) |
| 176 | if font is not None: |
| 177 | return font |
| 178 | |
| 179 | # A default is defined. If it's a string, try to find it. Avoid c76ircular |
| 180 | # calls. |
| 181 | if isinstance(default, str) and default != fontPath: |
| 182 | return findFont(default, lazy=lazy) |
| 183 | |
| 184 | assert default is None or isinstance(default, Font) |
| 185 | # Otherwise assume it is a Font instance or None. |
| 186 | return default |
| 187 | |
| 188 | def getFontPath(font): |
| 189 | """Answer the font file path for @font. |
no test coverage detected