diff --git a/src/hb-ot-var-gvar-table.hh b/src/hb-ot-var-gvar-table.hh index d8ee504c7..b7d1b5e42 100644 --- a/src/hb-ot-var-gvar-table.hh +++ b/src/hb-ot-var-gvar-table.hh @@ -625,17 +625,27 @@ struct gvar deltas[pt_index].y += y_deltas[i] * scalar; } + /* find point before phantoms start which is an end point */ + unsigned all_contours_end = points.length ? points.length - 1 : 0; + while (all_contours_end > 0) + { + if (points[all_contours_end].is_end_point) break; + --all_contours_end; + } + /* infer deltas for unreferenced points */ - for (unsigned start_point = 0; start_point + 4 < points.length; ++start_point) + for (unsigned start_point = 0; start_point < all_contours_end; ++start_point) { /* Check the number of unreferenced points in a contour. If no unref points or no ref points, nothing to do. */ - unsigned unref_count = 0; unsigned end_point = start_point; - do + unsigned unref_count = 0; + for (; end_point <= all_contours_end; ++end_point) { - if (!deltas[end_point].flag) unref_count++; - end_point++; - } while (!points[end_point].is_end_point && end_point + 4 < points.length); + if (!deltas[end_point].flag) + unref_count++; + if (points[end_point].is_end_point) + break; + } unsigned j = start_point; if (unref_count == 0 || unref_count > end_point - start_point) diff --git a/test/api/fonts/TestGVAREight.ttf b/test/api/fonts/TestGVAREight.ttf new file mode 100644 index 000000000..271dc4b58 Binary files /dev/null and b/test/api/fonts/TestGVAREight.ttf differ diff --git a/test/api/test-ot-metrics-tt-var.c b/test/api/test-ot-metrics-tt-var.c index 2305a95b0..cffdeb764 100644 --- a/test/api/test-ot-metrics-tt-var.c +++ b/test/api/test-ot-metrics-tt-var.c @@ -234,6 +234,23 @@ test_advance_tt_var_comp_v (void) hb_font_destroy (font); } +static void +test_advance_tt_var_gvar_infer (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/TestGVAREight.ttf"); + hb_font_t *font = hb_font_create (face); + hb_ot_font_set_funcs (font); + hb_face_destroy (face); + + int coords[6] = {100}; + hb_font_set_var_coords_normalized (font, coords, 6); + + hb_glyph_extents_t extents = {0}; + g_assert (hb_font_get_glyph_extents (font, 4, &extents)); + + hb_font_destroy (font); +} + int main (int argc, char **argv) { @@ -245,6 +262,7 @@ main (int argc, char **argv) hb_test_add (test_advance_tt_var_anchor); hb_test_add (test_extents_tt_var_comp); hb_test_add (test_advance_tt_var_comp_v); + hb_test_add (test_advance_tt_var_gvar_infer); return hb_test_run (); }