From fd72cb33447e5529ed73628caf8fb20d0bad0d9a Mon Sep 17 00:00:00 2001 From: chaoskagami Date: Sun, 17 Jul 2016 21:06:07 -0400 Subject: [PATCH] Output the font directly --- bdf.c | 82 +++++----------------------------------------------------- main.c | 14 +--------- 2 files changed, 8 insertions(+), 88 deletions(-) diff --git a/bdf.c b/bdf.c index d9d401f..c726fce 100644 --- a/bdf.c +++ b/bdf.c @@ -36,15 +36,6 @@ #include "bdf.h" -static int printable(unsigned character) { - // This is a workaround for older glibc - isprint doesn't - // return the needed results (and it's only standard behavior for 0-255 anyways) - - if (character < 0x20 || character == 0x7f || character > 0xff) - return 0; - return 1; -} - // check if 'buf' starts with 'key' and store pointer to the argument static char *key_arg(char *buf, const char *key, char **arg) { @@ -98,18 +89,6 @@ bdfe_t *bdf_convert(const char *name, unsigned gmin, unsigned gmax, unsigned asc return NULL; memset(buf, 0, sizeof(buf)); - int mute = flags & BDF_MUTE; - - if (!mute && (flags & BDF_HEADER)) { - printf("/* File generated by 'bdfe"); - if (flags & BDF_NATIVE) - printf(" -n"); - if (flags & BDF_ROTATE) - printf(" -r"); - if (ascender) - printf(" -a %d", ascender); - printf(" -s %d-%d %s' */\n", gmin, gmax, name); - } // parse file header up to 'CHARS' keyword unsigned nchars = 0, dx = 0, dy = 0, descent = 0; @@ -117,20 +96,7 @@ bdfe_t *bdf_convert(const char *name, unsigned gmin, unsigned gmax, unsigned asc arg = strchr(buf, '\0'); while(*arg < ' ' && arg != buf) *arg-- = '\0'; - if (!mute && (flags & BDF_HEADER)) { - if (key_arg(buf, "FONT", &arg)) - printf("/* %s */\n", buf); - if (key_arg(buf, "COMMENT", &arg)) - printf("/* %s */\n", buf); - if (key_arg(buf, "COPYRIGHT", &arg)) - printf("/* %s */\n", buf); - if (key_arg(buf, "FONT_ASCENT", &arg)) - printf("/* %s */\n", buf); - } - if (key_arg(buf, "FONTBOUNDINGBOX", &arg)) { - if (!mute && (flags & BDF_HEADER)) - printf("/* %s */\n", buf); dx = strtoul(arg, &arg, 10); dy = strtoul(arg, &arg, 10); strtoul(arg, &arg, 10); @@ -138,8 +104,6 @@ bdfe_t *bdf_convert(const char *name, unsigned gmin, unsigned gmax, unsigned asc } if (key_arg(buf, "FONT_DESCENT", &arg)) { - if (!mute && (flags & BDF_HEADER)) - printf("/* %s */\n", buf); descent = strtoul(arg, &arg, 10); } @@ -189,13 +153,15 @@ bdfe_t *bdf_convert(const char *name, unsigned gmin, unsigned gmax, unsigned asc gh = dy; } - if (!mute && (flags & BDF_HEADER)) - printf("// Converted Font Size %dx%d\n\n", dx, dy); if (ascender > dy/2) ascender = dy/2; + // rewind the file pointer ans start parsing glyphs fseek(fp, 0, SEEK_SET); + fwrite(&dx, 1, 4, stdout); + fwrite(&dy, 1, 4, stdout); + unsigned gsize = dy * ((dx + 7) / 8); font = (bdfe_t *)malloc(sizeof(bdfe_t) + gsize*nchars); font->chars = 0; @@ -227,10 +193,6 @@ bdfe_t *bdf_convert(const char *name, unsigned gmin, unsigned gmax, unsigned asc idx = atoi(arg); if (idx < gmin || idx > gmax) break; - if (!mute && !(flags & BDF_GPL) && (flags & BDF_VERBOSE)) { - printf("/* %s */\n", startchar); - printf("/* %s */\n", buf); - } } if (key_arg(buf, "DWIDTH", &arg)) { gw = atoi(arg); @@ -238,8 +200,6 @@ bdfe_t *bdf_convert(const char *name, unsigned gmin, unsigned gmax, unsigned asc break; } if (key_arg(buf, "BBX", &arg)) { - if (!mute && !(flags & BDF_GPL) && (flags & BDF_VERBOSE)) - printf("/* %s */\n", buf); bbw = strtol(arg, &arg, 10); strtol(arg, &arg, 10); // skip bbh, we'll calculate it (i) bbox = strtol(arg, &arg, 10); @@ -265,38 +225,10 @@ bdfe_t *bdf_convert(const char *name, unsigned gmin, unsigned gmax, unsigned asc else memcpy(gout, gin, dy); - if (!mute) { - // glyph per line - if (flags & BDF_GPL) { - printf("\t"); - for(i = 0; i < gh; i++) { - if ((i == gh/2) && (flags & BDF_ROTATE)) - printf("\n\t"); - printf("0x%02X,", gout[i]); - } - printf(" /* %5d", idx); - if (printable(idx)) - printf(" '%c'", idx); - printf(" */\n"); - } - else { - printf("/* %5d '%c' |", idx, printable(idx) ? idx : ' '); - for(i = 0; i < gw; i++) - printf("%d", i); - printf("| */\n"); - for(i = 0; i < gh; i++) { - printf(" 0x%02X, /* %2d|", gout[i], i); - for(unsigned bit = 0; bit < gw; bit++) { - if (gout[i] & (0x80 >> bit)) - printf("#"); - else - printf(" "); - } - printf("| */\n"); - } - printf("\n"); - } + for(i = 0; i < gh; i++) { + fwrite(&gout[i], 1, 1, stdout); } + gout += gh; break; } diff --git a/main.c b/main.c index c7ac1e9..40065fc 100644 --- a/main.c +++ b/main.c @@ -53,12 +53,9 @@ static int arg_is(const char *arg, const char *sarg, const char *larg) static void usage(const char *name) { - printf("%s [options] bdf [> output]\n", name); + printf("%s [options] bdf [> output.bin]\n", name); printf(" -h (--help) display this help text\n"); - printf(" -L (--header) print file header\n"); - printf(" -v (--verbose) add more info to the header\n"); printf(" -a h (--ascend h) add ascend gap of H pixels per glyph\n"); - printf(" -l (--line) output should be one line per glyph\n"); printf(" -S a-b (--subset a-b) subset of glyphs to convert a to b, default 32-126\n"); printf(" -A (--all-glyphs) convert all glyphs, not just 32-126\n"); printf(" -n (--native) do not adjust font height 8 pixels\n"); @@ -84,20 +81,11 @@ int main(int argc, char **argv) return 0; } - if (arg_is(argv[i], "-L", "--header")) - flags |= BDF_HEADER; - - if (arg_is(argv[i], "-v", "--verbose")) - flags |= BDF_VERBOSE; - if (arg_is(argv[i], "-a", "--ascend")) { if (i < argc && isdigit(*argv[i+1])) ascender = atoi(argv[++i]); } - if (arg_is(argv[i], "-l", "--line")) - flags |= BDF_GPL; - if (arg_is(argv[i], "-S", "--subset")) { if (i < argc && isdigit(*argv[i+1])) { i++; -- 2.39.5