nxml-glyph.el 11 KB

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