mittos65/toolchain/build-uni_vga.sh

45 lines
1.3 KiB
Bash
Executable File

#!/bin/sh -e
# Download and convert the Unicode VGA font by Dmitry Yu. Bolkhovityanov
# https://www.inp.nsk.su/~bolkhov/files/fonts/univga/
mkdir -p /opt/external && cd /opt/external
[ -f "uni-vga.tgz" ] || wget "https://www.inp.nsk.su/~bolkhov/files/fonts/univga/uni-vga.tgz"
[ -d "uni_vga" ] || tar -xf uni-vga.tgz
cd uni_vga
python3 - << EOF
codepoint = 0
reading = False
chars = {}
with open("u_vga16.bdf") as fp:
while line := fp.readline():
if line.startswith("ENCODING"):
codepoint = int(line.split()[1])
continue
if line.startswith("BITMAP"):
values = []
while True:
line = fp.readline()
if line.startswith("ENDCHAR"):
break
values.append(int(line, 16))
chars[codepoint] = values
with open("u_vga16.termfont.inc", "w") as fp:
fp.write("// THIS FILE IS GENERATED BY toolchain/build-univga-font.sh\n")
fp.write(f"unsigned char font[{127-32}][16] =")
fp.write("{\n")
for codepoint in range(32, 127): # ONLY SAVE ASCII (for now)
fp.write("\t{" + ", ".join([f"0x{v:02X}" for v in chars.get(codepoint, [])]) + "},\n")
fp.write("};")
EOF
cp u_vga16.termfont.inc ${BUILDROOT}/src/libmittos/graphics/.