|
28 | 28 |
|
29 | 29 | def load_font(filename, bitmap=None):
|
30 | 30 | """Loads a font file. Returns None if unsupported."""
|
31 |
| - # pylint: disable=import-outside-toplevel |
| 31 | + # pylint: disable=import-outside-toplevel, consider-using-with |
32 | 32 | if not bitmap:
|
33 | 33 | import displayio
|
34 | 34 |
|
35 | 35 | bitmap = displayio.Bitmap
|
36 |
| - with open(filename, "rb") as font_file: |
37 |
| - first_four = font_file.read(4) |
38 |
| - if filename.endswith("bdf") and first_four == b"STAR": |
39 |
| - from . import bdf |
| 36 | + font_file = open(filename, "rb") |
| 37 | + first_four = font_file.read(4) |
| 38 | + if filename.endswith("bdf") and first_four == b"STAR": |
| 39 | + from . import bdf |
40 | 40 |
|
41 |
| - return bdf.BDF(font_file, bitmap) |
42 |
| - if filename.endswith("pcf") and first_four == b"\x01fcp": |
43 |
| - from . import pcf |
| 41 | + return bdf.BDF(font_file, bitmap) |
| 42 | + if filename.endswith("pcf") and first_four == b"\x01fcp": |
| 43 | + from . import pcf |
44 | 44 |
|
45 |
| - return pcf.PCF(font_file, bitmap) |
46 |
| - if filename.endswith("ttf") and first_four == b"\x00\x01\x00\x00": |
47 |
| - from . import ttf |
| 45 | + return pcf.PCF(font_file, bitmap) |
| 46 | + if filename.endswith("ttf") and first_four == b"\x00\x01\x00\x00": |
| 47 | + from . import ttf |
48 | 48 |
|
49 |
| - return ttf.TTF(font_file, bitmap) |
| 49 | + return ttf.TTF(font_file, bitmap) |
50 | 50 |
|
51 | 51 | raise ValueError("Unknown magic number %r" % first_four)
|
0 commit comments