Speed up preloads with duplicate code points
The original logic wouldn't recognize duplicate characters in the given set to preload and therefore it'd read the whole font file looking for a character it already found. A set deduplicates the given characters at a small memory cost.
This commit is contained in:
parent
2f64725e6e
commit
fc75a1aade
1 changed files with 16 additions and 8 deletions
|
|
@ -89,7 +89,16 @@ class BDF(GlyphCache):
|
||||||
current_info = {}
|
current_info = {}
|
||||||
current_y = 0
|
current_y = 0
|
||||||
rounded_x = 1
|
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 cp in remaining:
|
||||||
|
if cp in self._glyphs and self._glyphs[cp]:
|
||||||
|
remaining.remove(cp)
|
||||||
|
if not remaining:
|
||||||
|
return
|
||||||
|
|
||||||
x, _, _, _ = self.get_bounding_box()
|
x, _, _, _ = self.get_bounding_box()
|
||||||
|
|
||||||
|
|
@ -113,6 +122,7 @@ class BDF(GlyphCache):
|
||||||
if desired_character:
|
if desired_character:
|
||||||
bounds = current_info["bounds"]
|
bounds = current_info["bounds"]
|
||||||
shift = current_info["shift"]
|
shift = current_info["shift"]
|
||||||
|
gc.collect()
|
||||||
self._glyphs[code_point] = Glyph(current_info["bitmap"],
|
self._glyphs[code_point] = Glyph(current_info["bitmap"],
|
||||||
0,
|
0,
|
||||||
bounds[0],
|
bounds[0],
|
||||||
|
|
@ -121,8 +131,8 @@ class BDF(GlyphCache):
|
||||||
bounds[3],
|
bounds[3],
|
||||||
shift[0],
|
shift[0],
|
||||||
shift[1])
|
shift[1])
|
||||||
gc.collect()
|
remaining.remove(code_point)
|
||||||
if total_remaining == 0:
|
if not remaining:
|
||||||
return
|
return
|
||||||
desired_character = False
|
desired_character = False
|
||||||
elif line.startswith(b"BBX"):
|
elif line.startswith(b"BBX"):
|
||||||
|
|
@ -146,9 +156,7 @@ class BDF(GlyphCache):
|
||||||
elif line.startswith(b"ENCODING"):
|
elif line.startswith(b"ENCODING"):
|
||||||
_, code_point = line.split()
|
_, code_point = line.split()
|
||||||
code_point = int(code_point)
|
code_point = int(code_point)
|
||||||
if code_point == code_points or code_point in code_points:
|
if code_point in remaining:
|
||||||
total_remaining -= 1
|
|
||||||
if code_point not in self._glyphs or not self._glyphs[code_point]:
|
|
||||||
desired_character = True
|
desired_character = True
|
||||||
current_info = {"bitmap": None, "bounds": None, "shift": None}
|
current_info = {"bitmap": None, "bounds": None, "shift": None}
|
||||||
elif line.startswith(b"DWIDTH"):
|
elif line.startswith(b"DWIDTH"):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue