… | |
… | |
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; |
… | |
… | |
99 | { CS_UNKNOWN, 0 } |
98 | { CS_UNKNOWN, 0 } |
100 | }; |
99 | }; |
101 | |
100 | |
102 | ///////////////////////////////////////////////////////////////////////////// |
101 | ///////////////////////////////////////////////////////////////////////////// |
103 | |
102 | |
|
|
103 | #if XFT |
|
|
104 | rxvt_drawable::~rxvt_drawable () |
|
|
105 | { |
|
|
106 | if (xftdrawable) |
|
|
107 | XftDrawDestroy (xftdrawable); |
|
|
108 | } |
|
|
109 | |
|
|
110 | rxvt_drawable::operator XftDraw *() |
|
|
111 | { |
|
|
112 | if (!xftdrawable) |
|
|
113 | xftdrawable = XftDrawCreate (display->display, drawable, display->visual, display->cmap); |
|
|
114 | |
|
|
115 | return xftdrawable; |
|
|
116 | } |
|
|
117 | #endif |
|
|
118 | |
|
|
119 | ///////////////////////////////////////////////////////////////////////////// |
|
|
120 | |
104 | static void *enc_buf; |
121 | static void *enc_buf; |
105 | static uint32_t enc_len; |
122 | static uint32_t enc_len; |
106 | |
123 | |
107 | static inline void * |
124 | static inline void * |
108 | get_enc_buf (uint32_t len) |
125 | get_enc_buf (uint32_t len) |
… | |
… | |
161 | } |
178 | } |
162 | |
179 | |
163 | ///////////////////////////////////////////////////////////////////////////// |
180 | ///////////////////////////////////////////////////////////////////////////// |
164 | |
181 | |
165 | void |
182 | void |
166 | rxvt_font::clear_rect (int x, int y, int w, int h, int color) |
183 | rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) |
167 | { |
184 | { |
168 | if (color == Color_bg) |
185 | if (color == Color_bg) |
169 | XClearArea (DISPLAY, DRAWABLE, x, y, w, h, FALSE); |
186 | XClearArea (d.display->display, d, x, y, w, h, FALSE); |
170 | else if (color >= 0) |
187 | else if (color >= 0) |
171 | { |
188 | { |
|
|
189 | #if XFT |
|
|
190 | XftDrawRect (d, &r->PixColors[color].c, x, y, w, h); |
|
|
191 | #else |
172 | XSetForeground (DISPLAY, GC, r->PixColors[color]); |
192 | XSetForeground (d.display->display, GC, r->PixColors[color]); |
173 | XFillRectangle (DISPLAY, DRAWABLE, GC, x, y, w, h); |
193 | XFillRectangle (d.display->display, d, GC, x, y, w, h); |
|
|
194 | #endif |
174 | } |
195 | } |
175 | } |
196 | } |
176 | |
197 | |
177 | static const char *linedraw_cmds[128] = { |
198 | static const char *linedraw_cmds[128] = { |
178 | "1hH", "2hH", "1vV", "2vV", |
199 | "1hH", "2hH", "1vV", "2vV", |
… | |
… | |
263 | } |
284 | } |
264 | |
285 | |
265 | return false; |
286 | return false; |
266 | } |
287 | } |
267 | |
288 | |
268 | void draw (int x, int y, |
289 | void draw (rxvt_drawable &d, int x, int y, |
269 | const text_t *text, int len, |
290 | const text_t *text, int len, |
270 | int fg, int bg); |
291 | int fg, int bg); |
271 | }; |
292 | }; |
272 | |
293 | |
273 | void |
294 | void |
274 | rxvt_font_default::draw (int x, int y, |
295 | rxvt_font_default::draw (rxvt_drawable &d, int x, int y, |
275 | const text_t *text, int len, |
296 | const text_t *text, int len, |
276 | int fg, int bg) |
297 | int fg, int bg) |
277 | { |
298 | { |
278 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
299 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
279 | |
300 | |
280 | XSetForeground (DISPLAY, GC, r->PixColors[fg]); |
301 | XSetForeground (d.display->display, GC, r->PixColors[fg]); |
281 | |
302 | |
282 | while (len--) |
303 | while (len--) |
283 | { |
304 | { |
284 | text_t t = *text++; |
305 | text_t t = *text++; |
285 | |
306 | |
286 | if (t >= 0x2500 & t <= 0x2580 && linedraw_cmds[t - 0x2500]) |
307 | if (t >= 0x2500 & t <= 0x2580 && linedraw_cmds[t - 0x2500]) |
287 | { |
308 | { |
288 | const char *p = linedraw_cmds[t - 0x2500]; |
309 | const char *p = linedraw_cmds[t - 0x2500]; |
289 | |
310 | |
290 | int x0 = x, x1 = x + r->TermWin.fwidth / 2, x2 = x + r->TermWin.fwidth ; |
311 | int x0 = x, x1 = x + r->TermWin.fwidth / 2, x2 = x + r->TermWin.fwidth - 1; |
291 | int y0 = y, y1 = y + r->TermWin.fheight / 2, y2 = y + r->TermWin.fheight; |
312 | int y0 = y, y1 = y + r->TermWin.fheight / 2, y2 = y + r->TermWin.fheight - 1; |
292 | |
313 | |
293 | XGCValues gcv; |
314 | XGCValues gcv; |
294 | |
315 | |
295 | while (*p) |
316 | while (*p) |
296 | { |
317 | { |
297 | switch (*p++) |
318 | switch (*p++) |
298 | { |
319 | { |
299 | case '1': |
320 | case '1': |
300 | gcv.line_width = 0; |
321 | gcv.line_width = 0; |
301 | XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
322 | XChangeGC (d.display->display, GC, GCLineWidth, &gcv); |
302 | break; |
323 | break; |
303 | |
324 | |
304 | case '2': |
325 | case '2': |
305 | gcv.line_width = 2; |
326 | gcv.line_width = 2; |
306 | XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
327 | XChangeGC (d.display->display, GC, GCLineWidth, &gcv); |
307 | break; |
328 | break; |
308 | |
329 | |
309 | case 'h': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y1, x1, y1); break; |
330 | case 'h': XDrawLine (d.display->display, d, GC, x0, y1, x1, y1); break; |
310 | case 'H': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y1, x2, y1); break; |
331 | case 'H': XDrawLine (d.display->display, d, GC, x1, y1, x2, y1); break; |
311 | case 'v': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y0, x1, y1); break; |
332 | case 'v': XDrawLine (d.display->display, d, GC, x1, y0, x1, y1); break; |
312 | case 'V': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y1, x1, y2); break; |
333 | case 'V': XDrawLine (d.display->display, d, GC, x1, y1, x1, y2); break; |
313 | case 'a': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y2, x2, y0); break; |
334 | case 'a': XDrawLine (d.display->display, d, GC, x0, y2, x2, y0); break; |
314 | case 'b': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y0, x2, y2); break; |
335 | case 'b': XDrawLine (d.display->display, d, GC, x0, y0, x2, y2); break; |
315 | } |
336 | } |
316 | } |
337 | } |
317 | |
338 | |
318 | gcv.line_width = 0; |
339 | gcv.line_width = 0; |
319 | XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
340 | XChangeGC (d.display->display, GC, GCLineWidth, &gcv); |
320 | } |
341 | } |
321 | else |
342 | else |
322 | switch (*text++) |
343 | switch (*text++) |
323 | { |
344 | { |
324 | case NOCHAR: |
345 | case NOCHAR: |
325 | case ZERO_WIDTH_CHAR: |
346 | case ZERO_WIDTH_CHAR: |
326 | break; |
347 | break; |
327 | default: |
348 | default: |
328 | XDrawRectangle (DISPLAY, DRAWABLE, GC, x + 2, y + 2, r->TermWin.fwidth - 5, r->TermWin.fheight - 5); |
349 | XDrawRectangle (d.display->display, d, GC, x + 2, y + 2, r->TermWin.fwidth - 5, r->TermWin.fheight - 5); |
329 | } |
350 | } |
330 | |
351 | |
331 | x += r->TermWin.fwidth; |
352 | x += r->TermWin.fwidth; |
332 | } |
353 | } |
333 | } |
354 | } |
… | |
… | |
343 | |
364 | |
344 | bool load (const rxvt_fontprop &prop); |
365 | bool load (const rxvt_fontprop &prop); |
345 | |
366 | |
346 | bool has_codepoint (uint32_t unicode); |
367 | bool has_codepoint (uint32_t unicode); |
347 | |
368 | |
348 | void draw (int x, int y, |
369 | void draw (rxvt_drawable &d, int x, int y, |
349 | const text_t *text, int len, |
370 | const text_t *text, int len, |
350 | int fg, int bg); |
371 | int fg, int bg); |
351 | |
372 | |
352 | XFontStruct *f; |
373 | XFontStruct *f; |
353 | codeset cs; |
374 | codeset cs; |
… | |
… | |
644 | |
665 | |
645 | return true; |
666 | return true; |
646 | } |
667 | } |
647 | |
668 | |
648 | void |
669 | void |
649 | rxvt_font_x11::draw (int x, int y, |
670 | rxvt_font_x11::draw (rxvt_drawable &d, int x, int y, |
650 | const text_t *text, int len, |
671 | const text_t *text, int len, |
651 | int fg, int bg) |
672 | int fg, int bg) |
652 | { |
673 | { |
653 | // this looks like a mess /. |
674 | // this looks like a mess /. |
654 | // and it is a mess /. |
675 | // and it is a mess /. |
… | |
… | |
670 | { |
691 | { |
671 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
692 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
672 | |
693 | |
673 | if (bg == Color_bg && !slow) |
694 | if (bg == Color_bg && !slow) |
674 | { |
695 | { |
675 | XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); |
696 | XChangeGC (d.display->display, GC, GCForeground | GCBackground | GCFont, &v); |
676 | XDrawImageString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
697 | XDrawImageString16 (d.display->display, d, GC, x, y + base, xc, len); |
677 | } |
698 | } |
678 | else |
699 | else |
679 | { |
700 | { |
680 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
701 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
681 | |
702 | |
682 | XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); |
703 | XChangeGC (d.display->display, GC, GCForeground | GCFont, &v); |
683 | |
704 | |
684 | if (slow) |
705 | if (slow) |
685 | { |
706 | { |
686 | do |
707 | do |
687 | { |
708 | { |
688 | if (xc->byte1 || xc->byte2) |
709 | if (xc->byte1 || xc->byte2) |
689 | XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); |
710 | XDrawString16 (d.display->display, d, GC, x, y + base, xc, 1); |
690 | |
711 | |
691 | x += r->TermWin.fwidth; |
712 | x += r->TermWin.fwidth; |
692 | xc++; len--; |
713 | xc++; len--; |
693 | } |
714 | } |
694 | while (len); |
715 | while (len); |
695 | } |
716 | } |
696 | else |
717 | else |
697 | XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
718 | XDrawString16 (d.display->display, d, GC, x, y + base, xc, len); |
698 | } |
719 | } |
699 | } |
720 | } |
700 | else |
721 | else |
701 | { |
722 | { |
702 | const char *xc = enc_char (text, len, cs, slow); |
723 | const char *xc = enc_char (text, len, cs, slow); |
703 | |
724 | |
704 | if (bg == Color_bg && !slow) |
725 | if (bg == Color_bg && !slow) |
705 | { |
726 | { |
706 | XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); |
727 | XChangeGC (d.display->display, GC, GCForeground | GCBackground | GCFont, &v); |
707 | XDrawImageString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
728 | XDrawImageString (d.display->display, d, GC, x, y + base, xc, len); |
708 | } |
729 | } |
709 | else |
730 | else |
710 | { |
731 | { |
711 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
732 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
712 | |
733 | |
713 | XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); |
734 | XChangeGC (d.display->display, GC, GCForeground | GCFont, &v); |
714 | |
735 | |
715 | if (slow) |
736 | if (slow) |
716 | { |
737 | { |
717 | do |
738 | do |
718 | { |
739 | { |
719 | if (*xc) |
740 | if (*xc) |
720 | XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); |
741 | XDrawString (d.display->display, d, GC, x, y + base, xc, 1); |
721 | |
742 | |
722 | x += r->TermWin.fwidth; |
743 | x += r->TermWin.fwidth; |
723 | xc++; len--; |
744 | xc++; len--; |
724 | } |
745 | } |
725 | while (len); |
746 | while (len); |
726 | } |
747 | } |
727 | else |
748 | else |
728 | XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
749 | XDrawString (d.display->display, d, GC, x, y + base, xc, len); |
729 | } |
750 | } |
730 | } |
751 | } |
731 | } |
752 | } |
732 | |
753 | |
733 | ///////////////////////////////////////////////////////////////////////////// |
754 | ///////////////////////////////////////////////////////////////////////////// |
… | |
… | |
738 | //#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables |
759 | //#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables |
739 | #define SWATHBITS 8 |
760 | #define SWATHBITS 8 |
740 | #endif |
761 | #endif |
741 | |
762 | |
742 | struct rxvt_font_xft : rxvt_font { |
763 | struct rxvt_font_xft : rxvt_font { |
743 | rxvt_font_xft () { f = 0; d = 0; } |
764 | rxvt_font_xft () { f = 0; } |
744 | |
765 | |
745 | void clear (); |
766 | void clear (); |
746 | |
767 | |
747 | rxvt_fontprop properties (); |
768 | rxvt_fontprop properties (); |
748 | |
769 | |
749 | bool load (const rxvt_fontprop &prop); |
770 | bool load (const rxvt_fontprop &prop); |
750 | |
771 | |
751 | void draw (int x, int y, |
772 | void draw (rxvt_drawable &d, int x, int y, |
752 | const text_t *text, int len, |
773 | const text_t *text, int len, |
753 | int fg, int bg); |
774 | int fg, int bg); |
754 | |
775 | |
755 | bool has_codepoint (uint32_t unicode); |
776 | bool has_codepoint (uint32_t unicode); |
756 | |
777 | |
757 | protected: |
778 | protected: |
758 | XftFont *f; |
779 | XftFont *f; |
759 | XftDraw *d; |
|
|
760 | }; |
780 | }; |
761 | |
781 | |
762 | void |
782 | void |
763 | rxvt_font_xft::clear () |
783 | rxvt_font_xft::clear () |
764 | { |
784 | { |
765 | if (d) |
|
|
766 | { |
|
|
767 | XftDrawDestroy (d); |
|
|
768 | d = 0; |
|
|
769 | } |
|
|
770 | |
|
|
771 | if (f) |
785 | if (f) |
772 | { |
786 | { |
773 | XftFontClose (DISPLAY, f); |
787 | XftFontClose (DISPLAY, f); |
774 | f = 0; |
788 | f = 0; |
775 | } |
789 | } |
… | |
… | |
886 | { |
900 | { |
887 | return XftCharExists (DISPLAY, f, unicode); |
901 | return XftCharExists (DISPLAY, f, unicode); |
888 | } |
902 | } |
889 | |
903 | |
890 | void |
904 | void |
891 | rxvt_font_xft::draw (int x, int y, |
905 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
892 | const text_t *text, int len, |
906 | const text_t *text, int len, |
893 | int fg, int bg) |
907 | int fg, int bg) |
894 | { |
908 | { |
895 | d = XftDrawCreate (DISPLAY, DRAWABLE, r->display->visual, r->display->cmap); |
|
|
896 | |
|
|
897 | if (bg >= 0 && bg != Color_bg) |
|
|
898 | XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight); |
|
|
899 | else |
|
|
900 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
909 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
901 | |
910 | |
902 | if (!slow && width == r->TermWin.fwidth && 0) |
911 | if (!slow && width == r->TermWin.fwidth && 0) |
903 | { |
912 | { |
904 | if (sizeof (text_t) == sizeof (FcChar16)) |
913 | if (sizeof (text_t) == sizeof (FcChar16)) |
905 | XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); |
914 | XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); |
… | |
… | |
917 | fwidth *= 2; |
926 | fwidth *= 2; |
918 | |
927 | |
919 | XGlyphInfo extents; |
928 | XGlyphInfo extents; |
920 | if (sizeof (text_t) == sizeof (FcChar16)) |
929 | if (sizeof (text_t) == sizeof (FcChar16)) |
921 | { |
930 | { |
922 | XftTextExtents16 (DISPLAY, f, (const FcChar16 *)text, 1, &extents); |
931 | XftTextExtents16 (d.display->display, f, (const FcChar16 *)text, 1, &extents); |
923 | XftDrawString16 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2, |
932 | XftDrawString16 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2, |
924 | y + r->TermWin.fbase, (const FcChar16 *)text, 1); |
933 | y + r->TermWin.fbase, (const FcChar16 *)text, 1); |
925 | } |
934 | } |
926 | else |
935 | else |
927 | { |
936 | { |
928 | XGlyphInfo extents; |
937 | XGlyphInfo extents; |
929 | XftTextExtents32 (DISPLAY, f, (const FcChar32 *)text, 1, &extents); |
938 | XftTextExtents32 (d.display->display, f, (const FcChar32 *)text, 1, &extents); |
930 | XftDrawString32 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2, |
939 | XftDrawString32 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2, |
931 | y + r->TermWin.fbase, (const FcChar32 *)text, 1); |
940 | y + r->TermWin.fbase, (const FcChar32 *)text, 1); |
932 | } |
941 | } |
933 | } |
942 | } |
934 | |
943 | |