Working on fully automating the fontforge interaction

master
Andy Teijelo Pérez 2016-09-15 12:12:34 -04:00
parent e618ef401f
commit 0ea692c54a
4 changed files with 64 additions and 3 deletions

View File

@ -5,17 +5,36 @@ pngs: characters.png
gm convert -crop 8x8 characters.png +adjoin pngs/%03d.png
touch pngs
#PNGS=$(wildcard pngs/*.png)
#SVGS=$(patsubst pngs/%.png, %.svg, $(PNGS))
#
#%.svg: pngs/%.png | pngs
# echo $@ $<
#
#$(SVGS): %.svg: pngs/%.png | pngs
# echo $@ $<
# touch "$@"
svgs: narrow-svgs wide-svgs
narrow-svgs: pngs
mkdir -p narrow-svgs
for i in pngs/???.png ;\
do \
f=$$(basename "$$i") ;\
gm convert "$$i" -crop 6x8 -filter Point -resize 48x64 -black-threshold 50%% "$$f.bmp" ;\
potrace "$$f.bmp" -o narrow-svgs/"$${f%%.png}.svg" -i -a 1.01 -s -z black ;\
rm -f "$$f.bmp" ;\
./createsvg.sh "$$i" "narrow-svgs/$${f%%.png}.svg" 6 8 ;\
done
touch narrow-svgs
wide-svgs: pngs
mkdir -p wide-svgs
for i in pngs/???.png ;\
do \
f=$$(basename "$$i") ;\
./createsvg.sh "$$i" "wide-svgs/$${f%%.png}.svg" 8 8 ;\
done
touch wide-svgs
MSX-Screen0.woff: msx-screen0.sfd
MSX-Screen0.ttf: msx-screen0.sfd
@ -23,3 +42,8 @@ MSX-Screen0.ttf: msx-screen0.sfd
MSX-Screen1.woff: msx-screen1.sfd
MSX-Screen1.ttf: msx-screen1.sfd
.PHONY: clean
clean:
rm -rf narrow-svgs wide-svgs pngs

16
createsvg.sh 100755
View File

@ -0,0 +1,16 @@
#!/bin/sh
INPUT="$1"
OUTPUT="$2"
CROPWIDTH="$3"
CROPHEIGHT="$4"
W=$CROPWIDTH
H=$CROPHEIGHT
SW=$((W * 8))
SH=$((H * 8))
BMP="${INPUT}.bmp"
gm convert "$INPUT" -crop ${W}x${H} -filter Point -resize ${SW}x${SH} -black-threshold 50%% "$BMP"
potrace "$BMP" -o "$OUTPUT" -i -a 1.01 -s -z black
rm -f "$BMP"

19
importchars.py 100644
View File

@ -0,0 +1,19 @@
import fontforge
import sys
import os
font = fontforge.font()
f = open(sys.argv[1])
for line in f:
codepoint, msxcode = line.strip().split()
codepoint = int(codepoint)
msxcode = int(msxcode)
glyph = font.createChar(codepoint)
svgfile = "{:03d}.svg".format(msxcode)
print("importing", svgfile)
glyph.importOutlines(os.path.join(sys.argv[2], svgfile))
font.save(sys.argv[3])
font.generate(sys.argv[4])

View File

@ -49,6 +49,8 @@ if len(sys.argv) < 2:
if sys.argv[1] == '-l':
for m,c in msxchars():
if m < 32 or m == 127:
continue
try:
n = name(c)
except ValueError: