chiark / gitweb /
Create a subroutine for each aliased glyph
authorBen Harris <bjh21@bjh21.me.uk>
Sat, 2 Nov 2024 22:31:01 +0000 (22:31 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Thu, 14 Nov 2024 22:27:18 +0000 (22:27 +0000)
So both the original name and any aliases can then call the subroutine
instead.

bedstead.c

index afdc75f7afc7cf87f1a3b7a6d704986def2a4409..c045cea241097f790319f8cfb136bc7c5a8e65b6 100644 (file)
@@ -210,6 +210,7 @@ static struct glyph {
                /* Top row (and left column) don't appear in ROM. */
                char data[YSIZE - 1];
                char const *alias_of;
+               int subr_idx;
        };
        int_least32_t unicode;
        char const *name;
@@ -220,6 +221,7 @@ static struct glyph {
 #define SEP6 (SEP | MOS6)
 #define SEP4 (SEP | MOS4)
 #define IS_ALIAS 0x08
+#define IS_SUBR  0x10
 } glyphs[] = {
  /*
   * The first batch of glyphs comes from the code tables at the end of
@@ -2727,10 +2729,10 @@ compare_glyph_to_name(const void *vn, const void *vg)
        return strcmp(name, g->name);
 }
 
-static struct glyph const *
+static struct glyph *
 get_glyph_by_name(char const *name)
 {
-       struct glyph const * const *gp;
+       struct glyph * const *gp;
 
        gp = bsearch(name, glyphs_by_name, nglyphs,
                     sizeof(glyphs_by_name[0]), &compare_glyph_to_name);
@@ -2759,6 +2761,8 @@ compare_glyphs_by_ffid(const void *va, const void *vb)
        return strcmp(a->name, b->name);
 }
 
+static int nsubrs;
+
 int
 main(int argc, char **argv)
 {
@@ -3084,6 +3088,23 @@ main(int argc, char **argv)
                glyphs_by_name[i] = glyphs + i;
        qsort(glyphs_by_name, nglyphs, sizeof(glyphs_by_name[0]),
              &compare_glyphs_by_name);
+       /* Scan for aliased glyphs to turn into subroutines. */
+       printf("  <Subrs>\n");
+       nsubrs = 0;
+       for (i = 0; i < nglyphs; i++) {
+               struct glyph *g = &glyphs[i];
+               if (g->flags & IS_ALIAS) {
+                       while (g->flags & IS_ALIAS)
+                               g = get_glyph_by_name(g->alias_of);
+                       if (g->flags & IS_SUBR) continue;
+                       printf("  <CharString> <!-- %s -->\n", g->name);
+                       doglyph(g);
+                       g->flags = IS_SUBR;
+                       g->subr_idx = nsubrs++;
+                       printf("  </CharString>\n");
+               }
+       }
+       printf("  </Subrs>\n");
        printf("  </Private>\n");
        printf("  <CharStrings>\n");
        for (i = 0; i < nglyphs; i++) {
@@ -3286,7 +3307,10 @@ doglyph(struct glyph const *g)
 
        while (g->flags & IS_ALIAS)
                g = get_glyph_by_name(g->alias_of);
-       if (g->flags & MOS6)
+       if (g->flags & IS_SUBR)
+               printf("  %d callsubr\n", g->subr_idx -
+                      (nsubrs < 1240 ? 107 : 1131));
+       else if (g->flags & MOS6)
                domosaic(g->data[0], (g->flags & SEP) != 0);
        else if (g->flags & MOS4)
                domosaic4(g->data[0], (g->flags & SEP) != 0);