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

Comparing rxvt-unicode/src/rxvtfont.C (file contents):
Revision 1.64 by root, Tue Jan 11 05:45:57 2005 UTC vs.
Revision 1.66 by root, Fri Feb 11 05:51:14 2005 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * File: defaultfont.C 2 * File: rxvtfont.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> 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
331void 331void
332rxvt_font_default::draw (rxvt_drawable &d, int x, int y, 332rxvt_font_default::draw (rxvt_drawable &d, int x, int y,
333 const text_t *text, int len, 333 const text_t *text, int len,
334 int fg, int bg) 334 int fg, int bg)
335{ 335{
336 Display *disp = d.display->display;
337
336 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 338 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
337 339
338 XSetForeground (d.display->display, TGC, r->pix_colors[fg]); 340 XSetForeground (disp, TGC, r->pix_colors[fg]);
339 341
340 while (len) 342 while (len)
341 { 343 {
342#if ENABLE_COMBINING 344#if ENABLE_COMBINING
343 compose_char *cc; 345 compose_char *cc;
374 376
375 XGCValues gcv; 377 XGCValues gcv;
376 378
377 gcv.cap_style = CapButt; 379 gcv.cap_style = CapButt;
378 gcv.line_width = 0; 380 gcv.line_width = 0;
379 XChangeGC (d.display->display, TGC, GCLineWidth | GCCapStyle, &gcv); 381 XChangeGC (disp, TGC, GCLineWidth | GCCapStyle, &gcv);
380 382
381 while (a < b) 383 while (a < b)
382 { 384 {
383 uint32_t command = *a++; 385 uint32_t command = *a++;
384 386
391 int y2 = y_[(command >> 0) & 15]; 393 int y2 = y_[(command >> 0) & 15];
392 394
393 switch (op) 395 switch (op)
394 { 396 {
395 case 0: // line 397 case 0: // line
396 XDrawLine (d.display->display, d, TGC, x1, y1, x2, y2); 398 XDrawLine (disp, d, TGC, x1, y1, x2, y2);
397 break; 399 break;
398 400
399 case 1: // rectangle, possibly stippled 401 case 1: // rectangle, possibly stippled
400 if (a) 402 if (a)
401 { 403 {
402 static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; 404 static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 };
403 405
404 gcv.fill_style = FillStippled; 406 gcv.fill_style = FillStippled;
405 gcv.stipple = XCreateBitmapFromData (d.display->display, d, bm + a * 2, 2, 2); 407 gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2);
406 gcv.ts_x_origin = x; 408 gcv.ts_x_origin = x;
407 gcv.ts_y_origin = y; 409 gcv.ts_y_origin = y;
408 410
409 XChangeGC (d.display->display, TGC, 411 XChangeGC (disp, TGC,
410 GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, 412 GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin,
411 &gcv); 413 &gcv);
412 } 414 }
413 415
414 XFillRectangle (d.display->display, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1); 416 XFillRectangle (disp, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1);
415 417
416 if (a) 418 if (a)
417 { 419 {
418 XFreePixmap (d.display->display, gcv.stipple); 420 XFreePixmap (disp, gcv.stipple);
419 gcv.stipple = 0; 421 gcv.stipple = 0;
420 gcv.fill_style = FillSolid; 422 gcv.fill_style = FillSolid;
421 XChangeGC (d.display->display, TGC, GCFillStyle, &gcv); 423 XChangeGC (disp, TGC, GCFillStyle, &gcv);
422 } 424 }
423 break; 425 break;
424 case 2: // arc 426 case 2: // arc
425 XDrawArc (d.display->display, d, TGC, 427 XDrawArc (disp, d, TGC,
426 x1 - W/2, y1 - H/2, W-1, H-1, 428 x1 - W/2, y1 - H/2, W-1, H-1,
427 (a - 1) * 90*64, (b - 1) * 90*64); 429 (a - 1) * 90*64, (b - 1) * 90*64);
428 break; 430 break;
429 } 431 }
430 } 432 }
461 case ZERO_WIDTH_CHAR: 463 case ZERO_WIDTH_CHAR:
462 case NOCHAR: 464 case NOCHAR:
463 break; 465 break;
464 466
465 default: 467 default:
466 XDrawRectangle (d.display->display, d, TGC, x + 2, y + 2, 468 XDrawRectangle (disp, d, TGC, x + 2, y + 2,
467 fwidth - 4, r->TermWin.fheight - 4); 469 fwidth - 4, r->TermWin.fheight - 4);
468 } 470 }
469 471
470 x += fwidth; 472 x += fwidth;
471 } 473 }
630} 632}
631 633
632bool 634bool
633rxvt_font_x11::load (const rxvt_fontprop &prop) 635rxvt_font_x11::load (const rxvt_fontprop &prop)
634{ 636{
637 Display *disp = DISPLAY;
638
635 clear (); 639 clear ();
636 640
637 char field_str[64]; // enough for 128 bits 641 char field_str[64]; // enough for 128 bits
638 642
639 // first morph the font if required 643 // first morph the font if required
642 { 646 {
643 char fname[1024]; 647 char fname[1024];
644 648
645 if (name[0] != '-') 649 if (name[0] != '-')
646 { 650 {
647 f = XLoadQueryFont (DISPLAY, name); 651 f = XLoadQueryFont (disp, name);
648 652
649 if (!f) 653 if (!f)
650 return false; 654 return false;
651 655
652 char *new_name = get_property (f, "FONT", name); 656 char *new_name = get_property (f, "FONT", name);
654 if (new_name) 658 if (new_name)
655 set_name (new_name); 659 set_name (new_name);
656 else 660 else
657 rxvt_warn ("font '%s' has no FONT property, continuing without.", name); 661 rxvt_warn ("font '%s' has no FONT property, continuing without.", name);
658 662
659 XFreeFont (DISPLAY, f); 663 XFreeFont (disp, f);
660 f = 0; 664 f = 0;
661 } 665 }
662 666
663 if (prop.weight != rxvt_fontprop::unset) 667 if (prop.weight != rxvt_fontprop::unset)
664 { 668 {
694 ~font_weight () { free (name); } 698 ~font_weight () { free (name); }
695 }; 699 };
696 700
697 char **list; 701 char **list;
698 int count; 702 int count;
699 list = XListFonts (DISPLAY, name, 4000, &count); 703 list = XListFonts (disp, name, 4000, &count);
700 704
701 set_name (0); 705 set_name (0);
702 706
703 if (!list) 707 if (!list)
704 return false; 708 return false;
741 for (font_weight *w = best; w-- > fonts; ) 745 for (font_weight *w = best; w-- > fonts; )
742 if (w->diff < best->diff) 746 if (w->diff < best->diff)
743 best = w; 747 best = w;
744 748
745 if (!best->name 749 if (!best->name
746 || !(f = XLoadQueryFont (DISPLAY, best->name))) 750 || !(f = XLoadQueryFont (disp, best->name)))
747 break; 751 break;
748 752
749 set_name (best->name); 753 set_name (best->name);
750 best->clear (); 754 best->clear ();
751 755
1080} 1084}
1081 1085
1082bool 1086bool
1083rxvt_font_xft::load (const rxvt_fontprop &prop) 1087rxvt_font_xft::load (const rxvt_fontprop &prop)
1084{ 1088{
1089 Display *disp = DISPLAY;
1090
1085 clear (); 1091 clear ();
1086 1092
1087 FcPattern *p = FcNameParse ((FcChar8 *) name); 1093 FcPattern *p = FcNameParse ((FcChar8 *) name);
1088 1094
1089 if (!p) 1095 if (!p)
1115 1121
1116 // store generated name so iso14755 view gives better results 1122 // store generated name so iso14755 view gives better results
1117 set_name ((char *)FcNameUnparse (p)); 1123 set_name ((char *)FcNameUnparse (p));
1118 1124
1119 XftResult result; 1125 XftResult result;
1120 FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); 1126 FcPattern *match = XftFontMatch (disp, r->display->screen, p, &result);
1121 1127
1122 FcPatternDestroy (p); 1128 FcPatternDestroy (p);
1123 1129
1124 if (!match) 1130 if (!match)
1125 return false; 1131 return false;
1127 int ftheight = 0; 1133 int ftheight = 0;
1128 bool success = true; 1134 bool success = true;
1129 1135
1130 for (;;) 1136 for (;;)
1131 { 1137 {
1132 f = XftFontOpenPattern (DISPLAY, FcPatternDuplicate (match)); 1138 f = XftFontOpenPattern (disp, FcPatternDuplicate (match));
1133 1139
1134 if (!f) 1140 if (!f)
1135 { 1141 {
1136 success = false; 1142 success = false;
1137 break; 1143 break;
1161 bool careful; 1167 bool careful;
1162 if (!has_char (*t, &prop, careful)) 1168 if (!has_char (*t, &prop, careful))
1163 continue; 1169 continue;
1164 1170
1165 XGlyphInfo g; 1171 XGlyphInfo g;
1166 XftTextExtents16 (DISPLAY, f, &ch, 1, &g); 1172 XftTextExtents16 (disp, f, &ch, 1, &g);
1167 1173
1168 int wcw = wcwidth (ch); 1174 int wcw = wcwidth (ch);
1169 if (wcw > 0) g.width = g.width / wcw; 1175 if (wcw > 0) g.width = g.width / wcw;
1170 1176
1171 if (width < g.width) width = g.width; 1177 if (width < g.width) width = g.width;
1188 ftheight -= height - prop.height; 1194 ftheight -= height - prop.height;
1189 } 1195 }
1190 else 1196 else
1191 ftheight = prop.height - 1; 1197 ftheight = prop.height - 1;
1192 1198
1193 XftFontClose (DISPLAY, f); 1199 XftFontClose (disp, f);
1194 FcPatternDel (match, FC_PIXEL_SIZE); 1200 FcPatternDel (match, FC_PIXEL_SIZE);
1195 FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); 1201 FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight);
1196 } 1202 }
1197 1203
1198 FcPatternDestroy (match); 1204 FcPatternDestroy (match);
1543 FcPatternAddInteger (p, FC_SLANT, prop.slant); 1549 FcPatternAddInteger (p, FC_SLANT, prop.slant);
1544 FcPatternAddBool (p, FC_MINSPACE, 1); 1550 FcPatternAddBool (p, FC_MINSPACE, 1);
1545 //FcPatternAddBool (p, FC_ANTIALIAS, 1); 1551 //FcPatternAddBool (p, FC_ANTIALIAS, 1);
1546 1552
1547 XftResult result; 1553 XftResult result;
1548 FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); 1554 FcPattern *match = XftFontMatch (DISPLAY, r->display->screen, p, &result);
1549 1555
1550 FcPatternDestroy (p); 1556 FcPatternDestroy (p);
1551 1557
1552 if (match) 1558 if (match)
1553 { 1559 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines