Skip to content

Commit 4b663e6

Browse files
authored
Merge pull request #17 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents ffbfb56 + 0e13195 commit 4b663e6

File tree

11 files changed

+140
-116
lines changed

11 files changed

+140
-116
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
source actions-ci/install.sh
4141
- name: Pip install pylint, black, & Sphinx
4242
run: |
43-
pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme
43+
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
4444
- name: Library version
4545
run: git describe --dirty --always --tags
4646
- name: PyLint

adafruit_bitmap_font/bdf.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"""
4141

4242
import gc
43+
4344
try:
4445
from displayio import Glyph
4546
except ImportError:
@@ -49,8 +50,10 @@
4950
__version__ = "0.0.0-auto.0"
5051
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Bitmap_Font.git"
5152

53+
5254
class BDF(GlyphCache):
5355
"""Loads glyphs from a BDF file in the given bitmap_class."""
56+
5457
def __init__(self, f, bitmap_class):
5558
super().__init__()
5659
self.file = f
@@ -119,22 +122,24 @@ def load_glyphs(self, code_points):
119122
pass
120123
elif line.startswith(b"STARTCHAR"):
121124
# print(lineno, line.strip())
122-
#_, character_name = line.split()
125+
# _, character_name = line.split()
123126
character = True
124127
elif line.startswith(b"ENDCHAR"):
125128
character = False
126129
if desired_character:
127130
bounds = current_info["bounds"]
128131
shift = current_info["shift"]
129132
gc.collect()
130-
self._glyphs[code_point] = Glyph(current_info["bitmap"],
131-
0,
132-
bounds[0],
133-
bounds[1],
134-
bounds[2],
135-
bounds[3],
136-
shift[0],
137-
shift[1])
133+
self._glyphs[code_point] = Glyph(
134+
current_info["bitmap"],
135+
0,
136+
bounds[0],
137+
bounds[1],
138+
bounds[2],
139+
bounds[3],
140+
shift[0],
141+
shift[1],
142+
)
138143
remaining.remove(code_point)
139144
if not remaining:
140145
return
@@ -178,7 +183,7 @@ def load_glyphs(self, code_points):
178183
start = current_y * width
179184
x = 0
180185
for i in range(rounded_x):
181-
val = (bits >> ((rounded_x-i-1)*8)) & 0xFF
186+
val = (bits >> ((rounded_x - i - 1) * 8)) & 0xFF
182187
for j in range(7, -1, -1):
183188
if x >= width:
184189
break
@@ -189,5 +194,5 @@ def load_glyphs(self, code_points):
189194
x += 1
190195
current_y += 1
191196
elif metadata:
192-
#print(lineno, line.strip())
197+
# print(lineno, line.strip())
193198
pass

adafruit_bitmap_font/bitmap_font.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,23 @@
4545

4646
def load_font(filename, bitmap=None):
4747
"""Loads a font file. Returns None if unsupported."""
48+
# pylint: disable=import-outside-toplevel
4849
if not bitmap:
4950
import displayio
51+
5052
bitmap = displayio.Bitmap
5153
font_file = open(filename, "rb")
5254
first_four = font_file.read(4)
53-
#print(first_four)
5455
if filename.endswith("bdf") and first_four == b"STAR":
5556
from . import bdf
57+
5658
return bdf.BDF(font_file, bitmap)
5759
if filename.endswith("pcf") and first_four == b"\x01fcp":
5860
import pcf
61+
5962
return pcf.PCF(font_file)
6063
if filename.endswith("ttf") and first_four == b"\x00\x01\x00\x00":
6164
import ttf
65+
6266
return ttf.TTF(font_file)
6367
return None

adafruit_bitmap_font/glyph_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@
4747

4848
class GlyphCache:
4949
"""Caches glyphs loaded by a subclass."""
50+
5051
def __init__(self):
5152
self._glyphs = {}
5253

5354
def load_glyphs(self, code_points):
5455
"""Loads displayio.Glyph objects into the GlyphCache from the font."""
55-
pass
5656

5757
def get_glyph(self, code_point):
5858
"""Returns a displayio.Glyph for the given code point or None is unsupported."""

adafruit_bitmap_font/pcf.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,29 @@
55
import displayio
66
import struct
77

8-
_PCF_PROPERTIES = (1<<0)
9-
_PCF_ACCELERATORS = (1<<1)
10-
_PCF_METRICS = (1<<2)
11-
_PCF_BITMAPS = (1<<3)
12-
_PCF_INK_METRICS = (1<<4)
13-
_PCF_BDF_ENCODINGS = (1<<5)
14-
_PCF_SWIDTHS = (1<<6)
15-
_PCF_GLYPH_NAMES = (1<<7)
16-
_PCF_BDF_ACCELERATORS = (1<<8)
8+
_PCF_PROPERTIES = 1 << 0
9+
_PCF_ACCELERATORS = 1 << 1
10+
_PCF_METRICS = 1 << 2
11+
_PCF_BITMAPS = 1 << 3
12+
_PCF_INK_METRICS = 1 << 4
13+
_PCF_BDF_ENCODINGS = 1 << 5
14+
_PCF_SWIDTHS = 1 << 6
15+
_PCF_GLYPH_NAMES = 1 << 7
16+
_PCF_BDF_ACCELERATORS = 1 << 8
1717

1818
_PCF_DEFAULT_FORMAT = 0x00000000
1919
_PCF_INKBOUNDS = 0x00000200
2020
_PCF_ACCEL_W_INKBOUNDS = 0x00000100
2121
_PCF_COMPRESSED_METRICS = 0x00000100
2222

23-
_PCF_GLYPH_PAD_MASK = (3<<0) # See the bitmap table for explanation */
24-
_PCF_BYTE_MASK = (1<<2) # If set then Most Sig Byte First */
25-
_PCF_BIT_MASK = (1<<3) # If set then Most Sig Bit First */
26-
_PCF_SCAN_UNIT_MASK = (3<<4)
23+
_PCF_GLYPH_PAD_MASK = 3 << 0 # See the bitmap table for explanation */
24+
_PCF_BYTE_MASK = 1 << 2 # If set then Most Sig Byte First */
25+
_PCF_BIT_MASK = 1 << 3 # If set then Most Sig Bit First */
26+
_PCF_SCAN_UNIT_MASK = 3 << 4
2727

2828
# https://fontforge.github.io/en-US/documentation/reference/pcf-format/
2929

30+
3031
class PCF(GlyphCache):
3132
def __init__(self, f):
3233
super().__init__()
@@ -47,17 +48,17 @@ def read(self, format):
4748
def get_bounding_box(self):
4849
property_table_offset = self.tables[_PCF_PROPERTIES]["offset"]
4950
self.file.seek(property_table_offset)
50-
format, = self.read("<I")
51+
(format,) = self.read("<I")
5152

5253
if format & _PCF_BYTE_MASK == 0:
5354
raise RuntimeError("Only big endian supported")
54-
nprops, = self.read(">I")
55+
(nprops,) = self.read(">I")
5556
self.file.seek(property_table_offset + 8 + 9 * nprops)
5657

5758
pos = self.file.tell()
5859
if pos % 4 > 0:
5960
self.file.read(4 - pos % 4)
60-
string_size, = self.read(">I")
61+
(string_size,) = self.read(">I")
6162

6263
strings = self.file.read(string_size)
6364
string_map = {}
@@ -89,7 +90,7 @@ def load_glyphs(self, code_points):
8990

9091
x, _, _, _ = self.get_bounding_box()
9192
# create a scratch bytearray to load pixels into
92-
scratch_row = memoryview(bytearray((((x-1)//32)+1) * 4))
93+
scratch_row = memoryview(bytearray((((x - 1) // 32) + 1) * 4))
9394

9495
self.file.seek(0)
9596
while True:
@@ -104,7 +105,7 @@ def load_glyphs(self, code_points):
104105
pass
105106
elif line.startswith(b"STARTCHAR"):
106107
# print(lineno, line.strip())
107-
#_, character_name = line.split()
108+
# _, character_name = line.split()
108109
character = True
109110
elif line.startswith(b"ENDCHAR"):
110111
character = False
@@ -151,10 +152,12 @@ def load_glyphs(self, code_points):
151152
if desired_character:
152153
bits = int(line.strip(), 16)
153154
for i in range(rounded_x):
154-
val = (bits >> ((rounded_x-i-1)*8)) & 0xFF
155+
val = (bits >> ((rounded_x - i - 1) * 8)) & 0xFF
155156
scratch_row[i] = val
156-
current_info["bitmap"]._load_row(current_y, scratch_row[:bytes_per_row])
157+
current_info["bitmap"]._load_row(
158+
current_y, scratch_row[:bytes_per_row]
159+
)
157160
current_y += 1
158161
elif metadata:
159-
#print(lineno, line.strip())
162+
# print(lineno, line.strip())
160163
pass

adafruit_bitmap_font/ttf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
# https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6glyf.html
88

9+
910
class TTF:
1011
def __init__(self, f):
1112
f.seek(0)
@@ -41,7 +42,7 @@ def read(format):
4142
while f.tell() < glyf_offset + glyf_length:
4243
numberOfContours, xMin, yMin, xMax, yMax = read(">hhhhh")
4344

44-
if numberOfContours > 0: # Simple
45+
if numberOfContours > 0: # Simple
4546
print(numberOfContours)
4647
ends = []
4748
for _ in range(numberOfContours):

0 commit comments

Comments
 (0)