Convert BDF bitmap fonts to flf fonts for figlet
git clone https://github.com/m-col/bdf2flf
Files | Refs | Readme

Commit 0a8ce63b2db70c55d566d753fc3cb26fab7e5c95
Parent: b962685c57d00c70fdb4b02bc914868c69fb0cbe
Author: mcol <mcol@posteo.net>
Date: 2020-10-25 20:06:09 +0000
Committer: mcol <mcol@posteo.net>
Committed: 2020-10-25 20:06:09 +0000

read and output metadata

bdf2flf.c Modified

@@ -1,21 +1,67 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+
+
+#include <unistd.h> // ?
+#include <limits.h> // ?
+#include <errno.h> // ?
 
 #define PROGNAME "bdf2flf"
 
 
 void bdf2flf(FILE * in, FILE * out)
 {
+    char linebuf[1024];
+    char *s;
+    int widest = 0;
+    int comments = 2;
+    int chars, height, baseline, old_layout, direction, full_layout, codetags,
+	fbb_width, fbb_height, fbb_yoffset;
+    char font[1024];
+    char copyright[1024];
+
+    for (;;) {
+	if (!fgets(linebuf, sizeof(linebuf), in)) {	// EOF
+	    break;
+	}
+	if (!(s = strtok(linebuf, " \t\n\r"))) {	// empty line
+	    break;
+	}
+	if (!strcasecmp(s, "FONTBOUNDINGBOX")) {
+	    fbb_width = atoi(strtok(NULL, " \t\n\r"));
+	    fbb_height = atoi(strtok(NULL, " \t\n\r"));
+	    strtok(NULL, " \t\n\r");
+	    fbb_yoffset = atoi(strtok(NULL, " \t\n\r"));
+
+	} else if (!strcasecmp(s, "FONT")) {
+	    strcpy(font, strtok(NULL, "\n"));
+
+	} else if (!strcasecmp(s, "COPYRIGHT")) {
+	    strcpy(copyright, strtok(NULL, "\n"));
+	    comments = 3;
+
+	} else if (!strcasecmp(s, "CHARS")) {
+	    chars = atoi(strtok(NULL, " \t\n\r"));
+	    break;
+	}
+    }
+
+    // output header
+    fprintf(out, "flf2a$ %i %i %i %i %i %i %i %i\n", height, baseline, widest+2,
+	    old_layout, comments, direction, full_layout, codetags);
+    fprintf(out, "FIGlet font derived from %s\n", font);
+    if (comments > 2)
+	fprintf(out, "which has copyright: %s\n", copyright);
+    fprintf(out, "Converted to flf with bdf2flf (c) Matt Colligan.\n");
 }
 
 
 int main(int argc, char *argv[])
 {
     if (argc > 1) {
-	printf(
-	    PROGNAME "< font.bdf > font.flf\n"
-	    "bdf data is read from stdin and figlet font data is output to stdout.\n"
-	);
+	printf(PROGNAME "< input.bdf > output.flf\nbdf data is read from stdin"
+		"and figlet font data is output to stdout.\n");
 	exit(EXIT_SUCCESS);
     }