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.209 by root, Fri Jun 18 21:58:03 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
1330 clear (); 1351 clear ();
1331 success = false; 1352 success = false;
1332 } 1353 }
1333#endif 1354#endif
1334 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;
1366 }
1367#endif
1368
1335 return success; 1369 return success;
1336} 1370}
1337 1371
1338bool 1372bool
1339rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const 1373rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
1340{ 1374{
1341 careful = false; 1375 careful = false;
1342 1376
1343 rxvt_compose_expand_static<FcChar32> exp; 1377 // handle non-bmp chars when text_t is 16 bit
1344 FcChar32 *chrs = exp (unicode); 1378#if ENABLE_COMBINING && !UNICODE_3
1345 int nchrs = exp.length (chrs); 1379 if (ecb_expect_false (IS_COMPOSE (unicode)))
1346 1380 if (compose_char *cc = rxvt_composite [unicode])
1347 // allm chars in sequence must be available 1381 if (cc->c2 == NOCHAR)
1348 for (int i = 0; i < nchrs; ++i) 1382 unicode = cc->c1;
1349 if (!XftCharExists (term->dpy, f, chrs [i])) 1383 else
1384 return false;
1385 else
1350 return false; 1386 return false;
1387#endif
1388
1389 FcChar32 chr = unicode;
1390
1391 if (!XftCharExists (term->dpy, f, chr))
1392 return false;
1351 1393
1352 if (!prop || prop->width == rxvt_fontprop::unset) 1394 if (!prop || prop->width == rxvt_fontprop::unset)
1353 return true; 1395 return true;
1354 1396
1355 int wcw = max (WCWIDTH (chrs [0]), 1); 1397 int wcw = max (WCWIDTH (chr), 1);
1356 1398
1357 // we check against all glyph sizes. this is probably wrong,
1358 // due to the way ->draw positions these glyphs.
1359 for (int i = 0; i < nchrs; ++i)
1360 {
1361 XGlyphInfo g; 1399 XGlyphInfo g;
1362 XftTextExtents32 (term->dpy, f, chrs + i, 1, &g); 1400 XftTextExtents32 (term->dpy, f, &chr, 1, &g);
1363 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
1364 int w = g.width - g.x; 1408 int w = g.width - g.x;
1365 1409
1366 careful = g.x > 0 || w > prop->width * wcw; 1410 careful = g.x > 0 || w > cwidth;
1367 1411
1368 if (careful && !OVERLAP_OK (w, wcw, prop)) 1412 if (careful && !OVERLAP_OK (w, wcw, prop))
1369 return false; 1413 return false;
1370 1414
1371 // this weeds out _totally_ broken fonts, or glyphs 1415 // this weeds out _totally_ broken fonts, or glyphs
1372 if (!OVERLAP_OK (g.xOff, wcw, prop)) 1416 if (!OVERLAP_OK (g.xOff, wcw, prop))
1373 return false; 1417 return false;
1374 }
1375 1418
1376 return true; 1419 return true;
1377} 1420}
1378 1421
1379void 1422void
1380rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, 1423rxvt_font_xft::draw (rxvt_drawable &d, int x, int y,
1381 const text_t *text, int len, 1424 const text_t *text, int len,
1382 int fg, int bg) 1425 int fg, int bg)
1383{ 1426{
1384 //XftGlyphSpec *enc = rxvt_temp_buf<XftGlyphSpec> (len);//D 1427 XftGlyphSpec *enc = rxvt_temp_buf<XftGlyphSpec> (len);
1385 //XftGlyphSpec *ep = enc;//D 1428 XftGlyphSpec *ep = enc;
1386 static vector<XftGlyphSpec> enc; enc.resize (0); // static to avoid malloc, still slow
1387 1429
1388 dTermDisplay; 1430 dTermDisplay;
1389 dTermGC; 1431 dTermGC;
1390 1432
1391 int w = term->fwidth * len; 1433 int w = term->fwidth * len;
1402 int y_ = buffered ? 0 : y; 1444 int y_ = buffered ? 0 : y;
1403 1445
1404 while (len) 1446 while (len)
1405 { 1447 {
1406 int cwidth = term->fwidth; 1448 int cwidth = term->fwidth;
1407
1408 rxvt_compose_expand_static<FcChar32> exp;
1409 FcChar32 *chrs = exp (*text++); len--; 1449 FcChar32 chr = *text++; len--;
1410 int nchrs = exp.length (chrs);
1411 1450
1412 while (len && *text == NOCHAR) 1451 while (len && *text == NOCHAR)
1413 text++, len--, cwidth += term->fwidth; 1452 text++, len--, cwidth += term->fwidth;
1414 1453
1415 if (chrs [0] != ' ') // skip spaces 1454 if (chr != ' ') // skip spaces
1416 { 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
1417 #if 1 1464 #if 0
1418 FT_UInt glyphs [decltype (exp)::max_size]; 1465 FT_UInt glyphs [decltype (exp)::max_size];
1419 1466
1420 for (int i = 0; i < nchrs; ++i) 1467 for (int i = 0; i < nchrs; ++i)
1421 glyphs [i] = XftCharIndex (disp, f, chrs [i]); 1468 glyphs [i] = XftCharIndex (disp, f, chrs [i]);
1422 1469
1426 XftGlyphExtents (disp, f, glyphs+i, 1, &ep); 1473 XftGlyphExtents (disp, f, glyphs+i, 1, &ep);
1427 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);
1428 } 1475 }
1429 #endif 1476 #endif
1430 1477
1431 FT_UInt glyph = XftCharIndex (disp, f, chrs [0]); 1478 FT_UInt glyph;
1432 XGlyphInfo extents0; 1479 int xOff;
1433 XftGlyphExtents (disp, f, &glyph, 1, &extents0);
1434 1480
1435 int cx = x_ + (cwidth - extents0.xOff >> 1); 1481 #if XFT_CHAR_CACHE
1436 int cy = y_ + ascent; 1482 if (ecb_expect_true (IN_RANGE_INC (chr, char_cache_min, char_cache_max)))
1437
1438 XftGlyphSpec ep;
1439 ep.glyph = glyph;
1440 ep.x = cx + (extents0.xOff ? 0 : extents0.xOff);
1441 ep.y = cy;
1442
1443 enc.push_back (ep);
1444
1445 for (int i = 1; ecb_expect_false (i < nchrs); ++i)
1446 { 1483 {
1484 glyph = glyph_cache [chr - char_cache_min];
1485 xOff = xoff_cache [chr - char_cache_min];
1486 }
1487 else
1488 #endif
1489 {
1447 FT_UInt glyph = XftCharIndex (disp, f, chrs [i]); 1490 glyph = XftCharIndex (disp, f, chr);
1448 XGlyphInfo extents; 1491 XGlyphInfo extents;
1449 XftGlyphExtents (disp, f, &glyph, 1, &extents); 1492 XftGlyphExtents (disp, f, &glyph, 1, &extents);
1450 1493 xOff = extents.xOff;
1451 ep.glyph = glyph;
1452 ep.x = cx + (extents.xOff ? 0 : extents0.xOff);
1453
1454 enc.push_back (ep);
1455 } 1494 }
1495
1496 ep->glyph = glyph;
1497 ep->x = x_;
1498 ep->y = y_ + ascent;
1499
1500 // the xft font cell might differ from the terminal font cell,
1501 // in which case we use the average between the two.
1502 ep->x += xOff ? cwidth - xOff >> 1 : 0;
1503
1504 // xft/freetype represent combining characters as characters with zero
1505 // width rendered over the previous character with some fonts, while
1506 // in other fonts, they are considered normal characters, while yet
1507 // in other fonts, they are shifted all over the place.
1508 // we handle the first two cases by keying off on xOff being 0
1509 // for zero-width chars. normally, we would add extents.xOff
1510 // of the base character here, but we don't have that, so we use cwidth.
1511 ep->x += xOff ? 0 : cwidth;
1512
1513 ++ep;
1456 } 1514 }
1457 1515
1458 x_ += cwidth; 1516 x_ += cwidth;
1459 } 1517 }
1460 1518
1461 if (buffered) 1519 if (buffered)
1462 { 1520 {
1463 if (!enc.empty ()) 1521 if (ep != enc)
1464 { 1522 {
1465 rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); 1523 rxvt_drawable &d2 = d.screen->scratch_drawable (w, h);
1466 1524
1467#ifdef HAVE_IMG 1525#ifdef HAVE_IMG
1468 Picture dst = 0; // the only assignment is done conditionally in the following if condition 1526 Picture dst = 0; // the only assignment is done conditionally in the following if condition
1514 } 1572 }
1515 else 1573 else
1516#endif 1574#endif
1517 XftDrawRect (d2, &term->pix_colors[bg >= 0 ? bg : Color_bg].c, 0, 0, w, h); 1575 XftDrawRect (d2, &term->pix_colors[bg >= 0 ? bg : Color_bg].c, 0, 0, w, h);
1518 1576
1519 XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, &enc[0], enc.size ()); 1577 XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, enc, ep - enc);
1520 XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y); 1578 XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y);
1521 } 1579 }
1522 else 1580 else
1523 clear_rect (d, x, y, w, h, bg); 1581 clear_rect (d, x, y, w, h, bg);
1524 } 1582 }
1525 else 1583 else
1526 { 1584 {
1527 clear_rect (d, x, y, w, h, bg); 1585 clear_rect (d, x, y, w, h, bg);
1528 XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, &enc[0], enc.size ()); 1586 XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc);
1529 } 1587 }
1530} 1588}
1531 1589
1532#endif 1590#endif
1533 1591
1729} 1787}
1730 1788
1731int 1789int
1732rxvt_fontset::find_font_idx (unicode_t unicode) 1790rxvt_fontset::find_font_idx (unicode_t unicode)
1733{ 1791{
1734 // this limits fmap size. it has to accomodate COMPOSE_HI when UNICODE_3 1792 // this limits fmap size. it has to accommodate COMPOSE_HI when UNICODE_3
1735 if (unicode > 0x1fffff) 1793 if (unicode > 0x1fffff)
1736 return 0; 1794 return 0;
1737 1795
1738 unicode_t hi = unicode >> 8; 1796 unicode_t hi = unicode >> 8;
1739 1797

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines