From cf28bd71efd7dc2bc7634cc06f41184a0b6418a7 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Mon, 18 Nov 2024 23:29:57 +0000 Subject: [PATCH] Counter-mask support in select_hints() It detects evenly-spaced runs of at least three stems, which is a surprisingly fiddly thing to code. --- bedstead.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/bedstead.c b/bedstead.c index 6439e15..27b7d2c 100644 --- a/bedstead.c +++ b/bedstead.c @@ -3810,7 +3810,7 @@ emit_path(void) /* An "A" edge is top or left, a "Z" edge is bottom or right. */ enum hint_type { - hint_none, hint_stem, hint_aedge, hint_zedge + hint_none, hint_stem, hint_counter_stem, hint_aedge, hint_zedge }; static void @@ -3837,6 +3837,17 @@ select_hints(int nstems, int stems[nstems], } } } + /* Look for evenly spaced stems to attach counter masks to. */ + for (int step = 2; step < (nstems + 1) / 2; step++) + for (int i = 0; i < nstems - 2 * step; i++) + if (hints[i] && hints[i+step] && hints[i+step*2]) { + for (int j = i; j < nstems; j += step) + if (hints[j]) + hints[j] = hint_counter_stem; + else break; + goto counters_done; + } +counters_done: /* * Now look for edge hints, preferring ones closer to the edge * of the character. @@ -3850,7 +3861,7 @@ select_hints(int nstems, int stems[nstems], (i == nstems - 1 || hints[i+1] == hint_none)) hints[i] = hint_zedge; printf(""); } @@ -3867,6 +3878,7 @@ emit_hints(int vstems[XSIZE], int ledges[XSIZE], int redges[XSIZE], for (i = 0; i < YSIZE; i++) { switch (hhints[YSIZE - 1 - i]) { case hint_stem: + case hint_counter_stem: start = i * YPIX_S; size = YPIX_S; break; @@ -3894,6 +3906,7 @@ emit_hints(int vstems[XSIZE], int ledges[XSIZE], int redges[XSIZE], for (i = 0; i < XSIZE; i++) { switch (vhints[i]) { case hint_stem: + case hint_counter_stem: start = i * XPIX_S - weight->weight; size = XPIX_S + weight->weight; break; -- 2.30.2