diff --git a/Makefile b/Makefile index 3d7d533..f2306a0 100644 --- a/Makefile +++ b/Makefile @@ -1,45 +1,45 @@ -all: MSX-Screen0.woff MSX-Screen0.ttf MSX-Screen1.woff MSX-Screen1.ttf +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") -pngs: characters.png +all: msx-screen0.woff + +pngs: mkdir -p pngs + +$(PNGS): characters.png | pngs 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 + +narrow-svgs: mkdir -p narrow-svgs - for i in pngs/???.png ;\ - do \ - f=$$(basename "$$i") ;\ - ./createsvg.sh "$$i" "narrow-svgs/$${f%%.png}.svg" 6 8 ;\ - done - touch narrow-svgs -wide-svgs: pngs +wide-svgs: 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 + +$(NARROWSVGS): narrow-svgs/%.svg: pngs/%.png | narrow-svgs + ./createsvg.sh "$<" "$@" 6 8 + +$(WIDESVGS): wide-svgs/%.svg: pngs/%.png | wide-svgs + ./createsvg.sh "$<" "$@" 8 8 + +svgs: $(NARROWSVGS) $(WIDESVGS) unicode2msx.txt: msx2utf8.py ./msx2utf8.py -l | awk '{ print $$2" "$$1 }' > unicode2msx.txt -msx-screen0.sfd msx-screen0.woff: svgs unicode2msx.txt importchars.py - fontforge -script importchars.py unicode-to-msx.txt narrow-svgs/ msx-screen0.sfd msx-screen0.woff +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.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 diff --git a/countchars.sh b/countchars.sh new file mode 100755 index 0000000..eedef2d --- /dev/null +++ b/countchars.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +gm identify -format "%W %H" "$1" | while read width height +do + cols=$((width / 8)) + rows=$((height / 8)) + seq -f "$2" 0 $((cols*rows - 1)) +done diff --git a/importchars.py b/importchars.py index 6c963d4..1b963ca 100644 --- a/importchars.py +++ b/importchars.py @@ -1,18 +1,37 @@ import fontforge +import argparse import sys import os +parser = argparse.ArgumentParser() +parser.add_argument('charmap') +parser.add_argument('svgdir') +parser.add_argument('--fullname') +parser.add_argument('--output-sfd') +parser.add_argument('--output-woff') +parser.add_argument('--output-ttf') + +args = parser.parse_args() +print(args) + font = fontforge.font() -f = open(sys.argv[1]) +font.ascent = 1024 - 128 +font.descent = 128 + +font.fullname = args.fullname + +f = open(args.charmap) for line in f: codepoint, msxcode = line.strip().split() codepoint = int(codepoint) msxcode = int(msxcode) glyph = font.createChar(codepoint) svgfile = "{:03d}.svg".format(msxcode) - glyph.importOutlines(os.path.join(sys.argv[2], svgfile)) + glyph.importOutlines(os.path.join(args.svgdir, svgfile)) + glyph.simplify() + glyph.autoHint() -font.save(sys.argv[3]) -font.generate(sys.argv[4]) +font.save(args.output_sfd) +font.generate(args.output_woff)