chiark / gitweb /
Try to generate more-symmetric stem hints
authorBen Harris <bjh21@bjh21.me.uk>
Sat, 30 Aug 2025 13:01:56 +0000 (14:01 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Sat, 30 Aug 2025 13:01:56 +0000 (14:01 +0100)
When generating hints for a symmetric glyph like 'v', it's helpful if
the hits are symmetric because that means that the hinted bitmap is
also likely to be symmetric.  This is particularly visible on
Microsoft Windows where the version of 'v' before this patch ended up
horribly distorted when rendered at 20 ppem in Bedstead Condensed.  To
try to avoid such horrors, we now select hints starting at the outside
edges of the character and working inwards, instead of going from left
to right or top to bottom.  This means that where hints conflict,
we'll tend to choose the ones towards the outside edge of the
character, rather than towards the top or left.

This changes the hinting for 50 glyphs, but all in ways that look
superficially reasonable.

For more complicated characters we probably still want to think about
hint substitution, but that still scares me.

bedstead.c

index 35e3b40f360c209ff2a4c7fdd0b7a01e4fafdb96..952825ecff1c9f2226d09e876566caca75da63b2 100644 (file)
@@ -4389,12 +4389,14 @@ select_hints(int nstems, int stems[nstems],
        for (;most > 0; most--) {
                /* Prefer long stems. */
                for (int i = 0; i < nstems; i++) {
-                       if (stems[i] == most) {
-                               hints[i] = hint_stem;
-                               stems[i] = 0;
+                       /* Prefer outer stems. */
+                       int ii = i % 2 ? nstems - 1 - i / 2 : i / 2;
+                       if (stems[ii] == most) {
+                               hints[ii] = hint_stem;
+                               stems[ii] = 0;
                                /* Disallow overlapping stems. */
-                               if (i >= 1) stems[i-1] = 0;
-                               if (i < nstems - 1) stems [i+1] = 0;
+                               if (ii >= 1) stems[ii-1] = 0;
+                               if (ii < nstems - 1) stems [ii+1] = 0;
                        }
                }
        }