fontsrv: use 64 chars per subfont instead of 256
Makes loading faster, and makes larger sizes not too wide. Change-Id: I076c83fdb9577c1e596de45558f38ea93e3a2a31 Reviewed-on: https://plan9port-review.googlesource.com/1360 Reviewed-by: Russ Cox <rsc@swtch.com>
This commit is contained in:
parent
a78b1841be
commit
775cb933ec
4 changed files with 14 additions and 9 deletions
|
|
@ -2,11 +2,16 @@ typedef struct XFont XFont;
|
||||||
XFont *xfont;
|
XFont *xfont;
|
||||||
int nxfont;
|
int nxfont;
|
||||||
|
|
||||||
|
enum {
|
||||||
|
SubfontSize = 32,
|
||||||
|
SubfontMask = (1<<16)/SubfontSize - 1,
|
||||||
|
};
|
||||||
|
|
||||||
struct XFont
|
struct XFont
|
||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
int loaded;
|
int loaded;
|
||||||
uchar range[256]; // range[i] == whether to have subfont i<<8 to (i+1)<<8.
|
uchar range[(1<<16)/SubfontSize]; // range[i] == whether to have subfont i*SubfontSize to (i+1)*SubfontSize - 1.
|
||||||
int nrange;
|
int nrange;
|
||||||
int unit;
|
int unit;
|
||||||
double height;
|
double height;
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ enum
|
||||||
#define QFONT(p) (((p) >> 4) & 0xFFFF)
|
#define QFONT(p) (((p) >> 4) & 0xFFFF)
|
||||||
#define QSIZE(p) (((p) >> 20) & 0xFF)
|
#define QSIZE(p) (((p) >> 20) & 0xFF)
|
||||||
#define QANTIALIAS(p) (((p) >> 28) & 0x1)
|
#define QANTIALIAS(p) (((p) >> 28) & 0x1)
|
||||||
#define QRANGE(p) (((p) >> 29) & 0xFF)
|
#define QRANGE(p) (((p) >> 29) & SubfontMask)
|
||||||
static int sizes[] = { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 24, 28 };
|
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
|
static vlong
|
||||||
|
|
@ -109,7 +109,7 @@ dostat(vlong path, Qid *qid, Dir *dir)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Qsubfontfile:
|
case Qsubfontfile:
|
||||||
snprint(buf, sizeof buf, "x%02llx00.bit", QRANGE(path));
|
snprint(buf, sizeof buf, "x%04x.bit", (int)QRANGE(path)*SubfontSize);
|
||||||
name = buf;
|
name = buf;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -191,9 +191,9 @@ xwalk1(Fid *fid, char *name, Qid *qid)
|
||||||
goto NotFound;
|
goto NotFound;
|
||||||
p++;
|
p++;
|
||||||
n = strtoul(p, &p, 16);
|
n = strtoul(p, &p, 16);
|
||||||
if(p != name+5 || (n&0xFF) != 0 || strcmp(p, ".bit") != 0 || !f->range[(n>>8) & 0xFF])
|
if(p != name+5 || n%SubfontSize != 0 || strcmp(p, ".bit") != 0 || !f->range[(n/SubfontSize) & SubfontMask])
|
||||||
goto NotFound;
|
goto NotFound;
|
||||||
path += Qsubfontfile - Qsizedir + qpath(0, 0, 0, 0, (n>>8) & 0xFF);
|
path += Qsubfontfile - Qsizedir + qpath(0, 0, 0, 0, (n/SubfontSize) & SubfontMask);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Found:
|
Found:
|
||||||
|
|
@ -329,7 +329,7 @@ xread(Req *r)
|
||||||
for(i=0; i<nelem(f->range); i++) {
|
for(i=0; i<nelem(f->range); i++) {
|
||||||
if(f->range[i] == 0)
|
if(f->range[i] == 0)
|
||||||
continue;
|
continue;
|
||||||
fmtprint(&fmt, "0x%04x 0x%04x x%04x.bit\n", i<<8, (i<<8) + 0xFF, i<<8);
|
fmtprint(&fmt, "0x%04x 0x%04x x%04x.bit\n", i*SubfontSize, ((i+1)*SubfontSize) - 1, i*SubfontSize);
|
||||||
}
|
}
|
||||||
data = fmtstrflush(&fmt);
|
data = fmtstrflush(&fmt);
|
||||||
readstr(r, data);
|
readstr(r, data);
|
||||||
|
|
@ -339,7 +339,7 @@ xread(Req *r)
|
||||||
f = &xfont[QFONT(path)];
|
f = &xfont[QFONT(path)];
|
||||||
load(f);
|
load(f);
|
||||||
if(r->fid->aux == nil) {
|
if(r->fid->aux == nil) {
|
||||||
r->fid->aux = mksubfont(f, f->name, QRANGE(path)<<8, (QRANGE(path)<<8)+0xFF, QSIZE(path), QANTIALIAS(path));
|
r->fid->aux = mksubfont(f, f->name, QRANGE(path)*SubfontSize, ((QRANGE(path)+1)*SubfontSize)-1, QSIZE(path), QANTIALIAS(path));
|
||||||
if(r->fid->aux == nil) {
|
if(r->fid->aux == nil) {
|
||||||
responderrstr(r);
|
responderrstr(r);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ load(XFont *f)
|
||||||
for(charcode=FT_Get_First_Char(face, &glyph_index); glyph_index != 0;
|
for(charcode=FT_Get_First_Char(face, &glyph_index); glyph_index != 0;
|
||||||
charcode=FT_Get_Next_Char(face, charcode, &glyph_index)) {
|
charcode=FT_Get_Next_Char(face, charcode, &glyph_index)) {
|
||||||
|
|
||||||
int idx = charcode>>8;
|
int idx = charcode/SubfontSize;
|
||||||
|
|
||||||
if(charcode > 0xffff)
|
if(charcode > 0xffff)
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ openfont1(Display *d, char *name)
|
||||||
n = _drawflength(fd);
|
n = _drawflength(fd);
|
||||||
if(fd < 0 && strncmp(fname, "/mnt/font/", 10) == 0) {
|
if(fd < 0 && strncmp(fname, "/mnt/font/", 10) == 0) {
|
||||||
fd = _fontpipe(fname+10);
|
fd = _fontpipe(fname+10);
|
||||||
n = 8192;
|
n = 128*1024;
|
||||||
}
|
}
|
||||||
if(fd < 0)
|
if(fd < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue