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.121 by ayin, Sun Oct 28 11:25:04 2007 UTC vs.
Revision 1.161 by root, Wed Mar 31 22:22:32 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
43 const char *name; 42 const char *name;
44} fallback_fonts[] = { 43} fallback_fonts[] = {
45 { CS_ISO8859_1, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-1" }, 44 { CS_ISO8859_1, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-1" },
46 { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-15" }, 45 { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-15" },
47 { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-fcd8859-15" }, 46 { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-fcd8859-15" },
48 47
49#if ENCODING_EU 48#if ENCODING_EU
50 // cyrillic 49 // cyrillic
51 { CS_KOI8_R, "-*-*-*-r-*--*-*-*-*-c-*-koi8-r" }, 50 { CS_KOI8_R, "-*-*-*-r-*--*-*-*-*-c-*-koi8-r" },
52 { CS_KOI8_U, "-*-*-*-r-*--*-*-*-*-c-*-koi8-u" }, 51 { CS_KOI8_U, "-*-*-*-r-*--*-*-*-*-c-*-koi8-u" },
53 52
54 { CS_ISO8859_2, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-2" }, 53 { CS_ISO8859_2, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-2" },
55 { CS_ISO8859_3, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-3" }, 54 { CS_ISO8859_3, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-3" },
56 { CS_ISO8859_4, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-4" }, 55 { CS_ISO8859_4, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-4" },
57 { CS_ISO8859_5, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-5" }, 56 { CS_ISO8859_5, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-5" },
58 { CS_ISO8859_6, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-6" }, 57 { CS_ISO8859_6, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-6" },
65 { CS_ISO8859_14, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-14" }, 64 { CS_ISO8859_14, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-14" },
66 { CS_ISO8859_16, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-16" }, 65 { CS_ISO8859_16, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-16" },
67 66
68# if XFT 67# if XFT
69 { CS_KOI8_U, "xft::lang=ru" }, 68 { CS_KOI8_U, "xft::lang=ru" },
70 69
71 { CS_ISO8859_5, "xft::lang=ru" }, 70 { CS_ISO8859_5, "xft::lang=ru" },
72 { CS_ISO8859_6, "xft::lang=ar" }, 71 { CS_ISO8859_6, "xft::lang=ar" },
73 { CS_ISO8859_7, "xft::lang=el" }, 72 { CS_ISO8859_7, "xft::lang=el" },
74 { CS_ISO8859_8, "xft::lang=he" }, 73 { CS_ISO8859_8, "xft::lang=he" },
75 { CS_ISO8859_9, "xft::lang=tr" }, 74 { CS_ISO8859_9, "xft::lang=tr" },
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{
234 dTermDisplay; 233 dTermDisplay;
235 dTermGC; 234 dTermGC;
236 235
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 }
263} 262}
264 263
265///////////////////////////////////////////////////////////////////////////// 264/////////////////////////////////////////////////////////////////////////////
266
267#include "table/linedraw.h"
268 265
269struct rxvt_font_default : rxvt_font { 266struct rxvt_font_default : rxvt_font {
270 struct rxvt_fontset *fs; 267 struct rxvt_fontset *fs;
271 268
272 rxvt_font_default (rxvt_fontset *fs) 269 rxvt_font_default (rxvt_fontset *fs)
308 return false; 305 return false;
309 306
310 if (unicode <= 0x009f) 307 if (unicode <= 0x009f)
311 return true; 308 return true;
312 309
310#ifdef BUILTIN_GLYPHS
313 if (unicode >= 0x2500 && unicode <= 0x259f && 311 if (unicode >= 0x2500 && unicode <= 0x259f &&
314 !term->option (Opt_skipBuiltinGlyphs)) 312 !term->option (Opt_skipBuiltinGlyphs))
315 return true; 313 return true;
314#endif
316 315
317 if (IS_COMPOSE (unicode)) 316 if (IS_COMPOSE (unicode))
318 return true; 317 return true;
319 318
320 switch (unicode) 319 switch (unicode)
356 ; 355 ;
357 356
358 int width = text - tp; 357 int width = text - tp;
359 int fwidth = term->fwidth * width; 358 int fwidth = term->fwidth * width;
360 359
360#ifdef BUILTIN_GLYPHS
361 if (0x2500 <= t && t <= 0x259f) 361 if (0x2500 <= t && t <= 0x259f)
362 { 362 {
363# include "table/linedraw.h"
363 uint16_t offs = linedraw_offs[t - 0x2500]; 364 uint16_t offs = linedraw_offs[t - 0x2500];
364 uint32_t *a = linedraw_command + (offs >> 4); 365 uint32_t *a = linedraw_command + (offs >> 4);
365 uint32_t *b = a + (offs & 15); 366 uint32_t *b = a + (offs & 15);
366 367
367 int W = fwidth; 368 int W = fwidth;
405 406
406 case 1: // rectangle, possibly stippled 407 case 1: // rectangle, possibly stippled
407 if (a) 408 if (a)
408 { 409 {
409 static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; 410 static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 };
410 411
411 gcv.fill_style = FillStippled; 412 gcv.fill_style = FillStippled;
412 gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2); 413 gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2);
413 gcv.ts_x_origin = x; 414 gcv.ts_x_origin = x;
414 gcv.ts_y_origin = y; 415 gcv.ts_y_origin = y;
415 416
434 (a - 1) * 90*64, (b - 1) * 90*64); 435 (a - 1) * 90*64, (b - 1) * 90*64);
435 break; 436 break;
436 } 437 }
437 } 438 }
438 } 439 }
440#else
441 if (0)
442 ;
443#endif
439#if ENABLE_COMBINING 444#if ENABLE_COMBINING
440 else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) 445 else if (IS_COMPOSE (t) && (cc = rxvt_composite[t]))
441 { 446 {
442 min_it (width, 2); // we only support wcwidth up to 2 447 min_it (width, 2); // we only support wcwidth up to 2
443 448
477 482
478 x += fwidth; 483 x += fwidth;
479 } 484 }
480} 485}
481 486
487struct rxvt_font_meta : rxvt_font {
488 struct rxvt_fontset *fs;
489
490 rxvt_font_meta (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 meta 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
482///////////////////////////////////////////////////////////////////////////// 537/////////////////////////////////////////////////////////////////////////////
483 538
484struct rxvt_font_x11 : rxvt_font { 539struct rxvt_font_x11 : rxvt_font {
485 rxvt_font_x11 () { f = 0; } 540 rxvt_font_x11 () { f = 0; }
486 541
494 549
495 void draw (rxvt_drawable &d, int x, int y, 550 void draw (rxvt_drawable &d, int x, int y,
496 const text_t *text, int len, 551 const text_t *text, int len,
497 int fg, int bg); 552 int fg, int bg);
498 553
499 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
500 XFontStruct *f; 555 XFontStruct *f;
501 bool enc2b, encm; 556 bool enc2b, encm;
502 557
503 char *get_property (XFontStruct *f, Atom property, const char *repl) const; 558 char *get_property (XFontStruct *f, Atom property, const char *repl) const;
504 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);
604 return false; 659 return false;
605} 660}
606 661
607// fix the size of scalable fonts 662// fix the size of scalable fonts
608static bool 663static bool
609replace_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)
610{ 665{
611 int slashes = 0; 666 int slashes = 0;
612 const char *field, *end; 667 const char *field, *end;
613 668
614 for (const char *c = name; *c; c++) 669 for (const char *c = name; *c; c++)
624 break; 679 break;
625 } 680 }
626 681
627 if (slashes >= 13 && (!old || *field == old)) 682 if (slashes >= 13 && (!old || *field == old))
628 { 683 {
629 // TODO: check for overflow in font-name 684 size_t len = field - name;
630 strncpy (buf, name, field - name); 685 *ptr = (char *)malloc (len + strlen (replace) + strlen (end) + 1);
631 buf += field - name; 686 memcpy (*ptr, name, len);
632 strcpy (buf, replace); 687 strcpy (*ptr + len, replace);
633 strcat (buf, end); 688 strcat (*ptr, end);
634 689
635 return true; 690 return true;
636 } 691 }
637 else 692 else
638 { 693 {
639 strcpy (buf, name); 694 *ptr = strdup (name);
640 695
641 return false; 696 return false;
642 } 697 }
643} 698}
644 699
652 char field_str[64]; // enough for 128 bits 707 char field_str[64]; // enough for 128 bits
653 708
654 // first morph the font if required 709 // first morph the font if required
655 if (force_prop) 710 if (force_prop)
656 { 711 {
657 char fname[1024]; 712 char *fname;
658 713
659 if (name[0] != '-') 714 if (name[0] != '-')
660 { 715 {
661 f = XLoadQueryFont (disp, name); 716 f = XLoadQueryFont (disp, name);
662 717
674 f = 0; 729 f = 0;
675 } 730 }
676 731
677 if (prop.weight != rxvt_fontprop::unset) 732 if (prop.weight != rxvt_fontprop::unset)
678 { 733 {
679 replace_field (fname, name, 2, 0, 734 replace_field (&fname, name, 2, 0,
680 prop.weight < rxvt_fontprop::bold 735 prop.weight < rxvt_fontprop::bold
681 ? "medium" : "bold"); 736 ? "medium" : "bold");
682 set_name (strdup (fname)); 737 set_name (fname);
683 } 738 }
684 739
685 if (prop.slant != rxvt_fontprop::unset) 740 if (prop.slant != rxvt_fontprop::unset)
686 { 741 {
687 replace_field (fname, name, 3, 0, 742 replace_field (&fname, name, 3, 0,
688 prop.slant < rxvt_fontprop::italic 743 prop.slant < rxvt_fontprop::italic
689 ? "r" : "i"); // TODO: handle "o"blique, too 744 ? "r" : "i"); // TODO: handle "o"blique, too
690 set_name (strdup (fname)); 745 set_name (fname);
691 } 746 }
692 } 747 }
693 748
694 sprintf (field_str, "%d", prop.height == rxvt_fontprop::unset 749 sprintf (field_str, "%d", prop.height == rxvt_fontprop::unset
695 ? 0 : prop.height); 750 ? 0 : prop.height);
720 font_weight *fonts = new font_weight[count]; 775 font_weight *fonts = new font_weight[count];
721 776
722 for (int i = 0; i < count; i++) 777 for (int i = 0; i < count; i++)
723 { 778 {
724 rxvt_fontprop p; 779 rxvt_fontprop p;
725 char fname[1024]; 780 char *fname;
726 781
727 int diff = 0; 782 int diff = 0;
728 783
729 if (replace_field (fname, list[i], 6, '0', field_str)) 784 if (replace_field (&fname, list[i], 6, '0', field_str))
730 diff += 10; // slightly penalize scalable fonts 785 diff += 10; // slightly penalize scalable fonts
786 else
787 {
788 free (fname);
731 else if (replace_field (fname, list[i], 11, '0', "0")) 789 if (replace_field (&fname, list[i], 11, '0', "0"))
732 diff += 300; // more heavily penalize what looks like scaled bitmap fonts 790 diff += 300; // more heavily penalize what looks like scaled bitmap fonts
791 }
733 792
734 if (!set_properties (p, fname)) 793 if (!set_properties (p, fname))
735 continue; 794 continue;
736 795
737 if (prop.height != rxvt_fontprop::unset 796 if (prop.height != rxvt_fontprop::unset
741 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;
742 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);
743 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);
744 //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);
745 804
746 fonts[i].name = strdup (fname); 805 fonts[i].name = fname;
747 fonts[i].diff = diff; 806 fonts[i].diff = diff;
748 } 807 }
749 808
750 XFreeFontNames (list); 809 XFreeFontNames (list);
751 810
783 return false; 842 return false;
784 843
785 char *registry = get_property (f, term->xa [XA_CHARSET_REGISTRY], 0); 844 char *registry = get_property (f, term->xa [XA_CHARSET_REGISTRY], 0);
786 char *encoding = get_property (f, term->xa [XA_CHARSET_ENCODING], 0); 845 char *encoding = get_property (f, term->xa [XA_CHARSET_ENCODING], 0);
787 846
847 cs = CS_UNKNOWN;
848
788 if (registry && encoding) 849 if (registry && encoding)
789 { 850 {
790 char charset[64]; 851 char charset[64];
791 snprintf (charset, 64, "%s-%s", registry, encoding); 852 snprintf (charset, 64, "%s-%s", registry, encoding);
792 853
793 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);
794 } 858 }
795 else 859
860 free (registry);
861 free (encoding);
862
863 if (cs == CS_UNKNOWN)
796 { 864 {
797 const char *charset = get_property (f, XA_FONT, 0); 865 const char *charset = get_property (f, XA_FONT, 0);
798 866
799 if (!charset) 867 if (!charset)
800 charset = name; 868 charset = name;
803 while (*charset) 871 while (*charset)
804 if (*charset++ == '-' && !--count) 872 if (*charset++ == '-' && !--count)
805 break; 873 break;
806 874
807 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)
808 } 881 {
809 882 clear ();
810 free (registry); 883 return false;
811 free (encoding); 884 }
812 885
813 if (cs == CS_UNICODE) 886 if (cs == CS_UNICODE)
814 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
815 888
816 encm = f->min_byte1 != 0 || f->max_byte1 != 0; 889 encm = f->min_byte1 != 0 || f->max_byte1 != 0;
828 int N = f->max_char_or_byte2 - f->min_char_or_byte2; 901 int N = f->max_char_or_byte2 - f->min_char_or_byte2;
829 902
830 if (encm) 903 if (encm)
831 N += (f->max_byte1 - f->min_byte1) 904 N += (f->max_byte1 - f->min_byte1)
832 * (f->max_char_or_byte2 - f->min_char_or_byte2 + 1); 905 * (f->max_char_or_byte2 - f->min_char_or_byte2 + 1);
833 906
834 while (N) 907 while (N)
835 { 908 {
836 if (f->per_char[N].width > width) 909 if (f->per_char[N].width > width)
837 width = f->per_char[N].width; 910 width = f->per_char[N].width;
838 911
863 if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; 936 if (wcw > 0) g.width = (g.width + wcw - 1) / wcw;
864 937
865 if (width < g.width) width = g.width; 938 if (width < g.width) width = g.width;
866 } 939 }
867 940
868 if (cs == CS_UNKNOWN) 941#if 0 // do it per-character
942 if (prop && width > prop->width)
869 { 943 {
870 fprintf (stderr, "unable to deduce codeset, ignoring font '%s'\n", name);
871
872 clear (); 944 clear ();
873 return false; 945 return false;
874 } 946 }
875
876#if 0 // do it per-character
877 if (prop && width > prop->width)
878 {
879 clear ();
880 return false;
881 }
882#endif 947#endif
883 948
884 return true; 949 return true;
885} 950}
886 951
900 uint32_t ch = FROM_UNICODE (cs, unicode); 965 uint32_t ch = FROM_UNICODE (cs, unicode);
901 966
902 if (ch == NOCHAR) 967 if (ch == NOCHAR)
903 return false; 968 return false;
904 969
905 /* check wether the character exists in _this_ font. horrible. */ 970 /* check whether the character exists in _this_ font. horrible. */
906 XCharStruct *xcs; 971 XCharStruct *xcs;
907 972
908 if (encm) 973 if (encm)
909 { 974 {
910 unsigned char byte1 = ch >> 8; 975 unsigned char byte1 = ch >> 8;
940 return false; 1005 return false;
941 1006
942 if (!prop || prop->width == rxvt_fontprop::unset) 1007 if (!prop || prop->width == rxvt_fontprop::unset)
943 return true; 1008 return true;
944 1009
945 // check wether character overlaps previous/next character 1010 // check whether character overlaps previous/next character
946 int w = xcs->rbearing - xcs->lbearing; 1011 int w = xcs->rbearing - xcs->lbearing;
947 int wcw = max (WCWIDTH (unicode), 1); 1012 int wcw = max (WCWIDTH (unicode), 1);
948 1013
949 careful = xcs->lbearing < 0 || xcs->rbearing > prop->width * wcw; 1014 careful = xcs->lbearing < 0 || xcs->rbearing > prop->width * wcw;
950 1015
990 else 1055 else
991 { 1056 {
992 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); 1057 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
993 1058
994 XChangeGC (disp, gc, GCForeground | GCFont, &v); 1059 XChangeGC (disp, gc, GCForeground | GCFont, &v);
995 1060
996 if (slow) 1061 if (slow)
997 { 1062 {
998 do 1063 do
999 { 1064 {
1000 if (xc->byte1 || xc->byte2) 1065 if (xc->byte1 || xc->byte2)
1022 else 1087 else
1023 { 1088 {
1024 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); 1089 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
1025 1090
1026 XChangeGC (disp, gc, GCForeground | GCFont, &v); 1091 XChangeGC (disp, gc, GCForeground | GCFont, &v);
1027 1092
1028 if (slow) 1093 if (slow)
1029 { 1094 {
1030 do 1095 do
1031 { 1096 {
1032 if (*xc) 1097 if (*xc)
1124 FcPatternAddInteger (p, FC_SLANT, prop.slant); 1189 FcPatternAddInteger (p, FC_SLANT, prop.slant);
1125 1190
1126#if 0 // clipping unfortunately destroys our precious double-width-characters 1191#if 0 // clipping unfortunately destroys our precious double-width-characters
1127 // clip width, we can't do better, or can we? 1192 // clip width, we can't do better, or can we?
1128 if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) 1193 if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch)
1129 FcPatternAddInteger (p, FC_CHAR_WIDTH, prop->width); 1194 FcPatternAddInteger (p, FC_CHAR_WIDTH, prop.width);
1130#endif 1195#endif
1131 1196
1132 if (FcPatternGet (p, FC_MINSPACE, 0, &v) != FcResultMatch) 1197 if (FcPatternGet (p, FC_MINSPACE, 0, &v) != FcResultMatch)
1133 FcPatternAddBool (p, FC_MINSPACE, 1); 1198 FcPatternAddBool (p, FC_MINSPACE, 1);
1134 1199
1278rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, 1343rxvt_font_xft::draw (rxvt_drawable &d, int x, int y,
1279 const text_t *text, int len, 1344 const text_t *text, int len,
1280 int fg, int bg) 1345 int fg, int bg)
1281{ 1346{
1282 XGlyphInfo extents; 1347 XGlyphInfo extents;
1283 XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec)); 1348 XftGlyphSpec *enc = rxvt_temp_buf<XftGlyphSpec> (len);
1284 XftGlyphSpec *ep = enc; 1349 XftGlyphSpec *ep = enc;
1285 1350
1286 dTermDisplay; 1351 dTermDisplay;
1287 dTermGC; 1352 dTermGC;
1288 1353
1289 int w = term->fwidth * len; 1354 int w = term->fwidth * len;
1290 int h = term->fheight; 1355 int h = term->fheight;
1291 1356
1292 /* TODO: this logic needs some more thinking, since we no longer do pseudo-transparency. 1357 bool buffered = bg >= Color_transparent
1293 * Maybe make buffering into a resource flag? Compile time option doesn't seems like a 1358 && term->option (Opt_buffered);
1294 * good idea from the perspective of packaging for wide variety of user configs. 1359
1295 */
1296 bool buffered = true
1297#ifdef FORCE_UNBUFFERED_XFT
1298 && bg >= 0
1299#endif
1300 ;
1301 // cut trailing spaces 1360 // cut trailing spaces
1302 while (len && text [len - 1] == ' ') 1361 while (len && text [len - 1] == ' ')
1303 len--; 1362 len--;
1304 1363
1305 int x_ = buffered ? 0 : x; 1364 int x_ = buffered ? 0 : x;
1310 int cwidth = term->fwidth; 1369 int cwidth = term->fwidth;
1311 FcChar32 fc = *text++; len--; 1370 FcChar32 fc = *text++; len--;
1312 1371
1313 while (len && *text == NOCHAR) 1372 while (len && *text == NOCHAR)
1314 text++, len--, cwidth += term->fwidth; 1373 text++, len--, cwidth += term->fwidth;
1315 1374
1316 if (fc != ' ') // skip spaces 1375 if (fc != ' ') // skip spaces
1317 { 1376 {
1318 FT_UInt glyph = XftCharIndex (disp, f, fc); 1377 FT_UInt glyph = XftCharIndex (disp, f, fc);
1319 XftGlyphExtents (disp, f, &glyph, 1, &extents); 1378 XftGlyphExtents (disp, f, &glyph, 1, &extents);
1320 1379
1331 x_ += cwidth; 1390 x_ += cwidth;
1332 } 1391 }
1333 1392
1334 if (buffered) 1393 if (buffered)
1335 { 1394 {
1336 bool back_rendered = false;
1337 if (ep != enc) 1395 if (ep != enc)
1338 { 1396 {
1339 rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); 1397 rxvt_drawable &d2 = d.screen->scratch_drawable (w, h);
1340 1398
1341#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
1342 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))))))
1343 { 1405 {
1344 Picture dst = 0; 1406 int src_x = x, src_y = y;
1345 1407
1346 if (bg >= 0 && term->pix_colors[bg].c.color.alpha < 0x0ff00) 1408 if (term->bgPixmap.is_parentOrigin ())
1347 dst = XftDrawPicture (d2);
1348
1349 if (bg < 0 || dst != 0)
1350 { 1409 {
1351 int src_x = x, src_y = y ;
1352
1353 if (term->bgPixmap.is_parentOrigin ())
1354 {
1355 src_x += term->window_vt_x; 1410 src_x += term->window_vt_x;
1356 src_y += term->window_vt_y; 1411 src_y += term->window_vt_y;
1357 } 1412 }
1358 1413
1359 if (term->bgPixmap.pmap_width >= src_x+w 1414 if (term->bgPixmap.pmap_width >= src_x + w
1360 && term->bgPixmap.pmap_height >= src_y+h) 1415 && term->bgPixmap.pmap_height >= src_y + h)
1361 { 1416 {
1362 XCopyArea (disp, term->bgPixmap.pixmap, d2, gc, 1417 XCopyArea (disp, term->bgPixmap.pixmap, d2, gc,
1363 src_x, src_y, w, h, 0, 0); 1418 src_x, src_y, w, h, 0, 0);
1364 } 1419 }
1365 else 1420 else
1366 { 1421 {
1367 XGCValues gcv; 1422 XGCValues gcv;
1368 1423
1369 gcv.fill_style = FillTiled; 1424 gcv.fill_style = FillTiled;
1370 gcv.tile = term->bgPixmap.pixmap; 1425 gcv.tile = term->bgPixmap.pixmap;
1371 gcv.ts_x_origin = -src_x; 1426 gcv.ts_x_origin = -src_x;
1372 gcv.ts_y_origin = -src_y; 1427 gcv.ts_y_origin = -src_y;
1373 1428
1374 XChangeGC (disp, gc, 1429 XChangeGC (disp, gc,
1375 GCTile | GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle, 1430 GCTile | GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle,
1376 &gcv); 1431 &gcv);
1377 1432
1378 XFillRectangle (disp, d2, gc, 0, 0, w, h); 1433 XFillRectangle (disp, d2, gc, 0, 0, w, h);
1379 1434
1380 gcv.fill_style = FillSolid; 1435 gcv.fill_style = FillSolid;
1381 XChangeGC (disp, gc, GCFillStyle, &gcv); 1436 XChangeGC (disp, gc, GCFillStyle, &gcv);
1382 } 1437 }
1383 1438
1384 if (bg >= 0) 1439 if (dst)
1385 { 1440 {
1386 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
1387 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);
1388 }
1389
1390 back_rendered = true;
1391 } 1445 }
1392 } 1446 }
1447 else
1393#endif 1448#endif
1394
1395 if (bg >= 0 && !back_rendered)
1396 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);
1397 1450
1398 XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, enc, ep - enc); 1451 XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, enc, ep - enc);
1399 XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y); 1452 XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y);
1400 } 1453 }
1401 else 1454 else
1445 1498
1446rxvt_font * 1499rxvt_font *
1447rxvt_fontset::new_font (const char *name, codeset cs) 1500rxvt_fontset::new_font (const char *name, codeset cs)
1448{ 1501{
1449 rxvt_font *f; 1502 rxvt_font *f;
1450 1503
1451 if (!name || !*name) 1504 if (!name || !*name)
1452 { 1505 {
1453 name = ""; 1506 name = "";
1454 f = new rxvt_font_default (this); 1507 f = new rxvt_font_default (this);
1455 } 1508 }
1523 if (!end) 1576 if (!end)
1524 end = desc + strlen (desc); 1577 end = desc + strlen (desc);
1525 1578
1526 if (end - desc < 511) 1579 if (end - desc < 511)
1527 { 1580 {
1528 strncpy (buf, desc, end - desc); 1581 memcpy (buf, desc, end - desc);
1529 buf[end - desc] = 0; 1582 buf[end - desc] = 0;
1530 1583
1531 fonts.push_back (new_font (buf, cs)); 1584 fonts.push_back (new_font (buf, cs));
1532 } 1585 }
1533 else 1586 else
1583 1636
1584 return -1; 1637 return -1;
1585} 1638}
1586 1639
1587int 1640int
1588rxvt_fontset::find_font (unicode_t unicode) 1641rxvt_fontset::find_font_idx (unicode_t unicode)
1589{ 1642{
1590 if (unicode >= 1<<20) 1643 if (unicode >= 1<<20)
1591 return 0; 1644 return 0;
1592 1645
1593 unicode_t hi = unicode >> 8; 1646 unicode_t hi = unicode >> 8;
1619 goto next_font; 1672 goto next_font;
1620 1673
1621 bool careful; 1674 bool careful;
1622 if (f->has_char (unicode, &prop, careful)) 1675 if (f->has_char (unicode, &prop, careful))
1623 { 1676 {
1624 if (careful) 1677 i = (i << 1) | careful;
1625 i |= 128;
1626 1678
1627 goto found; 1679 goto found;
1628 } 1680 }
1629 1681
1630 next_font: 1682 next_font:
1672 FcPatternDestroy (match); 1724 FcPatternDestroy (match);
1673 1725
1674 if (find_font (font) < 0) 1726 if (find_font (font) < 0)
1675 { 1727 {
1676 char fontname[4096]; 1728 char fontname[4096];
1677 sprintf (fontname, "xft:%-.4090s", font); 1729 snprintf (fontname, sizeof (fontname), "xft:%s", font);
1678 1730
1679 fonts.push_back (new_font (fontname, CS_UNICODE)); 1731 fonts.push_back (new_font (fontname, CS_UNICODE));
1680 } 1732 }
1681 1733
1682 free (font); 1734 free (font);
1683 } 1735 }
1684#endif 1736#endif
1706 } 1758 }
1707 1759
1708 return i; 1760 return i;
1709} 1761}
1710 1762
1763int
1764rxvt_fontset::find_font (unicode_t unicode)
1765{
1766 return min<int> ((fontCount << 1) | 1, find_font_idx (unicode));
1767}
1711 1768
1712

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines