ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/defaultfont.C
(Generate patch)

Comparing rxvt-unicode/src/defaultfont.C (file contents):
Revision 1.54 by root, Mon Jun 21 19:47:51 2004 UTC vs.
Revision 1.59 by root, Wed Aug 11 15:55:35 2004 UTC

92#endif 92#endif
93 93
94#if XFT 94#if XFT
95 { CS_UNICODE, "xft:Andale Mono" }, 95 { CS_UNICODE, "xft:Andale Mono" },
96 { CS_UNICODE, "xft:Arial Unicode MS" }, 96 { CS_UNICODE, "xft:Arial Unicode MS" },
97 { CS_UNICODE, "xft:FreeMono" },
98#endif 97#endif
99 { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, 98 { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" },
100 { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, 99 { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" },
101 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, 100 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" },
102 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, 101 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" },
103 102#if XFT
104#if UNICODE_3 && XFT 103 // FreeMono is usually uglier than x fonts, so try last only.
105 { CS_UNICODE, "xft:Code2001" }, // contains many plane-1 characters 104 //{ CS_UNICODE, "xft:FreeMono" },
106#endif 105#endif
107 106
108 { CS_UNKNOWN, 0 } 107 { CS_UNKNOWN, 0 }
109}; 108};
110 109
136{ 135{
137 if (len > enc_len) 136 if (len > enc_len)
138 { 137 {
139 free (enc_buf); 138 free (enc_buf);
140 enc_buf = malloc (len); 139 enc_buf = malloc (len);
140 enc_len = len;
141 } 141 }
142 142
143 return enc_buf; 143 return enc_buf;
144} 144}
145 145
542{ 542{
543 clear (); 543 clear ();
544 544
545 char **list; 545 char **list;
546 int count; 546 int count;
547 list = XListFonts (DISPLAY, name, 512, &count); 547 list = XListFonts (DISPLAY, name, 1024, &count);
548 set_name (0); 548 set_name (0);
549 549
550 if (!list) 550 if (!list)
551 return false; 551 return false;
552 552
845{ 845{
846 rxvt_fontprop p; 846 rxvt_fontprop p;
847 847
848 FT_Face face = XftLockFace (f); 848 FT_Face face = XftLockFace (f);
849 849
850 p.width = width; p.height = height; 850 p.width = width;
851 p.weight = face->style_flags & FT_STYLE_FLAG_BOLD ? rxvt_fontprop::bold : rxvt_fontprop::medium; 851 p.height = height;
852 p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC ? rxvt_fontprop::italic : rxvt_fontprop::roman; 852 p.weight = face->style_flags & FT_STYLE_FLAG_BOLD
853 ? rxvt_fontprop::bold : rxvt_fontprop::medium;
854 p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC
855 ? rxvt_fontprop::italic : rxvt_fontprop::roman;
853 856
854 XftUnlockFace (f); 857 XftUnlockFace (f);
855 858
856 return p; 859 return p;
857} 860}
871 if (!p) 874 if (!p)
872 return false; 875 return false;
873 876
874 FcValue v; 877 FcValue v;
875 878
879 if (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch)
880 FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height);
881
876 if (FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) 882 if (FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch)
877 FcPatternAddInteger (p, FC_WEIGHT, prop.weight); 883 FcPatternAddInteger (p, FC_WEIGHT, prop.weight);
878 884
879 if (FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch) 885 if (FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch)
880 FcPatternAddInteger (p, FC_SLANT, prop.slant); 886 FcPatternAddInteger (p, FC_SLANT, prop.slant);
887
888 if (FcPatternGet (p, FC_MINSPACE, 0, &v) != FcResultMatch)
889 FcPatternAddBool (p, FC_MINSPACE, 1);
881 890
882#if 0 // clipping unfortunately destroys our precious double-width-characters 891#if 0 // clipping unfortunately destroys our precious double-width-characters
883 // clip width, we can't do better, or can we? 892 // clip width, we can't do better, or can we?
884 if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) 893 if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch)
885 FcPatternAddInteger (p, FC_CHAR_WIDTH, prop.width); 894 FcPatternAddInteger (p, FC_CHAR_WIDTH, prop.width);
886#endif 895#endif
887
888 //FcPatternAddBool (p, FC_MINSPACE, 1);
889 896
890 XftResult result; 897 XftResult result;
891 FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); 898 FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result);
892 899
893 FcPatternDestroy (p); 900 FcPatternDestroy (p);
1162 1169
1163 return true; 1170 return true;
1164} 1171}
1165 1172
1166int 1173int
1174rxvt_fontset::find_font (const char *name) const
1175{
1176 for (rxvt_font *const *f = fonts.begin (); f < fonts.end (); f++)
1177 if ((*f)->name && !strcmp ((*f)->name, name))
1178 return f - fonts.begin ();
1179
1180 return -1;
1181}
1182
1183int
1167rxvt_fontset::find_font (unicode_t unicode) 1184rxvt_fontset::find_font (unicode_t unicode, bool bold)
1168{ 1185{
1186
1169 for (unsigned int i = !!(0x20 <= unicode && unicode <= 0x7f); // skip pseudo-font for ascii 1187 for (unsigned int i = !!(0x20 <= unicode && unicode <= 0x7f); // skip pseudo-font for ascii
1170 i < fonts.size (); 1188 i < fonts.size ();
1171 i++) 1189 i++)
1172 { 1190 {
1173 rxvt_font *f = fonts[i]; 1191 rxvt_font *f = fonts[i];
1179 1197
1180 if (!realize_font (i)) 1198 if (!realize_font (i))
1181 goto next_font; 1199 goto next_font;
1182 } 1200 }
1183 1201
1202 if (f->cs == CS_UNKNOWN)
1203 goto next_font;
1204
1205 if (bold && f->properties ().weight < rxvt_fontprop::bold)
1206 goto next_font;
1207
1184 if (f->cs != CS_UNKNOWN && f->has_codepoint (unicode)) 1208 if (f->has_codepoint (unicode))
1185 return i; 1209 return i;
1186 1210
1187 next_font: 1211 next_font:
1188 if (i == fonts.size () - 1 && fallback->name) 1212 if (i == fonts.size () - 1)
1213 {
1214 if (fallback->name)
1189 { 1215 {
1216 // search through the fallback list
1190 fonts.push_back (new_font (fallback->name, fallback->cs)); 1217 fonts.push_back (new_font (fallback->name, fallback->cs));
1191 fallback++; 1218 fallback++;
1192 i = 0;
1193 } 1219 }
1220 else
1221 {
1222 // try to find a new font.
1223 // only xft currently supported, as there is no
1224 // way to configure this and xft is easier to hack in,
1225 // while x11 has more framework in place already.
1226#if XFT
1227 // grab the first xft font that seems suitable
1228 FcPattern *p = FcPatternCreate ();
1229
1230 FcCharSet *s = FcCharSetCreate ();
1231 FcCharSetAddChar (s, unicode);
1232 FcPatternAddCharSet (p, FC_CHARSET, s);
1233 // charsets don't help that much, as xft might return
1234 // a non-matching font even if a better font is available :/
1235
1236 FcPatternAddInteger (p, FC_PIXEL_SIZE, base_prop.height);
1237 FcPatternAddInteger (p, FC_WEIGHT, base_prop.weight);
1238 FcPatternAddInteger (p, FC_SLANT, base_prop.slant);
1239 FcPatternAddBool (p, FC_MINSPACE, 1);
1240 //FcPatternAddBool (p, FC_ANTIALIAS, 1);
1241
1242 XftResult result;
1243 FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result);
1244
1245 FcPatternDestroy (p);
1246
1247 if (match)
1248 {
1249 FcPatternDel (match, FC_CHARSET);
1250 char *font = (char *)FcNameUnparse (match);
1251 FcPatternDestroy (match);
1252
1253 if (find_font (font) < 0)
1254 {
1255 char fontname[4096];
1256 sprintf (fontname, "xft:%-.4090s", font);
1257
1258 fonts.push_back (new_font (fontname, CS_UNICODE));
1259 }
1260
1261 free (font);
1262 }
1263#endif
1264 }
1265 }
1194 } 1266 }
1267
1268 // if no bold font found, use a regular one
1269 if (bold)
1270 return find_font (unicode);
1195 1271
1196 return 0; /* we must return SOME font */ 1272 return 0; /* we must return SOME font */
1197} 1273}
1198 1274
1199 1275

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines