text
stringlengths
1
93.6k
# offsets inside section
h.char_offsets = [2 + 128 + 256] + [read_uint16(f) for _ in range(127)]
read_uint16(f) # alignment
assert f.tell() == 2 + 128 + 256
save_ff_header(ff_name, h)
# Glyphs
f.seek(h.char_offsets[1])
for ch in range(1,128):
width = h.char_widths[ch]
height = h.max_height
offset = h.char_offsets[ch]
assert f.tell() == offset
if width == 0:
continue
img = Image.new("P", (width,height))
attach_palette(img, pal)
y = 0
while y < height:
x = 0
while 1:
byte = read_uint8(f)
col = (byte & 0b11000000) >> 6
img.putpixel((x,y), col)
x += 1
if x == width:
break
col = (byte & 0b00110000) >> 4
img.putpixel((x,y), col)
x += 1
if x == width:
break
col = (byte & 0b00001100) >> 2
img.putpixel((x,y), col)
x += 1
if x == width:
break
col = (byte & 0b00000011) >> 0
img.putpixel((x,y), col)
x += 1
if x == width:
break
y += 1
oname = "{}.{:03}.png".format(ff_name, ch)
img.save(oname)
output(oname)
def export_ftb(ff_name, scale=3):
""" Export font to custom binary ftb format
"""
h = load_ff_header(ff_name)
with open(ff_name+'.ftb', 'wb') as f:
write_uint32(f, 0x46425446)
write_uint32(f, 0x00000001)
write_uint32(f, 0x44414548)
write_int16(f, h.max_height*scale)
write_int16(f, 0)
write_int16(f, 0)
write_uint32(f, 0x50594c47)
write_uint32(f, 128)
cpos_y = 0
for i in range(128):
width = h.char_widths[i]*scale
height = h.max_height*scale
pos_x = 0
pos_y = cpos_y
advance = width
bearing_x = 0
bearing_y = 0
write_uint32(f, i) # code
write_int16(f, bearing_x);
write_int16(f, bearing_y);
write_int16(f, advance);
write_int16(f, width);
write_int16(f, height);