make it possible to access fonts without a display.
This commit is contained in:
parent
a2c2caaafe
commit
4e20688042
7 changed files with 78 additions and 48 deletions
|
|
@ -54,14 +54,20 @@ creadimage(Display *d, int fd, int dolock)
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dolock)
|
if(d){
|
||||||
lockdisplay(d);
|
if(dolock)
|
||||||
i = allocimage(d, r, chan, 0, 0);
|
lockdisplay(d);
|
||||||
if(dolock)
|
i = allocimage(d, r, chan, 0, 0);
|
||||||
unlockdisplay(d);
|
if(dolock)
|
||||||
if(i == nil)
|
unlockdisplay(d);
|
||||||
return nil;
|
if(i == nil)
|
||||||
ncblock = _compblocksize(r, i->depth);
|
return nil;
|
||||||
|
}else{
|
||||||
|
i = mallocz(sizeof(Image), 1);
|
||||||
|
if(i == nil)
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
ncblock = _compblocksize(r, chantodepth(chan));
|
||||||
buf = malloc(ncblock);
|
buf = malloc(ncblock);
|
||||||
if(buf == nil)
|
if(buf == nil)
|
||||||
goto Errout;
|
goto Errout;
|
||||||
|
|
@ -90,22 +96,24 @@ creadimage(Display *d, int fd, int dolock)
|
||||||
}
|
}
|
||||||
if(readn(fd, buf, nb)!=nb)
|
if(readn(fd, buf, nb)!=nb)
|
||||||
goto Errout;
|
goto Errout;
|
||||||
if(dolock)
|
if(d){
|
||||||
lockdisplay(d);
|
if(dolock)
|
||||||
a = bufimage(i->display, 21+nb);
|
lockdisplay(d);
|
||||||
if(a == nil)
|
a = bufimage(i->display, 21+nb);
|
||||||
goto Erroutlock;
|
if(a == nil)
|
||||||
a[0] = 'Y';
|
goto Erroutlock;
|
||||||
BPLONG(a+1, i->id);
|
a[0] = 'Y';
|
||||||
BPLONG(a+5, r.min.x);
|
BPLONG(a+1, i->id);
|
||||||
BPLONG(a+9, miny);
|
BPLONG(a+5, r.min.x);
|
||||||
BPLONG(a+13, r.max.x);
|
BPLONG(a+9, miny);
|
||||||
BPLONG(a+17, maxy);
|
BPLONG(a+13, r.max.x);
|
||||||
if(!new) /* old image: flip the data bits */
|
BPLONG(a+17, maxy);
|
||||||
_twiddlecompressed(buf, nb);
|
if(!new) /* old image: flip the data bits */
|
||||||
memmove(a+21, buf, nb);
|
_twiddlecompressed(buf, nb);
|
||||||
if(dolock)
|
memmove(a+21, buf, nb);
|
||||||
unlockdisplay(d);
|
if(dolock)
|
||||||
|
unlockdisplay(d);
|
||||||
|
}
|
||||||
miny = maxy;
|
miny = maxy;
|
||||||
}
|
}
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
|
||||||
|
|
@ -161,7 +161,8 @@ cf2subfont(Cachefont *cf, Font *f)
|
||||||
if(f->display){
|
if(f->display){
|
||||||
if(f->display->screenimage)
|
if(f->display->screenimage)
|
||||||
depth = f->display->screenimage->depth;
|
depth = f->display->screenimage->depth;
|
||||||
}
|
}else
|
||||||
|
depth = 8;
|
||||||
name = subfontname(cf->name, f->name, depth);
|
name = subfontname(cf->name, f->name, depth);
|
||||||
if(name == nil)
|
if(name == nil)
|
||||||
return nil;
|
return nil;
|
||||||
|
|
@ -244,7 +245,7 @@ loadchar(Font *f, Rune r, Cacheinfo *c, int h, int noflush, char **subfontname)
|
||||||
}
|
}
|
||||||
|
|
||||||
subf->cf = cf;
|
subf->cf = cf;
|
||||||
if(subf->f->ascent > f->ascent){
|
if(subf->f->ascent > f->ascent && f->display){
|
||||||
/* should print something? this is a mistake in the font file */
|
/* should print something? this is a mistake in the font file */
|
||||||
/* must prevent c->top from going negative when loading cache */
|
/* must prevent c->top from going negative when loading cache */
|
||||||
Image *b;
|
Image *b;
|
||||||
|
|
@ -297,6 +298,8 @@ loadchar(Font *f, Rune r, Cacheinfo *c, int h, int noflush, char **subfontname)
|
||||||
c->width = fi->width;
|
c->width = fi->width;
|
||||||
c->x = h*f->width;
|
c->x = h*f->width;
|
||||||
c->left = fi->left;
|
c->left = fi->left;
|
||||||
|
if(f->display == nil)
|
||||||
|
return 1;
|
||||||
flushimage(f->display, 0); /* flush any pending errors */
|
flushimage(f->display, 0); /* flush any pending errors */
|
||||||
b = bufimage(f->display, 37);
|
b = bufimage(f->display, 37);
|
||||||
if(b == 0)
|
if(b == 0)
|
||||||
|
|
@ -355,10 +358,13 @@ fontresize(Font *f, int wid, int ncache, int depth)
|
||||||
Display *d;
|
Display *d;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
d = f->display;
|
|
||||||
if(depth <= 0)
|
if(depth <= 0)
|
||||||
depth = 1;
|
depth = 1;
|
||||||
|
|
||||||
|
d = f->display;
|
||||||
|
if(d == nil)
|
||||||
|
goto Nodisplay;
|
||||||
|
|
||||||
new = allocimage(d, Rect(0, 0, ncache*wid, f->height), CHAN1(CGrey, depth), 0, 0);
|
new = allocimage(d, Rect(0, 0, ncache*wid, f->height), CHAN1(CGrey, depth), 0, 0);
|
||||||
if(new == nil){
|
if(new == nil){
|
||||||
fprint(2, "font cache resize failed: %r\n");
|
fprint(2, "font cache resize failed: %r\n");
|
||||||
|
|
@ -382,6 +388,7 @@ fontresize(Font *f, int wid, int ncache, int depth)
|
||||||
}
|
}
|
||||||
freeimage(f->cacheimage);
|
freeimage(f->cacheimage);
|
||||||
f->cacheimage = new;
|
f->cacheimage = new;
|
||||||
|
Nodisplay:
|
||||||
f->width = wid;
|
f->width = wid;
|
||||||
f->maxdepth = depth;
|
f->maxdepth = depth;
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
|
||||||
|
|
@ -24,10 +24,10 @@ _getsubfont(Display *d, char *name)
|
||||||
* _getsubfont is called only from string.c and stringwidth.c,
|
* _getsubfont is called only from string.c and stringwidth.c,
|
||||||
* which are known to be safe to have this done.
|
* which are known to be safe to have this done.
|
||||||
*/
|
*/
|
||||||
if(d->locking == 0)
|
if(d && d->locking == 0)
|
||||||
unlockdisplay(d);
|
unlockdisplay(d);
|
||||||
f = readsubfont(d, name, fd, d->locking==0);
|
f = readsubfont(d, name, fd, d && d->locking==0);
|
||||||
if(d->locking == 0)
|
if(d && d->locking == 0)
|
||||||
lockdisplay(d);
|
lockdisplay(d);
|
||||||
if(f == 0)
|
if(f == 0)
|
||||||
fprint(2, "getsubfont: can't read %s: %r\n", name);
|
fprint(2, "getsubfont: can't read %s: %r\n", name);
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,10 @@ readimage(Display *d, int fd, int dolock)
|
||||||
return creadimage(d, fd, dolock);
|
return creadimage(d, fd, dolock);
|
||||||
if(readn(fd, hdr+11, 5*12-11) != 5*12-11)
|
if(readn(fd, hdr+11, 5*12-11) != 5*12-11)
|
||||||
return nil;
|
return nil;
|
||||||
chunk = d->bufsize - 32; /* a little room for header */
|
if(d)
|
||||||
|
chunk = d->bufsize - 32; /* a little room for header */
|
||||||
|
else
|
||||||
|
chunk = 8192;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* distinguish new channel descriptor from old ldepth.
|
* distinguish new channel descriptor from old ldepth.
|
||||||
|
|
@ -69,13 +72,20 @@ readimage(Display *d, int fd, int dolock)
|
||||||
maxy = r.max.y;
|
maxy = r.max.y;
|
||||||
|
|
||||||
l = bytesperline(r, chantodepth(chan));
|
l = bytesperline(r, chantodepth(chan));
|
||||||
if(dolock)
|
if(d){
|
||||||
lockdisplay(d);
|
if(dolock)
|
||||||
i = allocimage(d, r, chan, 0, -1);
|
lockdisplay(d);
|
||||||
if(dolock)
|
i = allocimage(d, r, chan, 0, -1);
|
||||||
unlockdisplay(d);
|
if(dolock)
|
||||||
if(i == nil)
|
unlockdisplay(d);
|
||||||
return nil;
|
if(i == nil)
|
||||||
|
return nil;
|
||||||
|
}else{
|
||||||
|
i = mallocz(sizeof(Image), 1);
|
||||||
|
if(i == nil)
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
tmp = malloc(chunk);
|
tmp = malloc(chunk);
|
||||||
if(tmp == nil)
|
if(tmp == nil)
|
||||||
goto Err;
|
goto Err;
|
||||||
|
|
@ -105,12 +115,14 @@ readimage(Display *d, int fd, int dolock)
|
||||||
for(j=0; j<chunk; j++)
|
for(j=0; j<chunk; j++)
|
||||||
tmp[j] ^= 0xFF;
|
tmp[j] ^= 0xFF;
|
||||||
|
|
||||||
if(dolock)
|
if(d){
|
||||||
lockdisplay(d);
|
if(dolock)
|
||||||
if(loadimage(i, Rect(r.min.x, miny, r.max.x, miny+dy), tmp, chunk) <= 0)
|
lockdisplay(d);
|
||||||
goto Err1;
|
if(loadimage(i, Rect(r.min.x, miny, r.max.x, miny+dy), tmp, chunk) <= 0)
|
||||||
if(dolock)
|
goto Err1;
|
||||||
unlockdisplay(d);
|
if(dolock)
|
||||||
|
unlockdisplay(d);
|
||||||
|
}
|
||||||
miny += dy;
|
miny += dy;
|
||||||
}
|
}
|
||||||
free(tmp);
|
free(tmp);
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,12 @@ readsubfonti(Display*d, char *name, int fd, Image *ai, int dolock)
|
||||||
n = atoi(hdr);
|
n = atoi(hdr);
|
||||||
p = malloc(6*(n+1));
|
p = malloc(6*(n+1));
|
||||||
if(p == nil)
|
if(p == nil)
|
||||||
return nil;
|
goto Err;
|
||||||
if(read(fd, p, 6*(n+1)) != 6*(n+1)){
|
if(read(fd, p, 6*(n+1)) != 6*(n+1)){
|
||||||
werrstr("rdsubfonfile: fontchar read error: %r");
|
werrstr("rdsubfonfile: fontchar read error: %r");
|
||||||
Err:
|
Err:
|
||||||
|
if(ai == nil)
|
||||||
|
freeimage(i);
|
||||||
free(p);
|
free(p);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ _stringnwidth(Font *f, char *s, Rune *r, int len)
|
||||||
}else
|
}else
|
||||||
rptr = &r;
|
rptr = &r;
|
||||||
twid = 0;
|
twid = 0;
|
||||||
while(len && (*s || *r)){
|
while(len>0 && (*s || *r)){
|
||||||
max = Max;
|
max = Max;
|
||||||
if(len < max)
|
if(len < max)
|
||||||
max = len;
|
max = len;
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,10 @@ Subfont *lastsubfont;
|
||||||
Subfont*
|
Subfont*
|
||||||
lookupsubfont(Display *d, char *name)
|
lookupsubfont(Display *d, char *name)
|
||||||
{
|
{
|
||||||
if(strcmp(name, "*default*") == 0)
|
if(d && strcmp(name, "*default*") == 0)
|
||||||
return d->defaultsubfont;
|
return d->defaultsubfont;
|
||||||
if(lastname && strcmp(name, lastname)==0 && d==lastsubfont->bits->display){
|
if(lastname && strcmp(name, lastname)==0)
|
||||||
|
if(d==lastsubfont->bits->display){
|
||||||
lastsubfont->ref++;
|
lastsubfont->ref++;
|
||||||
return lastsubfont;
|
return lastsubfont;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue