6 if test "x$1" == 'x-o'; then
14 if test "x${fontfile:0:1}" == 'x-'; then
15 echo "Specify font file before other options." >&2
19 if ! echo "$hb_shape" | grep -q 'hb-shape'; then
20 echo "Specify hb-shape (not hb-view, etc): got "$hb_shape"." >&2
26 if test "x${arg:0:1}" == 'x-'; then
27 if echo "$arg" | grep -q ' '; then
28 echo "Space in argument is not supported: '$arg'." >&2
31 options="$options${options:+ }$arg"
35 echo "Too many arguments found... Use '=' notation for options: '$arg'" >&2
44 unicodes=`echo "$text" | ./hb-unicode-decode`
45 glyphs=`echo "$text" | $hb_shape $options "$fontfile"`
47 echo "hb-shape failed." >&2
50 glyph_ids=`echo "$text" | $hb_shape $options --no-glyph-names --no-clusters --no-positions "$fontfile" | sed 's/[][]//g; s/|/,/g'`
52 cp "$fontfile" "$dir/font.ttf"
53 echo fonttools subset \
56 --layout-features='*' \
63 --layout-features='*' \
67 if ! test -s "$dir/font.subset.ttf"; then
68 echo "Subsetter didn't produce nonempty subset font in $dir/font.subset.ttf" >&2
72 # Verify that subset font produces same glyphs!
73 glyphs_subset=`echo "$text" | $hb_shape $options "$dir/font.subset.ttf"`
75 if ! test "x$glyphs" = "x$glyphs_subset"; then
76 echo "Subset font produced different glyphs!" >&2
77 echo "Perhaps font doesn't have glyph names; checking visually..." >&2
78 hb_view=${hb_shape/shape/view}
79 echo "$text" | $hb_view $options "$dir/font.ttf" --output-format=png --output-file="$dir/orig.png"
80 echo "$text" | $hb_view $options "$dir/font.subset.ttf" --output-format=png --output-file="$dir/subset.png"
81 if ! cmp "$dir/orig.png" "$dir/subset.png"; then
82 echo "Images differ. Please inspect $dir/*.png." >&2
83 echo "$glyphs" >> "$out"
84 echo "$glyphs_subset" >> "$out"
87 echo "Yep; all good." >&2
89 rm -f "$dir/subset.png"
93 sha1sum=`sha1sum "$dir/font.subset.ttf" | cut -d' ' -f1`
94 subset="data/in-house/fonts/$sha1sum.ttf"
95 mv "$dir/font.subset.ttf" "$subset"
97 # There ought to be an easier way to do this, but it escapes me...
98 unicodes_file=`mktemp`
100 echo "$unicodes" > "$unicodes_file"
101 echo "$glyphs" > "$glyphs_file"
103 exec 3<"$unicodes_file"
104 exec 4<"$glyphs_file"
105 relative_subset="$subset"
106 if test "$out" != "/dev/stdout"; then
107 relative_subset="$(/usr/bin/python -c 'import os, sys; print (os.path.relpath (sys.argv[1], sys.argv[2]))' "$subset" "$(dirname "$out")")"
109 while read uline <&3 && read gline <&4; do
110 echo "$relative_subset:$options:$uline:$gline" >> "$out"
114 rm -f "$dir/font.ttf"