From f1a9a9ccaf329e1d1935f468a8299fa9c8d663ba Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 3 Feb 2022 14:10:40 -0600 Subject: [PATCH] [draw-state] Pass state down to callbacks --- src/hb-draw.cc | 5 +++++ src/hb-draw.h | 5 +++++ src/hb-draw.hh | 34 +++++++++++++++++----------------- src/main.cc | 5 +++++ test/api/test-draw.c | 5 +++++ test/fuzzing/hb-draw-fuzzer.cc | 5 +++++ 6 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/hb-draw.cc b/src/hb-draw.cc index 058d5cb9c..d64b328b4 100644 --- a/src/hb-draw.cc +++ b/src/hb-draw.cc @@ -30,22 +30,26 @@ static void hb_draw_move_to_nil (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data HB_UNUSED, + hb_draw_state_t *st HB_UNUSED, float to_x HB_UNUSED, float to_y HB_UNUSED, void *user_data HB_UNUSED) {} static void hb_draw_line_to_nil (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data HB_UNUSED, + hb_draw_state_t *st HB_UNUSED, float to_x HB_UNUSED, float to_y HB_UNUSED, void *user_data HB_UNUSED) {} static void hb_draw_quadratic_to_nil (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data HB_UNUSED, + hb_draw_state_t *st HB_UNUSED, float control_x HB_UNUSED, float control_y HB_UNUSED, float to_x HB_UNUSED, float to_y HB_UNUSED, void *user_data HB_UNUSED) {} static void hb_draw_cubic_to_nil (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data HB_UNUSED, + hb_draw_state_t *st HB_UNUSED, float control1_x HB_UNUSED, float control1_y HB_UNUSED, float control2_x HB_UNUSED, float control2_y HB_UNUSED, float to_x HB_UNUSED, float to_y HB_UNUSED, @@ -53,6 +57,7 @@ hb_draw_cubic_to_nil (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data HB_UNUS static void hb_draw_close_path_nil (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data HB_UNUSED, + hb_draw_state_t *st HB_UNUSED, void *user_data HB_UNUSED) {} diff --git a/src/hb-draw.h b/src/hb-draw.h index f8332fcf7..0dea7f7dd 100644 --- a/src/hb-draw.h +++ b/src/hb-draw.h @@ -67,21 +67,26 @@ typedef struct hb_draw_funcs_t hb_draw_funcs_t; typedef void (*hb_draw_move_to_func_t) (hb_draw_funcs_t *dfuncs, void *draw_data, + hb_draw_state_t *st, float to_x, float to_y, void *user_data); typedef void (*hb_draw_line_to_func_t) (hb_draw_funcs_t *dfuncs, void *draw_data, + hb_draw_state_t *st, float to_x, float to_y, void *user_data); typedef void (*hb_draw_quadratic_to_func_t) (hb_draw_funcs_t *dfuncs, void *draw_data, + hb_draw_state_t *st, float control_x, float control_y, float to_x, float to_y, void *user_data); typedef void (*hb_draw_cubic_to_func_t) (hb_draw_funcs_t *dfuncs, void *draw_data, + hb_draw_state_t *st, float control1_x, float control1_y, float control2_x, float control2_y, float to_x, float to_y, void *user_data); typedef void (*hb_draw_close_path_func_t) (hb_draw_funcs_t *dfuncs, void *draw_data, + hb_draw_state_t *st, void *user_data); HB_EXTERN void diff --git a/src/hb-draw.hh b/src/hb-draw.hh index 1357915ed..c4919d42e 100644 --- a/src/hb-draw.hh +++ b/src/hb-draw.hh @@ -62,34 +62,34 @@ struct hb_draw_funcs_t #undef HB_DRAW_FUNC_IMPLEMENT } destroy; - void emit_move_to (void *draw_data, + void emit_move_to (void *draw_data, hb_draw_state_t &st, float to_x, float to_y) - { func.move_to (this, draw_data, + { func.move_to (this, draw_data, &st, to_x, to_y, user_data.move_to); } - void emit_line_to (void *draw_data, + void emit_line_to (void *draw_data, hb_draw_state_t &st, float to_x, float to_y) - { func.line_to (this, draw_data, + { func.line_to (this, draw_data, &st, to_x, to_y, user_data.line_to); } - void emit_quadratic_to (void *draw_data, + void emit_quadratic_to (void *draw_data, hb_draw_state_t &st, float control_x, float control_y, float to_x, float to_y) - { func.quadratic_to (this, draw_data, + { func.quadratic_to (this, draw_data, &st, control_x, control_y, to_x, to_y, user_data.quadratic_to); } - void emit_cubic_to (void *draw_data, + void emit_cubic_to (void *draw_data, hb_draw_state_t &st, float control1_x, float control1_y, float control2_x, float control2_y, float to_x, float to_y) - { func.cubic_to (this, draw_data, + { func.cubic_to (this, draw_data, &st, control1_x, control1_y, control2_x, control2_y, to_x, to_y, user_data.cubic_to); } - void emit_close_path (void *draw_data) - { func.close_path (this, draw_data, + void emit_close_path (void *draw_data, hb_draw_state_t &st) + { func.close_path (this, draw_data, &st, user_data.close_path); } /* XXX Remove */ @@ -107,7 +107,7 @@ struct hb_draw_funcs_t float to_x, float to_y) { if (!st.path_open) start_path (draw_data, st); - emit_line_to (draw_data, to_x, to_y); + emit_line_to (draw_data, st, to_x, to_y); st.current_x = to_x; st.current_y = to_y; } @@ -119,9 +119,9 @@ struct hb_draw_funcs_t { if (!st.path_open) start_path (draw_data, st); if (quadratic_to_is_set ()) - emit_quadratic_to (draw_data, control_x, control_y, to_x, to_y); + emit_quadratic_to (draw_data, st, control_x, control_y, to_x, to_y); else - emit_cubic_to (draw_data, + emit_cubic_to (draw_data, st, (st.current_x + 2.f * control_x) / 3.f, (st.current_y + 2.f * control_y) / 3.f, (to_x + 2.f * control_x) / 3.f, @@ -138,7 +138,7 @@ struct hb_draw_funcs_t float to_x, float to_y) { if (!st.path_open) start_path (draw_data, st); - emit_cubic_to (draw_data, control1_x, control1_y, control2_x, control2_y, to_x, to_y); + emit_cubic_to (draw_data, st, control1_x, control1_y, control2_x, control2_y, to_x, to_y); st.current_x = to_x; st.current_y = to_y; } @@ -149,8 +149,8 @@ struct hb_draw_funcs_t if (st.path_open) { if ((st.path_start_x != st.current_x) || (st.path_start_y != st.current_y)) - emit_line_to (draw_data, st.path_start_x, st.path_start_y); - emit_close_path (draw_data); + emit_line_to (draw_data, st, st.path_start_x, st.path_start_y); + emit_close_path (draw_data, st); } st.path_open = false; st.path_start_x = st.current_x = st.path_start_y = st.current_y = 0; @@ -162,7 +162,7 @@ struct hb_draw_funcs_t { assert (!st.path_open); st.path_open = true; - emit_move_to (draw_data, st.path_start_x, st.path_start_y); + emit_move_to (draw_data, st, st.path_start_x, st.path_start_y); } }; DECLARE_NULL_INSTANCE (hb_draw_funcs_t); diff --git a/src/main.cc b/src/main.cc index 7fe94642e..fa35ae177 100644 --- a/src/main.cc +++ b/src/main.cc @@ -137,6 +137,7 @@ struct draw_data_t static void move_to (hb_draw_funcs_t *dfuncs, draw_data_t *draw_data, + hb_draw_state_t *st, float to_x, float to_y, void *) { @@ -145,6 +146,7 @@ move_to (hb_draw_funcs_t *dfuncs, draw_data_t *draw_data, static void line_to (hb_draw_funcs_t *dfuncs, draw_data_t *draw_data, + hb_draw_state_t *st, float to_x, float to_y, void *) { @@ -153,6 +155,7 @@ line_to (hb_draw_funcs_t *dfuncs, draw_data_t *draw_data, static void quadratic_to (hb_draw_funcs_t *dfuncs, draw_data_t *draw_data, + hb_draw_state_t *st, float control_x, float control_y, float to_x, float to_y, void *) @@ -163,6 +166,7 @@ quadratic_to (hb_draw_funcs_t *dfuncs, draw_data_t *draw_data, static void cubic_to (hb_draw_funcs_t *dfuncs, draw_data_t *draw_data, + hb_draw_state_t *st, float control1_x, float control1_y, float control2_x, float control2_y, float to_x, float to_y, @@ -175,6 +179,7 @@ cubic_to (hb_draw_funcs_t *dfuncs, draw_data_t *draw_data, static void close_path (hb_draw_funcs_t *dfuncs, draw_data_t *draw_data, + hb_draw_state_t *st, void *) { fprintf (draw_data->f, "Z"); diff --git a/test/api/test-draw.c b/test/api/test-draw.c index 0040daa54..be90f7c08 100644 --- a/test/api/test-draw.c +++ b/test/api/test-draw.c @@ -97,6 +97,7 @@ test_itoa (void) static void move_to (hb_draw_funcs_t *dfuncs, draw_data_t *draw_data, + hb_draw_state_t *st, float to_x, float to_y, void *user_data) { @@ -110,6 +111,7 @@ move_to (hb_draw_funcs_t *dfuncs, draw_data_t *draw_data, static void line_to (hb_draw_funcs_t *dfuncs, draw_data_t *draw_data, + hb_draw_state_t *st, float to_x, float to_y, void *user_data) { @@ -122,6 +124,7 @@ line_to (hb_draw_funcs_t *dfuncs, draw_data_t *draw_data, static void quadratic_to (hb_draw_funcs_t *dfuncs, draw_data_t *draw_data, + hb_draw_state_t *st, float control_x, float control_y, float to_x, float to_y, void *user_data) @@ -140,6 +143,7 @@ quadratic_to (hb_draw_funcs_t *dfuncs, draw_data_t *draw_data, static void cubic_to (hb_draw_funcs_t *dfuncs, draw_data_t *draw_data, + hb_draw_state_t *st, float control1_x, float control1_y, float control2_x, float control2_y, float to_x, float to_y, @@ -162,6 +166,7 @@ cubic_to (hb_draw_funcs_t *dfuncs, draw_data_t *draw_data, static void close_path (hb_draw_funcs_t *dfuncs, draw_data_t *draw_data, + hb_draw_state_t *st, void *user_data) { if (draw_data->consumed + 2 > draw_data->size) return; diff --git a/test/fuzzing/hb-draw-fuzzer.cc b/test/fuzzing/hb-draw-fuzzer.cc index 6da5c2ed3..f265889ef 100644 --- a/test/fuzzing/hb-draw-fuzzer.cc +++ b/test/fuzzing/hb-draw-fuzzer.cc @@ -17,6 +17,7 @@ struct _draw_data_t static void _move_to (hb_draw_funcs_t *dfuncs, void *draw_data_, + hb_draw_state_t *st, float to_x, float to_y, void *user_data) { @@ -29,6 +30,7 @@ _move_to (hb_draw_funcs_t *dfuncs, void *draw_data_, static void _line_to (hb_draw_funcs_t *dfuncs, void *draw_data_, + hb_draw_state_t *st, float to_x, float to_y, void *user_data) { @@ -42,6 +44,7 @@ _line_to (hb_draw_funcs_t *dfuncs, void *draw_data_, static void _quadratic_to (hb_draw_funcs_t *dfuncs, void *draw_data_, + hb_draw_state_t *st, float control_x, float control_y, float to_x, float to_y, void *user_data) @@ -57,6 +60,7 @@ _quadratic_to (hb_draw_funcs_t *dfuncs, void *draw_data_, static void _cubic_to (hb_draw_funcs_t *dfuncs, void *draw_data_, + hb_draw_state_t *st, float control1_x, float control1_y, float control2_x, float control2_y, float to_x, float to_y, @@ -74,6 +78,7 @@ _cubic_to (hb_draw_funcs_t *dfuncs, void *draw_data_, static void _close_path (hb_draw_funcs_t *dfuncs, void *draw_data_, + hb_draw_state_t *st, void *user_data) { _draw_data_t *draw_data = (_draw_data_t *) draw_data_;