42 lines
1 KiB
Python
42 lines
1 KiB
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('out', help='PPM file with the rendered output')
|
|
parsed = parser.parse_args()
|
|
|
|
lines = []
|
|
try:
|
|
while True:
|
|
lines.append(input())
|
|
except EOFError:
|
|
pass
|
|
|
|
rows = len(lines)
|
|
columns = max(map(len, lines))
|
|
|
|
with open(parsed.font) as f:
|
|
char_width, char_height, atlas = fontdata.parse(f)
|
|
|
|
width = columns * char_width
|
|
height = rows * char_height
|
|
|
|
with open(parsed.out, 'wb') as f:
|
|
f.write(f'P6\n{width} {height}\n255\n'.encode())
|
|
for row in range(rows):
|
|
for y in range(char_height):
|
|
for column in range(columns):
|
|
if len(lines[row]) <= column:
|
|
f.write(colours.bg1 * char_width)
|
|
continue
|
|
codepoint = ord(lines[row][column])
|
|
for x in range(char_width):
|
|
if codepoint in atlas and atlas[codepoint][y][x]:
|
|
f.write(colours.fg)
|
|
elif codepoint not in atlas and codepoint != 0x20:
|
|
f.write(colours.notchar)
|
|
else:
|
|
f.write(colours.bg1)
|