|
st2205term/ax206term bug fix for version 0.11 and below July 02, 2012 08:34AM |
Registered: 1 year ago Posts: 61 |
static font_t *load_font(char *file,int num)
{
fprintf(stderr,"load_font(%s,%d) - loading font defintion\n",file,num);
FILE *fd=fopen(file,"r");
if (!fd) { perror("fopen"); fprintf(stderr,"ERROR: could not open file : %s\n",file); exit(1); }
int font_size[4][2];
if (fscanf(fd,"%d %d %d %d %d %d %d %d",
&font_size[0][0],&font_size[0][1],&font_size[1][0],&font_size[1][1],
&font_size[2][0],&font_size[2][1],&font_size[3][0],&font_size[3][1])!=8)
{ fprintf(stderr,"ERROR: could read font sizes from file : %s\n",file); exit(1); }
fseek(fd,1,SEEK_CUR);
int f,sz;
for (f=0;f<num;f++)
{
sz=95*(font_size[f][0]+1)*font_size[f][1];
if (fseek(fd,sz,SEEK_CUR)<0)
{ perror("fseek "); fprintf(stderr,"ERROR: could read font %d (sz=%d) from file : %s\n",f,sz,file); exit(1); }
}
sz=95*(font_size[f][0]+1)*font_size[f][1];
font_t *d=(font_t *)malloc(sizeof(font_t)+sz);
d->w=font_size[f][0];
d->h=font_size[f][1];
if (fread(d->data,1,sz,fd)!=sz)
{ fprintf(stderr,"ERROR: could read font %d (sz=%d) from file : %s\n",f,sz,file); exit(1); }
fclose(fd);
return d;
}