Final touches, both fonts are now created automatically

This commit is contained in:
Andy Teijelo Pérez 2016-09-15 13:53:50 -04:00
parent e18cb54f9c
commit 45f09af09c
2 changed files with 34 additions and 21 deletions

View file

@ -2,7 +2,10 @@ PNGS = $(shell ./countchars.sh characters.png "pngs/%03.0f.png")
NARROWSVGS = $(shell ./countchars.sh characters.png "narrow-svgs/%03.0f.svg")
WIDESVGS = $(shell ./countchars.sh characters.png "wide-svgs/%03.0f.svg")
all: msx-screen0.woff
SCREEN0_OUTPUTS = msx-screen0.sfd msx-screen0.woff msx-screen0.ttf
SCREEN1_OUTPUTS = msx-screen1.sfd msx-screen1.woff msx-screen1.ttf
all: $(SCREEN0_OUTPUTS) $(SCREEN1_OUTPUTS)
pngs:
mkdir -p pngs
@ -27,30 +30,31 @@ svgs: $(NARROWSVGS) $(WIDESVGS)
unicode2msx.txt: msx2utf8.py
./msx2utf8.py -l | awk '{ print $$2" "$$1 }' > unicode2msx.txt
msx-screen0.sfd msx-screen0.woff: $(NARROWSVGS) unicode2msx.txt importchars.py
fontforge -script importchars.py \
$(SCREEN0_OUTPUTS): $(NARROWSVGS) unicode2msx.txt createfont.py
./createfont.py \
--output-sfd msx-screen0.sfd \
--output-woff msx-screen0.woff \
--fullname 'MSX-Screen0' \
--output-ttf msx-screen0.ttf \
--familyname 'MSX' \
--fontname 'MSX-Screen0' \
--fullname 'MSX Screen 0' \
--width 768 \
unicode2msx.txt narrow-svgs
msx-screen0.sfd msx-screen0.woff: $(NARROWSVGS) unicode2msx.txt importchars.py
fontforge -script importchars.py \
--output-sfd msx-screen0.sfd \
--output-woff msx-screen0.woff \
--fullname 'MSX-Screen0' \
unicode2msx.txt narrow-svgs
MSX-Screen0.woff: msx-screen0.sfd
MSX-Screen0.ttf: msx-screen0.sfd
MSX-Screen1.woff: msx-screen1.sfd
MSX-Screen1.ttf: msx-screen1.sfd
$(SCREEN1_OUTPUTS): $(WIDESVGS) unicode2msx.txt createfont.py
./createfont.py \
--output-sfd msx-screen1.sfd \
--output-woff msx-screen1.woff \
--output-ttf msx-screen1.ttf \
--familyname 'MSX' \
--fontname 'MSX-Screen1' \
--fullname 'MSX Screen 1' \
--width 1024 \
unicode2msx.txt wide-svgs
.PHONY: clean
clean:
rm -rf narrow-svgs wide-svgs pngs
rm -f $(SCREEN0_OUTPUTS) $(SCREEN1_OUTPUTS)
rm -f unicode2msx.txt

13
importchars.py → createfont.py Normal file → Executable file
View file

@ -1,3 +1,5 @@
#!/usr/bin/env python
import fontforge
import argparse
import sys
@ -6,20 +8,24 @@ import os
parser = argparse.ArgumentParser()
parser.add_argument('charmap')
parser.add_argument('svgdir')
parser.add_argument('--fontname')
parser.add_argument('--fullname')
parser.add_argument('--familyname')
parser.add_argument('--width', type=int)
parser.add_argument('--output-sfd')
parser.add_argument('--output-woff')
parser.add_argument('--output-ttf')
args = parser.parse_args()
print(args)
font = fontforge.font()
font.ascent = 1024 - 128
font.descent = 128
font.fontname = args.fontname
font.fullname = args.fullname
font.familyname = args.familyname
font.copyright = "Created by Andy Teijelo with FontForge 2.0 (http://fontforge.sf.net)"
f = open(args.charmap)
for line in f:
@ -29,9 +35,12 @@ for line in f:
glyph = font.createChar(codepoint)
svgfile = "{:03d}.svg".format(msxcode)
glyph.importOutlines(os.path.join(args.svgdir, svgfile))
glyph.width = args.width
glyph.simplify()
glyph.simplify(1.02, "forcelines")
glyph.autoHint()
font.save(args.output_sfd)
font.generate(args.output_woff)
font.generate(args.output_ttf)