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.26 by pcg, Fri Feb 27 02:52:51 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
78 { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0 }, 77 { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" },
79 { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" }, 78 { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" },
80 { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" }, 79 { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" },
81 { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" }, 80 { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" },
82 { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" }, 81 { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" },
83 { CS_CNS11643_1992_5, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-5" }, 82 { CS_CNS11643_1992_5, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-5" },
99 { CS_UNKNOWN, 0 } 98 { CS_UNKNOWN, 0 }
100}; 99};
101 100
102///////////////////////////////////////////////////////////////////////////// 101/////////////////////////////////////////////////////////////////////////////
103 102
103#if XFT
104rxvt_drawable::~rxvt_drawable ()
105{
106 if (xftdrawable)
107 XftDrawDestroy (xftdrawable);
108}
109
110rxvt_drawable::operator XftDraw *()
111{
112 if (!xftdrawable)
113 xftdrawable = XftDrawCreate (display->display, drawable, display->visual, display->cmap);
114
115 return xftdrawable;
116}
117#endif
118
119/////////////////////////////////////////////////////////////////////////////
120
104static void *enc_buf; 121static void *enc_buf;
105static uint32_t enc_len; 122static uint32_t enc_len;
106 123
107static inline void * 124static inline void *
108get_enc_buf (int len) 125get_enc_buf (uint32_t len)
109{ 126{
110 if (len > enc_len) 127 if (len > enc_len)
111 { 128 {
112 free (enc_buf); 129 free (enc_buf);
113 enc_buf = malloc (len); 130 enc_buf = malloc (len);
115 132
116 return enc_buf; 133 return enc_buf;
117} 134}
118 135
119static const char * 136static const char *
120enc_char (const text_t *text, int len, codeset cs, bool &zero) 137enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero)
121{ 138{
122 uint8_t *buf = (uint8_t *)get_enc_buf (len); 139 uint8_t *buf = (uint8_t *)get_enc_buf (len);
123 140
124 while (len--) 141 while (len--)
125 { 142 {
136 153
137 return (const char *)enc_buf; 154 return (const char *)enc_buf;
138} 155}
139 156
140static const XChar2b * 157static const XChar2b *
141enc_xchar2b (const text_t *text, int len, codeset cs, bool &zero) 158enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero)
142{ 159{
143 XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b)); 160 XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b));
144 161
145 while (len--) 162 while (len--)
146 { 163 {
161} 178}
162 179
163///////////////////////////////////////////////////////////////////////////// 180/////////////////////////////////////////////////////////////////////////////
164 181
165void 182void
166rxvt_font::clear_rect (int x, int y, int w, int h, int color) 183rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color)
167{ 184{
168 if (color == Color_bg) 185 if (color == Color_bg)
169 XClearArea (DISPLAY, DRAWABLE, x, y, w, h, FALSE); 186 XClearArea (d.display->display, d, x, y, w, h, FALSE);
170 else if (color >= 0) 187 else if (color >= 0)
171 { 188 {
189#if XFT
190 XftDrawRect (d, &r->PixColors[color].c, x, y, w, h);
191#else
172 XSetForeground (DISPLAY, GC, r->PixColors[color]); 192 XSetForeground (d.display->display, GC, r->PixColors[color]);
173 XFillRectangle (DISPLAY, DRAWABLE, GC, x, y, w, h); 193 XFillRectangle (d.display->display, d, GC, x, y, w, h);
194#endif
174 } 195 }
175} 196}
176 197
177static const char *linedraw_cmds[128] = { 198static const char *linedraw_cmds[128] = {
178 "1hH", "2hH", "1vV", "2vV", 199 "1hH", "2hH", "1vV", "2vV",
263 } 284 }
264 285
265 return false; 286 return false;
266 } 287 }
267 288
268 void draw (int x, int y, 289 void draw (rxvt_drawable &d, int x, int y,
269 const text_t *text, int len, 290 const text_t *text, int len,
270 int fg, int bg); 291 int fg, int bg);
271}; 292};
272 293
273void 294void
274rxvt_font_default::draw (int x, int y, 295rxvt_font_default::draw (rxvt_drawable &d, int x, int y,
275 const text_t *text, int len, 296 const text_t *text, int len,
276 int fg, int bg) 297 int fg, int bg)
277{ 298{
278 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 299 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
279 300
280 XSetForeground (DISPLAY, GC, r->PixColors[fg]); 301 XSetForeground (d.display->display, GC, r->PixColors[fg]);
281 302
282 while (len--) 303 while (len--)
283 { 304 {
284 text_t t = *text++; 305 text_t t = *text++;
285 306
286 if (t >= 0x2500 & t <= 0x2580 && linedraw_cmds[t - 0x2500]) 307 if (t >= 0x2500 & t <= 0x2580 && linedraw_cmds[t - 0x2500])
287 { 308 {
288 const char *p = linedraw_cmds[t - 0x2500]; 309 const char *p = linedraw_cmds[t - 0x2500];
289 310
290 int x0 = x, x1 = x + r->TermWin.fwidth / 2, x2 = x + r->TermWin.fwidth ; 311 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; 312 int y0 = y, y1 = y + r->TermWin.fheight / 2, y2 = y + r->TermWin.fheight - 1;
292 313
293 XGCValues gcv; 314 XGCValues gcv;
294 315
295 while (*p) 316 while (*p)
296 { 317 {
297 switch (*p++) 318 switch (*p++)
298 { 319 {
299 case '1': 320 case '1':
300 gcv.line_width = 0; 321 gcv.line_width = 0;
301 XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); 322 XChangeGC (d.display->display, GC, GCLineWidth, &gcv);
302 break; 323 break;
303 324
304 case '2': 325 case '2':
305 gcv.line_width = 2; 326 gcv.line_width = 2;
306 XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); 327 XChangeGC (d.display->display, GC, GCLineWidth, &gcv);
307 break; 328 break;
308 329
309 case 'h': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y1, x1, y1); break; 330 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; 331 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; 332 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; 333 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; 334 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; 335 case 'b': XDrawLine (d.display->display, d, GC, x0, y0, x2, y2); break;
315 } 336 }
316 } 337 }
317 338
318 gcv.line_width = 0; 339 gcv.line_width = 0;
319 XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); 340 XChangeGC (d.display->display, GC, GCLineWidth, &gcv);
320 } 341 }
321 else 342 else
322 switch (*text++) 343 switch (*text++)
323 { 344 {
324 case NOCHAR: 345 case NOCHAR:
325 case ZERO_WIDTH_CHAR: 346 case ZERO_WIDTH_CHAR:
326 break; 347 break;
327 default: 348 default:
328 XDrawRectangle (DISPLAY, DRAWABLE, GC, x + 2, y + 2, r->TermWin.fwidth - 5, r->TermWin.fheight - 5); 349 XDrawRectangle (d.display->display, d, GC, x + 2, y + 2, r->TermWin.fwidth - 5, r->TermWin.fheight - 5);
329 } 350 }
330 351
331 x += r->TermWin.fwidth; 352 x += r->TermWin.fwidth;
332 } 353 }
333} 354}
343 364
344 bool load (const rxvt_fontprop &prop); 365 bool load (const rxvt_fontprop &prop);
345 366
346 bool has_codepoint (uint32_t unicode); 367 bool has_codepoint (uint32_t unicode);
347 368
348 void draw (int x, int y, 369 void draw (rxvt_drawable &d, int x, int y,
349 const text_t *text, int len, 370 const text_t *text, int len,
350 int fg, int bg); 371 int fg, int bg);
351 372
352 XFontStruct *f; 373 XFontStruct *f;
353 codeset cs; 374 codeset cs;
428 449
429 XFontStruct *f = XLoadQueryFont (DISPLAY, name); 450 XFontStruct *f = XLoadQueryFont (DISPLAY, name);
430 451
431 if (f) 452 if (f)
432 { 453 {
433 // the font should really exists now. if not, we have a problem 454 // 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). 455 // (e.g. if the user did xset fp rehash just when we were searching fonts).
435 // in that case, just return garbage. 456 // in that case, just return garbage.
436 bool ret = set_properties (p, f); 457 bool ret = set_properties (p, f);
437 XFreeFont (DISPLAY, f); 458 XFreeFont (DISPLAY, f);
438 return ret; 459 return ret;
515 f = XLoadQueryFont (DISPLAY, name); 536 f = XLoadQueryFont (DISPLAY, name);
516 537
517 if (!f) 538 if (!f)
518 return false; 539 return false;
519 540
520 unsigned long value;
521
522 const char *registry = get_property (f, "CHARSET_REGISTRY", 0); 541 const char *registry = get_property (f, "CHARSET_REGISTRY", 0);
523 const char *encoding = get_property (f, "CHARSET_ENCODING", 0); 542 const char *encoding = get_property (f, "CHARSET_ENCODING", 0);
524 543
525 if (registry && encoding) 544 if (registry && encoding)
526 { 545 {
612 /* check wether the character exists in _this_ font. horrible. */ 631 /* check wether the character exists in _this_ font. horrible. */
613 XCharStruct *xcs; 632 XCharStruct *xcs;
614 633
615 if (encm) 634 if (encm)
616 { 635 {
617 int byte1 = ch >> 8; 636 unsigned char byte1 = ch >> 8;
618 int byte2 = ch & 255; 637 unsigned char byte2 = ch & 255;
619 638
620 if (byte1 < f->min_byte1 || byte1 > f->max_byte1 639 if (byte1 < f->min_byte1 || byte1 > f->max_byte1
621 || byte2 < f->min_char_or_byte2 || byte2 > f->max_char_or_byte2) 640 || byte2 < f->min_char_or_byte2 || byte2 > f->max_char_or_byte2)
622 return false; 641 return false;
623 642
646 665
647 return true; 666 return true;
648} 667}
649 668
650void 669void
651rxvt_font_x11::draw (int x, int y, 670rxvt_font_x11::draw (rxvt_drawable &d, int x, int y,
652 const text_t *text, int len, 671 const text_t *text, int len,
653 int fg, int bg) 672 int fg, int bg)
654{ 673{
655 // this looks like a mess /. 674 // this looks like a mess /.
656 // and it is a mess /. 675 // and it is a mess /.
672 { 691 {
673 const XChar2b *xc = enc_xchar2b (text, len, cs, slow); 692 const XChar2b *xc = enc_xchar2b (text, len, cs, slow);
674 693
675 if (bg == Color_bg && !slow) 694 if (bg == Color_bg && !slow)
676 { 695 {
677 XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); 696 XChangeGC (d.display->display, GC, GCForeground | GCBackground | GCFont, &v);
678 XDrawImageString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); 697 XDrawImageString16 (d.display->display, d, GC, x, y + base, xc, len);
679 } 698 }
680 else 699 else
681 { 700 {
682 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 701 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
683 702
684 XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); 703 XChangeGC (d.display->display, GC, GCForeground | GCFont, &v);
685 704
686 if (slow) 705 if (slow)
687 { 706 {
688 do 707 do
689 { 708 {
690 if (xc->byte1 || xc->byte2) 709 if (xc->byte1 || xc->byte2)
691 XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); 710 XDrawString16 (d.display->display, d, GC, x, y + base, xc, 1);
692 711
693 x += r->TermWin.fwidth; 712 x += r->TermWin.fwidth;
694 xc++; len--; 713 xc++; len--;
695 } 714 }
696 while (len); 715 while (len);
697 } 716 }
698 else 717 else
699 XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); 718 XDrawString16 (d.display->display, d, GC, x, y + base, xc, len);
700 } 719 }
701 } 720 }
702 else 721 else
703 { 722 {
704 const char *xc = enc_char (text, len, cs, slow); 723 const char *xc = enc_char (text, len, cs, slow);
705 724
706 if (bg == Color_bg && !slow) 725 if (bg == Color_bg && !slow)
707 { 726 {
708 XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); 727 XChangeGC (d.display->display, GC, GCForeground | GCBackground | GCFont, &v);
709 XDrawImageString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); 728 XDrawImageString (d.display->display, d, GC, x, y + base, xc, len);
710 } 729 }
711 else 730 else
712 { 731 {
713 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 732 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
714 733
715 XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); 734 XChangeGC (d.display->display, GC, GCForeground | GCFont, &v);
716 735
717 if (slow) 736 if (slow)
718 { 737 {
719 do 738 do
720 { 739 {
721 if (*xc) 740 if (*xc)
722 XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); 741 XDrawString (d.display->display, d, GC, x, y + base, xc, 1);
723 742
724 x += r->TermWin.fwidth; 743 x += r->TermWin.fwidth;
725 xc++; len--; 744 xc++; len--;
726 } 745 }
727 while (len); 746 while (len);
728 } 747 }
729 else 748 else
730 XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); 749 XDrawString (d.display->display, d, GC, x, y + base, xc, len);
731 } 750 }
732 } 751 }
733} 752}
734 753
735///////////////////////////////////////////////////////////////////////////// 754/////////////////////////////////////////////////////////////////////////////
740//#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables 759//#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables
741#define SWATHBITS 8 760#define SWATHBITS 8
742#endif 761#endif
743 762
744struct rxvt_font_xft : rxvt_font { 763struct rxvt_font_xft : rxvt_font {
745 rxvt_font_xft () { f = 0; d = 0; } 764 rxvt_font_xft () { f = 0; }
746 765
747 void clear (); 766 void clear ();
748 767
749 rxvt_fontprop properties (); 768 rxvt_fontprop properties ();
750 769
751 bool load (const rxvt_fontprop &prop); 770 bool load (const rxvt_fontprop &prop);
752 771
753 void draw (int x, int y, 772 void draw (rxvt_drawable &d, int x, int y,
754 const text_t *text, int len, 773 const text_t *text, int len,
755 int fg, int bg); 774 int fg, int bg);
756 775
757 bool has_codepoint (uint32_t unicode); 776 bool has_codepoint (uint32_t unicode);
758 777
759protected: 778protected:
760 XftFont *f; 779 XftFont *f;
761 XftDraw *d;
762}; 780};
763 781
764void 782void
765rxvt_font_xft::clear () 783rxvt_font_xft::clear ()
766{ 784{
767 if (f) 785 if (f)
768 { 786 {
769 XftFontClose (DISPLAY, f); 787 XftFontClose (DISPLAY, f);
770 f = 0; 788 f = 0;
771 }
772
773 if (d)
774 {
775 XftDrawDestroy (d);
776 d = 0;
777 } 789 }
778} 790}
779 791
780rxvt_fontprop 792rxvt_fontprop
781rxvt_font_xft::properties () 793rxvt_font_xft::properties ()
888{ 900{
889 return XftCharExists (DISPLAY, f, unicode); 901 return XftCharExists (DISPLAY, f, unicode);
890} 902}
891 903
892void 904void
893rxvt_font_xft::draw (int x, int y, 905rxvt_font_xft::draw (rxvt_drawable &d, int x, int y,
894 const text_t *text, int len, 906 const text_t *text, int len,
895 int fg, int bg) 907 int fg, int bg)
896{ 908{
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); 909 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
907 910
908 if (!slow && width == r->TermWin.fwidth && 0) 911 if (!slow && width == r->TermWin.fwidth && 0)
909 { 912 {
910 if (sizeof (text_t) == sizeof (FcChar16)) 913 if (sizeof (text_t) == sizeof (FcChar16))
911 XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); 914 XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len);
923 fwidth *= 2; 926 fwidth *= 2;
924 927
925 XGlyphInfo extents; 928 XGlyphInfo extents;
926 if (sizeof (text_t) == sizeof (FcChar16)) 929 if (sizeof (text_t) == sizeof (FcChar16))
927 { 930 {
928 XftTextExtents16 (DISPLAY, f, (const FcChar16 *)text, 1, &extents); 931 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, 932 XftDrawString16 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2,
930 y + r->TermWin.fbase, (const FcChar16 *)text, 1); 933 y + r->TermWin.fbase, (const FcChar16 *)text, 1);
931 } 934 }
932 else 935 else
933 { 936 {
934 XGlyphInfo extents; 937 XGlyphInfo extents;
935 XftTextExtents32 (DISPLAY, f, (const FcChar32 *)text, 1, &extents); 938 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, 939 XftDrawString32 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2,
937 y + r->TermWin.fbase, (const FcChar32 *)text, 1); 940 y + r->TermWin.fbase, (const FcChar32 *)text, 1);
938 } 941 }
939 } 942 }
940 943
947#endif 950#endif
948 951
949///////////////////////////////////////////////////////////////////////////// 952/////////////////////////////////////////////////////////////////////////////
950 953
951rxvt_fontset::rxvt_fontset (rxvt_t r) 954rxvt_fontset::rxvt_fontset (rxvt_t r)
952#ifdef EXPLICIT_CONTEXT
953: r(r) 955: r (r)
954#endif
955{ 956{
956 clear (); 957 clear ();
957} 958}
958 959
959rxvt_fontset::~rxvt_fontset () 960rxvt_fontset::~rxvt_fontset ()
962} 963}
963 964
964void 965void
965rxvt_fontset::clear () 966rxvt_fontset::clear ()
966{ 967{
967 for (rxvt_font **i = fonts.begin (); i != fonts.end(); i++) 968 for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++)
968 FONT_UNREF (*i); 969 FONT_UNREF (*i);
969 970
970 fonts.clear (); 971 fonts.clear ();
971 base_id = 0; 972 base_id = 0;
972 base_prop.height = 0x7fffffff; 973 base_prop.height = 0x7fffffff;
1026 1027
1027 if (*desc == '[') 1028 if (*desc == '[')
1028 { 1029 {
1029 fprintf (stderr, "extra font parameters not yet supported, skipping.\n"); 1030 fprintf (stderr, "extra font parameters not yet supported, skipping.\n");
1030 1031
1031 const char *extra = desc++; 1032 //const char *extra = desc++; // not yet used
1032 1033
1033 desc = strchr (desc, ']'); 1034 desc = strchr (desc, ']');
1034 1035
1035 if (!desc) 1036 if (!desc)
1036 { 1037 {
1075 } 1076 }
1076 1077
1077 return true; 1078 return true;
1078} 1079}
1079 1080
1080void 1081bool
1081rxvt_fontset::populate (const char *desc) 1082rxvt_fontset::populate (const char *desc)
1082{ 1083{
1083 clear (); 1084 clear ();
1084 1085
1085 fonts.push_back (new_font (0, CS_UNICODE)); 1086 fonts.push_back (new_font (0, CS_UNICODE));
1089 1090
1090 if (!base_id) 1091 if (!base_id)
1091 base_id = 1; 1092 base_id = 1;
1092 1093
1093 // we currently need a base-font, no matter what 1094 // we currently need a base-font, no matter what
1094 if (fonts.size () <= base_id || !realize_font (base_id)) 1095 if ((int)fonts.size () <= base_id || !realize_font (base_id))
1095 { 1096 {
1096 puts ("unable to load specified font(s), falling back to 'fixed'\n"); 1097 puts ("unable to load specified font (s), falling back to 'fixed'\n");
1097 add_fonts ("fixed"); 1098 add_fonts ("fixed");
1098 base_id = fonts.size () - 1; 1099 base_id = fonts.size () - 1;
1099 } 1100 }
1100 1101
1101 if (fonts.size () <= base_id || !realize_font (base_id)) 1102 if ((int)fonts.size () <= base_id || !realize_font (base_id))
1102 { 1103 return false;
1103 fprintf (stderr, "unable to load a base font, please provide one using -fn fontname\n");
1104 exit (1);
1105 }
1106 1104
1107 base_prop = fonts[base_id]->properties (); 1105 base_prop = fonts[base_id]->properties ();
1106
1107 return true;
1108} 1108}
1109 1109
1110int 1110int
1111rxvt_fontset::find_font (uint32_t unicode) 1111rxvt_fontset::find_font (uint32_t unicode)
1112{ 1112{
1113 for (int i = 0; i < fonts.size (); i++) 1113 for (unsigned int i = 0; i < fonts.size (); i++)
1114 { 1114 {
1115 rxvt_font *f = fonts[i]; 1115 rxvt_font *f = fonts[i];
1116 1116
1117 if (!f->loaded) 1117 if (!f->loaded)
1118 { 1118 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines