From fb44727401d36adc14615deda91574a6e7ec2cd6 Mon Sep 17 00:00:00 2001 From: Qunxin Liu Date: Mon, 7 Aug 2023 09:44:41 -0700 Subject: [PATCH] [instancer] add instantiate () for gvar --- src/hb-ot-var-common.hh | 11 ++++++++--- src/hb-ot-var-gvar-table.hh | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/hb-ot-var-common.hh b/src/hb-ot-var-common.hh index ae1f3785b..e1de07901 100644 --- a/src/hb-ot-var-common.hh +++ b/src/hb-ot-var-common.hh @@ -1088,7 +1088,7 @@ struct TupleVariationData void merge_tuple_variations () { hb_vector_t new_vars; - hb_hashmap_t, unsigned> m; + hb_hashmap_t*, unsigned> m; unsigned i = 0; for (const tuple_delta_t& var : tuple_vars) { @@ -1096,14 +1096,14 @@ struct TupleVariationData if (var.axis_tuples.is_empty ()) continue; unsigned *idx; - if (m.has (var.axis_tuples, &idx)) + if (m.has (&(var.axis_tuples), &idx)) { new_vars[*idx] += var; } else { new_vars.push (var); - m.set (var.axis_tuples, i); + m.set (&(var.axis_tuples), i); i++; } } @@ -1256,6 +1256,11 @@ struct TupleVariationData { if (!tuple_vars) return true; change_tuple_variations_axis_limits (normalized_axes_location, axes_triple_distances); + /* compute inferred deltas only for gvar */ + if (contour_points) + if (!calc_inferred_deltas (*contour_points)) + return false; + merge_tuple_variations (); return !tuple_vars.in_error (); } diff --git a/src/hb-ot-var-gvar-table.hh b/src/hb-ot-var-gvar-table.hh index 5b9e64243..3f9e10612 100644 --- a/src/hb-ot-var-gvar-table.hh +++ b/src/hb-ot-var-gvar-table.hh @@ -378,9 +378,31 @@ struct gvar (char *) glyph_var_data_offsets)); } + bool instantiate (hb_subset_context_t *c) const + { + TRACE_SUBSET (this); + glyph_variations_t glyph_vars; + if (!decompile_glyph_variations (c->plan, glyph_vars)) + return_trace (false); + + if (!glyph_vars.instantiate (c->plan)) return_trace (false); + if (!glyph_vars.compile_bytes (c->plan->axes_index_map, c->plan->axes_old_index_tag_map)) + return_trace (false); + + unsigned axis_count = c->plan->axes_index_map.get_population (); + unsigned num_glyphs = c->plan->num_output_glyphs (); + auto it = hb_iter (c->plan->new_to_old_gid_list); + return_trace (serialize (c->serializer, glyph_vars, it, axis_count, num_glyphs)); + } + bool subset (hb_subset_context_t *c) const { TRACE_SUBSET (this); + if (c->plan->all_axes_pinned) + return_trace (false); + + if (c->plan->normalized_coords) + return_trace (instantiate (c)); unsigned glyph_count = version.to_int () ? c->plan->source->get_num_glyphs () : 0;