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 |
… | |
… | |
24 | #include "defaultfont.h" |
24 | #include "defaultfont.h" |
25 | |
25 | |
26 | #include <cstdlib> |
26 | #include <cstdlib> |
27 | |
27 | |
28 | #define DISPLAY r->display->display |
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 | |
32 | const struct rxvt_fallback_font { |
31 | const 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_EXT, "-*-*-*-*-*-*-*-*-*-*-c-*-big5*-0" }, |
78 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" }, |
78 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" }, |
79 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" }, |
79 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" }, |
80 | { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" }, |
80 | { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" }, |
81 | { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" }, |
81 | { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" }, |
82 | { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" }, |
82 | { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" }, |
83 | { CS_CNS11643_1992_5, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-5" }, |
83 | { CS_CNS11643_1992_5, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-5" }, |
84 | { CS_CNS11643_1992_6, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-6" }, |
84 | { CS_CNS11643_1992_6, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-6" }, |
85 | { CS_CNS11643_1992_7, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-7" }, |
85 | { CS_CNS11643_1992_7, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-7" }, |
86 | { CS_CNS11643_1992_F, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-f" }, |
86 | { CS_CNS11643_1992_F, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-f" }, |
87 | #endif |
87 | #endif |
88 | |
88 | |
89 | #if XFT |
89 | #if XFT |
90 | { CS_UNICODE, "xft:Andale Mono" }, |
90 | { CS_UNICODE, "xft:Andale Mono" }, |
91 | { CS_UNICODE, "xft:Arial Unicode MS" }, |
91 | { CS_UNICODE, "xft:Arial Unicode MS" }, |
… | |
… | |
99 | { CS_UNKNOWN, 0 } |
99 | { CS_UNKNOWN, 0 } |
100 | }; |
100 | }; |
101 | |
101 | |
102 | ///////////////////////////////////////////////////////////////////////////// |
102 | ///////////////////////////////////////////////////////////////////////////// |
103 | |
103 | |
|
|
104 | #if XFT |
|
|
105 | rxvt_drawable::~rxvt_drawable () |
|
|
106 | { |
|
|
107 | if (xftdrawable) |
|
|
108 | XftDrawDestroy (xftdrawable); |
|
|
109 | } |
|
|
110 | |
|
|
111 | rxvt_drawable::operator XftDraw *() |
|
|
112 | { |
|
|
113 | if (!xftdrawable) |
|
|
114 | xftdrawable = XftDrawCreate (display->display, drawable, display->visual, display->cmap); |
|
|
115 | |
|
|
116 | return xftdrawable; |
|
|
117 | } |
|
|
118 | #endif |
|
|
119 | |
|
|
120 | ///////////////////////////////////////////////////////////////////////////// |
|
|
121 | |
104 | static void *enc_buf; |
122 | static void *enc_buf; |
105 | static uint32_t enc_len; |
123 | static uint32_t enc_len; |
106 | |
124 | |
107 | static inline void * |
125 | static inline void * |
108 | get_enc_buf (uint32_t len) |
126 | get_enc_buf (uint32_t len) |
… | |
… | |
161 | } |
179 | } |
162 | |
180 | |
163 | ///////////////////////////////////////////////////////////////////////////// |
181 | ///////////////////////////////////////////////////////////////////////////// |
164 | |
182 | |
165 | void |
183 | void |
166 | rxvt_font::clear_rect (int x, int y, int w, int h, int color) |
184 | rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) |
167 | { |
185 | { |
168 | if (color == Color_bg) |
186 | if (color == Color_bg) |
169 | XClearArea (DISPLAY, DRAWABLE, x, y, w, h, FALSE); |
187 | XClearArea (d.display->display, d, x, y, w, h, FALSE); |
170 | else if (color >= 0) |
188 | else if (color >= 0) |
171 | { |
189 | { |
|
|
190 | #if XFT |
|
|
191 | XftDrawRect (d, &r->PixColors[color].c, x, y, w, h); |
|
|
192 | #else |
172 | XSetForeground (DISPLAY, GC, r->PixColors[color]); |
193 | XSetForeground (d.display->display, GC, r->PixColors[color]); |
173 | XFillRectangle (DISPLAY, DRAWABLE, GC, x, y, w, h); |
194 | XFillRectangle (d.display->display, d, GC, x, y, w, h); |
|
|
195 | #endif |
174 | } |
196 | } |
175 | } |
197 | } |
176 | |
198 | |
177 | static const char *linedraw_cmds[128] = { |
199 | static const char *linedraw_cmds[128] = { |
178 | "1hH", "2hH", "1vV", "2vV", |
200 | "1hH", "2hH", "1vV", "2vV", |
… | |
… | |
263 | } |
285 | } |
264 | |
286 | |
265 | return false; |
287 | return false; |
266 | } |
288 | } |
267 | |
289 | |
268 | void draw (int x, int y, |
290 | void draw (rxvt_drawable &d, int x, int y, |
269 | const text_t *text, int len, |
291 | const text_t *text, int len, |
270 | int fg, int bg); |
292 | int fg, int bg); |
271 | }; |
293 | }; |
272 | |
294 | |
273 | void |
295 | void |
274 | rxvt_font_default::draw (int x, int y, |
296 | rxvt_font_default::draw (rxvt_drawable &d, int x, int y, |
275 | const text_t *text, int len, |
297 | const text_t *text, int len, |
276 | int fg, int bg) |
298 | int fg, int bg) |
277 | { |
299 | { |
278 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
300 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
279 | |
301 | |
280 | XSetForeground (DISPLAY, GC, r->PixColors[fg]); |
302 | XSetForeground (d.display->display, GC, r->PixColors[fg]); |
281 | |
303 | |
282 | while (len--) |
304 | while (len--) |
283 | { |
305 | { |
284 | text_t t = *text++; |
306 | text_t t = *text++; |
285 | |
307 | |
|
|
308 | // is it in our linedrawing table? |
286 | if (t >= 0x2500 & t <= 0x2580 && linedraw_cmds[t - 0x2500]) |
309 | if (t >= 0x2500 & t <= 0x2580 && linedraw_cmds[t - 0x2500]) |
287 | { |
310 | { |
288 | const char *p = linedraw_cmds[t - 0x2500]; |
311 | const char *p = linedraw_cmds[t - 0x2500]; |
289 | |
312 | |
290 | int x0 = x, x1 = x + r->TermWin.fwidth / 2, x2 = x + r->TermWin.fwidth ; |
313 | 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; |
314 | int y0 = y, y1 = y + r->TermWin.fheight / 2, y2 = y + r->TermWin.fheight - 1; |
292 | |
315 | |
293 | XGCValues gcv; |
316 | XGCValues gcv; |
294 | |
317 | |
295 | while (*p) |
318 | while (*p) |
296 | { |
319 | { |
297 | switch (*p++) |
320 | switch (*p++) |
298 | { |
321 | { |
299 | case '1': |
322 | case '1': |
300 | gcv.line_width = 0; |
323 | gcv.line_width = 0; |
301 | XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
324 | XChangeGC (d.display->display, GC, GCLineWidth, &gcv); |
302 | break; |
325 | break; |
303 | |
326 | |
304 | case '2': |
327 | case '2': |
305 | gcv.line_width = 2; |
328 | gcv.line_width = 2; |
306 | XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
329 | XChangeGC (d.display->display, GC, GCLineWidth, &gcv); |
307 | break; |
330 | break; |
308 | |
331 | |
309 | case 'h': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y1, x1, y1); break; |
332 | 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; |
333 | 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; |
334 | 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; |
335 | 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; |
336 | 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; |
337 | case 'b': XDrawLine (d.display->display, d, GC, x0, y0, x2, y2); break; |
315 | } |
338 | } |
316 | } |
339 | } |
317 | |
340 | |
318 | gcv.line_width = 0; |
341 | gcv.line_width = 0; |
319 | XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
342 | XChangeGC (d.display->display, GC, GCLineWidth, &gcv); |
320 | } |
343 | } |
321 | else |
344 | else |
322 | switch (*text++) |
345 | switch (t) |
323 | { |
346 | { |
324 | case NOCHAR: |
|
|
325 | case ZERO_WIDTH_CHAR: |
347 | case ZERO_WIDTH_CHAR: |
326 | break; |
348 | break; |
327 | default: |
349 | default: |
328 | XDrawRectangle (DISPLAY, DRAWABLE, GC, x + 2, y + 2, r->TermWin.fwidth - 5, r->TermWin.fheight - 5); |
350 | int w = 0; |
|
|
351 | while (len > 0 && *text == NOCHAR) |
|
|
352 | { |
|
|
353 | ++text; |
|
|
354 | --len; |
|
|
355 | w += r->TermWin.fwidth; |
|
|
356 | } |
|
|
357 | |
|
|
358 | XDrawRectangle (d.display->display, d, GC, x + 2, y + 2, |
|
|
359 | w + r->TermWin.fwidth - 5, r->TermWin.fheight - 5); |
|
|
360 | x += w; |
329 | } |
361 | } |
330 | |
362 | |
331 | x += r->TermWin.fwidth; |
363 | x += r->TermWin.fwidth; |
332 | } |
364 | } |
333 | } |
365 | } |
… | |
… | |
343 | |
375 | |
344 | bool load (const rxvt_fontprop &prop); |
376 | bool load (const rxvt_fontprop &prop); |
345 | |
377 | |
346 | bool has_codepoint (uint32_t unicode); |
378 | bool has_codepoint (uint32_t unicode); |
347 | |
379 | |
348 | void draw (int x, int y, |
380 | void draw (rxvt_drawable &d, int x, int y, |
349 | const text_t *text, int len, |
381 | const text_t *text, int len, |
350 | int fg, int bg); |
382 | int fg, int bg); |
351 | |
383 | |
352 | XFontStruct *f; |
384 | XFontStruct *f; |
353 | codeset cs; |
385 | codeset cs; |
… | |
… | |
428 | |
460 | |
429 | XFontStruct *f = XLoadQueryFont (DISPLAY, name); |
461 | XFontStruct *f = XLoadQueryFont (DISPLAY, name); |
430 | |
462 | |
431 | if (f) |
463 | if (f) |
432 | { |
464 | { |
433 | // the font should really exists now. if not, we have a problem |
465 | // 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). |
466 | // (e.g. if the user did xset fp rehash just when we were searching fonts). |
435 | // in that case, just return garbage. |
467 | // in that case, just return garbage. |
436 | bool ret = set_properties (p, f); |
468 | bool ret = set_properties (p, f); |
437 | XFreeFont (DISPLAY, f); |
469 | XFreeFont (DISPLAY, f); |
438 | return ret; |
470 | return ret; |
… | |
… | |
644 | |
676 | |
645 | return true; |
677 | return true; |
646 | } |
678 | } |
647 | |
679 | |
648 | void |
680 | void |
649 | rxvt_font_x11::draw (int x, int y, |
681 | rxvt_font_x11::draw (rxvt_drawable &d, int x, int y, |
650 | const text_t *text, int len, |
682 | const text_t *text, int len, |
651 | int fg, int bg) |
683 | int fg, int bg) |
652 | { |
684 | { |
653 | // this looks like a mess /. |
685 | // this looks like a mess /. |
654 | // and it is a mess /. |
686 | // and it is a mess /. |
… | |
… | |
670 | { |
702 | { |
671 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
703 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
672 | |
704 | |
673 | if (bg == Color_bg && !slow) |
705 | if (bg == Color_bg && !slow) |
674 | { |
706 | { |
675 | XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); |
707 | XChangeGC (d.display->display, GC, GCForeground | GCBackground | GCFont, &v); |
676 | XDrawImageString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
708 | XDrawImageString16 (d.display->display, d, GC, x, y + base, xc, len); |
677 | } |
709 | } |
678 | else |
710 | else |
679 | { |
711 | { |
680 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
712 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
681 | |
713 | |
682 | XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); |
714 | XChangeGC (d.display->display, GC, GCForeground | GCFont, &v); |
683 | |
715 | |
684 | if (slow) |
716 | if (slow) |
685 | { |
717 | { |
686 | do |
718 | do |
687 | { |
719 | { |
688 | if (xc->byte1 || xc->byte2) |
720 | if (xc->byte1 || xc->byte2) |
689 | XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); |
721 | XDrawString16 (d.display->display, d, GC, x, y + base, xc, 1); |
690 | |
722 | |
691 | x += r->TermWin.fwidth; |
723 | x += r->TermWin.fwidth; |
692 | xc++; len--; |
724 | xc++; len--; |
693 | } |
725 | } |
694 | while (len); |
726 | while (len); |
695 | } |
727 | } |
696 | else |
728 | else |
697 | XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
729 | XDrawString16 (d.display->display, d, GC, x, y + base, xc, len); |
698 | } |
730 | } |
699 | } |
731 | } |
700 | else |
732 | else |
701 | { |
733 | { |
702 | const char *xc = enc_char (text, len, cs, slow); |
734 | const char *xc = enc_char (text, len, cs, slow); |
703 | |
735 | |
704 | if (bg == Color_bg && !slow) |
736 | if (bg == Color_bg && !slow) |
705 | { |
737 | { |
706 | XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); |
738 | XChangeGC (d.display->display, GC, GCForeground | GCBackground | GCFont, &v); |
707 | XDrawImageString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
739 | XDrawImageString (d.display->display, d, GC, x, y + base, xc, len); |
708 | } |
740 | } |
709 | else |
741 | else |
710 | { |
742 | { |
711 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
743 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
712 | |
744 | |
713 | XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); |
745 | XChangeGC (d.display->display, GC, GCForeground | GCFont, &v); |
714 | |
746 | |
715 | if (slow) |
747 | if (slow) |
716 | { |
748 | { |
717 | do |
749 | do |
718 | { |
750 | { |
719 | if (*xc) |
751 | if (*xc) |
720 | XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); |
752 | XDrawString (d.display->display, d, GC, x, y + base, xc, 1); |
721 | |
753 | |
722 | x += r->TermWin.fwidth; |
754 | x += r->TermWin.fwidth; |
723 | xc++; len--; |
755 | xc++; len--; |
724 | } |
756 | } |
725 | while (len); |
757 | while (len); |
726 | } |
758 | } |
727 | else |
759 | else |
728 | XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
760 | XDrawString (d.display->display, d, GC, x, y + base, xc, len); |
729 | } |
761 | } |
730 | } |
762 | } |
731 | } |
763 | } |
732 | |
764 | |
733 | ///////////////////////////////////////////////////////////////////////////// |
765 | ///////////////////////////////////////////////////////////////////////////// |
… | |
… | |
738 | //#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables |
770 | //#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables |
739 | #define SWATHBITS 8 |
771 | #define SWATHBITS 8 |
740 | #endif |
772 | #endif |
741 | |
773 | |
742 | struct rxvt_font_xft : rxvt_font { |
774 | struct rxvt_font_xft : rxvt_font { |
743 | rxvt_font_xft () { f = 0; d = 0; } |
775 | rxvt_font_xft () { f = 0; } |
744 | |
776 | |
745 | void clear (); |
777 | void clear (); |
746 | |
778 | |
747 | rxvt_fontprop properties (); |
779 | rxvt_fontprop properties (); |
748 | |
780 | |
749 | bool load (const rxvt_fontprop &prop); |
781 | bool load (const rxvt_fontprop &prop); |
750 | |
782 | |
751 | void draw (int x, int y, |
783 | void draw (rxvt_drawable &d, int x, int y, |
752 | const text_t *text, int len, |
784 | const text_t *text, int len, |
753 | int fg, int bg); |
785 | int fg, int bg); |
754 | |
786 | |
755 | bool has_codepoint (uint32_t unicode); |
787 | bool has_codepoint (uint32_t unicode); |
756 | |
788 | |
757 | protected: |
789 | protected: |
758 | XftFont *f; |
790 | XftFont *f; |
759 | XftDraw *d; |
|
|
760 | }; |
791 | }; |
761 | |
792 | |
762 | void |
793 | void |
763 | rxvt_font_xft::clear () |
794 | rxvt_font_xft::clear () |
764 | { |
795 | { |
765 | if (f) |
796 | if (f) |
766 | { |
797 | { |
767 | XftFontClose (DISPLAY, f); |
798 | XftFontClose (DISPLAY, f); |
768 | f = 0; |
799 | f = 0; |
769 | } |
|
|
770 | |
|
|
771 | if (d) |
|
|
772 | { |
|
|
773 | XftDrawDestroy (d); |
|
|
774 | d = 0; |
|
|
775 | } |
800 | } |
776 | } |
801 | } |
777 | |
802 | |
778 | rxvt_fontprop |
803 | rxvt_fontprop |
779 | rxvt_font_xft::properties () |
804 | rxvt_font_xft::properties () |
… | |
… | |
886 | { |
911 | { |
887 | return XftCharExists (DISPLAY, f, unicode); |
912 | return XftCharExists (DISPLAY, f, unicode); |
888 | } |
913 | } |
889 | |
914 | |
890 | void |
915 | void |
891 | rxvt_font_xft::draw (int x, int y, |
916 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
892 | const text_t *text, int len, |
917 | const text_t *text, int len, |
893 | int fg, int bg) |
918 | int fg, int bg) |
894 | { |
919 | { |
895 | if (!d) |
|
|
896 | d = XftDrawCreate (DISPLAY, DRAWABLE, r->display->visual, r->display->cmap); |
|
|
897 | |
|
|
898 | if (bg >= 0 && bg != Color_bg) |
|
|
899 | XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight); |
|
|
900 | else |
|
|
901 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
920 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
902 | |
921 | |
903 | if (!slow && width == r->TermWin.fwidth && 0) |
922 | if (!slow && width == r->TermWin.fwidth && 0) |
904 | { |
923 | { |
905 | if (sizeof (text_t) == sizeof (FcChar16)) |
924 | if (sizeof (text_t) == sizeof (FcChar16)) |
906 | XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); |
925 | XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); |
… | |
… | |
918 | fwidth *= 2; |
937 | fwidth *= 2; |
919 | |
938 | |
920 | XGlyphInfo extents; |
939 | XGlyphInfo extents; |
921 | if (sizeof (text_t) == sizeof (FcChar16)) |
940 | if (sizeof (text_t) == sizeof (FcChar16)) |
922 | { |
941 | { |
923 | XftTextExtents16 (DISPLAY, f, (const FcChar16 *)text, 1, &extents); |
942 | XftTextExtents16 (d.display->display, f, (const FcChar16 *)text, 1, &extents); |
924 | XftDrawString16 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2, |
943 | XftDrawString16 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2, |
925 | y + r->TermWin.fbase, (const FcChar16 *)text, 1); |
944 | y + r->TermWin.fbase, (const FcChar16 *)text, 1); |
926 | } |
945 | } |
927 | else |
946 | else |
928 | { |
947 | { |
929 | XGlyphInfo extents; |
948 | XGlyphInfo extents; |
930 | XftTextExtents32 (DISPLAY, f, (const FcChar32 *)text, 1, &extents); |
949 | XftTextExtents32 (d.display->display, f, (const FcChar32 *)text, 1, &extents); |
931 | XftDrawString32 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2, |
950 | XftDrawString32 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2, |
932 | y + r->TermWin.fbase, (const FcChar32 *)text, 1); |
951 | y + r->TermWin.fbase, (const FcChar32 *)text, 1); |
933 | } |
952 | } |
934 | } |
953 | } |
935 | |
954 | |
… | |
… | |
942 | #endif |
961 | #endif |
943 | |
962 | |
944 | ///////////////////////////////////////////////////////////////////////////// |
963 | ///////////////////////////////////////////////////////////////////////////// |
945 | |
964 | |
946 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
965 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
947 | : r(r) |
966 | : r (r) |
948 | { |
967 | { |
949 | clear (); |
968 | clear (); |
950 | } |
969 | } |
951 | |
970 | |
952 | rxvt_fontset::~rxvt_fontset () |
971 | rxvt_fontset::~rxvt_fontset () |
… | |
… | |
955 | } |
974 | } |
956 | |
975 | |
957 | void |
976 | void |
958 | rxvt_fontset::clear () |
977 | rxvt_fontset::clear () |
959 | { |
978 | { |
960 | for (rxvt_font **i = fonts.begin (); i != fonts.end(); i++) |
979 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
961 | FONT_UNREF (*i); |
980 | FONT_UNREF (*i); |
962 | |
981 | |
963 | fonts.clear (); |
982 | fonts.clear (); |
964 | base_id = 0; |
983 | base_id = 0; |
965 | base_prop.height = 0x7fffffff; |
984 | base_prop.height = 0x7fffffff; |
… | |
… | |
1068 | } |
1087 | } |
1069 | |
1088 | |
1070 | return true; |
1089 | return true; |
1071 | } |
1090 | } |
1072 | |
1091 | |
1073 | void |
1092 | bool |
1074 | rxvt_fontset::populate (const char *desc) |
1093 | rxvt_fontset::populate (const char *desc) |
1075 | { |
1094 | { |
1076 | clear (); |
1095 | clear (); |
1077 | |
1096 | |
1078 | fonts.push_back (new_font (0, CS_UNICODE)); |
1097 | fonts.push_back (new_font (0, CS_UNICODE)); |
… | |
… | |
1084 | base_id = 1; |
1103 | base_id = 1; |
1085 | |
1104 | |
1086 | // we currently need a base-font, no matter what |
1105 | // we currently need a base-font, no matter what |
1087 | if ((int)fonts.size () <= base_id || !realize_font (base_id)) |
1106 | if ((int)fonts.size () <= base_id || !realize_font (base_id)) |
1088 | { |
1107 | { |
1089 | puts ("unable to load specified font(s), falling back to 'fixed'\n"); |
1108 | puts ("unable to load specified font (s), falling back to 'fixed'\n"); |
1090 | add_fonts ("fixed"); |
1109 | add_fonts ("fixed"); |
1091 | base_id = fonts.size () - 1; |
1110 | base_id = fonts.size () - 1; |
1092 | } |
1111 | } |
1093 | |
1112 | |
1094 | if ((int)fonts.size () <= base_id || !realize_font (base_id)) |
1113 | if ((int)fonts.size () <= base_id || !realize_font (base_id)) |
1095 | { |
1114 | return false; |
1096 | fprintf (stderr, "unable to load a base font, please provide one using -fn fontname\n"); |
|
|
1097 | exit (1); |
|
|
1098 | } |
|
|
1099 | |
1115 | |
1100 | base_prop = fonts[base_id]->properties (); |
1116 | base_prop = fonts[base_id]->properties (); |
|
|
1117 | |
|
|
1118 | return true; |
1101 | } |
1119 | } |
1102 | |
1120 | |
1103 | int |
1121 | int |
1104 | rxvt_fontset::find_font (uint32_t unicode) |
1122 | rxvt_fontset::find_font (uint32_t unicode) |
1105 | { |
1123 | { |