From da37880e172c207001ceff65c51276538a2d90db Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Thu, 20 Feb 2020 19:01:43 +0330 Subject: [PATCH] [draw] Add a private bit field instead null-checking quad-to callback This doesn't imply the the design is good or stable just is better to not fail due to null quad-to callback so as our quad-cubic curves translation is currently table limited which can be revisited anytime. --- src/hb-draw.cc | 9 ++++++++- src/hb-draw.hh | 1 + src/hb-ot-glyf-table.hh | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/hb-draw.cc b/src/hb-draw.cc index f95bb8a13..797326398 100644 --- a/src/hb-draw.cc +++ b/src/hb-draw.cc @@ -81,6 +81,7 @@ hb_draw_funcs_set_quadratic_to_func (hb_draw_funcs_t *funcs, { if (unlikely (hb_object_is_immutable (funcs))) return; funcs->quadratic_to = quadratic_to; + funcs->is_quadratic_to_set = true; } /** @@ -123,6 +124,11 @@ _move_to_nil (hb_position_t to_x HB_UNUSED, hb_position_t to_y HB_UNUSED, void * static void _line_to_nil (hb_position_t to_x HB_UNUSED, hb_position_t to_y HB_UNUSED, void *user_data HB_UNUSED) {} +static void +_quadratic_to_nil (hb_position_t control_x HB_UNUSED, hb_position_t control_y HB_UNUSED, + hb_position_t to_x HB_UNUSED, hb_position_t to_y HB_UNUSED, + void *user_data HB_UNUSED) {} + static void _cubic_to_nil (hb_position_t control1_x HB_UNUSED, hb_position_t control1_y HB_UNUSED, hb_position_t control2_x HB_UNUSED, hb_position_t control2_y HB_UNUSED, @@ -148,7 +154,8 @@ hb_draw_funcs_create () funcs->move_to = (hb_draw_move_to_func_t) _move_to_nil; funcs->line_to = (hb_draw_line_to_func_t) _line_to_nil; - funcs->quadratic_to = nullptr; + funcs->quadratic_to = (hb_draw_quadratic_to_func_t) _quadratic_to_nil; + funcs->is_quadratic_to_set = false; funcs->cubic_to = (hb_draw_cubic_to_func_t) _cubic_to_nil; funcs->close_path = (hb_draw_close_path_func_t) _close_path_nil; return funcs; diff --git a/src/hb-draw.hh b/src/hb-draw.hh index acf315aed..16a34f162 100644 --- a/src/hb-draw.hh +++ b/src/hb-draw.hh @@ -34,6 +34,7 @@ struct hb_draw_funcs_t hb_draw_move_to_func_t move_to; hb_draw_line_to_func_t line_to; hb_draw_quadratic_to_func_t quadratic_to; + bool is_quadratic_to_set; hb_draw_cubic_to_func_t cubic_to; hb_draw_close_path_func_t close_path; }; diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index 31d1629dc..facc2f5cc 100644 --- a/src/hb-ot-glyf-table.hh +++ b/src/hb-ot-glyf-table.hh @@ -151,7 +151,7 @@ struct glyf TRACE_SERIALIZE (this); unsigned init_len = c->length (); for (const auto &_ : it) _.serialize (c, plan); - + /* As a special case when all glyph in the font are empty, add a zero byte * to the table, so that OTS doesn’t reject it, and to make the table work * on Windows as well. @@ -1073,7 +1073,7 @@ struct glyf font = font_; funcs = funcs_; user_data = user_data_; - quad_to = funcs->quadratic_to + quad_to = funcs->is_quadratic_to_set ? _normal_quadratic_to_call : _translate_quadratic_to_cubic; end_of_contour ();