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.56 by root, Mon Aug 2 04:42:11 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
543{ 539{
544 clear (); 540 clear ();
545 541
546 char **list; 542 char **list;
547 int count; 543 int count;
548 list = XListFonts (DISPLAY, name, 512, &count); 544 list = XListFonts (DISPLAY, name, 1024, &count);
549 set_name (0); 545 set_name (0);
550 546
551 if (!list) 547 if (!list)
552 return false; 548 return false;
553 549
846{ 842{
847 rxvt_fontprop p; 843 rxvt_fontprop p;
848 844
849 FT_Face face = XftLockFace (f); 845 FT_Face face = XftLockFace (f);
850 846
851 p.width = width; p.height = height; 847 p.width = width;
852 p.weight = face->style_flags & FT_STYLE_FLAG_BOLD ? rxvt_fontprop::bold : rxvt_fontprop::medium; 848 p.height = height;
853 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;
854 853
855 XftUnlockFace (f); 854 XftUnlockFace (f);
856 855
857 return p; 856 return p;
858} 857}
871 870
872 if (!p) 871 if (!p)
873 return false; 872 return false;
874 873
875 FcValue v; 874 FcValue v;
875
876 if (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch)
877 FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height);
876 878
877 if (FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) 879 if (FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch)
878 FcPatternAddInteger (p, FC_WEIGHT, prop.weight); 880 FcPatternAddInteger (p, FC_WEIGHT, prop.weight);
879 881
880 if (FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch) 882 if (FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch)
1163 1165
1164 return true; 1166 return true;
1165} 1167}
1166 1168
1167int 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
1168rxvt_fontset::find_font (unicode_t unicode, bool bold) 1180rxvt_fontset::find_font (unicode_t unicode, bool bold)
1169{ 1181{
1182
1170 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
1171 i < fonts.size (); 1184 i < fonts.size ();
1172 i++) 1185 i++)
1173 { 1186 {
1174 rxvt_font *f = fonts[i]; 1187 rxvt_font *f = fonts[i];
1190 1203
1191 if (f->has_codepoint (unicode)) 1204 if (f->has_codepoint (unicode))
1192 return i; 1205 return i;
1193 1206
1194 next_font: 1207 next_font:
1195 if (i == fonts.size () - 1 && fallback->name) 1208 if (i == fonts.size () - 1)
1209 {
1210 if (fallback->name)
1196 { 1211 {
1212 // search through the fallback list
1197 fonts.push_back (new_font (fallback->name, fallback->cs)); 1213 fonts.push_back (new_font (fallback->name, fallback->cs));
1198 fallback++; 1214 fallback++;
1199 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 }
1200 } 1257 }
1201 } 1258 }
1202 1259
1203 // if no bold font found, use a regular one 1260 // if no bold font found, use a regular one
1204 if (bold) 1261 if (bold)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines