… | |
… | |
448 | |
448 | |
449 | text_t chrs[2]; |
449 | text_t chrs[2]; |
450 | chrs [1] = NOCHAR; |
450 | chrs [1] = NOCHAR; |
451 | |
451 | |
452 | *chrs = cc->c1; |
452 | *chrs = cc->c1; |
453 | rxvt_font *f1 = fs->get (cc->c1); |
453 | rxvt_font *f1 = (*fs)[fs->find_font_idx (cc->c1)]; |
454 | f1->draw (d, x, y, chrs, width, fg, bg); |
454 | f1->draw (d, x, y, chrs, width, fg, bg); |
455 | |
455 | |
456 | if (cc->c2 != NOCHAR) |
456 | if (cc->c2 != NOCHAR) |
457 | { |
457 | { |
458 | bool careful; |
458 | bool careful; |
459 | |
459 | |
460 | // prefer font of first character, for no good reasons |
460 | // prefer font of first character, for no good reasons |
461 | *chrs = cc->c2; |
461 | *chrs = cc->c2; |
462 | rxvt_font *f2 = (f1->has_char (cc->c2, 0, careful) && !careful) |
462 | rxvt_font *f2 = (f1->has_char (cc->c2, 0, careful) && !careful) |
463 | ? f1 |
463 | ? f1 |
464 | : fs->get (cc->c2); |
464 | : (*fs)[fs->find_font_idx (cc->c2)]; |
465 | |
465 | |
466 | f2->draw (d, x, y, chrs, width, fg, Color_none); |
466 | f2->draw (d, x, y, chrs, width, fg, Color_none); |
467 | } |
467 | } |
468 | } |
468 | } |
469 | #endif |
469 | #endif |
… | |
… | |
482 | |
482 | |
483 | x += fwidth; |
483 | x += fwidth; |
484 | } |
484 | } |
485 | } |
485 | } |
486 | |
486 | |
|
|
487 | struct rxvt_font_overflow : rxvt_font { |
|
|
488 | struct rxvt_fontset *fs; |
|
|
489 | |
|
|
490 | rxvt_font_overflow (rxvt_fontset *fs) |
|
|
491 | : rxvt_font () |
|
|
492 | { |
|
|
493 | this->fs = fs; |
|
|
494 | } |
|
|
495 | |
|
|
496 | rxvt_fontprop properties () |
|
|
497 | { |
|
|
498 | rxvt_fontprop p; |
|
|
499 | |
|
|
500 | p.width = p.height = 1; |
|
|
501 | p.ascent = rxvt_fontprop::unset; |
|
|
502 | p.weight = rxvt_fontprop::medium; |
|
|
503 | p.slant = rxvt_fontprop::roman; |
|
|
504 | |
|
|
505 | return p; |
|
|
506 | } |
|
|
507 | |
|
|
508 | bool load (const rxvt_fontprop &prop, bool force_prop) |
|
|
509 | { |
|
|
510 | width = 1; height = 1; |
|
|
511 | ascent = 1; descent = 0; |
|
|
512 | |
|
|
513 | set_name (strdup ("built-in rendition overflow font")); |
|
|
514 | |
|
|
515 | return true; |
|
|
516 | } |
|
|
517 | |
|
|
518 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
|
|
519 | { |
|
|
520 | return false; |
|
|
521 | } |
|
|
522 | |
|
|
523 | void draw (rxvt_drawable &d, int x, int y, |
|
|
524 | const text_t *text, int len, |
|
|
525 | int fg, int bg) |
|
|
526 | { |
|
|
527 | while (len--) |
|
|
528 | { |
|
|
529 | int fid = fs->find_font_idx (*text); |
|
|
530 | (*fs)[fid]->draw (d, x, y, text, 1, fg, bg); |
|
|
531 | ++text; |
|
|
532 | x += term->fwidth; |
|
|
533 | } |
|
|
534 | } |
|
|
535 | }; |
|
|
536 | |
487 | ///////////////////////////////////////////////////////////////////////////// |
537 | ///////////////////////////////////////////////////////////////////////////// |
488 | |
538 | |
489 | struct rxvt_font_x11 : rxvt_font { |
539 | struct rxvt_font_x11 : rxvt_font { |
490 | rxvt_font_x11 () { f = 0; } |
540 | rxvt_font_x11 () { f = 0; } |
491 | |
541 | |
… | |
… | |
499 | |
549 | |
500 | void draw (rxvt_drawable &d, int x, int y, |
550 | void draw (rxvt_drawable &d, int x, int y, |
501 | const text_t *text, int len, |
551 | const text_t *text, int len, |
502 | int fg, int bg); |
552 | int fg, int bg); |
503 | |
553 | |
504 | bool slow; // wether this is a proportional font or has other funny characteristics |
554 | bool slow; // whether this is a proportional font or has other funny characteristics |
505 | XFontStruct *f; |
555 | XFontStruct *f; |
506 | bool enc2b, encm; |
556 | bool enc2b, encm; |
507 | |
557 | |
508 | char *get_property (XFontStruct *f, Atom property, const char *repl) const; |
558 | char *get_property (XFontStruct *f, Atom property, const char *repl) const; |
509 | bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth); |
559 | bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth); |
… | |
… | |
915 | uint32_t ch = FROM_UNICODE (cs, unicode); |
965 | uint32_t ch = FROM_UNICODE (cs, unicode); |
916 | |
966 | |
917 | if (ch == NOCHAR) |
967 | if (ch == NOCHAR) |
918 | return false; |
968 | return false; |
919 | |
969 | |
920 | /* check wether the character exists in _this_ font. horrible. */ |
970 | /* check whether the character exists in _this_ font. horrible. */ |
921 | XCharStruct *xcs; |
971 | XCharStruct *xcs; |
922 | |
972 | |
923 | if (encm) |
973 | if (encm) |
924 | { |
974 | { |
925 | unsigned char byte1 = ch >> 8; |
975 | unsigned char byte1 = ch >> 8; |
… | |
… | |
955 | return false; |
1005 | return false; |
956 | |
1006 | |
957 | if (!prop || prop->width == rxvt_fontprop::unset) |
1007 | if (!prop || prop->width == rxvt_fontprop::unset) |
958 | return true; |
1008 | return true; |
959 | |
1009 | |
960 | // check wether character overlaps previous/next character |
1010 | // check whether character overlaps previous/next character |
961 | int w = xcs->rbearing - xcs->lbearing; |
1011 | int w = xcs->rbearing - xcs->lbearing; |
962 | int wcw = max (WCWIDTH (unicode), 1); |
1012 | int wcw = max (WCWIDTH (unicode), 1); |
963 | |
1013 | |
964 | careful = xcs->lbearing < 0 || xcs->rbearing > prop->width * wcw; |
1014 | careful = xcs->lbearing < 0 || xcs->rbearing > prop->width * wcw; |
965 | |
1015 | |
… | |
… | |
1353 | && (bg == Color_transparent || bg == Color_bg |
1403 | && (bg == Color_transparent || bg == Color_bg |
1354 | || (bg >= 0 && !term->pix_colors[bg].is_opaque () && ((dst = XftDrawPicture (d2)))))) |
1404 | || (bg >= 0 && !term->pix_colors[bg].is_opaque () && ((dst = XftDrawPicture (d2)))))) |
1355 | { |
1405 | { |
1356 | int src_x = x, src_y = y; |
1406 | int src_x = x, src_y = y; |
1357 | |
1407 | |
1358 | if (term->bgPixmap.is_parentOrigin ()) |
1408 | if (term->bgPixmap.flags & bgPixmap_t::isTransparent) |
1359 | { |
1409 | { |
1360 | src_x += term->window_vt_x; |
1410 | src_x += term->window_vt_x; |
1361 | src_y += term->window_vt_y; |
1411 | src_y += term->window_vt_y; |
1362 | } |
1412 | } |
1363 | |
1413 | |
… | |
… | |
1432 | prop.width = prop.height = prop.ascent = prop.weight = prop.slant |
1482 | prop.width = prop.height = prop.ascent = prop.weight = prop.slant |
1433 | = rxvt_fontprop::unset; |
1483 | = rxvt_fontprop::unset; |
1434 | force_prop = false; |
1484 | force_prop = false; |
1435 | |
1485 | |
1436 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1486 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1437 | FONT_UNREF (*i); |
1487 | (*i)->unref (); |
1438 | |
1488 | |
1439 | for (pagemap **p = fmap.begin (); p != fmap.end (); p++) |
1489 | for (pagemap **p = fmap.begin (); p != fmap.end (); p++) |
1440 | delete *p; |
1490 | delete *p; |
1441 | |
1491 | |
1442 | free (fontdesc); fontdesc = 0; |
1492 | free (fontdesc); fontdesc = 0; |
… | |
… | |
1444 | fonts.clear (); |
1494 | fonts.clear (); |
1445 | |
1495 | |
1446 | fallback = fallback_fonts; |
1496 | fallback = fallback_fonts; |
1447 | } |
1497 | } |
1448 | |
1498 | |
|
|
1499 | void |
|
|
1500 | rxvt_fontset::prepare_font (rxvt_font *font, codeset cs) |
|
|
1501 | { |
|
|
1502 | font->set_term (term); |
|
|
1503 | |
|
|
1504 | font->cs = cs; |
|
|
1505 | font->loaded = false; |
|
|
1506 | } |
|
|
1507 | |
1449 | rxvt_font * |
1508 | rxvt_font * |
1450 | rxvt_fontset::new_font (const char *name, codeset cs) |
1509 | rxvt_fontset::new_font (const char *name, codeset cs) |
1451 | { |
1510 | { |
1452 | rxvt_font *f; |
1511 | rxvt_font *f; |
1453 | |
1512 | |
… | |
… | |
1469 | f = new rxvt_font_x11; |
1528 | f = new rxvt_font_x11; |
1470 | } |
1529 | } |
1471 | else |
1530 | else |
1472 | f = new rxvt_font_x11; |
1531 | f = new rxvt_font_x11; |
1473 | |
1532 | |
1474 | f->set_term (term); |
|
|
1475 | f->set_name (strdup (name)); |
1533 | f->set_name (strdup (name)); |
1476 | |
1534 | prepare_font (f, cs); |
1477 | f->cs = cs; |
|
|
1478 | f->loaded = false; |
|
|
1479 | |
1535 | |
1480 | return f; |
1536 | return f; |
1481 | } |
1537 | } |
1482 | |
1538 | |
1483 | ///////////////////////////////////////////////////////////////////////////// |
1539 | ///////////////////////////////////////////////////////////////////////////// |
|
|
1540 | |
|
|
1541 | void |
|
|
1542 | rxvt_fontset::push_font (rxvt_font *font) |
|
|
1543 | { |
|
|
1544 | // the fontCount index is reserved for the overflow font, it is only |
|
|
1545 | // necessary when we get fontCount or more fonts, as they cannot be |
|
|
1546 | // represented in the rendition. |
|
|
1547 | if (fonts.size () == fontCount) |
|
|
1548 | { |
|
|
1549 | rxvt_font *f = new rxvt_font_overflow (this); |
|
|
1550 | |
|
|
1551 | prepare_font (f, CS_UNICODE); |
|
|
1552 | fonts.push_back (f); |
|
|
1553 | } |
|
|
1554 | |
|
|
1555 | fonts.push_back (font); |
|
|
1556 | } |
1484 | |
1557 | |
1485 | void |
1558 | void |
1486 | rxvt_fontset::add_fonts (const char *desc) |
1559 | rxvt_fontset::add_fonts (const char *desc) |
1487 | { |
1560 | { |
1488 | if (desc) |
1561 | if (desc) |
… | |
… | |
1529 | if (end - desc < 511) |
1602 | if (end - desc < 511) |
1530 | { |
1603 | { |
1531 | memcpy (buf, desc, end - desc); |
1604 | memcpy (buf, desc, end - desc); |
1532 | buf[end - desc] = 0; |
1605 | buf[end - desc] = 0; |
1533 | |
1606 | |
1534 | fonts.push_back (new_font (buf, cs)); |
1607 | push_font (new_font (buf, cs)); |
1535 | } |
1608 | } |
1536 | else |
1609 | else |
1537 | rxvt_warn ("fontset element too long (>511 bytes), ignored."); |
1610 | rxvt_warn ("fontset element too long (>511 bytes), ignored."); |
1538 | |
1611 | |
1539 | desc = end + 1; |
1612 | desc = end + 1; |
… | |
… | |
1567 | { |
1640 | { |
1568 | clear (); |
1641 | clear (); |
1569 | |
1642 | |
1570 | fontdesc = strdup (desc); |
1643 | fontdesc = strdup (desc); |
1571 | |
1644 | |
1572 | fonts.push_back (new_font (0, CS_UNICODE)); |
1645 | push_font (new_font (0, CS_UNICODE)); |
1573 | realize_font (0); |
1646 | realize_font (0); |
1574 | |
1647 | |
1575 | add_fonts (desc); |
1648 | add_fonts (desc); |
1576 | |
1649 | |
1577 | return true; |
1650 | return true; |
… | |
… | |
1586 | |
1659 | |
1587 | return -1; |
1660 | return -1; |
1588 | } |
1661 | } |
1589 | |
1662 | |
1590 | int |
1663 | int |
1591 | rxvt_fontset::find_font_ (unicode_t unicode) |
1664 | rxvt_fontset::find_font_idx (unicode_t unicode) |
1592 | { |
1665 | { |
1593 | if (unicode >= 1<<20) |
1666 | if (unicode >= 1<<20) |
1594 | return 0; |
1667 | return 0; |
1595 | |
1668 | |
1596 | unicode_t hi = unicode >> 8; |
1669 | unicode_t hi = unicode >> 8; |
… | |
… | |
1622 | goto next_font; |
1695 | goto next_font; |
1623 | |
1696 | |
1624 | bool careful; |
1697 | bool careful; |
1625 | if (f->has_char (unicode, &prop, careful)) |
1698 | if (f->has_char (unicode, &prop, careful)) |
1626 | { |
1699 | { |
1627 | if (careful) |
1700 | i = (i << 1) | careful; |
1628 | i |= 128; |
|
|
1629 | |
1701 | |
1630 | goto found; |
1702 | goto found; |
1631 | } |
1703 | } |
1632 | |
1704 | |
1633 | next_font: |
1705 | next_font: |
1634 | if (i == fonts.size () - 1) |
1706 | if (i == fonts.size () - 1) |
1635 | { |
1707 | { |
1636 | if (fallback->name) |
1708 | if (fallback->name) |
1637 | { |
1709 | { |
1638 | // search through the fallback list |
1710 | // search through the fallback list |
1639 | fonts.push_back (new_font (fallback->name, fallback->cs)); |
1711 | push_font (new_font (fallback->name, fallback->cs)); |
1640 | fallback++; |
1712 | fallback++; |
1641 | } |
1713 | } |
1642 | else |
1714 | else |
1643 | { |
1715 | { |
1644 | // try to find a new font. |
1716 | // try to find a new font. |
… | |
… | |
1677 | if (find_font (font) < 0) |
1749 | if (find_font (font) < 0) |
1678 | { |
1750 | { |
1679 | char fontname[4096]; |
1751 | char fontname[4096]; |
1680 | snprintf (fontname, sizeof (fontname), "xft:%s", font); |
1752 | snprintf (fontname, sizeof (fontname), "xft:%s", font); |
1681 | |
1753 | |
1682 | fonts.push_back (new_font (fontname, CS_UNICODE)); |
1754 | push_font (new_font (fontname, CS_UNICODE)); |
1683 | } |
1755 | } |
1684 | |
1756 | |
1685 | free (font); |
1757 | free (font); |
1686 | } |
1758 | } |
1687 | #endif |
1759 | #endif |
… | |
… | |
1709 | } |
1781 | } |
1710 | |
1782 | |
1711 | return i; |
1783 | return i; |
1712 | } |
1784 | } |
1713 | |
1785 | |
1714 | int |
|
|
1715 | rxvt_fontset::find_font (unicode_t unicode) |
|
|
1716 | { |
|
|
1717 | return min<int> (fontCount, find_font_ (unicode)); |
|
|
1718 | } |
|
|
1719 | |
|
|
1720 | |
|
|
1721 | |
|
|