2017-12-19 21:28:42 +00:00
|
|
|
#!/usr/bin/env python2
|
|
|
|
|
|
|
|
import os
|
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
glyphmap = {
|
2018-01-24 19:05:16 +00:00
|
|
|
"0": "0",
|
|
|
|
"1": "1",
|
|
|
|
"2": "2",
|
|
|
|
"3": "3",
|
|
|
|
"4": "4",
|
|
|
|
"5": "5",
|
|
|
|
"6": "6",
|
|
|
|
"7": "7",
|
|
|
|
"8": "8",
|
|
|
|
"9": "9",
|
|
|
|
"al": "a",
|
2017-12-19 21:28:42 +00:00
|
|
|
"ampersand": "&",
|
|
|
|
"apostrophe": "'",
|
2018-01-24 19:05:16 +00:00
|
|
|
"apple": 1,
|
|
|
|
"arrow-down": 3,
|
|
|
|
"arrow-down-lines": 2,
|
|
|
|
"arrow-left": 5,
|
|
|
|
"arrow-left-lines": 4,
|
|
|
|
"arrow-return": 6,
|
|
|
|
"arrow-right": 8,
|
|
|
|
"arrow-right-lines": 7,
|
|
|
|
"arrow-up": 11,
|
|
|
|
"arrow-up-lines": 9,
|
2017-12-19 21:28:42 +00:00
|
|
|
"asterisk": "*",
|
|
|
|
"at": "@",
|
2018-01-24 19:05:16 +00:00
|
|
|
"au": "A",
|
2017-12-19 21:28:42 +00:00
|
|
|
"backslash": "\\",
|
|
|
|
"bar": "|",
|
2018-01-24 19:05:16 +00:00
|
|
|
"bl": "b",
|
2017-12-19 21:28:42 +00:00
|
|
|
"blank": " ",
|
2018-01-24 19:05:16 +00:00
|
|
|
"bu": "B",
|
2017-12-19 21:28:42 +00:00
|
|
|
"caret": "^",
|
2018-01-24 19:05:16 +00:00
|
|
|
"check": 13,
|
|
|
|
"check-inverse": 12,
|
|
|
|
"checkerboard1": 14,
|
|
|
|
"checkerboard2": 15,
|
|
|
|
"cl": "c",
|
2017-12-19 21:28:42 +00:00
|
|
|
"colon": ":",
|
|
|
|
"comma": ",",
|
2018-01-24 19:05:16 +00:00
|
|
|
"crosshairs": 16,
|
|
|
|
"cu": "C",
|
|
|
|
"diamond": 17,
|
|
|
|
"dl": "d",
|
2017-12-19 21:28:42 +00:00
|
|
|
"dollar": "$",
|
2018-01-24 19:05:16 +00:00
|
|
|
"du": "D",
|
|
|
|
"el": "e",
|
|
|
|
"ellipsis": 18,
|
2017-12-19 21:28:42 +00:00
|
|
|
"emark": "!",
|
|
|
|
"equal": "=",
|
2018-01-24 19:05:16 +00:00
|
|
|
"eu": "E",
|
|
|
|
"file-left": 19,
|
|
|
|
"file-right": 20,
|
|
|
|
"finger": 21,
|
|
|
|
"fl": "f",
|
|
|
|
"fu": "F",
|
|
|
|
"gl": "g",
|
2017-12-19 21:28:42 +00:00
|
|
|
"grave": "`",
|
2018-01-24 19:05:16 +00:00
|
|
|
"gu": "G",
|
|
|
|
"hl": "h",
|
|
|
|
"hourglass": 22,
|
|
|
|
"hu": "H",
|
2017-12-19 21:28:42 +00:00
|
|
|
"hyphen": "-",
|
2018-01-24 19:05:16 +00:00
|
|
|
"il": "i",
|
|
|
|
"iu": "I",
|
|
|
|
"jl": "j",
|
|
|
|
"ju": "J",
|
|
|
|
"kl": "k",
|
|
|
|
"ku": "K",
|
2017-12-19 21:28:42 +00:00
|
|
|
"langle": "<",
|
|
|
|
"lbrace": "{",
|
|
|
|
"lbracket": "[",
|
2018-01-24 19:05:16 +00:00
|
|
|
"line-box": 23,
|
|
|
|
"line-left": 25,
|
|
|
|
"line-left-bottom": 24,
|
|
|
|
"line-middle": 26,
|
|
|
|
"line-right": 28,
|
|
|
|
"line-right-inverse": 27,
|
|
|
|
"line-top": 30,
|
|
|
|
"line-top-bottom": 29,
|
|
|
|
"ll": "l",
|
2017-12-19 21:28:42 +00:00
|
|
|
"lparen": "(",
|
2018-01-24 19:05:16 +00:00
|
|
|
"lu": "L",
|
|
|
|
"mailbox": 31,
|
|
|
|
"ml": "m",
|
|
|
|
"mu": "M",
|
|
|
|
"nl": "n",
|
|
|
|
"nu": "N",
|
|
|
|
"ol": "o",
|
2018-01-24 21:05:29 +00:00
|
|
|
"open-apple": 0,
|
2018-01-24 19:05:16 +00:00
|
|
|
"ou": "O",
|
2017-12-19 21:28:42 +00:00
|
|
|
"percent": "%",
|
|
|
|
"perfcurs": 10,
|
|
|
|
"period": ".",
|
2018-01-24 19:05:16 +00:00
|
|
|
"pl": "p",
|
2017-12-19 21:28:42 +00:00
|
|
|
"plus": "+",
|
2018-01-24 19:05:16 +00:00
|
|
|
"pointer": 127,
|
2017-12-19 21:28:42 +00:00
|
|
|
"pound": "#",
|
2018-01-24 19:05:16 +00:00
|
|
|
"pu": "P",
|
|
|
|
"ql": "q",
|
2017-12-19 21:28:42 +00:00
|
|
|
"qmark": "?",
|
2018-01-24 19:05:16 +00:00
|
|
|
"qu": "Q",
|
2017-12-19 21:28:42 +00:00
|
|
|
"quote": '"',
|
|
|
|
"rangle": ">",
|
|
|
|
"rbrace": "}",
|
|
|
|
"rbracket": "]",
|
2018-01-24 19:05:16 +00:00
|
|
|
"rl": "r",
|
2017-12-19 21:28:42 +00:00
|
|
|
"rparen": ")",
|
2018-01-24 19:05:16 +00:00
|
|
|
"ru": "R",
|
2017-12-19 21:28:42 +00:00
|
|
|
"semicolon": ";",
|
2018-01-24 19:05:16 +00:00
|
|
|
"sl": "s",
|
2017-12-19 21:28:42 +00:00
|
|
|
"slash": "/",
|
2018-01-24 19:05:16 +00:00
|
|
|
"su": "S",
|
2017-12-19 21:28:42 +00:00
|
|
|
"tilde": "~",
|
|
|
|
"tl": "t",
|
|
|
|
"tu": "T",
|
2018-01-24 19:05:16 +00:00
|
|
|
"ul": "u",
|
|
|
|
"underscore": "_",
|
2017-12-19 21:28:42 +00:00
|
|
|
"uu": "U",
|
2018-01-24 19:05:16 +00:00
|
|
|
"vl": "v",
|
2017-12-19 21:28:42 +00:00
|
|
|
"vu": "V",
|
2018-01-24 19:05:16 +00:00
|
|
|
"wl": "w",
|
2017-12-19 21:28:42 +00:00
|
|
|
"wu": "W",
|
2018-01-24 19:05:16 +00:00
|
|
|
"xl": "x",
|
2017-12-19 21:28:42 +00:00
|
|
|
"xu": "X",
|
2018-01-24 19:05:16 +00:00
|
|
|
"yl": "y",
|
2017-12-19 21:28:42 +00:00
|
|
|
"yu": "Y",
|
2018-01-24 19:05:16 +00:00
|
|
|
"zl": "z",
|
2017-12-19 21:28:42 +00:00
|
|
|
"zu": "Z",
|
|
|
|
}
|
|
|
|
|
|
|
|
def build_font(name, path, gridfiles):
|
|
|
|
img = Image.new("RGB", (112, 64))
|
|
|
|
pix = img.load()
|
|
|
|
for gridfile in gridfiles:
|
|
|
|
with open(os.path.join(path, gridfile)) as openf:
|
|
|
|
glyphname = gridfile.split('.')[0]
|
|
|
|
glyphchar = name_to_char(glyphname)
|
|
|
|
render(glyph_coords(glyphchar), glyphchar, openf.read(), pix)
|
2017-12-19 22:13:04 +00:00
|
|
|
img.save('./fonts/' + name + '.bmp')
|
2017-12-19 21:28:42 +00:00
|
|
|
|
|
|
|
def name_to_char(name):
|
2018-01-24 21:05:29 +00:00
|
|
|
if not glyphmap[name] and glyphmap[name] is not 0:
|
2017-12-19 21:28:42 +00:00
|
|
|
raise Exception('unknown glyph')
|
|
|
|
return glyphmap[name]
|
|
|
|
|
|
|
|
|
|
|
|
# Return the row and column that a character should be saved in our bitmap
|
|
|
|
# font.
|
|
|
|
def glyph_coords(ch):
|
|
|
|
if type(ch) == int:
|
|
|
|
code = ch
|
|
|
|
else:
|
|
|
|
code = ord(ch)
|
|
|
|
|
|
|
|
row = (code & 0xf0) >> 4
|
|
|
|
col = code & 0x0f
|
|
|
|
return (row, col)
|
|
|
|
|
|
|
|
def render_row(offset, row, line, pix):
|
|
|
|
row_offset, col_offset = offset
|
|
|
|
row_offset = row_offset * 8
|
|
|
|
col_offset = col_offset * 7
|
|
|
|
col = 0
|
|
|
|
for c in line[1:]:
|
|
|
|
if c == 'o':
|
|
|
|
pix[col_offset + col, row_offset + row] = (255, 255, 255)
|
|
|
|
col = col + 1
|
|
|
|
|
|
|
|
def render(offset, ch, grid, pix):
|
|
|
|
row, col = glyph_coords(ch)
|
|
|
|
lines = grid.split("\n")
|
|
|
|
render_row(offset, 0, lines[1], pix)
|
|
|
|
render_row(offset, 1, lines[2], pix)
|
|
|
|
render_row(offset, 2, lines[3], pix)
|
|
|
|
render_row(offset, 3, lines[4], pix)
|
|
|
|
render_row(offset, 4, lines[5], pix)
|
|
|
|
render_row(offset, 5, lines[6], pix)
|
|
|
|
render_row(offset, 6, lines[7], pix)
|
|
|
|
render_row(offset, 7, lines[8], pix)
|
|
|
|
|
|
|
|
for root, subdirs, subfiles in os.walk('./fonts'):
|
|
|
|
if subdirs == []:
|
|
|
|
fontname = root.replace('./fonts/', '')
|
|
|
|
fontname = fontname.replace('/', '-')
|
|
|
|
build_font(fontname, root, subfiles)
|