Skip to content

Speed up preloads with duplicate code points #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions adafruit_bitmap_font/bdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,16 @@ def load_glyphs(self, code_points):
current_info = {}
current_y = 0
rounded_x = 1
total_remaining = len(code_points)
if isinstance(code_points, int):
remaining = set()
remaining.add(code_points)
else:
remaining = set(code_points)
for code_point in remaining:
if code_point in self._glyphs and self._glyphs[code_point]:
remaining.remove(code_point)
if not remaining:
return

x, _, _, _ = self.get_bounding_box()

Expand All @@ -113,6 +122,7 @@ def load_glyphs(self, code_points):
if desired_character:
bounds = current_info["bounds"]
shift = current_info["shift"]
gc.collect()
self._glyphs[code_point] = Glyph(current_info["bitmap"],
0,
bounds[0],
Expand All @@ -121,8 +131,8 @@ def load_glyphs(self, code_points):
bounds[3],
shift[0],
shift[1])
gc.collect()
if total_remaining == 0:
remaining.remove(code_point)
if not remaining:
return
desired_character = False
elif line.startswith(b"BBX"):
Expand All @@ -146,11 +156,9 @@ def load_glyphs(self, code_points):
elif line.startswith(b"ENCODING"):
_, code_point = line.split()
code_point = int(code_point)
if code_point == code_points or code_point in code_points:
total_remaining -= 1
if code_point not in self._glyphs or not self._glyphs[code_point]:
desired_character = True
current_info = {"bitmap": None, "bounds": None, "shift": None}
if code_point in remaining:
desired_character = True
current_info = {"bitmap": None, "bounds": None, "shift": None}
elif line.startswith(b"DWIDTH"):
if desired_character:
_, shift_x, shift_y = line.split()
Expand Down