(U-00027B32): Use "𡲬" instead of "⿸尸⿱氺出".
[chise/ids.git] / www / www-ids-find.el
index f3d0c1d..5907fb4 100644 (file)
@@ -1,4 +1,7 @@
 (require 'ids-find)
+(require 'cwiki-common)
+
+(setq www-format-char-img-style "vertical-align:middle;")
 
 (defun decode-url-string (string &optional coding-system)
   (if (> (length string) 0)
@@ -15,7 +18,7 @@
         (concat dest (substring string i))
         coding-system))))
 
-(defconst www-ids-find-version "0.24.2")
+(defconst www-ids-find-version "0.99.1")
 
 (defvar www-ids-find-ideographic-products-file-name
   (expand-file-name "ideographic-products"
                      "character"
                      chise-system-db-directory))))
 
+(defvar www-ids-find-char-viewer-url
+  "/est/view/character/")
+
 (defvar www-ids-find-chise-link-map-url-prefix
-  "http://kamichi.jp/chise_linkmap/map.cgi?code=")
+  "http://fonts.jp/chise_linkmap/map.cgi?code=")
 
 (defvar www-ids-find-tang-chars-file-name
   "~tomo/projects/chise/ids/www/tang-chars.udd")
 
 (defun www-ids-find-format-char (c &optional code-desc)
-  (let ((str (encode-coding-string (format "%c" c) 'utf-8-er))
-       plane code)
-    (princ
-     (with-temp-buffer
-       (cond
-       ((string-match "&CB\\([0-9]+\\);" str)
-        (setq code (string-to-int (match-string 1 str)))
-        (insert "<a href=\"/char-desc?char=")
-        (insert str)
-        (insert (format "\"><img alt=\"CB%05d\" src=\"/glyphs/cb-gaiji/%02d/CB%05d.gif\">\n"
-                        code (/ code 1000) code))
-        (when code-desc
-          (insert (format "CB%05d</a>" code)))
-        )
-       ((string-match "&JC3-\\([0-9A-F]+\\);" str)
-        (setq code (string-to-int (match-string 1 str) 16))
-        (insert "<a href=\"/char-desc?char=")
-        (insert str)
-        (insert (format "\"><img alt=\"JC3-%04X\" src=\"http://kanji.zinbun.kyoto-u.ac.jp/db/CHINA3/Gaiji/%04x.gif\">\n"
-                        code code))
-        (when code-desc
-          (insert (format "JC3-%04X</a>" code)))
-        )
-       ((string-match "&J\\(78\\|83\\|90\\|SP\\)-\\([0-9A-F]+\\);" str)
-        (setq plane (match-string 1 str)
-              code (string-to-int (match-string 2 str) 16))
-        (insert "<a href=\"/char-desc?char=")
-        (insert str)
-        (insert (format "\"><img alt=\"J%s-%04X\" src=\"/glyphs/JIS-%s/%02d-%02d.gif\">\n"
-                        plane code plane
-                        (- (lsh code -8) 32)
-                        (- (logand code 255) 32)))
-        (when code-desc
-          (insert (format "J%s-%04X</a>" plane code)))
-        )
-       ((string-match "&G\\([01]\\)-\\([0-9A-F]+\\);" str)
-        (setq plane (string-to-int (match-string 1 str))
-              code (string-to-int (match-string 2 str) 16))
-        (insert "<a href=\"/char-desc?char=")
-        (insert str)
-        (insert (format "\"><img alt=\"G%d-%04X\" src=\"/glyphs/GB%d/%02d-%02d.gif\">\n"
-                        plane code plane
-                        (- (lsh code -8) 32)
-                        (- (logand code 255) 32)))
-        (when code-desc
-          (insert (format "G%d-%04X</a>" plane code)))
-        )
-       ((string-match "&C\\([1-7]\\)-\\([0-9A-F]+\\);" str)
-        (setq plane (string-to-int (match-string 1 str))
-              code (string-to-int (match-string 2 str) 16))
-        (insert "<a href=\"/char-desc?char=")
-        (insert str)
-        (insert (format "\"><img alt=\"C%d-%04X\" src=\"/glyphs/CNS%d/%04X.gif\">\n"
-                        plane code plane code))
-        (when code-desc
-          (insert (format "C%d-%04X</a>" plane code)))
-        )
-       ((string-match "&ZOB-\\([0-9]+\\);" str)
-        (setq code (string-to-int (match-string 1 str)))
-        (insert "<a href=\"/char-desc?char=")
-        (insert str)
-        (insert (format "\"><img alt=\"ZOB-%04d\" src=\"/glyphs/ZOB-1968/%04d.png\">\n"
-                        code code))
-        (when code-desc
-          (insert (format "ZOB-%04d</a>" code)))
-        )
-       (t
-        (insert "<a href=\"/char-desc?char=")
-         ;; (insert str)
-        (insert
-         (mapconcat (lambda (c)
-                      (if (<= (char-int c) #x7F)
-                          (char-to-string c)
-                        (format "%%%02X" c)))
-                    str ""))
-        (insert "\">")
-        (insert str)
-        (insert "</a>")
-        ))
-       (goto-char (point-min))
-       (while (search-forward "&" nil t)
-         (replace-match "&amp;" t 'literal))
-       (buffer-string)))))
+  (princ
+   (format "<a href=\"%s%s\">%s</a>"
+          www-ids-find-char-viewer-url
+          (www-uri-encode-object c)
+          (www-format-encode-string (char-to-string c))))
+  ;; (let ((str (encode-coding-string (format "%c" c) 'utf-8-er))
+  ;;       plane code)
+  ;;   (princ
+  ;;    (with-temp-buffer
+  ;;      (cond
+  ;;       ((string-match "&CB\\([0-9]+\\);" str)
+  ;;        (setq code (string-to-int (match-string 1 str)))
+  ;;        (insert (format "<a href=\"%s"
+  ;;                        www-ids-find-char-viewer-url))
+  ;;        (insert str)
+  ;;        (insert (format "\"><img alt=\"CB%05d\" src=\"/glyphs/cb-gaiji/%02d/CB%05d.gif\">\n"
+  ;;                        code (/ code 1000) code))
+  ;;        (when code-desc
+  ;;          (insert (format "CB%05d</a>" code)))
+  ;;        )
+  ;;       ((string-match "&JC3-\\([0-9A-F]+\\);" str)
+  ;;        (setq code (string-to-int (match-string 1 str) 16))
+  ;;        (insert (format "<a href=\"%s"
+  ;;                        www-ids-find-char-viewer-url))
+  ;;        (insert str)
+  ;;        (insert (format "\"><img alt=\"JC3-%04X\" src=\"http://kanji.zinbun.kyoto-u.ac.jp/db/CHINA3/Gaiji/%04x.gif\">\n"
+  ;;                        code code))
+  ;;        (when code-desc
+  ;;          (insert (format "JC3-%04X</a>" code)))
+  ;;        )
+  ;;       ((string-match "&J\\(78\\|83\\|90\\|SP\\)-\\([0-9A-F]+\\);" str)
+  ;;        (setq plane (match-string 1 str)
+  ;;              code (string-to-int (match-string 2 str) 16))
+  ;;        (insert (format "<a href=\"%s"
+  ;;                        www-ids-find-char-viewer-url))
+  ;;        (insert str)
+  ;;        (insert (format "\"><img alt=\"J%s-%04X\" src=\"/glyphs/JIS-%s/%02d-%02d.gif\">\n"
+  ;;                        plane code plane
+  ;;                        (- (lsh code -8) 32)
+  ;;                        (- (logand code 255) 32)))
+  ;;        (when code-desc
+  ;;          (insert (format "J%s-%04X</a>" plane code)))
+  ;;        )
+  ;;       ((string-match "&G\\([01]\\)-\\([0-9A-F]+\\);" str)
+  ;;        (setq plane (string-to-int (match-string 1 str))
+  ;;              code (string-to-int (match-string 2 str) 16))
+  ;;        (insert (format "<a href=\"%s"
+  ;;                        www-ids-find-char-viewer-url))
+  ;;        (insert str)
+  ;;        (insert (format "\"><img alt=\"G%d-%04X\" src=\"/glyphs/GB%d/%02d-%02d.gif\">\n"
+  ;;                        plane code plane
+  ;;                        (- (lsh code -8) 32)
+  ;;                        (- (logand code 255) 32)))
+  ;;        (when code-desc
+  ;;          (insert (format "G%d-%04X</a>" plane code)))
+  ;;        )
+  ;;       ((string-match "&C\\([1-7]\\)-\\([0-9A-F]+\\);" str)
+  ;;        (setq plane (string-to-int (match-string 1 str))
+  ;;              code (string-to-int (match-string 2 str) 16))
+  ;;        (insert (format "<a href=\"%s"
+  ;;                        www-ids-find-char-viewer-url))
+  ;;        (insert str)
+  ;;        (insert (format "\"><img alt=\"C%d-%04X\" src=\"/glyphs/CNS%d/%04X.gif\">\n"
+  ;;                        plane code plane code))
+  ;;        (when code-desc
+  ;;          (insert (format "C%d-%04X</a>" plane code)))
+  ;;        )
+  ;;       ((string-match "&ZOB-\\([0-9]+\\);" str)
+  ;;        (setq code (string-to-int (match-string 1 str)))
+  ;;        (insert (format "<a href=\"%s"
+  ;;                        www-ids-find-char-viewer-url))
+  ;;        (insert str)
+  ;;        (insert (format "\"><img alt=\"ZOB-%04d\" src=\"/glyphs/ZOB-1968/%04d.png\">\n"
+  ;;                        code code))
+  ;;        (when code-desc
+  ;;          (insert (format "ZOB-%04d</a>" code)))
+  ;;        )
+  ;;       (t
+  ;;        (insert (format "<a href=\"%s"
+  ;;                        www-ids-find-char-viewer-url))
+  ;;        ;; (insert str)
+  ;;        (insert
+  ;;         (mapconcat (lambda (c)
+  ;;                      (if (<= (char-int c) #x7F)
+  ;;                          (char-to-string c)
+  ;;                        (format "%%%02X" c)))
+  ;;                    str ""))
+  ;;        (insert "\">")
+  ;;        (insert str)
+  ;;        (insert "</a>")
+  ;;        ))
+  ;;      (goto-char (point-min))
+  ;;      (while (search-forward "&" nil t)
+  ;;        (replace-match "&amp;" t 'literal))
+  ;;      (buffer-string))))
+  )
   
 (defun www-ids-find-format-line (c is)
   (let (ucs len i ids)
+    (princ "<span class=\"entry\">")
     (www-ids-find-format-char c 'code-desc)
+    (princ "</span>")
     (princ
      (or (if (setq ucs (or (char-ucs c)
                           (encode-char c 'ucs)))
       (setq ids (ideographic-structure-to-ids is))
       (setq i 0
            len (length ids))
+      (princ "<span class=\"ids\">")      
       (while (< i len)
        (www-ids-find-format-char (aref ids i))
-       (setq i (1+ i))))
+       (setq i (1+ i)))
+      (princ "</span>"))
     (when (and ucs
               (with-current-buffer
                   (find-file-noselect
       (princ (encode-coding-string "\e$B"M\e(B[\e$BEbBeBsK\\e(B]</a>" 'utf-8-jp-er)))
     (princ "<br>\n")))
 
-(defun www-ids-insert-chars-including-components (components
-                                                 &optional ignored-chars)
-  (let ((products (copy-list (ideographic-products-find components)))
-       is as bs len ignore-children)
+(defun www-ids-insert-chars-including-components* (components
+                                                  &optional ignored-chars products)
+  (unless products
+    (setq products (ideograph-find-products components ignored-chars)))
+  (let (is as bs len)
     (setq len (length products))
+    (princ "<ul>\n")
     (dolist (c (cond
-               ((> len 8192)
-                (setq ignore-children t)
-                products)
-               ((> len 4096)
-                (sort products
+               ((>= len 1024)
+                (sort (copy-list products)
                       (lambda (a b)
                         (< (char-int a)(char-int b))))
                 )
-               ((> len 512)
-                (sort products
+               ((>= len 512)
+                (sort (copy-list products)
                       (lambda (a b)
                         (if (setq as (char-total-strokes a))
                             (if (setq bs (char-total-strokes b))
                           (< (char-int a)(char-int b)))))
                 )
                (t
-                (sort products
+                (sort (copy-list products)
                       (lambda (a b)
                         (if (setq as (char-total-strokes a))
                             (if (setq bs (char-total-strokes b))
        (setq is (char-feature c 'ideographic-structure))
        (princ "<li>")
        (www-ids-find-format-line c is)
-       (unless ignore-children
-         (princ "<ul>\n")
-         (setq ignored-chars
-               (www-ids-insert-chars-including-components
-                (char-to-string c)
-                (cons c ignored-chars)))
-         (princ "</ul>\n"))
+       (setq ignored-chars
+             (www-ids-insert-chars-including-components*
+              (char-to-string c) (cons c ignored-chars)))
        )
-      ))
+      )
+    (princ "</ul>\n")
+    )
+  ignored-chars)
+
+(defun www-ids-insert-chars-including-components (components
+                                                 &optional ignored-chars)
+  (let ((products (ideograph-find-products components ignored-chars))
+       is as bs len ignore-children)
+    (setq len (length products))
+    (when (>= len 1024)
+      (setq ignore-children t)
+      (princ
+       (encode-coding-string
+       "<p>\e$B7k2L$,B?$9$.$k$?$a!":F5"E*8!:w$r>JN,$7$^$7$?!#\e(B</p>"
+       'utf-8-jp-er)))
+    (if (>= len 2048)
+       (dolist (c products)
+         (www-ids-find-format-char c))
+      (setq ignored-chars
+           (nreverse
+            (www-ids-insert-chars-including-components* components ignored-chars products)))
+      (dolist (c ignored-chars)
+       (dolist (vc (char-component-variants c))
+         (unless (memq vc ignored-chars)
+           (when (setq is (get-char-attribute vc 'ideographic-structure))
+             (princ "<li>")
+             (www-ids-find-format-line vc is)
+             (setq ignored-chars
+                   (www-ids-insert-chars-including-components*
+                    (char-to-string vc)
+                    (cons vc ignored-chars)))))))
+      (setq products (ideograph-find-products-with-variants components ignored-chars))
+      (setq len (length products))
+      (when (>= len 512)
+       (setq ignore-children t)
+       (princ
+        (encode-coding-string
+         "<p>\e$B7k2L$,B?$9$.$k$?$a!"4XO";z$N:F5"E*8!:w$r>JN,$7$^$7$?!#\e(B</p>"
+         'utf-8-jp-er)))
+      (if (>= len 1024)
+         (dolist (c products)
+           (www-ids-find-format-char c))
+       (dolist (c (sort (copy-tree products)
+                        (lambda (a b)
+                          (if (setq as (char-total-strokes a))
+                              (if (setq bs (char-total-strokes b))
+                                  (if (= as bs)
+                                      (ideograph-char< a b)
+                                    (< as bs))
+                                t)
+                            (ideograph-char< a b)))))
+         (unless (memq c ignored-chars)
+           (setq is (get-char-attribute c 'ideographic-structure))
+           (princ "<li>")
+           (www-ids-find-format-line c is)
+           (unless ignore-children
+             (setq ignored-chars
+                   (www-ids-insert-chars-including-components*
+                    (char-to-string c)
+                    (cons c ignored-chars))))
+           ))
+       ))
+    )
   ignored-chars)
 
 (defun www-batch-ids-find ()
             \"http://www.w3.org/TR/html4/loose.dtd\">
 <html lang=\"ja\">
 <head>
+<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">
 <title>CHISE IDS Find</title>
+<link href=\"/css/bootstrap-4.5.0.min.css\" rel=\"stylesheet\">
+<style type=\"text/css\">
+<!--
+.entry { font-size: 36px; }
+.entry a img { height: 36px; }
+.ids { font-size: 24px; }
+.ids a img { height: 24px; }
+img { vertical-align:middle; }
+a { text-decoration:none; }
+ul { margin: 0 0; }
+li { margin: 0 0 -0.2em; }
+.tooltip {
+    position: relative;
+    display: inline-block;
+}
+.tooltip .tooltiptext {
+    display: none;
+}
+-->
+</style>
 </head>
 
 <body>
 
-<h1>")
+<div class=\"jumbotron jumbotron-fluid mb-0\">
+<h1 class=\"display-4 text-center\">")
     (princ (encode-coding-string "CHISE IDS \e$B4A;z8!:w\e(B" 'utf-8-jp-er))
     (princ "</h1>")
     (princ "
-<p>Version ")
+<p class=\"text-center\">Version ")
     (princ www-ids-find-version)
     (princ (format-time-string
-           " (Last-modified: %Y-%m-%d %H:%M:%S)"
+           " (Last-modified: %Y-%m-%d %H:%M:%S)</p>"
            (nth 5
                 (file-attributes
                  www-ids-find-ideographic-products-file-name))))
     (princ "
-<hr>
-<p>
+</div>
+<div class=\"container mt-0 mw-100 d-inline-block align-top bg-dark\">
+<p />
+<div class=\"input-group mb-3 h3 my-4\">
+<div class=\"input-group-prepend mw-75 ml-3\">
 <form action=\"/ids-find\" method=\"GET\">
+<span class=\"input-group-text\" id=\"basic-addon1\">
 ")
     (princ (encode-coding-string "\e$BItIJJ8;zNs\e(B" 'utf-8-jp-er))
-    (princ " <input type=\"text\" name=\"components\" size=\"30\" maxlength=\"30\" value=\"")
+    (princ "</span>
+</div>
+<input type=\"text\" class=\"form-control\" aria-describedby=\"basic-addon1\" name=\"components\" size=\"30\" maxlength=\"30\" value=\"")
     (if (> (length components) 0)
        (princ (encode-coding-string components 'utf-8-er)))
     (princ "\">
-<input type=\"submit\" value=\"")
+<input class=\"mr-3\" type=\"submit\" value=\"")
     (princ (encode-coding-string "\e$B8!:w3+;O\e(B" 'utf-8-jp-er))
     (princ "\">
 </form>
+</div>
+</div>
 
 ")
     (unless (file-newer-than-file-p
       )
     (cond
      (components
+      (princ "<div class=\"container\">
+")
       ;; (map-char-attribute
       ;;  (lambda (c v)
       ;;    (when (every (lambda (p)
       ;;                  (ideographic-structure-member c is))
       ;;                components)
       ;;     (www-ids-find-format-line c is)))
-      (princ "<ul>\n")
+      ;; (princ "<ul>\n")
       (www-ids-insert-chars-including-components components)
-      (princ "</ul>\n")
+      ;; (princ "</ul>\n")
+      (princ "</div>\n")
       )
      (t
-      (princ (encode-coding-string "<hr>
+      (princ (encode-coding-string "<div class=\"container mt-4\">
+<div class=\"ml-3\">
 <p>
 \e$B;XDj$7$?ItIJ$rA4$F4^$`4A;z$N0lMw$rI=<($7$^$9!#\e(B
+</p>
 <p>
-CHISE \e$B$GMQ$$$i$l$k<BBV;2>H7A<0!JNc!'\e(B&amp;M-00256;\e$B!K$GItIJ$r;XDj$9$k;v$b$G$-$^$9!#\e(B" 'utf-8-jp-er))
+CHISE \e$B$GMQ$$$i$l$k<BBV;2>H7A<0!JNc!'\e(B&amp;M-00256;\e$B!K$GItIJ$r;XDj$9$k;v$b$G$-$^$9!#\e(B
+</p>
+</div>
+" 'utf-8-jp-er))
       (princ (encode-coding-string "
-<p>
+<p  class=\"ml-0\">
 \[Links\]
 <ul>
 <li><a href=\"http://www.shuiren.org/chuden/toyoshi/syoseki/chise_ids.html\"
@@ -342,13 +461,13 @@ href=\"http://www.shuiren.org/\">\e$B?g?MDb\e(B</a>\e$B!K$K$h$k2r@b\e(B
 >\e$B2aN)c7\e(B</a>\e$B!K\e(B
 </ul>
 <ul>
-<li><a href=\"http://cvs.m17n.org/viewcvs/chise/ids/www/www-ids-find.el?view=markup\"
+<li><a href=\"http://git.chise.org/gitweb/?p=chise/ids.git;a=blob;f=www/www-ids-find.el\"
 >www-ids-find.el (source file (Emacs Lisp part))
-<li><a href=\"http://kanji.zinbun.kyoto-u.ac.jp/projects/chise/ids/\"
+<li><a href=\"http://www.chise.org/ids/\"
 >\e$B!V\e(BCHISE \e$B4A;z9=B$>pJs%G!<%?%Y!<%9!W\e(B</a>
 <li><a href=\"http://fonts.jp/chise_linkmap/\"
 >\e$B!V\e(Bchise_linkmap : CHISE \e$B4A;zO"4D?^!W\e(B</a> by \e$B>eCO9(0l$5$s\e(B
-<li><a href=\"http://kanji.zinbun.kyoto-u.ac.jp/projects/chise/\"
+<li><a href=\"http://www.chise.org/\"
 >CHISE Project</a>
 </ul>
 <ul>
@@ -358,21 +477,27 @@ href=\"http://www.shuiren.org/\">\e$B?g?MDb\e(B</a>\e$B!K$K$h$k2r@b\e(B
 >\e$B5~ETBg3X\e(B21\e$B@$5*\e(BCOE\e$B!VEl%"%8%"@$3&$N?MJ8>pJs3X8&5f650i5rE@!W\e(B</a>
 <li><a href=\"http://www.unicode.org/\"
 >Unicode</a>
-</ul>"
+</ul>
+</p>
+</div>
+"
  'utf-8-jp-er))
 
       ))
-    (princ "<hr>")
-    (princ "<p>
-Copyright (C) 2005, 2006, 2007, 2008, 2009 <a href=\"http://kanji.zinbun.kyoto-u.ac.jp/~tomo/\"
->MORIOKA Tomohiko</a>")
+    (princ "<hr>
+<div class=\"container\">
+")
+    (princ "<div class=\"ml-0\">
+Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2015, 2016, 2017, 2020 <a href=\"http://kanji.zinbun.kyoto-u.ac.jp/~tomo/\"
+>MORIOKA Tomohiko</a></div>")
     (princ
      (format
-      "<p>Powered by <a
-href=\"http://kanji.zinbun.kyoto-u.ac.jp/projects/chise/xemacs/\"
->XEmacs CHISE</a> %s."
-      xemacs-chise-version))
+      "<div>Powered by <a
+href=\"http://www.chise.org/xemacs/\"
+>XEmacs CHISE</a> %s.</div>"
+      (encode-coding-string xemacs-chise-version 'utf-8-jp-er)))
     (princ "
+</div>
 </body>
 </html>
 ")))