From 46a5c058853b8cd6c964c5d21ee88424e8e3bc4f Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Thu, 31 Oct 2024 23:34:18 +0000 Subject: [PATCH] Add rough support for generating BDF without FontForge This is extremely silly, but it's actually quite functional and surprisingly compact. bedstead.c gains the ability to generate a PostScript file that emits a BDF file rendering each glyph into an image and then dumping the image in hex. I still need to get the font metadata right, which is my main reason for wanting to get away from FontForge, but that shouldn't be difficult. And the Makefile needs to be updated to make this work properly. But the bitmaps are coming out correctly. --- bedstead.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/bedstead.c b/bedstead.c index f30bac9..8c239db 100644 --- a/bedstead.c +++ b/bedstead.c @@ -191,6 +191,7 @@ static void domosaic4(unsigned code, bool sep); static void doalias(char const *alias_of); static void dopanose(void); static void glyph_complement(void); +static void bdf_gen(int size); /* U(N) sets the code point and name of a glyph not in AGLFN */ #define U(N) 0x ## N, 0x ## N >= 0x10000 ? "u" #N : "uni" #N @@ -2727,6 +2728,7 @@ compare_glyphs_by_ffid(const void *va, const void *vb) int main(int argc, char **argv) { + bool gen_bdf = false; int i; int extraglyphs = 0; char *endptr; @@ -2752,6 +2754,8 @@ main(int argc, char **argv) if (strcmp(argv[1], "--plotter") == 0) { plottermode = true; argv++; argc--; + } else if (strcmp(argv[1], "--bdfgen") == 0) { + gen_bdf = true; } else if (strcmp(argv[1], "--") == 0) { argv++; argc--; break; @@ -2763,6 +2767,11 @@ main(int argc, char **argv) next:; } + if (gen_bdf) { + bdf_gen(10); + return EXIT_SUCCESS; + } + if (argc > 1) { char data[YSIZE]; int i, y; @@ -3825,3 +3834,46 @@ glyph_complement() printf("showpage\n"); printf("%%%%EOF\n"); } + +static void +bdf_gen(int px_height) +{ + int px_width = (px_height * XPIX * XSIZE) / (YPIX * YSIZE); + int base = (px_height * 200) / (YPIX * YSIZE); + int i; + + printf("%%!\n"); + printf("/d [1 0 0 1 0 0] %d %d makeimagedevice def\n", + (px_width + 7) / 8 * 8, px_height); + printf("d setdevice\n"); + printf("/Bedstead findfont %d scalefont setfont\n", px_height); + printf("/f (%%stdout) (w) file def\n"); + printf("/buf %d string def\n", (px_width + 7) / 8); + printf("(\\\n"); + printf("STARTFONT 2.1\n"); + printf("FONT bedstead-%d\n", px_height); + printf("SIZE %d 75 75\n", px_height); + printf("FONTBOUNDINGBOX %d %d 0 %d\n", px_width, px_height, -base); + printf("CHARS %d\n", nglyphs); + for (i = 0; i < nglyphs; i++) { + struct glyph *g = &glyphs[i]; + printf("STARTCHAR %s\n", g->name); + printf("ENCODING %d\n", g->unicode); + printf("SWIDTH %d 0\n", (int)(XPIX * XSIZE)); + printf("DWIDTH %d 0\n", px_width); + printf("BBX %d %d 0 %d\n", px_width, px_height, -base); + printf("BITMAP\n"); + printf(") print\n"); + printf("erasepage\n"); + printf("0 %d moveto\n", base); + printf("/%s glyphshow\n", g->name); + printf("%d -1 0 {\n", px_height - 1); + printf(" d exch buf copyscanlines\n"); + printf(" f exch writehexstring (\n) print\n"); + printf("} for\n"); + printf("(\\\n"); + printf("ENDCHAR\n"); + } + printf("ENDFONT\n"); + printf(") print\n"); +} -- 2.30.2