8000 Use FONTBOUNDINGBOX for font metrics · losingrose/circuitpython@7c908b0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7c908b0

Browse files
committed
Use FONTBOUNDINGBOX for font metrics
Instead of iterating over all the glyphs and calculating the maximum width and height, use the FONTBOUNDINGBOX to determine the size of a tile for terminalio. This works better with fonts such as generated by FontForge, that don't include the empty space in the glyph bitmap itself. It also lets the font author specify vertical spacing they want. I only tested this with the default font and with one I generated with FontForge.
1 parent f0a112e commit 7c908b0

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

tools/gen_display_resources.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def _load_row(self, y, row):
2929
self.rows[y] = bytes(row)
3030

3131
f = bitmap_font.load_font(args.font, BitmapStub)
32-
real_bb = [0, 0]
3332

3433
# Load extra characters from the sample file.
3534
sample_characters = set()
@@ -61,13 +60,11 @@ def _load_row(self, y, row):
6160
print("Font missing character:", c, ord(c))
6261
filtered_characters = filtered_characters.replace(c, "")
6362
continue
64-
x, y, dx, dy = g["bounds"]
6563
if g["shift"][1] != 0:
6664
raise RuntimeError("y shift")
67-
real_bb[0] = max(real_bb[0], x - dx)
68-
real_bb[1] = max(real_bb[1], y - dy)
6965

70-
tile_x, tile_y = real_bb
66+
x, y, dx, dy = f.get_bounding_box()
67+
tile_x, tile_y = x - dx, y - dy
7168
total_bits = tile_x * len(all_characters)
7269
total_bits += 32 - total_bits % 32
7370
bytes_per_row = total_bits // 8

0 commit comments

Comments
 (0)
0