chiark / gitweb /
Counter-mask support in select_hints()
authorBen Harris <bjh21@bjh21.me.uk>
Mon, 18 Nov 2024 23:29:57 +0000 (23:29 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Mon, 18 Nov 2024 23:29:57 +0000 (23:29 +0000)
It detects evenly-spaced runs of at least three stems, which is a
surprisingly fiddly thing to code.

bedstead.c

index 6439e154659c405a93022ce7c149fc7af0ce35f1..27b7d2c109171ef7bd6d4a65b0f8c574241b2b8f 100644 (file)
@@ -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("<!-- HINTS ");
-       for (int i = 0; i < nstems; i++) printf("%c", ".|[]"[hints[i]]);
+       for (int i = 0; i < nstems; i++) printf("%c", ".|I[]"[hints[i]]);
        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;