{{037,021,021,021,021,021,037,000,000}, -1, ".notdef" },
};
-static int const nglyphs = sizeof(glyphs) / sizeof(glyphs[0]);
+#define NGLYPHS (sizeof(glyphs) / sizeof(glyphs[0]))
+static int const nglyphs = NGLYPHS;
+
+static struct glyph const *glyphs_by_name[NGLYPHS];
static void dolookups(struct glyph const *);
return fontname;
}
+static int
+compare_glyphs_by_name(const void *va, const void *vb)
+{
+ struct glyph const * const *ap = va, * const *bp = vb;
+ struct glyph const *a = *ap, *b = *bp;
+ char a_buf[10], b_buf[10];
+ char const *an, *bn;
+
+ if (a->name) {
+ an = a->name;
+ } else {
+ sprintf(a_buf, "uni%04X.", a->unicode);
+ an = a_buf;
+ }
+ if (b->name) {
+ bn = b->name;
+ } else {
+ sprintf(b_buf, "uni%04X.", b->unicode);
+ bn = b_buf;
+ }
+ return strcmp(an, bn);
+}
+
int
main(int argc, char **argv)
{
"['c2sc' ('latn' <'dflt'>)]\n");
printf("BeginChars: %d %d\n", 0x110000 + extraglyphs, nglyphs);
extraglyphs = 0;
+ for (i = 0; i < nglyphs; i++)
+ glyphs_by_name[i] = glyphs + i;
+ qsort(glyphs_by_name, nglyphs, sizeof(glyphs_by_name[0]),
+ &compare_glyphs_by_name);
for (i = 0; i < nglyphs; i++) {
if (glyphs[i].name)
printf("\nStartChar: %s\n", glyphs[i].name);
dolookups(struct glyph const *g)
{
char prefix[32];
+ struct glyph const **found;
size_t plen;
int i;
assert(plen < 32);
/* Look for related glyphs */
- for (i = 0; i < nglyphs; i++) {
- if (glyphs[i].name &&
- strncmp(prefix, glyphs[i].name, plen) == 0) {
- if (strcmp(glyphs[i].name + plen, "saa5051") == 0)
+ found = bsearch(&g, glyphs_by_name, nglyphs, sizeof(glyphs_by_name[0]),
+ &compare_glyphs_by_name);
+ assert(found != NULL);
+ for (found++; found < glyphs_by_name + nglyphs; found++) {
+ if ((*found)->name &&
+ strncmp(prefix, (*found)->name, plen) == 0) {
+ if (strcmp((*found)->name + plen, "saa5051") == 0)
printf("Substitution2: \"ss01\" %s\n",
- glyphs[i].name);
- if (strcmp(glyphs[i].name + plen, "saa5052") == 0)
+ (*found)->name);
+ if (strcmp((*found)->name + plen, "saa5052") == 0)
printf("Substitution2: \"ss02\" %s\n",
- glyphs[i].name);
- if (strcmp(glyphs[i].name + plen, "saa5054") == 0)
+ (*found)->name);
+ if (strcmp((*found)->name + plen, "saa5054") == 0)
printf("Substitution2: \"ss04\" %s\n",
- glyphs[i].name);
- if (strcmp(glyphs[i].name + plen, "sc") == 0)
+ (*found)->name);
+ if (strcmp((*found)->name + plen, "sc") == 0)
printf("Substitution2: \"smcp\" %s\n",
- glyphs[i].name);
+ (*found)->name);
printf("AlternateSubs2: \"aalt\" %s\n",
- glyphs[i].name);
- }
+ (*found)->name);
+ } else break;
}
if ((g->flags & SC))
printf("Substitution2: \"%s\" %c%ssc\n", "c2sc",