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