… | |
… | |
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 (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 (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_meta : rxvt_font { |
|
|
488 | struct rxvt_fontset *fs; |
|
|
489 | |
|
|
490 | rxvt_font_meta (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 meta 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 | |
… | |
… | |
1586 | |
1636 | |
1587 | return -1; |
1637 | return -1; |
1588 | } |
1638 | } |
1589 | |
1639 | |
1590 | int |
1640 | int |
1591 | rxvt_fontset::find_font_idx (unicode_t unicode, bool &careful) |
1641 | rxvt_fontset::find_font_idx (unicode_t unicode) |
1592 | { |
1642 | { |
1593 | if (unicode >= 1<<20) |
1643 | if (unicode >= 1<<20) |
1594 | return 0; |
1644 | return 0; |
1595 | |
1645 | |
1596 | unicode_t hi = unicode >> 8; |
1646 | unicode_t hi = unicode >> 8; |
1597 | |
1647 | |
1598 | if (hi < fmap.size () && fmap[hi]) |
1648 | if (hi < fmap.size () |
1599 | { |
1649 | && fmap[hi] |
|
|
1650 | && (*fmap[hi])[unicode & 0xff] != 0xff) |
1600 | unsigned char m = (*fmap[hi])[unicode & 0xff]; |
1651 | return (*fmap[hi])[unicode & 0xff]; |
1601 | |
|
|
1602 | if (m != 0xff) |
|
|
1603 | { |
|
|
1604 | careful = m & 128; |
|
|
1605 | return m & 127; |
|
|
1606 | } |
|
|
1607 | } |
|
|
1608 | |
1652 | |
1609 | unsigned int i; |
1653 | unsigned int i; |
1610 | |
1654 | |
1611 | for (i = 0; i < fonts.size (); i++) |
1655 | for (i = 0; i < fonts.size (); i++) |
1612 | { |
1656 | { |
… | |
… | |
1625 | } |
1669 | } |
1626 | |
1670 | |
1627 | if (f->cs == CS_UNKNOWN) |
1671 | if (f->cs == CS_UNKNOWN) |
1628 | goto next_font; |
1672 | goto next_font; |
1629 | |
1673 | |
|
|
1674 | bool careful; |
1630 | if (f->has_char (unicode, &prop, careful)) |
1675 | if (f->has_char (unicode, &prop, careful)) |
|
|
1676 | { |
|
|
1677 | i = (i << 1) | careful; |
|
|
1678 | |
1631 | goto found; |
1679 | goto found; |
|
|
1680 | } |
1632 | |
1681 | |
1633 | next_font: |
1682 | next_font: |
1634 | if (i == fonts.size () - 1) |
1683 | if (i == fonts.size () - 1) |
1635 | { |
1684 | { |
1636 | if (fallback->name) |
1685 | if (fallback->name) |
… | |
… | |
1689 | } |
1738 | } |
1690 | } |
1739 | } |
1691 | |
1740 | |
1692 | /* we must return SOME font */ |
1741 | /* we must return SOME font */ |
1693 | i = 0; |
1742 | i = 0; |
1694 | careful = false; |
|
|
1695 | |
1743 | |
1696 | found: |
1744 | found: |
1697 | // found a font, cache it |
1745 | // found a font, cache it |
1698 | if (i < 127) |
1746 | if (i < 255) |
1699 | { |
1747 | { |
1700 | while (hi >= fmap.size ()) |
1748 | while (hi >= fmap.size ()) |
1701 | fmap.push_back (0); |
1749 | fmap.push_back (0); |
1702 | |
1750 | |
1703 | if (!fmap[hi]) |
1751 | if (!fmap[hi]) |
1704 | { |
1752 | { |
1705 | fmap[hi] = (pagemap *)new pagemap; |
1753 | fmap[hi] = (pagemap *)new pagemap; |
1706 | memset (fmap[hi], 0xff, sizeof (pagemap)); |
1754 | memset (fmap[hi], 0xff, sizeof (pagemap)); |
1707 | } |
1755 | } |
1708 | |
1756 | |
1709 | (*fmap[hi])[unicode & 0xff] = i | (careful ? 128 : 0); |
1757 | (*fmap[hi])[unicode & 0xff] = i; |
1710 | } |
1758 | } |
1711 | |
1759 | |
1712 | return i; |
1760 | return i; |
1713 | } |
1761 | } |
1714 | |
1762 | |
1715 | int |
1763 | int |
1716 | rxvt_fontset::find_font (unicode_t unicode) |
1764 | rxvt_fontset::find_font (unicode_t unicode) |
1717 | { |
1765 | { |
1718 | bool careful; |
1766 | return min<int> ((fontCount << 1) | 1, find_font_idx (unicode)); |
1719 | int id = find_font_idx (unicode, careful); |
|
|
1720 | |
|
|
1721 | return min<int> (fontCount, id) | (careful ? Careful : 0); |
|
|
1722 | } |
1767 | } |
1723 | |
1768 | |