mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-21 15:01:01 +01:00
[hb-draw-compare] Simplify sharding; remove non-sharded path
This commit is contained in:
1 parent
abb15ee099
commit
8a5e9536e3
1 file changed
+90
-43
+90
-43
@@ -26,6 +26,7 @@ unicodes=
|
||||
glyphs=
|
||||
quiet=false
|
||||
help=false
|
||||
max_procs=
|
||||
while test $# -gt 0; do
|
||||
case "$1" in
|
||||
-o|--output-dir)
|
||||
@@ -68,6 +69,11 @@ while test $# -gt 0; do
|
||||
precision=$1
|
||||
shift
|
||||
;;
|
||||
--max-procs)
|
||||
shift
|
||||
max_procs=$1
|
||||
shift
|
||||
;;
|
||||
--font-size)
|
||||
shift
|
||||
font_size=$1
|
||||
@@ -143,7 +149,8 @@ if $help; then
|
||||
echo " --hb-info HB_INFO: Path to hb-info; default $hb_info"
|
||||
echo " --hb-svg-compare HB_SVG_COMPARE: Path to hb-svg-compare; default $hb_svg_compare"
|
||||
echo " --tolerance TOLERANCE: Tolerance for SVG comparison; default $tolerance"
|
||||
echo " --precision N: hb-draw precision override; default 6"
|
||||
echo " --precision N: hb-draw precision override; default 5"
|
||||
echo " --max-procs N: Max parallel processes for render/compare; default auto"
|
||||
echo " --font-size SIZE: Font size; default $font_size"
|
||||
echo " --features FEATURES: Font features; default none"
|
||||
echo " --variations VARIATIONS: Font variations; default none"
|
||||
@@ -169,6 +176,17 @@ get_num_jobs() {
|
||||
echo "$n"
|
||||
}
|
||||
|
||||
if test "x$max_procs" != x; then
|
||||
echo "$max_procs" | grep -Eq '^[0-9]+$' || {
|
||||
echo "Invalid max-procs '$max_procs'" >&2
|
||||
exit 2
|
||||
}
|
||||
test "$max_procs" -gt 0 || {
|
||||
echo "Invalid max-procs '$max_procs'" >&2
|
||||
exit 2
|
||||
}
|
||||
fi
|
||||
|
||||
if test "x$font_file" == x; then
|
||||
echo "No font file specified." >&2
|
||||
exit 2
|
||||
@@ -212,7 +230,7 @@ if test "x$precision" != x; then
|
||||
}
|
||||
draw_precision="$precision"
|
||||
else
|
||||
draw_precision=6
|
||||
draw_precision=5
|
||||
fi
|
||||
$quiet || echo "Using precision=$draw_precision for tolerance=$tolerance." >&2
|
||||
|
||||
@@ -237,10 +255,21 @@ if test "x$unicodes" == x -a "x$glyphs" == x; then
|
||||
sed 's/^/gid/' >> "$glyphs_file"
|
||||
fi
|
||||
num_glyphs=`wc -l < "$glyphs_file" | tr -d '[:space:]'`
|
||||
compare_jobs=`get_num_jobs`
|
||||
if test "$num_glyphs" -lt 1; then
|
||||
echo "No glyphs to compare." >&2
|
||||
exit 2
|
||||
fi
|
||||
base_jobs=`get_num_jobs`
|
||||
if test "x$max_procs" != x; then
|
||||
if test "$base_jobs" -gt "$max_procs"; then
|
||||
base_jobs="$max_procs"
|
||||
fi
|
||||
fi
|
||||
compare_jobs="$base_jobs"
|
||||
if test "$compare_jobs" -gt "$num_glyphs"; then
|
||||
compare_jobs="$num_glyphs"
|
||||
fi
|
||||
$quiet || test "$base_jobs" -le 1 || echo "Using up to $base_jobs shards." >&2
|
||||
|
||||
flavor=
|
||||
if test "$features" != ""; then
|
||||
@@ -267,8 +296,9 @@ for font_funcs in "$font_funcs1" "$font_funcs2"; do
|
||||
|
||||
funcs_prefix="$output_dir/$font_funcs$flavor"
|
||||
mkdir -p "$funcs_prefix"
|
||||
render_cmds="$output_dir/render-cmds.$font_funcs$flavor"
|
||||
> "$render_cmds"
|
||||
count=0
|
||||
cat "$glyphs_file" |
|
||||
while read glyph; do
|
||||
dir="$funcs_prefix"
|
||||
svg="$dir/$glyph.svg"
|
||||
@@ -279,22 +309,43 @@ for font_funcs in "$font_funcs1" "$font_funcs2"; do
|
||||
if test $((count % 100)) == 0; then
|
||||
$quiet || echo -n . >&2
|
||||
fi
|
||||
echo \
|
||||
--font-file="$font_file" \
|
||||
--face-index=$face_index \
|
||||
--glyphs \
|
||||
--face-loader=$face_loader \
|
||||
--font-funcs=$font_funcs \
|
||||
--features="$features" \
|
||||
--variations="$variations" \
|
||||
--font-size=$font_size \
|
||||
--precision=$draw_precision \
|
||||
--output-file="$svg" \
|
||||
"$glyph"
|
||||
done |
|
||||
sed 's/ /;/g' |
|
||||
"$hb_draw" --batch | grep -v success
|
||||
$quiet || echo "" >&2
|
||||
printf '%s;%s;%s;%s;%s;%s;%s;%s;%s;%s;%s\n' \
|
||||
"--font-file=$font_file" \
|
||||
"--face-index=$face_index" \
|
||||
"--glyphs" \
|
||||
"--face-loader=$face_loader" \
|
||||
"--font-funcs=$font_funcs" \
|
||||
"--features=$features" \
|
||||
"--variations=$variations" \
|
||||
"--font-size=$font_size" \
|
||||
"--precision=$draw_precision" \
|
||||
"--output-file=$svg" \
|
||||
"$glyph" >> "$render_cmds"
|
||||
done < "$glyphs_file"
|
||||
|
||||
render_cmd_count=`wc -l < "$render_cmds" | tr -d '[:space:]'`
|
||||
render_jobs="$base_jobs"
|
||||
if test "$render_jobs" -gt "$render_cmd_count"; then
|
||||
render_jobs="$render_cmd_count"
|
||||
fi
|
||||
if test "$render_cmd_count" -gt 0; then
|
||||
render_shard_dir="$output_dir/render-shards.$font_funcs$flavor"
|
||||
rm -rf "$render_shard_dir"
|
||||
mkdir -p "$render_shard_dir" || exit 1
|
||||
split -d -n l/"$render_jobs" "$render_cmds" "$render_shard_dir/cmds." || exit 1
|
||||
pids=
|
||||
for shard in "$render_shard_dir"/cmds.*; do
|
||||
"$hb_draw" --batch < "$shard" > "$shard.out" &
|
||||
pids="$pids $!"
|
||||
done
|
||||
for pid in $pids; do
|
||||
wait "$pid" || exit 1
|
||||
done
|
||||
cat "$render_shard_dir"/cmds.*.out | grep -v '^success$' || true
|
||||
fi
|
||||
if test "$count" -ge 100; then
|
||||
$quiet || echo >&2
|
||||
fi
|
||||
done
|
||||
|
||||
test "x$font_funcs1" == x || test "x$font_funcs2" == x && exit 0
|
||||
@@ -304,9 +355,6 @@ rm -f "$diff"
|
||||
> "$diff"
|
||||
test "x$flavor" == x || ln -f -s "diff$flavor" "$output_dir/diff"
|
||||
$quiet || echo "Comparing SVGs into '$diff'..." >&2
|
||||
if test "$compare_jobs" -gt 1; then
|
||||
$quiet || echo "Using $compare_jobs compare shards." >&2
|
||||
fi
|
||||
funcs1_prefix="$output_dir/$font_funcs1$flavor"
|
||||
funcs2_prefix="$output_dir/$font_funcs2$flavor"
|
||||
pairs="$output_dir/pairs$flavor"
|
||||
@@ -328,28 +376,27 @@ while read glyph; do
|
||||
|
||||
echo -e "$svg1\t$svg2" >> "$pairs"
|
||||
done < "$glyphs_file"
|
||||
|
||||
raw_diff="$output_dir/diff.raw$flavor"
|
||||
if test "$compare_jobs" -gt 1; then
|
||||
shard_dir="$output_dir/compare-shards$flavor"
|
||||
rm -rf "$shard_dir"
|
||||
mkdir -p "$shard_dir" || exit 1
|
||||
split -d -n l/"$compare_jobs" "$pairs" "$shard_dir/pairs." || exit 1
|
||||
pids=
|
||||
for shard in "$shard_dir"/pairs.*; do
|
||||
"$hb_svg_compare" "$tolerance" < "$shard" > "$shard.out" &
|
||||
pids="$pids $!"
|
||||
done
|
||||
for pid in $pids; do
|
||||
wait "$pid" || exit 1
|
||||
done
|
||||
cat "$shard_dir"/pairs.*.out > "$raw_diff" || exit 1
|
||||
else
|
||||
"$hb_svg_compare" "$tolerance" < "$pairs" > "$raw_diff" || exit 1
|
||||
if test "$count" -ge 100; then
|
||||
$quiet || echo >&2
|
||||
fi
|
||||
|
||||
while read line; do
|
||||
$quiet || echo -e "\n$line"
|
||||
raw_diff="$output_dir/diff.raw$flavor"
|
||||
shard_dir="$output_dir/compare-shards$flavor"
|
||||
rm -rf "$shard_dir"
|
||||
mkdir -p "$shard_dir" || exit 1
|
||||
split -d -n l/"$compare_jobs" "$pairs" "$shard_dir/pairs." || exit 1
|
||||
pids=
|
||||
for shard in "$shard_dir"/pairs.*; do
|
||||
"$hb_svg_compare" "$tolerance" < "$shard" > "$shard.out" &
|
||||
pids="$pids $!"
|
||||
done
|
||||
for pid in $pids; do
|
||||
wait "$pid" || exit 1
|
||||
done
|
||||
cat "$shard_dir"/pairs.*.out > "$raw_diff" || exit 1
|
||||
|
||||
while IFS= read -r line; do
|
||||
$quiet || echo "$line"
|
||||
echo "$line" >> "$diff"
|
||||
done < "$raw_diff"
|
||||
# Sort diff by error
|
||||
|
||||
Reference in new issue
Block a user