Created
September 14, 2017 10:08
-
-
Save klange/fd0d2a59ee25eb05d295dedcb4a88caf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
from bdflib import reader | |
import sys | |
reload(sys) | |
sys.setdefaultencoding('utf8') | |
with open('knxt.bdf','r') as f: | |
font = reader.read_bdf(f) | |
ibm437_visible = lambda byt: byt.decode('ibm437').translate({ | |
0x01: u"\u263A", 0x02: u"\u263B", 0x03: u"\u2665", 0x04: u"\u2666", | |
0x05: u"\u2663", 0x06: u"\u2660", 0x07: u"\u2022", 0x08: u"\u25D8", | |
0x09: u"\u25CB", 0x0a: u"\u25D9", 0x0b: u"\u2642", 0x0c: u"\u2640", | |
0x0d: u"\u266A", 0x0e: u"\u266B", 0x0f: u"\u263C", 0x10: u"\u25BA", | |
0x11: u"\u25C4", 0x12: u"\u2195", 0x13: u"\u203C", 0x14: u"\u00B6", | |
0x15: u"\u00A7", 0x16: u"\u25AC", 0x17: u"\u21A8", 0x18: u"\u2191", | |
0x19: u"\u2193", 0x1a: u"\u2192", 0x1b: u"\u2190", 0x1c: u"\u221F", | |
0x1d: u"\u2194", 0x1e: u"\u25B2", 0x1f: u"\u25BC", 0x7f: u"\u2302", | |
}) | |
def to_bit_string(j): | |
out = [" "]*16 | |
x = int("0x" + j, 16) | |
for i in range(16): | |
if x & (1 << (15-i)): | |
out[i] = "#" | |
return ''.join(out) | |
print "uint16_t large_font[][20] = {" | |
for i in range(256): | |
c = ibm437_visible(chr(i)) | |
print "\t/*", i, ord(c), c, "*/" | |
print "\t{" | |
if ord(c) in font: | |
glyph = font[ord(c)] | |
for j in glyph.get_data(): | |
print "\t\t0x{j}, /* {bits} */".format(j=j,bits=to_bit_string(j)) | |
else: | |
for j in xrange(20): | |
print "\t\t0xFFFF," | |
print "\t}," | |
print "};" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment