[draw] Convert API to float instead of hb_position_t

This commit is contained in:
Behdad Esfahbod 2022-02-02 16:08:40 -06:00
parent d6e49b8278
commit 35190dc961
7 changed files with 61 additions and 61 deletions

View File

@ -119,20 +119,20 @@ hb_draw_funcs_set_close_path_func (hb_draw_funcs_t *funcs,
}
static void
_move_to_nil (hb_position_t to_x HB_UNUSED, hb_position_t to_y HB_UNUSED, void *user_data HB_UNUSED) {}
_move_to_nil (float to_x HB_UNUSED, float to_y HB_UNUSED, void *user_data HB_UNUSED) {}
static void
_line_to_nil (hb_position_t to_x HB_UNUSED, hb_position_t to_y HB_UNUSED, void *user_data HB_UNUSED) {}
_line_to_nil (float to_x HB_UNUSED, float to_y HB_UNUSED, void *user_data HB_UNUSED) {}
static void
_quadratic_to_nil (hb_position_t control_x HB_UNUSED, hb_position_t control_y HB_UNUSED,
hb_position_t to_x HB_UNUSED, hb_position_t to_y HB_UNUSED,
_quadratic_to_nil (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
_cubic_to_nil (hb_position_t control1_x HB_UNUSED, hb_position_t control1_y HB_UNUSED,
hb_position_t control2_x HB_UNUSED, hb_position_t control2_y HB_UNUSED,
hb_position_t to_x HB_UNUSED, hb_position_t to_y HB_UNUSED,
_cubic_to_nil (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,
void *user_data HB_UNUSED) {}
static void

View File

@ -33,14 +33,14 @@
HB_BEGIN_DECLS
typedef void (*hb_draw_move_to_func_t) (hb_position_t to_x, hb_position_t to_y, void *user_data);
typedef void (*hb_draw_line_to_func_t) (hb_position_t to_x, hb_position_t to_y, void *user_data);
typedef void (*hb_draw_quadratic_to_func_t) (hb_position_t control_x, hb_position_t control_y,
hb_position_t to_x, hb_position_t to_y,
typedef void (*hb_draw_move_to_func_t) (float to_x, float to_y, void *user_data);
typedef void (*hb_draw_line_to_func_t) (float to_x, float to_y, void *user_data);
typedef void (*hb_draw_quadratic_to_func_t) (float control_x, float control_y,
float to_x, float to_y,
void *user_data);
typedef void (*hb_draw_cubic_to_func_t) (hb_position_t control1_x, hb_position_t control1_y,
hb_position_t control2_x, hb_position_t control2_y,
hb_position_t to_x, hb_position_t to_y,
typedef void (*hb_draw_cubic_to_func_t) (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) (void *user_data);

View File

@ -50,14 +50,14 @@ struct draw_helper_t
}
~draw_helper_t () { end_path (); }
void move_to (hb_position_t x, hb_position_t y)
void move_to (float x, float y)
{
if (path_open) end_path ();
current_x = path_start_x = x;
current_y = path_start_y = y;
}
void line_to (hb_position_t x, hb_position_t y)
void line_to (float x, float y)
{
if (equal_to_current (x, y)) return;
if (!path_open) start_path ();
@ -67,8 +67,8 @@ struct draw_helper_t
}
void
quadratic_to (hb_position_t control_x, hb_position_t control_y,
hb_position_t to_x, hb_position_t to_y)
quadratic_to (float control_x, float control_y,
float to_x, float to_y)
{
if (equal_to_current (control_x, control_y) && equal_to_current (to_x, to_y))
return;
@ -86,9 +86,9 @@ struct draw_helper_t
}
void
cubic_to (hb_position_t control1_x, hb_position_t control1_y,
hb_position_t control2_x, hb_position_t control2_y,
hb_position_t to_x, hb_position_t to_y)
cubic_to (float control1_x, float control1_y,
float control2_x, float control2_y,
float to_x, float to_y)
{
if (equal_to_current (control1_x, control1_y) &&
equal_to_current (control2_x, control2_y) &&
@ -113,7 +113,7 @@ struct draw_helper_t
}
protected:
bool equal_to_current (hb_position_t x, hb_position_t y)
bool equal_to_current (float x, float y)
{ return current_x == x && current_y == y; }
void start_path ()
@ -123,11 +123,11 @@ struct draw_helper_t
funcs->move_to (path_start_x, path_start_y, user_data);
}
hb_position_t path_start_x;
hb_position_t path_start_y;
float path_start_x;
float path_start_y;
hb_position_t current_x;
hb_position_t current_y;
float current_x;
float current_y;
bool path_open;
const hb_draw_funcs_t *funcs;

View File

@ -457,14 +457,14 @@ struct cff1_path_param_t
{
point_t point = p;
if (delta) point.move (*delta);
draw_helper->move_to (font->em_scalef_x (point.x.to_real ()), font->em_scalef_y (point.y.to_real ()));
draw_helper->move_to (font->em_fscalef_x (point.x.to_real ()), font->em_fscalef_y (point.y.to_real ()));
}
void line_to (const point_t &p)
{
point_t point = p;
if (delta) point.move (*delta);
draw_helper->line_to (font->em_scalef_x (point.x.to_real ()), font->em_scalef_y (point.y.to_real ()));
draw_helper->line_to (font->em_fscalef_x (point.x.to_real ()), font->em_fscalef_y (point.y.to_real ()));
}
void cubic_to (const point_t &p1, const point_t &p2, const point_t &p3)
@ -476,9 +476,9 @@ struct cff1_path_param_t
point2.move (*delta);
point3.move (*delta);
}
draw_helper->cubic_to (font->em_scalef_x (point1.x.to_real ()), font->em_scalef_y (point1.y.to_real ()),
font->em_scalef_x (point2.x.to_real ()), font->em_scalef_y (point2.y.to_real ()),
font->em_scalef_x (point3.x.to_real ()), font->em_scalef_y (point3.y.to_real ()));
draw_helper->cubic_to (font->em_fscalef_x (point1.x.to_real ()), font->em_fscalef_y (point1.y.to_real ()),
font->em_fscalef_x (point2.x.to_real ()), font->em_fscalef_y (point2.y.to_real ()),
font->em_fscalef_x (point3.x.to_real ()), font->em_fscalef_y (point3.y.to_real ()));
}
void end_path () { draw_helper->end_path (); }

View File

@ -152,16 +152,16 @@ struct cff2_path_param_t
}
void move_to (const point_t &p)
{ draw_helper->move_to (font->em_scalef_x (p.x.to_real ()), font->em_scalef_y (p.y.to_real ())); }
{ draw_helper->move_to (font->em_fscalef_x (p.x.to_real ()), font->em_fscalef_y (p.y.to_real ())); }
void line_to (const point_t &p)
{ draw_helper->line_to (font->em_scalef_x (p.x.to_real ()), font->em_scalef_y (p.y.to_real ())); }
{ draw_helper->line_to (font->em_fscalef_x (p.x.to_real ()), font->em_fscalef_y (p.y.to_real ())); }
void cubic_to (const point_t &p1, const point_t &p2, const point_t &p3)
{
draw_helper->cubic_to (font->em_scalef_x (p1.x.to_real ()), font->em_scalef_y (p1.y.to_real ()),
font->em_scalef_x (p2.x.to_real ()), font->em_scalef_y (p2.y.to_real ()),
font->em_scalef_x (p3.x.to_real ()), font->em_scalef_y (p3.y.to_real ()));
draw_helper->cubic_to (font->em_fscalef_x (p1.x.to_real ()), font->em_fscalef_y (p1.y.to_real ()),
font->em_fscalef_x (p2.x.to_real ()), font->em_fscalef_y (p2.y.to_real ()),
font->em_fscalef_x (p3.x.to_real ()), font->em_fscalef_y (p3.y.to_real ()));
}
protected:

View File

@ -1194,7 +1194,7 @@ struct glyf
if (is_on_curve)
{
first_oncurve = p;
draw_helper->move_to (font->em_scalef_x (p.x), font->em_scalef_y (p.y));
draw_helper->move_to (font->em_fscalef_x (p.x), font->em_fscalef_y (p.y));
}
else
{
@ -1203,7 +1203,7 @@ struct glyf
optional_point_t mid = first_offcurve.lerp (p, .5f);
first_oncurve = mid;
last_offcurve = p;
draw_helper->move_to (font->em_scalef_x (mid.x), font->em_scalef_y (mid.y));
draw_helper->move_to (font->em_fscalef_x (mid.x), font->em_fscalef_y (mid.y));
}
else
first_offcurve = p;
@ -1215,22 +1215,22 @@ struct glyf
{
if (is_on_curve)
{
draw_helper->quadratic_to (font->em_scalef_x (last_offcurve.x), font->em_scalef_y (last_offcurve.y),
font->em_scalef_x (p.x), font->em_scalef_y (p.y));
draw_helper->quadratic_to (font->em_fscalef_x (last_offcurve.x), font->em_fscalef_y (last_offcurve.y),
font->em_fscalef_x (p.x), font->em_fscalef_y (p.y));
last_offcurve = optional_point_t ();
}
else
{
optional_point_t mid = last_offcurve.lerp (p, .5f);
draw_helper->quadratic_to (font->em_scalef_x (last_offcurve.x), font->em_scalef_y (last_offcurve.y),
font->em_scalef_x (mid.x), font->em_scalef_y (mid.y));
draw_helper->quadratic_to (font->em_fscalef_x (last_offcurve.x), font->em_fscalef_y (last_offcurve.y),
font->em_fscalef_x (mid.x), font->em_fscalef_y (mid.y));
last_offcurve = p;
}
}
else
{
if (is_on_curve)
draw_helper->line_to (font->em_scalef_x (p.x), font->em_scalef_y (p.y));
draw_helper->line_to (font->em_fscalef_x (p.x), font->em_fscalef_y (p.y));
else
last_offcurve = p;
}
@ -1241,20 +1241,20 @@ struct glyf
if (first_offcurve.has_data && last_offcurve.has_data)
{
optional_point_t mid = last_offcurve.lerp (first_offcurve, .5f);
draw_helper->quadratic_to (font->em_scalef_x (last_offcurve.x), font->em_scalef_y (last_offcurve.y),
font->em_scalef_x (mid.x), font->em_scalef_y (mid.y));
draw_helper->quadratic_to (font->em_fscalef_x (last_offcurve.x), font->em_fscalef_y (last_offcurve.y),
font->em_fscalef_x (mid.x), font->em_fscalef_y (mid.y));
last_offcurve = optional_point_t ();
/* now check the rest */
}
if (first_offcurve.has_data && first_oncurve.has_data)
draw_helper->quadratic_to (font->em_scalef_x (first_offcurve.x), font->em_scalef_y (first_offcurve.y),
font->em_scalef_x (first_oncurve.x), font->em_scalef_y (first_oncurve.y));
draw_helper->quadratic_to (font->em_fscalef_x (first_offcurve.x), font->em_fscalef_y (first_offcurve.y),
font->em_fscalef_x (first_oncurve.x), font->em_fscalef_y (first_oncurve.y));
else if (last_offcurve.has_data && first_oncurve.has_data)
draw_helper->quadratic_to (font->em_scalef_x (last_offcurve.x), font->em_scalef_y (last_offcurve.y),
font->em_scalef_x (first_oncurve.x), font->em_scalef_y (first_oncurve.y));
draw_helper->quadratic_to (font->em_fscalef_x (last_offcurve.x), font->em_fscalef_y (last_offcurve.y),
font->em_fscalef_x (first_oncurve.x), font->em_fscalef_y (first_oncurve.y));
else if (first_oncurve.has_data)
draw_helper->line_to (font->em_scalef_x (first_oncurve.x), font->em_scalef_y (first_oncurve.y));
draw_helper->line_to (font->em_fscalef_x (first_oncurve.x), font->em_fscalef_y (first_oncurve.y));
/* Getting ready for the next contour */
first_oncurve = first_offcurve = last_offcurve = optional_point_t ();

View File

@ -136,33 +136,33 @@ struct user_data_t
};
static void
move_to (hb_position_t to_x, hb_position_t to_y, user_data_t &user_data)
move_to (float to_x, float to_y, user_data_t &user_data)
{
fprintf (user_data.f, "M%d,%d", to_x, user_data.ascender - to_y);
fprintf (user_data.f, "M%g,%g", to_x, user_data.ascender - to_y);
}
static void
line_to (hb_position_t to_x, hb_position_t to_y, user_data_t &user_data)
line_to (float to_x, float to_y, user_data_t &user_data)
{
fprintf (user_data.f, "L%d,%d", to_x, user_data.ascender - to_y);
fprintf (user_data.f, "L%g,%g", to_x, user_data.ascender - to_y);
}
static void
quadratic_to (hb_position_t control_x, hb_position_t control_y,
hb_position_t to_x, hb_position_t to_y,
quadratic_to (float control_x, float control_y,
float to_x, float to_y,
user_data_t &user_data)
{
fprintf (user_data.f, "Q%d,%d %d,%d", control_x, user_data.ascender - control_y,
fprintf (user_data.f, "Q%g,%g %g,%g", control_x, user_data.ascender - control_y,
to_x, user_data.ascender - to_y);
}
static void
cubic_to (hb_position_t control1_x, hb_position_t control1_y,
hb_position_t control2_x, hb_position_t control2_y,
hb_position_t to_x, hb_position_t to_y,
cubic_to (float control1_x, float control1_y,
float control2_x, float control2_y,
float to_x, float to_y,
user_data_t &user_data)
{
fprintf (user_data.f, "C%d,%d %d,%d %d,%d", control1_x, user_data.ascender - control1_y,
fprintf (user_data.f, "C%g,%g %g,%g %g,%g", control1_x, user_data.ascender - control1_y,
control2_x, user_data.ascender - control2_y,
to_x, user_data.ascender - to_y);
}