3 dir=`mktemp --directory`
8 if test "x${fontfile:0:1}" == 'x-'; then
9 echo "Specify font file before other options." >&2
13 if ! echo "$hb_shape" | grep -q 'hb-shape'; then
14 echo "Specify hb-shape (not hb-view, etc)." >&2
20 if test "x${arg:0:1}" == 'x-'; then
21 if echo "$arg" | grep -q ' '; then
22 echo "Space in argument is not supported: '$arg'." >&2
25 options="$options${options:+ }$arg"
29 echo "Too many arguments found... Use '=' notation for options: '$arg'" >&2
38 unicodes=`echo "$text" | ./hb-unicode-decode`
39 glyphs=`echo "$text" | $hb_shape $options "$fontfile"`
41 echo "hb-shape failed." >&2
45 cp "$fontfile" "$dir/font.ttf"
51 if ! test -s "$dir/font.ttf.subset"; then
52 echo "Subsetter didn't produce nonempty subset font in $dir/font.ttf.subset" >&2
56 # Verify that subset font produces same glyphs!
57 glyphs_subset=`echo "$text" | $hb_shape $options "$dir/font.ttf.subset"`
59 if ! test "x$glyphs" = "x$glyphs_subset"; then
60 echo "Subset font produced different glyphs!" >&2
61 echo "Perhaps font doesn't have glyph names; checking visually..." >&2
62 hb_view=${hb_shape/shape/view}
63 echo "$text" | $hb_view $options "$dir/font.ttf" --output-format=png --output-file="$dir/orig.png"
64 echo "$text" | $hb_view $options "$dir/font.ttf.subset" --output-format=png --output-file="$dir/subset.png"
65 if ! cmp "$dir/orig.png" "$dir/subset.png"; then
66 echo "Images differ. Please inspect $dir/*.png." >&2
71 echo "Yep; all good." >&2
73 rm -f "$dir/subset.png"
77 sha1sum=`sha1sum "$dir/font.ttf.subset" | cut -d' ' -f1`
78 subset="fonts/sha1sum/$sha1sum.ttf"
79 mv "$dir/font.ttf.subset" "$subset"
81 # There ought to be an easier way to do this, but it escapes me...
82 unicodes_file=`mktemp`
84 echo "$unicodes" > "$unicodes_file"
85 echo "$glyphs" > "$glyphs_file"
87 exec 3<"$unicodes_file"
89 while read uline <&3 && read gline <&4; do
90 echo "$subset:$options:$uline:$gline"