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.123 by ayin, Sat Nov 24 10:32:33 2007 UTC vs.
Revision 1.165 by root, Sat May 22 23:55:56 2010 UTC

1/*----------------------------------------------------------------------* 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-2008 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"
25#include "rxvtutil.h" 24#include "rxvtutil.h"
26#include "rxvtfont.h" 25#include "rxvtfont.h"
27 26
28#include <cstdlib> 27#include <cstdlib>
29 28
80 79
81 // japanese 80 // japanese
82#if ENCODING_JP || ENCODING_JP_EXT 81#if ENCODING_JP || ENCODING_JP_EXT
83# if XFT 82# if XFT
84 // prefer xft for complex scripts 83 // prefer xft for complex scripts
84 { CS_JIS0208_1990_0, "xft:Sazanami Mincho:antialias=false" },
85 { CS_JIS0208_1990_0, "xft:Kochi Gothic:antialias=false" }, 85 { CS_JIS0208_1990_0, "xft:Kochi Gothic:antialias=false" },
86 { CS_JIS0208_1990_0, "xft:Sazanami Mincho:antialias=false" },
87 { CS_JIS0208_1990_0, "xft:Mincho:antialias=false" }, 86 { CS_JIS0208_1990_0, "xft:Mincho:antialias=false" },
88 { CS_JIS0208_1990_0, "xft::lang=ja:antialias=false" }, 87 { CS_JIS0208_1990_0, "xft::lang=ja:antialias=false" },
89# endif 88# endif
90 { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, 89 { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" },
91 { CS_JIS0208_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, 90 { CS_JIS0208_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" },
217: name(0), width(rxvt_fontprop::unset), height(rxvt_fontprop::unset) 216: name(0), width(rxvt_fontprop::unset), height(rxvt_fontprop::unset)
218{ 217{
219} 218}
220 219
221void 220void
222rxvt_font::set_name (char *name) 221rxvt_font::set_name (char *name_)
223{ 222{
224 if (this->name == name) 223 if (name == name_)
225 return; 224 return;
226 225
227 if (this->name) free (this->name); // let the compiler optimize 226 if (name) free (name); // let the compiler optimize
228 this->name = name; 227 name = name_;
229} 228}
230 229
231void 230void
232rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const 231rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const
233{ 232{
237 if (color == Color_bg || color == Color_transparent) 236 if (color == Color_bg || color == Color_transparent)
238 XClearArea (disp, d, x, y, w, h, false); 237 XClearArea (disp, d, x, y, w, h, false);
239 else if (color >= 0) 238 else if (color >= 0)
240 { 239 {
241#if XFT 240#if XFT
242 bool done = false; 241 Picture dst;
242
243#ifdef HAVE_BG_PIXMAP 243# ifdef HAVE_BG_PIXMAP
244 if (term->bgPixmap.pixmap && color >= 0 && term->pix_colors[color].c.color.alpha < 0x0ff00) 244 if (term->bgPixmap.pixmap
245 { 245 && !term->pix_colors[color].is_opaque ()
246 Picture dst = XftDrawPicture (d); 246 && ((dst = XftDrawPicture (d))))
247 if (dst != 0)
248 { 247 {
249 XClearArea (disp, d, x, y, w, h, false); 248 XClearArea (disp, d, x, y, w, h, false);
249
250 Picture solid_color_pict = XftDrawSrcPicture (d, &term->pix_colors[color].c); 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); 251 XRenderComposite (disp, PictOpOver, solid_color_pict, None, dst, 0, 0, 0, 0, x, y, w, h);
252 done = true;
253 } 252 }
254 } 253 else
255#endif 254# endif
256 if (!done)
257 XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h); 255 XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h);
256
258#else 257#else
259 XSetForeground (disp, gc, term->pix_colors[color]); 258 XSetForeground (disp, gc, term->pix_colors[color]);
260 XFillRectangle (disp, d, gc, x, y, w, h); 259 XFillRectangle (disp, d, gc, x, y, w, h);
261#endif 260#endif
262 } 261 }
306 return false; 305 return false;
307 306
308 if (unicode <= 0x009f) 307 if (unicode <= 0x009f)
309 return true; 308 return true;
310 309
310#ifdef BUILTIN_GLYPHS
311 if (unicode >= 0x2500 && unicode <= 0x259f && 311 if (unicode >= 0x2500 && unicode <= 0x259f &&
312 !term->option (Opt_skipBuiltinGlyphs)) 312 !term->option (Opt_skipBuiltinGlyphs))
313 return true; 313 return true;
314#endif
314 315
315 if (IS_COMPOSE (unicode)) 316 if (IS_COMPOSE (unicode))
316 return true; 317 return true;
317 318
318 switch (unicode) 319 switch (unicode)
447 448
448 text_t chrs[2]; 449 text_t chrs[2];
449 chrs [1] = NOCHAR; 450 chrs [1] = NOCHAR;
450 451
451 *chrs = cc->c1; 452 *chrs = cc->c1;
452 rxvt_font *f1 = (*fs)[fs->find_font (cc->c1)]; 453 rxvt_font *f1 = (*fs)[fs->find_font_idx (cc->c1)];
453 f1->draw (d, x, y, chrs, width, fg, bg); 454 f1->draw (d, x, y, chrs, width, fg, bg);
454 455
455 if (cc->c2 != NOCHAR) 456 if (cc->c2 != NOCHAR)
456 { 457 {
457 bool careful; 458 bool careful;
458 459
459 // prefer font of first character, for no good reasons 460 // prefer font of first character, for no good reasons
460 *chrs = cc->c2; 461 *chrs = cc->c2;
461 rxvt_font *f2 = (f1->has_char (cc->c2, 0, careful) && !careful) 462 rxvt_font *f2 = (f1->has_char (cc->c2, 0, careful) && !careful)
462 ? f1 463 ? f1
463 : (*fs)[fs->find_font (cc->c2)]; 464 : (*fs)[fs->find_font_idx (cc->c2)];
464 465
465 f2->draw (d, x, y, chrs, width, fg, Color_none); 466 f2->draw (d, x, y, chrs, width, fg, Color_none);
466 } 467 }
467 } 468 }
468#endif 469#endif
481 482
482 x += fwidth; 483 x += fwidth;
483 } 484 }
484} 485}
485 486
487struct rxvt_font_overflow : rxvt_font {
488 struct rxvt_fontset *fs;
489
490 rxvt_font_overflow (rxvt_fontset *fs)
491 : rxvt_font ()
492 {
493 this->fs = fs;
494 }
495
496 rxvt_fontprop properties ()
497 {
498 rxvt_fontprop p;
499
500 p.width = p.height = 1;
501 p.ascent = rxvt_fontprop::unset;
502 p.weight = rxvt_fontprop::medium;
503 p.slant = rxvt_fontprop::roman;
504
505 return p;
506 }
507
508 bool load (const rxvt_fontprop &prop, bool force_prop)
509 {
510 width = 1; height = 1;
511 ascent = 1; descent = 0;
512
513 set_name (strdup ("built-in rendition overflow font"));
514
515 return true;
516 }
517
518 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
519 {
520 return false;
521 }
522
523 void draw (rxvt_drawable &d, int x, int y,
524 const text_t *text, int len,
525 int fg, int bg)
526 {
527 while (len--)
528 {
529 int fid = fs->find_font_idx (*text);
530 (*fs)[fid]->draw (d, x, y, text, 1, fg, bg);
531 ++text;
532 x += term->fwidth;
533 }
534 }
535};
536
486///////////////////////////////////////////////////////////////////////////// 537/////////////////////////////////////////////////////////////////////////////
487 538
488struct rxvt_font_x11 : rxvt_font { 539struct rxvt_font_x11 : rxvt_font {
489 rxvt_font_x11 () { f = 0; } 540 rxvt_font_x11 () { f = 0; }
490 541
498 549
499 void draw (rxvt_drawable &d, int x, int y, 550 void draw (rxvt_drawable &d, int x, int y,
500 const text_t *text, int len, 551 const text_t *text, int len,
501 int fg, int bg); 552 int fg, int bg);
502 553
503 bool slow; // wether this is a proportional font or has other funny characteristics 554 bool slow; // whether this is a proportional font or has other funny characteristics
504 XFontStruct *f; 555 XFontStruct *f;
505 bool enc2b, encm; 556 bool enc2b, encm;
506 557
507 char *get_property (XFontStruct *f, Atom property, const char *repl) const; 558 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); 559 bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth);
608 return false; 659 return false;
609} 660}
610 661
611// fix the size of scalable fonts 662// fix the size of scalable fonts
612static bool 663static bool
613replace_field (char *buf, const char *name, int index, const char old, const char *replace) 664replace_field (char **ptr, const char *name, int index, const char old, const char *replace)
614{ 665{
615 int slashes = 0; 666 int slashes = 0;
616 const char *field, *end; 667 const char *field, *end;
617 668
618 for (const char *c = name; *c; c++) 669 for (const char *c = name; *c; c++)
628 break; 679 break;
629 } 680 }
630 681
631 if (slashes >= 13 && (!old || *field == old)) 682 if (slashes >= 13 && (!old || *field == old))
632 { 683 {
633 // TODO: check for overflow in font-name 684 size_t len = field - name;
634 strncpy (buf, name, field - name); 685 *ptr = (char *)malloc (len + strlen (replace) + strlen (end) + 1);
635 buf += field - name; 686 memcpy (*ptr, name, len);
636 strcpy (buf, replace); 687 strcpy (*ptr + len, replace);
637 strcat (buf, end); 688 strcat (*ptr, end);
638 689
639 return true; 690 return true;
640 } 691 }
641 else 692 else
642 { 693 {
643 strcpy (buf, name); 694 *ptr = strdup (name);
644 695
645 return false; 696 return false;
646 } 697 }
647} 698}
648 699
656 char field_str[64]; // enough for 128 bits 707 char field_str[64]; // enough for 128 bits
657 708
658 // first morph the font if required 709 // first morph the font if required
659 if (force_prop) 710 if (force_prop)
660 { 711 {
661 char fname[1024]; 712 char *fname;
662 713
663 if (name[0] != '-') 714 if (name[0] != '-')
664 { 715 {
665 f = XLoadQueryFont (disp, name); 716 f = XLoadQueryFont (disp, name);
666 717
678 f = 0; 729 f = 0;
679 } 730 }
680 731
681 if (prop.weight != rxvt_fontprop::unset) 732 if (prop.weight != rxvt_fontprop::unset)
682 { 733 {
683 replace_field (fname, name, 2, 0, 734 replace_field (&fname, name, 2, 0,
684 prop.weight < rxvt_fontprop::bold 735 prop.weight < rxvt_fontprop::bold
685 ? "medium" : "bold"); 736 ? "medium" : "bold");
686 set_name (strdup (fname)); 737 set_name (fname);
687 } 738 }
688 739
689 if (prop.slant != rxvt_fontprop::unset) 740 if (prop.slant != rxvt_fontprop::unset)
690 { 741 {
691 replace_field (fname, name, 3, 0, 742 replace_field (&fname, name, 3, 0,
692 prop.slant < rxvt_fontprop::italic 743 prop.slant < rxvt_fontprop::italic
693 ? "r" : "i"); // TODO: handle "o"blique, too 744 ? "r" : "i"); // TODO: handle "o"blique, too
694 set_name (strdup (fname)); 745 set_name (fname);
695 } 746 }
696 } 747 }
697 748
698 sprintf (field_str, "%d", prop.height == rxvt_fontprop::unset 749 sprintf (field_str, "%d", prop.height == rxvt_fontprop::unset
699 ? 0 : prop.height); 750 ? 0 : prop.height);
724 font_weight *fonts = new font_weight[count]; 775 font_weight *fonts = new font_weight[count];
725 776
726 for (int i = 0; i < count; i++) 777 for (int i = 0; i < count; i++)
727 { 778 {
728 rxvt_fontprop p; 779 rxvt_fontprop p;
729 char fname[1024]; 780 char *fname;
730 781
731 int diff = 0; 782 int diff = 0;
732 783
733 if (replace_field (fname, list[i], 6, '0', field_str)) 784 if (replace_field (&fname, list[i], 6, '0', field_str))
734 diff += 10; // slightly penalize scalable fonts 785 diff += 10; // slightly penalize scalable fonts
786 else
787 {
788 free (fname);
735 else if (replace_field (fname, list[i], 11, '0', "0")) 789 if (replace_field (&fname, list[i], 11, '0', "0"))
736 diff += 300; // more heavily penalize what looks like scaled bitmap fonts 790 diff += 300; // more heavily penalize what looks like scaled bitmap fonts
791 }
737 792
738 if (!set_properties (p, fname)) 793 if (!set_properties (p, fname))
739 continue; 794 continue;
740 795
741 if (prop.height != rxvt_fontprop::unset 796 if (prop.height != rxvt_fontprop::unset
745 if (prop.height != rxvt_fontprop::unset) diff += (prop.height - p.height) * 128; 800 if (prop.height != rxvt_fontprop::unset) diff += (prop.height - p.height) * 128;
746 if (prop.weight != rxvt_fontprop::unset) diff += abs (prop.weight - p.weight); 801 if (prop.weight != rxvt_fontprop::unset) diff += abs (prop.weight - p.weight);
747 if (prop.slant != rxvt_fontprop::unset) diff += abs (prop.slant - p.slant); 802 if (prop.slant != rxvt_fontprop::unset) diff += abs (prop.slant - p.slant);
748 //if (prop.width != rxvt_fontprop::unset) diff += abs (prop.width - p.width); 803 //if (prop.width != rxvt_fontprop::unset) diff += abs (prop.width - p.width);
749 804
750 fonts[i].name = strdup (fname); 805 fonts[i].name = fname;
751 fonts[i].diff = diff; 806 fonts[i].diff = diff;
752 } 807 }
753 808
754 XFreeFontNames (list); 809 XFreeFontNames (list);
755 810
787 return false; 842 return false;
788 843
789 char *registry = get_property (f, term->xa [XA_CHARSET_REGISTRY], 0); 844 char *registry = get_property (f, term->xa [XA_CHARSET_REGISTRY], 0);
790 char *encoding = get_property (f, term->xa [XA_CHARSET_ENCODING], 0); 845 char *encoding = get_property (f, term->xa [XA_CHARSET_ENCODING], 0);
791 846
847 cs = CS_UNKNOWN;
848
792 if (registry && encoding) 849 if (registry && encoding)
793 { 850 {
794 char charset[64]; 851 char charset[64];
795 snprintf (charset, 64, "%s-%s", registry, encoding); 852 snprintf (charset, 64, "%s-%s", registry, encoding);
796 853
797 cs = codeset_from_name (charset); 854 cs = codeset_from_name (charset);
855
856 if (cs == CS_UNKNOWN)
857 rxvt_warn ("%s: cannot deduce encoding from registry/encoding properties \"%s\", ignoring font.\n", name, charset);
798 } 858 }
799 else 859
860 free (registry);
861 free (encoding);
862
863 if (cs == CS_UNKNOWN)
800 { 864 {
801 const char *charset = get_property (f, XA_FONT, 0); 865 const char *charset = get_property (f, XA_FONT, 0);
802 866
803 if (!charset) 867 if (!charset)
804 charset = name; 868 charset = name;
807 while (*charset) 871 while (*charset)
808 if (*charset++ == '-' && !--count) 872 if (*charset++ == '-' && !--count)
809 break; 873 break;
810 874
811 cs = codeset_from_name (charset); 875 cs = codeset_from_name (charset);
876 if (cs == CS_UNKNOWN)
877 rxvt_warn ("%s: cannot deduce encoding from font name property \"%s\", ignoring font.\n", name, charset);
878 }
879
880 if (cs == CS_UNKNOWN)
812 } 881 {
813 882 clear ();
814 free (registry); 883 return false;
815 free (encoding); 884 }
816 885
817 if (cs == CS_UNICODE) 886 if (cs == CS_UNICODE)
818 cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font 887 cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font
819 888
820 encm = f->min_byte1 != 0 || f->max_byte1 != 0; 889 encm = f->min_byte1 != 0 || f->max_byte1 != 0;
867 if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; 936 if (wcw > 0) g.width = (g.width + wcw - 1) / wcw;
868 937
869 if (width < g.width) width = g.width; 938 if (width < g.width) width = g.width;
870 } 939 }
871 940
872 if (cs == CS_UNKNOWN) 941#if 0 // do it per-character
942 if (prop && width > prop->width)
873 { 943 {
874 fprintf (stderr, "unable to deduce codeset, ignoring font '%s'\n", name);
875
876 clear (); 944 clear ();
877 return false; 945 return false;
878 } 946 }
879
880#if 0 // do it per-character
881 if (prop && width > prop->width)
882 {
883 clear ();
884 return false;
885 }
886#endif 947#endif
887 948
888 return true; 949 return true;
889} 950}
890 951
904 uint32_t ch = FROM_UNICODE (cs, unicode); 965 uint32_t ch = FROM_UNICODE (cs, unicode);
905 966
906 if (ch == NOCHAR) 967 if (ch == NOCHAR)
907 return false; 968 return false;
908 969
909 /* check wether the character exists in _this_ font. horrible. */ 970 /* check whether the character exists in _this_ font. horrible. */
910 XCharStruct *xcs; 971 XCharStruct *xcs;
911 972
912 if (encm) 973 if (encm)
913 { 974 {
914 unsigned char byte1 = ch >> 8; 975 unsigned char byte1 = ch >> 8;
944 return false; 1005 return false;
945 1006
946 if (!prop || prop->width == rxvt_fontprop::unset) 1007 if (!prop || prop->width == rxvt_fontprop::unset)
947 return true; 1008 return true;
948 1009
949 // check wether character overlaps previous/next character 1010 // check whether character overlaps previous/next character
950 int w = xcs->rbearing - xcs->lbearing; 1011 int w = xcs->rbearing - xcs->lbearing;
951 int wcw = max (WCWIDTH (unicode), 1); 1012 int wcw = max (WCWIDTH (unicode), 1);
952 1013
953 careful = xcs->lbearing < 0 || xcs->rbearing > prop->width * wcw; 1014 careful = xcs->lbearing < 0 || xcs->rbearing > prop->width * wcw;
954 1015
1128 FcPatternAddInteger (p, FC_SLANT, prop.slant); 1189 FcPatternAddInteger (p, FC_SLANT, prop.slant);
1129 1190
1130#if 0 // clipping unfortunately destroys our precious double-width-characters 1191#if 0 // clipping unfortunately destroys our precious double-width-characters
1131 // clip width, we can't do better, or can we? 1192 // clip width, we can't do better, or can we?
1132 if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) 1193 if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch)
1133 FcPatternAddInteger (p, FC_CHAR_WIDTH, prop->width); 1194 FcPatternAddInteger (p, FC_CHAR_WIDTH, prop.width);
1134#endif 1195#endif
1135 1196
1136 if (FcPatternGet (p, FC_MINSPACE, 0, &v) != FcResultMatch) 1197 if (FcPatternGet (p, FC_MINSPACE, 0, &v) != FcResultMatch)
1137 FcPatternAddBool (p, FC_MINSPACE, 1); 1198 FcPatternAddBool (p, FC_MINSPACE, 1);
1138 1199
1282rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, 1343rxvt_font_xft::draw (rxvt_drawable &d, int x, int y,
1283 const text_t *text, int len, 1344 const text_t *text, int len,
1284 int fg, int bg) 1345 int fg, int bg)
1285{ 1346{
1286 XGlyphInfo extents; 1347 XGlyphInfo extents;
1287 XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec)); 1348 XftGlyphSpec *enc = rxvt_temp_buf<XftGlyphSpec> (len);
1288 XftGlyphSpec *ep = enc; 1349 XftGlyphSpec *ep = enc;
1289 1350
1290 dTermDisplay; 1351 dTermDisplay;
1291 dTermGC; 1352 dTermGC;
1292 1353
1293 int w = term->fwidth * len; 1354 int w = term->fwidth * len;
1294 int h = term->fheight; 1355 int h = term->fheight;
1295 1356
1296 /* TODO: this logic needs some more thinking, since we no longer do pseudo-transparency. 1357 bool buffered = bg >= Color_transparent
1297 * Maybe make buffering into a resource flag? Compile time option doesn't seems like a 1358 && term->option (Opt_buffered);
1298 * good idea from the perspective of packaging for wide variety of user configs. 1359
1299 */
1300 bool buffered = true
1301#ifdef FORCE_UNBUFFERED_XFT
1302 && bg >= 0
1303#endif
1304 ;
1305 // cut trailing spaces 1360 // cut trailing spaces
1306 while (len && text [len - 1] == ' ') 1361 while (len && text [len - 1] == ' ')
1307 len--; 1362 len--;
1308 1363
1309 int x_ = buffered ? 0 : x; 1364 int x_ = buffered ? 0 : x;
1335 x_ += cwidth; 1390 x_ += cwidth;
1336 } 1391 }
1337 1392
1338 if (buffered) 1393 if (buffered)
1339 { 1394 {
1340 bool back_rendered = false;
1341 if (ep != enc) 1395 if (ep != enc)
1342 { 1396 {
1343 rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); 1397 rxvt_drawable &d2 = d.screen->scratch_drawable (w, h);
1344 1398
1345#ifdef HAVE_BG_PIXMAP 1399#ifdef HAVE_BG_PIXMAP
1400 Picture dst = 0; // the only assignment is done conditionally in the following if condition
1401
1346 if (term->bgPixmap.pixmap) 1402 if (term->bgPixmap.pixmap
1403 && (bg == Color_transparent || bg == Color_bg
1404 || (bg >= 0 && !term->pix_colors[bg].is_opaque () && ((dst = XftDrawPicture (d2))))))
1347 { 1405 {
1348 Picture dst = 0; 1406 int src_x = x, src_y = y;
1349 1407
1350 if (bg >= 0 && term->pix_colors[bg].c.color.alpha < 0x0ff00) 1408 if (term->bgPixmap.is_parentOrigin ())
1351 dst = XftDrawPicture (d2);
1352
1353 if (bg < 0 || dst != 0)
1354 { 1409 {
1355 int src_x = x, src_y = y ;
1356
1357 if (term->bgPixmap.is_parentOrigin ())
1358 {
1359 src_x += term->window_vt_x; 1410 src_x += term->window_vt_x;
1360 src_y += term->window_vt_y; 1411 src_y += term->window_vt_y;
1361 } 1412 }
1362 1413
1363 if (term->bgPixmap.pmap_width >= src_x+w 1414 if (term->bgPixmap.pmap_width >= src_x + w
1364 && term->bgPixmap.pmap_height >= src_y+h) 1415 && term->bgPixmap.pmap_height >= src_y + h)
1365 { 1416 {
1366 XCopyArea (disp, term->bgPixmap.pixmap, d2, gc, 1417 XCopyArea (disp, term->bgPixmap.pixmap, d2, gc,
1367 src_x, src_y, w, h, 0, 0); 1418 src_x, src_y, w, h, 0, 0);
1368 } 1419 }
1369 else 1420 else
1370 { 1421 {
1371 XGCValues gcv; 1422 XGCValues gcv;
1372 1423
1373 gcv.fill_style = FillTiled; 1424 gcv.fill_style = FillTiled;
1374 gcv.tile = term->bgPixmap.pixmap; 1425 gcv.tile = term->bgPixmap.pixmap;
1375 gcv.ts_x_origin = -src_x; 1426 gcv.ts_x_origin = -src_x;
1376 gcv.ts_y_origin = -src_y; 1427 gcv.ts_y_origin = -src_y;
1377 1428
1378 XChangeGC (disp, gc, 1429 XChangeGC (disp, gc,
1379 GCTile | GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle, 1430 GCTile | GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle,
1380 &gcv); 1431 &gcv);
1381 1432
1382 XFillRectangle (disp, d2, gc, 0, 0, w, h); 1433 XFillRectangle (disp, d2, gc, 0, 0, w, h);
1383 1434
1384 gcv.fill_style = FillSolid; 1435 gcv.fill_style = FillSolid;
1385 XChangeGC (disp, gc, GCFillStyle, &gcv); 1436 XChangeGC (disp, gc, GCFillStyle, &gcv);
1386 } 1437 }
1387 1438
1388 if (bg >= 0) 1439 if (dst)
1389 { 1440 {
1390 Picture solid_color_pict = XftDrawSrcPicture (d2, &term->pix_colors[bg].c); 1441 Picture solid_color_pict = XftDrawSrcPicture (d2, &term->pix_colors[bg].c);
1442
1443 // dst can only be set when bg >= 0
1391 XRenderComposite (disp, PictOpOver, solid_color_pict, None, dst, 0, 0, 0, 0, 0, 0, w, h); 1444 XRenderComposite (disp, PictOpOver, solid_color_pict, None, dst, 0, 0, 0, 0, 0, 0, w, h);
1392 }
1393
1394 back_rendered = true;
1395 } 1445 }
1396 } 1446 }
1447 else
1397#endif 1448#endif
1398
1399 if (bg >= 0 && !back_rendered)
1400 XftDrawRect (d2, &term->pix_colors[bg].c, 0, 0, w, h); 1449 XftDrawRect (d2, &term->pix_colors[bg >= 0 ? bg : Color_bg].c, 0, 0, w, h);
1401 1450
1402 XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, enc, ep - enc); 1451 XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, enc, ep - enc);
1403 XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y); 1452 XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y);
1404 } 1453 }
1405 else 1454 else
1433 prop.width = prop.height = prop.ascent = prop.weight = prop.slant 1482 prop.width = prop.height = prop.ascent = prop.weight = prop.slant
1434 = rxvt_fontprop::unset; 1483 = rxvt_fontprop::unset;
1435 force_prop = false; 1484 force_prop = false;
1436 1485
1437 for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) 1486 for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++)
1438 FONT_UNREF (*i); 1487 (*i)->unref ();
1439 1488
1440 for (pagemap **p = fmap.begin (); p != fmap.end (); p++) 1489 for (pagemap **p = fmap.begin (); p != fmap.end (); p++)
1441 delete *p; 1490 delete *p;
1442 1491
1443 free (fontdesc); fontdesc = 0; 1492 free (fontdesc); fontdesc = 0;
1445 fonts.clear (); 1494 fonts.clear ();
1446 1495
1447 fallback = fallback_fonts; 1496 fallback = fallback_fonts;
1448} 1497}
1449 1498
1499void
1500rxvt_fontset::prepare_font (rxvt_font *font, codeset cs)
1501{
1502 font->set_term (term);
1503
1504 font->cs = cs;
1505 font->loaded = false;
1506}
1507
1450rxvt_font * 1508rxvt_font *
1451rxvt_fontset::new_font (const char *name, codeset cs) 1509rxvt_fontset::new_font (const char *name, codeset cs)
1452{ 1510{
1453 rxvt_font *f; 1511 rxvt_font *f;
1454 1512
1470 f = new rxvt_font_x11; 1528 f = new rxvt_font_x11;
1471 } 1529 }
1472 else 1530 else
1473 f = new rxvt_font_x11; 1531 f = new rxvt_font_x11;
1474 1532
1475 f->set_term (term);
1476 f->set_name (strdup (name)); 1533 f->set_name (strdup (name));
1477 1534 prepare_font (f, cs);
1478 f->cs = cs;
1479 f->loaded = false;
1480 1535
1481 return f; 1536 return f;
1482} 1537}
1483 1538
1484///////////////////////////////////////////////////////////////////////////// 1539/////////////////////////////////////////////////////////////////////////////
1540
1541void
1542rxvt_fontset::push_font (rxvt_font *font)
1543{
1544 // the fontCount index is reserved for the overflow font, it is only
1545 // necessary when we get fontCount or more fonts, as they cannot be
1546 // represented in the rendition.
1547 if (fonts.size () == fontCount)
1548 {
1549 rxvt_font *f = new rxvt_font_overflow (this);
1550
1551 prepare_font (f, CS_UNICODE);
1552 fonts.push_back (f);
1553 }
1554
1555 fonts.push_back (font);
1556}
1485 1557
1486void 1558void
1487rxvt_fontset::add_fonts (const char *desc) 1559rxvt_fontset::add_fonts (const char *desc)
1488{ 1560{
1489 if (desc) 1561 if (desc)
1527 if (!end) 1599 if (!end)
1528 end = desc + strlen (desc); 1600 end = desc + strlen (desc);
1529 1601
1530 if (end - desc < 511) 1602 if (end - desc < 511)
1531 { 1603 {
1532 strncpy (buf, desc, end - desc); 1604 memcpy (buf, desc, end - desc);
1533 buf[end - desc] = 0; 1605 buf[end - desc] = 0;
1534 1606
1535 fonts.push_back (new_font (buf, cs)); 1607 push_font (new_font (buf, cs));
1536 } 1608 }
1537 else 1609 else
1538 rxvt_warn ("fontset element too long (>511 bytes), ignored."); 1610 rxvt_warn ("fontset element too long (>511 bytes), ignored.");
1539 1611
1540 desc = end + 1; 1612 desc = end + 1;
1568{ 1640{
1569 clear (); 1641 clear ();
1570 1642
1571 fontdesc = strdup (desc); 1643 fontdesc = strdup (desc);
1572 1644
1573 fonts.push_back (new_font (0, CS_UNICODE)); 1645 push_font (new_font (0, CS_UNICODE));
1574 realize_font (0); 1646 realize_font (0);
1575 1647
1576 add_fonts (desc); 1648 add_fonts (desc);
1577 1649
1578 return true; 1650 return true;
1587 1659
1588 return -1; 1660 return -1;
1589} 1661}
1590 1662
1591int 1663int
1592rxvt_fontset::find_font (unicode_t unicode) 1664rxvt_fontset::find_font_idx (unicode_t unicode)
1593{ 1665{
1594 if (unicode >= 1<<20) 1666 if (unicode >= 1<<20)
1595 return 0; 1667 return 0;
1596 1668
1597 unicode_t hi = unicode >> 8; 1669 unicode_t hi = unicode >> 8;
1623 goto next_font; 1695 goto next_font;
1624 1696
1625 bool careful; 1697 bool careful;
1626 if (f->has_char (unicode, &prop, careful)) 1698 if (f->has_char (unicode, &prop, careful))
1627 { 1699 {
1628 if (careful) 1700 i = (i << 1) | careful;
1629 i |= 128;
1630 1701
1631 goto found; 1702 goto found;
1632 } 1703 }
1633 1704
1634 next_font: 1705 next_font:
1635 if (i == fonts.size () - 1) 1706 if (i == fonts.size () - 1)
1636 { 1707 {
1637 if (fallback->name) 1708 if (fallback->name)
1638 { 1709 {
1639 // search through the fallback list 1710 // search through the fallback list
1640 fonts.push_back (new_font (fallback->name, fallback->cs)); 1711 push_font (new_font (fallback->name, fallback->cs));
1641 fallback++; 1712 fallback++;
1642 } 1713 }
1643 else 1714 else
1644 { 1715 {
1645 // try to find a new font. 1716 // try to find a new font.
1676 FcPatternDestroy (match); 1747 FcPatternDestroy (match);
1677 1748
1678 if (find_font (font) < 0) 1749 if (find_font (font) < 0)
1679 { 1750 {
1680 char fontname[4096]; 1751 char fontname[4096];
1681 sprintf (fontname, "xft:%-.4090s", font); 1752 snprintf (fontname, sizeof (fontname), "xft:%s", font);
1682 1753
1683 fonts.push_back (new_font (fontname, CS_UNICODE)); 1754 push_font (new_font (fontname, CS_UNICODE));
1684 } 1755 }
1685 1756
1686 free (font); 1757 free (font);
1687 } 1758 }
1688#endif 1759#endif
1710 } 1781 }
1711 1782
1712 return i; 1783 return i;
1713} 1784}
1714 1785
1715
1716

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines