#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)
{
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;
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);
}
if (key_arg(buf, "FONT_DESCENT", &arg)) {
- if (!mute && (flags & BDF_HEADER))
- printf("/* %s */\n", buf);
descent = strtoul(arg, &arg, 10);
}
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;
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);
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);
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;
}
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");
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++;