… | |
… | |
769 | /****************************************************************************/ |
769 | /****************************************************************************/ |
770 | |
770 | |
771 | #define UNICODE_MASK 0x1fffffUL |
771 | #define UNICODE_MASK 0x1fffffUL |
772 | |
772 | |
773 | #if UNICODE_3 |
773 | #if UNICODE_3 |
774 | # define COMPOSE_LO 0x40000000UL |
774 | # define COMPOSE_LO 0x110000UL |
775 | # define COMPOSE_HI 0x400fffffUL |
775 | # define COMPOSE_HI 0x1fffffUL |
776 | # define IS_COMPOSE(n) ((int32_t)(n) >= COMPOSE_LO) |
776 | # define IS_COMPOSE(n) ((int32_t)(n) >= COMPOSE_LO) |
777 | #else |
777 | #else |
778 | # if ENABLE_PERL |
778 | # if ENABLE_PERL |
779 | # define COMPOSE_LO 0xe000UL // our _own_ functions don't like (illegal) surrogates |
779 | # define COMPOSE_LO 0xe000UL // our _own_ functions don't like (illegal) surrogates |
780 | # define COMPOSE_HI 0xf8ffUL // in utf-8, so use private use area only |
780 | # define COMPOSE_HI 0xf8ffUL // in utf-8, so use private use area only |
… | |
… | |
789 | // compose chars are used to represent composite characters |
789 | // compose chars are used to represent composite characters |
790 | // that are not representable in unicode, as well as characters |
790 | // that are not representable in unicode, as well as characters |
791 | // not fitting in the BMP. |
791 | // not fitting in the BMP. |
792 | struct compose_char |
792 | struct compose_char |
793 | { |
793 | { |
794 | // c1 can be any chaarcter != NOCHAR, including another compose character |
794 | // c1 can be any character != NOCHAR, including another compose character |
795 | // c2 must always be a zero-width character or NOCHAR, in case |
795 | // c2 must always be a zero-width character or NOCHAR, in case |
796 | // this just extends beyondthe BMP. |
796 | // this just extends beyond the BMP. |
797 | unicode_t c1, c2; |
797 | unicode_t c1, c2; |
798 | |
798 | |
799 | compose_char (unicode_t c1, unicode_t c2) |
799 | compose_char (unicode_t c1, unicode_t c2) |
800 | : c1(c1), c2(c2) |
800 | : c1(c1), c2(c2) |
801 | { } |
801 | { } |
802 | }; |
802 | }; |
803 | |
803 | |
804 | class rxvt_composite_vec |
804 | struct rxvt_composite_vec |
805 | { |
805 | { |
806 | vector<compose_char> v; |
806 | vector<compose_char> v; |
807 | public: |
807 | |
808 | text_t compose (unicode_t c1, unicode_t c2 = NOCHAR); |
808 | text_t compose (unicode_t c1, unicode_t c2 = NOCHAR); |
809 | template<typename T> int expand (unicode_t c, T *r); |
809 | template<typename T> int expand (unicode_t c, T *r); |
810 | int expand (unicode_t c) { return expand (c, (text_t *)0); } |
810 | int expand (unicode_t c) { return expand (c, (text_t *)0); } |
811 | compose_char *operator [](text_t c) |
811 | compose_char *operator [](text_t c) |
812 | { |
812 | { |
… | |
… | |
815 | : 0; |
815 | : 0; |
816 | } |
816 | } |
817 | }; |
817 | }; |
818 | |
818 | |
819 | extern class rxvt_composite_vec rxvt_composite; |
819 | extern class rxvt_composite_vec rxvt_composite; |
|
|
820 | #endif |
|
|
821 | |
|
|
822 | #if 0 |
|
|
823 | // expand the sequence into a static array |
|
|
824 | // works even without ENABLE_COMBINING |
|
|
825 | template<typename T, int max_size_ = 48> |
|
|
826 | struct rxvt_compose_expand_static |
|
|
827 | { |
|
|
828 | #if ENABLE_COMBINING |
|
|
829 | enum { max_size = max_size_ }; |
|
|
830 | |
|
|
831 | T chrs[max_size]; |
|
|
832 | |
|
|
833 | // expand sequence and return start ptr |
|
|
834 | // guarantees at least one output |
|
|
835 | // get the length with length () on that ptr |
|
|
836 | T *operator ()(unicode_t c) |
|
|
837 | { |
|
|
838 | T *cur = chrs + max_size; |
|
|
839 | |
|
|
840 | while (ecb_expect_false (IS_COMPOSE (c))) |
|
|
841 | if (ecb_expect_true (c - COMPOSE_LO < rxvt_composite.v.size ())) |
|
|
842 | { |
|
|
843 | compose_char *cc = &rxvt_composite.v [c - COMPOSE_LO]; |
|
|
844 | |
|
|
845 | if (cc->c2 != NOCHAR) |
|
|
846 | { |
|
|
847 | cur -= cur > chrs; *cur = cc->c2; |
|
|
848 | } |
|
|
849 | |
|
|
850 | c = cc->c1; |
|
|
851 | } |
|
|
852 | else |
|
|
853 | c = NOCHAR; |
|
|
854 | |
|
|
855 | cur -= cur > chrs; *cur = c; |
|
|
856 | |
|
|
857 | return cur; |
|
|
858 | } |
|
|
859 | |
|
|
860 | int length (T *first) |
|
|
861 | { |
|
|
862 | return chrs + max_size - first; |
|
|
863 | } |
|
|
864 | #else |
|
|
865 | T chr; |
|
|
866 | |
|
|
867 | T *operator ()(text_t c); |
|
|
868 | { |
|
|
869 | chr = c; |
|
|
870 | return &chr; |
|
|
871 | } |
|
|
872 | |
|
|
873 | int length (T *first) |
|
|
874 | { |
|
|
875 | return 1; |
|
|
876 | } |
|
|
877 | #endif |
|
|
878 | }; |
820 | #endif |
879 | #endif |
821 | |
880 | |
822 | /****************************************************************************/ |
881 | /****************************************************************************/ |
823 | |
882 | |
824 | #ifdef KEYSYM_RESOURCE |
883 | #ifdef KEYSYM_RESOURCE |