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