… | |
… | |
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 | |
1140 | struct rxvt_font_xft : rxvt_font |
1140 | struct 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 | |
… | |
… | |
1330 | clear (); |
1341 | clear (); |
1331 | success = false; |
1342 | success = false; |
1332 | } |
1343 | } |
1333 | #endif |
1344 | #endif |
1334 | |
1345 | |
|
|
1346 | #if XFT_CHAR_CACHE |
|
|
1347 | // populate char cache |
|
|
1348 | for (FcChar16 ch = char_cache_min; ch <= char_cache_max; ++ch) |
|
|
1349 | { |
|
|
1350 | FT_UInt glyph = XftCharIndex (disp, f, ch); |
|
|
1351 | glyph_cache [ch - char_cache_min] = glyph; |
|
|
1352 | |
|
|
1353 | XGlyphInfo g; |
|
|
1354 | XftGlyphExtents (disp, f, &glyph, 1, &g); |
|
|
1355 | xoff_cache [ch - char_cache_min] = g.xOff; |
|
|
1356 | } |
|
|
1357 | #endif |
|
|
1358 | |
1335 | return success; |
1359 | return success; |
1336 | } |
1360 | } |
1337 | |
1361 | |
1338 | bool |
1362 | bool |
1339 | rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
1363 | rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
1340 | { |
1364 | { |
1341 | careful = false; |
1365 | careful = false; |
1342 | |
1366 | |
1343 | rxvt_compose_expand_static<FcChar32> exp; |
1367 | // handle non-bmp chars when text_t is 16 bit |
|
|
1368 | #if ENABLE_COMBINING && !UNICODE_3 |
|
|
1369 | if (ecb_expect_false (IS_COMPOSE (unicode))) |
|
|
1370 | if (compose_char *cc = rxvt_composite [unicode]) |
|
|
1371 | if (cc->c2 == NOCHAR) |
|
|
1372 | unicode = cc->c1; |
|
|
1373 | else |
|
|
1374 | return false; |
|
|
1375 | else |
|
|
1376 | return false; |
|
|
1377 | #endif |
|
|
1378 | |
1344 | FcChar32 *chrs = exp (unicode); |
1379 | FcChar32 chr = unicode; |
1345 | int nchrs = exp.length (chrs); |
|
|
1346 | |
1380 | |
1347 | // we handle the sequence if the first char is available |
|
|
1348 | if (!XftCharExists (term->dpy, f, chrs [0])) |
1381 | if (!XftCharExists (term->dpy, f, chr)) |
1349 | return false; |
1382 | return false; |
1350 | |
1383 | |
1351 | if (!prop || prop->width == rxvt_fontprop::unset) |
1384 | if (!prop || prop->width == rxvt_fontprop::unset) |
1352 | return true; |
1385 | return true; |
1353 | |
1386 | |
1354 | // but we check against the whoile sequence bounding box |
1387 | int wcw = max (WCWIDTH (chr), 1); |
1355 | |
1388 | |
1356 | // check character against base font bounding box |
|
|
1357 | FcChar32 ch = unicode; |
|
|
1358 | XGlyphInfo g; |
1389 | XGlyphInfo g; |
1359 | XftTextExtents32 (term->dpy, f, chrs, nchrs, &g); |
1390 | XftTextExtents32 (term->dpy, f, &chr, 1, &g); |
|
|
1391 | |
|
|
1392 | int cwidth = prop->width * wcw; |
|
|
1393 | |
|
|
1394 | // use same adjustments as in ->draw, see there |
|
|
1395 | g.x += g.xOff ? cwidth - g.xOff >> 1 : 0; |
|
|
1396 | g.x += g.xOff ? 0 : cwidth; |
1360 | |
1397 | |
1361 | int w = g.width - g.x; |
1398 | int w = g.width - g.x; |
1362 | int wcw = max (WCWIDTH (chrs [0]), 1); |
|
|
1363 | |
1399 | |
1364 | careful = g.x > 0 || w > prop->width * wcw; |
1400 | careful = g.x > 0 || w > cwidth; |
1365 | |
1401 | |
1366 | if (careful && !OVERLAP_OK (w, wcw, prop)) |
1402 | if (careful && !OVERLAP_OK (w, wcw, prop)) |
1367 | return false; |
1403 | return false; |
1368 | |
1404 | |
1369 | // this weeds out _totally_ broken fonts, or glyphs |
1405 | // this weeds out _totally_ broken fonts, or glyphs |
… | |
… | |
1376 | void |
1412 | void |
1377 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1413 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1378 | const text_t *text, int len, |
1414 | const text_t *text, int len, |
1379 | int fg, int bg) |
1415 | int fg, int bg) |
1380 | { |
1416 | { |
1381 | XGlyphInfo extents; |
|
|
1382 | //XftGlyphSpec *enc = rxvt_temp_buf<XftGlyphSpec> (len);//D |
1417 | XftGlyphSpec *enc = rxvt_temp_buf<XftGlyphSpec> (len); |
1383 | //XftGlyphSpec *ep = enc;//D |
1418 | XftGlyphSpec *ep = enc; |
1384 | static vector<XftGlyphSpec> enc; enc.resize (0); // static to avoid malloc, still slow |
|
|
1385 | |
1419 | |
1386 | dTermDisplay; |
1420 | dTermDisplay; |
1387 | dTermGC; |
1421 | dTermGC; |
1388 | |
1422 | |
1389 | int w = term->fwidth * len; |
1423 | int w = term->fwidth * len; |
… | |
… | |
1400 | int y_ = buffered ? 0 : y; |
1434 | int y_ = buffered ? 0 : y; |
1401 | |
1435 | |
1402 | while (len) |
1436 | while (len) |
1403 | { |
1437 | { |
1404 | int cwidth = term->fwidth; |
1438 | int cwidth = term->fwidth; |
1405 | |
|
|
1406 | rxvt_compose_expand_static<FcChar32> exp; |
|
|
1407 | FcChar32 *chrs = exp (*text++); len--; |
1439 | FcChar32 chr = *text++; len--; |
1408 | int nchrs = exp.length (chrs); |
|
|
1409 | |
1440 | |
1410 | while (len && *text == NOCHAR) |
1441 | while (len && *text == NOCHAR) |
1411 | text++, len--, cwidth += term->fwidth; |
1442 | text++, len--, cwidth += term->fwidth; |
1412 | |
1443 | |
1413 | if (chrs [0] != ' ') // skip spaces |
1444 | if (chr != ' ') // skip spaces |
1414 | { |
1445 | { |
1415 | FT_UInt glyphs [rxvt_compose_expand_static<FcChar32>::max_size]; |
1446 | // handle non-bmp chars when text_t is 16 bit |
|
|
1447 | #if ENABLE_COMBINING && !UNICODE_3 |
|
|
1448 | if (ecb_expect_false (IS_COMPOSE (chr))) |
|
|
1449 | if (compose_char *cc = rxvt_composite [chr]) |
|
|
1450 | if (cc->c2 == NOCHAR) |
|
|
1451 | chr = cc->c1; |
|
|
1452 | #endif |
|
|
1453 | |
|
|
1454 | #if 0 |
|
|
1455 | FT_UInt glyphs [decltype (exp)::max_size]; |
1416 | |
1456 | |
1417 | for (int i = 0; i < nchrs; ++i) |
1457 | for (int i = 0; i < nchrs; ++i) |
1418 | glyphs [i] = XftCharIndex (disp, f, chrs [i]); |
1458 | glyphs [i] = XftCharIndex (disp, f, chrs [i]); |
1419 | |
1459 | |
1420 | XftGlyphExtents (disp, f, glyphs, nchrs, &extents); |
|
|
1421 | |
|
|
1422 | XftGlyphSpec ep; |
|
|
1423 | |
|
|
1424 | ep.x = x_ + (cwidth - extents.xOff >> 1); |
|
|
1425 | ep.y = y_ + ascent; |
|
|
1426 | |
|
|
1427 | if (extents.xOff == 0) |
|
|
1428 | ep.x = x_ + cwidth; |
|
|
1429 | |
|
|
1430 | for (int i = 0; i < nchrs; ++i) |
1460 | for (int i = 0; i < nchrs; ++i) |
1431 | { |
1461 | { |
1432 | ep.glyph = glyphs [i]; |
1462 | XGlyphInfo ep; |
1433 | enc.push_back (ep); |
1463 | XftGlyphExtents (disp, f, glyphs+i, 1, &ep); |
|
|
1464 | 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); |
1434 | } |
1465 | } |
|
|
1466 | #endif |
|
|
1467 | |
|
|
1468 | FT_UInt glyph; |
|
|
1469 | int xOff; |
|
|
1470 | |
|
|
1471 | #if XFT_CHAR_CACHE |
|
|
1472 | if (ecb_expect_true (IN_RANGE_INC (chr, char_cache_min, char_cache_max))) |
|
|
1473 | { |
|
|
1474 | glyph = glyph_cache [chr - char_cache_min]; |
|
|
1475 | xOff = xoff_cache [chr - char_cache_min]; |
|
|
1476 | } |
|
|
1477 | else |
|
|
1478 | #endif |
|
|
1479 | { |
|
|
1480 | glyph = XftCharIndex (disp, f, chr); |
|
|
1481 | XGlyphInfo extents; |
|
|
1482 | XftGlyphExtents (disp, f, &glyph, 1, &extents); |
|
|
1483 | xOff = extents.xOff; |
|
|
1484 | } |
|
|
1485 | |
|
|
1486 | ep->glyph = glyph; |
|
|
1487 | ep->x = x_; |
|
|
1488 | ep->y = y_ + ascent; |
|
|
1489 | |
|
|
1490 | // the xft font cell might differ from the terminal font cell, |
|
|
1491 | // in which case we use the average between the two. |
|
|
1492 | ep->x += xOff ? cwidth - xOff >> 1 : 0; |
|
|
1493 | |
|
|
1494 | // xft/freetype represent combining characters as characters with zero |
|
|
1495 | // width rendered over the previous character with some fonts, while |
|
|
1496 | // in other fonts, they are considered normal characters, while yet |
|
|
1497 | // in other fonts, they are shifted all over the place. |
|
|
1498 | // we handle the first two cases by keying off on xOff being 0 |
|
|
1499 | // for zero-width chars. normally, we would add extents.xOff |
|
|
1500 | // of the base character here, but we don't have that, so we use cwidth. |
|
|
1501 | ep->x += xOff ? 0 : cwidth; |
|
|
1502 | |
|
|
1503 | ++ep; |
1435 | } |
1504 | } |
1436 | |
1505 | |
1437 | x_ += cwidth; |
1506 | x_ += cwidth; |
1438 | } |
1507 | } |
1439 | |
1508 | |
1440 | if (buffered) |
1509 | if (buffered) |
1441 | { |
1510 | { |
1442 | if (!enc.empty ()) |
1511 | if (ep != enc) |
1443 | { |
1512 | { |
1444 | rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); |
1513 | rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); |
1445 | |
1514 | |
1446 | #ifdef HAVE_IMG |
1515 | #ifdef HAVE_IMG |
1447 | Picture dst = 0; // the only assignment is done conditionally in the following if condition |
1516 | Picture dst = 0; // the only assignment is done conditionally in the following if condition |
… | |
… | |
1493 | } |
1562 | } |
1494 | else |
1563 | else |
1495 | #endif |
1564 | #endif |
1496 | XftDrawRect (d2, &term->pix_colors[bg >= 0 ? bg : Color_bg].c, 0, 0, w, h); |
1565 | XftDrawRect (d2, &term->pix_colors[bg >= 0 ? bg : Color_bg].c, 0, 0, w, h); |
1497 | |
1566 | |
1498 | XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, &enc[0], enc.size ()); |
1567 | XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, enc, ep - enc); |
1499 | XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y); |
1568 | XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y); |
1500 | } |
1569 | } |
1501 | else |
1570 | else |
1502 | clear_rect (d, x, y, w, h, bg); |
1571 | clear_rect (d, x, y, w, h, bg); |
1503 | } |
1572 | } |
1504 | else |
1573 | else |
1505 | { |
1574 | { |
1506 | clear_rect (d, x, y, w, h, bg); |
1575 | clear_rect (d, x, y, w, h, bg); |
1507 | XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, &enc[0], enc.size ()); |
1576 | XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc); |
1508 | } |
1577 | } |
1509 | } |
1578 | } |
1510 | |
1579 | |
1511 | #endif |
1580 | #endif |
1512 | |
1581 | |
… | |
… | |
1708 | } |
1777 | } |
1709 | |
1778 | |
1710 | int |
1779 | int |
1711 | rxvt_fontset::find_font_idx (unicode_t unicode) |
1780 | rxvt_fontset::find_font_idx (unicode_t unicode) |
1712 | { |
1781 | { |
1713 | // this limits fmap size. it has to accomodate COMPOSE_HI when UNICODE_3 |
1782 | // this limits fmap size. it has to accommodate COMPOSE_HI when UNICODE_3 |
1714 | if (unicode > 0x1fffff) |
1783 | if (unicode > 0x1fffff) |
1715 | return 0; |
1784 | return 0; |
1716 | |
1785 | |
1717 | unicode_t hi = unicode >> 8; |
1786 | unicode_t hi = unicode >> 8; |
1718 | |
1787 | |