#!/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
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=
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.subset.ttf"; then
echo "Subsetter didn't produce nonempty subset font in $dir/font.subset.ttf" >&2
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
fi
sha1sum=`sha1sum "$dir/font.subset.ttf" | cut -d' ' -f1`
-subset="fonts/sha1sum/$sha1sum.ttf"
+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...
# 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