(get-char-feature-from-domains): New function [moved from
[chise/xemacs-chise.git.1] / lisp / utf-2000 / ideograph-subr.el
1 ;;; ideograph-subr.el --- basic lisp subroutines about Ideographs -*- coding: utf-8-er; -*-
2
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
4 ;;   2007, 2008, 2009, 2010 MORIOKA Tomohiko.
5
6 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
7 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, UCS, Unicode, MULE.
8
9 ;; This file is part of XEmacs CHISE.
10
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.
15
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.
20
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.
25
26 ;;; Code:
27
28 ;;; @ radical code
29 ;;;
30
31 (defconst ideographic-radicals
32   (let ((v (make-vector 215 nil))
33         (i 1))
34     (while (< i 215)
35       (aset v i (decode-char '=ucs (+ #x2EFF i)))
36       (setq i (1+ i)))
37     v))
38
39 ;;;###autoload
40 (defun ideographic-radical (number)
41   "Return character corresponding with Kangxi-radical number."
42   (aref ideographic-radicals number))
43
44
45 ;;; @ char feature
46 ;;;
47
48 (defun get-char-feature-from-domains (char feature domains
49                                            &optional tester arg
50                                            ignore-sisters)
51   (map-char-family
52    (lambda (ch)
53      (let (ret)
54        (catch 'tag
55          (dolist (domain domains)
56            (if (and (or (null tester)
57                         (equal (or (char-feature
58                                     ch (expand-char-feature-name
59                                         tester domain))
60                                    (char-feature ch tester))
61                                arg))
62                     (setq ret (or (char-feature
63                                    ch (expand-char-feature-name
64                                        feature domain))
65                                   (char-feature ch feature))))
66                (throw 'tag ret))))))
67    char ignore-sisters))
68
69 (defun char-ideographic-radical (char &optional radical ignore-sisters)
70   (let (ret)
71     (or (if radical
72             (get-char-feature-from-domains
73              char 'ideographic-radical (cons nil char-db-feature-domains)
74              'ideographic-radical radical ignore-sisters)
75           (get-char-feature-from-domains
76            char 'ideographic-radical (cons nil char-db-feature-domains)
77            ignore-sisters))
78         ;; (catch 'tag
79         ;;   (dolist (domain char-db-feature-domains)
80         ;;     (if (and (setq ret (char-feature
81         ;;                         char
82         ;;                         (intern
83         ;;                          (format "%s@%s"
84         ;;                                  'ideographic-radical domain))))
85         ;;              (or (eq ret radical)
86         ;;                  (null radical)))
87         ;;         (throw 'tag ret))))
88         (catch 'tag
89           (dolist (cell (get-char-attribute char 'ideographic-))
90             (if (and (setq ret (plist-get cell :radical))
91                      (or (eq ret radical)
92                          (null radical)))
93                 (throw 'tag ret))))
94         (get-char-feature-from-domains
95          char 'ideographic-radical (cons nil char-db-feature-domains))
96         ;; (char-feature char 'ideographic-radical)
97         (progn
98           (setq ret
99                 (or (get-char-attribute char 'daikanwa-radical)
100                     (get-char-attribute char 'kangxi-radical)
101                     (get-char-attribute char 'japanese-radical)
102                     (get-char-attribute char 'korean-radical)))
103           (when ret
104             (put-char-attribute char 'ideographic-radical ret)
105             ret)))))
106
107
108 ;;; @ end
109 ;;;
110
111 (provide 'ideograph-subr)
112
113 ;;; ideograph-subr.el ends here