1 ;;; nxml-glyph.el --- glyph-handling for nxml-mode
3 ;; Copyright (C) 2003 Free Software Foundation, Inc.
8 ;; This program is free software; you can redistribute it and/or
9 ;; modify it under the terms of the GNU General Public License as
10 ;; published by the Free Software Foundation; either version 2 of
11 ;; the License, or (at your option) any later version.
13 ;; This program is distributed in the hope that it will be
14 ;; useful, but WITHOUT ANY WARRANTY; without even the implied
15 ;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 ;; PURPOSE. See the GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public
19 ;; License along with this program; if not, write to the Free
20 ;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
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-hook'.
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-hook nil
336 "*Hook for determining the set of glyphs in a face.
337 The hook will receive a single argument FACE. If it can determine the
338 set of glyphs representable by FACE, it must set the variable
339 `nxml-glyph-set' and return non-nil. Otherwise, it must return
340 nil. The hook will be run until success. The constants
341 `nxml-ascii-glyph-set', `nxml-latin1-glyph-set',
342 `nxml-misc-fixed-1-glyph-set', `nxml-misc-fixed-2-glyph-set',
343 `nxml-misc-fixed-3-glyph-set' and `nxml-wgl4-glyph-set' are predefined
344 for use by `nxml-glyph-set-hook'.")
346 (defvar nxml-glyph-set nil
347 "Used by `nxml-glyph-set-hook' to return set of glyphs in a FACE.
348 This should dynamically bound by any function that runs
349 `nxml-glyph-set-hook'. The value must be either nil representing an
350 empty set or a vector. Each member of the vector is either a single
351 integer or a cons (FIRST . LAST) representing the range of integers
352 from FIRST to LAST. An integer represents a glyph with that Unicode
353 code-point. The vector must be ordered.")
355 (defun nxml-x-set-glyph-set (face)
357 (if (equal (face-attribute face
:family
) "misc-fixed")
358 nxml-misc-fixed-3-glyph-set
359 nxml-wgl4-glyph-set
)))
361 (defun nxml-w32-set-glyph-set (face)
362 (setq nxml-glyph-set nxml-wgl4-glyph-set
))
364 (defun nxml-window-system-set-glyph-set (face)
365 (setq nxml-glyph-set nxml-latin1-glyph-set
))
367 (defun nxml-terminal-set-glyph-set (face)
368 (setq nxml-glyph-set nxml-ascii-glyph-set
))
370 (add-hook 'nxml-glyph-set-hook
371 (or (cdr (assq window-system
372 '((x . nxml-x-set-glyph-set
)
373 (w32 . nxml-w32-set-glyph-set
)
374 (nil . nxml-terminal-set-glyph-set
))))
375 'nxml-window-system-set-glyph-set
)
379 (defun nxml-glyph-display-string (n face
)
380 "Return a string that can display a glyph for Unicode code-point N.
381 FACE gives the face that will be used for displaying the string.
382 Return nil if the face cannot display a glyph for N."
383 (let ((nxml-glyph-set nil
))
384 (run-hook-with-args-until-success 'nxml-glyph-set-hook face
)
386 (nxml-glyph-set-contains-p n nxml-glyph-set
)
387 (let ((ch (decode-char 'ucs n
)))
388 (and ch
(string ch
))))))
390 (defun nxml-glyph-set-contains-p (n v
)
393 found mid mid-val mid-start-val mid-end-val
)
396 (/ (- end start
) 2)))
397 (setq mid-val
(aref v mid
))
399 (setq mid-start-val
(car mid-val
)
400 mid-end-val
(cdr mid-val
))
401 (setq mid-start-val mid-val
402 mid-end-val mid-val
))
403 (cond ((and (<= mid-start-val n
)
416 (provide 'nxml-glyph
)
418 ;;; nxml-glyph.el ends here