[draw-state] Pass state down to callbacks

This commit is contained in:
Behdad Esfahbod 2022-02-03 14:10:40 -06:00
parent a9dd9f0bae
commit f1a9a9ccaf
6 changed files with 42 additions and 17 deletions

View File

@ -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) {}

View File

@ -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

View File

@ -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);

View File

@ -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");

View File

@ -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;

View File

@ -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_;