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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines