diff --git a/src/hb-ot-var-common.hh b/src/hb-ot-var-common.hh index 2081f1b9b..a5132c0a2 100644 --- a/src/hb-ot-var-common.hh +++ b/src/hb-ot-var-common.hh @@ -260,14 +260,15 @@ struct TupleVariationHeader else { unsigned int index = get_index (); - if (unlikely (index * coord_count >= shared_tuples.length)) + if (unlikely ((index + 1) * coord_count > shared_tuples.length)) return 0.f; peak_tuple = shared_tuples.sub_array (coord_count * index, coord_count); } hb_array_t start_tuple; hb_array_t end_tuple; - if (has_intermediate ()) + bool has_interm = has_intermediate (); + if (has_interm) { start_tuple = get_start_tuple (coord_count); end_tuple = get_end_tuple (coord_count); @@ -276,14 +277,16 @@ struct TupleVariationHeader float scalar = 1.f; for (unsigned int i = 0; i < coord_count; i++) { - int v = coords[i]; - int peak = peak_tuple[i].to_int (); - if (!peak || v == peak) continue; + int peak = peak_tuple.arrayZ[i].to_int (); + if (!peak) continue; - if (has_intermediate ()) + int v = coords[i]; + if (v == peak) continue; + + if (has_interm) { - int start = start_tuple[i].to_int (); - int end = end_tuple[i].to_int (); + int start = start_tuple.arrayZ[i].to_int (); + int end = end_tuple.arrayZ[i].to_int (); if (unlikely (start > peak || peak > end || (start < 0 && end > 0 && peak))) continue; if (v < start || v > end) return 0.f; diff --git a/src/hb-ot-var-gvar-table.hh b/src/hb-ot-var-gvar-table.hh index f770480c7..6b4c3b0a1 100644 --- a/src/hb-ot-var-gvar-table.hh +++ b/src/hb-ot-var-gvar-table.hh @@ -274,19 +274,14 @@ struct gvar return true; /* so isn't applied at all */ /* Save original points for inferred delta calculation */ - contour_point_vector_t orig_points_vec; - orig_points_vec.extend (points); - if (unlikely (orig_points_vec.in_error ())) return false; + contour_point_vector_t orig_points_vec; // Populated lazily auto orig_points = orig_points_vec.as_array (); contour_point_vector_t deltas_vec; /* flag is used to indicate referenced point */ - if (unlikely (!deltas_vec.resize (points.length, false))) return false; + if (unlikely (!deltas_vec.resize (points.length))) return false; auto deltas = deltas_vec.as_array (); - hb_vector_t end_points; - for (unsigned i = 0; i < points.length; ++i) - if (points.arrayZ[i].is_end_point) - end_points.push (i); + hb_vector_t end_points; // Populated lazily unsigned num_coords = table->axisCount; hb_array_t shared_tuples = (table+table->sharedTuples).as_array (table->sharedTupleCount * table->axisCount); @@ -294,6 +289,7 @@ struct gvar hb_vector_t private_indices; hb_vector_t x_deltas; hb_vector_t y_deltas; + bool flush = false; do { float scalar = iterator.current_tuple->calculate_scalar (coords, num_coords, shared_tuples); @@ -318,16 +314,31 @@ struct gvar if (unlikely (!y_deltas.resize (num_deltas, false))) return false; if (unlikely (!GlyphVariationData::unpack_deltas (p, y_deltas, end))) return false; - hb_memset (deltas.arrayZ, 0, deltas.get_size ()); + if (!apply_to_all) + { + if (!orig_points) + { + orig_points_vec.extend (points); + if (unlikely (orig_points_vec.in_error ())) return false; + orig_points = orig_points_vec.as_array (); + } + + if (flush) + { + for (unsigned int i = 0; i < points.length; i++) + points.arrayZ[i].translate (deltas.arrayZ[i]); + flush = false; + + } + hb_memset (deltas.arrayZ, 0, deltas.get_size ()); + } - unsigned ref_points = 0; if (scalar != 1.0f) for (unsigned int i = 0; i < num_deltas; i++) { unsigned int pt_index = apply_to_all ? i : indices[i]; if (unlikely (pt_index >= deltas.length)) continue; auto &delta = deltas.arrayZ[pt_index]; - ref_points += !delta.flag; delta.flag = 1; /* this point is referenced, i.e., explicit deltas specified */ delta.x += x_deltas.arrayZ[i] * scalar; delta.y += y_deltas.arrayZ[i] * scalar; @@ -338,20 +349,23 @@ struct gvar unsigned int pt_index = apply_to_all ? i : indices[i]; if (unlikely (pt_index >= deltas.length)) continue; auto &delta = deltas.arrayZ[pt_index]; - ref_points += !delta.flag; delta.flag = 1; /* this point is referenced, i.e., explicit deltas specified */ delta.x += x_deltas.arrayZ[i]; delta.y += y_deltas.arrayZ[i]; } /* infer deltas for unreferenced points */ - if (ref_points && ref_points < orig_points.length) + if (!apply_to_all) { - unsigned start_point = 0; - for (unsigned c = 0; c < end_points.length; c++) - { - unsigned end_point = end_points.arrayZ[c]; + if (!end_points) + for (unsigned i = 0; i < points.length; ++i) + if (points.arrayZ[i].is_end_point) + end_points.push (i); + if (unlikely (end_points.in_error ())) return false; + unsigned start_point = 0; + for (unsigned end_point : end_points) + { /* Check the number of unreferenced points in a contour. If no unref points or no ref points, nothing to do. */ unsigned unref_count = 0; for (unsigned i = start_point; i < end_point + 1; i++) @@ -398,12 +412,14 @@ struct gvar } } - /* apply specified / inferred deltas to points */ - for (unsigned int i = 0; i < points.length; i++) - points.arrayZ[i].translate (deltas.arrayZ[i]); + flush = true; } while (iterator.move_to_next ()); + if (flush) + for (unsigned int i = 0; i < points.length; i++) + points.arrayZ[i].translate (deltas.arrayZ[i]); + return true; } diff --git a/test/subset/data/expected/full_instance/Roboto-Variable.default.retain-all-codepoint.wght=300,wdth=90.ttf b/test/subset/data/expected/full_instance/Roboto-Variable.default.retain-all-codepoint.wght=300,wdth=90.ttf index 02a3a6723..2a02cdba2 100644 Binary files a/test/subset/data/expected/full_instance/Roboto-Variable.default.retain-all-codepoint.wght=300,wdth=90.ttf and b/test/subset/data/expected/full_instance/Roboto-Variable.default.retain-all-codepoint.wght=300,wdth=90.ttf differ diff --git a/test/subset/data/expected/full_instance/Roboto-Variable.no-prune-unicode-ranges.retain-all-codepoint.wght=300,wdth=90.ttf b/test/subset/data/expected/full_instance/Roboto-Variable.no-prune-unicode-ranges.retain-all-codepoint.wght=300,wdth=90.ttf index 02a3a6723..2a02cdba2 100644 Binary files a/test/subset/data/expected/full_instance/Roboto-Variable.no-prune-unicode-ranges.retain-all-codepoint.wght=300,wdth=90.ttf and b/test/subset/data/expected/full_instance/Roboto-Variable.no-prune-unicode-ranges.retain-all-codepoint.wght=300,wdth=90.ttf differ diff --git a/test/subset/data/tests/full_instance.tests b/test/subset/data/tests/full_instance.tests index f99e5ebe9..f7605725d 100644 --- a/test/subset/data/tests/full_instance.tests +++ b/test/subset/data/tests/full_instance.tests @@ -11,3 +11,6 @@ SUBSETS: INSTANCES: wght=150,wdth=80 wght=300,wdth=90 + +OPTIONS: +no_fonttools