From 6b4a6fbedded342182cca5356707050696912753 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 1 Feb 2023 15:59:37 -0700 Subject: [PATCH] [embolden] Add orientation detection --- src/hb-draw-embolden.hh | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/hb-draw-embolden.hh b/src/hb-draw-embolden.hh index 60ac3dc13..a9c95ab97 100644 --- a/src/hb-draw-embolden.hh +++ b/src/hb-draw-embolden.hh @@ -51,7 +51,7 @@ using hb_contour_t = hb_vector_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 points; hb_vector_t 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 {