From f6076890c5103f7078196d14cfc15323a4781b17 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 14 Nov 2022 16:06:39 -0700 Subject: [PATCH] Hide all mentions of name_table_overrides behind EXPERIMENTAL_API Fixes https://github.com/harfbuzz/harfbuzz/issues/3872 --- src/hb-ot-name-table.hh | 39 ++++++++++++++++++++++++++++++--------- src/hb-subset-input.cc | 13 +++++++++++-- src/hb-subset-input.hh | 8 +++++++- src/hb-subset-plan.cc | 3 ++- src/hb-subset-plan.hh | 4 ++++ 5 files changed, 54 insertions(+), 13 deletions(-) diff --git a/src/hb-ot-name-table.hh b/src/hb-ot-name-table.hh index 22b734233..a5ddbcfd9 100644 --- a/src/hb-ot-name-table.hh +++ b/src/hb-ot-name-table.hh @@ -142,14 +142,19 @@ struct NameRecord return UNSUPPORTED; } - NameRecord* copy (hb_serialize_context_t *c, const void *base, - const hb_hashmap_t *name_table_overrides) const + NameRecord* copy (hb_serialize_context_t *c, const void *base +#ifdef HB_EXPERIMENTAL_API + , const hb_hashmap_t *name_table_overrides +#endif + ) const { TRACE_SERIALIZE (this); - auto snap = c->snapshot (); + HB_UNUSED auto snap = c->snapshot (); auto *out = c->embed (this); if (unlikely (!out)) return_trace (nullptr); - if (name_table_overrides->has (nameID)) { +#ifdef HB_EXPERIMENTAL_API + if (name_table_overrides->has (nameID)) + { hb_bytes_t name_bytes = name_table_overrides->get (nameID); unsigned text_size = hb_ot_name_convert_utf (name_bytes, nullptr, nullptr); @@ -177,7 +182,10 @@ struct NameRecord utf16_be_bytes.copy (c); c->add_link (out->offset, c->pop_pack (), hb_serialize_context_t::Tail, 0); hb_free (name_str_utf16_be); - } else { + } + else +#endif + { out->offset.serialize_copy (c, offset, base, 0, hb_serialize_context_t::Tail, length); } return_trace (out); @@ -293,8 +301,11 @@ struct name hb_requires (hb_is_source_of (Iterator, const NameRecord &))> bool serialize (hb_serialize_context_t *c, Iterator it, - const void *src_string_pool, - const hb_hashmap_t *name_table_overrides) + const void *src_string_pool +#ifdef HB_EXPERIMENTAL_API + , const hb_hashmap_t *name_table_overrides +#endif + ) { TRACE_SERIALIZE (this); @@ -316,7 +327,12 @@ struct name records.qsort (); - c->copy_all (records, src_string_pool, name_table_overrides); + c->copy_all (records, + src_string_pool +#ifdef HB_EXPERIMENTAL_API + , name_table_overrides +#endif + ); hb_free (records.arrayZ); @@ -345,7 +361,12 @@ struct name }) ; - name_prime->serialize (c->serializer, it, std::addressof (this + stringOffset), c->plan->name_table_overrides); + name_prime->serialize (c->serializer, + it, std::addressof (this + stringOffset) +#ifdef HB_EXPERIMENTAL_API + , c->plan->name_table_overrides +#endif + ); return_trace (name_prime->count); } diff --git a/src/hb-subset-input.cc b/src/hb-subset-input.cc index 10ec5c38a..880c5eea2 100644 --- a/src/hb-subset-input.cc +++ b/src/hb-subset-input.cc @@ -49,9 +49,15 @@ hb_subset_input_create_or_fail (void) set = hb_set_create (); input->axes_location = hb_hashmap_create (); +#ifdef HB_EXPERIMENTAL_API input->name_table_overrides = hb_hashmap_create (); +#endif - if (!input->axes_location || !input->name_table_overrides || input->in_error ()) + if (!input->axes_location || +#ifdef HB_EXPERIMENTAL_API + !input->name_table_overrides || +#endif + input->in_error ()) { hb_subset_input_destroy (input); return nullptr; @@ -249,13 +255,14 @@ hb_subset_input_destroy (hb_subset_input_t *input) hb_hashmap_destroy (input->axes_location); +#ifdef HB_EXPERIMENTAL_API if (input->name_table_overrides) { for (auto _ : input->name_table_overrides->values ()) _.fini (); } - hb_hashmap_destroy (input->name_table_overrides); +#endif hb_free (input); } @@ -487,7 +494,9 @@ hb_subset_preprocess (hb_face_t *source) return new_source; } +#endif +#ifdef HB_EXPERIMENTAL_API /** * hb_subset_input_override_name_table: * @input: a #hb_subset_input_t object. diff --git a/src/hb-subset-input.hh b/src/hb-subset-input.hh index 8e8cf5402..cb9652d6c 100644 --- a/src/hb-subset-input.hh +++ b/src/hb-subset-input.hh @@ -61,7 +61,9 @@ struct hb_subset_input_t unsigned flags; bool attach_accelerator_data = false; hb_hashmap_t *axes_location; +#ifdef HB_EXPERIMENTAL_API hb_hashmap_t *name_table_overrides; +#endif inline unsigned num_sets () const { @@ -81,7 +83,11 @@ struct hb_subset_input_t return true; } - return axes_location->in_error () || name_table_overrides->in_error (); + return axes_location->in_error () +#ifdef HB_EXPERIMENTAL_API + || name_table_overrides->in_error () +#endif + ; } }; diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index 3a06c5eaa..fb65be0d7 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -848,6 +848,7 @@ hb_subset_plan_create_or_fail (hb_face_t *face, plan->check_success (plan->vmtx_map = hb_hashmap_create> ()); plan->check_success (plan->hmtx_map = hb_hashmap_create> ()); +#ifdef HB_EXPERIMENTAL_API plan->check_success (plan->name_table_overrides = hb_hashmap_create ()); if (plan->name_table_overrides && input->name_table_overrides) { @@ -869,7 +870,7 @@ hb_subset_plan_create_or_fail (hb_face_t *face, plan->name_table_overrides->set (name_id, hb_bytes_t (name_str, len)); } } - +#endif void* accel = hb_face_get_user_data(face, hb_subset_accelerator_t::user_data_key()); diff --git a/src/hb-subset-plan.hh b/src/hb-subset-plan.hh index 2e1997a18..e31030f4e 100644 --- a/src/hb-subset-plan.hh +++ b/src/hb-subset-plan.hh @@ -87,12 +87,14 @@ struct hb_subset_plan_t hb_hashmap_destroy (vmtx_map); hb_hashmap_destroy (layout_variation_idx_delta_map); +#ifdef HB_EXPERIMENTAL_API if (name_table_overrides) { for (auto _ : name_table_overrides->values ()) _.fini (); } hb_hashmap_destroy (name_table_overrides); +#endif if (user_axes_location) { @@ -198,9 +200,11 @@ struct hb_subset_plan_t //vmtx metrics map: new gid->(advance, lsb) hb_hashmap_t> *vmtx_map; +#ifdef HB_EXPERIMENTAL_API // name table overrides map: name_id->name string new value or None // to indicate should remove hb_hashmap_t *name_table_overrides; +#endif const hb_subset_accelerator_t* accelerator;