From a35e3dfc775f8a86b8a95623059f581c02cf8e00 Mon Sep 17 00:00:00 2001 From: Michiharu Ariza Date: Sun, 17 Mar 2019 17:48:10 -0700 Subject: [PATCH] fix infer_delta code cleanup --- src/hb-ot-glyf-table.hh | 22 ++++++++++++++-------- src/hb-ot-var-gvar-table.hh | 9 +++++++-- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index 8f79e2aa3..cd7dc46e6 100644 --- a/src/hb-ot-glyf-table.hh +++ b/src/hb-ot-glyf-table.hh @@ -513,9 +513,9 @@ struct glyf return true; } - struct bounds_t + struct contour_bounds_t { - bounds_t () { min.x = min.y = FLT_MAX; max.x = max.y = FLT_MIN; } + contour_bounds_t () { min.x = min.y = FLT_MAX; max.x = max.y = FLT_MIN; } void add (const contour_point_t &p) { @@ -525,8 +525,14 @@ struct glyf max.y = MAX (max.y, p.y); } - void _union (const bounds_t &b) - { add (b.min); add (b.max); } + void merge (const contour_bounds_t &b) + { + if (empty ()) { *this = b; return; } + add (b.min); + add (b.max); + } + + bool empty () const { return (min.x >= max.x) || (min.y >= max.y); } contour_point_t min; contour_point_t max; @@ -535,7 +541,7 @@ struct glyf /* Note: Recursively calls itself. Who's checking recursively nested composite glyph BTW? */ bool get_bounds_var (hb_codepoint_t glyph, const int *coords, unsigned int coord_count, - bounds_t &bounds) const + contour_bounds_t &bounds) const { hb_vector_t points; hb_vector_t end_points; @@ -555,12 +561,12 @@ struct glyf /* composite glyph */ do { - bounds_t comp_bounds; + contour_bounds_t comp_bounds; if (unlikely (!get_bounds_var (composite.current->glyphIndex, coords, coord_count, comp_bounds))) return false; composite.current->transform_point (comp_bounds.min.x, comp_bounds.min.y); composite.current->transform_point (comp_bounds.max.x, comp_bounds.max.y); - bounds._union (comp_bounds); + bounds.merge (comp_bounds); } while (composite.move_to_next()); /* Shift bounds by the updated left side bearing (vertically too?) */ @@ -577,7 +583,7 @@ struct glyf const int *coords, unsigned int coord_count, hb_glyph_extents_t *extents) const { - bounds_t bounds; + contour_bounds_t bounds; if (unlikely (!get_bounds_var (glyph, coords, coord_count, bounds))) return false; if (bounds.min.x >= bounds.max.x) diff --git a/src/hb-ot-var-gvar-table.hh b/src/hb-ot-var-gvar-table.hh index 738c1e731..fbcd55408 100644 --- a/src/hb-ot-var-gvar-table.hh +++ b/src/hb-ot-var-gvar-table.hh @@ -575,6 +575,11 @@ struct gvar } while (iterator.move_to_next ()); /* infer deltas for unreferenced points */ + hb_vector_t orig_points; + orig_points.resize (points.length); + for (unsigned int i = 0; i < orig_points.length; i++) + orig_points[i] = points[i]; + unsigned int start_point = 0; for (unsigned int c = 0; c < end_points.length; c++) { @@ -597,8 +602,8 @@ struct gvar if (next == i || deltas[next].flag) break; } assert (next != i); - deltas[i].x = infer_delta (points[i].x, points[prev].x, points[next].x, deltas[prev].x, deltas[next].x); - deltas[i].y = infer_delta (points[i].y, points[prev].y, points[next].y, deltas[prev].y, deltas[next].y); + deltas[i].x = infer_delta (orig_points.as_array (), deltas.as_array (), i, prev, next); + deltas[i].y = infer_delta (orig_points.as_array (), deltas.as_array (), i, prev, next); } start_point = end_point + 1; }