[cubic-glyf] Handle contour-initial cubic offcurves

This commit is contained in:
Behdad Esfahbod 2023-02-21 15:25:59 -07:00
parent 9c27fe625f
commit 050f5a58fe
1 changed files with 12 additions and 3 deletions

View File

@ -26,13 +26,13 @@ struct path_builder_t
optional_point_t lerp (optional_point_t p, float t) optional_point_t lerp (optional_point_t p, float t)
{ return optional_point_t (x + t * (p.x - x), y + t * (p.y - y)); } { return optional_point_t (x + t * (p.x - x), y + t * (p.y - y)); }
} first_oncurve, first_offcurve, last_offcurve, last_offcurve2; } first_oncurve, first_offcurve, first_offcurve2, last_offcurve, last_offcurve2;
path_builder_t (hb_font_t *font_, hb_draw_session_t &draw_session_) path_builder_t (hb_font_t *font_, hb_draw_session_t &draw_session_)
{ {
font = font_; font = font_;
draw_session = &draw_session_; draw_session = &draw_session_;
first_oncurve = first_offcurve = last_offcurve = last_offcurve2 = optional_point_t (); first_oncurve = first_offcurve = first_offcurve2 = last_offcurve = last_offcurve2 = optional_point_t ();
} }
/* based on https://github.com/RazrFalcon/ttf-parser/blob/4f32821/src/glyf.rs#L287 /* based on https://github.com/RazrFalcon/ttf-parser/blob/4f32821/src/glyf.rs#L287
@ -59,7 +59,12 @@ struct path_builder_t
} }
else else
{ {
if (first_offcurve) if (is_cubic && !first_offcurve2)
{
first_offcurve2 = first_offcurve;
first_offcurve = p;
}
else if (first_offcurve)
{ {
optional_point_t mid = first_offcurve.lerp (p, .5f); optional_point_t mid = first_offcurve.lerp (p, .5f);
first_oncurve = mid; first_oncurve = mid;
@ -133,6 +138,10 @@ struct path_builder_t
/* now check the rest */ /* now check the rest */
} }
if (first_offcurve2 && first_offcurve && first_oncurve)
draw_session->cubic_to (first_offcurve2.x, first_offcurve2.y,
first_offcurve.x, first_offcurve.y,
first_oncurve.x, first_oncurve.y);
if (first_offcurve && first_oncurve) if (first_offcurve && first_oncurve)
draw_session->quadratic_to (first_offcurve.x, first_offcurve.y, draw_session->quadratic_to (first_offcurve.x, first_offcurve.y,
first_oncurve.x, first_oncurve.y); first_oncurve.x, first_oncurve.y);