chiark / gitweb /
Sort glyph complement by Unicode code point.
authorBen Harris <bjh21@bjh21.me.uk>
Tue, 25 Jul 2017 23:17:57 +0000 (00:17 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Tue, 25 Jul 2017 23:17:57 +0000 (00:17 +0100)
bedstead.c

index 8ba649eea8013b25317d455715113c4e1cfbc30e..38fb2192f97ec5a595f0d6b30c8667103604eefb 100644 (file)
@@ -2096,12 +2096,29 @@ domosaic(unsigned code, bool sep)
        emit_path();
 }
 
+static int
+byunicode(const void *va, const void *vb)
+{
+       struct glyph const *a = *(struct glyph const **)va,
+               *b = *(struct glyph const **)vb;
+
+       /* Cast to unsigned so -1 sorts last. */
+       if ((unsigned)a->unicode < (unsigned)b->unicode) return -1;
+       if ((unsigned)a->unicode > (unsigned)b->unicode) return +1;
+       return strcmp(a->name, b->name);
+}
+       
 static void
 glyph_complement()
 {
        int i;
+       int const nrow = 20, ncol=12;
        int const nglyphs = sizeof(glyphs) / sizeof(glyphs[0]);
-       
+       struct glyph const *sorted[nglyphs], *g;
+
+       for (i = 0; i < nglyphs; i++)
+               sorted[i] = &glyphs[i];
+       qsort(sorted, nglyphs, sizeof(sorted[0]), &byunicode);
        printf("%%!\n");
        printf("/xfont /Bedstead findfont 20 scalefont def\n");
        printf("/lfont /Bedstead findfont 4 scalefont def\n");
@@ -2122,18 +2139,21 @@ glyph_complement()
        printf("  1 setlinewidth stroke\n");
        printf("} def\n");
        for (i = 0; i < nglyphs; i++) {
+               g = sorted[i];
                printf("gsave %d %d translate 0 0 moveto ",
-                      20 + (((i%240)/20) * 40), 800 - ((i%20) * 40));
-               if (glyphs[i].unicode != -1)
-                       printf("(U+%04X)", glyphs[i].unicode);
+                      20 + (((i%(nrow*ncol)/nrow) * 40)),
+                      800 - ((i%nrow) * 40));
+               if (g->unicode != -1)
+                       printf("(U+%04X)", g->unicode);
                else
                        printf("()");
-               if (glyphs[i].name != NULL)
-                       printf("/%s ", glyphs[i].name);
+               if (g->name != NULL)
+                       printf("/%s ", g->name);
                else
-                       printf("/uni%04X ", glyphs[i].unicode);
+                       printf("/uni%04X ", g->unicode);
                printf("exemplify grestore\n");
-               if (i % 240 == 239) printf("showpage\n");
+                     if (i % (nrow*ncol) == (nrow*ncol)-1)
+                              printf("showpage\n");
        }
        printf("showpage\n");
 }