ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/defaultfont.C
(Generate patch)

Comparing rxvt-unicode/src/defaultfont.C (file contents):
Revision 1.23 by pcg, Sun Feb 22 08:28:36 2004 UTC vs.
Revision 1.24 by pcg, Tue Feb 24 00:44:23 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines