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.55 by root, Mon Jul 26 14:57:12 2004 UTC vs.
Revision 1.57 by root, Wed Aug 11 01:36:51 2004 UTC

99 { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, 99 { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" },
100 { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, 100 { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" },
101 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, 101 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" },
102 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, 102 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" },
103 103
104#if UNICODE_3 && XFT
105 { CS_UNICODE, "xft:Code2001" }, // contains many plane-1 characters
106#endif
107
108 { CS_UNKNOWN, 0 } 104 { CS_UNKNOWN, 0 }
109}; 105};
110 106
111///////////////////////////////////////////////////////////////////////////// 107/////////////////////////////////////////////////////////////////////////////
112 108
136{ 132{
137 if (len > enc_len) 133 if (len > enc_len)
138 { 134 {
139 free (enc_buf); 135 free (enc_buf);
140 enc_buf = malloc (len); 136 enc_buf = malloc (len);
137 enc_len = len;
141 } 138 }
142 139
143 return enc_buf; 140 return enc_buf;
144} 141}
145 142
542{ 539{
543 clear (); 540 clear ();
544 541
545 char **list; 542 char **list;
546 int count; 543 int count;
547 list = XListFonts (DISPLAY, name, 512, &count); 544 list = XListFonts (DISPLAY, name, 1024, &count);
548 set_name (0); 545 set_name (0);
549 546
550 if (!list) 547 if (!list)
551 return false; 548 return false;
552 549
845{ 842{
846 rxvt_fontprop p; 843 rxvt_fontprop p;
847 844
848 FT_Face face = XftLockFace (f); 845 FT_Face face = XftLockFace (f);
849 846
850 p.width = width; p.height = height; 847 p.width = width;
851 p.weight = face->style_flags & FT_STYLE_FLAG_BOLD ? rxvt_fontprop::bold : rxvt_fontprop::medium; 848 p.height = height;
852 p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC ? rxvt_fontprop::italic : rxvt_fontprop::roman; 849 p.weight = face->style_flags & FT_STYLE_FLAG_BOLD
850 ? rxvt_fontprop::bold : rxvt_fontprop::medium;
851 p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC
852 ? rxvt_fontprop::italic : rxvt_fontprop::roman;
853 853
854 XftUnlockFace (f); 854 XftUnlockFace (f);
855 855
856 return p; 856 return p;
857} 857}
870 870
871 if (!p) 871 if (!p)
872 return false; 872 return false;
873 873
874 FcValue v; 874 FcValue v;
875
876 if (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch)
877 FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height);
875 878
876 if (FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) 879 if (FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch)
877 FcPatternAddInteger (p, FC_WEIGHT, prop.weight); 880 FcPatternAddInteger (p, FC_WEIGHT, prop.weight);
878 881
879 if (FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch) 882 if (FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch)
1162 1165
1163 return true; 1166 return true;
1164} 1167}
1165 1168
1166int 1169int
1170rxvt_fontset::find_font (const char *name) const
1171{
1172 for (rxvt_font *const *f = fonts.begin (); f < fonts.end (); f++)
1173 if ((*f)->name && !strcmp ((*f)->name, name))
1174 return f - fonts.begin ();
1175
1176 return -1;
1177}
1178
1179int
1167rxvt_fontset::find_font (unicode_t unicode, bool bold) 1180rxvt_fontset::find_font (unicode_t unicode, bool bold)
1168{ 1181{
1182
1169 for (unsigned int i = !!(0x20 <= unicode && unicode <= 0x7f); // skip pseudo-font for ascii 1183 for (unsigned int i = !!(0x20 <= unicode && unicode <= 0x7f); // skip pseudo-font for ascii
1170 i < fonts.size (); 1184 i < fonts.size ();
1171 i++) 1185 i++)
1172 { 1186 {
1173 rxvt_font *f = fonts[i]; 1187 rxvt_font *f = fonts[i];
1189 1203
1190 if (f->has_codepoint (unicode)) 1204 if (f->has_codepoint (unicode))
1191 return i; 1205 return i;
1192 1206
1193 next_font: 1207 next_font:
1194 if (i == fonts.size () - 1 && fallback->name) 1208 if (i == fonts.size () - 1)
1209 {
1210 if (fallback->name)
1195 { 1211 {
1212 // search through the fallback list
1196 fonts.push_back (new_font (fallback->name, fallback->cs)); 1213 fonts.push_back (new_font (fallback->name, fallback->cs));
1197 fallback++; 1214 fallback++;
1198 i = 0; 1215 }
1216 else
1217 {
1218 // try to find a new font
1219 // only xft currently supported, as there is no
1220 // way to configure this and xft is easier to hack in,
1221 // while x11 has more framework in place already.
1222#if XFT
1223 // grab the first xft font that is suitable
1224 FcPattern *p = FcPatternCreate ();
1225
1226 FcCharSet *s = FcCharSetCreate ();
1227 FcCharSetAddChar (s, unicode);
1228 FcPatternAddCharSet (p, FC_CHARSET, s);
1229
1230 FcPatternAddInteger (p, FC_PIXEL_SIZE, base_prop.height);
1231 FcPatternAddInteger (p, FC_WEIGHT, base_prop.weight);
1232 FcPatternAddInteger (p, FC_SLANT, base_prop.slant);
1233
1234 XftResult result;
1235 FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result);
1236
1237 FcPatternDestroy (p);
1238
1239 if (match)
1240 {
1241 FcPatternDel (match, FC_CHARSET);
1242 char *font = (char *)FcNameUnparse (match);
1243 FcPatternDestroy (match);
1244
1245 if (find_font (font) < 0)
1246 {
1247 char fontname[4096];
1248 sprintf (fontname, "xft:%-.4090s", font);
1249
1250 fonts.push_back (new_font (fontname, CS_UNICODE));
1251 }
1252
1253 free (font);
1254 }
1255#endif
1256 }
1199 } 1257 }
1200 } 1258 }
1201 1259
1202 // if no bold font found, use a regular one 1260 // if no bold font found, use a regular one
1203 if (bold) 1261 if (bold)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines