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.213 by sf-exg, Sat Jun 19 09:13:51 2021 UTC vs.
Revision 1.221 by root, Thu Aug 26 03:58:29 2021 UTC

134# endif 134# endif
135#endif 135#endif
136 136
137 //{ CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, // this gem of a font has actual dotted circles within the combining character glyphs. 137 //{ CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, // this gem of a font has actual dotted circles within the combining character glyphs.
138#if XFT 138#if XFT
139 { CS_UNICODE, "xft:Bitstream Vera Sans Mono:antialias=false:autohint=true" }, 139 { CS_UNICODE, "xft:DejaVu Sans Mono:antialias=false:autohint=true" },
140 { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" }, 140 { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" },
141 { CS_UNICODE, "xft:Andale Mono:antialias=false:autohint=false" }, 141 { CS_UNICODE, "xft:Andale Mono:antialias=false:autohint=false" },
142 { CS_UNICODE, "xft:Arial Unicode MS:antialias=false:autohint=false" }, 142 { CS_UNICODE, "xft:Arial Unicode MS:antialias=false:autohint=false" },
143 143
144 // FreeMono is usually uglier than x fonts, so try after the others 144 // FreeMono is usually uglier than x fonts, so try after the others
145 { CS_UNICODE, "xft:FreeMono:autohint=true" }, 145 { CS_UNICODE, "xft:FreeMono:autohint=true" },
146#endif 146#endif
147 147
1137 1137
1138#if XFT 1138#if XFT
1139 1139
1140struct rxvt_font_xft : rxvt_font 1140struct rxvt_font_xft : rxvt_font
1141{ 1141{
1142#if XFT_CHAR_CACHE
1143 // we cache the qascii range xoffsets in the name of speed,
1144 // expecting terminals to deal mostly with these characters
1145 // we also assume the xoff always fits into uint8_t,
1146 // which is questionable, but let's see...
1147 // also, it is uncomfortably big, due to the uints.
1148 enum { char_cache_min = 0x20, char_cache_max = 0x7e };
1149 uint8_t xoff_cache [char_cache_max - char_cache_min + 1];
1150 FT_UInt glyph_cache [char_cache_max - char_cache_min + 1];
1151#endif
1152
1142 rxvt_font_xft () 1153 rxvt_font_xft ()
1143 { 1154 {
1144 f = 0; 1155 f = 0;
1145 } 1156 }
1146 1157
1252 break; 1263 break;
1253 } 1264 }
1254 1265
1255 FT_Face face = XftLockFace (f); 1266 FT_Face face = XftLockFace (f);
1256 1267
1268 // fuck me plenty: XftLockFace can actually return 0. try not to crash.
1269 // we also assume blindly that if the first lock succeeeds, then subsequent
1270 // locks will also succeed.
1271 if (!face)
1272 {
1273 XftFontClose (disp, f);
1274 success = false;
1275 break;
1276 }
1277
1257 ascent = (face->size->metrics.ascender + 63) >> 6; 1278 ascent = (face->size->metrics.ascender + 63) >> 6;
1258 descent = (-face->size->metrics.descender + 63) >> 6; 1279 descent = (-face->size->metrics.descender + 63) >> 6;
1259 height = max (ascent + descent, (face->size->metrics.height + 63) >> 6); 1280 height = max (ascent + descent, (face->size->metrics.height + 63) >> 6);
1260 width = 0; 1281 width = 0;
1261 1282
1327#if 0 // do it per-character 1348#if 0 // do it per-character
1328 if (prop.width != rxvt_fontprop::unset && width > prop.width) 1349 if (prop.width != rxvt_fontprop::unset && width > prop.width)
1329 { 1350 {
1330 clear (); 1351 clear ();
1331 success = false; 1352 success = false;
1353 }
1354#endif
1355
1356#if XFT_CHAR_CACHE
1357 // populate char cache
1358 for (FcChar16 ch = char_cache_min; ch <= char_cache_max; ++ch)
1359 {
1360 FT_UInt glyph = XftCharIndex (disp, f, ch);
1361 glyph_cache [ch - char_cache_min] = glyph;
1362
1363 XGlyphInfo g;
1364 XftGlyphExtents (disp, f, &glyph, 1, &g);
1365 xoff_cache [ch - char_cache_min] = g.xOff;
1332 } 1366 }
1333#endif 1367#endif
1334 1368
1335 return success; 1369 return success;
1336} 1370}
1363 int wcw = max (WCWIDTH (chr), 1); 1397 int wcw = max (WCWIDTH (chr), 1);
1364 1398
1365 XGlyphInfo g; 1399 XGlyphInfo g;
1366 XftTextExtents32 (term->dpy, f, &chr, 1, &g); 1400 XftTextExtents32 (term->dpy, f, &chr, 1, &g);
1367 1401
1402 int cwidth = prop->width * wcw;
1403
1404 // use same adjustments as in ->draw, see there
1405 g.x += g.xOff ? cwidth - g.xOff >> 1 : 0;
1406 g.x += g.xOff ? 0 : cwidth;
1407
1368 int w = g.width - g.x; 1408 int w = g.width - g.x;
1369 1409
1370 careful = g.x > 0 || w > prop->width * wcw; 1410 careful = g.x > 0 || w > cwidth;
1371 1411
1372 if (careful && !OVERLAP_OK (w, wcw, prop)) 1412 if (careful && !OVERLAP_OK (w, wcw, prop))
1373 return false; 1413 return false;
1374 1414
1375 // this weeds out _totally_ broken fonts, or glyphs 1415 // this weeds out _totally_ broken fonts, or glyphs
1406 while (len) 1446 while (len)
1407 { 1447 {
1408 int cwidth = term->fwidth; 1448 int cwidth = term->fwidth;
1409 FcChar32 chr = *text++; len--; 1449 FcChar32 chr = *text++; len--;
1410 1450
1411 // handle non-bmp chars when text_t is 16 bit
1412 #if ENABLE_COMBINING && !UNICODE_3
1413 if (ecb_expect_false (IS_COMPOSE (chr)))
1414 if (compose_char *cc = rxvt_composite [chr])
1415 if (cc->c2 == NOCHAR)
1416 chr = cc->c1;
1417 #endif
1418
1419 while (len && *text == NOCHAR) 1451 while (len && *text == NOCHAR)
1420 text++, len--, cwidth += term->fwidth; 1452 text++, len--, cwidth += term->fwidth;
1421 1453
1422 if (chr != ' ') // skip spaces 1454 if (chr != ' ') // skip spaces
1423 { 1455 {
1456 // handle non-bmp chars when text_t is 16 bit
1457 #if ENABLE_COMBINING && !UNICODE_3
1458 if (ecb_expect_false (IS_COMPOSE (chr)))
1459 if (compose_char *cc = rxvt_composite [chr])
1460 if (cc->c2 == NOCHAR)
1461 chr = cc->c1;
1462 #endif
1463
1424 #if 0 1464 #if 0
1425 FT_UInt glyphs [decltype (exp)::max_size]; 1465 FT_UInt glyphs [decltype (exp)::max_size];
1426 1466
1427 for (int i = 0; i < nchrs; ++i) 1467 for (int i = 0; i < nchrs; ++i)
1428 glyphs [i] = XftCharIndex (disp, f, chrs [i]); 1468 glyphs [i] = XftCharIndex (disp, f, chrs [i]);
1433 XftGlyphExtents (disp, f, glyphs+i, 1, &ep); 1473 XftGlyphExtents (disp, f, glyphs+i, 1, &ep);
1434 printf ("gs %4x g %4x + %3d,%3d o %3d,%3d wh %3d,%3d\n", chrs[i],glyphs[i],ep.x,ep.y,ep.xOff,ep.yOff,ep.width,ep.height); 1474 printf ("gs %4x g %4x + %3d,%3d o %3d,%3d wh %3d,%3d\n", chrs[i],glyphs[i],ep.x,ep.y,ep.xOff,ep.yOff,ep.width,ep.height);
1435 } 1475 }
1436 #endif 1476 #endif
1437 1477
1478 FT_UInt glyph;
1479 int xOff;
1480
1481 #if XFT_CHAR_CACHE
1482 if (ecb_expect_true (IN_RANGE_INC (chr, char_cache_min, char_cache_max)))
1483 {
1484 glyph = glyph_cache [chr - char_cache_min];
1485 xOff = xoff_cache [chr - char_cache_min];
1486 }
1487 else
1488 #endif
1489 {
1438 FT_UInt glyph = XftCharIndex (disp, f, chr); 1490 glyph = XftCharIndex (disp, f, chr);
1439 XGlyphInfo extents; 1491 XGlyphInfo extents;
1440 XftGlyphExtents (disp, f, &glyph, 1, &extents); 1492 XftGlyphExtents (disp, f, &glyph, 1, &extents);
1493 xOff = extents.xOff;
1494 }
1441 1495
1442 ep->glyph = glyph; 1496 ep->glyph = glyph;
1443 ep->x = x_; 1497 ep->x = x_;
1444 ep->y = y_ + ascent; 1498 ep->y = y_ + ascent;
1445 1499
1446 // the xft font cell might differ from the terminal font cell, 1500 // the xft font cell might differ from the terminal font cell,
1447 // in which case we use the average between the two. 1501 // in which case we use the average between the two.
1448 ep->x += cwidth - extents.xOff >> 1; 1502 ep->x += xOff ? cwidth - xOff >> 1 : 0;
1449 1503
1450 // xft/freetype represent combining characters as characters with zero 1504 // xft/freetype represent combining characters as characters with zero
1451 // width rendered over the previous character with some fonts, while 1505 // width rendered over the previous character with some fonts, while
1452 // in other fonts, they are considered normal characters, while yet 1506 // in other fonts, they are considered normal characters, while yet
1453 // in other fonts, they are shifted all over the place. 1507 // in other fonts, they are shifted all over the place.
1454 // we handle the first two cases by keying off on xOff being 0 1508 // we handle the first two cases by keying off on xOff being 0
1455 // for zero-width chars. normally, we would add extents.xOff 1509 // for zero-width chars. normally, we would add extents.xOff
1456 // of the base character here, but we don't have that, so we use cwidth. 1510 // of the base character here, but we don't have that, so we use cwidth.
1457 ep->x += extents.xOff ? 0 : cwidth; 1511 ep->x += xOff ? 0 : cwidth;
1458 1512
1459 ++ep; 1513 ++ep;
1460 } 1514 }
1461 1515
1462 x_ += cwidth; 1516 x_ += cwidth;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines