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_ids=`echo "$text" | $hb_shape $options --no-glyph-names --no-clusters --no-positions "$fontfile" | sed 's/[][]//g; s/|/,/g'`
51 cp "$fontfile" "$dir/font.ttf"
52 echo fonttools subset \
55 --layout-features='*' \
62 --layout-features='*' \
66 if ! test -s "$dir/font.subset.ttf"; then
67 echo "Subsetter didn't produce nonempty subset font in $dir/font.subset.ttf" >&2
71 # Verify that subset font produces same glyphs!
72 glyphs_subset=`echo "$text" | $hb_shape $options "$dir/font.subset.ttf"`
74 if ! test "x$glyphs" = "x$glyphs_subset"; then
75 echo "Subset font produced different glyphs!" >&2
76 echo "Perhaps font doesn't have glyph names; checking visually..." >&2
77 hb_view=${hb_shape/shape/view}
78 echo "$text" | $hb_view $options "$dir/font.ttf" --output-format=png --output-file="$dir/orig.png"
79 echo "$text" | $hb_view $options "$dir/font.subset.ttf" --output-format=png --output-file="$dir/subset.png"
80 if ! cmp "$dir/orig.png" "$dir/subset.png"; then
81 echo "Images differ. Please inspect $dir/*.png." >&2
82 echo "$glyphs" >> "$out"
83 echo "$glyphs_subset" >> "$out"
86 echo "Yep; all good." >&2
88 rm -f "$dir/subset.png"
92 sha1sum=`sha1sum "$dir/font.subset.ttf" | cut -d' ' -f1`
93 subset="data/in-house/fonts/$sha1sum.ttf"
94 mv "$dir/font.subset.ttf" "$subset"
96 # There ought to be an easier way to do this, but it escapes me...
97 unicodes_file=`mktemp`
99 echo "$unicodes" > "$unicodes_file"
100 echo "$glyphs" > "$glyphs_file"
102 exec 3<"$unicodes_file"
103 exec 4<"$glyphs_file"
104 relative_subset="$subset"
105 if test "$out" != "/dev/stdout"; then
106 relative_subset="$(/usr/bin/python -c 'import os, sys; print (os.path.relpath (sys.argv[1], sys.argv[2]))' "$subset" "$(dirname "$out")")"
108 while read uline <&3 && read gline <&4; do
109 echo "$relative_subset:$options:$uline:$gline" >> "$out"
113 rm -f "$dir/font.ttf"