1 ;;; ideograph-subr.el --- basic lisp subroutines about Ideographs -*- coding: utf-8-er; -*-
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010
6 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
7 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, UCS, Unicode, MULE.
9 ;; This file is part of XEmacs CHISE.
11 ;; XEmacs CHISE is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; XEmacs CHISE 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 GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs CHISE; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
34 (defconst ideographic-radicals
35 (let ((v (make-vector 215 nil))
38 (aset v i (decode-char '=ucs (+ #x2EFF i)))
43 (defun ideographic-radical (number)
44 "Return character corresponding with Kangxi-radical number."
45 (aref ideographic-radicals number))
51 (defun get-char-feature-from-domains (char feature domains
58 (dolist (domain domains)
59 (if (and (or (null tester)
60 (equal (or (char-feature
61 ch (expand-char-feature-name
63 (char-feature ch tester))
65 (setq ret (or (char-feature
66 ch (expand-char-feature-name
68 (char-feature ch feature))))
77 (defun char-ideographic-radical (char &optional radical ignore-sisters)
80 (get-char-feature-from-domains
81 char 'ideographic-radical (cons nil char-db-feature-domains)
82 'ideographic-radical radical ignore-sisters)
83 (get-char-feature-from-domains
84 char 'ideographic-radical (cons nil char-db-feature-domains)
87 ;; (dolist (domain char-db-feature-domains)
88 ;; (if (and (setq ret (char-feature
92 ;; 'ideographic-radical domain))))
93 ;; (or (eq ret radical)
95 ;; (throw 'tag ret))))
97 (dolist (cell (get-char-attribute char 'ideographic-))
98 (if (and (setq ret (plist-get cell :radical))
102 (get-char-feature-from-domains
103 char 'ideographic-radical (cons nil char-db-feature-domains))
104 ;; (char-feature char 'ideographic-radical)
107 (or (get-char-attribute char 'daikanwa-radical)
108 (get-char-attribute char 'kangxi-radical)
109 (get-char-attribute char 'japanese-radical)
110 (get-char-attribute char 'korean-radical)))
112 (put-char-attribute char 'ideographic-radical ret)
116 ;;; @@ strokes of non-radical parts
120 (defun char-ideographic-strokes-from-domains (char domains &optional radical)
122 (get-char-feature-from-domains char 'ideographic-strokes domains
123 'ideographic-radical radical)
124 (get-char-feature-from-domains char 'ideographic-strokes domains)))
126 (defvar ideograph-radical-strokes-vector
127 ;;0 1 2 3 4 5 6 7 8 9
128 [nil 1 1 1 1 1 1 2 2 2
147 9 9 9 9 8 9 9 10 10 10
148 10 10 10 10 10 11 11 11 11 11
150 11 12 12 12 12 13 13 13 13 14
154 (defun char-ideographic-strokes (char &optional radical preferred-domains)
157 (dolist (cell (get-char-attribute char 'ideographic-))
158 (if (and (setq ret (plist-get cell :radical))
161 (throw 'tag (plist-get cell :strokes)))))
162 (char-ideographic-strokes-from-domains
163 char (append preferred-domains
165 char-db-feature-domains))
167 (get-char-attribute char 'daikanwa-strokes)
169 (or (get-char-attribute char 'kangxi-strokes)
170 (get-char-attribute char 'japanese-strokes)
171 (get-char-attribute char 'korean-strokes)
172 (let ((r (char-ideographic-radical char))
173 (ts (get-char-attribute char 'total-strokes)))
175 (- ts (aref ideograph-radical-strokes-vector r))))
178 (put-char-attribute char 'ideographic-strokes strokes)
186 (defun char-total-strokes-from-domains (char domains)
189 (dolist (domain domains)
190 (if (setq ret (char-feature
194 'total-strokes domain))))
195 (throw 'tag ret))))))
198 (defun char-total-strokes (char &optional preferred-domains)
199 (or (char-total-strokes-from-domains char preferred-domains)
200 (char-feature char 'total-strokes)
201 (char-total-strokes-from-domains char char-db-feature-domains)))
207 (provide 'ideograph-subr)
209 ;;; ideograph-subr.el ends here