Separate selecting usable hints from emitting them

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.
This commit is contained in:
Ben Harris 2024-11-16 18:58:41 +00:00
parent 1459c8cf93
commit 30d226f30f

View 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;
}
}