alot of renaming...
[k8sterm.git] / src / x11drawstr.c
blob493672320257d18644a5d2d8d0b34a5dba87fb2a
1 static void k8t_DrawString (K8Term *term, const char *s, const K8TGlyph *base, int x, int y, int charlen, int bytelen) {
2 if (term != NULL) {
3 int fg = base->fg, bg = base->bg, temp;
4 int winx = x*xw.cw, winy = y*xw.ch+dc.font[0].ascent, width = charlen*xw.cw;
5 XFontSet fontset = dc.font[0].set;
6 int defF = base->attr&K8T_ATTR_DEFFG, defB = base->attr&K8T_ATTR_DEFBG;
7 //
8 /* only switch default fg/bg if term is in RV mode */
9 if (K8T_ISSET(term, K8T_MODE_REVERSE)) {
10 if (defF) fg = term->defbg;
11 if (defB) bg = term->deffg;
13 if (base->attr&K8T_ATTR_REVERSE) defF = defB = 0;
14 if (base->attr&K8T_ATTR_BOLD) {
15 if (defF && defB && defaultBoldFG >= 0) fg = defaultBoldFG;
16 else if (fg < 8) fg += 8;
17 fontset = dc.font[1].set;
19 if ((base->attr&K8T_ATTR_UNDERLINE) && defaultUnderlineFG >= 0) {
20 if (defF && defB) fg = defaultUnderlineFG;
23 if (base->attr&K8T_ATTR_REVERSE) { temp = fg; fg = bg; bg = temp; }
25 XSetBackground(xw.dpy, dc.gc, getColor(bg));
26 XSetForeground(xw.dpy, dc.gc, getColor(fg));
30 FILE *fo = fopen("zlog.log", "ab");
31 fprintf(fo, "k8t_DrawString: x=%d; y=%d; charlen=%d; bytelen=%d\n", x, y, charlen, bytelen);
32 fclose(fo);
36 if (K8T_ISGFX(base->attr)) {
37 XmbDrawImageString(xw.dpy, term->picbuf, fontset, dc.gc, winx, winy, s, bytelen);
38 } else if (!needConversion) {
39 XmbDrawImageString(xw.dpy, term->picbuf, fontset, dc.gc, winx, winy, s, bytelen);
40 } else {
41 if (bytelen > 0) {
42 //k8: dunno why, but Xutf8DrawImageString() ignores ascii (at least for terminus)
43 const char *pos = s;
44 int xpos = winx;
46 while (pos < s+bytelen) {
47 const char *e;
48 int clen;
50 if ((unsigned char)(pos[0]) < 128) {
51 for (e = pos+1; e < s+bytelen && (unsigned char)(*e) < 128; ++e) ;
52 clen = e-pos;
53 XmbDrawImageString(xw.dpy, term->picbuf, fontset, dc.gc, xpos, winy, pos, e-pos);
56 FILE *fo = fopen("zlog.log", "ab");
57 fprintf(fo, " norm: clen=%d (%d); [", clen, (int)(e-pos));
58 fwrite(pos, 1, e-pos, fo);
59 fprintf(fo, "]\n");
60 fclose(fo);
63 } else {
64 for (clen = 0, e = pos; e < s+bytelen && (unsigned char)(*e) >= 128; ++e) {
65 if (((unsigned char)(e[0])&0xc0) == 0xc0) ++clen;
67 Xutf8DrawImageString(xw.dpy, term->picbuf, fontset, dc.gc, xpos, winy, pos, e-pos);
70 FILE *fo = fopen("zlog.log", "ab");
71 fprintf(fo, " utf8: clen=%d (%d); [", clen, (int)(e-pos));
72 fwrite(pos, 1, e-pos, fo);
73 fprintf(fo, "]\n");
74 fclose(fo);
78 xpos += xw.cw*clen;
79 pos = e;
84 if (opt_drawunderline && (base->attr&K8T_ATTR_UNDERLINE)) {
85 XDrawLine(xw.dpy, term->picbuf, dc.gc, winx, winy+1, winx+width-1, winy+1);