1 | /*--------------------------------*-C-*---------------------------------*; |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: defaultfont.C |
2 | * File: defaultfont.C |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> |
4 | * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> |
5 | * - original version. |
5 | * - original version. |
6 | * |
6 | * |
… | |
… | |
30 | |
30 | |
31 | const struct rxvt_fallback_font { |
31 | const struct rxvt_fallback_font { |
32 | codeset cs; |
32 | codeset cs; |
33 | const char *name; |
33 | const char *name; |
34 | } fallback_fonts[] = { |
34 | } fallback_fonts[] = { |
35 | { CS_ISO8859_1, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-1" }, |
35 | { CS_ISO8859_1, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-1" }, |
36 | { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-15" }, |
36 | { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-15" }, |
37 | { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-fcd8859-15" }, |
37 | { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-fcd8859-15" }, |
38 | |
38 | |
39 | #if ENCODING_EU |
39 | #if ENCODING_EU |
40 | // cyrillic |
40 | // cyrillic |
41 | { CS_KOI8_R, "-*-*-*-r-*--*-*-*-*-c-*-koi8-r" }, |
41 | { CS_KOI8_R, "-*-*-*-r-*--*-*-*-*-c-*-koi8-r" }, |
42 | { CS_KOI8_U, "-*-*-*-r-*--*-*-*-*-c-*-koi8-u" }, |
42 | { CS_KOI8_U, "-*-*-*-r-*--*-*-*-*-c-*-koi8-u" }, |
43 | |
43 | |
44 | { CS_ISO8859_2, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-2" }, |
44 | { CS_ISO8859_2, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-2" }, |
45 | { CS_ISO8859_3, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-3" }, |
45 | { CS_ISO8859_3, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-3" }, |
46 | { CS_ISO8859_4, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-4" }, |
46 | { CS_ISO8859_4, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-4" }, |
47 | { CS_ISO8859_5, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-5" }, |
47 | { CS_ISO8859_5, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-5" }, |
48 | { CS_ISO8859_6, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-6" }, |
48 | { CS_ISO8859_6, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-6" }, |
49 | { CS_ISO8859_7, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-7" }, |
49 | { CS_ISO8859_7, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-7" }, |
50 | { CS_ISO8859_8, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-8" }, |
50 | { CS_ISO8859_8, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-8" }, |
51 | { CS_ISO8859_9, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-9" }, |
51 | { CS_ISO8859_9, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-9" }, |
52 | { CS_ISO8859_10, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-10" }, |
52 | { CS_ISO8859_10, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-10" }, |
53 | { CS_ISO8859_11, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-11" }, |
53 | { CS_ISO8859_11, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-11" }, |
54 | { CS_ISO8859_13, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-13" }, |
54 | { CS_ISO8859_13, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-13" }, |
55 | { CS_ISO8859_14, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-14" }, |
55 | { CS_ISO8859_14, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-14" }, |
56 | { CS_ISO8859_16, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-16" }, |
56 | { CS_ISO8859_16, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-16" }, |
57 | #endif |
57 | #endif |
58 | |
58 | |
59 | // japanese |
59 | // japanese |
60 | #if ENCODING_JP || ENCODING_JP_EXT |
60 | #if ENCODING_JP || ENCODING_JP_EXT |
61 | # if XFT |
61 | # if XFT |
… | |
… | |
63 | { CS_UNICODE, "xft:Kochi Gothic:antialias=false" }, |
63 | { CS_UNICODE, "xft:Kochi Gothic:antialias=false" }, |
64 | # endif |
64 | # endif |
65 | { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
65 | { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
66 | { CS_JIS0208_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
66 | { CS_JIS0208_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
67 | { CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
67 | { CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
|
|
68 | { CS_JIS0201_1976_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
|
|
69 | { CS_JIS0208_1990_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
|
|
70 | { CS_JIS0212_1990_0, "-*-*-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
68 | #endif |
71 | #endif |
69 | |
72 | |
70 | #if ENCODING_CN || ENCODING_CN_EXT |
73 | #if ENCODING_CN || ENCODING_CN_EXT |
71 | # if XFT |
74 | # if XFT |
72 | { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, |
75 | { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, |
… | |
… | |
89 | #endif |
92 | #endif |
90 | |
93 | |
91 | #if XFT |
94 | #if XFT |
92 | { CS_UNICODE, "xft:Andale Mono" }, |
95 | { CS_UNICODE, "xft:Andale Mono" }, |
93 | { CS_UNICODE, "xft:Arial Unicode MS" }, |
96 | { CS_UNICODE, "xft:Arial Unicode MS" }, |
|
|
97 | { CS_UNICODE, "xft:FreeMono" }, |
94 | #endif |
98 | #endif |
95 | { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, |
99 | { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, |
96 | { CS_UNICODE, "xft:FreeMono" }, |
|
|
97 | { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, |
100 | { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, |
98 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, |
101 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, |
99 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
102 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
100 | |
103 | |
101 | #if UNICODE_3 && XFT |
104 | #if UNICODE_3 && XFT |
… | |
… | |
133 | { |
136 | { |
134 | if (len > enc_len) |
137 | if (len > enc_len) |
135 | { |
138 | { |
136 | free (enc_buf); |
139 | free (enc_buf); |
137 | enc_buf = malloc (len); |
140 | enc_buf = malloc (len); |
|
|
141 | enc_len = len; |
138 | } |
142 | } |
139 | |
143 | |
140 | return enc_buf; |
144 | return enc_buf; |
141 | } |
145 | } |
142 | |
146 | |
… | |
… | |
729 | |
733 | |
730 | int base = r->TermWin.fbase; |
734 | int base = r->TermWin.fbase; |
731 | |
735 | |
732 | XGCValues v; |
736 | XGCValues v; |
733 | v.foreground = r->PixColors[fg]; |
737 | v.foreground = r->PixColors[fg]; |
734 | v.background = r->PixColors[bg]; |
|
|
735 | v.font = f->fid; |
738 | v.font = f->fid; |
736 | |
739 | |
737 | if (enc2b) |
740 | if (enc2b) |
738 | { |
741 | { |
739 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
742 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
740 | |
743 | |
741 | if (bg == Color_bg && !slow) |
744 | if (bg == Color_bg && !slow) |
742 | { |
745 | { |
|
|
746 | v.background = r->PixColors[bg]; |
743 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
747 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
744 | XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); |
748 | XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); |
745 | } |
749 | } |
746 | else |
750 | else |
747 | { |
751 | { |
… | |
… | |
769 | { |
773 | { |
770 | const char *xc = enc_char (text, len, cs, slow); |
774 | const char *xc = enc_char (text, len, cs, slow); |
771 | |
775 | |
772 | if (bg == Color_bg && !slow) |
776 | if (bg == Color_bg && !slow) |
773 | { |
777 | { |
|
|
778 | v.background = r->PixColors[bg]; |
774 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
779 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
775 | XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); |
780 | XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); |
776 | } |
781 | } |
777 | else |
782 | else |
778 | { |
783 | { |
… | |
… | |
997 | #endif |
1002 | #endif |
998 | |
1003 | |
999 | ///////////////////////////////////////////////////////////////////////////// |
1004 | ///////////////////////////////////////////////////////////////////////////// |
1000 | |
1005 | |
1001 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
1006 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
1002 | : r (r) |
1007 | : r (r), fontdesc (0) |
1003 | { |
1008 | { |
1004 | clear (); |
1009 | clear (); |
1005 | } |
1010 | } |
1006 | |
1011 | |
1007 | rxvt_fontset::~rxvt_fontset () |
1012 | rxvt_fontset::~rxvt_fontset () |
… | |
… | |
1012 | void |
1017 | void |
1013 | rxvt_fontset::clear () |
1018 | rxvt_fontset::clear () |
1014 | { |
1019 | { |
1015 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1020 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1016 | FONT_UNREF (*i); |
1021 | FONT_UNREF (*i); |
|
|
1022 | |
|
|
1023 | free (fontdesc); fontdesc = 0; |
1017 | |
1024 | |
1018 | fonts.clear (); |
1025 | fonts.clear (); |
1019 | base_id = 0; |
1026 | base_id = 0; |
1020 | base_prop.height = 0x7fffffff; |
1027 | base_prop.height = 0x7fffffff; |
1021 | base_prop.weight = rxvt_fontprop::medium; |
1028 | base_prop.weight = rxvt_fontprop::medium; |
… | |
… | |
1129 | bool |
1136 | bool |
1130 | rxvt_fontset::populate (const char *desc) |
1137 | rxvt_fontset::populate (const char *desc) |
1131 | { |
1138 | { |
1132 | clear (); |
1139 | clear (); |
1133 | |
1140 | |
|
|
1141 | fontdesc = strdup (desc); |
|
|
1142 | |
1134 | fonts.push_back (new_font (0, CS_UNICODE)); |
1143 | fonts.push_back (new_font (0, CS_UNICODE)); |
1135 | realize_font (0); |
1144 | realize_font (0); |
1136 | |
1145 | |
1137 | add_fonts (desc); |
1146 | add_fonts (desc); |
1138 | |
1147 | |
… | |
… | |
1154 | |
1163 | |
1155 | return true; |
1164 | return true; |
1156 | } |
1165 | } |
1157 | |
1166 | |
1158 | int |
1167 | int |
1159 | rxvt_fontset::find_font (unicode_t unicode) |
1168 | rxvt_fontset::find_font (unicode_t unicode, bool bold) |
1160 | { |
1169 | { |
1161 | for (unsigned int i = !!(0x20 <= unicode && unicode <= 0x7f); // skip pseudo-font for ascii |
1170 | for (unsigned int i = !!(0x20 <= unicode && unicode <= 0x7f); // skip pseudo-font for ascii |
1162 | i < fonts.size (); |
1171 | i < fonts.size (); |
1163 | i++) |
1172 | i++) |
1164 | { |
1173 | { |
… | |
… | |
1171 | |
1180 | |
1172 | if (!realize_font (i)) |
1181 | if (!realize_font (i)) |
1173 | goto next_font; |
1182 | goto next_font; |
1174 | } |
1183 | } |
1175 | |
1184 | |
|
|
1185 | if (f->cs == CS_UNKNOWN) |
|
|
1186 | goto next_font; |
|
|
1187 | |
|
|
1188 | if (bold && f->properties ().weight < rxvt_fontprop::bold) |
|
|
1189 | goto next_font; |
|
|
1190 | |
1176 | if (f->cs != CS_UNKNOWN && f->has_codepoint (unicode)) |
1191 | if (f->has_codepoint (unicode)) |
1177 | return i; |
1192 | return i; |
1178 | |
1193 | |
1179 | next_font: |
1194 | next_font: |
1180 | if (i == fonts.size () - 1 && fallback->name) |
1195 | if (i == fonts.size () - 1 && fallback->name) |
1181 | { |
1196 | { |
… | |
… | |
1183 | fallback++; |
1198 | fallback++; |
1184 | i = 0; |
1199 | i = 0; |
1185 | } |
1200 | } |
1186 | } |
1201 | } |
1187 | |
1202 | |
|
|
1203 | // if no bold font found, use a regular one |
|
|
1204 | if (bold) |
|
|
1205 | return find_font (unicode); |
|
|
1206 | |
1188 | return 0; /* we must return SOME font */ |
1207 | return 0; /* we must return SOME font */ |
1189 | } |
1208 | } |
1190 | |
1209 | |
1191 | |
1210 | |
1192 | |
1211 | |