a69157f734e372b7a68e0cdd872f8afe68312c08
[platform/upstream/harfbuzz.git] / test / shaping / record-test.sh
1 #!/bin/bash
2
3 dir=`mktemp --directory`
4
5 hb_shape=$1
6 shift
7 fontfile=$1
8 shift
9 hb_shape="$hb_shape $@"
10 unicodes=`./hb-unicode-decode`
11 text=`./hb-unicode-encode "$unicodes"`
12 glyphs=`echo "$text" | $hb_shape "$fontfile"`
13
14 cp "$fontfile" "$dir/font.ttf"
15 pyftsubset \
16         --glyph-names \
17         "$dir/font.ttf" \
18         --text="$text"
19 if ! test -s "$dir/font.ttf.subset"; then
20         echo "Subsetter didn't produce nonempty subset font in $dir/font.ttf.subset" >&2
21         exit 2
22 fi
23
24 # Verify that subset font produces same glyphs!
25 glyphs_subset=`echo "$text" | $hb_shape "$dir/font.ttf.subset"`
26
27 if ! test "x$glyphs" = "x$glyphs_subset"; then
28         echo "Subset font produced different glyphs!" >&2
29         echo "Perhaps font doesn't have glyph names; checking visually..." >&2
30         hb_view=${hb_shape/shape/view}
31         echo "$text" | $hb_view "$dir/font.ttf" --output-format=png --output-file="$dir/orig.png"
32         echo "$text" | $hb_view "$dir/font.ttf.subset" --output-format=png --output-file="$dir/subset.png"
33         if ! cmp "$dir/orig.png" "$dir/subset.png"; then
34                 echo "Images differ.  Please inspect $dir/*.png." >&2
35                 echo "$glyphs"
36                 echo "$glyphs_subset"
37                 exit 2
38         fi
39         echo "Yep; all good." >&2
40         rm -f "$dir/orig.png"
41         rm -f "$dir/subset.png"
42         glyphs=$glyphs_subset
43 fi
44
45 sha1sum=`sha1sum "$dir/font.ttf.subset" | cut -d' ' -f1`
46 subset="fonts/sha1sum/$sha1sum.ttf"
47 mv "$dir/font.ttf.subset" "$subset"
48
49 echo "$subset:$unicodes:$glyphs"
50
51 rm -f "$dir/font.ttf"
52 rmdir "$dir"