ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/defaultfont.C
(Generate patch)

Comparing rxvt-unicode/src/defaultfont.C (file contents):
Revision 1.14 by pcg, Thu Jan 29 00:27:16 2004 UTC vs.
Revision 1.30 by pcg, Wed Mar 3 23:06:58 2004 UTC

1/*--------------------------------*-C-*---------------------------------*; 1/*--------------------------------*-C-*---------------------------------*;
2 * File: defaultfont.C 2 * File: defaultfont.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * Copyright (c) 2003 Marc Lehmann rxvt@plan9.de> 4 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com>
5 * - original version. 5 * - original version.
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or 9 * the Free Software Foundation; either version 2 of the License, or
23#include "rxvt.h" 23#include "rxvt.h"
24#include "defaultfont.h" 24#include "defaultfont.h"
25 25
26#include <cstdlib> 26#include <cstdlib>
27 27
28#define DISPLAY r->Xdisplay 28#define DISPLAY r->display->display
29#define DRAWABLE r->TermWin.vt
30#define GC r->TermWin.gc 29#define GC r->TermWin.gc
31 30
32const struct rxvt_fallback_font { 31const struct rxvt_fallback_font {
33 codeset cs; 32 codeset cs;
34 const char *name; 33 const char *name;
73 { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, 72 { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" },
74 { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, 73 { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" },
75 { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, 74 { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" },
76 { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, 75 { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" },
77# endif 76# endif
77 { CS_BIG5, "-*-*-*-*-*-*-*-*-*-*-c-*-big5-0" },
78 { CS_BIG5_PLUS, "-*-*-*-*-*-*-*-*-*-*-c-*-big5p-0" },
79 { CS_BIG5_EXT, "-*-*-*-*-*-*-*-*-*-*-c-*-big5.eten-0" },
78 { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0 }, 80 { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" },
79 { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" }, 81 { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" },
80 { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" }, 82 { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" },
81 { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" }, 83 { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" },
82 { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" }, 84 { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" },
83 { CS_CNS11643_1992_5, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-5" }, 85 { CS_CNS11643_1992_5, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-5" },
84 { CS_CNS11643_1992_6, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-6" }, 86 { CS_CNS11643_1992_6, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-6" },
85 { CS_CNS11643_1992_7, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-7" }, 87 { CS_CNS11643_1992_7, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-7" },
86 { CS_CNS11643_1992_F, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-f" }, 88 { CS_CNS11643_1992_F, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-f" },
87#endif 89#endif
88 90
89#if XFT 91#if XFT
90 { CS_UNICODE, "xft:Andale Mono" }, 92 { CS_UNICODE, "xft:Andale Mono" },
91 { CS_UNICODE, "xft:Arial Unicode MS" }, 93 { CS_UNICODE, "xft:Arial Unicode MS" },
94 { CS_UNICODE, "xft:FreeMono" }, 96 { CS_UNICODE, "xft:FreeMono" },
95 { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, 97 { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" },
96 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, 98 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" },
97 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, 99 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" },
98 100
101#if UNICODE_3 && XFT
102 { CS_UNICODE, "xft:Code2001" }, // contains many plane-1 characters
103#endif
104
99 { CS_UNKNOWN, 0 } 105 { CS_UNKNOWN, 0 }
100}; 106};
101 107
102///////////////////////////////////////////////////////////////////////////// 108/////////////////////////////////////////////////////////////////////////////
103 109
110#if XFT
111rxvt_drawable::~rxvt_drawable ()
112{
113 if (xftdrawable)
114 XftDrawDestroy (xftdrawable);
115}
116
117rxvt_drawable::operator XftDraw *()
118{
119 if (!xftdrawable)
120 xftdrawable = XftDrawCreate (display->display, drawable, display->visual, display->cmap);
121
122 return xftdrawable;
123}
124#endif
125
126/////////////////////////////////////////////////////////////////////////////
127
104static void *enc_buf; 128static void *enc_buf;
105static uint32_t enc_len; 129static uint32_t enc_len;
106 130
107static inline void * 131static inline void *
108get_enc_buf (int len) 132get_enc_buf (uint32_t len)
109{ 133{
110 if (len > enc_len) 134 if (len > enc_len)
111 { 135 {
112 free (enc_buf); 136 free (enc_buf);
113 enc_buf = malloc (len); 137 enc_buf = malloc (len);
115 139
116 return enc_buf; 140 return enc_buf;
117} 141}
118 142
119static const char * 143static const char *
120enc_char (const text_t *text, int len, codeset cs, bool &zero) 144enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero)
121{ 145{
122 uint8_t *buf = (uint8_t *)get_enc_buf (len); 146 uint8_t *buf = (uint8_t *)get_enc_buf (len);
123 147
124 while (len--) 148 while (len--)
125 { 149 {
136 160
137 return (const char *)enc_buf; 161 return (const char *)enc_buf;
138} 162}
139 163
140static const XChar2b * 164static const XChar2b *
141enc_xchar2b (const text_t *text, int len, codeset cs, bool &zero) 165enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero)
142{ 166{
143 XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b)); 167 XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b));
144 168
145 while (len--) 169 while (len--)
146 { 170 {
161} 185}
162 186
163///////////////////////////////////////////////////////////////////////////// 187/////////////////////////////////////////////////////////////////////////////
164 188
165void 189void
166rxvt_font::clear_rect (int x, int y, int w, int h, int color) 190rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color)
167{ 191{
168 if (color == Color_bg) 192 if (color == Color_bg)
169 XClearArea (DISPLAY, DRAWABLE, x, y, w, h, FALSE); 193 XClearArea (d.display->display, d, x, y, w, h, FALSE);
170 else if (color >= 0) 194 else if (color >= 0)
171 { 195 {
196#if XFT
197 XftDrawRect (d, &r->PixColors[color].c, x, y, w, h);
198#else
172 XSetForeground (DISPLAY, GC, r->PixColors[color]); 199 XSetForeground (d.display->display, GC, r->PixColors[color]);
173 XFillRectangle (DISPLAY, DRAWABLE, GC, x, y, w, h); 200 XFillRectangle (d.display->display, d, GC, x, y, w, h);
201#endif
174 } 202 }
175} 203}
176 204
177static const char *linedraw_cmds[128] = { 205static const char *linedraw_cmds[128] = {
178 "1hH", "2hH", "1vV", "2vV", 206 "1hH", "2hH", "1vV", "2vV",
263 } 291 }
264 292
265 return false; 293 return false;
266 } 294 }
267 295
268 void draw (int x, int y, 296 void draw (rxvt_drawable &d, int x, int y,
269 const text_t *text, int len, 297 const text_t *text, int len,
270 int fg, int bg); 298 int fg, int bg);
271}; 299};
272 300
273void 301void
274rxvt_font_default::draw (int x, int y, 302rxvt_font_default::draw (rxvt_drawable &d, int x, int y,
275 const text_t *text, int len, 303 const text_t *text, int len,
276 int fg, int bg) 304 int fg, int bg)
277{ 305{
278 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 306 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
279 307
280 XSetForeground (DISPLAY, GC, r->PixColors[fg]); 308 XSetForeground (d.display->display, GC, r->PixColors[fg]);
281 309
282 while (len--) 310 while (len--)
283 { 311 {
284 text_t t = *text++; 312 text_t t = *text++;
285 313
314 // is it in our linedrawing table?
286 if (t >= 0x2500 & t <= 0x2580 && linedraw_cmds[t - 0x2500]) 315 if (t >= 0x2500 & t <= 0x2580 && linedraw_cmds[t - 0x2500])
287 { 316 {
288 const char *p = linedraw_cmds[t - 0x2500]; 317 const char *p = linedraw_cmds[t - 0x2500];
289 318
290 int x0 = x, x1 = x + r->TermWin.fwidth / 2, x2 = x + r->TermWin.fwidth ; 319 int x0 = x, x1 = x + r->TermWin.fwidth / 2, x2 = x + r->TermWin.fwidth - 1;
291 int y0 = y, y1 = y + r->TermWin.fheight / 2, y2 = y + r->TermWin.fheight; 320 int y0 = y, y1 = y + r->TermWin.fheight / 2, y2 = y + r->TermWin.fheight - 1;
292 321
293 XGCValues gcv; 322 XGCValues gcv;
294 323
295 while (*p) 324 while (*p)
296 { 325 {
297 switch (*p++) 326 switch (*p++)
298 { 327 {
299 case '1': 328 case '1':
300 gcv.line_width = 0; 329 gcv.line_width = 0;
301 XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); 330 XChangeGC (d.display->display, GC, GCLineWidth, &gcv);
302 break; 331 break;
303 332
304 case '2': 333 case '2':
305 gcv.line_width = 2; 334 gcv.line_width = 2;
306 XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); 335 XChangeGC (d.display->display, GC, GCLineWidth, &gcv);
307 break; 336 break;
308 337
309 case 'h': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y1, x1, y1); break; 338 case 'h': XDrawLine (d.display->display, d, GC, x0, y1, x1, y1); break;
310 case 'H': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y1, x2, y1); break; 339 case 'H': XDrawLine (d.display->display, d, GC, x1, y1, x2, y1); break;
311 case 'v': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y0, x1, y1); break; 340 case 'v': XDrawLine (d.display->display, d, GC, x1, y0, x1, y1); break;
312 case 'V': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y1, x1, y2); break; 341 case 'V': XDrawLine (d.display->display, d, GC, x1, y1, x1, y2); break;
313 case 'a': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y2, x2, y0); break; 342 case 'a': XDrawLine (d.display->display, d, GC, x0, y2, x2, y0); break;
314 case 'b': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y0, x2, y2); break; 343 case 'b': XDrawLine (d.display->display, d, GC, x0, y0, x2, y2); break;
315 } 344 }
316 } 345 }
317 346
318 gcv.line_width = 0; 347 gcv.line_width = 0;
319 XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); 348 XChangeGC (d.display->display, GC, GCLineWidth, &gcv);
320 } 349 }
321 else 350 else
322 switch (*text++) 351 switch (t)
323 { 352 {
324 case NOCHAR:
325 case ZERO_WIDTH_CHAR: 353 case ZERO_WIDTH_CHAR:
326 break; 354 break;
327 default: 355 default:
328 XDrawRectangle (DISPLAY, DRAWABLE, GC, x + 2, y + 2, r->TermWin.fwidth - 5, r->TermWin.fheight - 5); 356 int w = 0;
357 while (len > 0 && *text == NOCHAR)
358 {
359 ++text;
360 --len;
361 w += r->TermWin.fwidth;
362 }
363
364 XDrawRectangle (d.display->display, d, GC, x + 2, y + 2,
365 w + r->TermWin.fwidth - 5, r->TermWin.fheight - 5);
366 x += w;
329 } 367 }
330 368
331 x += r->TermWin.fwidth; 369 x += r->TermWin.fwidth;
332 } 370 }
333} 371}
343 381
344 bool load (const rxvt_fontprop &prop); 382 bool load (const rxvt_fontprop &prop);
345 383
346 bool has_codepoint (uint32_t unicode); 384 bool has_codepoint (uint32_t unicode);
347 385
348 void draw (int x, int y, 386 void draw (rxvt_drawable &d, int x, int y,
349 const text_t *text, int len, 387 const text_t *text, int len,
350 int fg, int bg); 388 int fg, int bg);
351 389
352 XFontStruct *f; 390 XFontStruct *f;
353 codeset cs; 391 codeset cs;
408 446
409bool 447bool
410rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) 448rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name)
411{ 449{
412 int slashes = 0; 450 int slashes = 0;
413 const char *comp[12]; 451 const char *comp[13];
414 452
415 for (const char *c = name; *c; c++) 453 for (const char *c = name; *c; c++)
416 if (*c == '-') 454 if (*c == '-')
417 { 455 {
418 comp[slashes++] = c + 1; 456 comp[slashes++] = c + 1;
428 466
429 XFontStruct *f = XLoadQueryFont (DISPLAY, name); 467 XFontStruct *f = XLoadQueryFont (DISPLAY, name);
430 468
431 if (f) 469 if (f)
432 { 470 {
433 // the font should really exists now. if not, we have a problem 471 // the font should really exist now. if not, we have a problem
434 // (e.g. if the user did xset fp rehash just when we were searching fonts). 472 // (e.g. if the user did xset fp rehash just when we were searching fonts).
435 // in that case, just return garbage. 473 // in that case, just return garbage.
436 bool ret = set_properties (p, f); 474 bool ret = set_properties (p, f);
437 XFreeFont (DISPLAY, f); 475 XFreeFont (DISPLAY, f);
438 return ret; 476 return ret;
515 f = XLoadQueryFont (DISPLAY, name); 553 f = XLoadQueryFont (DISPLAY, name);
516 554
517 if (!f) 555 if (!f)
518 return false; 556 return false;
519 557
520 unsigned long value;
521
522 const char *registry = get_property (f, "CHARSET_REGISTRY", 0); 558 const char *registry = get_property (f, "CHARSET_REGISTRY", 0);
523 const char *encoding = get_property (f, "CHARSET_ENCODING", 0); 559 const char *encoding = get_property (f, "CHARSET_ENCODING", 0);
524 560
525 if (registry && encoding) 561 if (registry && encoding)
526 { 562 {
612 /* check wether the character exists in _this_ font. horrible. */ 648 /* check wether the character exists in _this_ font. horrible. */
613 XCharStruct *xcs; 649 XCharStruct *xcs;
614 650
615 if (encm) 651 if (encm)
616 { 652 {
617 int byte1 = ch >> 8; 653 unsigned char byte1 = ch >> 8;
618 int byte2 = ch & 255; 654 unsigned char byte2 = ch & 255;
619 655
620 if (byte1 < f->min_byte1 || byte1 > f->max_byte1 656 if (byte1 < f->min_byte1 || byte1 > f->max_byte1
621 || byte2 < f->min_char_or_byte2 || byte2 > f->max_char_or_byte2) 657 || byte2 < f->min_char_or_byte2 || byte2 > f->max_char_or_byte2)
622 return false; 658 return false;
623 659
646 682
647 return true; 683 return true;
648} 684}
649 685
650void 686void
651rxvt_font_x11::draw (int x, int y, 687rxvt_font_x11::draw (rxvt_drawable &d, int x, int y,
652 const text_t *text, int len, 688 const text_t *text, int len,
653 int fg, int bg) 689 int fg, int bg)
654{ 690{
655 // this looks like a mess /. 691 // this looks like a mess /.
656 // and it is a mess /. 692 // and it is a mess /.
672 { 708 {
673 const XChar2b *xc = enc_xchar2b (text, len, cs, slow); 709 const XChar2b *xc = enc_xchar2b (text, len, cs, slow);
674 710
675 if (bg == Color_bg && !slow) 711 if (bg == Color_bg && !slow)
676 { 712 {
677 XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); 713 XChangeGC (d.display->display, GC, GCForeground | GCBackground | GCFont, &v);
678 XDrawImageString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); 714 XDrawImageString16 (d.display->display, d, GC, x, y + base, xc, len);
679 } 715 }
680 else 716 else
681 { 717 {
682 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 718 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
683 719
684 XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); 720 XChangeGC (d.display->display, GC, GCForeground | GCFont, &v);
685 721
686 if (slow) 722 if (slow)
687 { 723 {
688 do 724 do
689 { 725 {
690 if (xc->byte1 || xc->byte2) 726 if (xc->byte1 || xc->byte2)
691 XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); 727 XDrawString16 (d.display->display, d, GC, x, y + base, xc, 1);
692 728
693 x += r->TermWin.fwidth; 729 x += r->TermWin.fwidth;
694 xc++; len--; 730 xc++; len--;
695 } 731 }
696 while (len); 732 while (len);
697 } 733 }
698 else 734 else
699 XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); 735 XDrawString16 (d.display->display, d, GC, x, y + base, xc, len);
700 } 736 }
701 } 737 }
702 else 738 else
703 { 739 {
704 const char *xc = enc_char (text, len, cs, slow); 740 const char *xc = enc_char (text, len, cs, slow);
705 741
706 if (bg == Color_bg && !slow) 742 if (bg == Color_bg && !slow)
707 { 743 {
708 XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); 744 XChangeGC (d.display->display, GC, GCForeground | GCBackground | GCFont, &v);
709 XDrawImageString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); 745 XDrawImageString (d.display->display, d, GC, x, y + base, xc, len);
710 } 746 }
711 else 747 else
712 { 748 {
713 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 749 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
714 750
715 XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); 751 XChangeGC (d.display->display, GC, GCForeground | GCFont, &v);
716 752
717 if (slow) 753 if (slow)
718 { 754 {
719 do 755 do
720 { 756 {
721 if (*xc) 757 if (*xc)
722 XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); 758 XDrawString (d.display->display, d, GC, x, y + base, xc, 1);
723 759
724 x += r->TermWin.fwidth; 760 x += r->TermWin.fwidth;
725 xc++; len--; 761 xc++; len--;
726 } 762 }
727 while (len); 763 while (len);
728 } 764 }
729 else 765 else
730 XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); 766 XDrawString (d.display->display, d, GC, x, y + base, xc, len);
731 } 767 }
732 } 768 }
733} 769}
734 770
735///////////////////////////////////////////////////////////////////////////// 771/////////////////////////////////////////////////////////////////////////////
740//#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables 776//#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables
741#define SWATHBITS 8 777#define SWATHBITS 8
742#endif 778#endif
743 779
744struct rxvt_font_xft : rxvt_font { 780struct rxvt_font_xft : rxvt_font {
745 rxvt_font_xft () { f = 0; d = 0; } 781 rxvt_font_xft () { f = 0; }
746 782
747 void clear (); 783 void clear ();
748 784
749 rxvt_fontprop properties (); 785 rxvt_fontprop properties ();
750 786
751 bool load (const rxvt_fontprop &prop); 787 bool load (const rxvt_fontprop &prop);
752 788
753 void draw (int x, int y, 789 void draw (rxvt_drawable &d, int x, int y,
754 const text_t *text, int len, 790 const text_t *text, int len,
755 int fg, int bg); 791 int fg, int bg);
756 792
757 bool has_codepoint (uint32_t unicode); 793 bool has_codepoint (uint32_t unicode);
758 794
759protected: 795protected:
760 XftFont *f; 796 XftFont *f;
761 XftDraw *d;
762}; 797};
763 798
764void 799void
765rxvt_font_xft::clear () 800rxvt_font_xft::clear ()
766{ 801{
767 if (f) 802 if (f)
768 { 803 {
769 XftFontClose (DISPLAY, f); 804 XftFontClose (DISPLAY, f);
770 f = 0; 805 f = 0;
771 }
772
773 if (d)
774 {
775 XftDrawDestroy (d);
776 d = 0;
777 } 806 }
778} 807}
779 808
780rxvt_fontprop 809rxvt_fontprop
781rxvt_font_xft::properties () 810rxvt_font_xft::properties ()
888{ 917{
889 return XftCharExists (DISPLAY, f, unicode); 918 return XftCharExists (DISPLAY, f, unicode);
890} 919}
891 920
892void 921void
893rxvt_font_xft::draw (int x, int y, 922rxvt_font_xft::draw (rxvt_drawable &d, int x, int y,
894 const text_t *text, int len, 923 const text_t *text, int len,
895 int fg, int bg) 924 int fg, int bg)
896{ 925{
897 if (!d)
898 {
899 dR;
900 d = XftDrawCreate (DISPLAY, DRAWABLE, XVISUAL, XCMAP);
901 }
902
903 if (bg >= 0 && bg != Color_bg)
904 XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight);
905 else
906 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 926 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
907 927
908 if (!slow && width == r->TermWin.fwidth && 0) 928 if (!slow && width == r->TermWin.fwidth && 0)
909 { 929 {
910 if (sizeof (text_t) == sizeof (FcChar16)) 930 if (sizeof (text_t) == sizeof (FcChar16))
911 XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); 931 XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len);
923 fwidth *= 2; 943 fwidth *= 2;
924 944
925 XGlyphInfo extents; 945 XGlyphInfo extents;
926 if (sizeof (text_t) == sizeof (FcChar16)) 946 if (sizeof (text_t) == sizeof (FcChar16))
927 { 947 {
928 XftTextExtents16 (DISPLAY, f, (const FcChar16 *)text, 1, &extents); 948 XftTextExtents16 (d.display->display, f, (const FcChar16 *)text, 1, &extents);
929 XftDrawString16 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2, 949 XftDrawString16 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2,
930 y + r->TermWin.fbase, (const FcChar16 *)text, 1); 950 y + r->TermWin.fbase, (const FcChar16 *)text, 1);
931 } 951 }
932 else 952 else
933 { 953 {
934 XGlyphInfo extents; 954 XGlyphInfo extents;
935 XftTextExtents32 (DISPLAY, f, (const FcChar32 *)text, 1, &extents); 955 XftTextExtents32 (d.display->display, f, (const FcChar32 *)text, 1, &extents);
936 XftDrawString32 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2, 956 XftDrawString32 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2,
937 y + r->TermWin.fbase, (const FcChar32 *)text, 1); 957 y + r->TermWin.fbase, (const FcChar32 *)text, 1);
938 } 958 }
939 } 959 }
940 960
947#endif 967#endif
948 968
949///////////////////////////////////////////////////////////////////////////// 969/////////////////////////////////////////////////////////////////////////////
950 970
951rxvt_fontset::rxvt_fontset (rxvt_t r) 971rxvt_fontset::rxvt_fontset (rxvt_t r)
952#ifdef EXPLICIT_CONTEXT
953: r(r) 972: r (r)
954#endif
955{ 973{
956 clear (); 974 clear ();
957} 975}
958 976
959rxvt_fontset::~rxvt_fontset () 977rxvt_fontset::~rxvt_fontset ()
962} 980}
963 981
964void 982void
965rxvt_fontset::clear () 983rxvt_fontset::clear ()
966{ 984{
967 for (rxvt_font **i = fonts.begin (); i != fonts.end(); i++) 985 for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++)
968 FONT_UNREF (*i); 986 FONT_UNREF (*i);
969 987
970 fonts.clear (); 988 fonts.clear ();
971 base_id = 0; 989 base_id = 0;
972 base_prop.height = 0x7fffffff; 990 base_prop.height = 0x7fffffff;
1026 1044
1027 if (*desc == '[') 1045 if (*desc == '[')
1028 { 1046 {
1029 fprintf (stderr, "extra font parameters not yet supported, skipping.\n"); 1047 fprintf (stderr, "extra font parameters not yet supported, skipping.\n");
1030 1048
1031 const char *extra = desc++; 1049 //const char *extra = desc++; // not yet used
1032 1050
1033 desc = strchr (desc, ']'); 1051 desc = strchr (desc, ']');
1034 1052
1035 if (!desc) 1053 if (!desc)
1036 { 1054 {
1075 } 1093 }
1076 1094
1077 return true; 1095 return true;
1078} 1096}
1079 1097
1080void 1098bool
1081rxvt_fontset::populate (const char *desc) 1099rxvt_fontset::populate (const char *desc)
1082{ 1100{
1083 clear (); 1101 clear ();
1084 1102
1085 fonts.push_back (new_font (0, CS_UNICODE)); 1103 fonts.push_back (new_font (0, CS_UNICODE));
1089 1107
1090 if (!base_id) 1108 if (!base_id)
1091 base_id = 1; 1109 base_id = 1;
1092 1110
1093 // we currently need a base-font, no matter what 1111 // we currently need a base-font, no matter what
1094 if (fonts.size () <= base_id || !realize_font (base_id)) 1112 if ((int)fonts.size () <= base_id || !realize_font (base_id))
1095 { 1113 {
1096 puts ("unable to load specified font(s), falling back to 'fixed'\n"); 1114 puts ("unable to load specified font (s), falling back to 'fixed'\n");
1097 add_fonts ("fixed"); 1115 add_fonts ("fixed");
1098 base_id = fonts.size () - 1; 1116 base_id = fonts.size () - 1;
1099 } 1117 }
1100 1118
1101 if (fonts.size () <= base_id || !realize_font (base_id)) 1119 if ((int)fonts.size () <= base_id || !realize_font (base_id))
1102 { 1120 return false;
1103 fprintf (stderr, "unable to load a base font, please provide one using -fn fontname\n");
1104 exit (1);
1105 }
1106 1121
1107 base_prop = fonts[base_id]->properties (); 1122 base_prop = fonts[base_id]->properties ();
1123
1124 return true;
1108} 1125}
1109 1126
1110int 1127int
1111rxvt_fontset::find_font (uint32_t unicode) 1128rxvt_fontset::find_font (uint32_t unicode)
1112{ 1129{
1113 for (int i = 0; i < fonts.size (); i++) 1130 for (unsigned int i = 0; i < fonts.size (); i++)
1114 { 1131 {
1115 rxvt_font *f = fonts[i]; 1132 rxvt_font *f = fonts[i];
1116 1133
1117 if (!f->loaded) 1134 if (!f->loaded)
1118 { 1135 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines