1 ;;; devan-util.el --- Support for Devanagari Script Composition
3 ;; Copyright (C) 1996 Free Software Foundation, Inc.
5 ;; Author: KAWABATA, Taichi <kawabata@is.s.u-tokyo.ac.jp>
7 ;; Keywords: multilingual, Indian, Devanagari
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
29 ;; 1996.10.18 written by KAWABATA, Taichi <kawabata@is.s.u-tokyo.ac.jp>
30 ;; 1997.1.20 fixed some bugs.
31 ;; 1997.3.24 fixed some bugs.
34 ;; Decompose the input characters and process them on the character basis.
36 ;; Devanagari script composition rules and related programs.
41 ;;; Steps toward composition of Devanagari Characters.
44 ;;; Intersection Function will be used.
48 (defun setup-devanagari-environment ()
49 "Setup multilingual environment (MULE) for languages using Devanagari."
51 (setup-8-bit-environment "Devanagari" nil "devanagari-itrans"))
56 (defun indian-to-devanagari (ch)
57 "Convert IS 13194 characters to Devanagari basic characters."
58 (let ((charcodes (split-char ch)))
59 (if (eq (car charcodes) 'indian-is13194)
60 (make-char 'indian-2-column ?\x21 (nth 1 charcodes))
64 (defun devanagari-to-indian (ch)
65 "Convert Devanagari basic characters to IS 13194 characters."
66 (let* ((charcodes (split-char ch))
67 (charset (car charcodes))
68 (code-h (car (cdr charcodes))))
69 (if (and (eq (car charcodes) 'indian-2-column)
70 (= (nth 1 charcodes) ?\x21))
71 (make-char 'indian-is13194 (nth 2 charcodes))
75 (defun indian-to-devanagari-region (from to)
76 "Convert IS 13194 characters in region to Devanagari basic characters."
79 (narrow-to-region from to)
80 (goto-char (point-min))
81 ; (while (re-search-forward "\\cd" nil t)
82 (while (re-search-forward "." nil t)
83 (let* ((devanagari-char (indian-to-devanagari (preceding-char))))
85 (insert devanagari-char)))))
88 (defun devanagari-to-indian-region (from to)
89 "Convert Devanagari basic characters in region to Indian characters."
92 (narrow-to-region from to)
93 (goto-char (point-min))
94 ; (while (re-search-forward "\\cD" nil t) ; Devanagari Character Code.
95 (while (re-search-forward "." nil t)
96 (let* ((indian-char (devanagari-to-indian (preceding-char))))
98 (insert indian-char)))))
101 (defun indian-to-devanagari-string (str)
102 "Convert Indian String to Devanagari Basic Character String."
103 (let ((pos 0) (dst "") (src str) char)
104 (while (not (equal src ""))
105 (setq char (string-to-char src))
106 (setq src (substring src (char-bytes char)))
107 (setq dst (concat dst (char-to-string (indian-to-devanagari char)))))
110 ;; Phase 0 - Determine whether the characters can be composed.
113 ;;; Regular expressions to split characters for composition.
116 ;; Indian script word contains one or more syllables.
117 ;; In BNF, it can be expressed as follows:
119 ;; Word ::= {Syllable} [Cons-Syllable]
120 ;; Syllable ::= Cons-Vowel-Syllable | Vowel-Syllable
121 ;; Vowel-Syllable ::= V[D]
122 ;; Cons-Vowel-Syllable ::= [Cons-Syllable] Full-Cons [M] [D]
123 ;; Cons-Syllable ::= [Pure-Cons] [Pure-Cons] [Pure-Cons] Pure-Cons
124 ;; Pure-Cons ::= Full-Cons H
125 ;; Full-Cons ::= C [N]
127 ;; {} repeat, [] optional
129 ;; C - Consonant (
\e$(5!3!4!5!6!7!8!9!:!;!<!=!>!?!@!A!B!C!D!E
\e(B
130 ;;
\e$(5!F!G!H!I!J!K!L!M!N!O!P!Q!R!S!T!U!V!W!X
\e(B)
131 ;; N - Nukta (
\e$(5!i
\e(B)
132 ;; H - Halant(
\e$(5!h
\e(B) or Virama
133 ;; V - Vowel (
\e$(5!$!%!&!'!(!)!*!+!,!-!.!/!0!1!2#&#'#*
\e(B)
134 ;; ("
\e$(5#&#'#*
\e(B" can be obtained by IS13194 vowels with nukta.)
135 ;; D - Vowel Modifiers, i.e. Anuswar, Chandrabindu (
\e$(5!!!"
\e(B)
136 ;; (Visaraga (
\e$(5!#
\e(B) is excluded.)
137 ;; M - Matra (
\e$(5!Z![!\!]!^!_!`!a!b!c!d!e!f!g#K#L#M
\e(B)
138 ;; ("
\e$(5#K#L#M
\e(B" can be obtained by IS13194 matras with nukta.)
140 ;; In Emacs, one syllable of Indian language is considered to be one
141 ;; composite glyph. If we expand the above expression for
142 ;; cons-vowel-syllable, it would be:
144 ;; [[C [N] H] [C [N] H] [C [N] H] C [N] H] C [N] [M] [D]
146 ;; Therefore, in worst case, the one syllable may contain
147 ;; following characters.
149 ;; C N H C N H C N H C N H C N M D
151 ;; The example is a sanskrit word "kArtsnya", where five consecutive
152 ;; consonants appear.
154 ;; On the other hand, consonant-syllable, which appears at the end of
155 ;; the word, would have the following expression:
157 ;; [C [N] H] [C [N] H] [C [N] H] C [N] H
159 ;; This is acceptable BEFORE proper consonant-syllable is input. The
160 ;; string which doesn't match with the above expression is invalid and
161 ;; thus must be fixed.
164 ;; Third case can be considered, which is acceptable syllable and can
165 ;; not add any code more.
167 ;; [[C [N] H] [C [N] H] [C [N] H] C [N] H] C [N] [M] D
169 ;; However, to make editing possible even in this condition, we will
170 ;; not consider about this case.
173 ;; Currently, it seems that the only following consonants would have
174 ;; Nukta sign attatched.
175 ;; (
\e$(5!3!4!5!:!?!@!I
\e(B)
176 ;; Therefore, [
\e$(5!3
\e(B-
\e$(5!X
\e(B]
\e$(5!i
\e(B? can be re-written as
177 ;; \\([
\e$(5!3!4!5!:!?!@!I
\e(B]
\e$(5!i
\e(B\\)\\|[
\e$(5!3
\e(B-
\e$(5!X
\e(B]
179 (defconst devanagari-full-cons
180 "\\(\\([
\e$(5!3!4!5!:!?!@!I
\e(B]
\e$(5!i
\e(B\\)\\|[
\e$(5!3
\e(B-
\e$(5!X$.$E"%
\e(B]\\)"
181 "Devanagari full consonant")
183 (defconst devanagari-pure-cons
184 (concat "\\(" devanagari-full-cons "
\e$(5!h
\e(B\\)")
185 "Devanagari pure consonant")
187 (defconst devanagari-matra
188 "\\(\\([
\e$(5!_![!\
\e(B]
\e$(5!i
\e(B\\)\\|[
\e$(5!Z
\e(B-
\e$(5!g#K#L#M
\e(B]\\)"
189 "Devanagari Matra Signs. '
\e$(5#K#L#M
\e(B' can also be created from the combination
190 of '
\e$(5!_![!\
\e(B' and nukta sign.")
192 (defconst devanagari-vowel
193 "\\(\\([
\e$(5!*!&!'
\e(B]
\e$(5!i
\e(B\\)\\|[
\e$(5!$
\e(B-
\e$(5!2#&#'#*
\e(B]\\)"
194 "Devanagari Vowels. '
\e$(5#&#'#*
\e(B' can also be created from the combination
195 of '
\e$(5!*!&!'
\e(B' and nukta sign.")
197 (defconst devanagari-vowel-syllable
198 (concat devanagari-vowel "[
\e$(5!!!"
\e(B]?")
199 "Devanagari vowel syllable.")
201 (defconst devanagari-cons-syllable
202 (concat devanagari-pure-cons "?" devanagari-pure-cons "?"
203 devanagari-pure-cons "?" devanagari-pure-cons "$")
204 "Devanagari consonant syllable")
206 (defconst devanagari-cons-vowel-syllable
208 devanagari-pure-cons "?" devanagari-pure-cons "?"
209 devanagari-pure-cons "?" devanagari-pure-cons "\\)?"
210 devanagari-full-cons devanagari-matra "?[
\e$(5!!!"
\e(B]?")
211 "Devanagari consonant vowel syllable.")
214 ;; Also, digits and virams should be processed other than syllables.
216 ;; In IS 13194, Avagrah is obtained by Nukta after Viram, and
217 ;; OM is obtained by Nukta after Chandrabindu
220 (defconst devanagari-digit-viram-visarga
221 "[
\e$(5!q
\e(B-
\e$(5!z!j!#
\e(B]")
222 (defconst devanagari-other-sign
223 "\\([
\e$(5!!!j
\e(B]
\e$(5!i
\e(B\\)\\|\\([
\e$(5#!#J
\e(B]\\)")
225 (defconst devanagari-composite-glyph-unit
226 (concat "\\(" devanagari-cons-syllable
227 "\\)\\|\\(" devanagari-vowel-syllable
228 "\\)\\|\\(" devanagari-digit-viram-visarga
229 "\\)\\|\\(" devanagari-cons-vowel-syllable
230 "\\)\\|\\(" devanagari-other-sign "\\)")
231 "Regexp matching to Devanagari string to be composed form one glyph.")
233 ;;(put-charset-property charset-devanagari-1-column
234 ;; 'char-to-glyph 'devanagari-compose-string)
235 ;;(put-charset-property charset-devanagari-2-column
236 ;; 'char-to-glyph 'devanagari-compose-string)
240 ;;(string-match devanagari-cons-vowel-syllable-examine "
\e$(5!X![
\e(B") => 0
241 ;;(string-match devanagari-cons-vowel-syllable-examine "
\e$(5!F!h!D!\
\e(B") => 0
242 ;;(string-match devanagari-cons-vowel-syllable-examine "
\e$(5!X![!F!h!D!\
\e(B") => 0
245 ;; Steps toward the composition
246 ;; Converting Character Codes to Composite Glyph.
248 ;; Example :
\e$(5!X![
\e(B/
\e$(5!F!h!D!\
\e(B
250 ;; First, convert Characters to appropriate glyphs.
252 ;; =>
\e$(5!X![
\e(B/
\e$(5"F!D!\
\e(B
254 ;; Then, determine the base glyph, apply-orders and apply-rules.
256 ;; =>
\e$(5!X
\e(B (ml.mr)
\e$(5![
\e(B /
\e$(5!D
\e(B (ml.mr)
\e$(5"F
\e(B (mr ml)
\e$(5!\
\e(B
258 ;; Finally, convert 2-column glyphs to 1-column glyph
259 ;; if such a glyph exist.
261 ;; =>
\e$(6![
\e(B (ml.mr)
\e$(6!X
\e(B /
\e$(6!D
\e(B (ml.mr)
\e$(6"F
\e(B (mr ml)
\e$(6!\
\e(B
263 ;; Compose the glyph.
265 ;; =>
\e2
\e$(6!X@![
\e1
\e(B/
\e2
\e$(6!D@"FP!\
\e1
\e(B
266 ;; =>
\e2
\e$(6!X@![
\e1
\e2!D@"FP!\
\e1
\e(B
270 ;; Phase 1: Converting Character Code to Glyph Code.
274 ;; There may be many rules which you many want to be suppressed.
275 ;; In that case, please comment out that rule.
277 ;; RULES WILL BE EVALUATED FROM FIRST TO LAST.
278 ;; PUT MORE SPECIFIC RULES FIRST.
281 ;; Prepare multiple specific list of rules for each languages
282 ;; which adopts Devanagari script.
286 (defconst devanagari-char-to-glyph-rules
289 ;; `r' at the top of syllable and followed by other consonants.
290 ;; ("[^
\e$(5!h
\e(B]\\(
\e$(5!O!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!X
\e(B]" "
\e$(5"p
\e(B")
291 ("^\\(
\e$(5!O!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!X
\e(B]" "
\e$(5"p
\e(B")
294 ("\\(
\e$(5!3!h!B!h!O!h!M
\e(B\\)" "
\e$(5$!
\e(B" sanskrit)
295 ("\\(
\e$(5!3!h!B!h!T
\e(B\\)" "
\e$(5$"
\e(B" sanskrit)
296 ("\\(
\e$(5!3!h!B!h!M
\e(B\\)" "
\e$(5$#
\e(B" sanskrit)
297 ("\\(
\e$(5!3!h!F!h!M
\e(B\\)" "
\e$(5$$
\e(B")
298 ("\\(
\e$(5!3!h!O!h!M
\e(B\\)" "
\e$(5$%
\e(B")
299 ("\\(
\e$(5!3!h!O
\e(B\\)" "
\e$(5"#
\e(B") ; Post "r"
300 ("\\(
\e$(5!3!h!T!h!M
\e(B\\)" "
\e$(5$&
\e(B" sanskrit)
301 ("\\(
\e$(5!3!h
\e(B\\)
\e$(5!3!h
\e(B[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"3
\e(B") ; Special Half Form
302 ("\\(
\e$(5!3!h!3
\e(B\\)" "
\e$(5$'
\e(B")
303 ("\\(
\e$(5!3!h
\e(B\\)
\e$(5!B!h!O
\e(B" "
\e$(5"3
\e(B") ; Special Rules for "k-tr"
304 ("\\(
\e$(5!3!h!B
\e(B\\)" "
\e$(5$(
\e(B")
305 ("\\(
\e$(5!3!h!F
\e(B\\)" "
\e$(5$)
\e(B")
306 ("\\(
\e$(5!3!h!L
\e(B\\)" "
\e$(5$*
\e(B")
307 ("\\(
\e$(5!3!h!M
\e(B\\)" "
\e$(5$+
\e(B")
308 ("\\(
\e$(5!3!h!Q
\e(B\\)" "
\e$(5$,
\e(B")
309 ("\\(
\e$(5!3!h!T
\e(B\\)" "
\e$(5$-
\e(B")
310 ("\\(
\e$(5!3!h!V!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"l
\e(B") ; Half Form
311 ("\\(
\e$(5$.!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"l
\e(B") ; Half Form
312 ("\\(
\e$(5!3!h!V
\e(B\\)" "
\e$(5$.
\e(B")
313 ("\\(
\e$(5!3!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"3
\e(B") ; Half Form
314 ("\\(
\e$(5!3!i!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"s
\e(B") ; Nukta Half Form
315 ("\\(
\e$(5!3!i
\e(B\\)" "
\e$(5#3
\e(B") ; Nukta
316 ("\\(
\e$(5!4!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"4
\e(B") ; Half Form
317 ("\\(
\e$(5!4!i!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"t
\e(B") ; Nukta Half Form
318 ("\\(
\e$(5!4!i
\e(B\\)" "
\e$(5#4
\e(B") ; Nukta
319 ("\\(
\e$(5!5!h!O!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"`
\e(B") ; Half Form
320 ("\\(
\e$(5!5!h!O
\e(B\\)" "
\e$(5"$
\e(B") ; Post "r"
321 ("\\(
\e$(5!5!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"5
\e(B") ; Half Form
322 ("\\(
\e$(5!5!i!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"u
\e(B") ; Nukta Half Form
323 ("\\(
\e$(5!5!i
\e(B\\)" "
\e$(5#5
\e(B") ; Nukta
324 ("\\(
\e$(5!6!h!F!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"a
\e(B") ; Half Form
325 ("\\(
\e$(5!6!h!F
\e(B\\)" "
\e$(5$/
\e(B")
327 ("\\(
\e$(5!6!h!O
\e(B\\)" "
\e$(5!6"q
\e(B") ; Post "r"
328 ("\\(
\e$(5!6!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"6
\e(B") ; Half Form
329 ("\\(
\e$(5!7!h!3!h!B!h!M
\e(B\\)" "
\e$(5$0
\e(B" sanskrit)
330 ("\\(
\e$(5!7!h!3!h!V!h!T
\e(B\\)" "
\e$(5$1
\e(B" sanskrit)
331 ("\\(
\e$(5!7!h!3!h!B
\e(B\\)" "
\e$(5$2
\e(B" sanskrit)
332 ("\\(
\e$(5!7!h!3!h!V
\e(B\\)" "
\e$(5$3
\e(B" sanskrit)
333 ("\\(
\e$(5!7!h!3!h!O
\e(B\\)" "
\e$(5$9"q
\e(B") ; Special Rule. May be precomposed font needed.
334 ("\\(
\e$(5!7!h!6!h!O
\e(B\\)" "
\e$(5$4
\e(B" sanskrit)
335 ("\\(
\e$(5!7!h!3!h!M
\e(B\\)" "
\e$(5$5
\e(B" sanskrit)
336 ("\\(
\e$(5!7!h!4!h!M
\e(B\\)" "
\e$(5$6
\e(B" sanskrit)
337 ("\\(
\e$(5!7!h!5!h!M
\e(B\\)" "
\e$(5$7
\e(B" sanskrit)
338 ("\\(
\e$(5!7!h!6!h!M
\e(B\\)" "
\e$(5$8
\e(B" sanskrit)
339 ("\\(
\e$(5!7!h!3
\e(B\\)" "
\e$(5$9
\e(B")
340 ("\\(
\e$(5!7!h!4
\e(B\\)" "
\e$(5$:
\e(B")
341 ("\\(
\e$(5!7!h!5!h!O
\e(B\\)" "
\e$(5$;"q
\e(B") ; Special Rule. May be precomposed font needed.
342 ("\\(
\e$(5!7!h!5
\e(B\\)" "
\e$(5$;
\e(B")
343 ("\\(
\e$(5!7!h!6
\e(B\\)" "
\e$(5$<
\e(B")
344 ("\\(
\e$(5!7!h!7
\e(B\\)" "
\e$(5$=
\e(B")
345 ("\\(
\e$(5!7!h!F
\e(B\\)" "
\e$(5$>
\e(B")
346 ("\\(
\e$(5!7!h!L
\e(B\\)" "
\e$(5$?
\e(B")
347 ("\\(
\e$(5!7!h!M
\e(B\\)" "
\e$(5$@
\e(B")
348 ("\\(
\e$(5!8!h
\e(B\\)[
\e$(5!8!<
\e(B]
\e$(5!h
\e(B" "
\e$(5"8
\e(B") ; Half Form
349 ("\\(
\e$(5!8!h!8
\e(B\\)" "
\e$(5$A
\e(B")
350 ("\\(
\e$(5!8!h!<
\e(B\\)" "
\e$(5$B
\e(B")
351 ("\\(
\e$(5!8!h!O!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"8"q
\e(B") ; Half Form Post "r"
352 ("\\(
\e$(5!8!h!O
\e(B\\)" "
\e$(5!8"q
\e(B") ; Post "r"
353 ("\\(
\e$(5!8!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"8
\e(B") ; Half Form
354 ("\\(
\e$(5!9!h!M
\e(B\\)" "
\e$(5$C
\e(B")
355 ("\\(
\e$(5!:!h!O
\e(B\\)" "
\e$(5$D
\e(B")
356 ("\\(
\e$(5!:!h!<!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"m
\e(B") ; Half Form
357 ("\\(
\e$(5!:!h!<
\e(B\\)" "
\e$(5$E
\e(B")
358 ("\\(
\e$(5!:!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5":
\e(B") ; Half Form
359 ("\\(
\e$(5!:!i!h!O
\e(B\\)" "
\e$(5"!
\e(B") ; Nukta Post "r"
360 ("\\(
\e$(5!:!i!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"z
\e(B") ; Nukta Half Form
361 ("\\(
\e$(5!:!i
\e(B\\)" "
\e$(5#:
\e(B") ; Nukta
362 ("\\(
\e$(5!;!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5";
\e(B") ; Half Form
363 ("\\(
\e$(5!<!h
\e(B\\)
\e$(5!8!h
\e(B[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"<
\e(B") ; Special Half Form
364 ("\\(
\e$(5!<!h!8
\e(B\\)" "
\e$(5$F
\e(B")
365 ("\\(
\e$(5!<!h
\e(B\\)
\e$(5!:!h
\e(B[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"<
\e(B") ; Special Half Form
366 ("\\(
\e$(5!<!h!:
\e(B\\)" "
\e$(5$G
\e(B")
367 ("\\(
\e$(5!<!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"<
\e(B") ; Half Form
368 ("\\(
\e$(5!=!h!3
\e(B\\)" "
\e$(5$H
\e(B")
369 ("\\(
\e$(5!=!h!=
\e(B\\)" "
\e$(5$I
\e(B")
370 ("\\(
\e$(5!=!h!>
\e(B\\)" "
\e$(5$J
\e(B")
371 ("\\(
\e$(5!=!h!M
\e(B\\)" "
\e$(5$K
\e(B")
372 ("\\(
\e$(5!>!h!M
\e(B\\)" "
\e$(5$L
\e(B")
373 ("\\(
\e$(5!?!h!5!h!M
\e(B\\)" "
\e$(5$M
\e(B" sanskrit)
374 ("\\(
\e$(5!?!h!6!h!O
\e(B\\)" "
\e$(5$N
\e(B" sanskrit)
375 ("\\(
\e$(5!?!h!O!h!M
\e(B\\)" "
\e$(5$O
\e(B")
376 ("\\(
\e$(5!?!h!5
\e(B\\)" "
\e$(5$P
\e(B")
377 ("\\(
\e$(5!?!h!6
\e(B\\)" "
\e$(5$Q
\e(B")
378 ("\\(
\e$(5!?!h!?
\e(B\\)" "
\e$(5$R
\e(B")
379 ("\\(
\e$(5!?!h!L
\e(B\\)" "
\e$(5$S
\e(B")
380 ("\\(
\e$(5!?!h!M
\e(B\\)" "
\e$(5$T
\e(B")
381 ("\\(
\e$(5!?!i
\e(B\\)" "
\e$(5#?
\e(B") ; Nukta
382 ("\\(
\e$(5!@!h!M
\e(B\\)" "
\e$(5$`
\e(B")
383 ("\\(
\e$(5!@!i
\e(B\\)" "
\e$(5#@
\e(B") ; Nukta
384 ("\\(
\e$(5!A!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"A
\e(B") ; Half Form
385 ("\\(
\e$(5!B!h
\e(B\\)
\e$(5!B!h!O
\e(B" "
\e$(5"B
\e(B") ; Special Rule for "t-tr"
386 ("\\(
\e$(5!B!h!B!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"c
\e(B") ; Half Form
387 ("\\(
\e$(5!B!h!B
\e(B\\)" "
\e$(5$a
\e(B")
388 ("\\(
\e$(5!B!h!F
\e(B\\)" "
\e$(5$b
\e(B")
389 ("\\(
\e$(5!B!h!O!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"d
\e(B") ; Half Form Post "r"
390 ("\\(
\e$(5!B!h!O
\e(B\\)" "
\e$(5"%
\e(B") ; Post "r"
391 ("\\(
\e$(5!B!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"B
\e(B") ; Half Form
392 ("\\(
\e$(5!C!h!O
\e(B\\)" "
\e$(5!C"q
\e(B") ; Post "r"
393 ("\\(
\e$(5!C!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"C
\e(B") ; Half Form
394 ("\\(
\e$(5!D!h!D!h!M
\e(B\\)" "
\e$(5$c
\e(B")
395 ("\\(
\e$(5!D!h!E!h!M
\e(B\\)" "
\e$(5$d
\e(B")
396 ("\\(
\e$(5!D!h!K!h!M
\e(B\\)" "
\e$(5$e
\e(B")
397 ("\\(
\e$(5!D!h!K!h!O
\e(B\\)" "
\e$(5$r"r
\e(B") ; Special Case for "dbhr" ; ***
398 ("\\(
\e$(5!D!h!O!h!M
\e(B\\)" "
\e$(5$f
\e(B")
399 ("\\(
\e$(5!D!h!T!h!M
\e(B\\)" "
\e$(5$g
\e(B")
400 ("\\(
\e$(5!D!h!5!h!O
\e(B\\)" "
\e$(5$h
\e(B")
401 ("\\(
\e$(5!D!h!6!h!O
\e(B\\)" "
\e$(5$i
\e(B")
402 ("\\(
\e$(5!D!h!D!h!T
\e(B\\)" "
\e$(5$j
\e(B")
403 ("\\(
\e$(5!D!h!E!h!T
\e(B\\)" "
\e$(5$k
\e(B")
404 ("\\(
\e$(5!D!h
\e(B\\)
\e$(5!E!h
\e(B[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5!D!h
\e(B") ; Special Half Form (for ddhra)
405 ("\\(
\e$(5!D!h!5
\e(B\\)" "
\e$(5$l
\e(B")
406 ("\\(
\e$(5!D!h!6
\e(B\\)" "
\e$(5$m
\e(B")
407 ("\\(
\e$(5!D!h!D
\e(B\\)" "
\e$(5$n
\e(B")
408 ("\\(
\e$(5!D!h!E
\e(B\\)" "
\e$(5$o
\e(B")
409 ("\\(
\e$(5!D!h!F
\e(B\\)" "
\e$(5$p
\e(B")
410 ("\\(
\e$(5!D!h
\e(B\\)
\e$(5!J!h
\e(B" "
\e$(5!D!h
\e(B") ; Suppressing "db-"
411 ("\\(
\e$(5!D!h!J
\e(B\\)" "
\e$(5$q
\e(B")
412 ("\\(
\e$(5!D!h!K
\e(B\\)" "
\e$(5$r
\e(B")
413 ("\\(
\e$(5!D!h!L
\e(B\\)" "
\e$(5$s
\e(B")
414 ("\\(
\e$(5!D!h!M
\e(B\\)" "
\e$(5$t
\e(B")
415 ("\\(
\e$(5!D!h!T
\e(B\\)" "
\e$(5$u
\e(B")
416 ("\\(
\e$(5!E!h!F!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"e
\e(B") ; Half Form
417 ("\\(
\e$(5!E!h!F
\e(B\\)" "
\e$(5$v
\e(B")
418 ("\\(
\e$(5!E!h!O!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"f
\e(B") ; Half Form Post "r"
419 ("\\(
\e$(5!E!h!O
\e(B\\)" "
\e$(5!E"q
\e(B") ; Post "r"
420 ("\\(
\e$(5!E!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"E
\e(B") ; Half Form
421 ("\\(
\e$(5!F!h!F!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"k
\e(B") ; Half Form
422 ("\\(
\e$(5!F!h!F
\e(B\\)" "
\e$(5$w
\e(B")
423 ("\\(
\e$(5!F!h!O
\e(B\\)" "
\e$(5!F"q
\e(B")
424 ("\\(
\e$(5!F!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"F
\e(B") ; Half Form
425 ("\\(
\e$(5!G!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"G
\e(B") ; Nukta Half Form
426 ("\\(
\e$(5!H!h
\e(B\\)
\e$(5!B!h!O
\e(B" "
\e$(5"H
\e(B") ; Special Rule for "p-tr"
427 ("\\(
\e$(5!H!h!B!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"g
\e(B") ; Half Form
428 ("\\(
\e$(5!H!h!B
\e(B\\)" "
\e$(5$x
\e(B")
429 ("\\(
\e$(5!H!h!F
\e(B\\)" "
\e$(5$y
\e(B")
430 ("\\(
\e$(5!H!h!Q
\e(B\\)" "
\e$(5$z
\e(B")
431 ("\\(
\e$(5!H!h!O
\e(B\\)" "
\e$(5"&
\e(B") ; Post "r"
432 ("\\(
\e$(5!H!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"H
\e(B") ; Half Form
433 ("\\(
\e$(5!I!h!O
\e(B\\)" "
\e$(5"'
\e(B") ; Post "r"
434 ("\\(
\e$(5!I!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"I
\e(B") ; Half Form
435 ("\\(
\e$(5!I!i!h!O
\e(B\\)" "
\e$(5""
\e(B") ; Nukta Post "r"
436 ("\\(
\e$(5!I!i!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"y
\e(B") ; Nukta Half Form
437 ("\\(
\e$(5!I!i
\e(B\\)" "
\e$(5#I
\e(B") ; Nukta
438 ("\\(
\e$(5!J!h
\e(B\\)
\e$(5!F!h
\e(B[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"J
\e(B") ; Special Half Form
439 ("\\(
\e$(5!J!h!F
\e(B\\)" "
\e$(5${
\e(B")
440 ("\\(
\e$(5!J!h
\e(B\\)
\e$(5!J!h
\e(B[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"J
\e(B") ; Special Half Form
441 ("\\(
\e$(5!J!h!J
\e(B\\)" "
\e$(5$|
\e(B")
442 ("\\(
\e$(5!J!h
\e(B\\)
\e$(5!T!h
\e(B[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"J
\e(B") ; Special Half Form
443 ("\\(
\e$(5!J!h!T
\e(B\\)" "
\e$(5$}
\e(B")
444 ("\\(
\e$(5!J!h!O
\e(B\\)" "
\e$(5!J"q
\e(B") ; Post "r"
445 ("\\(
\e$(5!J!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"J
\e(B") ; Half Form
446 ("\\(
\e$(5!K!h!F
\e(B\\)" "
\e$(5$~
\e(B")
447 ("\\(
\e$(5!K!h!O
\e(B\\)" "
\e$(5!K"q
\e(B") ; Post "r"
448 ("\\(
\e$(5!K!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"K
\e(B") ; Half Form
449 ("\\(
\e$(5!L!h!F
\e(B\\)" "
\e$(5#P
\e(B")
450 ("\\(
\e$(5!L!h!Q
\e(B\\)" "
\e$(5#Q
\e(B")
451 ("\\(
\e$(5!L!h!O
\e(B\\)" "
\e$(5!L"q
\e(B") ; Post "r"
452 ("\\(
\e$(5!L!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"L
\e(B") ; Half Form
453 ("\\(
\e$(5!M!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"M
\e(B") ; Half Form
454 ("\\(
\e$(5!N!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"N
\e(B") ; Half Form
455 ;; special form for "ru".
456 ("\\(
\e$(5!O!]
\e(B\\)" "
\e$(5",
\e(B")
457 ("\\(
\e$(5!O!^
\e(B\\)" "
\e$(5"-
\e(B")
458 ("\\(
\e$(5!P!]
\e(B\\)" "
\e$(5".
\e(B")
459 ("\\(
\e$(5!P!^
\e(B\\)" "
\e$(5"/
\e(B")
461 ("\\(
\e$(5!Q!h!Q
\e(B\\)" "
\e$(5#`
\e(B" sanskrit)
462 ("\\(
\e$(5!Q!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"Q
\e(B") ; Half Form
463 ("\\(
\e$(5!R!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"R
\e(B") ; Half Form
464 ("\\(
\e$(5!S!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"S
\e(B") ; Half Form
465 ("\\(
\e$(5!T!h!F
\e(B\\)" "
\e$(5#a
\e(B")
466 ("\\(
\e$(5!T!h!T
\e(B\\)" "
\e$(5#b
\e(B")
467 ("\\(
\e$(5!T!h!O
\e(B\\)" "
\e$(5!T"q
\e(B") ; Post "r"
468 ("\\(
\e$(5!T!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"T
\e(B") ; Half Form
469 ("\\(
\e$(5!U!h!8!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"h
\e(B") ; Half Form
470 ("\\(
\e$(5!U!h!8
\e(B\\)" "
\e$(5#c
\e(B")
471 ("\\(
\e$(5!U!h!F
\e(B\\)" "
\e$(5#d
\e(B")
472 ("\\(
\e$(5!U!h!J
\e(B\\)" "
\e$(5#e
\e(B")
473 ("\\(
\e$(5!U!h!Q
\e(B\\)" "
\e$(5#f
\e(B")
474 ("\\(
\e$(5!U!h
\e(B\\)
\e$(5!T!h!O
\e(B" "
\e$(5"U
\e(B") ; Special Half Form
475 ("\\(
\e$(5!U!h!T!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"j
\e(B") ; Half Form
476 ; ("\\(
\e$(5!U!h!T
\e(B\\)" "
\e$(5#g
\e(B")
477 ("\\(
\e$(5!U!h!O!h!T
\e(B\\)" "
\e$(5#g
\e(B")
478 ("\\(
\e$(5!U!h!O!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"i
\e(B") ; Half Form
479 ("\\(
\e$(5!U!h!O
\e(B\\)" "
\e$(5")
\e(B") ; Post "r"
480 ("\\(
\e$(5!U!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"U
\e(B") ; Half Form
481 ("\\(
\e$(5!V!h!=!h!O!h!M
\e(B\\)" "
\e$(5#h
\e(B")
482 ("\\(
\e$(5!V!h!=!h!M
\e(B\\)" "
\e$(5#i
\e(B")
483 ("\\(
\e$(5!V!h!=!h!T
\e(B\\)" "
\e$(5#j
\e(B")
484 ("\\(
\e$(5!V!h!=
\e(B\\)" "
\e$(5#k
\e(B")
485 ("\\(
\e$(5!V!h!>
\e(B\\)" "
\e$(5#l
\e(B")
486 ("\\(
\e$(5!V!h!O
\e(B\\)" "
\e$(5!V"q
\e(B") ; Post "r"
487 ("\\(
\e$(5!V!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"V
\e(B") ; Half Form
488 ("\\(
\e$(5!W!h!F!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"W"F
\e(B") ; Special Half Form
489 ("\\(
\e$(5!W!h!F
\e(B\\)" "
\e$(5#m
\e(B")
490 ("\\(
\e$(5!W!h!O
\e(B\\)" "
\e$(5#n
\e(B")
491 ("\\(
\e$(5!W!h
\e(B\\)[
\e$(5!3
\e(B-
\e$(5!N!P
\e(B-
\e$(5!X
\e(B]" "
\e$(5"W
\e(B") ; Half Form
492 ("\\(
\e$(5!X!h!A
\e(B\\)" "
\e$(5#p
\e(B")
493 ("\\(
\e$(5!X!h!F
\e(B\\)" "
\e$(5#q
\e(B")
494 ("\\(
\e$(5!X!h!L
\e(B\\)" "
\e$(5#r
\e(B")
495 ("\\(
\e$(5!X!h!M
\e(B\\)" "
\e$(5#s
\e(B")
496 ("\\(
\e$(5!X!h!O
\e(B\\)" "
\e$(5#t
\e(B")
497 ("\\(
\e$(5!X!h!Q
\e(B\\)" "
\e$(5#u
\e(B")
498 ("\\(
\e$(5!X!h!T
\e(B\\)" "
\e$(5#v
\e(B")
499 ;; Special Ligature Rules
500 ("\\(
\e$(5!X!_
\e(B\\)" "
\e$(5#R
\e(B")
502 ;; For consonants other than listed above, glyph-composition will
503 ;; be applied. If the consonant which is preceding "
\e$(5!O
\e(B" does not
504 ;; have the vertical line (such as "
\e$(5!?
\e(B"), "
\e$(5"r
\e(B" is put beneath the
507 ("[
\e$(5!7!9!=!>!?!@!D!O!P!R!S!X
\e(B]\\(
\e$(5!h!O
\e(B\\)" "
\e$(5"r
\e(B")
508 ("[
\e$(5!6!8!C!E!F!H!J!K!L!M!T!V
\e(B]\\(
\e$(5!h!O
\e(B\\)" "
\e$(5"q
\e(B")
509 ("
\e$(5!?!i
\e(B\\(
\e$(5!h!O
\e(B\\)" "
\e$(5"r
\e(B")
510 ("
\e$(5!@!i
\e(B\\(
\e$(5!h!O
\e(B\\)" "
\e$(5"r
\e(B")
512 ;; Nukta with Non-Consonants
513 ("\\(
\e$(5!!!i
\e(B\\)" "
\e$(5#!
\e(B")
514 ("\\(
\e$(5!&!i
\e(B\\)" "
\e$(5#&
\e(B")
515 ("\\(
\e$(5!'!i
\e(B\\)" "
\e$(5#'
\e(B")
516 ("\\(
\e$(5!*!i
\e(B\\)" "
\e$(5#*
\e(B")
517 ("\\(
\e$(5![!i
\e(B\\)" "
\e$(5#L
\e(B")
518 ("\\(
\e$(5!\!i
\e(B\\)" "
\e$(5#M
\e(B")
519 ("\\(
\e$(5!_!i
\e(B\\)" "
\e$(5#K
\e(B")
520 ("\\(
\e$(5!j!i
\e(B\\)" "
\e$(5#J
\e(B")
522 ;; Special rule for "r + some vowels"
523 ("\\(
\e$(5!O!_
\e(B\\)" "
\e$(5!*"p
\e(B")
524 ("\\(
\e$(5!O#L
\e(B\\)" "
\e$(5#&"p
\e(B")
525 ("\\(
\e$(5!O#K
\e(B\\)" "
\e$(5#*"p
\e(B")
526 ("\\(
\e$(5!O#M
\e(B\\)" "
\e$(5#'"p
\e(B")
527 ;; If everything fails, "y" will connect to the front consonant.
528 ("\\(
\e$(5!h!M
\e(B\\)" "
\e$(5"]
\e(B")
530 "Alist of regexps of Devanagari character sequences vs composed characters.")
532 (let ((rules devanagari-char-to-glyph-rules))
534 (let ((rule (car rules))
535 (chars) (char) (glyphs) (glyph))
536 (setq rules (cdr rules))
537 (string-match "\\\\(\\(.+\\)\\\\)" (car rule))
538 (setq chars (substring (car rule) (match-beginning 1) (match-end 1)))
539 (setq char (string-to-char chars))
540 (setq glyphs (cdr rule))
541 (setq glyph (string-to-char (car glyphs)))
542 (put-char-code-property
544 ;; We don't "cons" it since priority is top to down.
545 (append (get-char-code-property char 'char-to-glyph) (list rule)))
547 (if (and (< ?
\e(5z
\e(B glyph) ; Glyphs only.
548 (null (get-char-code-property glyph 'glyph-to-char)))
549 ; One glyph may corresponds to multiple characters,
550 ; e.g., surrounding vowel in Tamil, etc.
551 ; but for Devanagari, we put this restriction
552 ; to make sure the fact that one glyph corresponds to one char.
553 (put-char-code-property
555 (cons (list (car glyphs) chars)
556 (get-char-code-property glyph 'glyph-to-char)
560 ;; Function used in both characters-to-glyphs conversion and
561 ;; glyphs-to-characters conversion.
564 (defun max-match-len (regexp-str)
565 "This returns the possible length of matched string of given regexp.
566 Only [...] pattern of regexp is recognized. The last character of
567 inside of [....] is used for its length."
568 (let ((dest-str regexp-str))
569 (while (string-match "\\[\\([^\]]\\)+\\]" dest-str)
571 (concat (substring dest-str 0 (match-beginning 0))
572 (substring dest-str (match-beginning 1) (match-end 1))
573 (substring dest-str (match-end 0)))))
576 (defun string-conversion-by-rule (src-str symbol &rest specs)
577 " This function converts the SRC-STR to the new string according to
578 the rules described in the each character's SYMBOL property. The
579 rules are described in the forms of '((regexp str <specs>) ...), and
580 the character sequence in the string which matches to 'regexp' are
581 replaced with str. If SPECS are not specified, only rules with no
582 <specs> would be applied. If SPECS are specified, then rules with no
583 <specs> specified and rules with <spec> matches with SPECS would be
584 applied. Rules are tested in the order of the list, thus more
585 specific rules should be placed in front of less important rules. No
586 composite character is supported, thus such must be converted by
587 decompose-char before applying to this function. If rule is given in
588 the forms of regexp '...\\(...\\)...', then inside the parenthesis is
589 the subject of the match. Otherwise, the entire expression is the
590 subject of the match."
593 (while (< pos (length src-str))
595 (rules (get-char-code-property
597 (substring src-str pos)) symbol)))
599 (let* ((rule (car rules))
601 (replace-str (car (cdr rule)))
602 (rule-specs (cdr (cdr rule)))
604 (if (not (or (null rule-specs)
605 (intersection specs rule-specs)))
606 (setq rules (cdr rules))
607 (if (null (string-match "\\\\(.+\\\\)" regexp))
609 (setq regexp (concat "\\(" regexp "\\)"))
610 (setq search-pos pos))
611 (setq search-pos (- pos (max-match-len
613 (string-match "^[^\\\\]*" regexp)
615 (if (< search-pos 0) (setq search-pos 0))
616 (if (string-match regexp src-str search-pos)
617 (if (= (match-beginning 1) pos)
619 (setq dst-str (concat dst-str replace-str))
620 (setq rules nil) ; Get out of the loop.
622 ;; proceed `pos' for replaced characters.
623 (setq pos (match-end 1)))
624 (setq rules (cdr rules)))
625 (setq rules (cdr rules))))))
626 ;; proceed to next position
628 (let ((nextchar (string-to-char (substring src-str pos))))
630 (char-bytes (string-to-char (substring src-str pos)))))
631 (setq dst-str (concat dst-str (char-to-string nextchar)))))))
636 ;; Convert Character Code to Glyph Code
640 (defun char-to-glyph-devanagari (src-str &rest langs)
641 "Convert Devanagari characters in the string to Devanagari glyphs.
642 Ligatures and special rules are processed."
644 'string-conversion-by-rule
645 (append (list src-str 'char-to-glyph) langs)))
648 ;;(char-to-glyph-devanagari "
\e$(5!X![!F!h!D!\
\e(B") => "
\e$(5!X!["F!D!\
\e(B"
649 ;;(char-to-glyph-devanagari "
\e$(5!O!Z!V!h!=!h!O![!M
\e(B") => ???
652 ;; Phase 2: Compose Glyphs to form One Glyph.
655 ;; Each list consist of glyph, application-priority and application-direction.
657 ;; Glyphs will be ordered from low priority number to high priority number.
658 ;; If application-priority is omitted, it is assumed to be 0.
659 ;; If application-direction is omitted, it is asumbed to be '(mr . ml).
661 (defconst devanagari-composition-rules
662 '((?
\e$(5!!
\e(B 0 (tr . br))
663 (?
\e$(5!"
\e(B 0 (mr . mr))
720 (?
\e$(5![
\e(B 0 (ml . mr))
722 (?
\e$(5!]
\e(B 0 (br . tr))
723 (?
\e$(5!^
\e(B 0 (br . tr))
724 (?
\e$(5!_
\e(B 0 (br . tr))
725 (?
\e$(5!`
\e(B 0 (mr . mr)) ; (tc . bc)
726 (?
\e$(5!a
\e(B 0 (mr . mr))
727 (?
\e$(5!b
\e(B 0 (mr . mr))
728 (?
\e$(5!c
\e(B 0 (mr . mr))
733 (?
\e$(5!h
\e(B 0 (br . tr))
734 (?
\e$(5!i
\e(B 0 (br . tr))
835 (?
\e$(5"p
\e(B 10 (mr . mr))
836 (?
\e$(5"q
\e(B 0 (br . br))
837 (?
\e$(5"r
\e(B 0 (br . tr))
892 (?
\e$(5#K
\e(B 0 (br . tr))
893 (?
\e$(5#L
\e(B 0 (br . tr))
894 (?
\e$(5#M
\e(B 0 (br . tr))
1040 ;; Determine composition priority and rule of the array of Glyphs.
1041 ;; Sort the glyphs with their priority.
1043 (defun devanagari-reorder-glyphs-for-composition (glyph-alist)
1045 (ordered-glyphs '()))
1046 (while (< pos (length glyph-alist))
1047 (let* ((glyph (aref glyph-alist pos)))
1049 (setq ordered-glyphs
1050 (append ordered-glyphs (list (assq glyph devanagari-composition-rules))))))
1051 (sort ordered-glyphs '(lambda (x y) (< (car (cdr x)) (car (cdr y)))))))
1053 ;;(devanagari-compose-to-one-glyph "
\e$(5"5!X![
\e(B") => "
\e2
\e$(6!XP"5@![
\e1
\e(B"
1055 (defun devanagari-compose-to-one-glyph (devanagari-string)
1056 (let* ((o-glyph-list (devanagari-reorder-glyphs-for-composition
1057 (string-to-vector devanagari-string)))
1058 ;; List of glyphs to be composed.
1059 (cmp-glyph-list (list (car (car o-glyph-list))))
1060 (o-glyph-list (cdr o-glyph-list)))
1062 (let* ((o-glyph (car o-glyph-list))
1063 (glyph (if (< 2 (length o-glyph))
1064 ;; default composition
1065 (list (car (cdr (cdr o-glyph))) (car o-glyph))
1066 ;; composition with a specified rule
1067 (list '(mr . ml) (car o-glyph)))))
1068 (setq o-glyph-list (cdr o-glyph-list))
1069 (setq cmp-glyph-list (append cmp-glyph-list glyph))))
1070 ;; Before applying compose-chars, convert glyphs to
1071 ;; 1-column width if possible.
1072 (setq cmp-glyph-list (devanagari-wide-to-narrow cmp-glyph-list))
1073 (if (= (length cmp-glyph-list) 1) (char-to-string (car cmp-glyph-list))
1074 (apply 'compose-chars cmp-glyph-list))))
1076 ;; Utility function for Phase 2.5
1077 ;; Check whether given glyph is a Devanagari vertical modifier or not.
1078 ;; If it is a vertical modifier, whether it should be 1-column shape or not
1079 ;; depends on previous non-vertical modifier.
1080 ; return nil if it is not vertical modifier.
1081 (defun devanagari-vertical-modifier-p (glyph)
1082 (string-match (char-to-string glyph)
1083 "[
\e$(5!]!^!_!`!a!b!c!h!i"p"q"r#K#L#M
\e(B]"))
1085 (defun devanagari-non-vertical-modifier-p (glyph)
1086 (string-match (char-to-string glyph)
1087 "[
\e$(5!Z![!\!d!e!f!g
\e(B]"))
1091 ;; Phase 2.5 Convert Appropriate Character to 1-column shape.
1093 ;; This is temporary and should be removed out when Emacs supports
1094 ;; variable width characters.
1096 ;; This will convert the composing glyphs (2 column glyphs)
1097 ;; to narrow (1 column) glyphs if they exist.
1099 ;; devanagari-wide-to-narrow-old converts glyphs simply.
1100 ;; devanagari-wide-to-narrow takes care of upper/lower apply-glyphs
1101 ;; with 2 column base-glyph.
1103 ;; Execution Examples
1104 ;;(devanagari-wide-to-narrow '(?
\e$(5!3
\e(B (ml . ml) ?
\e$(5!a
\e(B))
1105 ;;(devanagari-wide-to-narrow '(?
\e$(5!F
\e(B (ml . ml) ?
\e$(5!a
\e(B))
1107 ;(defun devanagari-wide-to-narrow (src-list)
1108 ; (if (null src-list) '()
1110 ; (if (and (numberp (car src-list))
1111 ; (cdr (assq (car src-list) devanagari-1-column-char)))
1112 ; (cdr (assq (car src-list) devanagari-1-column-char))
1114 ; (devanagari-wide-to-narrow (cdr src-list)))))
1116 (defun devanagari-wide-to-narrow (src-list)
1117 (devanagari-wide-to-narrow-iter src-list t))
1119 (defun devanagari-wide-to-narrow-iter (src-list wide-p)
1120 (let ((glyph (car src-list)))
1121 (cond ((null src-list) '())
1123 ((not (numberp glyph))
1124 (cons glyph (devanagari-wide-to-narrow-iter (cdr src-list) wide-p)))
1125 ; vertical modifier glyph
1126 ((devanagari-vertical-modifier-p glyph)
1127 (if (and (null wide-p)
1128 (cdr (assq glyph devanagari-1-column-char)))
1129 (cons (cdr (assq glyph devanagari-1-column-char))
1130 (devanagari-wide-to-narrow-iter (cdr src-list) nil))
1132 (devanagari-wide-to-narrow-iter (cdr src-list) t))))
1133 ; nonvertical modifier glyph
1134 ((devanagari-non-vertical-modifier-p glyph)
1135 (if (cdr (assq glyph devanagari-1-column-char))
1136 (cons (cdr (assq glyph devanagari-1-column-char))
1137 (devanagari-wide-to-narrow-iter (cdr src-list) wide-p))
1139 (devanagari-wide-to-narrow-iter (cdr src-list) wide-p))))
1142 (if (cdr (assq glyph devanagari-1-column-char))
1143 (cons (cdr (assq glyph devanagari-1-column-char))
1144 (devanagari-wide-to-narrow-iter (cdr src-list) nil))
1146 (devanagari-wide-to-narrow-iter (cdr src-list) t)))))))
1154 ;; Decomposition of composite font.
1157 (defun devanagari-normalize-narrow-glyph (charlist)
1158 (let ((wide-char (car (rassoc (car charlist) devanagari-1-column-char))))
1159 (if (null charlist) nil
1160 (cons (if (null wide-char) (car charlist) wide-char)
1161 (devanagari-normalize-narrow-glyph (cdr charlist))))))
1163 (defvar devanagari-decomposition-rules
1169 (defun devanagari-reorder-glyphs-for-decomposition (glyphlist)
1170 "This function re-orders glyph list for decomposition."
1173 (let ((xx (assoc x devanagari-decomposition-rules))
1174 (yy (assoc y devanagari-decomposition-rules)))
1175 (if (null xx) (setq xx 0))
1176 (if (null yy) (setq yy 0))
1179 (defun devanagari-decompose-char (glyph)
1180 "This function decomposes one Devanagari composite glyph to
1181 basic Devanagari characters as a string."
1183 (if (eq (car (split-char glyph)) 'composition)
1184 (string-to-list (decompose-composite-char glyph))
1186 (setq glyphlist (devanagari-normalize-narrow-glyph glyphlist))
1187 (setq glyphlist (devanagari-reorder-glyphs-for-decomposition glyphlist))
1188 (string-conversion-by-rule
1189 (mapconcat 'char-to-string glyphlist "") 'glyph-to-char)))
1192 (defun devanagari-decompose-string (str)
1193 "This function Decomposes Devanagari glyph string to
1194 basic Devanagari character string."
1195 (let ((src str) (dst ""))
1196 (while (not (equal src ""))
1197 (let* ((char (string-to-char src))
1198 (clen (char-bytes char)))
1199 (setq src (substring src clen))
1200 (setq dst (concat dst
1201 (devanagari-decompose-char char)))))
1205 (defun devanagari-decompose-region (from to)
1208 (narrow-to-region from to)
1209 (goto-char (point-min))
1210 (while (re-search-forward "." nil t)
1211 (let* ((match-b (match-beginning 0)) (match-e (match-end 0))
1212 (decmps (devanagari-decompose-string (buffer-substring match-b match-e))))
1221 (defun devanagari-compose-string (str &rest langs)
1222 (let ((len (length str))
1223 (src (devanagari-decompose-string str)) (dst "") rest match-b match-e)
1224 (while (string-match devanagari-composite-glyph-unit src)
1225 (setq match-b (match-beginning 0) match-e (match-end 0))
1228 (substring src 0 match-b)
1229 (devanagari-compose-to-one-glyph
1231 'char-to-glyph-devanagari
1232 (cons (substring src match-b match-e)
1234 (setq src (substring src match-e)))
1235 (setq dst (concat dst src))
1239 (defun devanagari-compose-region (from to &rest langs)
1242 (narrow-to-region from to)
1243 (goto-char (point-min))
1244 (while (re-search-forward devanagari-composite-glyph-unit nil t)
1245 (let* ((match-b (match-beginning 0)) (match-e (match-end 0))
1246 (cmps (devanagari-compose-to-one-glyph
1248 'char-to-glyph-devanagari
1249 (cons (buffer-substring match-b match-e)
1251 (delete-region match-b match-e)
1254 ;; For pre-write and post-read conversion
1257 (defun devanagari-compose-from-is13194-region (from to)
1258 "Compose IS 13194 characters in the region to Devanagari characters."
1262 (narrow-to-region from to)
1263 (indian-to-devanagari-region (point-min) (point-max))
1264 (devanagari-compose-region (point-min) (point-max))
1265 (- (point-max) (point-min)))))
1268 (defun in-is13194-devanagari-post-read-conversion (len)
1270 (buffer-modified-p (buffer-modified-p)))
1272 (devanagari-compose-from-is13194-region pos (+ pos len))
1273 (set-buffer-modified-p buffer-modified-p))))
1276 (defun devanagari-decompose-to-is13194-region (from to)
1277 "Decompose Devanagari characters in the region to IS 13194 characters."
1280 (narrow-to-region from to)
1281 (devanagari-decompose-region (point-min) (point-max))
1282 (devanagari-to-indian-region (point-min) (point-max))))
1285 (defun in-is13194-devanagari-pre-write-conversion (from to)
1286 (let ((old-buf (current-buffer))
1287 (work-buf (get-buffer-create " *devanagari-work*")))
1288 (set-buffer work-buf)
1292 (insert-buffer-substring old-buf from to))
1293 (devanagari-decompose-to-is13194-region (point-min) (point-max))
1294 ;; Should return nil as annotations.
1297 ;; For input/output of ITRANS
1300 (defun devanagari-encode-itrans-region (from to)
1303 (narrow-to-region from to)
1304 (devanagari-decompose-to-is13194-region (point-min) (point-max))
1305 (indian-encode-itrans-region (point-min) (point-max))))
1308 (defun devanagari-decode-itrans-region (from to)
1311 (narrow-to-region from to)
1312 (indian-decode-itrans-region (point-min) (point-max))
1313 (devanagari-compose-from-is13194-region (point-min) (point-max))))
1318 (provide 'devan-util)
1320 ;;; devan-util.el end here