* Font translation to vfonts (RST format) from character format.
* Use: ch2vft [ -i -s ] charfile > vfontfile
* Takes input from charfile (which must be in the format written
* by xxx2ch), converts to rst format and writes to stdout. If charfile
* is missing, stdin is read. The -i flag tells ch2rst to ignore the
* character codes at the start of each glyph definition, and pack the
* glyphs in consecutive code positions starting with 0. The -s flag
* forces ch2vft to include the whole bit-map that defines the glyph.
* Normally, it is trimmed of white space. This is usefull for making
* stipple patterns of fixed size.
#define RES 200 /* for vfont, resolution is 200 */
#define GLYPHSPACE (MAXLINE * MAXLINE)
#define DIRSIZ 256 /* vfonts MUST have 256 entries */
struct dispatch g
[DIRSIZ
]; /* directory of glyph definitions */
struct header head
; /* font file header */
int width
, length
, maxv
, minv
, maxh
, minh
, refv
, refh
;
char charbits
[GLYPHSPACE
]; /* place to store bits for a glyph */
head
.maxx
= head
.maxy
= head
.xtend
= 0;
while (argc
> 1 && argv
[1][0] == '-') {
error("%s, unknown option flag", argv
[1]);
if ((filep
= fopen (argv
[1], "r")) == NULL
)
error("can't open file \"%s\"", argv
[1]);
for (i
= 0; i
< DIRSIZ
; glyphs
[i
++] = (char *) 0);
fgets(ibuff
, MAXLINE
, filep
);
if (strcmp(ibuff
, "fontheader\n"))
error("not a character font file");
while (fgets(ibuff
, MAXLINE
, filep
) != NULL
) {
if (index(ibuff
, '\n') == 0)
error("input line too long");
sscanf (ibuff
, "%s %f", ebuff
, &par
);
if (strcmp(ebuff
, "size") == 0);
else if (strcmp(ebuff
, "version") == 0) {
error("wrong version (%d) for Font file.", (int)(par
+0.5));
} else if (strcmp(ebuff
, "mag") == 0);
else if (strcmp(ebuff
, "desiz") == 0); /*des_size = par/FIX + 0.5*/
else if (strcmp(ebuff
, "linesp") == 0);
else if (strcmp(ebuff
, "wordsp") == 0);
else if (strcmp(ebuff
, "rot") == 0);
else if (strcmp(ebuff
, "cadv") == 0);
else if (strcmp(ebuff
, "ladv") == 0);
else if (strcmp(ebuff
, "id") == 0);
else if (strcmp(ebuff
, "res") == 0) {
if (((int) (par
+ 0.5)) != RES
)
fprintf(stderr
, "ch2vft warning: wrong resolution (%d).\n",
error("unknown input descriptor, \"%s\"", ebuff
);
if (sscanf (ibuff
, ":%d, width = %f", &code
, &par
) != 2)
error("bad glyph header, %s", ibuff
);
if (ignorecode
) i
= codeindex
++; else i
= code
;
if (i
< 0 || i
>= DIRSIZ
) error("code (%d) out of range", i
);
if (fgets(chp
, MAXLINE
, filep
) == NULL
)
error("unexpected end of input");
for (length
= 0; *chp
!= '\n'; length
++) {
if ((length
+ 1) * width
> GLYPHSPACE
)
error ("out of glyph space");
for (j
= 0; j
< width
; j
++, chp
++) {
if (minv
< 0) minv
= length
;
error("illegal character '%c' in map.", *chp
);
if (fgets(chp
, MAXLINE
, filep
) == NULL
)
error("unexpected end of input");
if (stipple
) { /* force whole box if making stipples */
if (refv
< 0) error("no reference point in glyph %d.", code
);
g
[i
].up
= bound(refv
- minv
);
g
[i
].down
= bound(maxv
+ 1 - refv
);
g
[i
].right
= bound(maxh
+ 1 - refh
);
g
[i
].left
= bound(refh
- minh
);
g
[i
].nbytes
= (maxv
+ 1 - minv
) * ((maxh
+ 8 - minh
) >> 3);
/* convert from characters to bits */
bitp
= (glyphs
[i
] = malloc(g
[i
].nbytes
)) - 1;
for (k
= minv
; k
<= maxv
; k
++) {
chp
= &charbits
[0] + width
* k
+ minh
;
for (j
= minh
; j
<= maxh
; j
++, chp
++) {
if (*chp
!= '.') *bitp
|= 1 << bitwidth
;
for (i
= 0; i
< DIRSIZ
; i
++) {
if (glyphs
[i
] == (char *) 0) {
if (g
[i
].up
> head
.maxy
) head
.maxy
= g
[i
].up
;
if (g
[i
].down
> head
.xtend
) head
.xtend
= g
[i
].down
;
if (((int) g
[i
].left
+ g
[i
].right
) > head
.maxx
)
head
.maxx
= g
[i
].left
+ (int) g
[i
].right
;
vwrite((char *) &head
, sizeof(head
));
vwrite((char *) &(g
[0]), sizeof(g
));
for (i
= 0; i
< DIRSIZ
; i
++)
if (glyphs
[i
] != (char *) 0)
vwrite(glyphs
[i
], g
[i
].nbytes
);
tsize
= usize
> BUFSIZ
? BUFSIZ
: usize
;
if ((tsize
= write(1, buf
, tsize
)) < 0) {
perror("ch2vft: write failed");
error(string
, a1
, a2
, a3
, a4
)
fprintf(stderr
, "ch2vft: ");
fprintf(stderr
, string
, a1
, a2
, a3
, a4
);
if(i
< DIMLIMIT
&& i
>= -DIMLIMIT
) return i
;
error ("dimension out of range");