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.52 by root, Sat Dec 4 02:56:06 2004 UTC vs.
Revision 1.64 by root, Tue Jan 11 05:45:57 2005 UTC

90 { CS_JIS0212_1990_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, 90 { CS_JIS0212_1990_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0212*-0" },
91#endif 91#endif
92 92
93#if ENCODING_ZH || ENCODING_ZH_EXT 93#if ENCODING_ZH || ENCODING_ZH_EXT
94# if XFT 94# if XFT
95 { CS_GBK_0, "xft:AR PL KaitiM GB" },
96 { CS_GBK_0, "xft:AR PL SungtiL GB" },
97 { CS_GBK_0, "xft::spacing=100:lang=zh" },
95 { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, 98 { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" },
96 { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, 99 { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" },
97 { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, 100 { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" },
98 { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, 101 { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" },
99 { CS_GB2312_1980_0, "xft::spacing=100:lang=zh" }, 102 { CS_GB2312_1980_0, "xft::spacing=100:lang=zh" },
100# endif 103# endif
104 { CS_GBK_0, "-*-*-*-*-*-*-*-*-*-*-c-*-gbk*-0" },
101 { CS_BIG5, "-*-*-*-*-*-*-*-*-*-*-c-*-big5-0" }, 105 { CS_BIG5, "-*-*-*-*-*-*-*-*-*-*-c-*-big5-0" },
102 { CS_BIG5_PLUS, "-*-*-*-*-*-*-*-*-*-*-c-*-big5p-0" }, 106 { CS_BIG5_PLUS, "-*-*-*-*-*-*-*-*-*-*-c-*-big5p-0" },
103 { CS_BIG5_EXT, "-*-*-*-*-*-*-*-*-*-*-c-*-big5.eten-0" }, 107 { CS_BIG5_EXT, "-*-*-*-*-*-*-*-*-*-*-c-*-big5.eten-0" },
108 { CS_GB2312_1980_0, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" },
104 { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" }, 109 { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" },
105 { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" }, 110 { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" },
106 { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" }, 111 { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" },
107 { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" }, 112 { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" },
108 { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" }, 113 { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" },
138 143
139 { CS_UNKNOWN, 0 } 144 { CS_UNKNOWN, 0 }
140}; 145};
141 146
142// these characters are used to guess the font height and width 147// these characters are used to guess the font height and width
143// pango uses a similar algorithm and eosn't trust the font either. 148// pango uses a similar algorithm and doesn't trust the font either.
144static uint16_t extent_test_chars[] = { 149static uint16_t extent_test_chars[] = {
145 '0', '1', '8', 'a', 'd', 'x', 'm', 'y', 'g', 'W', 'X', '\'', '_', 150 '0', '1', '8', 'a', 'd', 'x', 'm', 'y', 'g', 'W', 'X', '\'', '_',
146 0x00cd, 0x00d5, 0x0114, 0x0177, 0x0643, // ÍÕĔŷﻙ 151 0x00cd, 0x00d5, 0x0114, 0x0177, 0x0643, // ÍÕĔŷﻙ
147 0x304c, 0x672c, // が本 152 0x304c, 0x672c, // が本
148}; 153};
330{ 335{
331 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); 336 clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
332 337
333 XSetForeground (d.display->display, TGC, r->pix_colors[fg]); 338 XSetForeground (d.display->display, TGC, r->pix_colors[fg]);
334 339
335 while (len--) 340 while (len)
336 { 341 {
337#if ENABLE_COMBINING 342#if ENABLE_COMBINING
338 compose_char *cc; 343 compose_char *cc;
339#endif 344#endif
345 const text_t *tp = text;
340 text_t t = *text++; 346 text_t t = *tp;
347
348 while (++text, --len && *text == NOCHAR)
349 ;
350
351 int width = text - tp;
352 int fwidth = r->TermWin.fwidth * width;
341 353
342 if (0x2500 <= t && t <= 0x259f) 354 if (0x2500 <= t && t <= 0x259f)
343 { 355 {
344 uint16_t offs = linedraw_offs[t - 0x2500]; 356 uint16_t offs = linedraw_offs[t - 0x2500];
345 uint32_t *a = linedraw_command + (offs >> 4); 357 uint32_t *a = linedraw_command + (offs >> 4);
346 uint32_t *b = a + (offs & 15); 358 uint32_t *b = a + (offs & 15);
347 359
348 int W = r->TermWin.fwidth; 360 int W = fwidth;
349 int H = r->TermWin.fheight; 361 int H = r->TermWin.fheight;
350
351 // support double-width (but not more) graphics chars
352 // TODO: do this outside the if/elsif.. statement for all cases
353 if (len && *text == NOCHAR)
354 W += r->TermWin.fwidth;
355 362
356 int x_[16]; 363 int x_[16];
357 int y_[16]; 364 int y_[16];
358 365
359 for (int i = 0; i <= 8; i++) 366 for (int i = 0; i <= 8; i++)
423 } 430 }
424 } 431 }
425#if ENABLE_COMBINING 432#if ENABLE_COMBINING
426 else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) 433 else if (IS_COMPOSE (t) && (cc = rxvt_composite[t]))
427 { 434 {
428 text_t c2[2]; 435 text_t chrs[2];
429 int len2 = 1; 436 width = min (2, width);
430 437 chrs [1] = NOCHAR;
431 // support double-width (but not more) combining characters
432 if (len && *text == NOCHAR)
433 {
434 c2[1] = *text; // not text++ to get correct x-width
435 len2++;
436 }
437 438
438 c2[0] = cc->c1; 439 *chrs = cc->c1;
439 rxvt_font *f1 = (*fs)[fs->find_font (c2[0])]; 440 rxvt_font *f1 = (*fs)[fs->find_font (cc->c1)];
440 f1->draw (d, x, y, c2, len2, fg, bg); 441 f1->draw (d, x, y, chrs, width, fg, bg);
441 442
442 if (cc->c2 != NOCHAR) 443 if (cc->c2 != NOCHAR)
443 { 444 {
444 bool careful; 445 bool careful;
445 446
446 // prefer font of first character, for no good reasons 447 // prefer font of first character, for no good reasons
447 c2[0] = cc->c2; 448 *chrs = cc->c2;
448 rxvt_font *f2 = (f1->has_char (c2[0], 0, careful) && !careful) 449 rxvt_font *f2 = (f1->has_char (cc->c2, 0, careful) && !careful)
449 ? f1 450 ? f1
450 : (*fs)[fs->find_font (c2[0])]; 451 : (*fs)[fs->find_font (cc->c2)];
451 452
452 f2->draw (d, x, y, c2, len2, fg, -1); 453 f2->draw (d, x, y, chrs, width, fg, -1);
453 } 454 }
454 } 455 }
455#endif 456#endif
456 else 457 else
457 switch (t) 458 switch (t)
460 case ZERO_WIDTH_CHAR: 461 case ZERO_WIDTH_CHAR:
461 case NOCHAR: 462 case NOCHAR:
462 break; 463 break;
463 464
464 default: 465 default:
465 int w = 0;
466 while (len > 0 && *text == NOCHAR)
467 {
468 ++text;
469 --len;
470 w += r->TermWin.fwidth;
471 }
472
473 XDrawRectangle (d.display->display, d, TGC, x + 2, y + 2, 466 XDrawRectangle (d.display->display, d, TGC, x + 2, y + 2,
474 w + r->TermWin.fwidth - 4, r->TermWin.fheight - 4); 467 fwidth - 4, r->TermWin.fheight - 4);
475 x += w;
476 } 468 }
477 469
478 x += r->TermWin.fwidth; 470 x += fwidth;
479 } 471 }
480} 472}
481 473
482///////////////////////////////////////////////////////////////////////////// 474/////////////////////////////////////////////////////////////////////////////
483 475
539 531
540bool 532bool
541rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) 533rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f)
542{ 534{
543 unsigned long height; 535 unsigned long height;
536
537#if 0
544 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) 538 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height))
545 return false; 539 return false;
540#else
541 height = f->ascent + f->descent;
542#endif
546 543
547 unsigned long avgwidth; 544 unsigned long avgwidth;
548 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) 545 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth))
549 avgwidth = 0; 546 avgwidth = 0;
550 547
678 ? "r" : "i"); // TODO: handle "o"blique, too 675 ? "r" : "i"); // TODO: handle "o"blique, too
679 set_name (strdup (fname)); 676 set_name (strdup (fname));
680 } 677 }
681 } 678 }
682 679
680 sprintf (field_str, "%d", prop.height == rxvt_fontprop::unset
681 ? 0 : prop.height);
682
683 struct font_weight {
684 char *name;
685 int diff;
686
687 void clear ()
688 {
689 name = 0;
690 diff = 0x7fffffff;
691 }
692
693 font_weight () { clear (); }
694 ~font_weight () { free (name); }
695 };
696
683 char **list; 697 char **list;
684 int count; 698 int count;
685 list = XListFonts (DISPLAY, name, 1024, &count); 699 list = XListFonts (DISPLAY, name, 4000, &count);
686 700
687 set_name (0); 701 set_name (0);
688 702
689 if (!list) 703 if (!list)
690 return false; 704 return false;
691 705
692 sprintf (field_str, "%d", prop.height == rxvt_fontprop::unset 706 font_weight *fonts = new font_weight[count];
693 ? 0 : prop.height);
694 707
695 int bestdiff = 0x7fffffff;
696 for (int i = 0; i < count; i++) 708 for (int i = 0; i < count; i++)
697 { 709 {
698 rxvt_fontprop p; 710 rxvt_fontprop p;
699 char fname[1024]; 711 char fname[1024];
700 712
713 if (prop.height != rxvt_fontprop::unset) diff += (prop.height - p.height) * 128; 725 if (prop.height != rxvt_fontprop::unset) diff += (prop.height - p.height) * 128;
714 if (prop.weight != rxvt_fontprop::unset) diff += abs (prop.weight - p.weight); 726 if (prop.weight != rxvt_fontprop::unset) diff += abs (prop.weight - p.weight);
715 if (prop.slant != rxvt_fontprop::unset) diff += abs (prop.slant - p.slant); 727 if (prop.slant != rxvt_fontprop::unset) diff += abs (prop.slant - p.slant);
716 //if (prop.width != rxvt_fontprop::unset) diff += abs (prop.width - p.width); 728 //if (prop.width != rxvt_fontprop::unset) diff += abs (prop.width - p.width);
717 729
718 if (!name // compare against best found so far 730 fonts[i].name = strdup (fname);
719 || diff < bestdiff) 731 fonts[i].diff = diff;
720 {
721 set_name (strdup (fname));
722 bestdiff = diff;
723 }
724 } 732 }
725 733
726 XFreeFontNames (list); 734 XFreeFontNames (list);
727 735
728 if (!name) 736 // this loop only iterates when the guessed font-size is too small
729 return false; 737 for (;;)
738 {
739 font_weight *best = fonts + count - 1;
730 740
741 for (font_weight *w = best; w-- > fonts; )
742 if (w->diff < best->diff)
743 best = w;
744
745 if (!best->name
731 f = XLoadQueryFont (DISPLAY, name); 746 || !(f = XLoadQueryFont (DISPLAY, best->name)))
747 break;
748
749 set_name (best->name);
750 best->clear ();
751
752 ascent = f->ascent;
753 descent = f->descent;
754 height = ascent + descent;
755
756 if (prop.height == rxvt_fontprop::unset
757 || height <= prop.height)
758 break; // font is ready for use
759
760 // PIXEL_SIZE small enough, but real height too large
761 clear ();
762 }
763
764 delete [] fonts;
732 765
733 if (!f) 766 if (!f)
734 return false; 767 return false;
735 768
736 char *registry = get_property (f, "CHARSET_REGISTRY", 0); 769 char *registry = get_property (f, "CHARSET_REGISTRY", 0);
764 if (cs == CS_UNICODE) 797 if (cs == CS_UNICODE)
765 cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font 798 cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font
766 799
767 encm = f->min_byte1 != 0 || f->max_byte1 != 0; 800 encm = f->min_byte1 != 0 || f->max_byte1 != 0;
768 enc2b = encm || f->max_char_or_byte2 > 255; 801 enc2b = encm || f->max_char_or_byte2 > 255;
769
770 ascent = f->ascent;
771 descent = f->descent;
772 height = ascent + descent;
773 802
774 slow = false; 803 slow = false;
775 804
776#if 1 // only used for slow detection, TODO optimize 805#if 1 // only used for slow detection, TODO optimize
777 if (f->min_bounds.width == f->max_bounds.width) 806 if (f->min_bounds.width == f->max_bounds.width)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines