30 lines
860 B
Python
30 lines
860 B
Python
#!/usr/bin/env python
|
|
import argparse
|
|
import colours
|
|
import fontdata
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('font', help='Text file describing the font')
|
|
parser.add_argument('start', help='First codepoint')
|
|
parser.add_argument('end', help='Last codepoint')
|
|
parser.add_argument('out', help='Output file')
|
|
parsed = parser.parse_args()
|
|
|
|
with open(parsed.font) as f:
|
|
char_width, char_height, atlas = fontdata.parse(f)
|
|
|
|
if parsed.start[0:2] == 'U+':
|
|
codepoint_start = int(parsed.start[2:], 16)
|
|
else:
|
|
codepoint_start = ord(parsed.start)
|
|
if parsed.end[0:2] == 'U+':
|
|
codepoint_end = int(parsed.end[2:], 16)
|
|
else:
|
|
codepoint_end = ord(parsed.end)
|
|
|
|
with open(parsed.out, 'wb') as f:
|
|
for codepoint in range(codepoint_start, codepoint_end + 1):
|
|
f.write(bytes(
|
|
sum(1<<(7-x) for x in range(8) if atlas[codepoint][y][x])
|
|
for y in range(16)
|
|
))
|