… | |
… | |
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" }, |
… | |
… | |
216 | : name(0), width(rxvt_fontprop::unset), height(rxvt_fontprop::unset) |
216 | : name(0), width(rxvt_fontprop::unset), height(rxvt_fontprop::unset) |
217 | { |
217 | { |
218 | } |
218 | } |
219 | |
219 | |
220 | void |
220 | void |
221 | rxvt_font::set_name (char *name) |
221 | rxvt_font::set_name (char *name_) |
222 | { |
222 | { |
223 | if (this->name == name) |
223 | if (name == name_) |
224 | return; |
224 | return; |
225 | |
225 | |
226 | if (this->name) free (this->name); // let the compiler optimize |
226 | if (name) free (name); // let the compiler optimize |
227 | this->name = name; |
227 | name = name_; |
228 | } |
228 | } |
229 | |
229 | |
230 | void |
230 | void |
231 | rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const |
231 | rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const |
232 | { |
232 | { |
… | |
… | |
482 | |
482 | |
483 | x += fwidth; |
483 | x += fwidth; |
484 | } |
484 | } |
485 | } |
485 | } |
486 | |
486 | |
|
|
487 | struct 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 | |
487 | ///////////////////////////////////////////////////////////////////////////// |
537 | ///////////////////////////////////////////////////////////////////////////// |
488 | |
538 | |
489 | struct rxvt_font_x11 : rxvt_font { |
539 | struct rxvt_font_x11 : rxvt_font { |
490 | rxvt_font_x11 () { f = 0; } |
540 | rxvt_font_x11 () { f = 0; } |
491 | |
541 | |
… | |
… | |
499 | |
549 | |
500 | void draw (rxvt_drawable &d, int x, int y, |
550 | void draw (rxvt_drawable &d, int x, int y, |
501 | const text_t *text, int len, |
551 | const text_t *text, int len, |
502 | int fg, int bg); |
552 | int fg, int bg); |
503 | |
553 | |
504 | 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 |
505 | XFontStruct *f; |
555 | XFontStruct *f; |
506 | bool enc2b, encm; |
556 | bool enc2b, encm; |
507 | |
557 | |
508 | char *get_property (XFontStruct *f, Atom property, const char *repl) const; |
558 | char *get_property (XFontStruct *f, Atom property, const char *repl) const; |
509 | 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); |
… | |
… | |
792 | return false; |
842 | return false; |
793 | |
843 | |
794 | char *registry = get_property (f, term->xa [XA_CHARSET_REGISTRY], 0); |
844 | char *registry = get_property (f, term->xa [XA_CHARSET_REGISTRY], 0); |
795 | char *encoding = get_property (f, term->xa [XA_CHARSET_ENCODING], 0); |
845 | char *encoding = get_property (f, term->xa [XA_CHARSET_ENCODING], 0); |
796 | |
846 | |
|
|
847 | cs = CS_UNKNOWN; |
|
|
848 | |
797 | if (registry && encoding) |
849 | if (registry && encoding) |
798 | { |
850 | { |
799 | char charset[64]; |
851 | char charset[64]; |
800 | snprintf (charset, 64, "%s-%s", registry, encoding); |
852 | snprintf (charset, 64, "%s-%s", registry, encoding); |
801 | |
853 | |
802 | 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); |
803 | } |
858 | } |
804 | else |
859 | |
|
|
860 | free (registry); |
|
|
861 | free (encoding); |
|
|
862 | |
|
|
863 | if (cs == CS_UNKNOWN) |
805 | { |
864 | { |
806 | const char *charset = get_property (f, XA_FONT, 0); |
865 | const char *charset = get_property (f, XA_FONT, 0); |
807 | |
866 | |
808 | if (!charset) |
867 | if (!charset) |
809 | charset = name; |
868 | charset = name; |
… | |
… | |
812 | while (*charset) |
871 | while (*charset) |
813 | if (*charset++ == '-' && !--count) |
872 | if (*charset++ == '-' && !--count) |
814 | break; |
873 | break; |
815 | |
874 | |
816 | 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) |
817 | } |
881 | { |
818 | |
882 | clear (); |
819 | free (registry); |
883 | return false; |
820 | free (encoding); |
884 | } |
821 | |
885 | |
822 | if (cs == CS_UNICODE) |
886 | if (cs == CS_UNICODE) |
823 | 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 |
824 | |
888 | |
825 | encm = f->min_byte1 != 0 || f->max_byte1 != 0; |
889 | encm = f->min_byte1 != 0 || f->max_byte1 != 0; |
… | |
… | |
872 | if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
936 | if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
873 | |
937 | |
874 | if (width < g.width) width = g.width; |
938 | if (width < g.width) width = g.width; |
875 | } |
939 | } |
876 | |
940 | |
877 | if (cs == CS_UNKNOWN) |
941 | #if 0 // do it per-character |
|
|
942 | if (prop && width > prop->width) |
878 | { |
943 | { |
879 | fprintf (stderr, "unable to deduce codeset, ignoring font '%s'\n", name); |
|
|
880 | |
|
|
881 | clear (); |
944 | clear (); |
882 | return false; |
945 | return false; |
883 | } |
946 | } |
884 | |
|
|
885 | #if 0 // do it per-character |
|
|
886 | if (prop && width > prop->width) |
|
|
887 | { |
|
|
888 | clear (); |
|
|
889 | return false; |
|
|
890 | } |
|
|
891 | #endif |
947 | #endif |
892 | |
948 | |
893 | return true; |
949 | return true; |
894 | } |
950 | } |
895 | |
951 | |
… | |
… | |
909 | uint32_t ch = FROM_UNICODE (cs, unicode); |
965 | uint32_t ch = FROM_UNICODE (cs, unicode); |
910 | |
966 | |
911 | if (ch == NOCHAR) |
967 | if (ch == NOCHAR) |
912 | return false; |
968 | return false; |
913 | |
969 | |
914 | /* check wether the character exists in _this_ font. horrible. */ |
970 | /* check whether the character exists in _this_ font. horrible. */ |
915 | XCharStruct *xcs; |
971 | XCharStruct *xcs; |
916 | |
972 | |
917 | if (encm) |
973 | if (encm) |
918 | { |
974 | { |
919 | unsigned char byte1 = ch >> 8; |
975 | unsigned char byte1 = ch >> 8; |
… | |
… | |
949 | return false; |
1005 | return false; |
950 | |
1006 | |
951 | if (!prop || prop->width == rxvt_fontprop::unset) |
1007 | if (!prop || prop->width == rxvt_fontprop::unset) |
952 | return true; |
1008 | return true; |
953 | |
1009 | |
954 | // check wether character overlaps previous/next character |
1010 | // check whether character overlaps previous/next character |
955 | int w = xcs->rbearing - xcs->lbearing; |
1011 | int w = xcs->rbearing - xcs->lbearing; |
956 | int wcw = max (WCWIDTH (unicode), 1); |
1012 | int wcw = max (WCWIDTH (unicode), 1); |
957 | |
1013 | |
958 | careful = xcs->lbearing < 0 || xcs->rbearing > prop->width * wcw; |
1014 | careful = xcs->lbearing < 0 || xcs->rbearing > prop->width * wcw; |
959 | |
1015 | |
… | |
… | |
1133 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1189 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1134 | |
1190 | |
1135 | #if 0 // clipping unfortunately destroys our precious double-width-characters |
1191 | #if 0 // clipping unfortunately destroys our precious double-width-characters |
1136 | // clip width, we can't do better, or can we? |
1192 | // clip width, we can't do better, or can we? |
1137 | if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) |
1193 | if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) |
1138 | FcPatternAddInteger (p, FC_CHAR_WIDTH, prop->width); |
1194 | FcPatternAddInteger (p, FC_CHAR_WIDTH, prop.width); |
1139 | #endif |
1195 | #endif |
1140 | |
1196 | |
1141 | if (FcPatternGet (p, FC_MINSPACE, 0, &v) != FcResultMatch) |
1197 | if (FcPatternGet (p, FC_MINSPACE, 0, &v) != FcResultMatch) |
1142 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1198 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1143 | |
1199 | |
… | |
… | |
1287 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1343 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1288 | const text_t *text, int len, |
1344 | const text_t *text, int len, |
1289 | int fg, int bg) |
1345 | int fg, int bg) |
1290 | { |
1346 | { |
1291 | XGlyphInfo extents; |
1347 | XGlyphInfo extents; |
1292 | XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec)); |
1348 | XftGlyphSpec *enc = rxvt_temp_buf<XftGlyphSpec> (len); |
1293 | XftGlyphSpec *ep = enc; |
1349 | XftGlyphSpec *ep = enc; |
1294 | |
1350 | |
1295 | dTermDisplay; |
1351 | dTermDisplay; |
1296 | dTermGC; |
1352 | dTermGC; |
1297 | |
1353 | |
1298 | int w = term->fwidth * len; |
1354 | int w = term->fwidth * len; |
1299 | int h = term->fheight; |
1355 | int h = term->fheight; |
1300 | |
1356 | |
1301 | bool buffered = bg >= Color_transparent |
1357 | bool buffered = bg >= Color_transparent |
1302 | && term->option (Opt_buffered); |
1358 | && term->option (Opt_buffered); |
1303 | |
1359 | |
1304 | // cut trailing spaces |
1360 | // cut trailing spaces |
1305 | while (len && text [len - 1] == ' ') |
1361 | while (len && text [len - 1] == ' ') |
1306 | len--; |
1362 | len--; |
1307 | |
1363 | |
… | |
… | |
1580 | |
1636 | |
1581 | return -1; |
1637 | return -1; |
1582 | } |
1638 | } |
1583 | |
1639 | |
1584 | int |
1640 | int |
1585 | rxvt_fontset::find_font (unicode_t unicode) |
1641 | rxvt_fontset::find_font_idx (unicode_t unicode) |
1586 | { |
1642 | { |
1587 | if (unicode >= 1<<20) |
1643 | if (unicode >= 1<<20) |
1588 | return 0; |
1644 | return 0; |
1589 | |
1645 | |
1590 | unicode_t hi = unicode >> 8; |
1646 | unicode_t hi = unicode >> 8; |
… | |
… | |
1616 | goto next_font; |
1672 | goto next_font; |
1617 | |
1673 | |
1618 | bool careful; |
1674 | bool careful; |
1619 | if (f->has_char (unicode, &prop, careful)) |
1675 | if (f->has_char (unicode, &prop, careful)) |
1620 | { |
1676 | { |
1621 | if (careful) |
1677 | i = (i << 1) | careful; |
1622 | i |= 128; |
|
|
1623 | |
1678 | |
1624 | goto found; |
1679 | goto found; |
1625 | } |
1680 | } |
1626 | |
1681 | |
1627 | next_font: |
1682 | next_font: |
… | |
… | |
1669 | FcPatternDestroy (match); |
1724 | FcPatternDestroy (match); |
1670 | |
1725 | |
1671 | if (find_font (font) < 0) |
1726 | if (find_font (font) < 0) |
1672 | { |
1727 | { |
1673 | char fontname[4096]; |
1728 | char fontname[4096]; |
1674 | sprintf (fontname, "xft:%-.4090s", font); |
1729 | snprintf (fontname, sizeof (fontname), "xft:%s", font); |
1675 | |
1730 | |
1676 | fonts.push_back (new_font (fontname, CS_UNICODE)); |
1731 | fonts.push_back (new_font (fontname, CS_UNICODE)); |
1677 | } |
1732 | } |
1678 | |
1733 | |
1679 | free (font); |
1734 | free (font); |
… | |
… | |
1703 | } |
1758 | } |
1704 | |
1759 | |
1705 | return i; |
1760 | return i; |
1706 | } |
1761 | } |
1707 | |
1762 | |
|
|
1763 | int |
|
|
1764 | rxvt_fontset::find_font (unicode_t unicode) |
|
|
1765 | { |
|
|
1766 | return min<int> ((fontCount << 1) | 1, find_font_idx (unicode)); |
|
|
1767 | } |
1708 | |
1768 | |
1709 | |
|
|