Imported Upstream version 1.7.6
[platform/upstream/harfbuzz.git] / test / shaping / record-test.sh
index b2a74f7..f31d30b 100755 (executable)
@@ -1,7 +1,12 @@
 #!/bin/bash
 
-dir=`mktemp --directory`
+dir=`mktemp -d`
 
+out=/dev/stdout
+if test "x${1:0:3}" == 'x-o='; then
+       out=${1:3}
+       shift
+fi
 hb_shape=$1
 shift
 fontfile=$1
@@ -11,7 +16,7 @@ if test "x${fontfile:0:1}" == 'x-'; then
 fi
 shift
 if ! echo "$hb_shape" | grep -q 'hb-shape'; then
-       echo "Specify hb-shape (not hb-view, etc)." >&2
+       echo "Specify hb-shape (not hb-view, etc): got "$hb_shape"." >&2
        exit 1
 fi
 options=
@@ -41,31 +46,34 @@ if test $? != 0; then
        echo "hb-shape failed." >&2
        exit 2
 fi
+glyph_names=`echo "$text" | $hb_shape $options --no-clusters --no-positions "$fontfile" | sed 's/[][]//g; s/|/,/g'`
 
 cp "$fontfile" "$dir/font.ttf"
-pyftsubset \
+fonttools subset \
        --glyph-names \
        --no-hinting \
+       --layout-features='*' \
        "$dir/font.ttf" \
+       --glyphs="$glyph_names" \
        --text="$text"
-if ! test -s "$dir/font.ttf.subset"; then
-       echo "Subsetter didn't produce nonempty subset font in $dir/font.ttf.subset" >&2
+if ! test -s "$dir/font.subset.ttf"; then
+       echo "Subsetter didn't produce nonempty subset font in $dir/font.subset.ttf" >&2
        exit 2
 fi
 
 # Verify that subset font produces same glyphs!
-glyphs_subset=`echo "$text" | $hb_shape $options "$dir/font.ttf.subset"`
+glyphs_subset=`echo "$text" | $hb_shape $options "$dir/font.subset.ttf"`
 
 if ! test "x$glyphs" = "x$glyphs_subset"; then
        echo "Subset font produced different glyphs!" >&2
        echo "Perhaps font doesn't have glyph names; checking visually..." >&2
        hb_view=${hb_shape/shape/view}
        echo "$text" | $hb_view $options "$dir/font.ttf" --output-format=png --output-file="$dir/orig.png"
-       echo "$text" | $hb_view $options "$dir/font.ttf.subset" --output-format=png --output-file="$dir/subset.png"
+       echo "$text" | $hb_view $options "$dir/font.subset.ttf" --output-format=png --output-file="$dir/subset.png"
        if ! cmp "$dir/orig.png" "$dir/subset.png"; then
                echo "Images differ.  Please inspect $dir/*.png." >&2
-               echo "$glyphs"
-               echo "$glyphs_subset"
+               echo "$glyphs" >> "$out"
+               echo "$glyphs_subset" >> "$out"
                exit 2
        fi
        echo "Yep; all good." >&2
@@ -74,9 +82,9 @@ if ! test "x$glyphs" = "x$glyphs_subset"; then
        glyphs=$glyphs_subset
 fi
 
-sha1sum=`sha1sum "$dir/font.ttf.subset" | cut -d' ' -f1`
-subset="fonts/sha1sum/$sha1sum.ttf"
-mv "$dir/font.ttf.subset" "$subset"
+sha1sum=`sha1sum "$dir/font.subset.ttf" | cut -d' ' -f1`
+subset="data/in-house/fonts/$sha1sum.ttf"
+mv "$dir/font.subset.ttf" "$subset"
 
 # There ought to be an easier way to do this, but it escapes me...
 unicodes_file=`mktemp`
@@ -86,8 +94,12 @@ echo "$glyphs" > "$glyphs_file"
 # Open the "file"s
 exec 3<"$unicodes_file"
 exec 4<"$glyphs_file"
+relative_subset="$subset"
+if test "$out" != "/dev/stdout"; then
+       relative_subset="$(/usr/bin/python -c 'import os, sys; print (os.path.relpath (sys.argv[1], sys.argv[2]))' "$subset" "$(dirname "$out")")"
+fi
 while read uline <&3 && read gline <&4; do
-       echo "$subset:$options:$uline:$gline"
+       echo "$relative_subset:$options:$uline:$gline" >> "$out"
 done