fontsrv: handle non-BMP runes on X11

Have to adjust algorithms to deal with
much larger number of subfont files as well.
This commit is contained in:
Russ Cox 2020-05-26 11:36:59 -04:00
parent a6ad39aaaa
commit 5f0fa185d0
4 changed files with 45 additions and 44 deletions

View file

@ -52,7 +52,7 @@ enum
#define QFONT(p) (((p) >> 4) & 0xFFFF)
#define QSIZE(p) (((p) >> 20) & 0xFF)
#define QANTIALIAS(p) (((p) >> 28) & 0x1)
#define QRANGE(p) (((p) >> 29) & SubfontMask)
#define QRANGE(p) (((p) >> 29) & 0xFFFFFF)
static int sizes[] = { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 24, 28 };
static vlong
@ -102,7 +102,7 @@ dostat(vlong path, Qid *qid, Dir *dir)
case Qfontfile:
f = &xfont[QFONT(path)];
load(f);
length = 11+1+11+1+f->nrange*(6+1+6+1+9+1);
length = 11+1+11+1+f->nfile*(6+1+6+1+9+1);
name = "font";
break;
@ -189,9 +189,9 @@ xwalk1(Fid *fid, char *name, Qid *qid)
goto NotFound;
p++;
n = strtoul(p, &p, 16);
if(p != name+5 || n%SubfontSize != 0 || strcmp(p, ".bit") != 0 || !f->range[(n/SubfontSize) & SubfontMask])
if(p < name+5 || p > name+5 && name[1] == '0' || n%SubfontSize != 0 || n/SubfontSize >= MaxSubfont || strcmp(p, ".bit") != 0 || !f->range[n/SubfontSize])
goto NotFound;
path += Qsubfontfile - Qsizedir + qpath(0, 0, 0, 0, (n/SubfontSize) & SubfontMask);
path += Qsubfontfile - Qsizedir + qpath(0, 0, 0, 0, n/SubfontSize);
break;
}
Found:
@ -229,7 +229,6 @@ sizegen(int i, Dir *d, void *v)
vlong path;
Fid *fid;
XFont *f;
int j;
fid = v;
path = fid->qid.path;
@ -240,15 +239,10 @@ sizegen(int i, Dir *d, void *v)
i--;
f = &xfont[QFONT(path)];
load(f);
for(j=0; j<nelem(f->range); j++) {
if(f->range[j] == 0)
continue;
if(i == 0) {
path += Qsubfontfile - Qsizedir;
path += qpath(0, 0, 0, 0, j);
goto Done;
}
i--;
if(i < f->nfile) {
path += Qsubfontfile - Qsizedir;
path += qpath(0, 0, 0, 0, f->file[i]);
goto Done;
}
return -1;
@ -315,23 +309,22 @@ xread(Req *r)
readstr(r, "font missing\n");
break;
}
height = 0;
ascent = 0;
if(f->unit > 0) {
height = f->height * (int)QSIZE(path)/f->unit + 0.99999999;
ascent = height - (int)(-f->originy * (int)QSIZE(path)/f->unit + 0.99999999);
if(f->fonttext == nil) {
height = 0;
ascent = 0;
if(f->unit > 0) {
height = f->height * (int)QSIZE(path)/f->unit + 0.99999999;
ascent = height - (int)(-f->originy * (int)QSIZE(path)/f->unit + 0.99999999);
}
if(f->loadheight != nil)
f->loadheight(f, QSIZE(path), &height, &ascent);
fmtprint(&fmt, "%11d %11d\n", height, ascent);
for(i=0; i<f->nfile; i++)
fmtprint(&fmt, "0x%04x 0x%04x x%04x.bit\n", f->file[i]*SubfontSize, ((f->file[i]+1)*SubfontSize) - 1, f->file[i]*SubfontSize);
f->fonttext = fmtstrflush(&fmt);
f->nfonttext = strlen(f->fonttext);
}
if(f->loadheight != nil)
f->loadheight(f, QSIZE(path), &height, &ascent);
fmtprint(&fmt, "%11d %11d\n", height, ascent);
for(i=0; i<nelem(f->range); i++) {
if(f->range[i] == 0)
continue;
fmtprint(&fmt, "0x%04x 0x%04x x%04x.bit\n", i*SubfontSize, ((i+1)*SubfontSize) - 1, i*SubfontSize);
}
data = fmtstrflush(&fmt);
readstr(r, data);
free(data);
readbuf(r, f->fonttext, f->nfonttext);
break;
case Qsubfontfile:
f = &xfont[QFONT(path)];