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