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.77 by root, Wed Jan 4 20:43:38 2006 UTC vs.
Revision 1.84 by root, Tue Jan 17 05:47:42 2006 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * File: rxvtfont.C 2 * File: rxvtfont.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> 4 * Copyright (c) 2003-2006 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
8 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or 9 * the Free Software Foundation; either version 2 of the License, or
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 ! OPTION_R (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 ! OPTION_R (Opt_skipBuiltinGlyphs))
361 { 364 {
362 uint16_t offs = linedraw_offs[t - 0x2500]; 365 uint16_t offs = linedraw_offs[t - 0x2500];
363 uint32_t *a = linedraw_command + (offs >> 4); 366 uint32_t *a = linedraw_command + (offs >> 4);
364 uint32_t *b = a + (offs & 15); 367 uint32_t *b = a + (offs & 15);
365 368
366 int W = fwidth; 369 int W = fwidth;
367 int H = r->fheight; 370 int H = term->fheight;
368 371
369 int x_[16]; 372 int x_[16];
370 int y_[16]; 373 int y_[16];
371 374
372 for (int i = 0; i <= 8; i++) 375 for (int i = 0; i <= 8; i++)
380 383
381 XGCValues gcv; 384 XGCValues gcv;
382 385
383 gcv.cap_style = CapButt; 386 gcv.cap_style = CapButt;
384 gcv.line_width = 0; 387 gcv.line_width = 0;
385 XChangeGC (disp, TGC, GCLineWidth | GCCapStyle, &gcv); 388 XChangeGC (disp, gc, GCLineWidth | GCCapStyle, &gcv);
386 389
387 while (a < b) 390 while (a < b)
388 { 391 {
389 uint32_t command = *a++; 392 uint32_t command = *a++;
390 393
397 int y2 = y_[(command >> 0) & 15]; 400 int y2 = y_[(command >> 0) & 15];
398 401
399 switch (op) 402 switch (op)
400 { 403 {
401 case 0: // line 404 case 0: // line
402 XDrawLine (disp, d, TGC, x1, y1, x2, y2); 405 XDrawLine (disp, d, gc, x1, y1, x2, y2);
403 break; 406 break;
404 407
405 case 1: // rectangle, possibly stippled 408 case 1: // rectangle, possibly stippled
406 if (a) 409 if (a)
407 { 410 {
410 gcv.fill_style = FillStippled; 413 gcv.fill_style = FillStippled;
411 gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2); 414 gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2);
412 gcv.ts_x_origin = x; 415 gcv.ts_x_origin = x;
413 gcv.ts_y_origin = y; 416 gcv.ts_y_origin = y;
414 417
415 XChangeGC (disp, TGC, 418 XChangeGC (disp, gc,
416 GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, 419 GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin,
417 &gcv); 420 &gcv);
418 } 421 }
419 422
420 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);
421 424
422 if (a) 425 if (a)
423 { 426 {
424 XFreePixmap (disp, gcv.stipple); 427 XFreePixmap (disp, gcv.stipple);
425 gcv.stipple = 0; 428 gcv.stipple = 0;
426 gcv.fill_style = FillSolid; 429 gcv.fill_style = FillSolid;
427 XChangeGC (disp, TGC, GCFillStyle, &gcv); 430 XChangeGC (disp, gc, GCFillStyle, &gcv);
428 } 431 }
429 break; 432 break;
430 case 2: // arc 433 case 2: // arc
431 XDrawArc (disp, d, TGC, 434 XDrawArc (disp, d, gc,
432 x1 - W/2, y1 - H/2, W-1, H-1, 435 x1 - W/2, y1 - H/2, W-1, H-1,
433 (a - 1) * 90*64, (b - 1) * 90*64); 436 (a - 1) * 90*64, (b - 1) * 90*64);
434 break; 437 break;
435 } 438 }
436 } 439 }
467 case ZERO_WIDTH_CHAR: 470 case ZERO_WIDTH_CHAR:
468 case NOCHAR: 471 case NOCHAR:
469 break; 472 break;
470 473
471 default: 474 default:
472 XDrawRectangle (disp, d, TGC, x + 2, y + 2, 475 XDrawRectangle (disp, d, gc, x + 2, y + 2,
473 fwidth - 4, r->fheight - 4); 476 fwidth - 4, term->fheight - 4);
474 } 477 }
475 478
476 x += fwidth; 479 x += fwidth;
477 } 480 }
478} 481}
486 489
487 rxvt_fontprop properties (); 490 rxvt_fontprop properties ();
488 491
489 bool load (const rxvt_fontprop &prop); 492 bool load (const rxvt_fontprop &prop);
490 493
491 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;
492 495
493 void draw (rxvt_drawable &d, int x, int y, 496 void draw (rxvt_drawable &d, int x, int y,
494 const text_t *text, int len, 497 const text_t *text, int len,
495 int fg, int bg); 498 int fg, int bg);
496 499
508char * 511char *
509rxvt_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
510{ 513{
511 unsigned long value; 514 unsigned long value;
512 515
513 if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) 516 if (XGetFontProperty (f, XInternAtom (term->display->display, property, 0), &value))
514 return XGetAtomName (DISPLAY, value); 517 return XGetAtomName (term->display->display, value);
515 else 518 else
516 return rxvt_strdup (repl); 519 return rxvt_strdup (repl);
517} 520}
518 521
519rxvt_fontprop 522rxvt_fontprop
540rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) 543rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f)
541{ 544{
542 unsigned long height; 545 unsigned long height;
543 546
544#if 0 547#if 0
545 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) 548 if (!XGetFontProperty (f, XInternAtom (term->display->display, "PIXEL_SIZE", 0), &height))
546 return false; 549 return false;
547#else 550#else
548 height = f->ascent + f->descent; 551 height = f->ascent + f->descent;
549#endif 552#endif
550 553
551 unsigned long avgwidth; 554 unsigned long avgwidth;
552 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) 555 if (!XGetFontProperty (f, XInternAtom (term->display->display, "AVERAGE_WIDTH", 0), &avgwidth))
553 avgwidth = 0; 556 avgwidth = 0;
554 557
555 char *weight = get_property (f, "WEIGHT_NAME", "medium"); 558 char *weight = get_property (f, "WEIGHT_NAME", "medium");
556 char *slant = get_property (f, "SLANT", "r"); 559 char *slant = get_property (f, "SLANT", "r");
557 560
566} 569}
567 570
568bool 571bool
569rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) 572rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name)
570{ 573{
574 dTermDisplay;
571 int slashes = 0; 575 int slashes = 0;
572 const char *comp[13]; 576 const char *comp[13];
573 577
574 for (const char *c = name; *c; c++) 578 for (const char *c = name; *c; c++)
575 if (*c == '-') 579 if (*c == '-')
583 if (slashes >= 13 587 if (slashes >= 13
584 && (*comp[ 6] >= '1' && *comp[ 6] <= '9') 588 && (*comp[ 6] >= '1' && *comp[ 6] <= '9')
585 && (*comp[11] >= '0' && *comp[11] <= '9')) 589 && (*comp[11] >= '0' && *comp[11] <= '9'))
586 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]));
587 591
588 XFontStruct *f = XLoadQueryFont (DISPLAY, name); 592 XFontStruct *f = XLoadQueryFont (disp, name);
589 593
590 if (f) 594 if (f)
591 { 595 {
592 // 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
593 // (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).
594 // in that case, just return garbage. 598 // in that case, just return garbage.
595 bool ret = set_properties (p, f); 599 bool ret = set_properties (p, f);
596 XFreeFont (DISPLAY, f); 600 XFreeFont (disp, f);
597 return ret; 601 return ret;
598 } 602 }
599 else 603 else
600 return false; 604 return false;
601} 605}
639} 643}
640 644
641bool 645bool
642rxvt_font_x11::load (const rxvt_fontprop &prop) 646rxvt_font_x11::load (const rxvt_fontprop &prop)
643{ 647{
644 Display *disp = DISPLAY; 648 dTermDisplay;
645 649
646 clear (); 650 clear ();
647 651
648 char field_str[64]; // enough for 128 bits 652 char field_str[64]; // enough for 128 bits
649 653
724 int diff = 0; 728 int diff = 0;
725 729
726 if (replace_field (fname, list[i], 6, '0', field_str)) 730 if (replace_field (fname, list[i], 6, '0', field_str))
727 diff += 10; // slightly penalize scalable fonts 731 diff += 10; // slightly penalize scalable fonts
728 else if (replace_field (fname, list[i], 11, '0', "0")) 732 else if (replace_field (fname, list[i], 11, '0', "0"))
729 diff += 300; // more heavily penalize what looks like scaled bitmap fotns 733 diff += 300; // more heavily penalize what looks like scaled bitmap fonts
730 734
731 if (!set_properties (p, fname)) 735 if (!set_properties (p, fname))
732 continue; 736 continue;
733 737
734 if (prop.height != rxvt_fontprop::unset 738 if (prop.height != rxvt_fontprop::unset
887void 891void
888rxvt_font_x11::clear () 892rxvt_font_x11::clear ()
889{ 893{
890 if (f) 894 if (f)
891 { 895 {
892 XFreeFont (DISPLAY, f); 896 XFreeFont (term->display->display, f);
893 f = 0; 897 f = 0;
894 } 898 }
895} 899}
896 900
897bool 901bool
898rxvt_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
899{ 903{
900 uint32_t ch = FROM_UNICODE (cs, unicode); 904 uint32_t ch = FROM_UNICODE (cs, unicode);
901 905
902 if (ch == NOCHAR) 906 if (ch == NOCHAR)
903 return false; 907 return false;
962 // this looks like a mess /. 966 // this looks like a mess /.
963 // and it is a mess /. 967 // and it is a mess /.
964 // yet we are trying to be perfect /. 968 // yet we are trying to be perfect /.
965 // but the result still isn't perfect /. 969 // but the result still isn't perfect /.
966 970
971 dTermDisplay;
972 dTermGC;
973
967 bool slow = this->slow 974 bool slow = this->slow
968 || width != r->fwidth 975 || width != term->fwidth
969 || height != r->fheight; 976 || height != term->fheight;
970 977
971 int base = ascent; // sorry, incorrect: r->fbase; 978 int base = ascent; // sorry, incorrect: term->fbase;
972 979
973 XGCValues v; 980 XGCValues v;
974 v.foreground = r->pix_colors[fg]; 981 v.foreground = term->pix_colors[fg];
975 v.font = f->fid; 982 v.font = f->fid;
976 983
977 if (enc2b) 984 if (enc2b)
978 { 985 {
979 const XChar2b *xc = enc_xchar2b (text, len, cs, slow); 986 const XChar2b *xc = enc_xchar2b (text, len, cs, slow);
980 987
981 if (bg == Color_bg && !slow) 988 if (bg == Color_bg && !slow)
982 { 989 {
983 v.background = r->pix_colors[bg]; 990 v.background = term->pix_colors[bg];
984 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); 991 XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v);
985 XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); 992 XDrawImageString16 (disp, d, gc, x, y + base, xc, len);
986 } 993 }
987 else 994 else
988 { 995 {
989 clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); 996 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
990 997
991 XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); 998 XChangeGC (disp, gc, GCForeground | GCFont, &v);
992 999
993 if (slow) 1000 if (slow)
994 { 1001 {
995 do 1002 do
996 { 1003 {
997 if (xc->byte1 || xc->byte2) 1004 if (xc->byte1 || xc->byte2)
998 XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); 1005 XDrawString16 (disp, d, gc, x, y + base, xc, 1);
999 1006
1000 x += r->fwidth; 1007 x += term->fwidth;
1001 xc++; len--; 1008 xc++; len--;
1002 } 1009 }
1003 while (len); 1010 while (len);
1004 } 1011 }
1005 else 1012 else
1006 XDrawString16 (d.display->display, d, TGC, x, y + base, xc, len); 1013 XDrawString16 (disp, d, gc, x, y + base, xc, len);
1007 } 1014 }
1008 } 1015 }
1009 else 1016 else
1010 { 1017 {
1011 const char *xc = enc_char (text, len, cs, slow); 1018 const char *xc = enc_char (text, len, cs, slow);
1012 1019
1013 if (bg == Color_bg && !slow) 1020 if (bg == Color_bg && !slow)
1014 { 1021 {
1015 v.background = r->pix_colors[bg]; 1022 v.background = term->pix_colors[bg];
1016 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); 1023 XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v);
1017 XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); 1024 XDrawImageString (disp, d, gc, x, y + base, xc, len);
1018 } 1025 }
1019 else 1026 else
1020 { 1027 {
1021 clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); 1028 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
1022 1029
1023 XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); 1030 XChangeGC (disp, gc, GCForeground | GCFont, &v);
1024 1031
1025 if (slow) 1032 if (slow)
1026 { 1033 {
1027 do 1034 do
1028 { 1035 {
1029 if (*xc) 1036 if (*xc)
1030 XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); 1037 XDrawString (disp, d, gc, x, y + base, xc, 1);
1031 1038
1032 x += r->fwidth; 1039 x += term->fwidth;
1033 xc++; len--; 1040 xc++; len--;
1034 } 1041 }
1035 while (len); 1042 while (len);
1036 } 1043 }
1037 else 1044 else
1038 XDrawString (d.display->display, d, TGC, x, y + base, xc, len); 1045 XDrawString (disp, d, gc, x, y + base, xc, len);
1039 } 1046 }
1040 } 1047 }
1041} 1048}
1042 1049
1043///////////////////////////////////////////////////////////////////////////// 1050/////////////////////////////////////////////////////////////////////////////
1055 1062
1056 void draw (rxvt_drawable &d, int x, int y, 1063 void draw (rxvt_drawable &d, int x, int y,
1057 const text_t *text, int len, 1064 const text_t *text, int len,
1058 int fg, int bg); 1065 int fg, int bg);
1059 1066
1060 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;
1061 1068
1062protected: 1069protected:
1063 XftFont *f; 1070 XftFont *f;
1064}; 1071};
1065 1072
1066void 1073void
1067rxvt_font_xft::clear () 1074rxvt_font_xft::clear ()
1068{ 1075{
1069 if (f) 1076 if (f)
1070 { 1077 {
1071 XftFontClose (DISPLAY, f); 1078 XftFontClose (term->display->display, f);
1072 f = 0; 1079 f = 0;
1073 } 1080 }
1074} 1081}
1075 1082
1076rxvt_fontprop 1083rxvt_fontprop
1094} 1101}
1095 1102
1096bool 1103bool
1097rxvt_font_xft::load (const rxvt_fontprop &prop) 1104rxvt_font_xft::load (const rxvt_fontprop &prop)
1098{ 1105{
1099 Display *disp = DISPLAY; 1106 dTermDisplay;
1100 1107
1101 clear (); 1108 clear ();
1102 1109
1103 FcPattern *p = FcNameParse ((FcChar8 *) name); 1110 FcPattern *p = FcNameParse ((FcChar8 *) name);
1104 1111
1131 1138
1132 // store generated name so iso14755 view gives better results 1139 // store generated name so iso14755 view gives better results
1133 set_name ((char *)FcNameUnparse (p)); 1140 set_name ((char *)FcNameUnparse (p));
1134 1141
1135 XftResult result; 1142 XftResult result;
1136 FcPattern *match = XftFontMatch (disp, r->display->screen, p, &result); 1143 FcPattern *match = XftFontMatch (disp, term->display->screen, p, &result);
1137 1144
1138 FcPatternDestroy (p); 1145 FcPatternDestroy (p);
1139 1146
1140 if (!match) 1147 if (!match)
1141 return false; 1148 return false;
1239 1246
1240 return success; 1247 return success;
1241} 1248}
1242 1249
1243bool 1250bool
1244rxvt_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
1245{ 1252{
1246 careful = false; 1253 careful = false;
1247 1254
1248 if (!XftCharExists (DISPLAY, f, unicode)) 1255 if (!XftCharExists (term->display->display, f, unicode))
1249 return false; 1256 return false;
1250 1257
1251 if (!prop || prop->width == rxvt_fontprop::unset) 1258 if (!prop || prop->width == rxvt_fontprop::unset)
1252 return true; 1259 return true;
1253 1260
1254 // check character against base font bounding box 1261 // check character against base font bounding box
1255 FcChar32 ch = unicode; 1262 FcChar32 ch = unicode;
1256 XGlyphInfo g; 1263 XGlyphInfo g;
1257 XftTextExtents32 (DISPLAY, f, &ch, 1, &g); 1264 XftTextExtents32 (term->display->display, f, &ch, 1, &g);
1258 1265
1259 int w = g.width - g.x; 1266 int w = g.width - g.x;
1260 int wcw = wcwidth (unicode); 1267 int wcw = wcwidth (unicode);
1261 if (wcw > 0) w = (w + wcw - 1) / wcw; 1268 if (wcw > 0) w = (w + wcw - 1) / wcw;
1262 1269
1270void 1277void
1271rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, 1278rxvt_font_xft::draw (rxvt_drawable &d, int x, int y,
1272 const text_t *text, int len, 1279 const text_t *text, int len,
1273 int fg, int bg) 1280 int fg, int bg)
1274{ 1281{
1275 clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); 1282 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
1276
1277 int base = ascent; // should be fbase, but that is incorrect
1278 1283
1279 XGlyphInfo extents; 1284 XGlyphInfo extents;
1280 FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32)); 1285 XftGlyphSpec *enc = (XftGlyphSpec *)get_enc_buf (len * sizeof (XftGlyphSpec));
1281 FcChar32 *ep = enc; 1286 XftGlyphSpec *ep = enc;
1282 int ewidth = 0; 1287
1288 dTermDisplay;
1289 dTermGC;
1290
1291 // cut trailing spaces
1292 while (len && text [len - 1] == ' ')
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 == ' ' && ep == enc) // skip leading spaces 1303 if (fc != ' ') // skip spaces
1304 {
1305 FT_UInt glyph = XftCharIndex (disp, f, fc);
1306 XftGlyphExtents (disp, f, &glyph, 1, &extents);
1307
1308 ep->glyph = glyph;
1309 ep->x = x + (cwidth - extents.xOff >> 1);
1310 ep->y = y + ascent;
1311 ep++;
1312 }
1313
1293 x += cwidth; 1314 x += cwidth;
1294 else
1295 {
1296 FT_UInt gl = XftCharIndex (d.display->display, f, fc);
1297 XftGlyphExtents (d.display->display, f, &gl, 1, &extents);
1298
1299 if (extents.xOff != cwidth)
1300 {
1301 if (ewidth)
1302 {
1303 XftDrawGlyphs (d, &r->pix_colors[fg].c, f,
1304 x, y + base, enc, ep - enc);
1305 x += ewidth;
1306
1307 ep = enc;
1308 ewidth = 0;
1309 }
1310
1311 if (extents.xOff > cwidth)
1312 extents.xOff = cwidth;
1313
1314 XftDrawGlyphs (d, &r->pix_colors[fg].c, f,
1315 x + (cwidth - extents.xOff >> 1),
1316 y + base, &gl, 1);
1317 x += cwidth;
1318 }
1319 else
1320 {
1321 *ep++ = gl;
1322 ewidth += cwidth;
1323 }
1324 }
1325 } 1315 }
1326 1316
1327 if (ep != enc) 1317 if (ep != enc)
1328 XftDrawGlyphs (d, &r->pix_colors[fg].c, f, 1318 XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc);
1329 x, y + base, enc, ep - enc);
1330} 1319}
1331#endif 1320#endif
1332 1321
1333///////////////////////////////////////////////////////////////////////////// 1322/////////////////////////////////////////////////////////////////////////////
1334 1323
1335rxvt_fontset::rxvt_fontset (rxvt_t r) 1324rxvt_fontset::rxvt_fontset (rxvt_term *term)
1336: fontdesc (0), r (r) 1325: fontdesc (0), term (term)
1337{ 1326{
1338 clear (); 1327 clear ();
1339} 1328}
1340 1329
1341rxvt_fontset::~rxvt_fontset () 1330rxvt_fontset::~rxvt_fontset ()
1385 f = new rxvt_font_x11; 1374 f = new rxvt_font_x11;
1386 } 1375 }
1387 else 1376 else
1388 f = new rxvt_font_x11; 1377 f = new rxvt_font_x11;
1389 1378
1390 f->set_term (r); 1379 f->set_term (term);
1391 f->set_name (strdup (name)); 1380 f->set_name (strdup (name));
1392 1381
1393 f->cs = cs; 1382 f->cs = cs;
1394 f->loaded = false; 1383 f->loaded = false;
1395 1384
1578 FcPatternAddInteger (p, FC_SLANT, prop.slant); 1567 FcPatternAddInteger (p, FC_SLANT, prop.slant);
1579 FcPatternAddBool (p, FC_MINSPACE, 1); 1568 FcPatternAddBool (p, FC_MINSPACE, 1);
1580 //FcPatternAddBool (p, FC_ANTIALIAS, 1); 1569 //FcPatternAddBool (p, FC_ANTIALIAS, 1);
1581 1570
1582 XftResult result; 1571 XftResult result;
1583 FcPattern *match = XftFontMatch (DISPLAY, r->display->screen, p, &result); 1572 FcPattern *match = XftFontMatch (term->display->display, term->display->screen, p, &result);
1584 1573
1585 FcPatternDestroy (p); 1574 FcPatternDestroy (p);
1586 1575
1587 if (match) 1576 if (match)
1588 { 1577 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines