-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbdf.py
executable file
·35 lines (27 loc) · 957 Bytes
/
bdf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/python3
from bdflib import reader
import numpy as np
import os, sys
class bdf:
def __init__(self, fontfilename):
self.bdffont = reader.read_bdf(open(fontfilename, "rb"))
def letter(self, let):
character = self.bdffont.glyphs_by_codepoint[ord(let)].data
return [
list("{0:0=8b}".format(row).replace("0", ".").replace("1", "x"))
for row in reversed(character)
]
def trim_letter(self, let):
im = np.array(self.letter(let))
height, width = np.shape(im)
x_indices = np.where(im == "x")
if len(x_indices[1]) == 0:
return np.array(list("." * height))[:, np.newaxis]
column_first = np.min(x_indices[1])
column_last = np.max(x_indices[1])
return np.hstack(
(
im[:, column_first : column_last + 1],
np.array(list("." * height))[:, np.newaxis],
)
)