1 ;;; nxml-glyph.el --- glyph-handling for nxml-mode
3 ;; Copyright (C) 2003, 2007, 2008 Free Software Foundation, Inc.
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, or (at your option)
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; 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.
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'.
34 (defconst nxml-ascii-glyph-set
37 (defconst nxml-latin1-glyph-set
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
45 (defconst nxml-misc-fixed-1-glyph-set
78 #x20AC
#x2116
#x2122
#x2126
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.")
89 (defconst nxml-misc-fixed-2-glyph-set
137 #x211A
#x211D
#x2122
#x2124
#x2126
#x212E
151 #x222E
#x223C
#x2243
#x2245
168 #x2424
#x2500
#x2502
#x250C
#x2510
#x2514
#x2518
#x251C
#x2524
#x252C
#x2534
#x253C
173 #x25BA
#x25BC
#x25C4
#x25C6
179 #x2640
#x2642
#x2660
#x2663
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")
188 (defconst nxml-misc-fixed-3-glyph-set
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")
277 (defconst nxml-wgl4-glyph-set
303 #x203C
#x203E
#x2044
#x207F
305 #x20A7
#x20AC
#x2105
#x2113
#x2116
#x2122
#x2126
#x212E
308 #x21A8
#x2202
#x2206
#x220F
318 #x2500
#x2502
#x250C
#x2510
#x2514
#x2518
#x251C
#x2524
321 #x2580
#x2584
#x2588
#x258C
325 #x25B2
#x25BA
#x25BC
#x25C4
331 #x2640
#x2642
#x2660
#x2663
335 "Glyph set corresponding to Windows Glyph List 4.")
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'.")
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.")
357 (defun nxml-x-set-glyph-set (face)
359 (if (equal (face-attribute face
:family
) "misc-fixed")
360 nxml-misc-fixed-3-glyph-set
361 nxml-wgl4-glyph-set
)))
363 (defun nxml-w32-set-glyph-set (face)
364 (setq nxml-glyph-set nxml-wgl4-glyph-set
))
366 (defun nxml-window-system-set-glyph-set (face)
367 (setq nxml-glyph-set nxml-latin1-glyph-set
))
369 (defun nxml-terminal-set-glyph-set (face)
370 (setq nxml-glyph-set nxml-ascii-glyph-set
))
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
)
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
)
388 (nxml-glyph-set-contains-p n nxml-glyph-set
)
389 (let ((ch (decode-char 'ucs n
)))
390 (and ch
(string ch
))))))
392 (defun nxml-glyph-set-contains-p (n v
)
395 found mid mid-val mid-start-val mid-end-val
)
398 (/ (- end start
) 2)))
399 (setq mid-val
(aref v mid
))
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
)
418 (provide 'nxml-glyph
)
420 ;; arch-tag: 50985104-27c6-4241-8625-b11aa5685633
421 ;;; nxml-glyph.el ends here