Skip to content

Commit 005a5bd

Browse files
committed
Add an end to end testing shell script.
Generates an ift font from a config, extends it for a given text sample, and then compares the resutls of shaping/rendering the original and extended version.
1 parent 8f22231 commit 005a5bd

File tree

5 files changed

+103
-0
lines changed

5 files changed

+103
-0
lines changed

MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ bazel_dep(name = "protobuf", version = "29.3")
1111
bazel_dep(name = "rules_proto", version = "7.1.0")
1212
bazel_dep(name = "platforms", version = "0.0.11")
1313
bazel_dep(name = "rules_rust", version = "0.56.0")
14+
bazel_dep(name = "glib", version = "2.82.2.bcr.5")
1415

1516
# Non Bazel Modules
1617
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

third_party/harfbuzz.BUILD

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@ config_setting(
77
],
88
)
99

10+
cc_binary(
11+
name = "hb-shape",
12+
srcs = [
13+
"util/hb-shape.cc",
14+
"util/batch.hh",
15+
"util/options.hh",
16+
"util/font-options.hh",
17+
"util/face-options.hh",
18+
"util/main-font-text.hh",
19+
"util/shape-consumer.hh",
20+
"util/shape-options.hh",
21+
"util/shape-output.hh",
22+
"util/shape-format.hh",
23+
"util/text-options.hh",
24+
"util/output-options.hh",
25+
],
26+
deps = [
27+
":harfbuzz",
28+
"@glib//glib",
29+
],
30+
)
31+
1032
cc_library(
1133
name = "harfbuzz",
1234
srcs = glob(

third_party/harfbuzz/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ cc_library(
22
name = "config",
33
hdrs = [
44
"config.h",
5+
"hb-features.h",
56
],
67
includes = [
78
"./",

third_party/harfbuzz/hb-features.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#define PACKAGE_NAME "HarfBuzz"
2+
#define PACKAGE_VERSION "11.0.0"

util/end-to-end.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
# This script does an end to end test on an IFT font encoding.
3+
#
4+
# Given a font, an encoder config, and a text sample it produces the IFT encoded font.
5+
# Extends it with an IFT client for the text sample. Then finally compares the rendering
6+
# of that text sample by the extended font against the original input font.
7+
#
8+
# Comparison is made using a locally compiled version of hb-shape. Additional, if there
9+
# is an installed copy of hb-view that's also used to compare actual rendering (ie. `which hb-view` returns something).
10+
#
11+
# Usage:
12+
# end-to-end.sh <path to font> <path to config> <text string>
13+
14+
FONT=$(readlink -f $1)
15+
CONFIG=$(readlink -f $2)
16+
TEXT_SAMPLE=$3
17+
WORKING_DIR=$(mktemp -d)
18+
19+
# TODO(garretrieger): take an optional design space position
20+
# TODO(garretrieger): take an optional list of feature tags
21+
22+
# Locate hb-view if available
23+
HB_VIEW=$(which hb-view)
24+
25+
# Create the IFT encoding
26+
bazel run //util:font2ift -- \
27+
--input_font="$FONT" --config="$CONFIG" \
28+
--output_path="$WORKING_DIR" --output_font="ift_font.ttf" 2> /dev/null 1> /dev/null
29+
30+
# Run an extesion on it using the provided text
31+
bazel run @fontations//:ift_extend -- \
32+
--font=$WORKING_DIR/ift_font.ttf --text="$TEXT_SAMPLE" -o $WORKING_DIR/extended.ttf 2> /dev/null 1> /dev/null
33+
34+
# Compare shaping
35+
bazel run @harfbuzz//:hb-shape -- \
36+
$FONT --text="$TEXT_SAMPLE" > $WORKING_DIR/original_shaping.txt 2> /dev/null
37+
bazel run @harfbuzz//:hb-shape -- \
38+
$WORKING_DIR/extended.ttf --text="$TEXT_SAMPLE" > $WORKING_DIR/extended_shaping.txt 2> /dev/null
39+
40+
diff -u $WORKING_DIR/original_shaping.txt $WORKING_DIR/extended_shaping.txt > $WORKING_DIR/diff.txt
41+
42+
SHAPE_RETCODE=$?
43+
if [ $SHAPE_RETCODE -ne 0 ]; then
44+
echo "Shaping Comparison: FAILED"
45+
cat $WORKING_DIR/diff.txt
46+
echo ""
47+
else
48+
echo "Shaping Comparison: SUCCESS"
49+
fi
50+
51+
VIEW_RETCODE=0
52+
if [[ -n "$HB_VIEW" ]]; then
53+
$HB_VIEW $FONT --text="$TEXT_SAMPLE" -o $WORKING_DIR/original.svg -O svg
54+
$HB_VIEW $WORKING_DIR/extended.ttf --text="$TEXT_SAMPLE" -o $WORKING_DIR/extended.svg -O svg
55+
diff -u $WORKING_DIR/original.svg $WORKING_DIR/extended.svg > $WORKING_DIR/diff.txt
56+
VIEW_RETCODE=$?
57+
if [ $VIEW_RETCODE -ne 0 ]; then
58+
echo "Rendering Comparison: FAILED"
59+
cat $WORKING_DIR/diff.txt
60+
else
61+
echo "Rendering Comparison: SUCCESS"
62+
fi
63+
rm $WORKING_DIR/*.svg
64+
else
65+
echo "Rendering Comparison: SKIPPED (hb-view not found)"
66+
fi
67+
68+
rm $WORKING_DIR/*.ttf
69+
rm $WORKING_DIR/*.txt
70+
rm $WORKING_DIR/*.ift_tk
71+
rm $WORKING_DIR/*.ift_gk
72+
rmdir $WORKING_DIR
73+
74+
if [ $SHAPE_RETCODE -ne 0 ] || [ $VIEW_RETCODE -ne 0 ]; then
75+
exit -1
76+
fi
77+
exit 0

0 commit comments

Comments
 (0)