1 (require 'cwiki-common)
3 (setq file-name-coding-system 'utf-8-jp)
5 (defun www-glyph-big5-to-ucs-pua (code-point)
6 (let ((H (lsh code-point -8))
7 (L (logand code-point #xff)))
8 (if (<= #x8140 code-point)
9 (if (<= code-point #x8DFE)
10 (+ #xEEB8 (* 157 (- H 0x81))
14 (if (<= #x8E40 code-point)
15 (if (<= code-point #xA0FE)
16 (+ #xE311 (* 157 (- H #x8e))
20 (if (<= #xC6A1 code-point)
21 (if (<= code-point #xC8FE)
22 (+ #xF672 (* 157 (- H #xC6))
26 (if (<= #xFA40 code-point)
27 (if (<= code-point #xFEFE)
28 (+ #xE000 (* 157 (- H #xFA))
31 (- L #x62)))))))))))))
33 (defun www-glyph-generate-png (ccs code-point &optional size)
36 (let (png-file dir font char ret plain)
38 ((eq ccs '=ucs@JP/hanazono)
40 (if (<= code-point 65535)
41 "/usr/local/share/fonts/TrueType/Hanazono/HanaMinA.ttf"
42 "/usr/local/share/fonts/TrueType/Hanazono/HanaMinB.ttf"))
43 (setq char (decode-char '=ucs code-point)
44 png-file (format "/opt/chisewiki/glyphs/%d/Hanazono/u%04X.png"
48 (setq char (decode-char '=gt code-point)
49 png-file (format "/opt/chisewiki/glyphs/%d/GT/%05d.png"
52 (while (and (<= plain 11)
54 (setq ret (encode-char
56 (intern (format "=gt-pj-%d" plain))))))
57 (setq plain (1+ plain)))
59 "/usr/local/share/fonts/TrueType/GT/gt2000%02d.ttf"
61 char (decode-char '=jis-x0208@1990 ret))
62 (when (setq ret (encode-char char '=ucs@jis/1990))
63 (setq char (decode-char '=ucs ret)))
66 (setq char (decode-char '=gt-k code-point)
67 png-file (format "/opt/chisewiki/glyphs/%d/GT-K/%05d.png"
70 (while (and (<= plain 11)
72 (setq ret (encode-char
74 (intern (format "=gt-pj-k%d" plain))))))
75 (setq plain (1+ plain)))
77 "/usr/local/share/fonts/TrueType/GT/gt2000k%d.ttf"
79 char (decode-char '=jis-x0208@1990 ret))
80 (when (setq ret (encode-char char '=ucs@jis/1990))
81 (setq char (decode-char '=ucs ret)))
84 (setq font "/usr/local/share/fonts/TrueType/Arphic/bsmi00lp.ttf"
85 char (decode-char '=big5 code-point)
86 png-file (format "/opt/chisewiki/glyphs/%d/Big5/%04X.png"
88 (when (setq ret (or (encode-char char '=ucs@big5)
90 (setq char (decode-char '=ucs ret)))
93 (setq font "/usr/local/share/fonts/TrueType/CDP/Cdpeudc.ttf"
94 char (or (decode-char '=big5-pua code-point)
96 (www-glyph-big5-to-ucs-pua code-point)))
97 png-file (format "/opt/chisewiki/glyphs/%d/CDP/%04X.png"
100 ((eq ccs '=hanziku-1)
101 (setq font "/usr/local/share/fonts/TrueType/Hanziku/hzk1u.ttf"
102 char (or (decode-char '=big5-pua code-point)
104 (www-glyph-big5-to-ucs-pua code-point)))
105 png-file (format "/opt/chisewiki/glyphs/%d/Hanziku-01/%04X.png"
108 ((eq ccs '=hanziku-2)
109 (setq font "/usr/local/share/fonts/TrueType/Hanziku/hzk2u.ttf"
110 char (or (decode-char '=big5-pua code-point)
112 (www-glyph-big5-to-ucs-pua code-point)))
113 png-file (format "/opt/chisewiki/glyphs/%d/Hanziku-02/%04X.png"
116 ((eq ccs '=hanziku-3)
117 (setq font "/usr/local/share/fonts/TrueType/Hanziku/hzk3u.ttf"
118 char (or (decode-char '=big5-pua code-point)
120 (www-glyph-big5-to-ucs-pua code-point)))
121 png-file (format "/opt/chisewiki/glyphs/%d/Hanziku-03/%04X.png"
124 ((eq ccs '=hanziku-4)
125 (setq font "/usr/local/share/fonts/TrueType/Hanziku/hzk4u.ttf"
126 char (or (decode-char '=big5-pua code-point)
128 (www-glyph-big5-to-ucs-pua code-point)))
129 png-file (format "/opt/chisewiki/glyphs/%d/Hanziku-04/%04X.png"
132 ((eq ccs '=hanziku-5)
133 (setq font "/usr/local/share/fonts/TrueType/Hanziku/hzk5u.ttf"
134 char (or (decode-char '=big5-pua code-point)
136 (www-glyph-big5-to-ucs-pua code-point)))
137 png-file (format "/opt/chisewiki/glyphs/%d/Hanziku-05/%04X.png"
140 ((eq ccs '=hanziku-6)
141 (setq font "/usr/local/share/fonts/TrueType/Hanziku/hzk6u.ttf"
142 char (or (decode-char '=big5-pua code-point)
144 (www-glyph-big5-to-ucs-pua code-point)))
145 png-file (format "/opt/chisewiki/glyphs/%d/Hanziku-06/%04X.png"
148 ((eq ccs '=hanziku-7)
149 (setq font "/usr/local/share/fonts/TrueType/Hanziku/hzk7u.ttf"
150 char (or (decode-char '=big5-pua code-point)
152 (www-glyph-big5-to-ucs-pua code-point)))
153 png-file (format "/opt/chisewiki/glyphs/%d/Hanziku-07/%04X.png"
156 ((eq ccs '=hanziku-8)
157 (setq font "/usr/local/share/fonts/TrueType/Hanziku/hzk8u.ttf"
158 char (or (decode-char '=big5-pua code-point)
160 (www-glyph-big5-to-ucs-pua code-point)))
161 png-file (format "/opt/chisewiki/glyphs/%d/Hanziku-08/%04X.png"
164 ((eq ccs '=hanziku-9)
165 (setq font "/usr/local/share/fonts/TrueType/Hanziku/hzk9u.ttf"
166 char (or (decode-char '=big5-pua code-point)
168 (www-glyph-big5-to-ucs-pua code-point)))
169 png-file (format "/opt/chisewiki/glyphs/%d/Hanziku-09/%04X.png"
172 ((eq ccs '=hanziku-10)
173 (setq font "/usr/local/share/fonts/TrueType/Hanziku/hzkau.ttf"
174 char (or (decode-char '=big5-pua code-point)
176 (www-glyph-big5-to-ucs-pua code-point)))
177 png-file (format "/opt/chisewiki/glyphs/%d/Hanziku-10/%04X.png"
180 ((eq ccs '=hanziku-11)
181 (setq font "/usr/local/share/fonts/TrueType/Hanziku/hzkbu.ttf"
182 char (or (decode-char '=big5-pua code-point)
184 (www-glyph-big5-to-ucs-pua code-point)))
185 png-file (format "/opt/chisewiki/glyphs/%d/Hanziku-11/%04X.png"
188 ((eq ccs '=hanziku-12)
189 (setq font "/usr/local/share/fonts/TrueType/Hanziku/hzkcu.ttf"
190 char (or (decode-char '=big5-pua code-point)
192 (www-glyph-big5-to-ucs-pua code-point)))
193 png-file (format "/opt/chisewiki/glyphs/%d/Hanziku-12/%04X.png"
196 ((eq ccs '=ruimoku-v6)
197 (setq font "/usr/local/share/fonts/TrueType/Zinbun/rui6-eudc.ttf"
198 char (decode-char '=ucs code-point)
199 png-file (format "/opt/chisewiki/glyphs/%d/Ruimoku-v6/%04X.png"
204 "convert" nil nil nil
205 "-size" (format "%dx%d" size size)
207 (concat "label:" (char-to-string char))
209 (setq dir (file-name-directory png-file))
210 (unless (file-exists-p dir)
211 (make-directory dir t))
216 (defun www-glyph-display-png (char-rep &optional size)
218 (setq size (string-to-int size)))
221 ((string-match "^hana-JU\\+\\([0-9A-F]+\\)" char-rep)
222 (www-glyph-generate-png
224 (string-to-int (match-string 1 char-rep) 16)
227 ((string-match "^GT-\\([0-9]+\\)" char-rep)
228 (www-glyph-generate-png
230 (string-to-int (match-string 1 char-rep))
233 ((string-match "^GT-K\\([0-9]+\\)" char-rep)
234 (www-glyph-generate-png
236 (string-to-int (match-string 1 char-rep))
239 ((string-match "^B-\\([0-9A-F]+\\)" char-rep)
240 (www-glyph-generate-png
242 (string-to-int (match-string 1 char-rep) 16)
245 ((string-match "^CDP-\\([0-9A-F]+\\)" char-rep)
246 (www-glyph-generate-png
248 (string-to-int (match-string 1 char-rep) 16)
252 "^HZK\\(0[1-9]\\|1[0-2]\\)-\\([0-9A-F]+\\)"
254 (www-glyph-generate-png
255 (intern (format "=hanziku-%d"
256 (string-to-int (match-string 1 char-rep))))
257 (string-to-int (match-string 2 char-rep) 16)
260 ((string-match "^RUI6-\\([0-9A-F]+\\)" char-rep)
261 (www-glyph-generate-png
263 (string-to-int (match-string 1 char-rep) 16)
268 (princ (format "Content-Type: %s"
273 "-b" "--mime" png-file)
275 (let ((coding-system-for-read 'binary)
276 (coding-system-for-write 'binary))
277 (insert-file-contents-literally png-file))
278 (buffer-string)))))))
280 (defun www-batch-display-glyph ()
281 (setq terminal-coding-system 'binary)
283 (let* ((target (pop command-line-args-left))
284 ;; (user (pop command-line-args-left))
285 ;; (accept-language (pop command-line-args-left))
288 ;; (car (split-string
289 ;; (car (split-string
290 ;; (car (split-string accept-language ","))
297 (mapcar (lambda (cell)
298 (if (string-match "=" cell)
302 (substring cell 0 (match-beginning 0))
304 (substring cell (match-end 0)))
305 (list (decode-uri-string cell 'utf-8-mcs-er))))
306 (split-string target "&")))
307 (setq ret (car target))
308 (cond ((eq (car ret) 'char)
309 (www-glyph-display-png
311 (cdr (assq 'size target)))
316 (princ (format "%S" err)))