1 ;;; nxml-glyph.el --- glyph-handling for nxml-mode
3 ;; Copyright (C) 2003, 2007-2015 Free Software Foundation, Inc.
6 ;; Keywords: wp, hypermedia, languages, XML
8 ;; This file is part of GNU Emacs.
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 of the License, or
13 ;; (at your option) any later version.
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.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; The entry point to this file is `nxml-glyph-display-string'.
26 ;; The current implementation is heuristic due to a lack of
27 ;; Emacs primitives necessary to implement it properly. The user
28 ;; can tweak the heuristics using `nxml-glyph-set-functions'.
32 (defconst nxml-ascii-glyph-set
35 (defconst nxml-latin1-glyph-set
39 ;; These were generated by using nxml-insert-target-repertoire-glyph-set
40 ;; on the TARGET[123] files in
41 ;; http://www.cl.cam.ac.uk/~mgk25/download/ucs-fonts.tar.gz
43 (defconst nxml-misc-fixed-1-glyph-set
76 #x20AC
#x2116
#x2122
#x2126
83 #x2424
#x2500
#x2502
#x250C
#x2510
#x2514
#x2518
#x251C
#x2524
#x252C
#x2534
#x253C
#x2592
#x25C6
#x266A
#xFFFD
]
84 "Glyph set for TARGET1 glyph repertoire of misc-fixed-* font.
85 This repertoire is supported for the bold and oblique fonts.")
87 (defconst nxml-misc-fixed-2-glyph-set
135 #x211A
#x211D
#x2122
#x2124
#x2126
#x212E
149 #x222E
#x223C
#x2243
#x2245
166 #x2424
#x2500
#x2502
#x250C
#x2510
#x2514
#x2518
#x251C
#x2524
#x252C
#x2534
#x253C
171 #x25BA
#x25BC
#x25C4
#x25C6
177 #x2640
#x2642
#x2660
#x2663
182 "Glyph set for TARGET2 glyph repertoire of the misc-fixed-* fonts.
183 This repertoire is supported for the following fonts:
184 5x7.bdf 5x8.bdf 6x9.bdf 6x10.bdf 6x12.bdf 7x13.bdf 7x14.bdf clR6x12.bdf")
186 (defconst nxml-misc-fixed-3-glyph-set
271 "Glyph set for TARGET3 glyph repertoire of the misc-fixed-* fonts.
272 This repertoire is supported for the following fonts:
273 6x13.bdf 8x13.bdf 9x15.bdf 9x18.bdf 10x20.bdf")
275 (defconst nxml-wgl4-glyph-set
301 #x203C
#x203E
#x2044
#x207F
303 #x20A7
#x20AC
#x2105
#x2113
#x2116
#x2122
#x2126
#x212E
306 #x21A8
#x2202
#x2206
#x220F
316 #x2500
#x2502
#x250C
#x2510
#x2514
#x2518
#x251C
#x2524
319 #x2580
#x2584
#x2588
#x258C
323 #x25B2
#x25BA
#x25BC
#x25C4
329 #x2640
#x2642
#x2660
#x2663
333 "Glyph set corresponding to Windows Glyph List 4.")
335 (defvar nxml-glyph-set-functions nil
336 "Abnormal hook for determining the set of glyphs in a face.
337 Each function in this hook is called in turn, unless one of them
338 returns non-nil. Each function is called with a single argument
339 FACE. If it can determine the set of glyphs representable by
340 FACE, it must set the variable `nxml-glyph-set' and return
341 non-nil. Otherwise, it must return nil.
343 The constants `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
346 predefined for use by `nxml-glyph-set-functions'.")
348 (define-obsolete-variable-alias 'nxml-glyph-set-hook
349 'nxml-glyph-set-functions
"24.3")
351 (defvar nxml-glyph-set nil
352 "Used by `nxml-glyph-set-functions' to return set of glyphs in a FACE.
353 This should dynamically bound by any function that runs
354 `nxml-glyph-set-functions'. The value must be either nil representing an
355 empty set or a vector. Each member of the vector is either a single
356 integer or a cons (FIRST . LAST) representing the range of integers
357 from FIRST to LAST. An integer represents a glyph with that Unicode
358 code-point. The vector must be ordered.")
360 (defun nxml-x-set-glyph-set (face)
362 (if (equal (face-attribute face
:family
) "misc-fixed")
363 nxml-misc-fixed-3-glyph-set
364 nxml-wgl4-glyph-set
)))
366 (defun nxml-w32-set-glyph-set (face)
367 (setq nxml-glyph-set nxml-wgl4-glyph-set
))
369 (defun nxml-window-system-set-glyph-set (face)
370 (setq nxml-glyph-set nxml-latin1-glyph-set
))
372 (defun nxml-terminal-set-glyph-set (face)
373 (setq nxml-glyph-set nxml-ascii-glyph-set
))
375 (add-hook 'nxml-glyph-set-functions
376 (or (cdr (assq window-system
377 '((x . nxml-x-set-glyph-set
)
378 (w32 . nxml-w32-set-glyph-set
)
379 (nil . nxml-terminal-set-glyph-set
))))
380 'nxml-window-system-set-glyph-set
)
384 (defun nxml-glyph-display-string (n face
)
385 "Return a string that can display a glyph for Unicode code-point N.
386 FACE gives the face that will be used for displaying the string.
387 Return nil if the face cannot display a glyph for N."
388 (let ((nxml-glyph-set nil
))
389 (run-hook-with-args-until-success 'nxml-glyph-set-functions face
)
391 (nxml-glyph-set-contains-p n nxml-glyph-set
)
392 (let ((ch (decode-char 'ucs n
)))
393 (and ch
(string ch
))))))
395 (defun nxml-glyph-set-contains-p (n v
)
398 found mid mid-val mid-start-val mid-end-val
)
401 (/ (- end start
) 2)))
402 (setq mid-val
(aref v mid
))
404 (setq mid-start-val
(car mid-val
)
405 mid-end-val
(cdr mid-val
))
406 (setq mid-start-val mid-val
407 mid-end-val mid-val
))
408 (cond ((and (<= mid-start-val n
)
421 (provide 'nxml-glyph
)
423 ;;; nxml-glyph.el ends here