vx32

Local 9vx git repository for patches.
git clone git://r-36.net/vx32
Log | Files | Refs

openmemsubfont.c (899B)


      1 #include "u.h"
      2 #include "lib.h"
      3 #include "draw.h"
      4 #include "memdraw.h"
      5 
      6 Memsubfont*
      7 openmemsubfont(char *name)
      8 {
      9 	Memsubfont *sf;
     10 	Memimage *i;
     11 	Fontchar *fc;
     12 	int fd, n;
     13 	char hdr[3*12+4+1];
     14 	uchar *p;
     15 
     16 	fd = open(name, OREAD);
     17 	if(fd < 0)
     18 		return nil;
     19 	p = nil;
     20 	i = readmemimage(fd);
     21 	if(i == nil)
     22 		goto Err;
     23 	if(read(fd, hdr, 3*12) != 3*12){
     24 		werrstr("openmemsubfont: header read error: %r");
     25 		goto Err;
     26 	}
     27 	n = atoi(hdr);
     28 	p = malloc(6*(n+1));
     29 	if(p == nil)
     30 		goto Err;
     31 	if(read(fd, p, 6*(n+1)) != 6*(n+1)){
     32 		werrstr("openmemsubfont: fontchar read error: %r");
     33 		goto Err;
     34 	}
     35 	fc = malloc(sizeof(Fontchar)*(n+1));
     36 	if(fc == nil)
     37 		goto Err;
     38 	_unpackinfo(fc, p, n);
     39 	sf = allocmemsubfont(name, n, atoi(hdr+12), atoi(hdr+24), fc, i);
     40 	if(sf == nil){
     41 		free(fc);
     42 		goto Err;
     43 	}
     44 	free(p);
     45 	return sf;
     46 Err:
     47 	close(fd);
     48 	if (i != nil)
     49 		freememimage(i);
     50 	if (p != nil)
     51 		free(p);
     52 	return nil;
     53 }