86361
|
1 ;;; nxml-glyph.el --- glyph-handling for nxml-mode
|
|
2
|
87665
|
3 ;; Copyright (C) 2003, 2007, 2008 Free Software Foundation, Inc.
|
86361
|
4
|
|
5 ;; Author: James Clark
|
|
6 ;; Keywords: XML
|
|
7
|
86536
|
8 ;; This file is part of GNU Emacs.
|
|
9
|
|
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
11 ;; it under the terms of the GNU General Public License as published by
|
|
12 ;; the Free Software Foundation; either version 3, or (at your option)
|
|
13 ;; any later version.
|
86361
|
14
|
86536
|
15 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 ;; GNU General Public License for more details.
|
86361
|
19
|
86536
|
20 ;; You should have received a copy of the GNU General Public License
|
|
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
23 ;; Boston, MA 02110-1301, USA.
|
86361
|
24
|
|
25 ;;; Commentary:
|
|
26
|
|
27 ;; The entry point to this file is `nxml-glyph-display-string'.
|
|
28 ;; The current implementation is heuristic due to a lack of
|
|
29 ;; Emacs primitives necessary to implement it properly. The user
|
|
30 ;; can tweak the heuristics using `nxml-glyph-set-hook'.
|
|
31
|
|
32 ;;; Code:
|
|
33
|
|
34 (defconst nxml-ascii-glyph-set
|
|
35 [(#x0020 . #x007E)])
|
|
36
|
|
37 (defconst nxml-latin1-glyph-set
|
|
38 [(#x0020 . #x007E)
|
|
39 (#x00A0 . #x00FF)])
|
|
40
|
|
41 ;; These were generated by using nxml-insert-target-repertoire-glyph-set
|
|
42 ;; on the TARGET[123] files in
|
|
43 ;; http://www.cl.cam.ac.uk/~mgk25/download/ucs-fonts.tar.gz
|
|
44
|
|
45 (defconst nxml-misc-fixed-1-glyph-set
|
|
46 [(#x0020 . #x007E)
|
|
47 (#x00A0 . #x00FF)
|
|
48 (#x0100 . #x017F)
|
|
49 #x018F #x0192
|
|
50 (#x0218 . #x021B)
|
|
51 #x0259
|
|
52 (#x02C6 . #x02C7)
|
|
53 (#x02D8 . #x02DD)
|
|
54 (#x0374 . #x0375)
|
|
55 #x037A #x037E
|
|
56 (#x0384 . #x038A)
|
|
57 #x038C
|
|
58 (#x038E . #x03A1)
|
|
59 (#x03A3 . #x03CE)
|
|
60 (#x0401 . #x040C)
|
|
61 (#x040E . #x044F)
|
|
62 (#x0451 . #x045C)
|
|
63 (#x045E . #x045F)
|
|
64 (#x0490 . #x0491)
|
|
65 (#x05D0 . #x05EA)
|
|
66 (#x1E02 . #x1E03)
|
|
67 (#x1E0A . #x1E0B)
|
|
68 (#x1E1E . #x1E1F)
|
|
69 (#x1E40 . #x1E41)
|
|
70 (#x1E56 . #x1E57)
|
|
71 (#x1E60 . #x1E61)
|
|
72 (#x1E6A . #x1E6B)
|
|
73 (#x1E80 . #x1E85)
|
|
74 (#x1EF2 . #x1EF3)
|
|
75 (#x2010 . #x2022)
|
|
76 #x2026 #x2030
|
|
77 (#x2039 . #x203A)
|
|
78 #x20AC #x2116 #x2122 #x2126
|
|
79 (#x215B . #x215E)
|
|
80 (#x2190 . #x2193)
|
|
81 #x2260
|
|
82 (#x2264 . #x2265)
|
|
83 (#x23BA . #x23BD)
|
|
84 (#x2409 . #x240D)
|
|
85 #x2424 #x2500 #x2502 #x250C #x2510 #x2514 #x2518 #x251C #x2524 #x252C #x2534 #x253C #x2592 #x25C6 #x266A #xFFFD]
|
|
86 "Glyph set for TARGET1 glyph repertoire of misc-fixed-* font.
|
|
87 This repertoire is supported for the bold and oblique fonts.")
|
|
88
|
|
89 (defconst nxml-misc-fixed-2-glyph-set
|
|
90 [(#x0020 . #x007E)
|
|
91 (#x00A0 . #x00FF)
|
|
92 (#x0100 . #x017F)
|
|
93 #x018F #x0192
|
|
94 (#x01FA . #x01FF)
|
|
95 (#x0218 . #x021B)
|
|
96 #x0259
|
|
97 (#x02C6 . #x02C7)
|
|
98 #x02C9
|
|
99 (#x02D8 . #x02DD)
|
|
100 (#x0300 . #x0311)
|
|
101 (#x0374 . #x0375)
|
|
102 #x037A #x037E
|
|
103 (#x0384 . #x038A)
|
|
104 #x038C
|
|
105 (#x038E . #x03A1)
|
|
106 (#x03A3 . #x03CE)
|
|
107 #x03D1
|
|
108 (#x03D5 . #x03D6)
|
|
109 #x03F1
|
|
110 (#x0401 . #x040C)
|
|
111 (#x040E . #x044F)
|
|
112 (#x0451 . #x045C)
|
|
113 (#x045E . #x045F)
|
|
114 (#x0490 . #x0491)
|
|
115 (#x05D0 . #x05EA)
|
|
116 (#x1E02 . #x1E03)
|
|
117 (#x1E0A . #x1E0B)
|
|
118 (#x1E1E . #x1E1F)
|
|
119 (#x1E40 . #x1E41)
|
|
120 (#x1E56 . #x1E57)
|
|
121 (#x1E60 . #x1E61)
|
|
122 (#x1E6A . #x1E6B)
|
|
123 (#x1E80 . #x1E85)
|
|
124 (#x1EF2 . #x1EF3)
|
|
125 (#x2010 . #x2022)
|
|
126 #x2026 #x2030
|
|
127 (#x2032 . #x2034)
|
|
128 (#x2039 . #x203A)
|
|
129 #x203C #x203E #x2044
|
|
130 (#x2070 . #x2071)
|
|
131 (#x2074 . #x208E)
|
|
132 (#x20A3 . #x20A4)
|
|
133 #x20A7 #x20AC
|
|
134 (#x20D0 . #x20D7)
|
|
135 #x2102 #x2105 #x2113
|
|
136 (#x2115 . #x2116)
|
|
137 #x211A #x211D #x2122 #x2124 #x2126 #x212E
|
|
138 (#x215B . #x215E)
|
|
139 (#x2190 . #x2195)
|
|
140 (#x21A4 . #x21A8)
|
|
141 (#x21D0 . #x21D5)
|
|
142 (#x2200 . #x2209)
|
|
143 (#x220B . #x220C)
|
|
144 #x220F
|
|
145 (#x2211 . #x2213)
|
|
146 #x2215
|
|
147 (#x2218 . #x221A)
|
|
148 (#x221D . #x221F)
|
|
149 #x2221
|
|
150 (#x2224 . #x222B)
|
|
151 #x222E #x223C #x2243 #x2245
|
|
152 (#x2248 . #x2249)
|
|
153 #x2259
|
|
154 (#x225F . #x2262)
|
|
155 (#x2264 . #x2265)
|
|
156 (#x226A . #x226B)
|
|
157 (#x2282 . #x228B)
|
|
158 #x2295 #x2297
|
|
159 (#x22A4 . #x22A7)
|
|
160 (#x22C2 . #x22C3)
|
|
161 #x22C5 #x2300 #x2302
|
|
162 (#x2308 . #x230B)
|
|
163 #x2310
|
|
164 (#x2320 . #x2321)
|
|
165 (#x2329 . #x232A)
|
|
166 (#x23BA . #x23BD)
|
|
167 (#x2409 . #x240D)
|
|
168 #x2424 #x2500 #x2502 #x250C #x2510 #x2514 #x2518 #x251C #x2524 #x252C #x2534 #x253C
|
|
169 (#x254C . #x2573)
|
|
170 (#x2580 . #x25A1)
|
|
171 (#x25AA . #x25AC)
|
|
172 (#x25B2 . #x25B3)
|
|
173 #x25BA #x25BC #x25C4 #x25C6
|
|
174 (#x25CA . #x25CB)
|
|
175 #x25CF
|
|
176 (#x25D8 . #x25D9)
|
|
177 #x25E6
|
|
178 (#x263A . #x263C)
|
|
179 #x2640 #x2642 #x2660 #x2663
|
|
180 (#x2665 . #x2666)
|
|
181 (#x266A . #x266B)
|
|
182 (#xFB01 . #xFB02)
|
|
183 #xFFFD]
|
|
184 "Glyph set for TARGET2 glyph repertoire of the misc-fixed-* fonts.
|
|
185 This repertoire is supported for the following fonts:
|
|
186 5x7.bdf 5x8.bdf 6x9.bdf 6x10.bdf 6x12.bdf 7x13.bdf 7x14.bdf clR6x12.bdf")
|
|
187
|
|
188 (defconst nxml-misc-fixed-3-glyph-set
|
|
189 [(#x0020 . #x007E)
|
|
190 (#x00A0 . #x00FF)
|
|
191 (#x0100 . #x01FF)
|
|
192 (#x0200 . #x0220)
|
|
193 (#x0222 . #x0233)
|
|
194 (#x0250 . #x02AD)
|
|
195 (#x02B0 . #x02EE)
|
|
196 (#x0300 . #x034F)
|
|
197 (#x0360 . #x036F)
|
|
198 (#x0374 . #x0375)
|
|
199 #x037A #x037E
|
|
200 (#x0384 . #x038A)
|
|
201 #x038C
|
|
202 (#x038E . #x03A1)
|
|
203 (#x03A3 . #x03CE)
|
|
204 (#x03D0 . #x03F6)
|
|
205 (#x0400 . #x0486)
|
|
206 (#x0488 . #x04CE)
|
|
207 (#x04D0 . #x04F5)
|
|
208 (#x04F8 . #x04F9)
|
|
209 (#x0500 . #x050F)
|
|
210 (#x0531 . #x0556)
|
|
211 (#x0559 . #x055F)
|
|
212 (#x0561 . #x0587)
|
|
213 (#x0589 . #x058A)
|
|
214 (#x05B0 . #x05B9)
|
|
215 (#x05BB . #x05C4)
|
|
216 (#x05D0 . #x05EA)
|
|
217 (#x05F0 . #x05F4)
|
|
218 (#x10D0 . #x10F8)
|
|
219 #x10FB
|
|
220 (#x1E00 . #x1E9B)
|
|
221 (#x1EA0 . #x1EF9)
|
|
222 (#x1F00 . #x1F15)
|
|
223 (#x1F18 . #x1F1D)
|
|
224 (#x1F20 . #x1F45)
|
|
225 (#x1F48 . #x1F4D)
|
|
226 (#x1F50 . #x1F57)
|
|
227 #x1F59 #x1F5B #x1F5D
|
|
228 (#x1F5F . #x1F7D)
|
|
229 (#x1F80 . #x1FB4)
|
|
230 (#x1FB6 . #x1FC4)
|
|
231 (#x1FC6 . #x1FD3)
|
|
232 (#x1FD6 . #x1FDB)
|
|
233 (#x1FDD . #x1FEF)
|
|
234 (#x1FF2 . #x1FF4)
|
|
235 (#x1FF6 . #x1FFE)
|
|
236 (#x2000 . #x200A)
|
|
237 (#x2010 . #x2027)
|
|
238 (#x202F . #x2052)
|
|
239 #x2057
|
|
240 (#x205F . #x2063)
|
|
241 (#x2070 . #x2071)
|
|
242 (#x2074 . #x208E)
|
|
243 (#x20A0 . #x20B1)
|
|
244 (#x20D0 . #x20EA)
|
|
245 (#x2100 . #x213A)
|
|
246 (#x213D . #x214B)
|
|
247 (#x2153 . #x2183)
|
|
248 (#x2190 . #x21FF)
|
|
249 (#x2200 . #x22FF)
|
|
250 (#x2300 . #x23CE)
|
|
251 (#x2400 . #x2426)
|
|
252 (#x2440 . #x244A)
|
|
253 (#x2500 . #x25FF)
|
|
254 (#x2600 . #x2613)
|
|
255 (#x2616 . #x2617)
|
|
256 (#x2619 . #x267D)
|
|
257 (#x2680 . #x2689)
|
|
258 (#x27E6 . #x27EB)
|
|
259 (#x27F5 . #x27FF)
|
|
260 (#x2A00 . #x2A06)
|
|
261 #x2A1D #x2A3F #x303F
|
|
262 (#xFB00 . #xFB06)
|
|
263 (#xFB13 . #xFB17)
|
|
264 (#xFB1D . #xFB36)
|
|
265 (#xFB38 . #xFB3C)
|
|
266 #xFB3E
|
|
267 (#xFB40 . #xFB41)
|
|
268 (#xFB43 . #xFB44)
|
|
269 (#xFB46 . #xFB4F)
|
|
270 (#xFE20 . #xFE23)
|
|
271 (#xFF61 . #xFF9F)
|
|
272 #xFFFD]
|
|
273 "Glyph set for TARGET3 glyph repertoire of the misc-fixed-* fonts.
|
|
274 This repertoire is supported for the following fonts:
|
|
275 6x13.bdf 8x13.bdf 9x15.bdf 9x18.bdf 10x20.bdf")
|
|
276
|
|
277 (defconst nxml-wgl4-glyph-set
|
|
278 [(#x0020 . #x007E)
|
|
279 (#x00A0 . #x017F)
|
|
280 #x0192
|
|
281 (#x01FA . #x01FF)
|
|
282 (#x02C6 . #x02C7)
|
|
283 #x02C9
|
|
284 (#x02D8 . #x02DB)
|
|
285 #x02DD
|
|
286 (#x0384 . #x038A)
|
|
287 #x038C
|
|
288 (#x038E . #x03A1)
|
|
289 (#x03A3 . #x03CE)
|
|
290 (#x0401 . #x040C)
|
|
291 (#x040E . #x044F)
|
|
292 (#x0451 . #x045C)
|
|
293 (#x045E . #x045F)
|
|
294 (#x0490 . #x0491)
|
|
295 (#x1E80 . #x1E85)
|
|
296 (#x1EF2 . #x1EF3)
|
|
297 (#x2013 . #x2015)
|
|
298 (#x2017 . #x201E)
|
|
299 (#x2020 . #x2022)
|
|
300 #x2026 #x2030
|
|
301 (#x2032 . #x2033)
|
|
302 (#x2039 . #x203A)
|
|
303 #x203C #x203E #x2044 #x207F
|
|
304 (#x20A3 . #x20A4)
|
|
305 #x20A7 #x20AC #x2105 #x2113 #x2116 #x2122 #x2126 #x212E
|
|
306 (#x215B . #x215E)
|
|
307 (#x2190 . #x2195)
|
|
308 #x21A8 #x2202 #x2206 #x220F
|
|
309 (#x2211 . #x2212)
|
|
310 #x2215
|
|
311 (#x2219 . #x221A)
|
|
312 (#x221E . #x221F)
|
|
313 #x2229 #x222B #x2248
|
|
314 (#x2260 . #x2261)
|
|
315 (#x2264 . #x2265)
|
|
316 #x2302 #x2310
|
|
317 (#x2320 . #x2321)
|
|
318 #x2500 #x2502 #x250C #x2510 #x2514 #x2518 #x251C #x2524
|
|
319 #x252C #x2534 #x253C
|
|
320 (#x2550 . #x256C)
|
|
321 #x2580 #x2584 #x2588 #x258C
|
|
322 (#x2590 . #x2593)
|
|
323 (#x25A0 . #x25A1)
|
|
324 (#x25AA . #x25AC)
|
|
325 #x25B2 #x25BA #x25BC #x25C4
|
|
326 (#x25CA . #x25CB)
|
|
327 #x25CF
|
|
328 (#x25D8 . #x25D9)
|
|
329 #x25E6
|
|
330 (#x263A . #x263C)
|
|
331 #x2640 #x2642 #x2660 #x2663
|
|
332 (#x2665 . #x2666)
|
|
333 (#x266A . #x266B)
|
|
334 (#xFB01 . #xFB02)]
|
|
335 "Glyph set corresponding to Windows Glyph List 4.")
|
|
336
|
|
337 (defvar nxml-glyph-set-hook nil
|
|
338 "*Hook for determining the set of glyphs in a face.
|
|
339 The hook will receive a single argument FACE. If it can determine the
|
|
340 set of glyphs representable by FACE, it must set the variable
|
|
341 `nxml-glyph-set' and return non-nil. Otherwise, it must return
|
|
342 nil. The hook will be run until success. The constants
|
|
343 `nxml-ascii-glyph-set', `nxml-latin1-glyph-set',
|
|
344 `nxml-misc-fixed-1-glyph-set', `nxml-misc-fixed-2-glyph-set',
|
|
345 `nxml-misc-fixed-3-glyph-set' and `nxml-wgl4-glyph-set' are predefined
|
|
346 for use by `nxml-glyph-set-hook'.")
|
|
347
|
|
348 (defvar nxml-glyph-set nil
|
|
349 "Used by `nxml-glyph-set-hook' to return set of glyphs in a FACE.
|
|
350 This should dynamically bound by any function that runs
|
|
351 `nxml-glyph-set-hook'. The value must be either nil representing an
|
|
352 empty set or a vector. Each member of the vector is either a single
|
|
353 integer or a cons (FIRST . LAST) representing the range of integers
|
|
354 from FIRST to LAST. An integer represents a glyph with that Unicode
|
|
355 code-point. The vector must be ordered.")
|
|
356
|
|
357 (defun nxml-x-set-glyph-set (face)
|
|
358 (setq nxml-glyph-set
|
|
359 (if (equal (face-attribute face :family) "misc-fixed")
|
|
360 nxml-misc-fixed-3-glyph-set
|
|
361 nxml-wgl4-glyph-set)))
|
|
362
|
|
363 (defun nxml-w32-set-glyph-set (face)
|
|
364 (setq nxml-glyph-set nxml-wgl4-glyph-set))
|
|
365
|
|
366 (defun nxml-window-system-set-glyph-set (face)
|
|
367 (setq nxml-glyph-set nxml-latin1-glyph-set))
|
|
368
|
|
369 (defun nxml-terminal-set-glyph-set (face)
|
|
370 (setq nxml-glyph-set nxml-ascii-glyph-set))
|
|
371
|
|
372 (add-hook 'nxml-glyph-set-hook
|
|
373 (or (cdr (assq window-system
|
|
374 '((x . nxml-x-set-glyph-set)
|
|
375 (w32 . nxml-w32-set-glyph-set)
|
|
376 (nil . nxml-terminal-set-glyph-set))))
|
|
377 'nxml-window-system-set-glyph-set)
|
|
378 t)
|
|
379
|
|
380 ;;;###autoload
|
|
381 (defun nxml-glyph-display-string (n face)
|
|
382 "Return a string that can display a glyph for Unicode code-point N.
|
|
383 FACE gives the face that will be used for displaying the string.
|
|
384 Return nil if the face cannot display a glyph for N."
|
|
385 (let ((nxml-glyph-set nil))
|
|
386 (run-hook-with-args-until-success 'nxml-glyph-set-hook face)
|
|
387 (and nxml-glyph-set
|
|
388 (nxml-glyph-set-contains-p n nxml-glyph-set)
|
|
389 (let ((ch (decode-char 'ucs n)))
|
|
390 (and ch (string ch))))))
|
|
391
|
|
392 (defun nxml-glyph-set-contains-p (n v)
|
|
393 (let ((start 0)
|
|
394 (end (length v))
|
|
395 found mid mid-val mid-start-val mid-end-val)
|
|
396 (while (> end start)
|
|
397 (setq mid (+ start
|
|
398 (/ (- end start) 2)))
|
|
399 (setq mid-val (aref v mid))
|
|
400 (if (consp mid-val)
|
|
401 (setq mid-start-val (car mid-val)
|
|
402 mid-end-val (cdr mid-val))
|
|
403 (setq mid-start-val mid-val
|
|
404 mid-end-val mid-val))
|
|
405 (cond ((and (<= mid-start-val n)
|
|
406 (<= n mid-end-val))
|
|
407 (setq found t)
|
|
408 (setq start end))
|
|
409 ((< n mid-start-val)
|
|
410 (setq end mid))
|
|
411 (t
|
|
412 (setq start
|
|
413 (if (eq start mid)
|
|
414 end
|
|
415 mid)))))
|
|
416 found))
|
|
417
|
|
418 (provide 'nxml-glyph)
|
|
419
|
86379
|
420 ;; arch-tag: 50985104-27c6-4241-8625-b11aa5685633
|
86361
|
421 ;;; nxml-glyph.el ends here
|