[embolden] Add orientation detection

This commit is contained in:
Behdad Esfahbod 2023-02-01 15:59:37 -07:00
parent 1817f18085
commit 6b4a6fbedd
1 changed files with 22 additions and 2 deletions

View File

@ -51,7 +51,7 @@ using hb_contour_t = hb_vector_t<hb_contour_point_t>;
struct hb_recording_pen_t
{
void replay (hb_draw_funcs_t *pen, void *pen_data)
void replay (hb_draw_funcs_t *pen, void *pen_data) const
{
hb_draw_state_t st = HB_DRAW_STATE_DEFAULT;
@ -101,6 +101,26 @@ struct hb_recording_pen_t
}
}
float area () const
{
float a = 0;
unsigned first = 0;
for (unsigned contour : contours)
{
for (unsigned i = first; i < contour; i++)
{
unsigned j = i + 1 < contour ? i + 1 : first;
auto &pi = points[i];
auto &pj = points[j];
a += pi.x * pj.y - pi.y * pj.x;
}
first = contour;
}
return a * .5f;
}
hb_vector_t<hb_contour_point_t> points;
hb_vector_t<unsigned> contours;
};
@ -181,7 +201,7 @@ struct hb_draw_embolden_context_t : hb_recording_pen_t
x_strength /= 2.f;
y_strength /= 2.f;
bool orientation_negative = true;
bool orientation_negative = area () < 0;
struct vector_t
{