chiark / gitweb /
Emit a format-14 'cmap' subtable for variation sequences
authorBen Harris <bjh21@bjh21.me.uk>
Thu, 20 Nov 2025 21:51:28 +0000 (21:51 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Tue, 13 Jan 2026 21:55:10 +0000 (21:55 +0000)
Now I can put <U+0030, U+FE00> in an HTML file and Firefox will pick the
correct glyphs.

bedstead.c

index 32623ca209d7a6df078127d53daf236e37dc3447..f6e134efa9e6081584728ceca142d62cd99f1534 100644 (file)
@@ -231,9 +231,9 @@ static struct glyph {
 #define U_HASVS  0x00200000 /* Is there a variation selector? */
 #define U_VSMASK 0x0F000000 /* Bottom 4 bits of VS code point. */
 #define U_VSSHIFT 24
-#define VS(uvs) ((((long)uvs << U_VSSHIFT) & U_VSMASK) | U_HASVS)
+#define VS(uvs) ((((unsigned long)uvs << U_VSSHIFT) & U_VSMASK) | U_HASVS)
 #define GET_UV(u) (u & U_UVMASK)
-#define GET_UVS(u) ((u & U_VSMASK) >> U_VSSHIFT)
+#define GET_UVS(u) ((u & U_VSMASK) >> U_VSSHIFT | 0xfe00)
 #define NU 0xFFFFFFFF /* No Unicode code point. Must be > all valid values. */
        char const *name;
        uint_least16_t flags;
@@ -3845,6 +3845,15 @@ main(int argc, char **argv)
        docmap(0, 4, 12);  /* Unicode 2.0+, full repertoire */
        docmap(3, 1, 4);   /* Windows Unicode, BMP only */
        docmap(3, 10, 12); /* Windows Unicode, full repertoire */
+       /* Variation sequences. */
+       printf("<cmap_format_14 platformID='0' platEncID='5'>\n");
+       for (i = 0; i < lenof(glyphs); i++) {
+               unsigned long u = glyphs[i].unicode;
+               if (u != NU && (u & U_HASVS))
+                       printf("<map uv='0x%lx' uvs='0x%lx' name='%s'/>\n",
+                              GET_UV(u), GET_UVS(u), glyphs[i].name);
+       }
+       printf("</cmap_format_14>\n");
        printf("</cmap>\n");
 
        dogpos(); /* Must be before 'CFF ' because it uses glyph bitmaps. */