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;
|
||||
int nxfont;
|
||||
|
||||
enum {
|
||||
SubfontSize = 32,
|
||||
SubfontMask = (1<<16)/SubfontSize - 1,
|
||||
};
|
||||
|
||||
struct XFont
|
||||
{
|
||||
char *name;
|
||||
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 unit;
|
||||
double height;
|
||||
|
|
|
|||
|
|
@ -54,7 +54,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) & 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 vlong
|
||||
|
|
@ -109,7 +109,7 @@ dostat(vlong path, Qid *qid, Dir *dir)
|
|||
break;
|
||||
|
||||
case Qsubfontfile:
|
||||
snprint(buf, sizeof buf, "x%02llx00.bit", QRANGE(path));
|
||||
snprint(buf, sizeof buf, "x%04x.bit", (int)QRANGE(path)*SubfontSize);
|
||||
name = buf;
|
||||
break;
|
||||
}
|
||||
|
|
@ -191,9 +191,9 @@ xwalk1(Fid *fid, char *name, Qid *qid)
|
|||
goto NotFound;
|
||||
p++;
|
||||
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;
|
||||
path += Qsubfontfile - Qsizedir + qpath(0, 0, 0, 0, (n>>8) & 0xFF);
|
||||
path += Qsubfontfile - Qsizedir + qpath(0, 0, 0, 0, (n/SubfontSize) & SubfontMask);
|
||||
break;
|
||||
}
|
||||
Found:
|
||||
|
|
@ -329,7 +329,7 @@ xread(Req *r)
|
|||
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<<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);
|
||||
readstr(r, data);
|
||||
|
|
@ -339,7 +339,7 @@ xread(Req *r)
|
|||
f = &xfont[QFONT(path)];
|
||||
load(f);
|
||||
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) {
|
||||
responderrstr(r);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ load(XFont *f)
|
|||
for(charcode=FT_Get_First_Char(face, &glyph_index); glyph_index != 0;
|
||||
charcode=FT_Get_Next_Char(face, charcode, &glyph_index)) {
|
||||
|
||||
int idx = charcode>>8;
|
||||
int idx = charcode/SubfontSize;
|
||||
|
||||
if(charcode > 0xffff)
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue