[draw-session] Add slant

This commit is contained in:
Behdad Esfahbod 2022-02-07 17:53:38 -06:00
parent 4f2704adb6
commit aa5c7a3811
1 changed files with 36 additions and 14 deletions

View File

@ -159,38 +159,59 @@ DECLARE_NULL_INSTANCE (hb_draw_funcs_t);
struct hb_draw_session_t struct hb_draw_session_t
{ {
hb_draw_session_t (hb_draw_funcs_t *funcs_, void *draw_data_) hb_draw_session_t (hb_draw_funcs_t *funcs_, void *draw_data_, float slant_ = 0.f)
: funcs {funcs_}, draw_data {draw_data_}, st HB_DRAW_STATE_DEFAULT {} : slant {slant_}, not_slanted {slant == 0.f},
funcs {funcs_}, draw_data {draw_data_}, st HB_DRAW_STATE_DEFAULT
{}
~hb_draw_session_t () { close_path (); } ~hb_draw_session_t () { close_path (); }
void move_to (float to_x, float to_y) void move_to (float to_x, float to_y)
{ {
if (likely (not_slanted))
funcs->move_to (draw_data, st, funcs->move_to (draw_data, st,
to_x, to_y); to_x, to_y);
else
funcs->move_to (draw_data, st,
to_x + to_y * slant, to_y);
} }
void line_to (float to_x, float to_y) void line_to (float to_x, float to_y)
{ {
if (likely (not_slanted))
funcs->line_to (draw_data, st, funcs->line_to (draw_data, st,
to_x, to_y); to_x, to_y);
else
funcs->line_to (draw_data, st,
to_x + to_y * slant, to_y);
} }
void void
quadratic_to (float control_x, float control_y, quadratic_to (float control_x, float control_y,
float to_x, float to_y) float to_x, float to_y)
{ {
if (likely (not_slanted))
funcs->quadratic_to (draw_data, st, funcs->quadratic_to (draw_data, st,
control_x, control_y, control_x, control_y,
to_x, to_y); to_x, to_y);
else
funcs->quadratic_to (draw_data, st,
control_x + control_y * slant, control_y,
to_x + to_y * slant, to_y);
} }
void void
cubic_to (float control1_x, float control1_y, cubic_to (float control1_x, float control1_y,
float control2_x, float control2_y, float control2_x, float control2_y,
float to_x, float to_y) float to_x, float to_y)
{ {
if (likely (not_slanted))
funcs->cubic_to (draw_data, st, funcs->cubic_to (draw_data, st,
control1_x, control1_y, control1_x, control1_y,
control2_x, control2_y, control2_x, control2_y,
to_x, to_y); to_x, to_y);
else
funcs->cubic_to (draw_data, st,
control1_x + control1_y * slant, control1_y,
control2_x + control2_y * slant, control2_y,
to_x + to_y * slant, to_y);
} }
void close_path () void close_path ()
{ {
@ -198,7 +219,8 @@ struct hb_draw_session_t
} }
protected: protected:
float slant;
bool not_slanted;
hb_draw_funcs_t *funcs; hb_draw_funcs_t *funcs;
void *draw_data; void *draw_data;
hb_draw_state_t st; hb_draw_state_t st;