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.4 by pcg, Sat Nov 29 18:42:07 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
173static const char *linedraw_cmds[128] = {
174 "1hH", "2hH", "1vV", "2vV",
175 0, 0, 0, 0,
176 0, 0, 0, 0,
177 "1HV", "2H1V", "1H2V", "2HV",
178
179 // 2510
180 "1hV", "2h1V", "1h2V", "2hV",
181 "1Hv", "2H1v", "1H2v", "2Hv",
182 "1hv", "2h1v", "1h2v", "2hv",
183 "1HvV", "2H1vV", "1HV2v", "1Hv2V",
184
185 // 2520
186 "1H2vV", "2Hv1V", "2HV1v", "2HvV",
187 "1hvV", "2h1vV", "1hV2v", "1hv2V",
188 "1h2vV", "2hv1V", "1v2hV", "2hvV",
189 "1hHV", "2h1HV", "2H1hV", "2hH1V",
190
191 // 2530
192 "1hH2V", "2hV1H", "1h2HV", "2hHV",
193 "1hHv", "1vH2h", "1hv2H", "1v2hH",
194 "1hH2v", "1H2hv", "1h2Hv", "2hHv",
195 "1hHvV", "1vVH2h", "1hvV2H", "1vV2hH",
196
197 // 2540
198 "1hHV2v", "1hHv2V", "1hH2vV", "1HV2hv",
199 "1hV2Hv", "1Hv2hV", "1hv2HV", "1V2hHv",
200 "1v2hHV", "1H2hvV", "1h2HvV", "2hHvV",
201 0, 0, 0, 0,
202
203 // 2550
204 0, 0, 0, 0,
205 0, 0, 0, 0,
206 0, 0, 0, 0,
207 0, 0, 0, 0,
208
209 // 2560
210 0, 0, 0, 0,
211 0, 0, 0, 0,
212 0, 0, 0, 0,
213 0, 0, 0, 0,
214
215 // 2570
216 0, "1a", "1b", "1ab",
217 "1h", "1v", "1H", "1V",
218 "2h", "2v", "2H", "2V",
219 "1h2H", "1v2V", "1H2h", "1V2v"
220
221 // to be done
222};
172 223
173struct rxvt_font_default : rxvt_font { 224struct rxvt_font_default : rxvt_font {
174 bool load (int maxheight) 225 bool load (int maxheight)
175 { 226 {
176 width = 1; height = 1; 227 width = 1; height = 1;
179 return true; 230 return true;
180 } 231 }
181 232
182 bool has_codepoint (uint32_t unicode) 233 bool has_codepoint (uint32_t unicode)
183 { 234 {
184 if (unicode <= 0x001f 235 if (unicode <= 0x001f)
236 return true;
185 || (unicode >= 0x80 && unicode <= 0x9f)) 237 if (unicode >= 0x0080 && unicode <= 0x009f)
238 return true;
239
240 if (unicode >= 0x2500 && unicode <= 0x257f
241 && linedraw_cmds[unicode - 0x2500])
186 return true; 242 return true;
187 243
188 switch (unicode) 244 switch (unicode)
189 { 245 {
190 case ZERO_WIDTH_CHAR: 246 case ZERO_WIDTH_CHAR:
202void 258void
203rxvt_font_default::draw (int x, int y, 259rxvt_font_default::draw (int x, int y,
204 const text_t *text, int len, 260 const text_t *text, int len,
205 int fg, int bg) 261 int fg, int bg)
206{ 262{
207 clear_rect (x, y, R->TermWin.fwidth * len, R->TermWin.fheight, bg); 263 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
264
265 XSetForeground (DISPLAY, GC, r->PixColors[fg]);
208 266
209 while (len--) 267 while (len--)
210 { 268 {
269 text_t t = *text++;
270
271 if (t >= 0x2500 & t <= 0x2580 && linedraw_cmds[t - 0x2500])
272 {
273 const char *p = linedraw_cmds[t - 0x2500];
274
275 int x0 = x, x1 = x + r->TermWin.fwidth / 2, x2 = x + r->TermWin.fwidth ;
276 int y0 = y, y1 = y + r->TermWin.fheight / 2, y2 = y + r->TermWin.fheight;
277
278 XGCValues gcv;
279
280 while (*p)
281 {
282 switch (*p++)
283 {
284 case '1':
285 gcv.line_width = 0;
286 XChangeGC (DISPLAY, GC, GCLineWidth, &gcv);
287 break;
288
289 case '2':
290 gcv.line_width = 2;
291 XChangeGC (DISPLAY, GC, GCLineWidth, &gcv);
292 break;
293
294 case 'h': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y1, x1, y1); break;
295 case 'H': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y1, x2, y1); break;
296 case 'v': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y0, x1, y1); break;
297 case 'V': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y1, x1, y2); break;
298 case 'a': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y2, x2, y0); break;
299 case 'b': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y0, x2, y2); break;
300 }
301 }
302
303 gcv.line_width = 0;
304 XChangeGC (DISPLAY, GC, GCLineWidth, &gcv);
305 }
306 else
211 switch (*text++) 307 switch (*text++)
212 { 308 {
213 case NOCHAR: 309 case NOCHAR:
214 case ZERO_WIDTH_CHAR: 310 case ZERO_WIDTH_CHAR:
215 break; 311 break;
216 default: 312 default:
217 XSetForeground (DISPLAY, GC, R->PixColors[fg]);
218 XDrawRectangle (DISPLAY, DRAWABLE, GC, x + 2, y + 2, R->TermWin.fwidth - 5, R->TermWin.fheight - 5); 313 XDrawRectangle (DISPLAY, DRAWABLE, GC, x + 2, y + 2, r->TermWin.fwidth - 5, r->TermWin.fheight - 5);
219 } 314 }
220 315
221 x += R->TermWin.fwidth; 316 x += r->TermWin.fwidth;
222 } 317 }
223} 318}
224 319
225///////////////////////////////////////////////////////////////////////////// 320/////////////////////////////////////////////////////////////////////////////
226 321
404 // and it is a mess /. 499 // and it is a mess /.
405 // yet we are trying to be perfect /. 500 // yet we are trying to be perfect /.
406 // but the result still isn't perfect /. 501 // but the result still isn't perfect /.
407 502
408 bool slow = prop 503 bool slow = prop
409 || width != R->TermWin.fwidth 504 || width != r->TermWin.fwidth
410 || height != R->TermWin.fheight; 505 || height != r->TermWin.fheight;
411 506
412 int base = R->TermWin.fbase; 507 int base = r->TermWin.fbase;
413 508
414 XGCValues v; 509 XGCValues v;
415 v.foreground = R->PixColors[fg]; 510 v.foreground = r->PixColors[fg];
416 v.background = R->PixColors[bg]; 511 v.background = r->PixColors[bg];
417 v.font = f->fid; 512 v.font = f->fid;
418 513
419 if (enc2b) 514 if (enc2b)
420 { 515 {
421 const XChar2b *xc = enc_xchar2b (text, len, cs, slow); 516 const XChar2b *xc = enc_xchar2b (text, len, cs, slow);
425 XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); 520 XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v);
426 XDrawImageString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); 521 XDrawImageString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len);
427 } 522 }
428 else 523 else
429 { 524 {
430 clear_rect (x, y, R->TermWin.fwidth * len, R->TermWin.fheight, bg); 525 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
431 526
432 XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); 527 XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v);
433 528
434 if (slow) 529 if (slow)
435 { 530 {
436 do 531 do
437 { 532 {
438 if (xc->byte1 || xc->byte2) 533 if (xc->byte1 || xc->byte2)
439 XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); 534 XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1);
440 535
441 x += R->TermWin.fwidth; 536 x += r->TermWin.fwidth;
442 xc++; len--; 537 xc++; len--;
443 } 538 }
444 while (len); 539 while (len);
445 } 540 }
446 else 541 else
456 XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); 551 XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v);
457 XDrawImageString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); 552 XDrawImageString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len);
458 } 553 }
459 else 554 else
460 { 555 {
461 clear_rect (x, y, R->TermWin.fwidth * len, R->TermWin.fheight, bg); 556 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
462 557
463 XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); 558 XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v);
464 559
465 if (slow) 560 if (slow)
466 { 561 {
467 do 562 do
468 { 563 {
469 if (*xc) 564 if (*xc)
470 XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); 565 XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1);
471 566
472 x += R->TermWin.fwidth; 567 x += r->TermWin.fwidth;
473 xc++; len--; 568 xc++; len--;
474 } 569 }
475 while (len); 570 while (len);
476 } 571 }
477 else 572 else
544void 639void
545rxvt_font_xft::clear () 640rxvt_font_xft::clear ()
546{ 641{
547 if (f) 642 if (f)
548 { 643 {
549 XftFontClose (R->Xdisplay, f); 644 XftFontClose (DISPLAY, f);
550 f = 0; 645 f = 0;
551 } 646 }
552 647
553 if (d) 648 if (d)
554 { 649 {
570 cvr[i] = 0; 665 cvr[i] = 0;
571#endif 666#endif
572 667
573 clear (); 668 clear ();
574 669
575 f = XftFontOpenName (R->Xdisplay, DefaultScreen (R->Xdisplay), name); 670 f = XftFontOpenName (DISPLAY, DefaultScreen (DISPLAY), name);
576 671
577 if (!f) 672 if (!f)
578 return false; 673 return false;
579 674
580 FT_Face face = XftLockFace (f); 675 FT_Face face = XftLockFace (f);
586 for (;;) 681 for (;;)
587 { 682 {
588 XGlyphInfo g1, g2; 683 XGlyphInfo g1, g2;
589 FcChar8 c; 684 FcChar8 c;
590 685
591 c = 'i'; XftTextExtents8 (R->Xdisplay, f, &c, 1, &g1); 686 c = 'i'; XftTextExtents8 (DISPLAY, f, &c, 1, &g1);
592 c = 'W'; XftTextExtents8 (R->Xdisplay, f, &c, 1, &g2); 687 c = 'W'; XftTextExtents8 (DISPLAY, f, &c, 1, &g2);
593 688
594 prop = prop || g1.xOff != g2.xOff; // don't simply trust the font 689 prop = prop || g1.xOff != g2.xOff; // don't simply trust the font
595 690
596 width = g2.xOff; 691 width = g2.xOff;
597 ascent = (face->size->metrics.ascender + 63) >> 6; 692 ascent = (face->size->metrics.ascender + 63) >> 6;
632#endif 727#endif
633 728
634bool 729bool
635rxvt_font_xft::has_codepoint (uint32_t unicode) 730rxvt_font_xft::has_codepoint (uint32_t unicode)
636{ 731{
637 return XftCharExists (R->Xdisplay, f, unicode); 732 return XftCharExists (DISPLAY, f, unicode);
638} 733}
639 734
640void 735void
641rxvt_font_xft::draw (int x, int y, 736rxvt_font_xft::draw (int x, int y,
642 const text_t *text, int len, 737 const text_t *text, int len,
643 int fg, int bg) 738 int fg, int bg)
644{ 739{
645 if (!d) 740 if (!d)
741 {
742 dR;
646 d = XftDrawCreate (R->Xdisplay, DRAWABLE, XVISUAL, XCMAP); 743 d = XftDrawCreate (DISPLAY, DRAWABLE, XVISUAL, XCMAP);
744 }
647 745
648 if (bg >= 0 && bg != Color_bg) 746 if (bg >= 0 && bg != Color_bg)
649 XftDrawRect (d, &R->PixColors[bg].c, x, y, R->TermWin.fwidth * len, R->TermWin.fheight); 747 XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight);
650 else 748 else
651 clear_rect (x, y, R->TermWin.fwidth * len, R->TermWin.fheight, bg); 749 clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
652 750
653 if (!prop && width == R->TermWin.fwidth) 751 if (!prop && width == r->TermWin.fwidth)
654 { 752 {
655 if (sizeof (text_t) == sizeof (FcChar16)) 753 if (sizeof (text_t) == sizeof (FcChar16))
656 XftDrawString16 (d, &R->PixColors[fg].c, f, x, y + R->TermWin.fbase, (const FcChar16 *)text, len); 754 XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len);
657 else 755 else
658 XftDrawString32 (d, &R->PixColors[fg].c, f, x, y + R->TermWin.fbase, (const FcChar32 *)text, len); 756 XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, len);
659 } 757 }
660 else 758 else
661 { 759 {
662 while (len) 760 while (len)
663 { 761 {
664 if (*text != NOCHAR && *text != ' ') 762 if (*text != NOCHAR && *text != ' ')
665 { 763 {
666 if (sizeof (text_t) == sizeof (FcChar16)) 764 if (sizeof (text_t) == sizeof (FcChar16))
667 XftDrawString16 (d, &R->PixColors[fg].c, f, x, y + R->TermWin.fbase, (const FcChar16 *)text, 1); 765 XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, 1);
668 else 766 else
669 XftDrawString32 (d, &R->PixColors[fg].c, f, x, y + R->TermWin.fbase, (const FcChar32 *)text, 1); 767 XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, 1);
670 } 768 }
671 769
672 x += R->TermWin.fwidth; 770 x += r->TermWin.fwidth;
673 text++; 771 text++;
674 len--; 772 len--;
675 } 773 }
676 } 774 }
677} 775}
678#endif 776#endif
679 777
680///////////////////////////////////////////////////////////////////////////// 778/////////////////////////////////////////////////////////////////////////////
681 779
682rxvt_fontset::rxvt_fontset (pR) 780rxvt_fontset::rxvt_fontset (rxvt_t r)
683#ifdef EXPLICIT_CONTEXT 781#ifdef EXPLICIT_CONTEXT
684: rxvt_term(R) 782: r(r)
685#endif 783#endif
686{ 784{
687 clear (); 785 clear ();
688} 786}
689 787
728 f = new rxvt_font_x11; 826 f = new rxvt_font_x11;
729 } 827 }
730 else 828 else
731 f = new rxvt_font_x11; 829 f = new rxvt_font_x11;
732 830
733 f->set_term (aR); 831 f->set_term (r);
734 f->set_name (strdup (name)); 832 f->set_name (strdup (name));
735 833
736 f->cs = cs; 834 f->cs = cs;
737 f->loaded = false; 835 f->loaded = false;
738 836

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines