diff --git a/font/characters16.txt b/font/characters16.txt new file mode 100644 index 0000000..6a9245a --- /dev/null +++ b/font/characters16.txt @@ -0,0 +1 @@ +0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.:!?+-*/= diff --git a/font/convert.py b/font/convert.py new file mode 100755 index 0000000..418199d --- /dev/null +++ b/font/convert.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 + +from PIL import Image +import sys + +if len(sys.argv) < 3: + print("usage: {} ") + exit(1) + +inputfile = sys.argv[1] +charfile = sys.argv[2] +outputfile = sys.argv[3] + +im = Image.open(inputfile) + +cols, rows = im.size + +offset = 4 # hardcoded 'space' +startpos = offset + +fixedwidth = 9 + +charpos = [0] # hardcoded 'space' +chardata = [0x00] * offset # hardcoded 'space' +charwidth = [offset] # hardcoded 'space' + +for col in range(cols): + coldata = 0 + + for row in range(rows): + px = 0 if im.getpixel( (col, row) ) else 1 + coldata |= (px << row) + + print("{:016b}".format(coldata)) + + width = offset - startpos + + chardata.append(coldata) + + if width == fixedwidth: + charpos.append(startpos) + charwidth.append(width) + startpos = offset + else: + offset += 1 + +dataarray = ", ".join([hex(n) for n in chardata]) +posarray = ", ".join([str(n) for n in charpos]) +widtharray = ", ".join([str(n) for n in charwidth]) + +asciimap = [0 for i in range(256)] + +with open(charfile, "r") as cfile: + s = " " + cfile.read().strip() + for i in range(len(s)): + asciimap[ord(s[i])] = i + +asciimaparray = ", ".join([str(n) for n in asciimap]) + +with open(outputfile, "w") as ofile: + ofile.write(""" +#include "font16_data.h" + +const uint16_t font_data[{}] = {{ {} }}; +const uint16_t font_pos[{}] = {{ {} }}; +const uint8_t font_width[{}] = {{ {} }}; + +const uint8_t font_lut[256] = {{ {} }}; + +const uint8_t font_height = {}; +""".format(len(chardata), dataarray, len(charpos), posarray, len(charwidth), widtharray, asciimaparray, rows)) diff --git a/font/font_h16.xcf b/font/font_h16.xcf new file mode 100644 index 0000000..39f46f3 Binary files /dev/null and b/font/font_h16.xcf differ