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 | |
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, "-*-*-*-*-*-*-*-*-*-*-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" }, |
… | |
… | |
99 | { CS_UNKNOWN, 0 } |
101 | { CS_UNKNOWN, 0 } |
100 | }; |
102 | }; |
101 | |
103 | |
102 | ///////////////////////////////////////////////////////////////////////////// |
104 | ///////////////////////////////////////////////////////////////////////////// |
103 | |
105 | |
|
|
106 | #if XFT |
|
|
107 | rxvt_drawable::~rxvt_drawable () |
|
|
108 | { |
|
|
109 | if (xftdrawable) |
|
|
110 | XftDrawDestroy (xftdrawable); |
|
|
111 | } |
|
|
112 | |
|
|
113 | rxvt_drawable::operator XftDraw *() |
|
|
114 | { |
|
|
115 | if (!xftdrawable) |
|
|
116 | xftdrawable = XftDrawCreate (display->display, drawable, display->visual, display->cmap); |
|
|
117 | |
|
|
118 | return xftdrawable; |
|
|
119 | } |
|
|
120 | #endif |
|
|
121 | |
|
|
122 | ///////////////////////////////////////////////////////////////////////////// |
|
|
123 | |
104 | static void *enc_buf; |
124 | static void *enc_buf; |
105 | static uint32_t enc_len; |
125 | static uint32_t enc_len; |
106 | |
126 | |
107 | static inline void * |
127 | static inline void * |
108 | get_enc_buf (int len) |
128 | get_enc_buf (uint32_t len) |
109 | { |
129 | { |
110 | if (len > enc_len) |
130 | if (len > enc_len) |
111 | { |
131 | { |
112 | free (enc_buf); |
132 | free (enc_buf); |
113 | enc_buf = malloc (len); |
133 | enc_buf = malloc (len); |
… | |
… | |
115 | |
135 | |
116 | return enc_buf; |
136 | return enc_buf; |
117 | } |
137 | } |
118 | |
138 | |
119 | static const char * |
139 | static const char * |
120 | enc_char (const text_t *text, int len, codeset cs, bool &zero) |
140 | enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) |
121 | { |
141 | { |
122 | uint8_t *buf = (uint8_t *)get_enc_buf (len); |
142 | uint8_t *buf = (uint8_t *)get_enc_buf (len); |
123 | |
143 | |
124 | while (len--) |
144 | while (len--) |
125 | { |
145 | { |
… | |
… | |
136 | |
156 | |
137 | return (const char *)enc_buf; |
157 | return (const char *)enc_buf; |
138 | } |
158 | } |
139 | |
159 | |
140 | static const XChar2b * |
160 | static const XChar2b * |
141 | enc_xchar2b (const text_t *text, int len, codeset cs, bool &zero) |
161 | enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero) |
142 | { |
162 | { |
143 | XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b)); |
163 | XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b)); |
144 | |
164 | |
145 | while (len--) |
165 | while (len--) |
146 | { |
166 | { |
… | |
… | |
161 | } |
181 | } |
162 | |
182 | |
163 | ///////////////////////////////////////////////////////////////////////////// |
183 | ///////////////////////////////////////////////////////////////////////////// |
164 | |
184 | |
165 | void |
185 | void |
166 | rxvt_font::clear_rect (int x, int y, int w, int h, int color) |
186 | rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) |
167 | { |
187 | { |
168 | if (color == Color_bg) |
188 | if (color == Color_bg) |
169 | XClearArea (DISPLAY, DRAWABLE, x, y, w, h, FALSE); |
189 | XClearArea (d.display->display, d, x, y, w, h, FALSE); |
170 | else if (color >= 0) |
190 | else if (color >= 0) |
171 | { |
191 | { |
|
|
192 | #if XFT |
|
|
193 | XftDrawRect (d, &r->PixColors[color].c, x, y, w, h); |
|
|
194 | #else |
172 | XSetForeground (DISPLAY, GC, r->PixColors[color]); |
195 | XSetForeground (d.display->display, GC, r->PixColors[color]); |
173 | XFillRectangle (DISPLAY, DRAWABLE, GC, x, y, w, h); |
196 | XFillRectangle (d.display->display, d, GC, x, y, w, h); |
|
|
197 | #endif |
174 | } |
198 | } |
175 | } |
199 | } |
176 | |
200 | |
177 | static const char *linedraw_cmds[128] = { |
201 | static const char *linedraw_cmds[128] = { |
178 | "1hH", "2hH", "1vV", "2vV", |
202 | "1hH", "2hH", "1vV", "2vV", |
… | |
… | |
263 | } |
287 | } |
264 | |
288 | |
265 | return false; |
289 | return false; |
266 | } |
290 | } |
267 | |
291 | |
268 | void draw (int x, int y, |
292 | void draw (rxvt_drawable &d, int x, int y, |
269 | const text_t *text, int len, |
293 | const text_t *text, int len, |
270 | int fg, int bg); |
294 | int fg, int bg); |
271 | }; |
295 | }; |
272 | |
296 | |
273 | void |
297 | void |
274 | rxvt_font_default::draw (int x, int y, |
298 | rxvt_font_default::draw (rxvt_drawable &d, int x, int y, |
275 | const text_t *text, int len, |
299 | const text_t *text, int len, |
276 | int fg, int bg) |
300 | int fg, int bg) |
277 | { |
301 | { |
278 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
302 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
279 | |
303 | |
280 | XSetForeground (DISPLAY, GC, r->PixColors[fg]); |
304 | XSetForeground (d.display->display, GC, r->PixColors[fg]); |
281 | |
305 | |
282 | while (len--) |
306 | while (len--) |
283 | { |
307 | { |
284 | text_t t = *text++; |
308 | text_t t = *text++; |
285 | |
309 | |
|
|
310 | // is it in our linedrawing table? |
286 | if (t >= 0x2500 & t <= 0x2580 && linedraw_cmds[t - 0x2500]) |
311 | if (t >= 0x2500 & t <= 0x2580 && linedraw_cmds[t - 0x2500]) |
287 | { |
312 | { |
288 | const char *p = linedraw_cmds[t - 0x2500]; |
313 | const char *p = linedraw_cmds[t - 0x2500]; |
289 | |
314 | |
290 | int x0 = x, x1 = x + r->TermWin.fwidth / 2, x2 = x + r->TermWin.fwidth ; |
315 | 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; |
316 | int y0 = y, y1 = y + r->TermWin.fheight / 2, y2 = y + r->TermWin.fheight - 1; |
292 | |
317 | |
293 | XGCValues gcv; |
318 | XGCValues gcv; |
294 | |
319 | |
295 | while (*p) |
320 | while (*p) |
296 | { |
321 | { |
297 | switch (*p++) |
322 | switch (*p++) |
298 | { |
323 | { |
299 | case '1': |
324 | case '1': |
300 | gcv.line_width = 0; |
325 | gcv.line_width = 0; |
301 | XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
326 | XChangeGC (d.display->display, GC, GCLineWidth, &gcv); |
302 | break; |
327 | break; |
303 | |
328 | |
304 | case '2': |
329 | case '2': |
305 | gcv.line_width = 2; |
330 | gcv.line_width = 2; |
306 | XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
331 | XChangeGC (d.display->display, GC, GCLineWidth, &gcv); |
307 | break; |
332 | break; |
308 | |
333 | |
309 | case 'h': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y1, x1, y1); break; |
334 | 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; |
335 | 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; |
336 | 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; |
337 | 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; |
338 | 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; |
339 | case 'b': XDrawLine (d.display->display, d, GC, x0, y0, x2, y2); break; |
315 | } |
340 | } |
316 | } |
341 | } |
317 | |
342 | |
318 | gcv.line_width = 0; |
343 | gcv.line_width = 0; |
319 | XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
344 | XChangeGC (d.display->display, GC, GCLineWidth, &gcv); |
320 | } |
345 | } |
321 | else |
346 | else |
322 | switch (*text++) |
347 | switch (t) |
323 | { |
348 | { |
324 | case NOCHAR: |
|
|
325 | case ZERO_WIDTH_CHAR: |
349 | case ZERO_WIDTH_CHAR: |
326 | break; |
350 | break; |
327 | default: |
351 | default: |
328 | XDrawRectangle (DISPLAY, DRAWABLE, GC, x + 2, y + 2, r->TermWin.fwidth - 5, r->TermWin.fheight - 5); |
352 | int w = 0; |
|
|
353 | while (len > 0 && *text == NOCHAR) |
|
|
354 | { |
|
|
355 | ++text; |
|
|
356 | --len; |
|
|
357 | w += r->TermWin.fwidth; |
|
|
358 | } |
|
|
359 | |
|
|
360 | XDrawRectangle (d.display->display, d, GC, x + 2, y + 2, |
|
|
361 | w + r->TermWin.fwidth - 5, r->TermWin.fheight - 5); |
|
|
362 | x += w; |
329 | } |
363 | } |
330 | |
364 | |
331 | x += r->TermWin.fwidth; |
365 | x += r->TermWin.fwidth; |
332 | } |
366 | } |
333 | } |
367 | } |
… | |
… | |
343 | |
377 | |
344 | bool load (const rxvt_fontprop &prop); |
378 | bool load (const rxvt_fontprop &prop); |
345 | |
379 | |
346 | bool has_codepoint (uint32_t unicode); |
380 | bool has_codepoint (uint32_t unicode); |
347 | |
381 | |
348 | void draw (int x, int y, |
382 | void draw (rxvt_drawable &d, int x, int y, |
349 | const text_t *text, int len, |
383 | const text_t *text, int len, |
350 | int fg, int bg); |
384 | int fg, int bg); |
351 | |
385 | |
352 | XFontStruct *f; |
386 | XFontStruct *f; |
353 | codeset cs; |
387 | codeset cs; |
… | |
… | |
408 | |
442 | |
409 | bool |
443 | bool |
410 | rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) |
444 | rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) |
411 | { |
445 | { |
412 | int slashes = 0; |
446 | int slashes = 0; |
413 | const char *comp[12]; |
447 | const char *comp[13]; |
414 | |
448 | |
415 | for (const char *c = name; *c; c++) |
449 | for (const char *c = name; *c; c++) |
416 | if (*c == '-') |
450 | if (*c == '-') |
417 | { |
451 | { |
418 | comp[slashes++] = c + 1; |
452 | comp[slashes++] = c + 1; |
… | |
… | |
428 | |
462 | |
429 | XFontStruct *f = XLoadQueryFont (DISPLAY, name); |
463 | XFontStruct *f = XLoadQueryFont (DISPLAY, name); |
430 | |
464 | |
431 | if (f) |
465 | if (f) |
432 | { |
466 | { |
433 | // the font should really exists now. if not, we have a problem |
467 | // 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). |
468 | // (e.g. if the user did xset fp rehash just when we were searching fonts). |
435 | // in that case, just return garbage. |
469 | // in that case, just return garbage. |
436 | bool ret = set_properties (p, f); |
470 | bool ret = set_properties (p, f); |
437 | XFreeFont (DISPLAY, f); |
471 | XFreeFont (DISPLAY, f); |
438 | return ret; |
472 | return ret; |
… | |
… | |
515 | f = XLoadQueryFont (DISPLAY, name); |
549 | f = XLoadQueryFont (DISPLAY, name); |
516 | |
550 | |
517 | if (!f) |
551 | if (!f) |
518 | return false; |
552 | return false; |
519 | |
553 | |
520 | unsigned long value; |
|
|
521 | |
|
|
522 | const char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
554 | const char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
523 | const char *encoding = get_property (f, "CHARSET_ENCODING", 0); |
555 | const char *encoding = get_property (f, "CHARSET_ENCODING", 0); |
524 | |
556 | |
525 | if (registry && encoding) |
557 | if (registry && encoding) |
526 | { |
558 | { |
… | |
… | |
612 | /* check wether the character exists in _this_ font. horrible. */ |
644 | /* check wether the character exists in _this_ font. horrible. */ |
613 | XCharStruct *xcs; |
645 | XCharStruct *xcs; |
614 | |
646 | |
615 | if (encm) |
647 | if (encm) |
616 | { |
648 | { |
617 | int byte1 = ch >> 8; |
649 | unsigned char byte1 = ch >> 8; |
618 | int byte2 = ch & 255; |
650 | unsigned char byte2 = ch & 255; |
619 | |
651 | |
620 | if (byte1 < f->min_byte1 || byte1 > f->max_byte1 |
652 | if (byte1 < f->min_byte1 || byte1 > f->max_byte1 |
621 | || byte2 < f->min_char_or_byte2 || byte2 > f->max_char_or_byte2) |
653 | || byte2 < f->min_char_or_byte2 || byte2 > f->max_char_or_byte2) |
622 | return false; |
654 | return false; |
623 | |
655 | |
… | |
… | |
646 | |
678 | |
647 | return true; |
679 | return true; |
648 | } |
680 | } |
649 | |
681 | |
650 | void |
682 | void |
651 | rxvt_font_x11::draw (int x, int y, |
683 | rxvt_font_x11::draw (rxvt_drawable &d, int x, int y, |
652 | const text_t *text, int len, |
684 | const text_t *text, int len, |
653 | int fg, int bg) |
685 | int fg, int bg) |
654 | { |
686 | { |
655 | // this looks like a mess /. |
687 | // this looks like a mess /. |
656 | // and it is a mess /. |
688 | // and it is a mess /. |
… | |
… | |
672 | { |
704 | { |
673 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
705 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
674 | |
706 | |
675 | if (bg == Color_bg && !slow) |
707 | if (bg == Color_bg && !slow) |
676 | { |
708 | { |
677 | XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); |
709 | XChangeGC (d.display->display, GC, GCForeground | GCBackground | GCFont, &v); |
678 | XDrawImageString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
710 | XDrawImageString16 (d.display->display, d, GC, x, y + base, xc, len); |
679 | } |
711 | } |
680 | else |
712 | else |
681 | { |
713 | { |
682 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
714 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
683 | |
715 | |
684 | XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); |
716 | XChangeGC (d.display->display, GC, GCForeground | GCFont, &v); |
685 | |
717 | |
686 | if (slow) |
718 | if (slow) |
687 | { |
719 | { |
688 | do |
720 | do |
689 | { |
721 | { |
690 | if (xc->byte1 || xc->byte2) |
722 | if (xc->byte1 || xc->byte2) |
691 | XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); |
723 | XDrawString16 (d.display->display, d, GC, x, y + base, xc, 1); |
692 | |
724 | |
693 | x += r->TermWin.fwidth; |
725 | x += r->TermWin.fwidth; |
694 | xc++; len--; |
726 | xc++; len--; |
695 | } |
727 | } |
696 | while (len); |
728 | while (len); |
697 | } |
729 | } |
698 | else |
730 | else |
699 | XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
731 | XDrawString16 (d.display->display, d, GC, x, y + base, xc, len); |
700 | } |
732 | } |
701 | } |
733 | } |
702 | else |
734 | else |
703 | { |
735 | { |
704 | const char *xc = enc_char (text, len, cs, slow); |
736 | const char *xc = enc_char (text, len, cs, slow); |
705 | |
737 | |
706 | if (bg == Color_bg && !slow) |
738 | if (bg == Color_bg && !slow) |
707 | { |
739 | { |
708 | XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); |
740 | XChangeGC (d.display->display, GC, GCForeground | GCBackground | GCFont, &v); |
709 | XDrawImageString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
741 | XDrawImageString (d.display->display, d, GC, x, y + base, xc, len); |
710 | } |
742 | } |
711 | else |
743 | else |
712 | { |
744 | { |
713 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
745 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
714 | |
746 | |
715 | XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); |
747 | XChangeGC (d.display->display, GC, GCForeground | GCFont, &v); |
716 | |
748 | |
717 | if (slow) |
749 | if (slow) |
718 | { |
750 | { |
719 | do |
751 | do |
720 | { |
752 | { |
721 | if (*xc) |
753 | if (*xc) |
722 | XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); |
754 | XDrawString (d.display->display, d, GC, x, y + base, xc, 1); |
723 | |
755 | |
724 | x += r->TermWin.fwidth; |
756 | x += r->TermWin.fwidth; |
725 | xc++; len--; |
757 | xc++; len--; |
726 | } |
758 | } |
727 | while (len); |
759 | while (len); |
728 | } |
760 | } |
729 | else |
761 | else |
730 | XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
762 | XDrawString (d.display->display, d, GC, x, y + base, xc, len); |
731 | } |
763 | } |
732 | } |
764 | } |
733 | } |
765 | } |
734 | |
766 | |
735 | ///////////////////////////////////////////////////////////////////////////// |
767 | ///////////////////////////////////////////////////////////////////////////// |
… | |
… | |
740 | //#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables |
772 | //#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables |
741 | #define SWATHBITS 8 |
773 | #define SWATHBITS 8 |
742 | #endif |
774 | #endif |
743 | |
775 | |
744 | struct rxvt_font_xft : rxvt_font { |
776 | struct rxvt_font_xft : rxvt_font { |
745 | rxvt_font_xft () { f = 0; d = 0; } |
777 | rxvt_font_xft () { f = 0; } |
746 | |
778 | |
747 | void clear (); |
779 | void clear (); |
748 | |
780 | |
749 | rxvt_fontprop properties (); |
781 | rxvt_fontprop properties (); |
750 | |
782 | |
751 | bool load (const rxvt_fontprop &prop); |
783 | bool load (const rxvt_fontprop &prop); |
752 | |
784 | |
753 | void draw (int x, int y, |
785 | void draw (rxvt_drawable &d, int x, int y, |
754 | const text_t *text, int len, |
786 | const text_t *text, int len, |
755 | int fg, int bg); |
787 | int fg, int bg); |
756 | |
788 | |
757 | bool has_codepoint (uint32_t unicode); |
789 | bool has_codepoint (uint32_t unicode); |
758 | |
790 | |
759 | protected: |
791 | protected: |
760 | XftFont *f; |
792 | XftFont *f; |
761 | XftDraw *d; |
|
|
762 | }; |
793 | }; |
763 | |
794 | |
764 | void |
795 | void |
765 | rxvt_font_xft::clear () |
796 | rxvt_font_xft::clear () |
766 | { |
797 | { |
767 | if (f) |
798 | if (f) |
768 | { |
799 | { |
769 | XftFontClose (DISPLAY, f); |
800 | XftFontClose (DISPLAY, f); |
770 | f = 0; |
801 | f = 0; |
771 | } |
|
|
772 | |
|
|
773 | if (d) |
|
|
774 | { |
|
|
775 | XftDrawDestroy (d); |
|
|
776 | d = 0; |
|
|
777 | } |
802 | } |
778 | } |
803 | } |
779 | |
804 | |
780 | rxvt_fontprop |
805 | rxvt_fontprop |
781 | rxvt_font_xft::properties () |
806 | rxvt_font_xft::properties () |
… | |
… | |
888 | { |
913 | { |
889 | return XftCharExists (DISPLAY, f, unicode); |
914 | return XftCharExists (DISPLAY, f, unicode); |
890 | } |
915 | } |
891 | |
916 | |
892 | void |
917 | void |
893 | rxvt_font_xft::draw (int x, int y, |
918 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
894 | const text_t *text, int len, |
919 | const text_t *text, int len, |
895 | int fg, int bg) |
920 | int fg, int bg) |
896 | { |
921 | { |
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); |
922 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
907 | |
923 | |
908 | if (!slow && width == r->TermWin.fwidth && 0) |
924 | if (!slow && width == r->TermWin.fwidth && 0) |
909 | { |
925 | { |
910 | if (sizeof (text_t) == sizeof (FcChar16)) |
926 | if (sizeof (text_t) == sizeof (FcChar16)) |
911 | XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); |
927 | XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); |
… | |
… | |
923 | fwidth *= 2; |
939 | fwidth *= 2; |
924 | |
940 | |
925 | XGlyphInfo extents; |
941 | XGlyphInfo extents; |
926 | if (sizeof (text_t) == sizeof (FcChar16)) |
942 | if (sizeof (text_t) == sizeof (FcChar16)) |
927 | { |
943 | { |
928 | XftTextExtents16 (DISPLAY, f, (const FcChar16 *)text, 1, &extents); |
944 | 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, |
945 | XftDrawString16 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2, |
930 | y + r->TermWin.fbase, (const FcChar16 *)text, 1); |
946 | y + r->TermWin.fbase, (const FcChar16 *)text, 1); |
931 | } |
947 | } |
932 | else |
948 | else |
933 | { |
949 | { |
934 | XGlyphInfo extents; |
950 | XGlyphInfo extents; |
935 | XftTextExtents32 (DISPLAY, f, (const FcChar32 *)text, 1, &extents); |
951 | 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, |
952 | XftDrawString32 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2, |
937 | y + r->TermWin.fbase, (const FcChar32 *)text, 1); |
953 | y + r->TermWin.fbase, (const FcChar32 *)text, 1); |
938 | } |
954 | } |
939 | } |
955 | } |
940 | |
956 | |
… | |
… | |
947 | #endif |
963 | #endif |
948 | |
964 | |
949 | ///////////////////////////////////////////////////////////////////////////// |
965 | ///////////////////////////////////////////////////////////////////////////// |
950 | |
966 | |
951 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
967 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
952 | #ifdef EXPLICIT_CONTEXT |
|
|
953 | : r(r) |
968 | : r (r) |
954 | #endif |
|
|
955 | { |
969 | { |
956 | clear (); |
970 | clear (); |
957 | } |
971 | } |
958 | |
972 | |
959 | rxvt_fontset::~rxvt_fontset () |
973 | rxvt_fontset::~rxvt_fontset () |
… | |
… | |
962 | } |
976 | } |
963 | |
977 | |
964 | void |
978 | void |
965 | rxvt_fontset::clear () |
979 | rxvt_fontset::clear () |
966 | { |
980 | { |
967 | for (rxvt_font **i = fonts.begin (); i != fonts.end(); i++) |
981 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
968 | FONT_UNREF (*i); |
982 | FONT_UNREF (*i); |
969 | |
983 | |
970 | fonts.clear (); |
984 | fonts.clear (); |
971 | base_id = 0; |
985 | base_id = 0; |
972 | base_prop.height = 0x7fffffff; |
986 | base_prop.height = 0x7fffffff; |
… | |
… | |
1026 | |
1040 | |
1027 | if (*desc == '[') |
1041 | if (*desc == '[') |
1028 | { |
1042 | { |
1029 | fprintf (stderr, "extra font parameters not yet supported, skipping.\n"); |
1043 | fprintf (stderr, "extra font parameters not yet supported, skipping.\n"); |
1030 | |
1044 | |
1031 | const char *extra = desc++; |
1045 | //const char *extra = desc++; // not yet used |
1032 | |
1046 | |
1033 | desc = strchr (desc, ']'); |
1047 | desc = strchr (desc, ']'); |
1034 | |
1048 | |
1035 | if (!desc) |
1049 | if (!desc) |
1036 | { |
1050 | { |
… | |
… | |
1075 | } |
1089 | } |
1076 | |
1090 | |
1077 | return true; |
1091 | return true; |
1078 | } |
1092 | } |
1079 | |
1093 | |
1080 | void |
1094 | bool |
1081 | rxvt_fontset::populate (const char *desc) |
1095 | rxvt_fontset::populate (const char *desc) |
1082 | { |
1096 | { |
1083 | clear (); |
1097 | clear (); |
1084 | |
1098 | |
1085 | fonts.push_back (new_font (0, CS_UNICODE)); |
1099 | fonts.push_back (new_font (0, CS_UNICODE)); |
… | |
… | |
1089 | |
1103 | |
1090 | if (!base_id) |
1104 | if (!base_id) |
1091 | base_id = 1; |
1105 | base_id = 1; |
1092 | |
1106 | |
1093 | // we currently need a base-font, no matter what |
1107 | // we currently need a base-font, no matter what |
1094 | if (fonts.size () <= base_id || !realize_font (base_id)) |
1108 | if ((int)fonts.size () <= base_id || !realize_font (base_id)) |
1095 | { |
1109 | { |
1096 | puts ("unable to load specified font(s), falling back to 'fixed'\n"); |
1110 | puts ("unable to load specified font (s), falling back to 'fixed'\n"); |
1097 | add_fonts ("fixed"); |
1111 | add_fonts ("fixed"); |
1098 | base_id = fonts.size () - 1; |
1112 | base_id = fonts.size () - 1; |
1099 | } |
1113 | } |
1100 | |
1114 | |
1101 | if (fonts.size () <= base_id || !realize_font (base_id)) |
1115 | if ((int)fonts.size () <= base_id || !realize_font (base_id)) |
1102 | { |
1116 | return false; |
1103 | fprintf (stderr, "unable to load a base font, please provide one using -fn fontname\n"); |
|
|
1104 | exit (1); |
|
|
1105 | } |
|
|
1106 | |
1117 | |
1107 | base_prop = fonts[base_id]->properties (); |
1118 | base_prop = fonts[base_id]->properties (); |
|
|
1119 | |
|
|
1120 | return true; |
1108 | } |
1121 | } |
1109 | |
1122 | |
1110 | int |
1123 | int |
1111 | rxvt_fontset::find_font (uint32_t unicode) |
1124 | rxvt_fontset::find_font (uint32_t unicode) |
1112 | { |
1125 | { |
1113 | for (int i = 0; i < fonts.size (); i++) |
1126 | for (unsigned int i = 0; i < fonts.size (); i++) |
1114 | { |
1127 | { |
1115 | rxvt_font *f = fonts[i]; |
1128 | rxvt_font *f = fonts[i]; |
1116 | |
1129 | |
1117 | if (!f->loaded) |
1130 | if (!f->loaded) |
1118 | { |
1131 | { |