#!/usr/bin/env bash # Generate a webpage that allows the comparison of two fonts. # Pass TTF font files as arguments if ! type fontforge &> /dev/null; then echo "ERROR: Missing dependency: fontforge" 1>&2; exit 1; fi OUTPUT="fontdiff.html" cat > "$OUTPUT" < Fontdiff $1 vs. $2

$1

$2

EOF # Use fontforge to list available glyphs of each font fontforge -lang=py -script - >> "$OUTPUT" < 0: print '
&#%s;
%s
'%(_class, glyph.unicode, glyph.glyphname) else: print '
'%(_class) font1 = fontforge.open("$1"); font2 = fontforge.open("$2"); glyphs1 = sorted(font1.glyphs(), key = lambda g: g.unicode) glyphs2 = sorted(font2.glyphs(), key = lambda g: g.unicode) while glyphs1 and glyphs2: if glyphs1[0].unicode > glyphs2[0].unicode: print_glyph(1, None) print_glyph(2, glyphs2.pop(0)) elif glyphs1[0].unicode < glyphs2[0].unicode: print_glyph(1, glyphs1.pop(0)) print_glyph(2, None) else: print_glyph(1, glyphs1.pop(0)) print_glyph(2, glyphs2.pop(0)) while glyphs1 or glyphs2: print_glyph(1, glyphs1.pop(0) if glyphs1 else None) print_glyph(2, glyphs2.pop(0) if glyphs2 else None) EOF cat >> "$OUTPUT" < EOF