… | |
… | |
212 | } |
212 | } |
213 | |
213 | |
214 | ///////////////////////////////////////////////////////////////////////////// |
214 | ///////////////////////////////////////////////////////////////////////////// |
215 | |
215 | |
216 | rxvt_font::rxvt_font () |
216 | rxvt_font::rxvt_font () |
217 | : name(0), width(rxvt_fontprop::unset), height(rxvt_fontprop::unset), can_compose(false) |
217 | : name(0), width(rxvt_fontprop::unset), height(rxvt_fontprop::unset) |
218 | { |
218 | { |
219 | } |
219 | } |
220 | |
220 | |
221 | void |
221 | void |
222 | rxvt_font::set_name (char *name_) |
222 | rxvt_font::set_name (char *name_) |
… | |
… | |
313 | if (unicode >= 0x2500 && unicode <= 0x259f && |
313 | if (unicode >= 0x2500 && unicode <= 0x259f && |
314 | !term->option (Opt_skipBuiltinGlyphs)) |
314 | !term->option (Opt_skipBuiltinGlyphs)) |
315 | return true; |
315 | return true; |
316 | #endif |
316 | #endif |
317 | |
317 | |
318 | if (IS_COMPOSE (unicode)) |
318 | // we do not check for IS_COMPOSE here, as this would |
319 | return true; |
319 | // rob other fonts from taking over. |
320 | |
320 | |
321 | switch (unicode) |
321 | switch (unicode) |
322 | { |
322 | { |
323 | case ZERO_WIDTH_CHAR: |
323 | case ZERO_WIDTH_CHAR: |
324 | case NOCHAR: |
324 | case NOCHAR: |
… | |
… | |
442 | #else |
442 | #else |
443 | if (0) |
443 | if (0) |
444 | ; |
444 | ; |
445 | #endif |
445 | #endif |
446 | #if ENABLE_COMBINING |
446 | #if ENABLE_COMBINING |
447 | else if (IS_COMPOSE (t) && rxvt_composite[t]) |
447 | else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) |
448 | { |
448 | { |
449 | min_it (width, 2); // we only support wcwidth up to 2 |
449 | min_it (width, 2); // we only support wcwidth up to 2 |
450 | |
|
|
451 | #if NOT_YET |
|
|
452 | vector<text_t> chrs; |
|
|
453 | chrs.reserve (rxvt_composite.expand (t)); |
|
|
454 | rxvt_composite.expand (t, &chrs[0]); |
|
|
455 | |
|
|
456 | while (!chrs.empty ()) |
|
|
457 | { |
|
|
458 | rxvt_font *f1 = fs->find_font_idx (chrs[0]) |
|
|
459 | |
|
|
460 | int i = 0; |
|
|
461 | while (i < chrs.size () - 1 |
|
|
462 | && f1->can_combine |
|
|
463 | && f1->has-char (chrs[i + 1], careful) |
|
|
464 | && !careful |
|
|
465 | ++i; |
|
|
466 | |
|
|
467 | (*fs)[f1]->draw (d, x, y, &chrs[0], width, fg, bg); |
|
|
468 | chrs.erase (&chrs[0], &chrs[i]); |
|
|
469 | } |
|
|
470 | #endif |
|
|
471 | |
|
|
472 | #if 1 |
|
|
473 | text_t chrs[2]; |
450 | text_t chrs[2]; |
474 | chrs [1] = NOCHAR; |
451 | chrs [1] = NOCHAR; |
475 | |
452 | |
476 | *chrs = cc->c1; |
453 | *chrs = cc->c1; |
477 | rxvt_font *f1 = (*fs)[fs->find_font_idx (cc->c1)]; |
454 | rxvt_font *f1 = (*fs)[fs->find_font_idx (cc->c1)]; |
… | |
… | |
487 | ? f1 |
464 | ? f1 |
488 | : (*fs)[fs->find_font_idx (cc->c2)]; |
465 | : (*fs)[fs->find_font_idx (cc->c2)]; |
489 | |
466 | |
490 | f2->draw (d, x, y, chrs, width, fg, Color_none); |
467 | f2->draw (d, x, y, chrs, width, fg, Color_none); |
491 | } |
468 | } |
492 | #endif |
|
|
493 | } |
469 | } |
494 | #endif |
470 | #endif |
495 | else |
471 | else |
496 | switch (t) |
472 | switch (t) |
497 | { |
473 | { |
… | |
… | |
1163 | |
1139 | |
1164 | struct rxvt_font_xft : rxvt_font |
1140 | struct rxvt_font_xft : rxvt_font |
1165 | { |
1141 | { |
1166 | rxvt_font_xft () |
1142 | rxvt_font_xft () |
1167 | { |
1143 | { |
1168 | can_compose = true; |
|
|
1169 | f = 0; |
1144 | f = 0; |
1170 | } |
1145 | } |
1171 | |
1146 | |
1172 | void clear (); |
1147 | void clear (); |
1173 | |
1148 | |
… | |
… | |
1317 | if (glheight < g.height - g.y) glheight = g.height - g.y; |
1292 | if (glheight < g.height - g.y) glheight = g.height - g.y; |
1318 | } |
1293 | } |
1319 | |
1294 | |
1320 | if (!width) |
1295 | if (!width) |
1321 | { |
1296 | { |
1322 | rxvt_warn ("unable to calculate font width for '%s', ignoring.\n", name); |
1297 | rxvt_warn ("unable to calculate font width for '%s', using max_advance_width.\n", name); |
1323 | |
1298 | width = f->max_advance_width; |
1324 | XftFontClose (disp, f); |
|
|
1325 | f = 0; |
|
|
1326 | |
|
|
1327 | success = false; |
|
|
1328 | break; |
1299 | break; |
1329 | } |
1300 | } |
1330 | |
1301 | |
1331 | if (prop.height == rxvt_fontprop::unset |
1302 | if (prop.height == rxvt_fontprop::unset |
1332 | || (height <= prop.height && glheight <= prop.height) |
1303 | || (height <= prop.height && glheight <= prop.height) |
… | |
… | |
1367 | bool |
1338 | bool |
1368 | rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
1339 | rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
1369 | { |
1340 | { |
1370 | careful = false; |
1341 | careful = false; |
1371 | |
1342 | |
|
|
1343 | rxvt_compose_expand_static<FcChar32> exp; |
|
|
1344 | FcChar32 *chrs = exp (unicode); |
|
|
1345 | int nchrs = exp.length (chrs); |
|
|
1346 | |
|
|
1347 | // allm chars in sequence must be available |
|
|
1348 | for (int i = 0; i < nchrs; ++i) |
1372 | if (!XftCharExists (term->dpy, f, unicode)) |
1349 | if (!XftCharExists (term->dpy, f, chrs [i])) |
1373 | return false; |
1350 | return false; |
1374 | |
1351 | |
1375 | if (!prop || prop->width == rxvt_fontprop::unset) |
1352 | if (!prop || prop->width == rxvt_fontprop::unset) |
1376 | return true; |
1353 | return true; |
1377 | |
1354 | |
1378 | // check character against base font bounding box |
1355 | int wcw = max (WCWIDTH (chrs [0]), 1); |
1379 | FcChar32 ch = unicode; |
1356 | |
|
|
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 | { |
1380 | XGlyphInfo g; |
1361 | XGlyphInfo g; |
1381 | XftTextExtents32 (term->dpy, f, &ch, 1, &g); |
1362 | XftTextExtents32 (term->dpy, f, chrs + i, 1, &g); |
1382 | |
1363 | |
1383 | int w = g.width - g.x; |
1364 | int w = g.width - g.x; |
1384 | int wcw = max (WCWIDTH (unicode), 1); |
|
|
1385 | |
1365 | |
1386 | careful = g.x > 0 || w > prop->width * wcw; |
1366 | careful = g.x > 0 || w > prop->width * wcw; |
1387 | |
1367 | |
1388 | if (careful && !OVERLAP_OK (w, wcw, prop)) |
1368 | if (careful && !OVERLAP_OK (w, wcw, prop)) |
1389 | return false; |
1369 | return false; |
1390 | |
1370 | |
1391 | // this weeds out _totally_ broken fonts, or glyphs |
1371 | // this weeds out _totally_ broken fonts, or glyphs |
1392 | if (!OVERLAP_OK (g.xOff, wcw, prop)) |
1372 | if (!OVERLAP_OK (g.xOff, wcw, prop)) |
1393 | return false; |
1373 | return false; |
|
|
1374 | } |
1394 | |
1375 | |
1395 | return true; |
1376 | return true; |
1396 | } |
1377 | } |
1397 | |
1378 | |
1398 | void |
1379 | void |
1399 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1380 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1400 | const text_t *text, int len, |
1381 | const text_t *text, int len, |
1401 | int fg, int bg) |
1382 | int fg, int bg) |
1402 | { |
1383 | { |
1403 | XGlyphInfo extents; |
|
|
1404 | XftGlyphSpec *enc = rxvt_temp_buf<XftGlyphSpec> (len); |
1384 | //XftGlyphSpec *enc = rxvt_temp_buf<XftGlyphSpec> (len);//D |
1405 | XftGlyphSpec *ep = enc; |
1385 | //XftGlyphSpec *ep = enc;//D |
|
|
1386 | static vector<XftGlyphSpec> enc; enc.resize (0); // static to avoid malloc, still slow |
1406 | |
1387 | |
1407 | dTermDisplay; |
1388 | dTermDisplay; |
1408 | dTermGC; |
1389 | dTermGC; |
1409 | |
1390 | |
1410 | int w = term->fwidth * len; |
1391 | int w = term->fwidth * len; |
… | |
… | |
1421 | int y_ = buffered ? 0 : y; |
1402 | int y_ = buffered ? 0 : y; |
1422 | |
1403 | |
1423 | while (len) |
1404 | while (len) |
1424 | { |
1405 | { |
1425 | int cwidth = term->fwidth; |
1406 | int cwidth = term->fwidth; |
|
|
1407 | |
|
|
1408 | rxvt_compose_expand_static<FcChar32> exp; |
1426 | FcChar32 fc = *text++; len--; |
1409 | FcChar32 *chrs = exp (*text++); len--; |
|
|
1410 | int nchrs = exp.length (chrs); |
1427 | |
1411 | |
1428 | while (len && *text == NOCHAR) |
1412 | while (len && *text == NOCHAR) |
1429 | text++, len--, cwidth += term->fwidth; |
1413 | text++, len--, cwidth += term->fwidth; |
1430 | |
1414 | |
1431 | if (fc != ' ') // skip spaces |
1415 | if (chrs [0] != ' ') // skip spaces |
|
|
1416 | { |
|
|
1417 | #if 0 |
|
|
1418 | FT_UInt glyphs [decltype (exp)::max_size]; |
|
|
1419 | |
|
|
1420 | for (int i = 0; i < nchrs; ++i) |
|
|
1421 | glyphs [i] = XftCharIndex (disp, f, chrs [i]); |
|
|
1422 | |
|
|
1423 | for (int i = 0; i < nchrs; ++i) |
1432 | { |
1424 | { |
|
|
1425 | XGlyphInfo ep; |
|
|
1426 | XftGlyphExtents (disp, f, glyphs+i, 1, &ep); |
|
|
1427 | printf ("gs %x g %x + %d,%d o %d,%d wh %d,%d\n", chrs[i],glyphs[i],ep.x,ep.y,ep.xOff,ep.yOff,ep.width,ep.height); |
|
|
1428 | } |
|
|
1429 | #endif |
|
|
1430 | |
|
|
1431 | for (int i = 0; i < nchrs; ++i) |
|
|
1432 | { |
1433 | FT_UInt glyph = XftCharIndex (disp, f, fc); |
1433 | FT_UInt glyph = XftCharIndex (disp, f, chrs [i]); |
|
|
1434 | XGlyphInfo extents; |
1434 | XftGlyphExtents (disp, f, &glyph, 1, &extents); |
1435 | XftGlyphExtents (disp, f, &glyph, 1, &extents); |
1435 | |
1436 | |
1436 | ep->glyph = glyph; |
1437 | XftGlyphSpec ep; |
|
|
1438 | |
1437 | ep->x = x_ + (cwidth - extents.xOff >> 1); |
1439 | int cx = x_ + (cwidth - extents.xOff >> 1); |
1438 | ep->y = y_ + ascent; |
1440 | int cy = y_ + ascent; |
1439 | |
1441 | |
|
|
1442 | // lone combining char |
1440 | if (extents.xOff == 0) |
1443 | if (extents.xOff == 0) |
1441 | ep->x = x_ + cwidth; |
1444 | cx = x_ + cwidth; |
1442 | |
1445 | |
1443 | ep++; |
1446 | ep.glyph = glyph; |
|
|
1447 | ep.x = cx + extents.x; |
|
|
1448 | ep.y = cy; |
|
|
1449 | |
|
|
1450 | enc.push_back (ep); |
|
|
1451 | } |
1444 | } |
1452 | } |
1445 | |
1453 | |
1446 | x_ += cwidth; |
1454 | x_ += cwidth; |
1447 | } |
1455 | } |
1448 | |
1456 | |
1449 | if (buffered) |
1457 | if (buffered) |
1450 | { |
1458 | { |
1451 | if (ep != enc) |
1459 | if (!enc.empty ()) |
1452 | { |
1460 | { |
1453 | rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); |
1461 | rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); |
1454 | |
1462 | |
1455 | #ifdef HAVE_IMG |
1463 | #ifdef HAVE_IMG |
1456 | Picture dst = 0; // the only assignment is done conditionally in the following if condition |
1464 | Picture dst = 0; // the only assignment is done conditionally in the following if condition |
… | |
… | |
1502 | } |
1510 | } |
1503 | else |
1511 | else |
1504 | #endif |
1512 | #endif |
1505 | XftDrawRect (d2, &term->pix_colors[bg >= 0 ? bg : Color_bg].c, 0, 0, w, h); |
1513 | XftDrawRect (d2, &term->pix_colors[bg >= 0 ? bg : Color_bg].c, 0, 0, w, h); |
1506 | |
1514 | |
1507 | XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, enc, ep - enc); |
1515 | XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, &enc[0], enc.size ()); |
1508 | XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y); |
1516 | XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y); |
1509 | } |
1517 | } |
1510 | else |
1518 | else |
1511 | clear_rect (d, x, y, w, h, bg); |
1519 | clear_rect (d, x, y, w, h, bg); |
1512 | } |
1520 | } |
1513 | else |
1521 | else |
1514 | { |
1522 | { |
1515 | clear_rect (d, x, y, w, h, bg); |
1523 | clear_rect (d, x, y, w, h, bg); |
1516 | XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc); |
1524 | XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, &enc[0], enc.size ()); |
1517 | } |
1525 | } |
1518 | } |
1526 | } |
1519 | |
1527 | |
1520 | #endif |
1528 | #endif |
1521 | |
1529 | |
… | |
… | |
1717 | } |
1725 | } |
1718 | |
1726 | |
1719 | int |
1727 | int |
1720 | rxvt_fontset::find_font_idx (unicode_t unicode) |
1728 | rxvt_fontset::find_font_idx (unicode_t unicode) |
1721 | { |
1729 | { |
1722 | if (unicode >= 1<<20) |
1730 | // this limits fmap size. it has to accomodate COMPOSE_HI when UNICODE_3 |
|
|
1731 | if (unicode > 0x1fffff) |
1723 | return 0; |
1732 | return 0; |
1724 | |
1733 | |
1725 | unicode_t hi = unicode >> 8; |
1734 | unicode_t hi = unicode >> 8; |
1726 | |
1735 | |
1727 | if (hi < fmap.size () |
1736 | if (hi < fmap.size ()) |
1728 | && fmap[hi] |
1737 | if (pagemap *pm = fmap[hi]) |
1729 | && (*fmap[hi])[unicode & 0xff] != 0xff) |
1738 | if ((*pm)[unicode & 0xff] != 0xff) |
1730 | return (*fmap[hi])[unicode & 0xff]; |
1739 | return (*pm)[unicode & 0xff]; |
1731 | |
1740 | |
1732 | unsigned int i; |
1741 | unsigned int i; |
1733 | |
1742 | |
1734 | for (i = 0; i < fonts.size (); i++) |
1743 | for (i = 0; i < fonts.size (); i++) |
1735 | { |
1744 | { |
… | |
… | |
1759 | } |
1768 | } |
1760 | |
1769 | |
1761 | next_font: |
1770 | next_font: |
1762 | if (i == fonts.size () - 1) |
1771 | if (i == fonts.size () - 1) |
1763 | { |
1772 | { |
|
|
1773 | // compose characters are handled by the default font, unless another font takes over |
|
|
1774 | // we do not go via the fallback list for speed reasons. |
|
|
1775 | if (IS_COMPOSE (unicode)) |
|
|
1776 | return 0; |
|
|
1777 | |
1764 | if (fallback->name) |
1778 | if (fallback->name) |
1765 | { |
1779 | { |
1766 | // search through the fallback list |
1780 | // search through the fallback list |
1767 | push_font (new_font (fallback->name, fallback->cs)); |
1781 | push_font (new_font (fallback->name, fallback->cs)); |
1768 | fallback++; |
1782 | fallback++; |