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.92 by root, Mon Jan 30 04:53:30 2006 UTC vs.
Revision 1.125 by ayin, Sun Nov 25 11:23:18 2007 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*----------------------------------------------------------------------*
2 * File: rxvtfont.C 2 * File: rxvtfont.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com> 4 * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com>
5 * - original version. 5 * - original version.
6 * 6 *
43 const char *name; 43 const char *name;
44} fallback_fonts[] = { 44} fallback_fonts[] = {
45 { CS_ISO8859_1, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-1" }, 45 { CS_ISO8859_1, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-1" },
46 { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-15" }, 46 { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-15" },
47 { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-fcd8859-15" }, 47 { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-fcd8859-15" },
48 48
49#if ENCODING_EU 49#if ENCODING_EU
50 // cyrillic 50 // cyrillic
51 { CS_KOI8_R, "-*-*-*-r-*--*-*-*-*-c-*-koi8-r" }, 51 { CS_KOI8_R, "-*-*-*-r-*--*-*-*-*-c-*-koi8-r" },
52 { CS_KOI8_U, "-*-*-*-r-*--*-*-*-*-c-*-koi8-u" }, 52 { CS_KOI8_U, "-*-*-*-r-*--*-*-*-*-c-*-koi8-u" },
53 53
54 { CS_ISO8859_2, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-2" }, 54 { CS_ISO8859_2, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-2" },
55 { CS_ISO8859_3, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-3" }, 55 { CS_ISO8859_3, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-3" },
56 { CS_ISO8859_4, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-4" }, 56 { CS_ISO8859_4, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-4" },
57 { CS_ISO8859_5, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-5" }, 57 { CS_ISO8859_5, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-5" },
58 { CS_ISO8859_6, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-6" }, 58 { CS_ISO8859_6, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-6" },
65 { CS_ISO8859_14, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-14" }, 65 { CS_ISO8859_14, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-14" },
66 { CS_ISO8859_16, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-16" }, 66 { CS_ISO8859_16, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-16" },
67 67
68# if XFT 68# if XFT
69 { CS_KOI8_U, "xft::lang=ru" }, 69 { CS_KOI8_U, "xft::lang=ru" },
70 70
71 { CS_ISO8859_5, "xft::lang=ru" }, 71 { CS_ISO8859_5, "xft::lang=ru" },
72 { CS_ISO8859_6, "xft::lang=ar" }, 72 { CS_ISO8859_6, "xft::lang=ar" },
73 { CS_ISO8859_7, "xft::lang=el" }, 73 { CS_ISO8859_7, "xft::lang=el" },
74 { CS_ISO8859_8, "xft::lang=he" }, 74 { CS_ISO8859_8, "xft::lang=he" },
75 { CS_ISO8859_9, "xft::lang=tr" }, 75 { CS_ISO8859_9, "xft::lang=tr" },
158 0x304c, 0x672c, // が本 158 0x304c, 0x672c, // が本
159}; 159};
160 160
161#define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0])) 161#define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0]))
162 162
163#define dTermDisplay Display *disp = term->xdisp 163#define dTermDisplay Display *disp = term->dpy
164#define dTermGC GC gc = term->gc 164#define dTermGC GC gc = term->gc
165
166/////////////////////////////////////////////////////////////////////////////
167
168#if XFT
169rxvt_drawable::~rxvt_drawable ()
170{
171 if (xftdrawable)
172 XftDrawDestroy (xftdrawable);
173}
174
175rxvt_drawable::operator XftDraw *()
176{
177 if (!xftdrawable)
178 xftdrawable = XftDrawCreate (screen->xdisp, drawable, screen->visual, screen->cmap);
179
180 return xftdrawable;
181}
182#endif
183 165
184///////////////////////////////////////////////////////////////////////////// 166/////////////////////////////////////////////////////////////////////////////
185 167
186static const char * 168static const char *
187enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) 169enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero)
249void 231void
250rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const 232rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const
251{ 233{
252 dTermDisplay; 234 dTermDisplay;
253 dTermGC; 235 dTermGC;
254 236
255 if (color == Color_bg) 237 if (color == Color_bg || color == Color_transparent)
256 XClearArea (disp, d, x, y, w, h, false); 238 XClearArea (disp, d, x, y, w, h, false);
257 else if (color >= 0) 239 else if (color >= 0)
258 { 240 {
259#if XFT 241#if XFT
242 bool done = false;
243#ifdef HAVE_BG_PIXMAP
244 if (term->bgPixmap.pixmap && color >= 0 && term->pix_colors[color].c.color.alpha < 0x0ff00)
245 {
246 Picture dst = XftDrawPicture (d);
247 if (dst != 0)
248 {
249 XClearArea (disp, d, x, y, w, h, false);
250 Picture solid_color_pict = XftDrawSrcPicture (d, &term->pix_colors[color].c);
251 XRenderComposite (disp, PictOpOver, solid_color_pict, None, dst, 0, 0, 0, 0, x, y, w, h);
252 done = true;
253 }
254 }
255#endif
256 if (!done)
260 XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h); 257 XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h);
261#else 258#else
262 XSetForeground (disp, gc, term->pix_colors[color]); 259 XSetForeground (disp, gc, term->pix_colors[color]);
263 XFillRectangle (disp, d, gc, x, y, w, h); 260 XFillRectangle (disp, d, gc, x, y, w, h);
264#endif 261#endif
265 } 262 }
266} 263}
267 264
268///////////////////////////////////////////////////////////////////////////// 265/////////////////////////////////////////////////////////////////////////////
269
270#include "table/linedraw.h"
271 266
272struct rxvt_font_default : rxvt_font { 267struct rxvt_font_default : rxvt_font {
273 struct rxvt_fontset *fs; 268 struct rxvt_fontset *fs;
274 269
275 rxvt_font_default (rxvt_fontset *fs) 270 rxvt_font_default (rxvt_fontset *fs)
288 p.slant = rxvt_fontprop::roman; 283 p.slant = rxvt_fontprop::roman;
289 284
290 return p; 285 return p;
291 } 286 }
292 287
293 bool load (const rxvt_fontprop &prop) 288 bool load (const rxvt_fontprop &prop, bool force_prop)
294 { 289 {
295 width = 1; height = 1; 290 width = 1; height = 1;
296 ascent = 1; descent = 0; 291 ascent = 1; descent = 0;
297 292
298 set_name (strdup ("built-in support font")); 293 set_name (strdup ("built-in support font"));
311 return false; 306 return false;
312 307
313 if (unicode <= 0x009f) 308 if (unicode <= 0x009f)
314 return true; 309 return true;
315 310
311#ifdef BUILTIN_GLYPHS
316 if (unicode >= 0x2500 && unicode <= 0x259f && 312 if (unicode >= 0x2500 && unicode <= 0x259f &&
317 !term->option (Opt_skipBuiltinGlyphs)) 313 !term->option (Opt_skipBuiltinGlyphs))
318 return true; 314 return true;
315#endif
319 316
320 if (IS_COMPOSE (unicode)) 317 if (IS_COMPOSE (unicode))
321 return true; 318 return true;
322 319
323 switch (unicode) 320 switch (unicode)
359 ; 356 ;
360 357
361 int width = text - tp; 358 int width = text - tp;
362 int fwidth = term->fwidth * width; 359 int fwidth = term->fwidth * width;
363 360
361#ifdef BUILTIN_GLYPHS
364 if (0x2500 <= t && t <= 0x259f) 362 if (0x2500 <= t && t <= 0x259f)
365 { 363 {
364# include "table/linedraw.h"
366 uint16_t offs = linedraw_offs[t - 0x2500]; 365 uint16_t offs = linedraw_offs[t - 0x2500];
367 uint32_t *a = linedraw_command + (offs >> 4); 366 uint32_t *a = linedraw_command + (offs >> 4);
368 uint32_t *b = a + (offs & 15); 367 uint32_t *b = a + (offs & 15);
369 368
370 int W = fwidth; 369 int W = fwidth;
408 407
409 case 1: // rectangle, possibly stippled 408 case 1: // rectangle, possibly stippled
410 if (a) 409 if (a)
411 { 410 {
412 static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; 411 static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 };
413 412
414 gcv.fill_style = FillStippled; 413 gcv.fill_style = FillStippled;
415 gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2); 414 gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2);
416 gcv.ts_x_origin = x; 415 gcv.ts_x_origin = x;
417 gcv.ts_y_origin = y; 416 gcv.ts_y_origin = y;
418 417
437 (a - 1) * 90*64, (b - 1) * 90*64); 436 (a - 1) * 90*64, (b - 1) * 90*64);
438 break; 437 break;
439 } 438 }
440 } 439 }
441 } 440 }
441#else
442 if (0)
443 ;
444#endif
442#if ENABLE_COMBINING 445#if ENABLE_COMBINING
443 else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) 446 else if (IS_COMPOSE (t) && (cc = rxvt_composite[t]))
444 { 447 {
445 min_it (width, 2); // we only support wcwidth up to 2 448 min_it (width, 2); // we only support wcwidth up to 2
446 449
459 *chrs = cc->c2; 462 *chrs = cc->c2;
460 rxvt_font *f2 = (f1->has_char (cc->c2, 0, careful) && !careful) 463 rxvt_font *f2 = (f1->has_char (cc->c2, 0, careful) && !careful)
461 ? f1 464 ? f1
462 : (*fs)[fs->find_font (cc->c2)]; 465 : (*fs)[fs->find_font (cc->c2)];
463 466
464 f2->draw (d, x, y, chrs, width, fg, -1); 467 f2->draw (d, x, y, chrs, width, fg, Color_none);
465 } 468 }
466 } 469 }
467#endif 470#endif
468 else 471 else
469 switch (t) 472 switch (t)
489 492
490 void clear (); 493 void clear ();
491 494
492 rxvt_fontprop properties (); 495 rxvt_fontprop properties ();
493 496
494 bool load (const rxvt_fontprop &prop); 497 bool load (const rxvt_fontprop &prop, bool force_prop);
495 498
496 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const; 499 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const;
497 500
498 void draw (rxvt_drawable &d, int x, int y, 501 void draw (rxvt_drawable &d, int x, int y,
499 const text_t *text, int len, 502 const text_t *text, int len,
500 int fg, int bg); 503 int fg, int bg);
501 504
502 bool slow; // wether this is a proportional font or has other funny characteristics 505 bool slow; // wether this is a proportional font or has other funny characteristics
503 XFontStruct *f; 506 XFontStruct *f;
504 codeset cs;
505 bool enc2b, encm; 507 bool enc2b, encm;
506 508
507 char *get_property (XFontStruct *f, Atom property, const char *repl) const; 509 char *get_property (XFontStruct *f, Atom property, const char *repl) const;
508 bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth); 510 bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth);
509 bool set_properties (rxvt_fontprop &p, XFontStruct *f); 511 bool set_properties (rxvt_fontprop &p, XFontStruct *f);
514rxvt_font_x11::get_property (XFontStruct *f, Atom property, const char *repl) const 516rxvt_font_x11::get_property (XFontStruct *f, Atom property, const char *repl) const
515{ 517{
516 unsigned long value; 518 unsigned long value;
517 519
518 if (XGetFontProperty (f, property, &value)) 520 if (XGetFontProperty (f, property, &value))
519 return XGetAtomName (term->xdisp, value); 521 return XGetAtomName (term->dpy, value);
520 else 522 else
521 return rxvt_strdup (repl); 523 return repl ? strdup (repl) : 0;
522} 524}
523 525
524rxvt_fontprop 526rxvt_fontprop
525rxvt_font_x11::properties () 527rxvt_font_x11::properties ()
526{ 528{
547rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) 549rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f)
548{ 550{
549 unsigned long height; 551 unsigned long height;
550 552
551#if 0 553#if 0
552 if (!XGetFontProperty (f, XInternAtom (term->xdisp, "PIXEL_SIZE", 0), &height)) 554 if (!XGetFontProperty (f, XInternAtom (term->dpy, "PIXEL_SIZE", 0), &height))
553 return false; 555 return false;
554#else 556#else
555 height = f->ascent + f->descent; 557 height = f->ascent + f->descent;
556#endif 558#endif
557 559
608 return false; 610 return false;
609} 611}
610 612
611// fix the size of scalable fonts 613// fix the size of scalable fonts
612static bool 614static bool
613replace_field (char *buf, const char *name, int index, const char old, const char *replace) 615replace_field (char **ptr, const char *name, int index, const char old, const char *replace)
614{ 616{
615 int slashes = 0; 617 int slashes = 0;
616 const char *field, *end; 618 const char *field, *end;
617 619
618 for (const char *c = name; *c; c++) 620 for (const char *c = name; *c; c++)
628 break; 630 break;
629 } 631 }
630 632
631 if (slashes >= 13 && (!old || *field == old)) 633 if (slashes >= 13 && (!old || *field == old))
632 { 634 {
633 // TODO: check for overflow in font-name 635 size_t len = field - name;
636 *ptr = (char *)malloc (len + strlen (replace) + strlen (end) + 1);
634 strncpy (buf, name, field - name); 637 strncpy (*ptr, name, len);
635 buf += field - name;
636 strcpy (buf, replace); 638 strcpy (*ptr + len, replace);
637 strcat (buf, end); 639 strcat (*ptr, end);
638 640
639 return true; 641 return true;
640 } 642 }
641 else 643 else
642 { 644 {
643 strcpy (buf, name); 645 *ptr = strdup (name);
644 646
645 return false; 647 return false;
646 } 648 }
647} 649}
648 650
649bool 651bool
650rxvt_font_x11::load (const rxvt_fontprop &prop) 652rxvt_font_x11::load (const rxvt_fontprop &prop, bool force_prop)
651{ 653{
652 dTermDisplay; 654 dTermDisplay;
653 655
654 clear (); 656 clear ();
655 657
656 char field_str[64]; // enough for 128 bits 658 char field_str[64]; // enough for 128 bits
657 659
658 // first morph the font if required 660 // first morph the font if required
659 if (prop.weight != rxvt_fontprop::unset 661 if (force_prop)
660 || prop.slant != rxvt_fontprop::unset)
661 { 662 {
662 char fname[1024]; 663 char *fname;
663 664
664 if (name[0] != '-') 665 if (name[0] != '-')
665 { 666 {
666 f = XLoadQueryFont (disp, name); 667 f = XLoadQueryFont (disp, name);
667 668
679 f = 0; 680 f = 0;
680 } 681 }
681 682
682 if (prop.weight != rxvt_fontprop::unset) 683 if (prop.weight != rxvt_fontprop::unset)
683 { 684 {
684 replace_field (fname, name, 2, 0, 685 replace_field (&fname, name, 2, 0,
685 prop.weight < rxvt_fontprop::bold 686 prop.weight < rxvt_fontprop::bold
686 ? "medium" : "bold"); 687 ? "medium" : "bold");
687 set_name (strdup (fname)); 688 set_name (fname);
688 } 689 }
689 690
690 if (prop.slant != rxvt_fontprop::unset) 691 if (prop.slant != rxvt_fontprop::unset)
691 { 692 {
692 replace_field (fname, name, 3, 0, 693 replace_field (&fname, name, 3, 0,
693 prop.slant < rxvt_fontprop::italic 694 prop.slant < rxvt_fontprop::italic
694 ? "r" : "i"); // TODO: handle "o"blique, too 695 ? "r" : "i"); // TODO: handle "o"blique, too
695 set_name (strdup (fname)); 696 set_name (fname);
696 } 697 }
697 } 698 }
698 699
699 sprintf (field_str, "%d", prop.height == rxvt_fontprop::unset 700 sprintf (field_str, "%d", prop.height == rxvt_fontprop::unset
700 ? 0 : prop.height); 701 ? 0 : prop.height);
725 font_weight *fonts = new font_weight[count]; 726 font_weight *fonts = new font_weight[count];
726 727
727 for (int i = 0; i < count; i++) 728 for (int i = 0; i < count; i++)
728 { 729 {
729 rxvt_fontprop p; 730 rxvt_fontprop p;
730 char fname[1024]; 731 char *fname;
731 732
732 int diff = 0; 733 int diff = 0;
733 734
734 if (replace_field (fname, list[i], 6, '0', field_str)) 735 if (replace_field (&fname, list[i], 6, '0', field_str))
735 diff += 10; // slightly penalize scalable fonts 736 diff += 10; // slightly penalize scalable fonts
737 else
738 {
739 free (fname);
736 else if (replace_field (fname, list[i], 11, '0', "0")) 740 if (replace_field (&fname, list[i], 11, '0', "0"))
737 diff += 300; // more heavily penalize what looks like scaled bitmap fonts 741 diff += 300; // more heavily penalize what looks like scaled bitmap fonts
742 }
738 743
739 if (!set_properties (p, fname)) 744 if (!set_properties (p, fname))
740 continue; 745 continue;
741 746
742 if (prop.height != rxvt_fontprop::unset 747 if (prop.height != rxvt_fontprop::unset
746 if (prop.height != rxvt_fontprop::unset) diff += (prop.height - p.height) * 128; 751 if (prop.height != rxvt_fontprop::unset) diff += (prop.height - p.height) * 128;
747 if (prop.weight != rxvt_fontprop::unset) diff += abs (prop.weight - p.weight); 752 if (prop.weight != rxvt_fontprop::unset) diff += abs (prop.weight - p.weight);
748 if (prop.slant != rxvt_fontprop::unset) diff += abs (prop.slant - p.slant); 753 if (prop.slant != rxvt_fontprop::unset) diff += abs (prop.slant - p.slant);
749 //if (prop.width != rxvt_fontprop::unset) diff += abs (prop.width - p.width); 754 //if (prop.width != rxvt_fontprop::unset) diff += abs (prop.width - p.width);
750 755
751 fonts[i].name = strdup (fname); 756 fonts[i].name = fname;
752 fonts[i].diff = diff; 757 fonts[i].diff = diff;
753 } 758 }
754 759
755 XFreeFontNames (list); 760 XFreeFontNames (list);
756 761
833 int N = f->max_char_or_byte2 - f->min_char_or_byte2; 838 int N = f->max_char_or_byte2 - f->min_char_or_byte2;
834 839
835 if (encm) 840 if (encm)
836 N += (f->max_byte1 - f->min_byte1) 841 N += (f->max_byte1 - f->min_byte1)
837 * (f->max_char_or_byte2 - f->min_char_or_byte2 + 1); 842 * (f->max_char_or_byte2 - f->min_char_or_byte2 + 1);
838 843
839 while (N) 844 while (N)
840 { 845 {
841 if (f->per_char[N].width > width) 846 if (f->per_char[N].width > width)
842 width = f->per_char[N].width; 847 width = f->per_char[N].width;
843 848
892void 897void
893rxvt_font_x11::clear () 898rxvt_font_x11::clear ()
894{ 899{
895 if (f) 900 if (f)
896 { 901 {
897 XFreeFont (term->xdisp, f); 902 XFreeFont (term->dpy, f);
898 f = 0; 903 f = 0;
899 } 904 }
900} 905}
901 906
902bool 907bool
995 else 1000 else
996 { 1001 {
997 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); 1002 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
998 1003
999 XChangeGC (disp, gc, GCForeground | GCFont, &v); 1004 XChangeGC (disp, gc, GCForeground | GCFont, &v);
1000 1005
1001 if (slow) 1006 if (slow)
1002 { 1007 {
1003 do 1008 do
1004 { 1009 {
1005 if (xc->byte1 || xc->byte2) 1010 if (xc->byte1 || xc->byte2)
1027 else 1032 else
1028 { 1033 {
1029 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); 1034 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
1030 1035
1031 XChangeGC (disp, gc, GCForeground | GCFont, &v); 1036 XChangeGC (disp, gc, GCForeground | GCFont, &v);
1032 1037
1033 if (slow) 1038 if (slow)
1034 { 1039 {
1035 do 1040 do
1036 { 1041 {
1037 if (*xc) 1042 if (*xc)
1057 1062
1058 void clear (); 1063 void clear ();
1059 1064
1060 rxvt_fontprop properties (); 1065 rxvt_fontprop properties ();
1061 1066
1062 bool load (const rxvt_fontprop &prop); 1067 bool load (const rxvt_fontprop &prop, bool force_prop);
1063 1068
1064 void draw (rxvt_drawable &d, int x, int y, 1069 void draw (rxvt_drawable &d, int x, int y,
1065 const text_t *text, int len, 1070 const text_t *text, int len,
1066 int fg, int bg); 1071 int fg, int bg);
1067 1072
1068 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &carefull) const; 1073 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const;
1069 1074
1070protected: 1075protected:
1071 XftFont *f; 1076 XftFont *f;
1072}; 1077};
1073 1078
1074void 1079void
1075rxvt_font_xft::clear () 1080rxvt_font_xft::clear ()
1076{ 1081{
1077 if (f) 1082 if (f)
1078 { 1083 {
1079 XftFontClose (term->xdisp, f); 1084 XftFontClose (term->dpy, f);
1080 f = 0; 1085 f = 0;
1081 } 1086 }
1082} 1087}
1083 1088
1084rxvt_fontprop 1089rxvt_fontprop
1100 1105
1101 return p; 1106 return p;
1102} 1107}
1103 1108
1104bool 1109bool
1105rxvt_font_xft::load (const rxvt_fontprop &prop) 1110rxvt_font_xft::load (const rxvt_fontprop &prop, bool force_prop)
1106{ 1111{
1107 dTermDisplay; 1112 dTermDisplay;
1108 1113
1109 clear (); 1114 clear ();
1110 1115
1119 && (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch 1124 && (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch
1120 && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) 1125 && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch))
1121 FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); 1126 FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height);
1122 1127
1123 if (prop.weight != rxvt_fontprop::unset 1128 if (prop.weight != rxvt_fontprop::unset
1124 && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) 1129 && (force_prop || FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch))
1125 FcPatternAddInteger (p, FC_WEIGHT, prop.weight); 1130 FcPatternAddInteger (p, FC_WEIGHT, prop.weight);
1126 1131
1127 if (prop.slant != rxvt_fontprop::unset 1132 if (prop.slant != rxvt_fontprop::unset
1128 && FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch) 1133 && (force_prop || FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch))
1129 FcPatternAddInteger (p, FC_SLANT, prop.slant); 1134 FcPatternAddInteger (p, FC_SLANT, prop.slant);
1130 1135
1131#if 0 // clipping unfortunately destroys our precious double-width-characters 1136#if 0 // clipping unfortunately destroys our precious double-width-characters
1132 // clip width, we can't do better, or can we? 1137 // clip width, we can't do better, or can we?
1133 if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) 1138 if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch)
1251bool 1256bool
1252rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const 1257rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
1253{ 1258{
1254 careful = false; 1259 careful = false;
1255 1260
1256 if (!XftCharExists (term->xdisp, f, unicode)) 1261 if (!XftCharExists (term->dpy, f, unicode))
1257 return false; 1262 return false;
1258 1263
1259 if (!prop || prop->width == rxvt_fontprop::unset) 1264 if (!prop || prop->width == rxvt_fontprop::unset)
1260 return true; 1265 return true;
1261 1266
1262 // check character against base font bounding box 1267 // check character against base font bounding box
1263 FcChar32 ch = unicode; 1268 FcChar32 ch = unicode;
1264 XGlyphInfo g; 1269 XGlyphInfo g;
1265 XftTextExtents32 (term->xdisp, f, &ch, 1, &g); 1270 XftTextExtents32 (term->dpy, f, &ch, 1, &g);
1266 1271
1267 int w = g.width - g.x; 1272 int w = g.width - g.x;
1268 int wcw = max (WCWIDTH (unicode), 1); 1273 int wcw = max (WCWIDTH (unicode), 1);
1269 1274
1270 careful = g.x > 0 || w > prop->width * wcw; 1275 careful = g.x > 0 || w > prop->width * wcw;
1282void 1287void
1283rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, 1288rxvt_font_xft::draw (rxvt_drawable &d, int x, int y,
1284 const text_t *text, int len, 1289 const text_t *text, int len,
1285 int fg, int bg) 1290 int fg, int bg)
1286{ 1291{
1287 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
1288
1289 XGlyphInfo extents; 1292 XGlyphInfo extents;
1290 XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec)); 1293 XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec));
1291 XftGlyphSpec *ep = enc; 1294 XftGlyphSpec *ep = enc;
1292 1295
1293 dTermDisplay; 1296 dTermDisplay;
1294 dTermGC; 1297 dTermGC;
1295 1298
1299 int w = term->fwidth * len;
1300 int h = term->fheight;
1301
1302 /* TODO: this logic needs some more thinking, since we no longer do pseudo-transparency.
1303 * Maybe make buffering into a resource flag? Compile time option doesn't seems like a
1304 * good idea from the perspective of packaging for wide variety of user configs.
1305 */
1306 bool buffered = true
1307#ifdef FORCE_UNBUFFERED_XFT
1308 && bg >= 0
1309#endif
1310 ;
1296 // cut trailing spaces 1311 // cut trailing spaces
1297 while (len && text [len - 1] == ' ') 1312 while (len && text [len - 1] == ' ')
1298 len--; 1313 len--;
1299 1314
1315 int x_ = buffered ? 0 : x;
1316 int y_ = buffered ? 0 : y;
1317
1300 while (len) 1318 while (len)
1301 { 1319 {
1302 int cwidth = term->fwidth; 1320 int cwidth = term->fwidth;
1303 FcChar32 fc = *text++; len--; 1321 FcChar32 fc = *text++; len--;
1304 1322
1305 while (len && *text == NOCHAR) 1323 while (len && *text == NOCHAR)
1306 text++, len--, cwidth += term->fwidth; 1324 text++, len--, cwidth += term->fwidth;
1307 1325
1308 if (fc != ' ') // skip spaces 1326 if (fc != ' ') // skip spaces
1309 { 1327 {
1310 FT_UInt glyph = XftCharIndex (disp, f, fc); 1328 FT_UInt glyph = XftCharIndex (disp, f, fc);
1311 XftGlyphExtents (disp, f, &glyph, 1, &extents); 1329 XftGlyphExtents (disp, f, &glyph, 1, &extents);
1312 1330
1313
1314 ep->glyph = glyph; 1331 ep->glyph = glyph;
1315 ep->x = x + (cwidth - extents.xOff >> 1); 1332 ep->x = x_ + (cwidth - extents.xOff >> 1);
1316 ep->y = y + ascent; 1333 ep->y = y_ + ascent;
1317 1334
1318 if (extents.xOff == 0) 1335 if (extents.xOff == 0)
1319 ep->x = x + cwidth; 1336 ep->x = x_ + cwidth;
1320 1337
1321 ep++; 1338 ep++;
1322 } 1339 }
1323 1340
1324 x += cwidth; 1341 x_ += cwidth;
1342 }
1343
1344 if (buffered)
1325 } 1345 {
1326 1346 bool back_rendered = false;
1327 if (ep != enc) 1347 if (ep != enc)
1348 {
1349 rxvt_drawable &d2 = d.screen->scratch_drawable (w, h);
1350
1351#ifdef HAVE_BG_PIXMAP
1352 if (term->bgPixmap.pixmap)
1353 {
1354 Picture dst = 0;
1355
1356 if (bg >= 0 && term->pix_colors[bg].c.color.alpha < 0x0ff00)
1357 dst = XftDrawPicture (d2);
1358
1359 if (bg < 0 || dst != 0)
1360 {
1361 int src_x = x, src_y = y ;
1362
1363 if (term->bgPixmap.is_parentOrigin ())
1364 {
1365 src_x += term->window_vt_x;
1366 src_y += term->window_vt_y;
1367 }
1368
1369 if (term->bgPixmap.pmap_width >= src_x+w
1370 && term->bgPixmap.pmap_height >= src_y+h)
1371 {
1372 XCopyArea (disp, term->bgPixmap.pixmap, d2, gc,
1373 src_x, src_y, w, h, 0, 0);
1374 }
1375 else
1376 {
1377 XGCValues gcv;
1378
1379 gcv.fill_style = FillTiled;
1380 gcv.tile = term->bgPixmap.pixmap;
1381 gcv.ts_x_origin = -src_x;
1382 gcv.ts_y_origin = -src_y;
1383
1384 XChangeGC (disp, gc,
1385 GCTile | GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle,
1386 &gcv);
1387
1388 XFillRectangle (disp, d2, gc, 0, 0, w, h);
1389
1390 gcv.fill_style = FillSolid;
1391 XChangeGC (disp, gc, GCFillStyle, &gcv);
1392 }
1393
1394 if (bg >= 0)
1395 {
1396 Picture solid_color_pict = XftDrawSrcPicture (d2, &term->pix_colors[bg].c);
1397 XRenderComposite (disp, PictOpOver, solid_color_pict, None, dst, 0, 0, 0, 0, 0, 0, w, h);
1398 }
1399
1400 back_rendered = true;
1401 }
1402 }
1403#endif
1404
1405 if (bg >= 0 && !back_rendered)
1406 XftDrawRect (d2, &term->pix_colors[bg].c, 0, 0, w, h);
1407
1408 XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, enc, ep - enc);
1409 XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y);
1410 }
1411 else
1412 clear_rect (d, x, y, w, h, bg);
1413 }
1414 else
1415 {
1416 clear_rect (d, x, y, w, h, bg);
1328 XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc); 1417 XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc);
1418 }
1329} 1419}
1420
1330#endif 1421#endif
1331 1422
1332///////////////////////////////////////////////////////////////////////////// 1423/////////////////////////////////////////////////////////////////////////////
1333 1424
1334rxvt_fontset::rxvt_fontset (rxvt_term *term) 1425rxvt_fontset::rxvt_fontset (rxvt_term *term)
1345void 1436void
1346rxvt_fontset::clear () 1437rxvt_fontset::clear ()
1347{ 1438{
1348 prop.width = prop.height = prop.ascent = prop.weight = prop.slant 1439 prop.width = prop.height = prop.ascent = prop.weight = prop.slant
1349 = rxvt_fontprop::unset; 1440 = rxvt_fontprop::unset;
1441 force_prop = false;
1350 1442
1351 for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) 1443 for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++)
1352 FONT_UNREF (*i); 1444 FONT_UNREF (*i);
1353 1445
1354 for (pagemap **p = fmap.begin (); p != fmap.end (); p++) 1446 for (pagemap **p = fmap.begin (); p != fmap.end (); p++)
1363 1455
1364rxvt_font * 1456rxvt_font *
1365rxvt_fontset::new_font (const char *name, codeset cs) 1457rxvt_fontset::new_font (const char *name, codeset cs)
1366{ 1458{
1367 rxvt_font *f; 1459 rxvt_font *f;
1368 1460
1369 if (!name || !*name) 1461 if (!name || !*name)
1370 { 1462 {
1371 name = ""; 1463 name = "";
1372 f = new rxvt_font_default (this); 1464 f = new rxvt_font_default (this);
1373 } 1465 }
1466 if (fonts[i]->loaded) 1558 if (fonts[i]->loaded)
1467 return true; 1559 return true;
1468 1560
1469 fonts[i]->loaded = true; 1561 fonts[i]->loaded = true;
1470 1562
1471 if (!fonts[i]->load (prop)) 1563 if (!fonts[i]->load (prop, force_prop))
1472 { 1564 {
1473 fonts[i]->cs = CS_UNKNOWN; 1565 fonts[i]->cs = CS_UNKNOWN;
1474 return false; 1566 return false;
1475 } 1567 }
1476 1568
1577 FcPatternAddInteger (p, FC_SLANT, prop.slant); 1669 FcPatternAddInteger (p, FC_SLANT, prop.slant);
1578 FcPatternAddBool (p, FC_MINSPACE, 1); 1670 FcPatternAddBool (p, FC_MINSPACE, 1);
1579 //FcPatternAddBool (p, FC_ANTIALIAS, 1); 1671 //FcPatternAddBool (p, FC_ANTIALIAS, 1);
1580 1672
1581 XftResult result; 1673 XftResult result;
1582 FcPattern *match = XftFontMatch (term->xdisp, term->display->screen, p, &result); 1674 FcPattern *match = XftFontMatch (term->dpy, term->display->screen, p, &result);
1583 1675
1584 FcPatternDestroy (p); 1676 FcPatternDestroy (p);
1585 1677
1586 if (match) 1678 if (match)
1587 { 1679 {
1592 if (find_font (font) < 0) 1684 if (find_font (font) < 0)
1593 { 1685 {
1594 char fontname[4096]; 1686 char fontname[4096];
1595 sprintf (fontname, "xft:%-.4090s", font); 1687 sprintf (fontname, "xft:%-.4090s", font);
1596 1688
1597 fonts.push_back (new_font (fontname, CS_UNICODE)); 1689 fonts.push_back (new_font (fontname, CS_UNICODE));
1598 } 1690 }
1599 1691
1600 free (font); 1692 free (font);
1601 } 1693 }
1602#endif 1694#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines