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.150 by root, Sun Mar 29 13:36:03 2009 UTC vs.
Revision 1.157 by root, Tue Mar 30 23:38:02 2010 UTC

79 79
80 // japanese 80 // japanese
81#if ENCODING_JP || ENCODING_JP_EXT 81#if ENCODING_JP || ENCODING_JP_EXT
82# if XFT 82# if XFT
83 // prefer xft for complex scripts 83 // prefer xft for complex scripts
84 { CS_JIS0208_1990_0, "xft:Sazanami Mincho:antialias=false" },
84 { CS_JIS0208_1990_0, "xft:Kochi Gothic:antialias=false" }, 85 { CS_JIS0208_1990_0, "xft:Kochi Gothic:antialias=false" },
85 { CS_JIS0208_1990_0, "xft:Sazanami Mincho:antialias=false" },
86 { CS_JIS0208_1990_0, "xft:Mincho:antialias=false" }, 86 { CS_JIS0208_1990_0, "xft:Mincho:antialias=false" },
87 { CS_JIS0208_1990_0, "xft::lang=ja:antialias=false" }, 87 { CS_JIS0208_1990_0, "xft::lang=ja:antialias=false" },
88# endif 88# endif
89 { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, 89 { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" },
90 { CS_JIS0208_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, 90 { CS_JIS0208_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" },
448 448
449 text_t chrs[2]; 449 text_t chrs[2];
450 chrs [1] = NOCHAR; 450 chrs [1] = NOCHAR;
451 451
452 *chrs = cc->c1; 452 *chrs = cc->c1;
453 rxvt_font *f1 = (*fs)[fs->find_font (cc->c1)]; 453 rxvt_font *f1 = fs->get (cc->c1);
454 f1->draw (d, x, y, chrs, width, fg, bg); 454 f1->draw (d, x, y, chrs, width, fg, bg);
455 455
456 if (cc->c2 != NOCHAR) 456 if (cc->c2 != NOCHAR)
457 { 457 {
458 bool careful; 458 bool careful;
459 459
460 // prefer font of first character, for no good reasons 460 // prefer font of first character, for no good reasons
461 *chrs = cc->c2; 461 *chrs = cc->c2;
462 rxvt_font *f2 = (f1->has_char (cc->c2, 0, careful) && !careful) 462 rxvt_font *f2 = (f1->has_char (cc->c2, 0, careful) && !careful)
463 ? f1 463 ? f1
464 : (*fs)[fs->find_font (cc->c2)]; 464 : fs->get (cc->c2);
465 465
466 f2->draw (d, x, y, chrs, width, fg, Color_none); 466 f2->draw (d, x, y, chrs, width, fg, Color_none);
467 } 467 }
468 } 468 }
469#endif 469#endif
792 return false; 792 return false;
793 793
794 char *registry = get_property (f, term->xa [XA_CHARSET_REGISTRY], 0); 794 char *registry = get_property (f, term->xa [XA_CHARSET_REGISTRY], 0);
795 char *encoding = get_property (f, term->xa [XA_CHARSET_ENCODING], 0); 795 char *encoding = get_property (f, term->xa [XA_CHARSET_ENCODING], 0);
796 796
797 cs = CS_UNKNOWN;
798
797 if (registry && encoding) 799 if (registry && encoding)
798 { 800 {
799 char charset[64]; 801 char charset[64];
800 snprintf (charset, 64, "%s-%s", registry, encoding); 802 snprintf (charset, 64, "%s-%s", registry, encoding);
801 803
802 cs = codeset_from_name (charset); 804 cs = codeset_from_name (charset);
805
806 if (cs == CS_UNKNOWN)
807 rxvt_warn ("%s: cannot deduce encoding from registry/encoding properties \"%s\", ignoring font.\n", name, charset);
803 } 808 }
804 else 809
810 free (registry);
811 free (encoding);
812
813 if (cs == CS_UNKNOWN)
805 { 814 {
806 const char *charset = get_property (f, XA_FONT, 0); 815 const char *charset = get_property (f, XA_FONT, 0);
807 816
808 if (!charset) 817 if (!charset)
809 charset = name; 818 charset = name;
812 while (*charset) 821 while (*charset)
813 if (*charset++ == '-' && !--count) 822 if (*charset++ == '-' && !--count)
814 break; 823 break;
815 824
816 cs = codeset_from_name (charset); 825 cs = codeset_from_name (charset);
826 if (cs == CS_UNKNOWN)
827 rxvt_warn ("%s: cannot deduce encoding from font name property \"%s\", ignoring font.\n", name, charset);
828 }
829
830 if (cs == CS_UNKNOWN)
817 } 831 {
818 832 clear ();
819 free (registry); 833 return false;
820 free (encoding); 834 }
821 835
822 if (cs == CS_UNICODE) 836 if (cs == CS_UNICODE)
823 cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font 837 cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font
824 838
825 encm = f->min_byte1 != 0 || f->max_byte1 != 0; 839 encm = f->min_byte1 != 0 || f->max_byte1 != 0;
870 884
871 int wcw = WCWIDTH (*t); 885 int wcw = WCWIDTH (*t);
872 if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; 886 if (wcw > 0) g.width = (g.width + wcw - 1) / wcw;
873 887
874 if (width < g.width) width = g.width; 888 if (width < g.width) width = g.width;
875 }
876
877 if (cs == CS_UNKNOWN)
878 {
879 fprintf (stderr, "unable to deduce codeset, ignoring font '%s'\n", name);
880
881 clear ();
882 return false;
883 } 889 }
884 890
885#if 0 // do it per-character 891#if 0 // do it per-character
886 if (prop && width > prop->width) 892 if (prop && width > prop->width)
887 { 893 {
1287rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, 1293rxvt_font_xft::draw (rxvt_drawable &d, int x, int y,
1288 const text_t *text, int len, 1294 const text_t *text, int len,
1289 int fg, int bg) 1295 int fg, int bg)
1290{ 1296{
1291 XGlyphInfo extents; 1297 XGlyphInfo extents;
1292 XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec)); 1298 XftGlyphSpec *enc = rxvt_temp_buf<XftGlyphSpec> (len);
1293 XftGlyphSpec *ep = enc; 1299 XftGlyphSpec *ep = enc;
1294 1300
1295 dTermDisplay; 1301 dTermDisplay;
1296 dTermGC; 1302 dTermGC;
1297 1303
1580 1586
1581 return -1; 1587 return -1;
1582} 1588}
1583 1589
1584int 1590int
1585rxvt_fontset::find_font (unicode_t unicode) 1591rxvt_fontset::find_font_idx (unicode_t unicode, bool &careful)
1586{ 1592{
1587 if (unicode >= 1<<20) 1593 if (unicode >= 1<<20)
1588 return 0; 1594 return 0;
1589 1595
1590 unicode_t hi = unicode >> 8; 1596 unicode_t hi = unicode >> 8;
1591 1597
1592 if (hi < fmap.size () 1598 if (hi < fmap.size () && fmap[hi])
1593 && fmap[hi] 1599 {
1594 && (*fmap[hi])[unicode & 0xff] != 0xff) 1600 unsigned char m = (*fmap[hi])[unicode & 0xff];
1595 return (*fmap[hi])[unicode & 0xff]; 1601
1602 if (m != 0xff)
1603 {
1604 careful = m & 128;
1605 return m & 127;
1606 }
1607 }
1596 1608
1597 unsigned int i; 1609 unsigned int i;
1598 1610
1599 for (i = 0; i < fonts.size (); i++) 1611 for (i = 0; i < fonts.size (); i++)
1600 { 1612 {
1613 } 1625 }
1614 1626
1615 if (f->cs == CS_UNKNOWN) 1627 if (f->cs == CS_UNKNOWN)
1616 goto next_font; 1628 goto next_font;
1617 1629
1618 bool careful;
1619 if (f->has_char (unicode, &prop, careful)) 1630 if (f->has_char (unicode, &prop, careful))
1620 {
1621 if (careful)
1622 i |= 128;
1623
1624 goto found; 1631 goto found;
1625 }
1626 1632
1627 next_font: 1633 next_font:
1628 if (i == fonts.size () - 1) 1634 if (i == fonts.size () - 1)
1629 { 1635 {
1630 if (fallback->name) 1636 if (fallback->name)
1669 FcPatternDestroy (match); 1675 FcPatternDestroy (match);
1670 1676
1671 if (find_font (font) < 0) 1677 if (find_font (font) < 0)
1672 { 1678 {
1673 char fontname[4096]; 1679 char fontname[4096];
1674 sprintf (fontname, "xft:%-.4090s", font); 1680 snprintf (fontname, sizeof (fontname), "xft:%s", font);
1675 1681
1676 fonts.push_back (new_font (fontname, CS_UNICODE)); 1682 fonts.push_back (new_font (fontname, CS_UNICODE));
1677 } 1683 }
1678 1684
1679 free (font); 1685 free (font);
1683 } 1689 }
1684 } 1690 }
1685 1691
1686 /* we must return SOME font */ 1692 /* we must return SOME font */
1687 i = 0; 1693 i = 0;
1694 careful = false;
1688 1695
1689found: 1696found:
1690 // found a font, cache it 1697 // found a font, cache it
1691 if (i < 255) 1698 if (i < 127)
1692 { 1699 {
1693 while (hi >= fmap.size ()) 1700 while (hi >= fmap.size ())
1694 fmap.push_back (0); 1701 fmap.push_back (0);
1695 1702
1696 if (!fmap[hi]) 1703 if (!fmap[hi])
1697 { 1704 {
1698 fmap[hi] = (pagemap *)new pagemap; 1705 fmap[hi] = (pagemap *)new pagemap;
1699 memset (fmap[hi], 0xff, sizeof (pagemap)); 1706 memset (fmap[hi], 0xff, sizeof (pagemap));
1700 } 1707 }
1701 1708
1702 (*fmap[hi])[unicode & 0xff] = i; 1709 (*fmap[hi])[unicode & 0xff] = i | (careful ? 128 : 0);
1703 } 1710 }
1704 1711
1705 return i; 1712 return i;
1706} 1713}
1707 1714
1715int
1716rxvt_fontset::find_font (unicode_t unicode)
1717{
1718 bool careful;
1719 int id = find_font_idx (unicode, careful);
1708 1720
1721 return min<int> (fontCount, id) | (careful ? Careful : 0);
1722}
1709 1723

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines