From: Ben Harris Date: Tue, 25 Jul 2017 23:17:57 +0000 (+0100) Subject: Sort glyph complement by Unicode code point. X-Git-Tag: bedstead-002.000~120 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=a9221006c24332a7d3c4d618017c68b56114f09e;p=bedstead.git Sort glyph complement by Unicode code point. --- diff --git a/bedstead.c b/bedstead.c index 8ba649e..38fb219 100644 --- a/bedstead.c +++ b/bedstead.c @@ -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"); }