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.1 by pcg, Mon Nov 24 17:28:08 2003 UTC vs.
Revision 1.2 by pcg, Tue Nov 25 15:25:17 2003 UTC

21 21
22#include "../config.h" 22#include "../config.h"
23#include "rxvt.h" 23#include "rxvt.h"
24#include "defaultfont.h" 24#include "defaultfont.h"
25 25
26#define DISPLAY R->Xdisplay 26#define DISPLAY r->Xdisplay
27#define DRAWABLE R->TermWin.vt 27#define DRAWABLE r->TermWin.vt
28#define GC R->TermWin.gc 28#define GC r->TermWin.gc
29 29
30const struct rxvt_fallback_font { 30const struct rxvt_fallback_font {
31 codeset cs; 31 codeset cs;
32 const char *name; 32 const char *name;
33} fallback_fonts[] = { 33} fallback_fonts[] = {
163{ 163{
164 if (color == Color_bg) 164 if (color == Color_bg)
165 XClearArea (DISPLAY, DRAWABLE, x, y, w, h, FALSE); 165 XClearArea (DISPLAY, DRAWABLE, x, y, w, h, FALSE);
166 else if (color >= 0) 166 else if (color >= 0)
167 { 167 {
168 XSetForeground (DISPLAY, GC, R->PixColors[color]); 168 XSetForeground (DISPLAY, GC, r->PixColors[color]);
169 XFillRectangle (DISPLAY, DRAWABLE, GC, x, y, w, h); 169 XFillRectangle (DISPLAY, DRAWABLE, GC, x, y, w, h);
170 } 170 }
171} 171}
172 172
173struct rxvt_font_default : rxvt_font { 173struct rxvt_font_default : rxvt_font {
202void 202void
203rxvt_font_default::draw (int x, int y, 203rxvt_font_default::draw (int x, int y,
204 const text_t *text, int len, 204 const text_t *text, int len,
205 int fg, int bg) 205 int fg, int bg)
206{ 206{
207 clear_rect (x, y, R->TermWin.fwidth * len, R->TermWin.fheight, bg); 207 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
208 208
209 while (len--) 209 while (len--)
210 { 210 {
211 switch (*text++) 211 switch (*text++)
212 { 212 {
213 case NOCHAR: 213 case NOCHAR:
214 case ZERO_WIDTH_CHAR: 214 case ZERO_WIDTH_CHAR:
215 break; 215 break;
216 default: 216 default:
217 XSetForeground (DISPLAY, GC, R->PixColors[fg]); 217 XSetForeground (DISPLAY, GC, r->PixColors[fg]);
218 XDrawRectangle (DISPLAY, DRAWABLE, GC, x + 2, y + 2, R->TermWin.fwidth - 5, R->TermWin.fheight - 5); 218 XDrawRectangle (DISPLAY, DRAWABLE, GC, x + 2, y + 2, r->TermWin.fwidth - 5, r->TermWin.fheight - 5);
219 } 219 }
220 220
221 x += R->TermWin.fwidth; 221 x += r->TermWin.fwidth;
222 } 222 }
223} 223}
224 224
225///////////////////////////////////////////////////////////////////////////// 225/////////////////////////////////////////////////////////////////////////////
226 226
404 // and it is a mess /. 404 // and it is a mess /.
405 // yet we are trying to be perfect /. 405 // yet we are trying to be perfect /.
406 // but the result still isn't perfect /. 406 // but the result still isn't perfect /.
407 407
408 bool slow = prop 408 bool slow = prop
409 || width != R->TermWin.fwidth 409 || width != r->TermWin.fwidth
410 || height != R->TermWin.fheight; 410 || height != r->TermWin.fheight;
411 411
412 int base = R->TermWin.fbase; 412 int base = r->TermWin.fbase;
413 413
414 XGCValues v; 414 XGCValues v;
415 v.foreground = R->PixColors[fg]; 415 v.foreground = r->PixColors[fg];
416 v.background = R->PixColors[bg]; 416 v.background = r->PixColors[bg];
417 v.font = f->fid; 417 v.font = f->fid;
418 418
419 if (enc2b) 419 if (enc2b)
420 { 420 {
421 const XChar2b *xc = enc_xchar2b (text, len, cs, slow); 421 const XChar2b *xc = enc_xchar2b (text, len, cs, slow);
425 XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); 425 XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v);
426 XDrawImageString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); 426 XDrawImageString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len);
427 } 427 }
428 else 428 else
429 { 429 {
430 clear_rect (x, y, R->TermWin.fwidth * len, R->TermWin.fheight, bg); 430 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
431 431
432 XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); 432 XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v);
433 433
434 if (slow) 434 if (slow)
435 { 435 {
436 do 436 do
437 { 437 {
438 if (xc->byte1 || xc->byte2) 438 if (xc->byte1 || xc->byte2)
439 XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); 439 XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1);
440 440
441 x += R->TermWin.fwidth; 441 x += r->TermWin.fwidth;
442 xc++; len--; 442 xc++; len--;
443 } 443 }
444 while (len); 444 while (len);
445 } 445 }
446 else 446 else
456 XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); 456 XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v);
457 XDrawImageString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); 457 XDrawImageString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len);
458 } 458 }
459 else 459 else
460 { 460 {
461 clear_rect (x, y, R->TermWin.fwidth * len, R->TermWin.fheight, bg); 461 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
462 462
463 XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); 463 XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v);
464 464
465 if (slow) 465 if (slow)
466 { 466 {
467 do 467 do
468 { 468 {
469 if (*xc) 469 if (*xc)
470 XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); 470 XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1);
471 471
472 x += R->TermWin.fwidth; 472 x += r->TermWin.fwidth;
473 xc++; len--; 473 xc++; len--;
474 } 474 }
475 while (len); 475 while (len);
476 } 476 }
477 else 477 else
544void 544void
545rxvt_font_xft::clear () 545rxvt_font_xft::clear ()
546{ 546{
547 if (f) 547 if (f)
548 { 548 {
549 XftFontClose (R->Xdisplay, f); 549 XftFontClose (DISPLAY, f);
550 f = 0; 550 f = 0;
551 } 551 }
552 552
553 if (d) 553 if (d)
554 { 554 {
570 cvr[i] = 0; 570 cvr[i] = 0;
571#endif 571#endif
572 572
573 clear (); 573 clear ();
574 574
575 f = XftFontOpenName (R->Xdisplay, DefaultScreen (R->Xdisplay), name); 575 f = XftFontOpenName (DISPLAY, DefaultScreen (DISPLAY), name);
576 576
577 if (!f) 577 if (!f)
578 return false; 578 return false;
579 579
580 FT_Face face = XftLockFace (f); 580 FT_Face face = XftLockFace (f);
586 for (;;) 586 for (;;)
587 { 587 {
588 XGlyphInfo g1, g2; 588 XGlyphInfo g1, g2;
589 FcChar8 c; 589 FcChar8 c;
590 590
591 c = 'i'; XftTextExtents8 (R->Xdisplay, f, &c, 1, &g1); 591 c = 'i'; XftTextExtents8 (DISPLAY, f, &c, 1, &g1);
592 c = 'W'; XftTextExtents8 (R->Xdisplay, f, &c, 1, &g2); 592 c = 'W'; XftTextExtents8 (DISPLAY, f, &c, 1, &g2);
593 593
594 prop = prop || g1.xOff != g2.xOff; // don't simply trust the font 594 prop = prop || g1.xOff != g2.xOff; // don't simply trust the font
595 595
596 width = g2.xOff; 596 width = g2.xOff;
597 ascent = (face->size->metrics.ascender + 63) >> 6; 597 ascent = (face->size->metrics.ascender + 63) >> 6;
632#endif 632#endif
633 633
634bool 634bool
635rxvt_font_xft::has_codepoint (uint32_t unicode) 635rxvt_font_xft::has_codepoint (uint32_t unicode)
636{ 636{
637 return XftCharExists (R->Xdisplay, f, unicode); 637 return XftCharExists (DISPLAY, f, unicode);
638} 638}
639 639
640void 640void
641rxvt_font_xft::draw (int x, int y, 641rxvt_font_xft::draw (int x, int y,
642 const text_t *text, int len, 642 const text_t *text, int len,
643 int fg, int bg) 643 int fg, int bg)
644{ 644{
645 if (!d) 645 if (!d)
646 {
647 dR;
646 d = XftDrawCreate (R->Xdisplay, DRAWABLE, XVISUAL, XCMAP); 648 d = XftDrawCreate (DISPLAY, DRAWABLE, XVISUAL, XCMAP);
649 }
647 650
648 if (bg >= 0 && bg != Color_bg) 651 if (bg >= 0 && bg != Color_bg)
649 XftDrawRect (d, &R->PixColors[bg].c, x, y, R->TermWin.fwidth * len, R->TermWin.fheight); 652 XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight);
650 else 653 else
651 clear_rect (x, y, R->TermWin.fwidth * len, R->TermWin.fheight, bg); 654 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
652 655
653 if (!prop && width == R->TermWin.fwidth) 656 if (!prop && width == r->TermWin.fwidth)
654 { 657 {
655 if (sizeof (text_t) == sizeof (FcChar16)) 658 if (sizeof (text_t) == sizeof (FcChar16))
656 XftDrawString16 (d, &R->PixColors[fg].c, f, x, y + R->TermWin.fbase, (const FcChar16 *)text, len); 659 XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len);
657 else 660 else
658 XftDrawString32 (d, &R->PixColors[fg].c, f, x, y + R->TermWin.fbase, (const FcChar32 *)text, len); 661 XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, len);
659 } 662 }
660 else 663 else
661 { 664 {
662 while (len) 665 while (len)
663 { 666 {
664 if (*text != NOCHAR && *text != ' ') 667 if (*text != NOCHAR && *text != ' ')
665 { 668 {
666 if (sizeof (text_t) == sizeof (FcChar16)) 669 if (sizeof (text_t) == sizeof (FcChar16))
667 XftDrawString16 (d, &R->PixColors[fg].c, f, x, y + R->TermWin.fbase, (const FcChar16 *)text, 1); 670 XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, 1);
668 else 671 else
669 XftDrawString32 (d, &R->PixColors[fg].c, f, x, y + R->TermWin.fbase, (const FcChar32 *)text, 1); 672 XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, 1);
670 } 673 }
671 674
672 x += R->TermWin.fwidth; 675 x += r->TermWin.fwidth;
673 text++; 676 text++;
674 len--; 677 len--;
675 } 678 }
676 } 679 }
677} 680}
678#endif 681#endif
679 682
680///////////////////////////////////////////////////////////////////////////// 683/////////////////////////////////////////////////////////////////////////////
681 684
682rxvt_fontset::rxvt_fontset (pR) 685rxvt_fontset::rxvt_fontset (rxvt_t r)
683#ifdef EXPLICIT_CONTEXT 686#ifdef EXPLICIT_CONTEXT
684: rxvt_term(R) 687: r(r)
685#endif 688#endif
686{ 689{
687 clear (); 690 clear ();
688} 691}
689 692
728 f = new rxvt_font_x11; 731 f = new rxvt_font_x11;
729 } 732 }
730 else 733 else
731 f = new rxvt_font_x11; 734 f = new rxvt_font_x11;
732 735
733 f->set_term (aR); 736 f->set_term (r);
734 f->set_name (strdup (name)); 737 f->set_name (strdup (name));
735 738
736 f->cs = cs; 739 f->cs = cs;
737 f->loaded = false; 740 f->loaded = false;
738 741

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines