chiark / gitweb /
Support for edge hints in select_hints()
authorBen Harris <bjh21@bjh21.me.uk>
Sun, 17 Nov 2024 13:43:08 +0000 (13:43 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Sun, 17 Nov 2024 13:43:08 +0000 (13:43 +0000)
Which demonstrated plenty of bugs in the code generating them.
Currently edge hints only appear in a helpful comment.

bedstead.c

index b07d267f95a6287db297175c760185879a3104ef..459ec2cc9aea3a51f3883a880fc41f94e710decb 100644 (file)
@@ -3837,6 +3837,21 @@ select_hints(int nstems, int stems[nstems],
                        }
                }
        }
+       /*
+        * Now look for edge hints, preferring ones closer to the edge
+        * of the character.
+        */
+       for (int i = 0; i < nstems - 1; i++)
+               if (aedges[i] > 0 && hints[i] == hint_none &&
+                   (i == 0 || hints[i-1] == hint_none))
+                       hints[i] = hint_aedge;
+       for (int i = nstems - 1; i >= 1; i--)
+               if (zedges[i] > 0 && hints[i] == hint_none &&
+                   (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]]);
+       printf(" -->");
 }
 
 static void
@@ -4035,8 +4050,8 @@ dochar(struct glyph *g)
 #define DL GETPIX(x-1, y+1)
 #define DR GETPIX(x+1, y+1)
 
-       for (x = 0; x < XSIZE; x++) vstems[x] = 0;
-       for (y = 0; y < YSIZE; y++) hstems[y] = 0;
+       for (x = 0; x < XSIZE; x++) vstems[x] = ledges[x] = redges[x] = 0;
+       for (y = 0; y < YSIZE; y++) hstems[y] = tedges[y] = bedges[y] = 0;
        clearpath();
        for (y = 0; y < YSIZE; y++) {
                for (x = 0; x < XSIZE; x++) {
@@ -4058,16 +4073,14 @@ dochar(struct glyph *g)
                                blackpixel(x, YSIZE - y - 1, bl, br, tr, tl);
                                if (!L && !R && (U || D))
                                        vstems[x]++;
-                               else if (!U && !D && (L || R))
+                               if (!U && !D && (L || R))
                                        hstems[y]++;
-                               else if (UL + U + UR + L + R + DL + D + DR == 0)
+                               if (UL + U + UR + L + R + DL + D + DR == 0)
                                        vstems[x]++, hstems[y]++;
-                               else { /* Not a stem.  Maybe an edge? */
-                                       if (UL + U + UR == 0) tedges[y]++;
-                                       if (DL + D + DR == 0) bedges[y]++;
-                                       if (UL + L + DL == 0) ledges[x]++;
-                                       if (UR + R + DR == 0) redges[x]++;
-                               }
+                               if (UL + U + UR == 0) tedges[y]++;
+                               if (DL + D + DR == 0) bedges[y]++;
+                               if (UL + L + DL == 0) ledges[x]++;
+                               if (UR + R + DR == 0) redges[x]++;
                        } else {
                                bool tl, tr, bl, br;