]> Chaos Git - corbenik/bdfe.git/commitdiff
Output the font directly
authorchaoskagami <chaos.kagami@gmail.com>
Mon, 18 Jul 2016 01:06:07 +0000 (21:06 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Mon, 18 Jul 2016 01:06:07 +0000 (21:06 -0400)
bdf.c
main.c

diff --git a/bdf.c b/bdf.c
index d9d401fee0d3b3593ccee9822a832115ea38fa66..c726fceb049c071fb56f49211f0f144524ec85aa 100644 (file)
--- a/bdf.c
+++ b/bdf.c
 
 #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 c7ac1e95c48557bf61bbbc62d12c34c005093f8c..40065fcf8dbd89f36dd0bdcc388138b186ce0fcb 100644 (file)
--- 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++;