[subset] use subset accelerator in tests.

This ensures it produces equivalent subsets as without the accelerator.
This commit is contained in:
Garret Rieger 2022-10-13 23:02:54 +00:00
parent f4903defc4
commit 3394ec7048
3 changed files with 48 additions and 1 deletions

View File

@ -122,6 +122,9 @@ static hb_face_t* preprocess_face(hb_face_t* face)
HB_SUBSET_SETS_NAME_ID)); HB_SUBSET_SETS_NAME_ID));
hb_subset_input_set_flags(input, 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_SUBSET_FLAGS_ADD_ACCELERATOR_DATA);
hb_face_t* subset = hb_subset_or_fail (face, input); hb_face_t* subset = hb_subset_or_fail (face, input);

View File

@ -52,6 +52,7 @@ def run_test (test, should_check_ots):
cli_args = ["--font-file=" + test.font_path, cli_args = ["--font-file=" + test.font_path,
"--output-file=" + out_file, "--output-file=" + out_file,
"--unicodes=%s" % test.unicodes (), "--unicodes=%s" % test.unicodes (),
"--preprocess-face",
"--drop-tables+=DSIG", "--drop-tables+=DSIG",
"--drop-tables-=sbix"] "--drop-tables-=sbix"]
cli_args.extend (test.get_profile_flags ()) cli_args.extend (test.get_profile_flags ())

View File

@ -32,6 +32,40 @@
#include <hb-subset.h> #include <hb-subset.h>
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. * 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<false>
{ {
parse (argc, argv); parse (argc, argv);
hb_face_t* orig_face = face;
if (preprocess)
orig_face = preprocess_face (face);
hb_face_t *new_face = nullptr; hb_face_t *new_face = nullptr;
for (unsigned i = 0; i < num_iterations; i++) 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<false>
} }
hb_face_destroy (new_face); hb_face_destroy (new_face);
if (preprocess)
hb_face_destroy (orig_face);
return success ? 0 : 1; return success ? 0 : 1;
} }
@ -160,6 +200,7 @@ struct subset_main_t : option_parser_t, face_options_t, output_options_t<false>
public: public:
unsigned num_iterations = 1; unsigned num_iterations = 1;
gboolean preprocess;
hb_subset_input_t *input = nullptr; hb_subset_input_t *input = nullptr;
}; };
@ -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<HB_SUBSET_FLAGS_NO_PRUNE_UNICODE_RANGES>, "Don't change the 'OS/2 ulUnicodeRange*' bits.", nullptr}, {"no-prune-unicode-ranges", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag<HB_SUBSET_FLAGS_NO_PRUNE_UNICODE_RANGES>, "Don't change the 'OS/2 ulUnicodeRange*' bits.", nullptr},
{"glyph-names", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag<HB_SUBSET_FLAGS_GLYPH_NAMES>, "Keep PS glyph names in TT-flavored fonts. ", nullptr}, {"glyph-names", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag<HB_SUBSET_FLAGS_GLYPH_NAMES>, "Keep PS glyph names in TT-flavored fonts. ", nullptr},
{"passthrough-tables", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag<HB_SUBSET_FLAGS_PASSTHROUGH_UNRECOGNIZED>, "Do not drop tables that the tool does not know how to subset.", nullptr}, {"passthrough-tables", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag<HB_SUBSET_FLAGS_PASSTHROUGH_UNRECOGNIZED>, "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} {nullptr}
}; };
add_group (flag_entries, add_group (flag_entries,