Exemple #1
0
Subfont*
_getsubfont(Display *d, char *name)
{
	int fd;
	Subfont *f;

	fd = libopen(name, OREAD);
		
	if(fd < 0){
		_drawprint(2, "getsubfont: can't open %s: %r\n", name);
		return 0;
	}
	/*
	 * unlock display so i/o happens with display released, unless
	 * user is doing his own locking, in which case this could break things.
	 * _getsubfont is called only from string.c and stringwidth.c,
	 * which are known to be safe to have this done.
	 */
	if(d->local == 0)
		unlockdisplay(d);
	f = readsubfont(d, name, fd, d->local == 0);
	if(d->local == 0)
		lockdisplay(d);
	if(f == 0)
		_drawprint(2, "getsubfont: can't read %s: %r\n", name);
	libclose(fd);
	return f;
}
Exemple #2
0
static void
loadfont(int n, int s)
{
    char file[256];
    int i, fd, t, deep;
    static char *try[3] = {"", "times/R.", "pelm/"};
    Subfont *f;
    Font *ff;

    try[0] = fname[n];
    for (t = 0; t < 3; t++) {
        i = s * mag * charmap[fmap[n]].xheight/0.72;	/* a pixel is 0.72 points */
        if (i < MINSIZE)
            i = MINSIZE;
        dprint(2, "size %d, i %d, mag %g\n", s, i, mag);
        for(; i >= MINSIZE; i--) {
            /* if .font file exists, take that */
            snprint(file, sizeof file, "%s/%s%d.font",
                    libfont, try[t], i);
            ff = openfont(display, file);
            if(ff != 0) {
                fonttab[n][s] = ff;
                dprint(2, "using %s for font %d %d\n", file, n, s);
                return;
            }
            /* else look for a subfont file */
            for (deep = log2[screen->depth]; deep >= 0; deep--) {
                snprint(file, sizeof file, "%s/%s%d.%d",
                        libfont, try[t], i, deep);
                dprint(2, "trying %s for %d\n", file, i);
                if ((fd = open(file, 0)) >= 0) {
                    f = readsubfont(display, file, fd, 0);
                    if (f == 0) {
                        fprint(2, "can't rdsubfontfile %s: %r\n", file);
                        exits("rdsubfont");
                    }
                    close(fd);
                    ff = mkfont(f, 0);
                    if(ff == 0) {
                        fprint(2, "can't mkfont %s: %r\n", file);
                        exits("rdsubfont");
                    }
                    fonttab[n][s] = ff;
                    dprint(2, "using %s for font %d %d\n", file, n, s);
                    return;
                }
            }
        }
    }
    fprint(2, "can't find font %s.%d or substitute, quitting\n", fname[n], s);
    exits("no font");
}

void
loadfontname(int n, char *s)
{
    int i;
    Font *f, *g = 0;

    if (strcmp(s, fname[n]) == 0)
        return;
    if(fname[n] && fname[n][0]) {
        if(lastload[n] && strcmp(lastload[n], fname[n]) == 0)
            return;
        strcpy(lastload[n], fname[n]);
    }
    fontlookup(n, s);
    for (i = 0; i < NSIZE; i++)
        if (f = fonttab[n][i]) {
            if (f != g) {
                freefont(f);
                g = f;
            }
            fonttab[n][i] = 0;
        }
}

void
allfree(void)
{
    int i;

    for (i=0; i<NFONT; i++)
        loadfontname(i, "??");
}


void
readmapfile(char *file)
{
    Biobuf *fp;
    char *p, cmd[100];

    if ((fp=Bopen(file, OREAD)) == 0) {
        fprint(2, "proof: can't open map file %s\n", file);
        exits("urk");
    }
    while((p=Brdline(fp, '\n')) != 0) {
        p[Blinelen(fp)-1] = 0;
        scanstr(p, cmd, 0);
        if(p[0]=='\0' || eq(cmd, "#"))	/* skip comments, empty */
            continue;
        else if(eq(cmd, "xheight"))
            buildxheight(fp);
        else if(eq(cmd, "map"))
            buildmap(fp);
        else if(eq(cmd, "special"))
            buildtroff(p);
        else if(eq(cmd, "troff"))
            buildtroff(p);
        else
            fprint(2, "weird map line %s\n", p);
    }
    Bterm(fp);
}