- "Compose a sequence of Tibetan character components into a composite character.
-Returns a string containing a composite character."
- (let ((t-str str)
- f-str s-str f-ch s-ch rest composed result)
- ;;Make sure no redundant vowel sign is present.
- (if (string-match
- "^\\(.+\\)\\(\e$(7"Q\e(B\\)\\([\e$(7!I!g!e"Q\e(B-\e$(7"^"_\e(B-\e$(7"l\e(B]\\)" t-str)
- (setq t-str (concat
- (match-string 1 t-str)
- (match-string 3 t-str))))
- (if (string-match
- "^\\(.+\\)\\([\e$(7!I!g!e"Q\e(B-\e$(7"^"_\e(B-\e$(7"l\e(B]\\)\\(\e$(7"Q\e(B\\)" t-str)
- (setq t-str (concat
- (match-string 1 t-str)
- (match-string 2 t-str))))
- ;;Start conversion.
- (setq result "")
- ;; Consecutive base/precomposed consonants are reduced to the last one.
- (while (string-match "^\\([\e$(7"!\e(B-\e$(7"J$!\e(B-\e$(7%u\e(B]\\)\\([\e$(7"!\e(B-\e$(7"@"B\e(B-\e$(7"J$!\e(B-\e$(7%u\e(B].*\\)" t-str)
- (setq result (concat result (match-string 1 t-str)))
- (setq t-str (match-string 2 t-str)))
- ;; Vowel/vowel modifier, subjoined consonants are added one by one
- ;; to the preceding element.
- (while
- (string-match "^\\(.\\)\\([\e$(7"A#!\e(B-\e$(7#J!I!g!e"Q\e(B-\e$(7"^"_\e(B-\e$(7"l\e(B]\\)\\(.*\\)" t-str)
- (setq f-str (match-string 1 t-str))
- (setq f-ch (string-to-char f-str))
- (setq s-str (match-string 2 t-str))
- ;;Special treatment for 'a chung.
- ;;If 'a follows a consonant, then turned into its subjoined form.
- (if (and (string-match "\e$(7"A\e(B" s-str)
- (not (tibetan-complete-char-examin f-ch)))
- (setq s-str "\e$(7#A\e(B"))
- (setq s-ch (string-to-char s-str))
- (setq rest (match-string 3 t-str))
- (cond ((string-match "\\c2" s-str);; upper vowel sign
- (setq composed
- (tibetan-vertical-stacking f-ch s-ch t)))
- ((string-match "\\c3" s-str);; lower vowel sign
- (setq composed
- (tibetan-vertical-stacking f-ch s-ch nil)))
- ;;Automatic conversion of ra-mgo (superscribed r).
- ;;'r' is converted if followed by a subjoined consonant
- ;;other than w, ', y, r.
- ((and (string-match "\e$(7"C\e(B" f-str)
- (not (string-match "[\e$(7#>#A#B#C\e(B]" s-str)))
- (setq f-ch ?\e$(7#P\e(B)
- (setq composed
- (tibetan-vertical-stacking f-ch s-ch nil)))
- ((not (tibetan-complete-char-examin f-ch))
- ;;Initial base consonant is tranformed, if followed by
- ;;a subjoined consonant, except when it is followed
- ;;by a subscribed 'a.
- (if (and (string-match "[\e$(7"!\e(B-\e$(7"="?"@"D\e(B-\e$(7"J\e(B]" f-str)
- (not (string-match "\e$(7#A\e(B" s-str)))
- (setq f-ch
- (string-to-char
- (cdr (assoc f-str tibetan-base-to-subjoined-alist)))))
- (setq composed
- (tibetan-vertical-stacking f-ch s-ch nil)))
- (t
- (setq composed s-str)
- (setq result (concat result f-str))))
- (setq t-str (concat composed rest)))
- (setq result (concat result t-str))))
-
-;;; quail <-> conversion interface.
-
-;;;###autoload
-(defun tibetan-composition (pc key)
- "Interface to quail input method.
-Takes two arguments: char PC and string KEY, where PC is the preceding
-character to be composed with current input KEY.
-Returns a string which is the result of composition."
- (let (trans cur-ch t-str result)
- ;; Make a tibetan character corresponding to current input key.
- (setq cur-ch (tibetan-transcription-to-tibetan key))
- ;; Check if the preceding character is Tibetan and composable.
- (cond ((and (tibetan-char-examin pc)
- (tibetan-composable-examin pc))
- ;;If Tibetan char corresponding to the current input key exists,
- (cond (cur-ch
- ;; Then,
- ;; Convert the preceding character into transcription,
- ;; and concatenate it with the current input key,
- (setq trans (tibetan-tibetan-to-transcription pc))
- (setq trans (concat trans key))
- ;; Concatenated transcription is converted to
- ;; a sequence of Tibetan characters,
- (setq t-str (tibetan-transcription-to-tibetan trans))
- ;; And it is composed into a composite character.
- (setq result (tibetan-compose-string t-str)))
- ;; Else,
- (t
- ;; Simply concatenate the preceding character and
- ;; the current input key.
- (setq result (char-to-string pc))
- (setq result (concat result key)))))
- ;; If the preceding char is not Tibetan or not composable,
- (t
- ;; pc = 0 means the point is at the beginning of buffer.
- (if (not (eq pc 0))
- (setq result (char-to-string pc)))
- (if cur-ch
- (setq result (concat result cur-ch))
- (setq result (concat result key))))
- )))
-