chiark / gitweb /
Separate selecting usable hints from emitting them
authorBen Harris <bjh21@bjh21.me.uk>
Sat, 16 Nov 2024 18:58:41 +0000 (18:58 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Sat, 16 Nov 2024 18:58:41 +0000 (18:58 +0000)
Now there's a select_hints() function that decides what hints should
be emitted, and emit_hints() just handles putting those hints into a
charstring.  I hope this will make each function reasonably simple.
Importantly, it means that select_hints() can be called twice, once
for horizontal stems and once for vertical ones.

bedstead.c

index cc2a0f00b0594669795723254617cdff70f89efd..e120c756197066e9af72eebb73e957021318efb9 100644 (file)
@@ -3808,12 +3808,25 @@ emit_path(void)
        printf(" endchar");
 }
 
+static void
+select_hints(int nstems, int stems[nstems])
+{
+
+       for (int i = 0; i < nstems; i++) {
+               if (stems[i] > 0) {
+                       stems[i] = 1;
+                       if (i + 1 < nstems) stems[i + 1] = 0;
+               }
+       }
+}
+
 static void
 emit_hints(int vstems[XSIZE], int hstems[YSIZE])
 {
        int i, start, size, cur;
        bool printed;
 
+       select_hints(YSIZE, hstems);
        cur = DESCENT * YPIX; printed = false;
        size = YPIX_S;
        for (i = YSIZE - 1; i >= 0; i--) {
@@ -3823,12 +3836,12 @@ emit_hints(int vstems[XSIZE], int hstems[YSIZE])
                               (double)((start - cur) / YSCALE),
                               (double)(size / YSCALE));
                        cur = start + size;
-                       i--; /* Avoid overlapping stems. */
                        printed = true;
                }
        }
        if (printed) printf(" hstem");
 
+       select_hints(XSIZE, vstems);
        cur = 0; printed = false;
        size = XPIX_S + weight->weight;
        for (i = 0; i < XSIZE; i++) {
@@ -3838,7 +3851,6 @@ emit_hints(int vstems[XSIZE], int hstems[YSIZE])
                               (double)((start - cur) / XSCALE),
                               (double)(size / XSCALE));
                        cur = start + size;
-                       i++; /* Avoid overlapping stems. */
                        printed = true;
                }
        }