6 if test "x${1:0:3}" == 'x-o='; then
13 if test "x${fontfile:0:1}" == 'x-'; then
14 echo "Specify font file before other options." >&2
18 if ! echo "$hb_shape" | grep -q 'hb-shape'; then
19 echo "Specify hb-shape (not hb-view, etc): got "$hb_shape"." >&2
25 if test "x${arg:0:1}" == 'x-'; then
26 if echo "$arg" | grep -q ' '; then
27 echo "Space in argument is not supported: '$arg'." >&2
30 options="$options${options:+ }$arg"
34 echo "Too many arguments found... Use '=' notation for options: '$arg'" >&2
43 unicodes=`echo "$text" | ./hb-unicode-decode`
44 glyphs=`echo "$text" | $hb_shape $options "$fontfile"`
46 echo "hb-shape failed." >&2
49 glyph_names=`echo "$text" | $hb_shape $options --no-clusters --no-positions "$fontfile" | sed 's/[][]//g; s/|/,/g'`
51 cp "$fontfile" "$dir/font.ttf"
55 --layout-features='*' \
57 --glyphs="$glyph_names" \
59 if ! test -s "$dir/font.subset.ttf"; then
60 echo "Subsetter didn't produce nonempty subset font in $dir/font.subset.ttf" >&2
64 # Verify that subset font produces same glyphs!
65 glyphs_subset=`echo "$text" | $hb_shape $options "$dir/font.subset.ttf"`
67 if ! test "x$glyphs" = "x$glyphs_subset"; then
68 echo "Subset font produced different glyphs!" >&2
69 echo "Perhaps font doesn't have glyph names; checking visually..." >&2
70 hb_view=${hb_shape/shape/view}
71 echo "$text" | $hb_view $options "$dir/font.ttf" --output-format=png --output-file="$dir/orig.png"
72 echo "$text" | $hb_view $options "$dir/font.subset.ttf" --output-format=png --output-file="$dir/subset.png"
73 if ! cmp "$dir/orig.png" "$dir/subset.png"; then
74 echo "Images differ. Please inspect $dir/*.png." >&2
75 echo "$glyphs" >> "$out"
76 echo "$glyphs_subset" >> "$out"
79 echo "Yep; all good." >&2
81 rm -f "$dir/subset.png"
85 sha1sum=`sha1sum "$dir/font.subset.ttf" | cut -d' ' -f1`
86 subset="data/in-house/fonts/$sha1sum.ttf"
87 mv "$dir/font.subset.ttf" "$subset"
89 # There ought to be an easier way to do this, but it escapes me...
90 unicodes_file=`mktemp`
92 echo "$unicodes" > "$unicodes_file"
93 echo "$glyphs" > "$glyphs_file"
95 exec 3<"$unicodes_file"
97 relative_subset="$subset"
98 if test "$out" != "/dev/stdout"; then
99 relative_subset="$(/usr/bin/python -c 'import os, sys; print (os.path.relpath (sys.argv[1], sys.argv[2]))' "$subset" "$(dirname "$out")")"
101 while read uline <&3 && read gline <&4; do
102 echo "$relative_subset:$options:$uline:$gline" >> "$out"
106 rm -f "$dir/font.ttf"