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.83 by root, Mon Jan 9 07:35:23 2006 UTC vs.
Revision 1.84 by root, Tue Jan 17 05:47:42 2006 UTC

26#include "rxvtfont.h" 26#include "rxvtfont.h"
27 27
28#include <cstdlib> 28#include <cstdlib>
29#include <wchar.h> 29#include <wchar.h>
30#include <inttypes.h> 30#include <inttypes.h>
31
32#define DISPLAY r->display->display
33#define TGC r->gc
34 31
35#define MAX_OVERLAP (4 + 1) // max. character width in 4ths of the base width 32#define MAX_OVERLAP (4 + 1) // max. character width in 4ths of the base width
36 33
37const struct rxvt_fallback_font { 34const struct rxvt_fallback_font {
38 codeset cs; 35 codeset cs;
153 0x304c, 0x672c, // が本 150 0x304c, 0x672c, // が本
154}; 151};
155 152
156#define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0])) 153#define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0]))
157 154
155#define dTermDisplay Display *disp = term->display->display
156#define dTermGC GC gc = term->gc
157
158///////////////////////////////////////////////////////////////////////////// 158/////////////////////////////////////////////////////////////////////////////
159 159
160#if XFT 160#if XFT
161rxvt_drawable::~rxvt_drawable () 161rxvt_drawable::~rxvt_drawable ()
162{ 162{
246 if (this->name) free (this->name); // let the compiler optimize 246 if (this->name) free (this->name); // let the compiler optimize
247 this->name = name; 247 this->name = name;
248} 248}
249 249
250void 250void
251rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) 251rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const
252{ 252{
253 dTermDisplay;
254 dTermGC;
255
253 if (color == Color_bg) 256 if (color == Color_bg)
254 XClearArea (d.display->display, d, x, y, w, h, FALSE); 257 XClearArea (disp, d, x, y, w, h, FALSE);
255 else if (color >= 0) 258 else if (color >= 0)
256 { 259 {
257#if XFT 260#if XFT
258 XftDrawRect (d, &r->pix_colors[color].c, x, y, w, h); 261 XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h);
259#else 262#else
260 XSetForeground (d.display->display, TGC, r->pix_colors[color]); 263 XSetForeground (disp, gc, term->pix_colors[color]);
261 XFillRectangle (d.display->display, d, TGC, x, y, w, h); 264 XFillRectangle (disp, d, gc, x, y, w, h);
262#endif 265#endif
263 } 266 }
264} 267}
265 268
266#include "table/linedraw.h" 269#include "table/linedraw.h"
294 set_name (strdup ("built-in support font")); 297 set_name (strdup ("built-in support font"));
295 298
296 return true; 299 return true;
297 } 300 }
298 301
299 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) 302 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
300 { 303 {
301 careful = false; 304 careful = false;
302 305
303 if (unicode <= 0x001f) 306 if (unicode <= 0x001f)
304 return true; 307 return true;
308 311
309 if (unicode <= 0x009f) 312 if (unicode <= 0x009f)
310 return true; 313 return true;
311 314
312 if (unicode >= 0x2500 && unicode <= 0x259f && 315 if (unicode >= 0x2500 && unicode <= 0x259f &&
313 !r->option (Opt_skipBuiltinGlyphs)) 316 !term->option (Opt_skipBuiltinGlyphs))
314 return true; 317 return true;
315 318
316 if (IS_COMPOSE (unicode)) 319 if (IS_COMPOSE (unicode))
317 return true; 320 return true;
318 321
334void 337void
335rxvt_font_default::draw (rxvt_drawable &d, int x, int y, 338rxvt_font_default::draw (rxvt_drawable &d, int x, int y,
336 const text_t *text, int len, 339 const text_t *text, int len,
337 int fg, int bg) 340 int fg, int bg)
338{ 341{
339 Display *disp = d.display->display; 342 dTermDisplay;
343 dTermGC;
340 344
341 clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); 345 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
342 346
343 XSetForeground (disp, TGC, r->pix_colors[fg]); 347 XSetForeground (disp, gc, term->pix_colors[fg]);
344 348
345 while (len) 349 while (len)
346 { 350 {
347#if ENABLE_COMBINING 351#if ENABLE_COMBINING
348 compose_char *cc; 352 compose_char *cc;
352 356
353 while (++text, --len && *text == NOCHAR) 357 while (++text, --len && *text == NOCHAR)
354 ; 358 ;
355 359
356 int width = text - tp; 360 int width = text - tp;
357 int fwidth = r->fwidth * width; 361 int fwidth = term->fwidth * width;
358 362
359 if (0x2500 <= t && t <= 0x259f) 363 if (0x2500 <= t && t <= 0x259f)
360 { 364 {
361 uint16_t offs = linedraw_offs[t - 0x2500]; 365 uint16_t offs = linedraw_offs[t - 0x2500];
362 uint32_t *a = linedraw_command + (offs >> 4); 366 uint32_t *a = linedraw_command + (offs >> 4);
363 uint32_t *b = a + (offs & 15); 367 uint32_t *b = a + (offs & 15);
364 368
365 int W = fwidth; 369 int W = fwidth;
366 int H = r->fheight; 370 int H = term->fheight;
367 371
368 int x_[16]; 372 int x_[16];
369 int y_[16]; 373 int y_[16];
370 374
371 for (int i = 0; i <= 8; i++) 375 for (int i = 0; i <= 8; i++)
379 383
380 XGCValues gcv; 384 XGCValues gcv;
381 385
382 gcv.cap_style = CapButt; 386 gcv.cap_style = CapButt;
383 gcv.line_width = 0; 387 gcv.line_width = 0;
384 XChangeGC (disp, TGC, GCLineWidth | GCCapStyle, &gcv); 388 XChangeGC (disp, gc, GCLineWidth | GCCapStyle, &gcv);
385 389
386 while (a < b) 390 while (a < b)
387 { 391 {
388 uint32_t command = *a++; 392 uint32_t command = *a++;
389 393
396 int y2 = y_[(command >> 0) & 15]; 400 int y2 = y_[(command >> 0) & 15];
397 401
398 switch (op) 402 switch (op)
399 { 403 {
400 case 0: // line 404 case 0: // line
401 XDrawLine (disp, d, TGC, x1, y1, x2, y2); 405 XDrawLine (disp, d, gc, x1, y1, x2, y2);
402 break; 406 break;
403 407
404 case 1: // rectangle, possibly stippled 408 case 1: // rectangle, possibly stippled
405 if (a) 409 if (a)
406 { 410 {
409 gcv.fill_style = FillStippled; 413 gcv.fill_style = FillStippled;
410 gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2); 414 gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2);
411 gcv.ts_x_origin = x; 415 gcv.ts_x_origin = x;
412 gcv.ts_y_origin = y; 416 gcv.ts_y_origin = y;
413 417
414 XChangeGC (disp, TGC, 418 XChangeGC (disp, gc,
415 GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, 419 GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin,
416 &gcv); 420 &gcv);
417 } 421 }
418 422
419 XFillRectangle (disp, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1); 423 XFillRectangle (disp, d, gc, x1, y1, x2 - x1 + 1, y2 - y1 + 1);
420 424
421 if (a) 425 if (a)
422 { 426 {
423 XFreePixmap (disp, gcv.stipple); 427 XFreePixmap (disp, gcv.stipple);
424 gcv.stipple = 0; 428 gcv.stipple = 0;
425 gcv.fill_style = FillSolid; 429 gcv.fill_style = FillSolid;
426 XChangeGC (disp, TGC, GCFillStyle, &gcv); 430 XChangeGC (disp, gc, GCFillStyle, &gcv);
427 } 431 }
428 break; 432 break;
429 case 2: // arc 433 case 2: // arc
430 XDrawArc (disp, d, TGC, 434 XDrawArc (disp, d, gc,
431 x1 - W/2, y1 - H/2, W-1, H-1, 435 x1 - W/2, y1 - H/2, W-1, H-1,
432 (a - 1) * 90*64, (b - 1) * 90*64); 436 (a - 1) * 90*64, (b - 1) * 90*64);
433 break; 437 break;
434 } 438 }
435 } 439 }
466 case ZERO_WIDTH_CHAR: 470 case ZERO_WIDTH_CHAR:
467 case NOCHAR: 471 case NOCHAR:
468 break; 472 break;
469 473
470 default: 474 default:
471 XDrawRectangle (disp, d, TGC, x + 2, y + 2, 475 XDrawRectangle (disp, d, gc, x + 2, y + 2,
472 fwidth - 4, r->fheight - 4); 476 fwidth - 4, term->fheight - 4);
473 } 477 }
474 478
475 x += fwidth; 479 x += fwidth;
476 } 480 }
477} 481}
485 489
486 rxvt_fontprop properties (); 490 rxvt_fontprop properties ();
487 491
488 bool load (const rxvt_fontprop &prop); 492 bool load (const rxvt_fontprop &prop);
489 493
490 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful); 494 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const;
491 495
492 void draw (rxvt_drawable &d, int x, int y, 496 void draw (rxvt_drawable &d, int x, int y,
493 const text_t *text, int len, 497 const text_t *text, int len,
494 int fg, int bg); 498 int fg, int bg);
495 499
507char * 511char *
508rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const 512rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const
509{ 513{
510 unsigned long value; 514 unsigned long value;
511 515
512 if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) 516 if (XGetFontProperty (f, XInternAtom (term->display->display, property, 0), &value))
513 return XGetAtomName (DISPLAY, value); 517 return XGetAtomName (term->display->display, value);
514 else 518 else
515 return rxvt_strdup (repl); 519 return rxvt_strdup (repl);
516} 520}
517 521
518rxvt_fontprop 522rxvt_fontprop
539rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) 543rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f)
540{ 544{
541 unsigned long height; 545 unsigned long height;
542 546
543#if 0 547#if 0
544 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) 548 if (!XGetFontProperty (f, XInternAtom (term->display->display, "PIXEL_SIZE", 0), &height))
545 return false; 549 return false;
546#else 550#else
547 height = f->ascent + f->descent; 551 height = f->ascent + f->descent;
548#endif 552#endif
549 553
550 unsigned long avgwidth; 554 unsigned long avgwidth;
551 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) 555 if (!XGetFontProperty (f, XInternAtom (term->display->display, "AVERAGE_WIDTH", 0), &avgwidth))
552 avgwidth = 0; 556 avgwidth = 0;
553 557
554 char *weight = get_property (f, "WEIGHT_NAME", "medium"); 558 char *weight = get_property (f, "WEIGHT_NAME", "medium");
555 char *slant = get_property (f, "SLANT", "r"); 559 char *slant = get_property (f, "SLANT", "r");
556 560
565} 569}
566 570
567bool 571bool
568rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) 572rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name)
569{ 573{
574 dTermDisplay;
570 int slashes = 0; 575 int slashes = 0;
571 const char *comp[13]; 576 const char *comp[13];
572 577
573 for (const char *c = name; *c; c++) 578 for (const char *c = name; *c; c++)
574 if (*c == '-') 579 if (*c == '-')
582 if (slashes >= 13 587 if (slashes >= 13
583 && (*comp[ 6] >= '1' && *comp[ 6] <= '9') 588 && (*comp[ 6] >= '1' && *comp[ 6] <= '9')
584 && (*comp[11] >= '0' && *comp[11] <= '9')) 589 && (*comp[11] >= '0' && *comp[11] <= '9'))
585 return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11])); 590 return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11]));
586 591
587 XFontStruct *f = XLoadQueryFont (DISPLAY, name); 592 XFontStruct *f = XLoadQueryFont (disp, name);
588 593
589 if (f) 594 if (f)
590 { 595 {
591 // the font should really exist now. if not, we have a problem 596 // the font should really exist now. if not, we have a problem
592 // (e.g. if the user did xset fp rehash just when we were searching fonts). 597 // (e.g. if the user did xset fp rehash just when we were searching fonts).
593 // in that case, just return garbage. 598 // in that case, just return garbage.
594 bool ret = set_properties (p, f); 599 bool ret = set_properties (p, f);
595 XFreeFont (DISPLAY, f); 600 XFreeFont (disp, f);
596 return ret; 601 return ret;
597 } 602 }
598 else 603 else
599 return false; 604 return false;
600} 605}
638} 643}
639 644
640bool 645bool
641rxvt_font_x11::load (const rxvt_fontprop &prop) 646rxvt_font_x11::load (const rxvt_fontprop &prop)
642{ 647{
643 Display *disp = DISPLAY; 648 dTermDisplay;
644 649
645 clear (); 650 clear ();
646 651
647 char field_str[64]; // enough for 128 bits 652 char field_str[64]; // enough for 128 bits
648 653
723 int diff = 0; 728 int diff = 0;
724 729
725 if (replace_field (fname, list[i], 6, '0', field_str)) 730 if (replace_field (fname, list[i], 6, '0', field_str))
726 diff += 10; // slightly penalize scalable fonts 731 diff += 10; // slightly penalize scalable fonts
727 else if (replace_field (fname, list[i], 11, '0', "0")) 732 else if (replace_field (fname, list[i], 11, '0', "0"))
728 diff += 300; // more heavily penalize what looks like scaled bitmap fotns 733 diff += 300; // more heavily penalize what looks like scaled bitmap fonts
729 734
730 if (!set_properties (p, fname)) 735 if (!set_properties (p, fname))
731 continue; 736 continue;
732 737
733 if (prop.height != rxvt_fontprop::unset 738 if (prop.height != rxvt_fontprop::unset
886void 891void
887rxvt_font_x11::clear () 892rxvt_font_x11::clear ()
888{ 893{
889 if (f) 894 if (f)
890 { 895 {
891 XFreeFont (DISPLAY, f); 896 XFreeFont (term->display->display, f);
892 f = 0; 897 f = 0;
893 } 898 }
894} 899}
895 900
896bool 901bool
897rxvt_font_x11::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) 902rxvt_font_x11::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
898{ 903{
899 uint32_t ch = FROM_UNICODE (cs, unicode); 904 uint32_t ch = FROM_UNICODE (cs, unicode);
900 905
901 if (ch == NOCHAR) 906 if (ch == NOCHAR)
902 return false; 907 return false;
961 // this looks like a mess /. 966 // this looks like a mess /.
962 // and it is a mess /. 967 // and it is a mess /.
963 // yet we are trying to be perfect /. 968 // yet we are trying to be perfect /.
964 // but the result still isn't perfect /. 969 // but the result still isn't perfect /.
965 970
971 dTermDisplay;
972 dTermGC;
973
966 bool slow = this->slow 974 bool slow = this->slow
967 || width != r->fwidth 975 || width != term->fwidth
968 || height != r->fheight; 976 || height != term->fheight;
969 977
970 int base = ascent; // sorry, incorrect: r->fbase; 978 int base = ascent; // sorry, incorrect: term->fbase;
971 979
972 XGCValues v; 980 XGCValues v;
973 v.foreground = r->pix_colors[fg]; 981 v.foreground = term->pix_colors[fg];
974 v.font = f->fid; 982 v.font = f->fid;
975 983
976 if (enc2b) 984 if (enc2b)
977 { 985 {
978 const XChar2b *xc = enc_xchar2b (text, len, cs, slow); 986 const XChar2b *xc = enc_xchar2b (text, len, cs, slow);
979 987
980 if (bg == Color_bg && !slow) 988 if (bg == Color_bg && !slow)
981 { 989 {
982 v.background = r->pix_colors[bg]; 990 v.background = term->pix_colors[bg];
983 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); 991 XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v);
984 XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); 992 XDrawImageString16 (disp, d, gc, x, y + base, xc, len);
985 } 993 }
986 else 994 else
987 { 995 {
988 clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); 996 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
989 997
990 XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); 998 XChangeGC (disp, gc, GCForeground | GCFont, &v);
991 999
992 if (slow) 1000 if (slow)
993 { 1001 {
994 do 1002 do
995 { 1003 {
996 if (xc->byte1 || xc->byte2) 1004 if (xc->byte1 || xc->byte2)
997 XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); 1005 XDrawString16 (disp, d, gc, x, y + base, xc, 1);
998 1006
999 x += r->fwidth; 1007 x += term->fwidth;
1000 xc++; len--; 1008 xc++; len--;
1001 } 1009 }
1002 while (len); 1010 while (len);
1003 } 1011 }
1004 else 1012 else
1005 XDrawString16 (d.display->display, d, TGC, x, y + base, xc, len); 1013 XDrawString16 (disp, d, gc, x, y + base, xc, len);
1006 } 1014 }
1007 } 1015 }
1008 else 1016 else
1009 { 1017 {
1010 const char *xc = enc_char (text, len, cs, slow); 1018 const char *xc = enc_char (text, len, cs, slow);
1011 1019
1012 if (bg == Color_bg && !slow) 1020 if (bg == Color_bg && !slow)
1013 { 1021 {
1014 v.background = r->pix_colors[bg]; 1022 v.background = term->pix_colors[bg];
1015 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); 1023 XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v);
1016 XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); 1024 XDrawImageString (disp, d, gc, x, y + base, xc, len);
1017 } 1025 }
1018 else 1026 else
1019 { 1027 {
1020 clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); 1028 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
1021 1029
1022 XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); 1030 XChangeGC (disp, gc, GCForeground | GCFont, &v);
1023 1031
1024 if (slow) 1032 if (slow)
1025 { 1033 {
1026 do 1034 do
1027 { 1035 {
1028 if (*xc) 1036 if (*xc)
1029 XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); 1037 XDrawString (disp, d, gc, x, y + base, xc, 1);
1030 1038
1031 x += r->fwidth; 1039 x += term->fwidth;
1032 xc++; len--; 1040 xc++; len--;
1033 } 1041 }
1034 while (len); 1042 while (len);
1035 } 1043 }
1036 else 1044 else
1037 XDrawString (d.display->display, d, TGC, x, y + base, xc, len); 1045 XDrawString (disp, d, gc, x, y + base, xc, len);
1038 } 1046 }
1039 } 1047 }
1040} 1048}
1041 1049
1042///////////////////////////////////////////////////////////////////////////// 1050/////////////////////////////////////////////////////////////////////////////
1054 1062
1055 void draw (rxvt_drawable &d, int x, int y, 1063 void draw (rxvt_drawable &d, int x, int y,
1056 const text_t *text, int len, 1064 const text_t *text, int len,
1057 int fg, int bg); 1065 int fg, int bg);
1058 1066
1059 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &carefull); 1067 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &carefull) const;
1060 1068
1061protected: 1069protected:
1062 XftFont *f; 1070 XftFont *f;
1063}; 1071};
1064 1072
1065void 1073void
1066rxvt_font_xft::clear () 1074rxvt_font_xft::clear ()
1067{ 1075{
1068 if (f) 1076 if (f)
1069 { 1077 {
1070 XftFontClose (DISPLAY, f); 1078 XftFontClose (term->display->display, f);
1071 f = 0; 1079 f = 0;
1072 } 1080 }
1073} 1081}
1074 1082
1075rxvt_fontprop 1083rxvt_fontprop
1093} 1101}
1094 1102
1095bool 1103bool
1096rxvt_font_xft::load (const rxvt_fontprop &prop) 1104rxvt_font_xft::load (const rxvt_fontprop &prop)
1097{ 1105{
1098 Display *disp = DISPLAY; 1106 dTermDisplay;
1099 1107
1100 clear (); 1108 clear ();
1101 1109
1102 FcPattern *p = FcNameParse ((FcChar8 *) name); 1110 FcPattern *p = FcNameParse ((FcChar8 *) name);
1103 1111
1130 1138
1131 // store generated name so iso14755 view gives better results 1139 // store generated name so iso14755 view gives better results
1132 set_name ((char *)FcNameUnparse (p)); 1140 set_name ((char *)FcNameUnparse (p));
1133 1141
1134 XftResult result; 1142 XftResult result;
1135 FcPattern *match = XftFontMatch (disp, r->display->screen, p, &result); 1143 FcPattern *match = XftFontMatch (disp, term->display->screen, p, &result);
1136 1144
1137 FcPatternDestroy (p); 1145 FcPatternDestroy (p);
1138 1146
1139 if (!match) 1147 if (!match)
1140 return false; 1148 return false;
1238 1246
1239 return success; 1247 return success;
1240} 1248}
1241 1249
1242bool 1250bool
1243rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) 1251rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
1244{ 1252{
1245 careful = false; 1253 careful = false;
1246 1254
1247 if (!XftCharExists (DISPLAY, f, unicode)) 1255 if (!XftCharExists (term->display->display, f, unicode))
1248 return false; 1256 return false;
1249 1257
1250 if (!prop || prop->width == rxvt_fontprop::unset) 1258 if (!prop || prop->width == rxvt_fontprop::unset)
1251 return true; 1259 return true;
1252 1260
1253 // check character against base font bounding box 1261 // check character against base font bounding box
1254 FcChar32 ch = unicode; 1262 FcChar32 ch = unicode;
1255 XGlyphInfo g; 1263 XGlyphInfo g;
1256 XftTextExtents32 (DISPLAY, f, &ch, 1, &g); 1264 XftTextExtents32 (term->display->display, f, &ch, 1, &g);
1257 1265
1258 int w = g.width - g.x; 1266 int w = g.width - g.x;
1259 int wcw = wcwidth (unicode); 1267 int wcw = wcwidth (unicode);
1260 if (wcw > 0) w = (w + wcw - 1) / wcw; 1268 if (wcw > 0) w = (w + wcw - 1) / wcw;
1261 1269
1269void 1277void
1270rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, 1278rxvt_font_xft::draw (rxvt_drawable &d, int x, int y,
1271 const text_t *text, int len, 1279 const text_t *text, int len,
1272 int fg, int bg) 1280 int fg, int bg)
1273{ 1281{
1282 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
1283
1274 XGlyphInfo extents; 1284 XGlyphInfo extents;
1275 XftGlyphSpec *enc = (XftGlyphSpec *)get_enc_buf (len * sizeof (XftGlyphSpec)); 1285 XftGlyphSpec *enc = (XftGlyphSpec *)get_enc_buf (len * sizeof (XftGlyphSpec));
1276 XftGlyphSpec *ep = enc; 1286 XftGlyphSpec *ep = enc;
1277 1287
1278 clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); 1288 dTermDisplay;
1289 dTermGC;
1279 1290
1280 // cut trailing spaces 1291 // cut trailing spaces
1281 while (len && text [len - 1] == ' ') 1292 while (len && text [len - 1] == ' ')
1282 len--; 1293 len--;
1283 1294
1284 while (len) 1295 while (len)
1285 { 1296 {
1286 int cwidth = r->fwidth; 1297 int cwidth = term->fwidth;
1287 FcChar32 fc = *text++; len--; 1298 FcChar32 fc = *text++; len--;
1288 1299
1289 while (len && *text == NOCHAR) 1300 while (len && *text == NOCHAR)
1290 text++, len--, cwidth += r->fwidth; 1301 text++, len--, cwidth += term->fwidth;
1291 1302
1292 if (fc != ' ') // skip spaces 1303 if (fc != ' ') // skip spaces
1293 { 1304 {
1294 FT_UInt glyph = XftCharIndex (d.display->display, f, fc); 1305 FT_UInt glyph = XftCharIndex (disp, f, fc);
1295 XftGlyphExtents (d.display->display, f, &glyph, 1, &extents); 1306 XftGlyphExtents (disp, f, &glyph, 1, &extents);
1296 1307
1297 ep->glyph = glyph; 1308 ep->glyph = glyph;
1298 ep->x = x + (cwidth - extents.xOff >> 1); 1309 ep->x = x + (cwidth - extents.xOff >> 1);
1299 ep->y = y + ascent; 1310 ep->y = y + ascent;
1300 ep++; 1311 ep++;
1302 1313
1303 x += cwidth; 1314 x += cwidth;
1304 } 1315 }
1305 1316
1306 if (ep != enc) 1317 if (ep != enc)
1307 XftDrawGlyphSpec (d, &r->pix_colors[fg].c, f, enc, ep - enc); 1318 XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc);
1308} 1319}
1309#endif 1320#endif
1310 1321
1311///////////////////////////////////////////////////////////////////////////// 1322/////////////////////////////////////////////////////////////////////////////
1312 1323
1313rxvt_fontset::rxvt_fontset (rxvt_t r) 1324rxvt_fontset::rxvt_fontset (rxvt_term *term)
1314: fontdesc (0), r (r) 1325: fontdesc (0), term (term)
1315{ 1326{
1316 clear (); 1327 clear ();
1317} 1328}
1318 1329
1319rxvt_fontset::~rxvt_fontset () 1330rxvt_fontset::~rxvt_fontset ()
1363 f = new rxvt_font_x11; 1374 f = new rxvt_font_x11;
1364 } 1375 }
1365 else 1376 else
1366 f = new rxvt_font_x11; 1377 f = new rxvt_font_x11;
1367 1378
1368 f->set_term (r); 1379 f->set_term (term);
1369 f->set_name (strdup (name)); 1380 f->set_name (strdup (name));
1370 1381
1371 f->cs = cs; 1382 f->cs = cs;
1372 f->loaded = false; 1383 f->loaded = false;
1373 1384
1556 FcPatternAddInteger (p, FC_SLANT, prop.slant); 1567 FcPatternAddInteger (p, FC_SLANT, prop.slant);
1557 FcPatternAddBool (p, FC_MINSPACE, 1); 1568 FcPatternAddBool (p, FC_MINSPACE, 1);
1558 //FcPatternAddBool (p, FC_ANTIALIAS, 1); 1569 //FcPatternAddBool (p, FC_ANTIALIAS, 1);
1559 1570
1560 XftResult result; 1571 XftResult result;
1561 FcPattern *match = XftFontMatch (DISPLAY, r->display->screen, p, &result); 1572 FcPattern *match = XftFontMatch (term->display->display, term->display->screen, p, &result);
1562 1573
1563 FcPatternDestroy (p); 1574 FcPatternDestroy (p);
1564 1575
1565 if (match) 1576 if (match)
1566 { 1577 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines