Return to Homepage

Return to Notes list

2023-12-05

Slicing cp437 Bitmap font pages

You sometimes run into oldschool fonts encoded as bitmap arrays (1, 2)

e.g.:

This snippet works well to get the position in the page corresponding to a character:

def char_to_pos(char: str) -> tuple:
    num = int(bytearray(char, "cp437")[0])
    row = num // 16
    col = num % 16
    return (row, col)