[draw] Emit move_to immediately, like other operators

This commit is contained in:
Behdad Esfahbod 2022-02-10 16:27:18 -06:00
parent aca80a4a40
commit 151f205819
3 changed files with 14 additions and 19 deletions

View File

@ -97,8 +97,9 @@ struct hb_draw_funcs_t
float to_x, float to_y)
{
if (st.path_open) close_path (draw_data, st);
st.current_x = st.path_start_x = to_x;
st.current_y = st.path_start_y = to_y;
emit_move_to (draw_data, st, to_x, to_y);
st.current_x = to_x;
st.current_y = to_y;
}
void line_to (void *draw_data, hb_draw_state_t &st,
@ -152,7 +153,8 @@ struct hb_draw_funcs_t
{
assert (!st.path_open);
st.path_open = true;
emit_move_to (draw_data, st, st.path_start_x, st.path_start_y);
st.path_start_x = st.current_x;
st.path_start_y = st.current_y;
}
};
DECLARE_NULL_INSTANCE (hb_draw_funcs_t);

View File

@ -534,6 +534,9 @@ hb_draw_move_to_default (hb_draw_funcs_t *dfuncs HB_UNUSED,
st->path_start_x *= x_scale;
st->path_start_y *= y_scale;
st->current_x *= x_scale;
st->current_y *= y_scale;
adaptor->draw_funcs->emit_move_to (adaptor->draw_data, *st,
x_scale * to_x, y_scale * to_y);
}

View File

@ -7,7 +7,6 @@
struct _draw_data_t
{
bool is_open;
unsigned path_len;
float path_start_x;
float path_start_y;
@ -22,8 +21,7 @@ _move_to (hb_draw_funcs_t *dfuncs, void *draw_data_,
void *user_data)
{
_draw_data_t *draw_data = (_draw_data_t *) draw_data_;
assert (!draw_data->is_open);
draw_data->is_open = true;
assert (!st->path_open);
draw_data->path_start_x = draw_data->path_last_x = to_x;
draw_data->path_start_y = draw_data->path_last_y = to_y;
}
@ -35,8 +33,7 @@ _line_to (hb_draw_funcs_t *dfuncs, void *draw_data_,
void *user_data)
{
_draw_data_t *draw_data = (_draw_data_t *) draw_data_;
assert (draw_data->is_open);
// assert (draw_data->path_last_x != to_x || draw_data->path_last_y != to_y);
assert (st->path_open);
++draw_data->path_len;
draw_data->path_last_x = to_x;
draw_data->path_last_y = to_y;
@ -50,9 +47,7 @@ _quadratic_to (hb_draw_funcs_t *dfuncs, void *draw_data_,
void *user_data)
{
_draw_data_t *draw_data = (_draw_data_t *) draw_data_;
assert (draw_data->is_open);
/* assert (draw_data->path_last_x != control_x || draw_data->path_last_y != control_y ||
draw_data->path_last_x != to_x || draw_data->path_last_y != to_y); */
assert (st->path_open);
++draw_data->path_len;
draw_data->path_last_x = to_x;
draw_data->path_last_y = to_y;
@ -67,10 +62,7 @@ _cubic_to (hb_draw_funcs_t *dfuncs, void *draw_data_,
void *user_data)
{
_draw_data_t *draw_data = (_draw_data_t *) draw_data_;
assert (draw_data->is_open);
/* assert (draw_data->path_last_x != control1_x || draw_data->path_last_y != control1_y ||
draw_data->path_last_x != control2_x || draw_data->path_last_y != control2_y ||
draw_data->path_last_x != to_x || draw_data->path_last_y != to_y); */
assert (st->path_open);
++draw_data->path_len;
draw_data->path_last_x = to_x;
draw_data->path_last_y = to_y;
@ -82,9 +74,8 @@ _close_path (hb_draw_funcs_t *dfuncs, void *draw_data_,
void *user_data)
{
_draw_data_t *draw_data = (_draw_data_t *) draw_data_;
assert (draw_data->is_open && draw_data->path_len != 0);
assert (st->path_open && draw_data->path_len != 0);
draw_data->path_len = 0;
draw_data->is_open = false;
assert (draw_data->path_start_x == draw_data->path_last_x &&
draw_data->path_start_y == draw_data->path_last_y);
}
@ -147,7 +138,7 @@ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
unsigned glyph_count = hb_face_get_glyph_count (face);
glyph_count = glyph_count > 16 ? 16 : glyph_count;
_draw_data_t draw_data = {false, 0, 0, 0, 0, 0};
_draw_data_t draw_data = {0, 0, 0, 0, 0};
hb_draw_funcs_t *funcs = hb_draw_funcs_create ();
hb_draw_funcs_set_move_to_func (funcs, (hb_draw_move_to_func_t) _move_to, nullptr, nullptr);
@ -160,7 +151,6 @@ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
for (unsigned gid = 0; gid < glyph_count; ++gid)
{
hb_font_get_glyph_shape (font, gid, funcs, &draw_data);
assert (!draw_data.is_open);
/* Glyph extents also may practices the similar path, call it now that is related */
hb_glyph_extents_t extents;