Skip to content

Instantly share code, notes, and snippets.

@deton
Last active August 29, 2015 14:25
Show Gist options
  • Save deton/f48b9eff706a10d7312c to your computer and use it in GitHub Desktop.
Save deton/f48b9eff706a10d7312c to your computer and use it in GitHub Desktop.
bdf2fontx.cでno ENDCHARになる問題の修正パッチ。BITMAP内の行数はBBX行のheightを使用
diff --git a/bdf2fontx.c b/bdf2fontx.c
index 816cfa6..b40a9a4 100644
--- a/bdf2fontx.c
+++ b/bdf2fontx.c
@@ -85,19 +85,20 @@ int match(char *s, char *t)
"FONT -%[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]--%d-%*d-%*d-%*d-%*[^-]-%d-%[^-]-%*s"
/* jis fixed medium r normal 14 130 75 75 C 70 jisx0201 */
-void bdfheader(char *name, int *width, int *height, int *type)
+void bdfheader(char *name, int *width, int *height, int *type, int *xoffset, int *yoffset)
{
char s[BUFSIZ];
char coding[BUFSIZ];
*type = -1;
*width = *height = -1;
+ *xoffset = *yoffset = 0;
strcpy(name, "unknown");
while (fgets(s, BUFSIZ, stdin) != NULL) {
if (match(s, "ENDPROPERTIES") == 0) {
break;
}
- if (match(s, "FONT") == 0) {
+ if (match(s, "FONT ") == 0) {
sscanf(s, XLFDCONV, name, height, width, coding);
*width /= 10;
if (match(coding, "jisx0201") == 0) {
@@ -109,7 +110,9 @@ void bdfheader(char *name, int *width, int *height, int *type)
else {
*type = 0;
}
- break;
+ }
+ else if (match(s, "FONTBOUNDINGBOX") == 0) {
+ sscanf(s, "FONTBOUNDINGBOX %*d %*d %d %d", xoffset, yoffset);
}
}
}
@@ -188,7 +191,7 @@ int jtos(unsigned short ch)
/* BDFファイルを読んで、中間ファイルに書く */
-int collect(FILE *co, FILE *gl, int width, int height, int type, int *ntab)
+int collect(FILE *co, FILE *gl, int width, int height, int type, int xoffset, int yoffset, int *ntab)
{
char s[BUFSIZ];
int n;
@@ -199,6 +202,9 @@ int collect(FILE *co, FILE *gl, int width, int height, int type, int *ntab)
int start, lastcode;
int code;
int convwidth;
+ int bbh = height;
+ int bbox = 0;
+ int bboy = 0;
*ntab = 0;
chars = 0;
@@ -230,17 +236,33 @@ int collect(FILE *co, FILE *gl, int width, int height, int type, int *ntab)
if (fgets(s, BUFSIZ, stdin) == NULL) {
break;
}
+ if (match(s, "BBX") == 0) {
+ sscanf(s, "BBX %*d %d %d %d", &bbh, &bbox, &bboy);
+ }
}
- for (y = 0; y < height; y++) {
+ int nbottom = bboy - yoffset; /* 下側に空けるライン数 */
+ int ntop = height - bbh - nbottom; /* 上側に空けるライン数 */
+ for (y = 0; y < ntop; y++) {
+ for (x = convwidth; x > 0; x -= 8) {
+ putc(0, gl);
+ }
+ }
+ for (y = 0; y < bbh; y++) {
if (fgets(s, BUFSIZ, stdin) == NULL) {
break;
}
sscanf(s, "%x", &p);
+ p >>= bbox - xoffset;
for (x = convwidth; x > 0; x -= 8) {
b = (p >> (x - 8)) & 0xff;
putc(b, gl);
}
}
+ for (y = 0; y < nbottom; y++) {
+ for (x = convwidth; x > 0; x -= 8) {
+ putc(0, gl);
+ }
+ }
fgets(s, BUFSIZ, stdin);
if (match(s, "ENDCHAR") != 0) {
fprintf(stderr, "no ENDCHAR at %d (0x%x)\n", n, n);
@@ -303,6 +325,7 @@ void codetable(FILE *co)
void main()
{
int width, height, type;
+ int xoffset, yoffset;
char name[BUFSIZ];
char fcodetab[BUFSIZ]; /* コード表中間ファイル */
char fglyph[BUFSIZ]; /* グリフ中間ファイル */
@@ -311,7 +334,7 @@ void main()
int ntab;
int ch;
- bdfheader(name, &width, &height, &type);
+ bdfheader(name, &width, &height, &type, &xoffset, &yoffset);
fprintf(stderr, "%s: %d x %d, type: %d\n", name, width, height, type);
strcpy(fcodetab, temp());
strcat(fcodetab, "/cXXXXXX.tbl");
@@ -325,7 +348,7 @@ void main()
fprintf(stderr, "can't open %s\n", fglyph);
exit(1);
}
- n = collect(co, gl, width, height, type, &ntab);
+ n = collect(co, gl, width, height, type, xoffset, yoffset, &ntab);
if (fclose(co) != 0) {
fprintf(stderr, "can't close %s\n", fcodetab);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment