2011-03-30 05:46:40 -07:00
|
|
|
#include <u.h>
|
|
|
|
#include <libc.h>
|
|
|
|
#include <draw.h>
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
Max = 100
|
|
|
|
};
|
|
|
|
|
|
|
|
Point
|
|
|
|
string(Image *dst, Point pt, Image *src, Point sp, Font *f, char *s)
|
|
|
|
{
|
|
|
|
return _string(dst, pt, src, sp, f, s, nil, 1<<24, dst->clipr, nil, ZP, SoverD);
|
|
|
|
}
|
|
|
|
|
|
|
|
Point
|
|
|
|
stringop(Image *dst, Point pt, Image *src, Point sp, Font *f, char *s, Drawop op)
|
|
|
|
{
|
|
|
|
return _string(dst, pt, src, sp, f, s, nil, 1<<24, dst->clipr, nil, ZP, op);
|
|
|
|
}
|
|
|
|
|
|
|
|
Point
|
|
|
|
stringn(Image *dst, Point pt, Image *src, Point sp, Font *f, char *s, int len)
|
|
|
|
{
|
|
|
|
return _string(dst, pt, src, sp, f, s, nil, len, dst->clipr, nil, ZP, SoverD);
|
|
|
|
}
|
|
|
|
|
|
|
|
Point
|
|
|
|
stringnop(Image *dst, Point pt, Image *src, Point sp, Font *f, char *s, int len, Drawop op)
|
|
|
|
{
|
|
|
|
return _string(dst, pt, src, sp, f, s, nil, len, dst->clipr, nil, ZP, op);
|
|
|
|
}
|
|
|
|
|
|
|
|
Point
|
|
|
|
runestring(Image *dst, Point pt, Image *src, Point sp, Font *f, Rune *r)
|
|
|
|
{
|
|
|
|
return _string(dst, pt, src, sp, f, nil, r, 1<<24, dst->clipr, nil, ZP, SoverD);
|
|
|
|
}
|
|
|
|
|
|
|
|
Point
|
|
|
|
runestringop(Image *dst, Point pt, Image *src, Point sp, Font *f, Rune *r, Drawop op)
|
|
|
|
{
|
|
|
|
return _string(dst, pt, src, sp, f, nil, r, 1<<24, dst->clipr, nil, ZP, op);
|
|
|
|
}
|
|
|
|
|
|
|
|
Point
|
|
|
|
runestringn(Image *dst, Point pt, Image *src, Point sp, Font *f, Rune *r, int len)
|
|
|
|
{
|
|
|
|
return _string(dst, pt, src, sp, f, nil, r, len, dst->clipr, nil, ZP, SoverD);
|
|
|
|
}
|
|
|
|
|
|
|
|
Point
|
|
|
|
runestringnop(Image *dst, Point pt, Image *src, Point sp, Font *f, Rune *r, int len, Drawop op)
|
|
|
|
{
|
|
|
|
return _string(dst, pt, src, sp, f, nil, r, len, dst->clipr, nil, ZP, op);
|
|
|
|
}
|
|
|
|
|
|
|
|
Point
|
|
|
|
_string(Image *dst, Point pt, Image *src, Point sp, Font *f, char *s, Rune *r, int len, Rectangle clipr, Image *bg, Point bgp, Drawop op)
|
|
|
|
{
|
2014-01-05 18:49:14 -08:00
|
|
|
int m, n, wid, max, try;
|
2011-03-30 05:46:40 -07:00
|
|
|
ushort cbuf[Max], *c, *ec;
|
|
|
|
uchar *b;
|
|
|
|
char *subfontname;
|
|
|
|
char **sptr;
|
2014-01-05 18:49:14 -08:00
|
|
|
Rune **rptr, rune;
|
2011-03-30 05:46:40 -07:00
|
|
|
Subfont *sf;
|
|
|
|
|
|
|
|
if(s == nil){
|
|
|
|
s = "";
|
|
|
|
sptr = nil;
|
|
|
|
}else
|
|
|
|
sptr = &s;
|
|
|
|
if(r == nil){
|
|
|
|
r = (Rune*) L"";
|
|
|
|
rptr = nil;
|
|
|
|
}else
|
|
|
|
rptr = &r;
|
|
|
|
sf = nil;
|
2014-01-05 18:49:14 -08:00
|
|
|
try = 0;
|
|
|
|
while((*s || *r) && len > 0){
|
2011-03-30 05:46:40 -07:00
|
|
|
max = Max;
|
|
|
|
if(len < max)
|
|
|
|
max = len;
|
2014-01-05 18:49:14 -08:00
|
|
|
if((n = cachechars(f, sptr, rptr, cbuf, max, &wid, &subfontname)) <= 0){
|
|
|
|
if(subfontname){
|
|
|
|
if(++try > 10)
|
|
|
|
break;
|
|
|
|
Nextfont:
|
|
|
|
freesubfont(sf);
|
|
|
|
if((sf=_getsubfont(f->display, subfontname)) != nil)
|
|
|
|
continue;
|
|
|
|
if(f->display->defaultfont == nil || f->display->defaultfont == f)
|
|
|
|
break;
|
|
|
|
f = f->display->defaultfont;
|
|
|
|
continue;
|
2011-03-30 05:46:40 -07:00
|
|
|
}
|
2014-01-05 18:49:14 -08:00
|
|
|
if(*r)
|
|
|
|
r++;
|
2011-03-30 05:46:40 -07:00
|
|
|
else
|
2014-01-05 18:49:14 -08:00
|
|
|
s += chartorune(&rune, s);
|
|
|
|
len--;
|
|
|
|
continue;
|
2011-03-30 05:46:40 -07:00
|
|
|
}
|
2014-01-05 18:49:14 -08:00
|
|
|
try = 0;
|
|
|
|
|
|
|
|
_setdrawop(dst->display, op);
|
|
|
|
|
|
|
|
m = 47+2*n;
|
|
|
|
if(bg)
|
|
|
|
m += 4+2*4;
|
|
|
|
b = bufimage(dst->display, m);
|
|
|
|
if(b == 0){
|
|
|
|
fprint(2, "string: %r\n");
|
|
|
|
break;
|
2011-03-30 05:46:40 -07:00
|
|
|
}
|
2014-01-05 18:49:14 -08:00
|
|
|
if(bg)
|
|
|
|
b[0] = 'x';
|
|
|
|
else
|
|
|
|
b[0] = 's';
|
|
|
|
BPLONG(b+1, dst->id);
|
|
|
|
BPLONG(b+5, src->id);
|
|
|
|
BPLONG(b+9, f->cacheimage->id);
|
|
|
|
BPLONG(b+13, pt.x);
|
|
|
|
BPLONG(b+17, pt.y+f->ascent);
|
|
|
|
BPLONG(b+21, clipr.min.x);
|
|
|
|
BPLONG(b+25, clipr.min.y);
|
|
|
|
BPLONG(b+29, clipr.max.x);
|
|
|
|
BPLONG(b+33, clipr.max.y);
|
|
|
|
BPLONG(b+37, sp.x);
|
|
|
|
BPLONG(b+41, sp.y);
|
|
|
|
BPSHORT(b+45, n);
|
|
|
|
b += 47;
|
|
|
|
if(bg){
|
|
|
|
BPLONG(b, bg->id);
|
|
|
|
BPLONG(b+4, bgp.x);
|
|
|
|
BPLONG(b+8, bgp.y);
|
|
|
|
b += 12;
|
|
|
|
}
|
|
|
|
ec = &cbuf[n];
|
|
|
|
for(c=cbuf; c<ec; c++, b+=2)
|
|
|
|
BPSHORT(b, *c);
|
|
|
|
pt.x += wid;
|
|
|
|
bgp.x += wid;
|
|
|
|
agefont(f);
|
|
|
|
len -= n;
|
|
|
|
|
|
|
|
if(subfontname)
|
|
|
|
goto Nextfont;
|
2011-03-30 05:46:40 -07:00
|
|
|
}
|
2011-09-05 09:34:46 -07:00
|
|
|
freesubfont(sf);
|
2011-03-30 05:46:40 -07:00
|
|
|
return pt;
|
|
|
|
}
|