… | |
… | |
262 | } |
262 | } |
263 | } |
263 | } |
264 | |
264 | |
265 | ///////////////////////////////////////////////////////////////////////////// |
265 | ///////////////////////////////////////////////////////////////////////////// |
266 | |
266 | |
267 | struct rxvt_font_default : rxvt_font { |
267 | struct rxvt_font_default : rxvt_font |
|
|
268 | { |
268 | struct rxvt_fontset *fs; |
269 | struct rxvt_fontset *fs; |
269 | |
270 | |
270 | rxvt_font_default (rxvt_fontset *fs) |
271 | rxvt_font_default (rxvt_fontset *fs) |
271 | : rxvt_font () |
272 | : rxvt_font () |
272 | { |
273 | { |
… | |
… | |
312 | if (unicode >= 0x2500 && unicode <= 0x259f && |
313 | if (unicode >= 0x2500 && unicode <= 0x259f && |
313 | !term->option (Opt_skipBuiltinGlyphs)) |
314 | !term->option (Opt_skipBuiltinGlyphs)) |
314 | return true; |
315 | return true; |
315 | #endif |
316 | #endif |
316 | |
317 | |
317 | if (IS_COMPOSE (unicode)) |
318 | // we do not check for IS_COMPOSE here, as this would |
318 | return true; |
319 | // rob other fonts from taking over. |
319 | |
320 | |
320 | switch (unicode) |
321 | switch (unicode) |
321 | { |
322 | { |
322 | case ZERO_WIDTH_CHAR: |
323 | case ZERO_WIDTH_CHAR: |
323 | case NOCHAR: |
324 | case NOCHAR: |
… | |
… | |
344 | |
345 | |
345 | XSetForeground (disp, gc, term->pix_colors[fg]); |
346 | XSetForeground (disp, gc, term->pix_colors[fg]); |
346 | |
347 | |
347 | while (len) |
348 | while (len) |
348 | { |
349 | { |
|
|
350 | const text_t *tp = text; |
|
|
351 | text_t t = *tp; |
|
|
352 | |
|
|
353 | while (++text, --len && *text == NOCHAR) |
|
|
354 | ; |
|
|
355 | |
349 | #if ENABLE_COMBINING |
356 | #if ENABLE_COMBINING |
350 | compose_char *cc; |
357 | compose_char *cc; |
351 | #endif |
358 | #endif |
352 | const text_t *tp = text; |
|
|
353 | text_t t = *tp; |
|
|
354 | |
|
|
355 | while (++text, --len && *text == NOCHAR) |
|
|
356 | ; |
|
|
357 | |
|
|
358 | int width = text - tp; |
359 | int width = text - tp; |
359 | int fwidth = term->fwidth * width; |
360 | int fwidth = term->fwidth * width; |
360 | |
361 | |
361 | #ifdef BUILTIN_GLYPHS |
362 | #ifdef BUILTIN_GLYPHS |
362 | if (0x2500 <= t && t <= 0x259f) |
363 | if (0x2500 <= t && t <= 0x259f) |
… | |
… | |
444 | #endif |
445 | #endif |
445 | #if ENABLE_COMBINING |
446 | #if ENABLE_COMBINING |
446 | else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) |
447 | else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) |
447 | { |
448 | { |
448 | min_it (width, 2); // we only support wcwidth up to 2 |
449 | min_it (width, 2); // we only support wcwidth up to 2 |
449 | |
|
|
450 | text_t chrs[2]; |
450 | text_t chrs[2]; |
451 | chrs [1] = NOCHAR; |
451 | chrs [1] = NOCHAR; |
452 | |
452 | |
453 | *chrs = cc->c1; |
453 | *chrs = cc->c1; |
454 | rxvt_font *f1 = (*fs)[fs->find_font_idx (cc->c1)]; |
454 | rxvt_font *f1 = (*fs)[fs->find_font_idx (cc->c1)]; |
… | |
… | |
474 | case '\t': |
474 | case '\t': |
475 | case ZERO_WIDTH_CHAR: |
475 | case ZERO_WIDTH_CHAR: |
476 | case NOCHAR: |
476 | case NOCHAR: |
477 | break; |
477 | break; |
478 | |
478 | |
|
|
479 | /* |
|
|
480 | * If the base font does not support variation selectors, treat them as ZWC. |
|
|
481 | * a point could be made to do this for all wcwidth == 0 characters, but I |
|
|
482 | * decided against that until more data is available. |
|
|
483 | */ |
|
|
484 | case 0xfe00: case 0xfe01: case 0xfe02: case 0xfe03: case 0xfe04: case 0xfe05: case 0xfe06: case 0xfe07: |
|
|
485 | case 0xfe08: case 0xfe09: case 0xfe0a: case 0xfe0b: case 0xfe0c: case 0xfe0d: case 0xfe0e: case 0xfe0f: |
|
|
486 | break; |
|
|
487 | |
479 | default: |
488 | default: |
480 | XDrawRectangle (disp, d, gc, x + 2, y + 2, |
489 | XDrawRectangle (disp, d, gc, x + 2, y + 2, |
481 | fwidth - 4, term->fheight - 4); |
490 | fwidth - 4, term->fheight - 4); |
482 | } |
491 | } |
483 | |
492 | |
484 | x += fwidth; |
493 | x += fwidth; |
485 | } |
494 | } |
486 | } |
495 | } |
487 | |
496 | |
488 | struct rxvt_font_overflow : rxvt_font { |
497 | struct rxvt_font_overflow : rxvt_font |
|
|
498 | { |
489 | struct rxvt_fontset *fs; |
499 | struct rxvt_fontset *fs; |
490 | |
500 | |
491 | rxvt_font_overflow (rxvt_fontset *fs) |
501 | rxvt_font_overflow (rxvt_fontset *fs) |
492 | : rxvt_font () |
502 | : rxvt_font () |
493 | { |
503 | { |
… | |
… | |
539 | } |
549 | } |
540 | }; |
550 | }; |
541 | |
551 | |
542 | ///////////////////////////////////////////////////////////////////////////// |
552 | ///////////////////////////////////////////////////////////////////////////// |
543 | |
553 | |
544 | struct rxvt_font_x11 : rxvt_font { |
554 | struct rxvt_font_x11 : rxvt_font |
|
|
555 | { |
545 | rxvt_font_x11 () { f = 0; } |
556 | rxvt_font_x11 () { f = 0; } |
546 | |
557 | |
547 | void clear (); |
558 | void clear (); |
548 | |
559 | |
549 | rxvt_fontprop properties (); |
560 | rxvt_fontprop properties (); |
… | |
… | |
1124 | |
1135 | |
1125 | ///////////////////////////////////////////////////////////////////////////// |
1136 | ///////////////////////////////////////////////////////////////////////////// |
1126 | |
1137 | |
1127 | #if XFT |
1138 | #if XFT |
1128 | |
1139 | |
1129 | struct rxvt_font_xft : rxvt_font { |
1140 | struct rxvt_font_xft : rxvt_font |
|
|
1141 | { |
1130 | rxvt_font_xft () { f = 0; } |
1142 | rxvt_font_xft () |
|
|
1143 | { |
|
|
1144 | f = 0; |
|
|
1145 | } |
1131 | |
1146 | |
1132 | void clear (); |
1147 | void clear (); |
1133 | |
1148 | |
1134 | rxvt_fontprop properties (); |
1149 | rxvt_fontprop properties (); |
1135 | |
1150 | |
… | |
… | |
1277 | if (glheight < g.height - g.y) glheight = g.height - g.y; |
1292 | if (glheight < g.height - g.y) glheight = g.height - g.y; |
1278 | } |
1293 | } |
1279 | |
1294 | |
1280 | if (!width) |
1295 | if (!width) |
1281 | { |
1296 | { |
1282 | 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); |
1283 | |
1298 | width = f->max_advance_width; |
1284 | XftFontClose (disp, f); |
|
|
1285 | f = 0; |
|
|
1286 | |
|
|
1287 | success = false; |
|
|
1288 | break; |
1299 | break; |
1289 | } |
1300 | } |
1290 | |
1301 | |
1291 | if (prop.height == rxvt_fontprop::unset |
1302 | if (prop.height == rxvt_fontprop::unset |
1292 | || (height <= prop.height && glheight <= prop.height) |
1303 | || (height <= prop.height && glheight <= prop.height) |
… | |
… | |
1327 | bool |
1338 | bool |
1328 | 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 |
1329 | { |
1340 | { |
1330 | careful = false; |
1341 | careful = false; |
1331 | |
1342 | |
|
|
1343 | rxvt_compose_expand_static<FcChar32> exp; |
|
|
1344 | FcChar32 *chrs = exp (unicode); |
|
|
1345 | int nchrs = exp.length (chrs); |
|
|
1346 | |
|
|
1347 | // we handle the sequence if the first char is available |
1332 | if (!XftCharExists (term->dpy, f, unicode)) |
1348 | if (!XftCharExists (term->dpy, f, chrs [0])) |
1333 | return false; |
1349 | return false; |
1334 | |
1350 | |
1335 | if (!prop || prop->width == rxvt_fontprop::unset) |
1351 | if (!prop || prop->width == rxvt_fontprop::unset) |
1336 | return true; |
1352 | return true; |
|
|
1353 | |
|
|
1354 | // but we check against the whole sequence bounding box |
1337 | |
1355 | |
1338 | // check character against base font bounding box |
1356 | // check character against base font bounding box |
1339 | FcChar32 ch = unicode; |
1357 | FcChar32 ch = unicode; |
1340 | XGlyphInfo g; |
1358 | XGlyphInfo g; |
1341 | XftTextExtents32 (term->dpy, f, &ch, 1, &g); |
1359 | XftTextExtents32 (term->dpy, f, chrs, nchrs, &g); |
1342 | |
1360 | |
1343 | int w = g.width - g.x; |
1361 | int w = g.width - g.x; |
1344 | int wcw = max (WCWIDTH (unicode), 1); |
1362 | int wcw = max (WCWIDTH (chrs [0]), 1); |
1345 | |
1363 | |
1346 | careful = g.x > 0 || w > prop->width * wcw; |
1364 | careful = g.x > 0 || w > prop->width * wcw; |
1347 | |
1365 | |
1348 | if (careful && !OVERLAP_OK (w, wcw, prop)) |
1366 | if (careful && !OVERLAP_OK (w, wcw, prop)) |
1349 | return false; |
1367 | return false; |
… | |
… | |
1359 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1377 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1360 | const text_t *text, int len, |
1378 | const text_t *text, int len, |
1361 | int fg, int bg) |
1379 | int fg, int bg) |
1362 | { |
1380 | { |
1363 | XGlyphInfo extents; |
1381 | XGlyphInfo extents; |
1364 | XftGlyphSpec *enc = rxvt_temp_buf<XftGlyphSpec> (len); |
1382 | //XftGlyphSpec *enc = rxvt_temp_buf<XftGlyphSpec> (len);//D |
1365 | XftGlyphSpec *ep = enc; |
1383 | //XftGlyphSpec *ep = enc;//D |
|
|
1384 | static vector<XftGlyphSpec> enc; enc.resize (0); // static to avoid malloc, still slow |
1366 | |
1385 | |
1367 | dTermDisplay; |
1386 | dTermDisplay; |
1368 | dTermGC; |
1387 | dTermGC; |
1369 | |
1388 | |
1370 | int w = term->fwidth * len; |
1389 | int w = term->fwidth * len; |
… | |
… | |
1381 | int y_ = buffered ? 0 : y; |
1400 | int y_ = buffered ? 0 : y; |
1382 | |
1401 | |
1383 | while (len) |
1402 | while (len) |
1384 | { |
1403 | { |
1385 | int cwidth = term->fwidth; |
1404 | int cwidth = term->fwidth; |
|
|
1405 | |
|
|
1406 | rxvt_compose_expand_static<FcChar32> exp; |
1386 | FcChar32 fc = *text++; len--; |
1407 | FcChar32 *chrs = exp (*text++); len--; |
|
|
1408 | int nchrs = exp.length (chrs); |
1387 | |
1409 | |
1388 | while (len && *text == NOCHAR) |
1410 | while (len && *text == NOCHAR) |
1389 | text++, len--, cwidth += term->fwidth; |
1411 | text++, len--, cwidth += term->fwidth; |
1390 | |
1412 | |
1391 | if (fc != ' ') // skip spaces |
1413 | if (chrs [0] != ' ') // skip spaces |
1392 | { |
1414 | { |
|
|
1415 | FT_UInt glyphs [rxvt_compose_expand_static<FcChar32>::max_size]; |
|
|
1416 | |
|
|
1417 | for (int i = 0; i < nchrs; ++i) |
1393 | FT_UInt glyph = XftCharIndex (disp, f, fc); |
1418 | glyphs [i] = XftCharIndex (disp, f, chrs [i]); |
|
|
1419 | |
1394 | XftGlyphExtents (disp, f, &glyph, 1, &extents); |
1420 | XftGlyphExtents (disp, f, glyphs, nchrs, &extents); |
1395 | |
1421 | |
1396 | ep->glyph = glyph; |
1422 | XftGlyphSpec ep; |
|
|
1423 | |
1397 | ep->x = x_ + (cwidth - extents.xOff >> 1); |
1424 | ep.x = x_ + (cwidth - extents.xOff >> 1); |
1398 | ep->y = y_ + ascent; |
1425 | ep.y = y_ + ascent; |
1399 | |
1426 | |
1400 | if (extents.xOff == 0) |
1427 | if (extents.xOff == 0) |
1401 | ep->x = x_ + cwidth; |
1428 | ep.x = x_ + cwidth; |
1402 | |
1429 | |
1403 | ep++; |
1430 | for (int i = 0; i < nchrs; ++i) |
|
|
1431 | { |
|
|
1432 | ep.glyph = glyphs [i]; |
|
|
1433 | enc.push_back (ep); |
|
|
1434 | } |
1404 | } |
1435 | } |
1405 | |
1436 | |
1406 | x_ += cwidth; |
1437 | x_ += cwidth; |
1407 | } |
1438 | } |
1408 | |
1439 | |
1409 | if (buffered) |
1440 | if (buffered) |
1410 | { |
1441 | { |
1411 | if (ep != enc) |
1442 | if (!enc.empty ()) |
1412 | { |
1443 | { |
1413 | rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); |
1444 | rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); |
1414 | |
1445 | |
1415 | #ifdef HAVE_IMG |
1446 | #ifdef HAVE_IMG |
1416 | Picture dst = 0; // the only assignment is done conditionally in the following if condition |
1447 | Picture dst = 0; // the only assignment is done conditionally in the following if condition |
… | |
… | |
1462 | } |
1493 | } |
1463 | else |
1494 | else |
1464 | #endif |
1495 | #endif |
1465 | XftDrawRect (d2, &term->pix_colors[bg >= 0 ? bg : Color_bg].c, 0, 0, w, h); |
1496 | XftDrawRect (d2, &term->pix_colors[bg >= 0 ? bg : Color_bg].c, 0, 0, w, h); |
1466 | |
1497 | |
1467 | XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, enc, ep - enc); |
1498 | XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, &enc[0], enc.size ()); |
1468 | XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y); |
1499 | XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y); |
1469 | } |
1500 | } |
1470 | else |
1501 | else |
1471 | clear_rect (d, x, y, w, h, bg); |
1502 | clear_rect (d, x, y, w, h, bg); |
1472 | } |
1503 | } |
1473 | else |
1504 | else |
1474 | { |
1505 | { |
1475 | clear_rect (d, x, y, w, h, bg); |
1506 | clear_rect (d, x, y, w, h, bg); |
1476 | XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc); |
1507 | XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, &enc[0], enc.size ()); |
1477 | } |
1508 | } |
1478 | } |
1509 | } |
1479 | |
1510 | |
1480 | #endif |
1511 | #endif |
1481 | |
1512 | |
… | |
… | |
1677 | } |
1708 | } |
1678 | |
1709 | |
1679 | int |
1710 | int |
1680 | rxvt_fontset::find_font_idx (unicode_t unicode) |
1711 | rxvt_fontset::find_font_idx (unicode_t unicode) |
1681 | { |
1712 | { |
1682 | if (unicode >= 1<<20) |
1713 | // this limits fmap size. it has to accomodate COMPOSE_HI when UNICODE_3 |
|
|
1714 | if (unicode > 0x1fffff) |
1683 | return 0; |
1715 | return 0; |
1684 | |
1716 | |
1685 | unicode_t hi = unicode >> 8; |
1717 | unicode_t hi = unicode >> 8; |
1686 | |
1718 | |
1687 | if (hi < fmap.size () |
1719 | if (hi < fmap.size ()) |
1688 | && fmap[hi] |
1720 | if (pagemap *pm = fmap[hi]) |
1689 | && (*fmap[hi])[unicode & 0xff] != 0xff) |
1721 | if ((*pm)[unicode & 0xff] != 0xff) |
1690 | return (*fmap[hi])[unicode & 0xff]; |
1722 | return (*pm)[unicode & 0xff]; |
1691 | |
1723 | |
1692 | unsigned int i; |
1724 | unsigned int i; |
1693 | |
1725 | |
1694 | for (i = 0; i < fonts.size (); i++) |
1726 | for (i = 0; i < fonts.size (); i++) |
1695 | { |
1727 | { |
… | |
… | |
1719 | } |
1751 | } |
1720 | |
1752 | |
1721 | next_font: |
1753 | next_font: |
1722 | if (i == fonts.size () - 1) |
1754 | if (i == fonts.size () - 1) |
1723 | { |
1755 | { |
|
|
1756 | // compose characters are handled by the default font, unless another font takes over |
|
|
1757 | // we do not go via the fallback list for speed reasons. |
|
|
1758 | if (IS_COMPOSE (unicode)) |
|
|
1759 | return 0; |
|
|
1760 | |
1724 | if (fallback->name) |
1761 | if (fallback->name) |
1725 | { |
1762 | { |
1726 | // search through the fallback list |
1763 | // search through the fallback list |
1727 | push_font (new_font (fallback->name, fallback->cs)); |
1764 | push_font (new_font (fallback->name, fallback->cs)); |
1728 | fallback++; |
1765 | fallback++; |
… | |
… | |
1734 | // way to configure this and xft is easier to hack in, |
1771 | // way to configure this and xft is easier to hack in, |
1735 | // while x11 has more framework in place already. |
1772 | // while x11 has more framework in place already. |
1736 | // TODO: this is a real resource hog, xft takes ages(?) |
1773 | // TODO: this is a real resource hog, xft takes ages(?) |
1737 | #if XFT && USE_SLOW_LOOKUP |
1774 | #if XFT && USE_SLOW_LOOKUP |
1738 | // grab the first xft font that seems suitable |
1775 | // grab the first xft font that seems suitable |
|
|
1776 | // TOOD: should go first for cellchar (spacing 110) then mono, then else |
1739 | FcPattern *p = FcPatternCreate (); |
1777 | FcPattern *p = FcPatternCreate (); |
1740 | |
1778 | |
1741 | FcCharSet *s = FcCharSetCreate (); |
1779 | FcCharSet *s = FcCharSetCreate (); |
1742 | FcCharSetAddChar (s, unicode); |
1780 | FcCharSetAddChar (s, unicode); |
1743 | FcPatternAddCharSet (p, FC_CHARSET, s); |
1781 | FcPatternAddCharSet (p, FC_CHARSET, s); |