void cursorswitch(Cursor *c) { if(c == 0) c = &arrow; if(c->id == 0){ if(bsrc == 0){ bsrc = balloc(crect, 0); bmask = balloc(crect, 0); } /* * Cursor should have fg where "set" is 1, * and bg where "clr" is 1 and "set" is 0, * and should leave places alone where "set" and "clr" are both 0 */ wrbitmap(bsrc, 0, 16, c->set); #ifdef CURSORBUG /* * Some X servers (e.g., Sun X-on-news for some color * monitors) don't do XCreatePixmapCursor properly: * only the mask gets displayed, all black */ wrbitmap(bmask, 0, 16, c->set); #else wrbitmap(bmask, 0, 16, c->clr); bitblt(bmask, Pt(0,0), bsrc, crect, S|D); #endif c->id = (int) XCreatePixmapCursor(_dpy, (Pixmap)bsrc->id, (Pixmap)bmask->id, &_fgcolor, &_bgcolor, -c->offset.x, -c->offset.y); } XDefineCursor(_dpy, (Window)screen.id, (xCursor)c->id); }
Bitmap * kreadbits(char *file, int n, long *chars, int size, uchar *bits, int **doneptr) { Bitmap *bm; Biobuf *bf; char *p; long kmin, kmax; int i, j, byt; int nch; long c; uchar *b; int *done; uchar *nbits; static int dig[256] = { ['0'] 0, ['1'] 1, ['2'] 2, ['3'] 3, ['4'] 4, ['5'] 5, ['6'] 6, ['7'] 7, ['8'] 8, ['9'] 9, ['a'] 10, ['b'] 11, ['c'] 12, ['d'] 13, ['e'] 14, ['f'] 15, }; bf = Bopen(file, OREAD); if(bf == 0){ fprint(2, "%s: %s: %r\n", argv0, file); exits("bitfile open error"); } done = (int *)malloc(n*sizeof(done[0])); if(done == 0){ fprint(2, "%s: malloc error (%d bytes)\n", argv0, n); exits("malloc error"); } *doneptr = done; memset(done, 0, n*sizeof(done[0])); kmin = 65536; kmax = 0; for(i = 0; i < n; i++){ c = chars[i]; if(kmin > c) kmin = c; if(kmax < c) kmax = c; } nch = 0; byt = size/8; Brdline(bf, '\n'); /* header line 1 */ Brdline(bf, '\n'); /* header line 2 */ while(p = (char *)Brdline(bf, '\n')){ c = strtol(p+17, (char **)0, 10); if((c < kmin) || (c > kmax)) continue; for(i = 0; i < n; i++) if(c == chars[i]){ nch++; done[i] = 1; p += 25; b = bits + i*byt; for(i = 0; i < size; i++){ /* rows */ for(j = 0; j < byt; j++){ *b++ = (dig[*p]<<4) | dig[p[1]]; p += 2; } b += (n-1)*byt; } break; } } nbits = (uchar *)malloc(nch*byt*size); if(nbits == 0){ fprint(2, "%s: malloc error (%d bytes)\n", argv0, nch*byt); exits("malloc error"); } c = 0; for(i = 0; i < n; i++) if(done[i]){ for(j = 0; j < size; j++) memmove(nbits+c*byt+j*nch*byt, bits+i*byt+j*n*byt, byt); c++; } bm = balloc((Rectangle){(Point){0, 0}, (Point){nch*size, size}}, 0); if(bm == 0){ fprint(2, "%s: balloc failure\n", argv0); exits("balloc failure"); } wrbitmap(bm, 0, size, nbits); for(i = 0; i < n; i++) if(done[i] == 0){ /*fprint(2, "char 0x%x (%d) not found\n", chars[i], chars[i]);/**/ } return(bm); }
Bitmap * breadbits(char *file, int n, long *chars, int size, uchar *bits, int **doneptr) { Bitmap *bm; Biobuf *bf; int i, j, byt; int nch; long c; uchar *b, *nbits; int *done; static uchar missing[32] = {0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, 0x04, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x80, 0x00, 0x40, 0x00, 0x20, 0x00, 0x10, 0x00, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; uchar buf[32]; bf = Bopen(file, OREAD); if(bf == 0){ fprint(2, "%s: %s: %r\n", argv0, file); exits("bitfile open error"); } done = (int *)malloc(n*sizeof(done[0])); if(done == 0){ fprint(2, "%s: malloc error (%d bytes)\n", argv0, n); exits("malloc error"); } *doneptr = done; byt = size/8; nch = 0; for(i = 0; i < n; i++){ done[i] = 1; nch++; c = chars[i]; if((c >= Void1b) && (c <= Void1e)){ done[i] = 0; nch--; continue; } /* magic via presotto for calculating the seek */ j = c; if(c >= 2*Charsperfont) j += 294; /* baffling hole between A3 and A4 */ if(c > Void1e) j -= 3*Charsperfont - 0x3F; j *= byt*size; /* bytes per char */ j += 256; /* 256 front matter */ Bseek(bf, j, 0); Bread(bf, buf, sizeof(missing)); if(memcmp(buf, missing, sizeof(missing)) == 0){ done[i] = 0; nch--; continue; } Bseek(bf, j, 0); b = bits + i*byt; for(j = 0; j < size; j++){ /* rows */ Bread(bf, b, byt); b += n*byt; } } nbits = (uchar *)malloc(nch*byt*size); if(nbits == 0){ fprint(2, "%s: malloc error (%d bytes)\n", argv0, nch*byt); exits("malloc error"); } c = 0; for(i = 0; i < n; i++) if(done[i]){ for(j = 0; j < size; j++) memmove(nbits+c*byt+j*nch*byt, bits+i*byt+j*n*byt, byt); c++; } bm = balloc((Rectangle){(Point){0, 0}, (Point){nch*size, size}}, 0); if(bm == 0){ fprint(2, "%s: balloc failure\n", argv0); exits("balloc failure"); } wrbitmap(bm, 0, size, nbits); return(bm); }