tfontsrv: use 64 chars per subfont instead of 256 - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 775cb933ecea6361717ef1def27b5d9e90c385fd
 (DIR) parent a78b1841be06709756d7fd3ccb6abac3a14a3cdb
 (HTM) Author: Russ Cox <rsc@swtch.com>
       Date:   Fri,  3 Jul 2015 10:57:42 -0400
       
       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>
       
       Diffstat:
         M src/cmd/fontsrv/a.h                 |       7 ++++++-
         M src/cmd/fontsrv/main.c              |      12 ++++++------
         M src/cmd/fontsrv/x11.c               |       2 +-
         M src/libdraw/openfont.c              |       2 +-
       
       4 files changed, 14 insertions(+), 9 deletions(-)
       ---
 (DIR) diff --git a/src/cmd/fontsrv/a.h b/src/cmd/fontsrv/a.h
       t@@ -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;
 (DIR) diff --git a/src/cmd/fontsrv/main.c b/src/cmd/fontsrv/main.c
       t@@ -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
       t@@ -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;
                }
       t@@ -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:
       t@@ -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);
       t@@ -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;
 (DIR) diff --git a/src/cmd/fontsrv/x11.c b/src/cmd/fontsrv/x11.c
       t@@ -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;
 (DIR) diff --git a/src/libdraw/openfont.c b/src/libdraw/openfont.c
       t@@ -61,7 +61,7 @@ openfont1(Display *d, char *name)
                        n = _drawflength(fd);
                if(fd < 0 && strncmp(fname, "/mnt/font/", 10) == 0) {
                        fd = _fontpipe(fname+10);
       -                n = 8192;
       +                n = 128*1024;
                }
                if(fd < 0)
                        return 0;