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

Comparing rxvt-unicode/src/rxvtfont.C (file contents):
Revision 1.66 by root, Fri Feb 11 05:51:14 2005 UTC vs.
Revision 1.73 by root, Mon Nov 28 19:35:04 2005 UTC

14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details. 15 * GNU General Public License for more details.
16 * 16 *
17 * You should have received a copy of the GNU General Public License 17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software 18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 *---------------------------------------------------------------------*/ 20 *---------------------------------------------------------------------*/
21 21
22#include "../config.h" 22#include "../config.h"
23#include "rxvt.h" 23#include "rxvt.h"
24#include "rxvtutil.h" 24#include "rxvtutil.h"
130 { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, 130 { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" },
131 { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, 131 { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" },
132 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, 132 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" },
133 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, 133 { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" },
134#if XFT 134#if XFT
135 { CS_UNICODE, "xft:Bitstream Vera Sans Mono:antialias=false:autohint=true"}, 135 { CS_UNICODE, "xft:Bitstream Vera Sans Mono:antialias=false:autohint=true" },
136 { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" }, 136 { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" },
137 { CS_UNICODE, "xft:Andale Mono:antialias=false" }, 137 { CS_UNICODE, "xft:Andale Mono:antialias=false:autohint=false" },
138 { CS_UNICODE, "xft:Arial Unicode MS:antialias=false" }, 138 { CS_UNICODE, "xft:Arial Unicode MS:antialias=false:autohint=false" },
139 139
140 // FreeMono is usually uglier than x fonts, so try last only. 140 // FreeMono is usually uglier than x fonts, so try last only.
141 { CS_UNICODE, "xft:FreeMono:autohint=true" }, 141 { CS_UNICODE, "xft:FreeMono:autohint=true" },
142#endif 142#endif
143 143
716 716
717 int diff = 0; 717 int diff = 0;
718 718
719 if (replace_field (fname, list[i], 6, '0', field_str)) 719 if (replace_field (fname, list[i], 6, '0', field_str))
720 diff += 10; // slightly penalize scalable fonts 720 diff += 10; // slightly penalize scalable fonts
721 else if (replace_field (fname, list[i], 11, '0', "0"))
722 diff += 300; // more heavily penalize what looks like scaled bitmap fotns
721 723
722 if (!set_properties (p, fname)) 724 if (!set_properties (p, fname))
723 continue; 725 continue;
724 726
725 if (prop.height != rxvt_fontprop::unset 727 if (prop.height != rxvt_fontprop::unset
741 for (;;) 743 for (;;)
742 { 744 {
743 font_weight *best = fonts + count - 1; 745 font_weight *best = fonts + count - 1;
744 746
745 for (font_weight *w = best; w-- > fonts; ) 747 for (font_weight *w = best; w-- > fonts; )
746 if (w->diff < best->diff) 748 if (w->diff <= best->diff)
747 best = w; 749 best = w;
748 750
749 if (!best->name 751 if (!best->name
750 || !(f = XLoadQueryFont (disp, best->name))) 752 || !(f = XLoadQueryFont (disp, best->name)))
751 break; 753 break;
849 851
850 XCharStruct g; 852 XCharStruct g;
851 int dir_ret, asc_ret, des_ret; 853 int dir_ret, asc_ret, des_ret;
852 XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); 854 XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g);
853 855
854 int wcw = wcwidth (*t); if (wcw > 0) g.width = g.width / wcw; 856 int wcw = wcwidth (*t); if (wcw > 0) g.width = (g.width + wcw - 1) / wcw;
855 857
856 if (width < g.width) width = g.width; 858 if (width < g.width) width = g.width;
857 } 859 }
858 860
859 if (cs == CS_UNKNOWN) 861 if (cs == CS_UNKNOWN)
934 return true; 936 return true;
935 937
936 // check character against base font bounding box 938 // check character against base font bounding box
937 int w = xcs->width; 939 int w = xcs->width;
938 int wcw = wcwidth (unicode); 940 int wcw = wcwidth (unicode);
939 if (wcw > 0) w /= wcw; 941 if (wcw > 0) w = (w + wcw - 1) / wcw;
940 942
941 careful = w > prop->width; 943 careful = w > prop->width;
942 if (careful && w > prop->width * MAX_OVERLAP >> 2) 944 if (careful && w > prop->width * MAX_OVERLAP >> 2)
943 return false; 945 return false;
944 946
1096 return false; 1098 return false;
1097 1099
1098 FcValue v; 1100 FcValue v;
1099 1101
1100 if (prop.height != rxvt_fontprop::unset 1102 if (prop.height != rxvt_fontprop::unset
1101 || (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch 1103 && (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch
1102 && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) 1104 && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch))
1103 FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); 1105 FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height);
1104 1106
1105 if (prop.weight != rxvt_fontprop::unset 1107 if (prop.weight != rxvt_fontprop::unset
1106 && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) 1108 && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch)
1152 1154
1153 bool scalable = face->face_flags & FT_FACE_FLAG_SCALABLE; 1155 bool scalable = face->face_flags & FT_FACE_FLAG_SCALABLE;
1154 1156
1155 XftUnlockFace (f); 1157 XftUnlockFace (f);
1156 1158
1159 int glheight = height;
1160
1157 for (uint16_t *t = extent_test_chars + NUM_EXTENT_TEST_CHARS; t-- > extent_test_chars; ) 1161 for (uint16_t *t = extent_test_chars + NUM_EXTENT_TEST_CHARS; t-- > extent_test_chars; )
1158 { 1162 {
1159 FcChar16 ch = *t; 1163 FcChar16 ch = *t;
1160 1164
1161 if (cs != CS_UNICODE 1165 if (cs != CS_UNICODE
1169 continue; 1173 continue;
1170 1174
1171 XGlyphInfo g; 1175 XGlyphInfo g;
1172 XftTextExtents16 (disp, f, &ch, 1, &g); 1176 XftTextExtents16 (disp, f, &ch, 1, &g);
1173 1177
1178 g.width -= g.x;
1179
1174 int wcw = wcwidth (ch); 1180 int wcw = wcwidth (ch);
1175 if (wcw > 0) g.width = g.width / wcw; 1181 if (wcw > 0) g.width = (g.width + wcw - 1) / wcw;
1176 1182
1177 if (width < g.width) width = g.width; 1183 if (width < g.width ) width = g.width;
1178 if (height < g.height) height = g.height; 1184 if (height < g.height ) height = g.height;
1185 if (glheight < g.height - g.y) glheight = g.height - g.y;
1179 } 1186 }
1180 1187
1181 if (prop.height == rxvt_fontprop::unset 1188 if (prop.height == rxvt_fontprop::unset
1182 || height <= prop.height 1189 || (height <= prop.height && glheight <= prop.height)
1183 || height <= 2 1190 || height <= 2
1184 || !scalable) 1191 || !scalable)
1185 break; 1192 break;
1186 1193
1187 if (ftheight) 1194 if (ftheight)
1228 // check character against base font bounding box 1235 // check character against base font bounding box
1229 FcChar32 ch = unicode; 1236 FcChar32 ch = unicode;
1230 XGlyphInfo g; 1237 XGlyphInfo g;
1231 XftTextExtents32 (DISPLAY, f, &ch, 1, &g); 1238 XftTextExtents32 (DISPLAY, f, &ch, 1, &g);
1232 1239
1233 int w = g.width; 1240 int w = g.width - g.x;
1234 int wcw = wcwidth (unicode); 1241 int wcw = wcwidth (unicode);
1235 if (wcw > 0) w /= wcw; 1242 if (wcw > 0) w = (w + wcw - 1) / wcw;
1236 1243
1237 careful = w > prop->width; 1244 careful = w > prop->width;
1238 if (careful && w > prop->width * MAX_OVERLAP >> 2) 1245 if (careful && w > prop->width * MAX_OVERLAP >> 2)
1239 return false; 1246 return false;
1240 1247
1252 1259
1253 XGlyphInfo extents; 1260 XGlyphInfo extents;
1254 FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32)); 1261 FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32));
1255 FcChar32 *ep = enc; 1262 FcChar32 *ep = enc;
1256 int ewidth = 0; 1263 int ewidth = 0;
1257 int xoff = 0;
1258 1264
1259 while (len) 1265 while (len)
1260 { 1266 {
1261 int cwidth = r->TermWin.fwidth; 1267 int cwidth = r->TermWin.fwidth;
1262 FcChar32 fc = *text++; len--; 1268 FcChar32 fc = *text++; len--;
1263 FT_UInt gl;
1264 1269
1265 while (len && *text == NOCHAR) 1270 while (len && *text == NOCHAR)
1266 text++, len--, cwidth += r->TermWin.fwidth; 1271 text++, len--, cwidth += r->TermWin.fwidth;
1267 1272
1268 gl = XftCharIndex (d.display->display, f, fc);
1269 XftGlyphExtents (d.display->display, f, &gl, 1, &extents);
1270
1271 if (extents.xOff != cwidth && ep != enc)
1272 {
1273 if (xoff > ewidth) xoff = ewidth;
1274 XftDrawGlyphs (d, &r->pix_colors[fg].c, f,
1275 x + (ewidth - xoff >> 1),
1276 y + base, enc, ep - enc);
1277 x += ewidth;
1278
1279 ep = enc;
1280 ewidth = 0;
1281 xoff = 0;
1282 }
1283
1284 if (fc == ' ' && ep == enc) // skip leading spaces 1273 if (fc == ' ' && ep == enc) // skip leading spaces
1285 {
1286 x += cwidth; 1274 x += cwidth;
1287 continue;
1288 }
1289
1290 else 1275 else
1291 { 1276 {
1277 FT_UInt gl = XftCharIndex (d.display->display, f, fc);
1278 XftGlyphExtents (d.display->display, f, &gl, 1, &extents);
1279
1280 if (extents.xOff != cwidth)
1281 {
1282 if (ewidth)
1283 {
1284 XftDrawGlyphs (d, &r->pix_colors[fg].c, f,
1285 x, y + base, enc, ep - enc);
1286 x += ewidth;
1287
1288 ep = enc;
1289 ewidth = 0;
1290 }
1291
1292 if (extents.xOff > cwidth)
1293 extents.xOff = cwidth;
1294
1295 XftDrawGlyphs (d, &r->pix_colors[fg].c, f,
1296 x + (cwidth - extents.xOff >> 1),
1297 y + base, &gl, 1);
1298 x += cwidth;
1299 }
1300 else
1301 {
1292 *ep++ = gl; 1302 *ep++ = gl;
1293 ewidth += cwidth; 1303 ewidth += cwidth;
1294 xoff += extents.xOff; 1304 }
1295 } 1305 }
1296 } 1306 }
1297 1307
1298 if (ep != enc) 1308 if (ep != enc)
1299 {
1300 if (xoff > ewidth) xoff = ewidth;
1301 XftDrawGlyphs (d, &r->pix_colors[fg].c, f, 1309 XftDrawGlyphs (d, &r->pix_colors[fg].c, f,
1302 x + (ewidth - xoff >> 1),
1303 y + base, enc, ep - enc); 1310 x, y + base, enc, ep - enc);
1304 }
1305} 1311}
1306#endif 1312#endif
1307 1313
1308///////////////////////////////////////////////////////////////////////////// 1314/////////////////////////////////////////////////////////////////////////////
1309 1315
1310rxvt_fontset::rxvt_fontset (rxvt_t r) 1316rxvt_fontset::rxvt_fontset (rxvt_t r)
1311: r (r), fontdesc (0) 1317: fontdesc (0), r (r)
1312{ 1318{
1313 clear (); 1319 clear ();
1314} 1320}
1315 1321
1316rxvt_fontset::~rxvt_fontset () 1322rxvt_fontset::~rxvt_fontset ()
1381 char buf[512]; 1387 char buf[512];
1382 const char *end; 1388 const char *end;
1383 1389
1384 do 1390 do
1385 { 1391 {
1386 while (*desc <= ' ') desc++; 1392 while (*desc && *desc <= ' ')
1393 desc++;
1387 1394
1388 codeset cs = CS_UNICODE; 1395 codeset cs = CS_UNICODE;
1389 1396
1390 if (*desc == '[') 1397 if (*desc == '[')
1391 { 1398 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines