diff --git a/src/hb-ot-var-common.hh b/src/hb-ot-var-common.hh index 8eec5195a..46a78e54e 100644 --- a/src/hb-ot-var-common.hh +++ b/src/hb-ot-var-common.hh @@ -33,6 +33,7 @@ namespace OT { +using tuple_active_indices_t = hb_vector_t; /* https://docs.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#tuplevariationheader */ struct TupleVariationHeader @@ -100,13 +101,11 @@ struct TupleVariationHeader double calculate_scalar (hb_array_t coords, unsigned int coord_count, const hb_array_t shared_tuples, - const hb_vector_t> *shared_tuple_active_idx = nullptr) const + const hb_vector_t *shared_tuple_active_idx = nullptr) const { const F2DOT14 *peak_tuple; - unsigned start_idx = 0; - unsigned end_idx = coord_count; - unsigned step = 1; + const tuple_active_indices_t *active_indices = nullptr; if (has_peak ()) peak_tuple = get_peak_tuple (coord_count).arrayZ; @@ -121,18 +120,7 @@ struct TupleVariationHeader { if (unlikely (index >= shared_tuple_active_idx->length)) return 0.0; - auto _ = (*shared_tuple_active_idx).arrayZ[index]; - if (_.second != -1) - { - start_idx = _.first; - end_idx = _.second + 1; - step = _.second - _.first; - } - else if (_.first != -1) - { - start_idx = _.first; - end_idx = start_idx + 1; - } + active_indices = &(*shared_tuple_active_idx)[index]; } } @@ -145,9 +133,12 @@ struct TupleVariationHeader end_tuple = get_end_tuple (coord_count).arrayZ; } + unsigned count = active_indices ? active_indices->length : coord_count; double scalar = 1.0; - for (unsigned int i = start_idx; i < end_idx; i += step) + for (unsigned int j = 0; j < count; j++) { + unsigned i = active_indices ? (*active_indices).arrayZ[j] : j; + int peak = peak_tuple[i].to_int (); if (!peak) continue; diff --git a/src/hb-ot-var-gvar-table.hh b/src/hb-ot-var-gvar-table.hh index 8523683b9..1489064d8 100644 --- a/src/hb-ot-var-gvar-table.hh +++ b/src/hb-ot-var-gvar-table.hh @@ -595,29 +595,17 @@ struct gvar_GVAR * for fonts with lots of axes and many "monovar" or "duovar" tuples. */ hb_array_t shared_tuples = (table+table->sharedTuples).as_array (table->sharedTupleCount * table->axisCount); unsigned count = table->sharedTupleCount; - if (unlikely (!shared_tuple_active_idx.resize (count, false))) return; + if (unlikely (!shared_tuple_active_idx.resize (count))) return; unsigned axis_count = table->axisCount; for (unsigned i = 0; i < count; i++) { hb_array_t tuple = shared_tuples.sub_array (axis_count * i, axis_count); - int idx1 = -1, idx2 = -1; for (unsigned j = 0; j < axis_count; j++) { const F2DOT14 &peak = tuple.arrayZ[j]; if (peak.to_int () != 0) - { - if (idx1 == -1) - idx1 = j; - else if (idx2 == -1) - idx2 = j; - else - { - idx1 = idx2 = -1; - break; - } - } + shared_tuple_active_idx.arrayZ[i].push (j); } - shared_tuple_active_idx.arrayZ[i] = {idx1, idx2}; } } ~accelerator_t () { table.destroy (); } @@ -884,7 +872,7 @@ struct gvar_GVAR private: hb_blob_ptr_t table; unsigned glyphCount; - hb_vector_t> shared_tuple_active_idx; + hb_vector_t shared_tuple_active_idx; }; protected: