From 3394ec7048ce7c61e39e7d1f176e5d260e3273d1 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Thu, 13 Oct 2022 23:02:54 +0000 Subject: [PATCH] [subset] use subset accelerator in tests. This ensures it produces equivalent subsets as without the accelerator. --- perf/benchmark-subset.cc | 3 +++ test/subset/run-tests.py | 1 + util/hb-subset.cc | 45 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/perf/benchmark-subset.cc b/perf/benchmark-subset.cc index c35f1109d..7c657880f 100644 --- a/perf/benchmark-subset.cc +++ b/perf/benchmark-subset.cc @@ -122,6 +122,9 @@ static hb_face_t* preprocess_face(hb_face_t* face) HB_SUBSET_SETS_NAME_ID)); hb_subset_input_set_flags(input, + HB_SUBSET_FLAGS_NOTDEF_OUTLINE | + HB_SUBSET_FLAGS_GLYPH_NAMES | + HB_SUBSET_FLAGS_RETAIN_GIDS | HB_SUBSET_FLAGS_ADD_ACCELERATOR_DATA); hb_face_t* subset = hb_subset_or_fail (face, input); diff --git a/test/subset/run-tests.py b/test/subset/run-tests.py index a0c9e2885..6a2146dbe 100755 --- a/test/subset/run-tests.py +++ b/test/subset/run-tests.py @@ -52,6 +52,7 @@ def run_test (test, should_check_ots): cli_args = ["--font-file=" + test.font_path, "--output-file=" + out_file, "--unicodes=%s" % test.unicodes (), + "--preprocess-face", "--drop-tables+=DSIG", "--drop-tables-=sbix"] cli_args.extend (test.get_profile_flags ()) diff --git a/util/hb-subset.cc b/util/hb-subset.cc index b27b82f8a..438764878 100644 --- a/util/hb-subset.cc +++ b/util/hb-subset.cc @@ -32,6 +32,40 @@ #include +static hb_face_t* preprocess_face(hb_face_t* face) +{ + hb_subset_input_t* input = hb_subset_input_create_or_fail (); + + hb_set_clear (hb_subset_input_set(input, HB_SUBSET_SETS_UNICODE)); + hb_set_invert (hb_subset_input_set(input, HB_SUBSET_SETS_UNICODE)); + + hb_set_clear (hb_subset_input_set(input, + HB_SUBSET_SETS_LAYOUT_FEATURE_TAG)); + hb_set_invert (hb_subset_input_set(input, + HB_SUBSET_SETS_LAYOUT_FEATURE_TAG)); + + hb_set_clear (hb_subset_input_set(input, + HB_SUBSET_SETS_LAYOUT_SCRIPT_TAG)); + hb_set_invert (hb_subset_input_set(input, + HB_SUBSET_SETS_LAYOUT_SCRIPT_TAG)); + + hb_set_clear (hb_subset_input_set(input, + HB_SUBSET_SETS_NAME_ID)); + hb_set_invert (hb_subset_input_set(input, + HB_SUBSET_SETS_NAME_ID)); + + hb_subset_input_set_flags(input, + HB_SUBSET_FLAGS_NOTDEF_OUTLINE | + HB_SUBSET_FLAGS_GLYPH_NAMES | + HB_SUBSET_FLAGS_RETAIN_GIDS | + HB_SUBSET_FLAGS_ADD_ACCELERATOR_DATA); + + hb_face_t* subset = hb_subset_or_fail (face, input); + hb_subset_input_destroy (input); + + return subset; +} + /* * Command line interface to the harfbuzz font subsetter. */ @@ -103,6 +137,10 @@ struct subset_main_t : option_parser_t, face_options_t, output_options_t { parse (argc, argv); + hb_face_t* orig_face = face; + if (preprocess) + orig_face = preprocess_face (face); + hb_face_t *new_face = nullptr; for (unsigned i = 0; i < num_iterations; i++) { @@ -119,6 +157,8 @@ struct subset_main_t : option_parser_t, face_options_t, output_options_t } hb_face_destroy (new_face); + if (preprocess) + hb_face_destroy (orig_face); return success ? 0 : 1; } @@ -160,6 +200,7 @@ struct subset_main_t : option_parser_t, face_options_t, output_options_t public: unsigned num_iterations = 1; + gboolean preprocess; hb_subset_input_t *input = nullptr; }; @@ -657,7 +698,7 @@ parse_instance (const char *name, GError **error) { subset_main_t *subset_main = (subset_main_t *) data; - + char *s = strtok((char *) arg, "="); while (s) { @@ -915,6 +956,8 @@ subset_main_t::add_options () {"no-prune-unicode-ranges", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag, "Don't change the 'OS/2 ulUnicodeRange*' bits.", nullptr}, {"glyph-names", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag, "Keep PS glyph names in TT-flavored fonts. ", nullptr}, {"passthrough-tables", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag, "Do not drop tables that the tool does not know how to subset.", nullptr}, + {"preprocess-face", 0, 0, G_OPTION_ARG_NONE, &this->preprocess, + "If set preprocesses the face with the add accelerator option before actually subsetting.", nullptr}, {nullptr} }; add_group (flag_entries,