/* */ #include #include #include #include #define ishexchar(ch) \ ((('0' <= (ch)) && ((ch) <= '9')) || \ (('A' <= (ch)) && ((ch) <= 'F')) || \ (('a' <= (ch)) && ((ch) <= 'f'))) #define NEWLINE '\n' #define EOS '\0' #define XLFDCONV \ "FONT -%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]--%d-%*d-%*d-%*d-%*[^-]-%d-%*[^-]-%*s" /* jis fixed medium r normal 14 130 75 75 C 70 jisx0201 */ /* 文字列が先頭一致するか */ int match(char *s, char *t) { return(strncasecmp(s, t, strlen(t))); } /* FONTプロパティから情報を得る */ void parsefont(char *s, int *width, int *height) { sscanf(s, XLFDCONV, height, width); *width /= 10; } int main(int argc, char *argv[]) { FILE *fp = stdin; char s[BUFSIZ]; unsigned int b, mask; int i; int width, height; width = -1; while (fgets(s, BUFSIZ, fp) != NULL) { if ((width < 0) && (match(s, "FONT") == 0)) { /* FONTプロパティ */ parsefont(s, &width, &height); width = 8 * ((width + 7) / 8); } if (match(s, "BITMAP") == 0) { fputs(s, stdout); while (fgets(s, BUFSIZ, fp) != NULL) { if (match(s, "ENDCHAR") == 0) { break; } if (ishexchar(s[0])) { /* HEX to TXT */ sscanf(s, "%x", &b); mask = 1 << (width - 1); for (i = 0; i < width; i++) { if (b & mask) { putc('#', stdout); } else { putc('-', stdout); } mask >>= 1; } } else { /* TXT to HEX */ i = 0; mask = 0x80; b = 0; while (s[i] != NEWLINE) { if ((s[i] != ' ') && (s[i] != '-') && (s[i] != '.')) { b |= mask; } ++i; mask >>= 1; if (mask == 0) { printf("%02x", b); mask = 0x80; b = 0; } } if (mask != 0x80) { printf("%02x", b); } } putc(NEWLINE, stdout); } } fputs(s, stdout); } exit(0); } /* Local Variables: */ /* compile-command:"cc -Wall -o bdf2txt bdf2txt.c" */ /* End: */