1 #include "lib9.h"
2 #include "draw.h"
3
4 Point
stringsubfont(Image * b,Point p,Image * color,Subfont * f,char * cs)5 stringsubfont(Image *b, Point p, Image *color, Subfont *f, char *cs)
6 {
7 int w, width;
8 uchar *s;
9 Rune c;
10 Fontchar *i;
11
12 s = (uchar*)cs;
13 for(; c=*s; p.x+=width){
14 width = 0;
15 if(c < Runeself)
16 s++;
17 else{
18 w = chartorune(&c, (char*)s);
19 if(w == 0){
20 s++;
21 continue;
22 }
23 s += w;
24 }
25 if(c >= f->n)
26 continue;
27 i = f->info+c;
28 width = i->width;
29 draw(b, Rect(p.x+i->left, p.y+i->top, p.x+i->left+(i[1].x-i[0].x), p.y+i->bottom),
30 color, f->bits, Pt(i->x, i->top));
31 }
32 return p;
33 }
34
35 Point
strsubfontwidth(Subfont * f,char * cs)36 strsubfontwidth(Subfont *f, char *cs)
37 {
38 Rune c;
39 Point p;
40 uchar *s;
41 Fontchar *i;
42 int w, width;
43
44 p = Pt(0, f->height);
45 s = (uchar*)cs;
46 for(; c=*s; p.x+=width){
47 width = 0;
48 if(c < Runeself)
49 s++;
50 else{
51 w = chartorune(&c, (char*)s);
52 if(w == 0){
53 s++;
54 continue;
55 }
56 s += w;
57 }
58 if(c >= f->n)
59 continue;
60 i = f->info+c;
61 width = i->width;
62 }
63 return p;
64 }
65