diff --git a/bedstead.c b/bedstead.c index 14b1deb..c32125d 100644 --- a/bedstead.c +++ b/bedstead.c @@ -3875,22 +3875,41 @@ docmap(int pid, int eid, int format) printf("\n", format); } +static int +compare_features_by_tag(const void *va, const void *vb) +{ + struct gsub_feature const * const *ap = va, * const *bp = vb; + + return namecmp((*ap)->tag, (*bp)->tag); +} + static void dogsub(void) { int i, j; + struct gsub_feature const *sorted[lenof(gsub_features)]; + for (i = 0; i < lenof(gsub_features); i++) + sorted[i] = &gsub_features[i]; + qsort(sorted, lenof(sorted), sizeof(sorted[0]), + &compare_features_by_tag); printf("\n"); TTXS("Version", "0x00010000"); printf("\n"); + /* + * The FeatureList should be sorted alphabetically by tag, but + * the LookupList has to be in the order in which the lookups + * should be applied. The FeatureIndices can be in any order + * we like. This requires some care with the indexing. + */ for (i = 0; i < lenof(gsub_scripts); i++) { printf("\n"); TTXS("ScriptTag", gsub_scripts[i].tag); printf("\n"); @@ -3898,34 +3917,37 @@ dogsub(void) } printf("\n"); printf("\n"); - for (i = 0; i < lenof(gsub_features); i++) { + for (i = 0; i < lenof(sorted); i++) { + struct gsub_feature const *feat = sorted[i]; + int featidx = (feat - gsub_features); printf("\n"); - TTXS("FeatureTag", gsub_features[i].tag); + TTXS("FeatureTag", feat->tag); printf("\n"); - if (gsub_features[i].name != NULL) { - if (gsub_features[i].tag[0] == 's') { + if (feat->name != NULL) { + if (feat->tag[0] == 's') { printf("\n"); TTXI("Version", 0); - TTXI("UINameID", NAMEBASE_GSUB + i); + TTXI("UINameID", NAMEBASE_GSUB + featidx); printf("\n"); } else { int nparam = 0; while (nparam < MAXSUBNAME && - gsub_features[i].subnames[nparam]) + feat->subnames[nparam]) nparam++; printf("\n"); TTXI("Format", 0); - TTXI("FeatUILabelNameID", NAMEBASE_GSUB + i); + TTXI("FeatUILabelNameID", + NAMEBASE_GSUB + featidx); TTXI("FeatUITooltipTextNameID", 0); TTXI("SampleTextNameID", 0); TTXI("NumNamedParameters", nparam); TTXI("FirstParamUILabelNameID", - NAMEBASE_GSUB_SUB + MAXSUBNAME * i); + NAMEBASE_GSUB_SUB + MAXSUBNAME * featidx); printf("\n"); } } /* We only have one GSUB lookup per feature, thankfully. */ - TTXI("LookupListIndex", i); + TTXI("LookupListIndex", featidx); printf("\n"); printf("\n"); }