Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
/*
* bdf2txt.c -- convert BDF to TXT
*
* 0.0: Jan. 22, 2015
* 0.1: Jul. 7, 2025
*/
#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;
int lin;
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, "BBX") == 0) { /* BBXプロパティ */
if (sscanf(s, "BBX %d %d", &width, &height) < 2) {
fprintf(stderr, "can't get width and height from BBX\n");
exit(1);
}
lin = 0;
}
if (match(s, "BITMAP") == 0) {
fputs(s, stdout);
while (fgets(s, BUFSIZ, fp) != NULL) {
++lin;
if (match(s, "ENDCHAR") == 0) {
if ((lin - 1) != height) {
fprintf(stderr,
"unexpected ENDCHAR, lin = %d, height = %d\n",
lin, height);
exit(1);
}
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: */