Example #1
0
int
entrytextwidth(Tk *tk, int n)
{
	TkEntry *tke = TKobj(TkEntry, tk);
	Rune c;
	Font *f;

	f = tk->env->font;
	if (tke->show != nil) {
		chartorune(&c, tke->show);
		return n * runestringnwidth(f, &c, 1);
	}
	return runestringnwidth(f, tke->text, n);
}
Example #2
0
File: mc.c Project: mkhl/plan9port
int
wordsize(Rune *w, int nw)
{
	if(nw < 0)
		abort();
	if(font)
		return runestringnwidth(font, w, nw);
	return nw;
}
Example #3
0
int
xtofchar(Rune *s, Font *f, long p)
{
    Rune *r;
    int q;

    if(p == 0)
        return 0;

    q = 0;
    for(r=s; *r!=L'\0'; r++) {
        p -= runestringnwidth(f, r, 1);
        if(p < 0)
            break;
        q++;
    }
    return q;
}
Example #4
0
void
center(Font *f, Point p, char *s, Image *color)
{
	int i, n, dx;
	Rune rbuf[32];
	char sbuf[32*UTFmax+1];

	dx = stringwidth(f, s);
	if(dx > Facesize){
		n = torune(rbuf, s, nelem(rbuf));
		for(i=0; i<n; i++){
			dx = runestringnwidth(f, rbuf, i+1);
			if(dx > Facesize)
				break;
		}
		sprint(sbuf, "%.*S", i, rbuf);
		s = sbuf;
		dx = stringwidth(f, s);
	}
	p.x += (Facesize-dx)/2;
	string(screen, p, color, ZP, f, s);
}