32 lines
726 B
Python
32 lines
726 B
Python
def parse(f):
|
|
dimensions = f.readline()
|
|
width, height = map(int, dimensions.split())
|
|
|
|
atlas = {}
|
|
while True:
|
|
line = f.readline()
|
|
if line == '': break
|
|
line = line.rstrip('\n')
|
|
|
|
if line[0:2] == 'U+':
|
|
codepoint = int(line[2:], 16)
|
|
glyph = [
|
|
[c == '*' for c in f.readline().rstrip('\n')] for _ in range(height)
|
|
]
|
|
atlas[codepoint] = glyph
|
|
|
|
return width, height, atlas
|
|
|
|
def serialize(f, width, height, atlas):
|
|
f.write(f'{width} {height}\n')
|
|
for codepoint, glyph in sorted(atlas.items()):
|
|
assert len(glyph) == height
|
|
f.write(f'U+{codepoint:04X}\n')
|
|
for line in glyph:
|
|
assert len(line) == width
|
|
for pixel in line:
|
|
if pixel:
|
|
f.write('*')
|
|
else:
|
|
f.write('.')
|
|
f.write('\n')
|