chiark / gitweb /
Generate ss0X substitutions less cleverly
authorBen Harris <bjh21@bjh21.me.uk>
Tue, 7 Jan 2025 22:37:19 +0000 (22:37 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Wed, 8 Jan 2025 01:52:55 +0000 (01:52 +0000)
These substitutions are not generated from the glyphs table, but are
specified statically.  Rather than taking a table and transforming it
into XML with C, we could just put the static XML in a string, which
is much simpler.  To avoid excessive simplicity, the string is
generated by a pile of preprocessor macros.

This causes no change to the output OTFs.

bedstead.c

index a3144f0bb0410cb0302113329b708972f3405c3c..8632cae0f0d187b2284de504ddbc54b1e4db48e8 100644 (file)
@@ -2723,7 +2723,6 @@ static struct alt_sub_override {
        { "ugrave", { "ugrave.roundjoined", "ugrave.sc" } },
 };
 
-#define MAXSUBS 10
 static struct gsub_feature {
        char const *tag;
 #define SCRIPT_DFLT 0x01
@@ -2731,7 +2730,7 @@ static struct gsub_feature {
 #define SCRIPT_ALL  0x03
        unsigned int scripts;
        char const *suffix; /* NULL for all alternative glyphs. */
-       char const *subs[MAXSUBS]; /* Individual character substitutions. */
+       char const *xml; /* Individual character substitutions. */
        char const *name;
        struct alt_sub_override const *overrides;
        int noverrides;
@@ -2741,19 +2740,26 @@ static struct gsub_feature {
        { "smcp", SCRIPT_LATN, .suffix = ".sc" },
        { "c2sc", SCRIPT_LATN, .suffix = ".c2sc" },
        { "rtlm", SCRIPT_ALL, .suffix = ".rtlm" },
+#define SINGLESUB(in, out) "<Substitution in='" in "' out='" out "'/>\n"
+#define SUFFIXSUB(base, suffix) SINGLESUB(base, base suffix)
        { "ss01", SCRIPT_ALL, .name = "SAA5051",
-         .subs = { "comma.left", "period.large", "colon.leftsmall",
-                   "semicolon.left", "question.open",
-                   "D.serif", "J.narrow", "L.narrow",
-                   "j.serif", "t.small" } },
+         .xml = "<SingleSubst>\n" SUFFIXSUB("comma", ".left")
+         SUFFIXSUB("period", ".large") SUFFIXSUB("colon", ".leftsmall")
+         SUFFIXSUB("semicolon", ".left") SUFFIXSUB("question", ".open")
+         SUFFIXSUB("D", ".serif") SUFFIXSUB("J", ".narrow")
+         SUFFIXSUB("L", ".narrow") SUFFIXSUB("j", ".serif")
+         SUFFIXSUB("t", ".small") "</SingleSubst>\n" },
        { "ss02", SCRIPT_ALL, .name = "SAA5052",
-         .subs = { "comma.left", "period.large", "colon.leftsmall",
-                   "semicolon.left", "question.open",
-                   "D.narrow", "J.narrow", "L.narrow",
-                   "j.serif", "t.small" } },
+         .xml = "<SingleSubst>\n" SUFFIXSUB("comma", ".left")
+         SUFFIXSUB("period", ".large") SUFFIXSUB("colon", ".leftsmall")
+         SUFFIXSUB("semicolon", ".left") SUFFIXSUB("question", ".open")
+         SUFFIXSUB("D", ".narrow") SUFFIXSUB("J", ".narrow")
+         SUFFIXSUB("L", ".narrow") SUFFIXSUB("j", ".serif")
+         SUFFIXSUB("t", ".small") "</SingleSubst>\n" },
        { "ss04", SCRIPT_ALL, .name = "SAA5054",
-         .subs = { "ugrave.roundjoined", "ocircumflex.large",
-                   "ccedilla.angular" } },
+         .xml = "<SingleSubst>\n" SUFFIXSUB("ugrave", ".roundjoined")
+         SUFFIXSUB("ocircumflex", ".large") SUFFIXSUB("ccedilla", ".angular")
+         "</SingleSubst>\n" },
        { "ss14", SCRIPT_ALL,  ".sep4", .name = "4-cell separated graphics" },
        { "ss16", SCRIPT_ALL,  ".sep6", .name = "6-cell separated graphics" },
 };
@@ -3634,21 +3640,11 @@ dogsub(void)
                        printf("     <SingleSubst>\n");
                        dosinglesubs(gsub_features[i].suffix);
                        printf("     </SingleSubst>\n");
-               } else if (gsub_features[i].subs[0] != NULL) {
-                       /* Stylistic set of pick and mix glyphs. */
+               } else if (gsub_features[i].xml != NULL) {
+                       /* Raw XML for a substitution. */
                        TTXI("LookupType", 1);
                        TTXI("LookupFlag", 0);
-                       printf("     <SingleSubst>\n");
-                       for (int j = 0; j < MAXSUBS; j++) {
-                               char const *sub = gsub_features[i].subs[j];
-                               if (sub == NULL) break;
-                               char *dot = strchr(sub, '.');
-                               assert(dot != NULL);
-                               printf("      "
-                                      "<Substitution in='%.*s' out='%s'/>\n",
-                                      (int)(dot - sub), sub, sub);
-                       }
-                       printf("     </SingleSubst>\n");
+                       printf("%s", gsub_features[i].xml);
                } else {
                        /* All possible alternative glyphs. */
                        TTXI("LookupType", 3);