From 515863e57c1d682e1a06373cf3dcd053602ed3b0 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Thu, 13 Oct 2022 23:42:00 +0000 Subject: [PATCH] [subset] Remove add accelerator flag, replace with new api method. Adds hb_subset_preprocess() which preprocesses the face and attaches accelerator data. --- perf/benchmark-subset.cc | 34 +++------------------------ src/hb-subset-input.cc | 50 +++++++++++++++++++++++++++++++++++++++- src/hb-subset-input.hh | 1 + src/hb-subset-plan.cc | 2 ++ src/hb-subset-plan.hh | 1 + src/hb-subset.cc | 2 +- src/hb-subset.h | 12 +++++----- util/hb-subset.cc | 35 ++++------------------------ 8 files changed, 68 insertions(+), 69 deletions(-) diff --git a/perf/benchmark-subset.cc b/perf/benchmark-subset.cc index 7c657880f..9bf3447a6 100644 --- a/perf/benchmark-subset.cc +++ b/perf/benchmark-subset.cc @@ -101,37 +101,9 @@ void AddGlyphs(unsigned num_glyphs_in_font, // the subsetting operations. 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_face_destroy (face); - hb_subset_input_destroy (input); - - return subset; + hb_face_t* new_face = hb_subset_preprocess(face); + hb_face_destroy(face); + return new_face; } /* benchmark for subsetting a font */ diff --git a/src/hb-subset-input.cc b/src/hb-subset-input.cc index 2c5e6daf1..f19bb5011 100644 --- a/src/hb-subset-input.cc +++ b/src/hb-subset-input.cc @@ -49,7 +49,7 @@ hb_subset_input_create_or_fail (void) set = hb_set_create (); input->axes_location = hb_hashmap_create (); - + if (!input->axes_location || input->in_error ()) { hb_subset_input_destroy (input); @@ -430,4 +430,52 @@ hb_subset_input_pin_axis_location (hb_subset_input_t *input, return input->axes_location->set (axis_tag, val); } #endif + +/** + * hb_subset_preprocess + * @input: a #hb_face_t object. + * + * Preprocesses the face and attaches data that will be needed by the + * subsetter. Future subsetting operations can then use the precomputed data + * to speed up the subsetting operation. + * + * Since: EXPERIMENTAL + **/ + +hb_face_t * +hb_subset_preprocess (hb_face_t *source) +{ + 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); + input->attach_accelerator_data = true; + + hb_face_t* new_source = hb_subset_or_fail (source, input); + hb_subset_input_destroy (input); + + return new_source; +} + + #endif diff --git a/src/hb-subset-input.hh b/src/hb-subset-input.hh index 2335f0634..dabb4918f 100644 --- a/src/hb-subset-input.hh +++ b/src/hb-subset-input.hh @@ -59,6 +59,7 @@ struct hb_subset_input_t }; unsigned flags; + bool attach_accelerator_data = false; hb_hashmap_t *axes_location; inline unsigned num_sets () const diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index ffa6446f3..9cf7c9e43 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -849,6 +849,8 @@ hb_subset_plan_create_or_fail (hb_face_t *face, plan->check_success (plan->hmtx_map = hb_hashmap_create> ()); void* accel = hb_face_get_user_data(face, hb_subset_accelerator_t::user_data_key()); + + plan->attach_accelerator_data = input->attach_accelerator_data; if (accel) plan->accelerator = (hb_subset_accelerator_t*) accel; diff --git a/src/hb-subset-plan.hh b/src/hb-subset-plan.hh index 8d66993c0..15fabba9c 100644 --- a/src/hb-subset-plan.hh +++ b/src/hb-subset-plan.hh @@ -98,6 +98,7 @@ struct hb_subset_plan_t bool successful; unsigned flags; + bool attach_accelerator_data = false; // For each cp that we'd like to retain maps to the corresponding gid. hb_set_t *unicodes; diff --git a/src/hb-subset.cc b/src/hb-subset.cc index d90371fff..6026aa6ef 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -598,7 +598,7 @@ hb_subset_plan_execute_or_fail (hb_subset_plan_t *plan) offset += num_tables; } - if (success && plan->flags & HB_SUBSET_FLAGS_ADD_ACCELERATOR_DATA) { + if (success && plan->attach_accelerator_data) { _attach_accelerator_data (plan, plan->dest); } diff --git a/src/hb-subset.h b/src/hb-subset.h index 9dbe11073..3baad0805 100644 --- a/src/hb-subset.h +++ b/src/hb-subset.h @@ -70,9 +70,6 @@ typedef struct hb_subset_plan_t hb_subset_plan_t; * in the final subset. * @HB_SUBSET_FLAGS_NO_PRUNE_UNICODE_RANGES: If set then the unicode ranges in * OS/2 will not be recalculated. - * @HB_SUBSET_FLAGS_ADD_ACCELERATOR_DATA: If set the subsetter will append into - * the output hb_face_t's user data, accelerator data that can be used to speedup - * further subsetting operations on the face. * @HB_SUBSET_FLAGS_PATCH_MODE: If set the subsetter behaviour will be modified * to produce a subset that is better suited to patching. For example cmap * subtable format will be kept stable. @@ -97,9 +94,8 @@ typedef enum { /*< flags >*/ HB_SUBSET_FLAGS_NOTDEF_OUTLINE = 0x00000040u, HB_SUBSET_FLAGS_GLYPH_NAMES = 0x00000080u, HB_SUBSET_FLAGS_NO_PRUNE_UNICODE_RANGES = 0x00000100u, - HB_SUBSET_FLAGS_ADD_ACCELERATOR_DATA = 0x00000200u, - // Not supported yet: HB_SUBSET_FLAGS_PATCH_MODE = 0x00000400u, - // Not supported yet: HB_SUBSET_FLAGS_OMIT_GLYF = 0x00000800u, + // Not supported yet: HB_SUBSET_FLAGS_PATCH_MODE = 0x00000200u, + // Not supported yet: HB_SUBSET_FLAGS_OMIT_GLYF = 0x00000400u, } hb_subset_flags_t; /** @@ -181,6 +177,10 @@ hb_subset_input_pin_axis_location (hb_subset_input_t *input, hb_tag_t axis_tag, float axis_value); #endif + +HB_EXTERN hb_face_t * +hb_subset_preprocess (hb_face_t *source); + #endif HB_EXTERN hb_face_t * diff --git a/util/hb-subset.cc b/util/hb-subset.cc index 438764878..f2606c767 100644 --- a/util/hb-subset.cc +++ b/util/hb-subset.cc @@ -34,36 +34,11 @@ 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; + #ifdef HB_EXPERIMENTAL_API + return hb_subset_preprocess (face); + #else + return hb_face_reference(face); + #endif } /*