fontset.el 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156
  1. ;;; fontset.el --- commands for handling fontset
  2. ;; Copyright (C) 1997-2012 Free Software Foundation, Inc.
  3. ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
  4. ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011
  5. ;; National Institute of Advanced Industrial Science and Technology (AIST)
  6. ;; Registration Number H14PRO021
  7. ;; Copyright (C) 2003, 2006
  8. ;; National Institute of Advanced Industrial Science and Technology (AIST)
  9. ;; Registration Number H13PRO009
  10. ;; Keywords: mule, i18n, fontset
  11. ;; This file is part of GNU Emacs.
  12. ;; GNU Emacs is free software: you can redistribute it and/or modify
  13. ;; it under the terms of the GNU General Public License as published by
  14. ;; the Free Software Foundation, either version 3 of the License, or
  15. ;; (at your option) any later version.
  16. ;; GNU Emacs is distributed in the hope that it will be useful,
  17. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. ;; 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/>.
  22. ;;; Commentary:
  23. ;;; Code:
  24. ;; Setup font-encoding-alist for all known encodings.
  25. (setq font-encoding-alist
  26. (mapcar (lambda (arg)
  27. (cons (purecopy (car arg)) (cdr arg)))
  28. '(("iso8859-1$" . iso-8859-1)
  29. ("iso8859-2$" . iso-8859-2)
  30. ("iso8859-3$" . iso-8859-3)
  31. ("iso8859-4$" . iso-8859-4)
  32. ("iso8859-5$" . iso-8859-5)
  33. ("iso8859-6$" . iso-8859-6)
  34. ("iso8859-7$" . iso-8859-7)
  35. ("iso8859-8$" . iso-8859-8)
  36. ("iso8859-9$" . iso-8859-9)
  37. ("iso8859-10$" . iso-8859-10)
  38. ("iso8859-11$" . iso-8859-11)
  39. ("iso8859-13$" . iso-8859-13)
  40. ("iso8859-14$" . iso-8859-14)
  41. ("iso8859-15$" . iso-8859-15)
  42. ("iso8859-16$" . iso-8859-16)
  43. ("ascii-0$" . ascii)
  44. ("gb2312.1980" . chinese-gb2312)
  45. ("gbk" . chinese-gbk)
  46. ("gb18030" . (unicode . nil))
  47. ("jisx0208.1978" . japanese-jisx0208-1978)
  48. ("jisx0208" . japanese-jisx0208)
  49. ("jisx0201" . jisx0201)
  50. ("jisx0212" . japanese-jisx0212)
  51. ("ksx1001" . korean-ksc5601)
  52. ("ksc5601.1987" . korean-ksc5601)
  53. ("cns11643.1992.*1" . chinese-cns11643-1)
  54. ("cns11643.1992.*2" . chinese-cns11643-2)
  55. ("cns11643.1992.*3" . chinese-cns11643-3)
  56. ("cns11643.1992.*4" . chinese-cns11643-4)
  57. ("cns11643.1992.*5" . chinese-cns11643-5)
  58. ("cns11643.1992.*6" . chinese-cns11643-6)
  59. ("cns11643.1992.*7" . chinese-cns11643-7)
  60. ("cns11643.92p1-0" . chinese-cns11643-1)
  61. ("cns11643.92p2-0" . chinese-cns11643-2)
  62. ("cns11643.92p3-0" . chinese-cns11643-3)
  63. ("cns11643.92p4-0" . chinese-cns11643-4)
  64. ("cns11643.92p5-0" . chinese-cns11643-5)
  65. ("cns11643.92p6-0" . chinese-cns11643-6)
  66. ("cns11643.92p7-0" . chinese-cns11643-7)
  67. ("big5" . big5)
  68. ("viscii" . viscii)
  69. ("tis620" . tis620-2533)
  70. ("microsoft-cp1251" . windows-1251)
  71. ("koi8-r" . koi8-r)
  72. ("jisx0213.2000-1" . japanese-jisx0213-1)
  73. ("jisx0213.2000-2" . japanese-jisx0213-2)
  74. ("jisx0213.2004-1" . japanese-jisx0213.2004-1)
  75. ("iso10646-1$" . (unicode-bmp . nil))
  76. ("iso10646.indian-1" . (unicode-bmp . nil))
  77. ("unicode-bmp" . (unicode-bmp . nil))
  78. ("abobe-symbol" . symbol)
  79. ("sisheng_cwnn" . chinese-sisheng)
  80. ("mulearabic-0" . arabic-digit)
  81. ("mulearabic-1" . arabic-1-column)
  82. ("mulearabic-2" . arabic-2-column)
  83. ("muleipa" . ipa)
  84. ("ethiopic-unicode" . (unicode-bmp . ethiopic))
  85. ("is13194-devanagari" . indian-is13194)
  86. ("Devanagari-CDAC" . devanagari-cdac)
  87. ("Sanskrit-CDAC" . sanskrit-cdac)
  88. ("Bengali-CDAC" . bengali-cdac)
  89. ("Assamese-CDAC" . assamese-cdac)
  90. ("Punjabi-CDAC" . punjabi-cdac)
  91. ("Gujarati-CDAC" . gujarati-cdac)
  92. ("Oriya-CDAC" . oriya-cdac)
  93. ("Tamil-CDAC" . tamil-cdac)
  94. ("Telugu-CDAC" . telugu-cdac)
  95. ("Kannada-CDAC" . kannada-cdac)
  96. ("Malayalam-CDAC" . malayalam-cdac)
  97. ("Devanagari-Akruti" . devanagari-akruti)
  98. ("Bengali-Akruti" . bengali-akruti)
  99. ("Punjabi-Akruti" . punjabi-akruti)
  100. ("Gujarati-Akruti" . gujarati-akruti)
  101. ("Oriya-Akruti" . oriya-akruti)
  102. ("Tamil-Akruti" . tamil-akruti)
  103. ("Telugu-Akruti" . telugu-akruti)
  104. ("Kannada-Akruti" . kannada-akruti)
  105. ("Malayalam-Akruti" . malayalam-akruti)
  106. ("muleindian-2" . indian-2-column)
  107. ("muleindian-1" . indian-1-column)
  108. ("mulelao-1" . mule-lao)
  109. ("muletibetan-2" . tibetan)
  110. ("muletibetan-0" . tibetan)
  111. ("muletibetan-1" . tibetan-1-column))))
  112. (defvar font-encoding-charset-alist)
  113. (setq font-encoding-charset-alist
  114. '((latin-iso8859-1 . iso-8859-1)
  115. (latin-iso8859-2 . iso-8859-2)
  116. (latin-iso8859-3 . iso-8859-3)
  117. (latin-iso8859-4 . iso-8859-4)
  118. (latin-iso8859-9 . iso-8859-9)
  119. (latin-iso8859-10 . iso-8859-10)
  120. (latin-iso8859-13 . iso-8859-13)
  121. (latin-iso8859-14 . iso-8859-14)
  122. (latin-iso8859-15 . iso-8859-15)
  123. (latin-iso8859-16 . iso-8859-16)
  124. (cyrillic-iso8859-5 . iso-8859-5)
  125. (greek-iso8859-7 . iso-8859-7)
  126. (arabic-iso8859-6 . iso-8859-6)
  127. (thai-tis620 . tis620-2533)
  128. (latin-jisx0201 . jisx0201)
  129. (katakana-jisx0201 . jisx0201)
  130. (chinese-big5-1 . big5)
  131. (chinese-big5-2 . big5)
  132. (vietnamese-viscii-lower . viscii)
  133. (vietnamese-viscii-upper . viscii)
  134. (tibetan . unicode-bmp)))
  135. (setq script-representative-chars
  136. '((latin ?A ?Z ?a ?z #x00C0 #x0100 #x0180 #x1e00)
  137. (phonetic #x250 #x283)
  138. (greek #x3A9)
  139. (coptic #x3E2)
  140. (cyrillic #x42F)
  141. (armenian #x531)
  142. (hebrew #x5D0)
  143. (arabic #x628)
  144. (syriac #x710)
  145. (thaana #x78C)
  146. (devanagari #x915)
  147. (bengali #x995)
  148. (gurmukhi #xA15)
  149. (gujarati #xA95)
  150. (oriya #xB15)
  151. (tamil #xB95)
  152. (telugu #xC15)
  153. (kannada #xC95)
  154. (malayalam #xD15)
  155. (sinhala #xD95)
  156. (thai #xE17)
  157. (lao #xEA5)
  158. (tibetan #xF40)
  159. (burmese #x1000)
  160. (georgian #x10D3)
  161. (ethiopic #x1208)
  162. (cherokee #x13B6)
  163. (canadian-aboriginal #x14C0)
  164. (ogham #x168F)
  165. (runic #x16A0)
  166. (khmer #x1780)
  167. (mongolian #x1826)
  168. (symbol . [#x201C #x2200 #x2500])
  169. (braille #x2800)
  170. (ideographic-description #x2FF0)
  171. (cjk-misc #x300E)
  172. (kana #x304B)
  173. (bopomofo #x3105)
  174. (kanbun #x319D)
  175. (han #x5B57)
  176. (yi #xA288)
  177. (cham #xAA00)
  178. (tai-viet #xAA80)
  179. (hangul #xAC00)
  180. (linear-b #x10000)
  181. (aegean-number #x10100)
  182. (ancient-greek-number #x10140)
  183. (ancient-symbol #x10190)
  184. (phaistos-disc #x101D0)
  185. (lycian #x10280)
  186. (carian #x102A0)
  187. (olt-italic #x10300)
  188. (ugaritic #x10380)
  189. (old-persian #x103A0)
  190. (deseret #x10400)
  191. (shavian #x10450)
  192. (osmanya #x10480)
  193. (cypriot-syllabary #x10800)
  194. (phoenician #x10900)
  195. (lydian #x10920)
  196. (kharoshthi #x10A00)
  197. (cuneiform #x12000)
  198. (cuneiform-numbers-and-punctuation #x12400)
  199. (byzantine-musical-symbol #x1D000)
  200. (musical-symbol #x1D100)
  201. (ancient-greek-musical-notation #x1D200)
  202. (tai-xuan-jing-symbol #x1D300)
  203. (counting-rod-numeral #x1D360)
  204. (mahjong-tile #x1F000)
  205. (domino-tile #x1F030)))
  206. (defvar otf-script-alist)
  207. (setq otf-script-alist
  208. '((arab . arabic)
  209. (armn . armenian)
  210. (bali . balinese)
  211. (beng . bengali)
  212. (bopo . bopomofo)
  213. (brai . braille)
  214. (bugi . buginese)
  215. (buhd . buhid)
  216. (byzm . byzantine-musical-symbol)
  217. (cans . canadian-aboriginal)
  218. (cher . cherokee)
  219. (copt . coptic)
  220. (xsux . cuneiform)
  221. (cyrl . cyrillic)
  222. (cprt . cypriot)
  223. (dsrt . deseret)
  224. (deva . devanagari)
  225. (ethi . ethiopic)
  226. (geor . georgian)
  227. (glag . glagolitic)
  228. (goth . gothic)
  229. (grek . greek)
  230. (gujr . gujarati)
  231. (guru . gurmukhi)
  232. (hani . han)
  233. (hang . hangul)
  234. (hano . hanunoo)
  235. (hebr . hebrew)
  236. (kana . kana)
  237. (knda . kannada)
  238. (khar . kharoshthi)
  239. (khmr . khmer)
  240. (lao\ . lao)
  241. (latn . latin)
  242. (limb . limbu)
  243. (linb . linear_b)
  244. (mlym . malayalam)
  245. (math . mathematical)
  246. (mong . mongolian)
  247. (musc . musical-symbol)
  248. (mymr . burmese)
  249. (nko\ . nko)
  250. (ogam . ogham)
  251. (ital . old_italic)
  252. (xpeo . old_persian)
  253. (orya . oriya)
  254. (osma . osmanya)
  255. (phag . phags-pa)
  256. (phnx . phoenician)
  257. (runr . runic)
  258. (shaw . shavian)
  259. (sinh . sinhala)
  260. (sylo . syloti_nagri)
  261. (syrc . syriac)
  262. (tglg . tagalog)
  263. (tagb . tagbanwa)
  264. (taml . tamil)
  265. (tale . tai_le)
  266. (telu . telugu)
  267. (thaa . thaana)
  268. (thai . thai)
  269. (tibt . tibetan)
  270. (tfng . tifinagh)
  271. (ugar . ugaritic)
  272. (yi\ \ . yi)))
  273. ;; Set standard fontname specification of characters in the default
  274. ;; fontset to find an appropriate font for each script/charset. The
  275. ;; specification has the form ((SCRIPT FONT-SPEC ...) ...), where
  276. ;; FONT-SPEC is:
  277. ;; a cons (FAMILY . REGISTRY),
  278. ;; or a string FONT-NAME,
  279. ;; or an object created by `font-spec'.
  280. ;;
  281. ;; FAMILY may be nil, in which case, the corresponding name of
  282. ;; default face is used. If REGISTRY contains a character `-', the
  283. ;; string before that is embedded in `CHARSET_REGISTRY' field, and the
  284. ;; string after that is embedded in `CHARSET_ENCODING' field. If it
  285. ;; does not contain `-', the whole string is embedded in
  286. ;; `CHARSET_REGISTRY' field, and a wild card character `*' is embedded
  287. ;; in `CHARSET_ENCODING' field.
  288. ;;
  289. ;; SCRIPT is a symbol that appears as an element of the char table
  290. ;; `char-script-table'. SCRIPT may be a charset specifying the range
  291. ;; of characters.
  292. (declare-function new-fontset "fontset.c" (name fontlist))
  293. (declare-function set-fontset-font "fontset.c"
  294. (name target font-spec &optional frame add))
  295. (eval-when-compile
  296. ;; Build a data to initialize the default fontset at compile time to
  297. ;; avoid loading charsets that won't be necessary at runtime.
  298. ;; The value is (CJK-REGISTRY-VECTOR TARGET-SPEC ...), where
  299. ;; CJK-REGISTRY-VECTOR is ["JISX0208.1983-0" "GB2312.1980-0" ...],
  300. ;; TARGET-SPEC is (TARGET . BITMASK) or (TARGET SPEC ...),
  301. ;; TARGET is CHAR or (FROM-CHAR . TO-CHAR),
  302. ;; BITMASK is a bitmask of indices to CJK-REGISTRY-VECTOR,
  303. ;; SPEC is a list of arguments to font-spec.
  304. (defmacro build-default-fontset-data ()
  305. (let* (;; CHARSET-REGISTRY CHARSET FROM-CODE TO-CODE
  306. (cjk '(("JISX0208.1983-0" japanese-jisx0208 #x2121 #x287E)
  307. ("GB2312.1980-0" chinese-gb2312 #x2121 #x297E)
  308. ("BIG5-0" big5 #xA140 #xA3FE)
  309. ("CNS11643.1992-1" chinese-cns11643-1 #x2121 #x427E)
  310. ("KSC5601.1987-0" korean-ksc5601 #x2121 #x2C7E)))
  311. (scripts '((tibetan
  312. (:registry "iso10646-1" :otf (tibt nil (ccmp blws abvs)))
  313. (:family "mtib" :registry "iso10646-1")
  314. (:registry "muletibetan-2"))
  315. (ethiopic
  316. (:registry "iso10646-1" :script ethiopic)
  317. (:registry "ethiopic-unicode"))
  318. (phonetic
  319. (:registry "iso10646-1" :script phonetic)
  320. (:registry "MuleIPA-1")
  321. (:registry "iso10646-1"))))
  322. (cjk-table (make-char-table nil))
  323. (script-coverage
  324. #'(lambda (script)
  325. (let ((coverage))
  326. (map-char-table
  327. #'(lambda (range val)
  328. (when (eq val script)
  329. (if (consp range)
  330. (setq range (cons (car range) (cdr range))))
  331. (push range coverage)))
  332. char-script-table)
  333. coverage)))
  334. (data (list (vconcat (mapcar 'car cjk))))
  335. (i 0))
  336. (dolist (elt cjk)
  337. (let ((mask (lsh 1 i)))
  338. (map-charset-chars
  339. #'(lambda (range arg)
  340. (let ((from (car range)) (to (cdr range)))
  341. (if (< to #x110000)
  342. (while (<= from to)
  343. (or (memq (aref char-script-table from)
  344. '(kana hangul han cjk-misc))
  345. (aset cjk-table from
  346. (logior (or (aref cjk-table from) 0) mask)))
  347. (setq from (1+ from))))))
  348. (nth 1 elt) nil (nth 2 elt) (nth 3 elt)))
  349. (setq i (1+ i)))
  350. (map-char-table
  351. #'(lambda (range val)
  352. (if (consp range)
  353. (setq range (cons (car range) (cdr range))))
  354. (push (cons range val) data))
  355. cjk-table)
  356. (dolist (script scripts)
  357. (dolist (range (funcall script-coverage (car script)))
  358. (push (cons range (cdr script)) data)))
  359. `(quote ,(nreverse data))))
  360. )
  361. (defun setup-default-fontset ()
  362. "Setup the default fontset."
  363. (new-fontset
  364. "fontset-default"
  365. `(;; for each script
  366. (latin (nil . "ISO8859-1")
  367. (nil . "ISO8859-2")
  368. (nil . "ISO8859-3")
  369. (nil . "ISO8859-4")
  370. (nil . "ISO8859-9")
  371. (nil . "ISO8859-10")
  372. (nil . "ISO8859-13")
  373. (nil . "ISO8859-14")
  374. (nil . "ISO8859-15")
  375. (nil . "ISO8859-16")
  376. (nil . "VISCII1.1-1")
  377. ,(font-spec :registry "iso10646-1" :script 'latin))
  378. (thai ,(font-spec :registry "iso10646-1" :otf '(thai nil nil (mark)))
  379. ,(font-spec :registry "iso10646-1" :script 'thai)
  380. (nil . "TIS620*")
  381. (nil . "ISO8859-11"))
  382. (devanagari ,(font-spec :registry "iso10646-1" :otf '(deva nil (rphf)))
  383. (nil . "iso10646.indian-1"))
  384. (bengali ,(font-spec :registry "iso10646-1" :otf '(beng nil (rphf))))
  385. (gurmukhi ,(font-spec :registry "iso10646-1" :otf '(guru nil (blwf))))
  386. (gujarati ,(font-spec :registry "iso10646-1" :otf '(gujr nil (rphf))))
  387. (oriya ,(font-spec :registry "iso10646-1" :otf '(orya nil (rphf))))
  388. (tamil ,(font-spec :registry "iso10646-1" :otf '(taml nil (akhn))))
  389. (telugu ,(font-spec :registry "iso10646-1" :otf '(telu nil (blwf))))
  390. (kannada ,(font-spec :registry "iso10646-1" :otf '(knda nil (rphf))))
  391. (sinhala ,(font-spec :registry "iso10646-1" :otf '(sinh nil (akhn))))
  392. (malayalam ,(font-spec :registry "iso10646-1" :otf '(mlym nil (akhn))))
  393. (burmese ,(font-spec :registry "iso10646-1" :otf '(mymr nil nil))
  394. ,(font-spec :registry "iso10646-1" :script 'burmese))
  395. (lao ,(font-spec :registry "iso10646-1" :otf '(lao\ nil nil (mark)))
  396. ,(font-spec :registry "iso10646-1" :script 'lao)
  397. (nil . "MuleLao-1"))
  398. (tai-viet ("TaiViet" . "iso10646-1"))
  399. (greek ,(font-spec :registry "iso10646-1" :script 'greek)
  400. (nil . "ISO8859-7"))
  401. (cyrillic ,(font-spec :registry "iso10646-1" :script 'cyrillic)
  402. (nil . "ISO8859-5")
  403. (nil . "microsoft-cp1251")
  404. (nil . "koi8-r"))
  405. (arabic ,(font-spec :registry "iso10646-1"
  406. :otf '(arab nil (init medi fina liga)))
  407. (nil . "MuleArabic-0")
  408. (nil . "MuleArabic-1")
  409. (nil . "MuleArabic-2")
  410. (nil . "ISO8859-6"))
  411. (hebrew ,(font-spec :registry "iso10646-1" :script 'hebrew)
  412. (nil . "ISO8859-8"))
  413. (khmer ,(font-spec :registry "iso10646-1" :otf '(khmr nil (pres))))
  414. (kana (nil . "JISX0208*")
  415. (nil . "GB2312.1980-0")
  416. (nil . "KSC5601.1987*")
  417. (nil . "JISX0201*")
  418. (nil . "JISX0213.2000-1")
  419. (nil . "JISX0213.2004-1")
  420. ,(font-spec :registry "iso10646-1" :script 'kana))
  421. (bopomofo ,(font-spec :registry "iso10646-1" :script 'bopomofo)
  422. (nil . "sisheng_cwnn-0"))
  423. (han (nil . "GB2312.1980-0")
  424. (nil . "JISX0208*")
  425. (nil . "JISX0212*")
  426. (nil . "big5*")
  427. (nil . "KSC5601.1987*")
  428. (nil . "CNS11643.1992-1")
  429. (nil . "CNS11643.1992-2")
  430. (nil . "CNS11643.1992-3")
  431. (nil . "CNS11643.1992-4")
  432. (nil . "CNS11643.1992-5")
  433. (nil . "CNS11643.1992-6")
  434. (nil . "CNS11643.1992-7")
  435. (nil . "gbk-0")
  436. (nil . "gb18030")
  437. (nil . "JISX0213.2000-1")
  438. (nil . "JISX0213.2000-2")
  439. (nil . "JISX0213.2004-1")
  440. ,(font-spec :registry "iso10646-1" :lang 'ja)
  441. ,(font-spec :registry "iso10646-1" :lang 'zh))
  442. (cjk-misc (nil . "GB2312.1980-0")
  443. (nil . "JISX0208*")
  444. (nil . "JISX0212*")
  445. (nil . "big5*")
  446. (nil . "KSC5601.1987*")
  447. (nil . "CNS11643.1992-1")
  448. (nil . "CNS11643.1992-2")
  449. (nil . "CNS11643.1992-3")
  450. (nil . "CNS11643.1992-4")
  451. (nil . "CNS11643.1992-5")
  452. (nil . "CNS11643.1992-6")
  453. (nil . "CNS11643.1992-7")
  454. (nil . "gbk-0")
  455. (nil . "gb18030")
  456. (nil . "JISX0213.2000-1")
  457. (nil . "JISX0213.2000-2")
  458. ,(font-spec :registry "iso10646-1" :lang 'ja)
  459. ,(font-spec :registry "iso10646-1" :lang 'zh))
  460. (hangul (nil . "KSC5601.1987-0")
  461. ,(font-spec :registry "iso10646-1" :lang 'ko))
  462. ;; for each charset
  463. (ascii (nil . "ISO8859-1"))
  464. (arabic-digit ("*" . "MuleArabic-0"))
  465. (arabic-1-column ("*" . "MuleArabic-1"))
  466. (arabic-2-column ("*" . "MuleArabic-2"))
  467. (indian-is13194 (nil . "is13194-devanagari"))
  468. (indian-1-column ("*" . "muleindian-2"))
  469. ;; Indian CDAC
  470. (devanagari-cdac (nil . "Devanagari-CDAC"))
  471. (sanskrit-cdac (nil . "Sanskrit-CDAC"))
  472. (bengali-cdac (nil . "Bengali-CDAC"))
  473. (assamese-cdac (nil . "Assamese-CDAC"))
  474. (punjabi-cdac (nil . "Punjabi-CDAC"))
  475. (gujarati-cdac (nil . "Gujarati-CDAC"))
  476. (oriya-cdac (nil . "Oriya-CDAC"))
  477. (tamil-cdac (nil . "Tamil-CDAC"))
  478. (telugu-cdac (nil . "Telugu-CDAC"))
  479. (kannada-cdac (nil . "Kannada-CDAC"))
  480. (malayalam-cdac (nil . "Malayalam-CDAC"))
  481. ;; Indian AKRUTI
  482. (devanagari-akruti (nil . "Devanagari-Akruti"))
  483. (bengali-akruti (nil . "Bengali-Akruti"))
  484. (punjabi-akruti (nil . "Punjabi-Akruti"))
  485. (gujarati-akruti (nil . "Gujarati-Akruti"))
  486. (oriya-akruti (nil . "Oriya-Akruti"))
  487. (tamil-akruti (nil . "Tamil-Akruti"))
  488. (telugu-akruti (nil . "Telugu-Akruti"))
  489. (kannada-akruti (nil . "Kannada-Akruti"))
  490. (malayalam-akruti (nil . "Malayalam-Akruti"))
  491. ;; Fallback fonts
  492. (nil (nil . "gb2312.1980")
  493. (nil . "gbk-0")
  494. (nil . "gb18030")
  495. (nil . "jisx0208")
  496. (nil . "ksc5601.1987")
  497. (nil . "CNS11643.1992-1")
  498. (nil . "CNS11643.1992-2")
  499. (nil . "CNS11643.1992-3")
  500. (nil . "CNS11643.1992-4")
  501. (nil . "CNS11643.1992-5")
  502. (nil . "CNS11643.1992-6")
  503. (nil . "CNS11643.1992-7")
  504. (nil . "big5")
  505. (nil . "jisx0213.2000-1")
  506. (nil . "jisx0213.2004-1")
  507. (nil . "jisx0212"))
  508. ))
  509. ;; For simple scripts
  510. (dolist (script '(phonetic
  511. armenian
  512. syriac
  513. thaana
  514. georgian
  515. cherokee
  516. canadian-aboriginal
  517. ogham
  518. runic
  519. symbol
  520. braille
  521. yi
  522. aegean-number
  523. ancient-greek-number
  524. ancient-symbol
  525. phaistos-disc
  526. lycian
  527. carian
  528. olt-italic
  529. ugaritic
  530. old-persian
  531. deseret
  532. shavian
  533. osmanya
  534. cypriot-syllabary
  535. phoenician
  536. lydian
  537. kharoshthi
  538. cuneiform
  539. cuneiform-numbers-and-punctuation
  540. byzantine-musical-symbol
  541. musical-symbol
  542. ancient-greek-musical-notation
  543. tai-xuan-jing-symbol
  544. counting-rod-numeral
  545. mahjong-tile
  546. domino-tile))
  547. (set-fontset-font "fontset-default"
  548. script (font-spec :registry "iso10646-1" :script script)
  549. nil 'append))
  550. ;; Special settings for `MATHEMATICAL (U+1D400..U+1D7FF)'.
  551. (dolist (math-subgroup '((#x1D400 #x1D433 mathematical-bold)
  552. (#x1D434 #x1D467 mathematical-italic)
  553. (#x1D468 #x1D49B mathematical-bold-italic)
  554. (#x1D49C #x1D4CF mathematical-script)
  555. (#x1D4D0 #x1D503 mathematical-bold-script)
  556. (#x1D504 #x1D537 mathematical-fraktur)
  557. (#x1D538 #x1D56B mathematical-double-struck)
  558. (#x1D56C #x1D59F mathematical-bold-fraktur)
  559. (#x1D5A0 #x1D5D3 mathematical-sans-serif)
  560. (#x1D5D4 #x1D607 mathematical-sans-serif-bold)
  561. (#x1D608 #x1D63B mathematical-sans-serif-italic)
  562. (#x1D63C #x1D66F mathematical-sans-serif-bold-italic)
  563. (#x1D670 #x1D6A3 mathematical-monospace)
  564. (#x1D6A4 #x1D6A5 mathematical-italic)
  565. (#x1D6A8 #x1D6E1 mathematical-bold)
  566. (#x1D6E2 #x1D71B mathematical-italic)
  567. (#x1D71C #x1D755 mathematical-bold-italic)
  568. (#x1D756 #x1D78F mathematical-sans-serif-bold)
  569. (#x1D790 #x1D7C9 mathematical-sans-serif-bold-italic)
  570. (#x1D7CA #x1D7D7 mathematical-bold)
  571. (#x1D7D8 #x1D7E1 mathematical-double-struck)
  572. (#x1D7E2 #x1D7EB mathematical-sans-serif)
  573. (#x1D7EC #x1D7F5 mathematical-sans-serif-bold)
  574. (#x1D7F6 #x1D7FF mathematical-monospace)))
  575. (let ((slot (assq (nth 2 math-subgroup) script-representative-chars)))
  576. (if slot
  577. (if (vectorp (cdr slot))
  578. (setcdr slot (vconcat (cdr slot) (vector (car math-subgroup))))
  579. (setcdr slot (vector (cadr slot) (car math-subgroup))))
  580. (setq slot (list (nth 2 math-subgroup) (car math-subgroup)))
  581. (nconc script-representative-chars (list slot))))
  582. (set-fontset-font
  583. "fontset-default"
  584. (cons (car math-subgroup) (nth 1 math-subgroup))
  585. (font-spec :registry "iso10646-1" :script (nth 2 math-subgroup))))
  586. ;; Append CJK fonts for characters other than han, kana, cjk-misc.
  587. ;; Append fonts for scripts whose name is also a charset name.
  588. (let* ((data (build-default-fontset-data))
  589. (registries (car data)))
  590. (dolist (target-spec (cdr data))
  591. (let ((target (car target-spec))
  592. (spec (cdr target-spec)))
  593. (if (integerp spec)
  594. (dotimes (i (length registries))
  595. (if (> (logand spec (lsh 1 i)) 0)
  596. (set-fontset-font "fontset-default" target
  597. (cons nil (aref registries i))
  598. nil 'append)))
  599. (dolist (args spec)
  600. (set-fontset-font "fontset-default" target
  601. (apply 'font-spec args) nil 'append))))))
  602. ;; Append Unicode fonts.
  603. ;; This may find fonts with more variants (bold, italic) but which
  604. ;; don't cover many characters.
  605. (set-fontset-font "fontset-default" nil
  606. '(nil . "iso10646-1") nil 'prepend)
  607. ;; These may find fonts that cover many characters but with fewer
  608. ;; variants.
  609. (set-fontset-font "fontset-default" nil
  610. '("gnu-unifont" . "iso10646-1") nil 'prepend)
  611. (set-fontset-font "fontset-default" nil
  612. '("mutt-clearlyu" . "iso10646-1") nil 'prepend)
  613. (set-fontset-font "fontset-default" '(#x20000 . #x2FFFF)
  614. '(nil . "unicode-sip"))
  615. (set-fontset-font "fontset-default" '(#xE000 . #xF8FF)
  616. '(nil . "iso10646-1"))
  617. ;; Don't try the fallback fonts even if no suitable font was found
  618. ;; by the above font-spec.
  619. (set-fontset-font "fontset-default" '(#xE000 . #xF8FF) nil nil 'append))
  620. (defun create-default-fontset ()
  621. "Create the default fontset.
  622. Internal use only. Should be called at startup time."
  623. (condition-case err
  624. (setup-default-fontset)
  625. (error (display-warning
  626. 'initialization
  627. (format "Creation of the default fontsets failed: %s" err)
  628. :error))))
  629. ;; These are the registered registries/encodings from
  630. ;; ftp://ftp.x.org/pub/DOCS/registry 2001/06/01
  631. ;; Name Reference
  632. ;; ---- ---------
  633. ;; "DEC" [27]
  634. ;; registry prefix
  635. ;; "DEC.CNS11643.1986-2" [53]
  636. ;; CNS11643 2-plane using the encoding
  637. ;; suggested in that standard
  638. ;; "DEC.DTSCS.1990-2" [54]
  639. ;; DEC Taiwan Supplemental Character Set
  640. ;; "fujitsu.u90x01.1991-0" [87]
  641. ;; "fujitsu.u90x03.1991-0" [87]
  642. ;; "GB2312.1980-0" [39],[12]
  643. ;; China (PRC) Hanzi, GL encoding
  644. ;; "GB2312.1980-1" [39]
  645. ;; (deprecated)
  646. ;; China (PRC) Hanzi, GR encoding
  647. ;; "HP-Arabic8" [36]
  648. ;; HPARABIC8 8-bit character set
  649. ;; "HP-East8" [36]
  650. ;; HPEAST8 8-bit character set
  651. ;; "HP-Greek8" [36]
  652. ;; HPGREEK8 8-bit character set
  653. ;; "HP-Hebrew8" [36]
  654. ;; HPHEBREW8 8-bit character set
  655. ;; "HP-Japanese15" [36]
  656. ;; HPJAPAN15 15-bit character set,
  657. ;; modified from industry de facto
  658. ;; standard Shift-JIS
  659. ;; "HP-Kana8" [36]
  660. ;; HPKANA8 8-bit character set
  661. ;; "HP-Korean15" [36]
  662. ;; HPKOREAN15 15-bit character set
  663. ;; "HP-Roman8" [36]
  664. ;; HPROMAN8 8-bit character set
  665. ;; "HP-SChinese15" [36]
  666. ;; HPSCHINA15 15-bit character set for
  667. ;; support of Simplified Chinese
  668. ;; "HP-TChinese15" [36]
  669. ;; HPTCHINA15 15-bit character set for
  670. ;; support of Traditional Chinese
  671. ;; "HP-Turkish8" [36]
  672. ;; HPTURKISH8 8-bit character set
  673. ;; "IPSYS" [59]
  674. ;; registry prefix
  675. ;; "IPSYS.IE-1" [59]
  676. ;; "ISO2022"<REG>"-"<ENC> [44]
  677. ;; "ISO646.1991-IRV" [107]
  678. ;; ISO 646 International Reference Version
  679. ;; "ISO8859-1" [15],[12]
  680. ;; ISO Latin alphabet No. 1
  681. ;; "ISO8859-2" [15],[12]
  682. ;; ISO Latin alphabet No. 2
  683. ;; "ISO8859-3" [15],[12]
  684. ;; ISO Latin alphabet No. 3
  685. ;; "ISO8859-4" [15],[12]
  686. ;; ISO Latin alphabet No. 4
  687. ;; "ISO8859-5" [15],[12]
  688. ;; ISO Latin/Cyrillic alphabet
  689. ;; "ISO8859-6" [15],[12]
  690. ;; ISO Latin/Arabic alphabet
  691. ;; "ISO8859-7" [15],[12]
  692. ;; ISO Latin/Greek alphabet
  693. ;; "ISO8859-8" [15],[12]
  694. ;; ISO Latin/Hebrew alphabet
  695. ;; "ISO8859-9" [15],[12]
  696. ;; ISO Latin alphabet No. 5
  697. ;; "ISO8859-10" [15],[12]
  698. ;; ISO Latin alphabet No. 6
  699. ;; "ISO8859-13" [15],[12]
  700. ;; ISO Latin alphabet No. 7
  701. ;; "ISO8859-14" [15],[12]
  702. ;; ISO Latin alphabet No. 8
  703. ;; "ISO8859-15" [15],[12]
  704. ;; ISO Latin alphabet No. 9
  705. ;; "FCD8859-15" [7]
  706. ;; (deprecated)
  707. ;; ISO Latin alphabet No. 9, Final Committee Draft
  708. ;; "ISO10646-1" [133]
  709. ;; Unicode Universal Multiple-Octet Coded Character Set
  710. ;; "ISO10646-MES" [133]
  711. ;; (deprecated)
  712. ;; Unicode Minimum European Subset
  713. ;; "JISX0201.1976-0" [38],[12]
  714. ;; 8-Bit Alphanumeric-Katakana Code
  715. ;; "JISX0208.1983-0" [40],[12]
  716. ;; Japanese Graphic Character Set,
  717. ;; GL encoding
  718. ;; "JISX0208.1990-0" [71]
  719. ;; Japanese Graphic Character Set,
  720. ;; GL encoding
  721. ;; "JISX0208.1983-1" [40]
  722. ;; (deprecated)
  723. ;; Japanese Graphic Character Set,
  724. ;; GR encoding
  725. ;; "JISX0212.1990-0" [72]
  726. ;; Supplementary Japanese Graphic Character Set,
  727. ;; GL encoding
  728. ;; "KOI8-R" [119]
  729. ;; Cyrillic alphabet
  730. ;; "KSC5601.1987-0" [41],[12]
  731. ;; Korean Graphic Character Set,
  732. ;; GL encoding
  733. ;; "KSC5601.1987-1" [41]
  734. ;; (deprecated)
  735. ;; Korean Graphic Character Set,
  736. ;; GR encoding
  737. ;; "omron_CNS11643-0" [45]
  738. ;; "omron_CNS11643-1" [45]
  739. ;; "omron_BIG5-0" [45]
  740. ;; "omron_BIG5-1" [45]
  741. ;; "wn.tamil.1993" [103]
  742. (defun set-font-encoding (pattern charset)
  743. "Set arguments in `font-encoding-alist' (which see)."
  744. (let ((slot (assoc pattern font-encoding-alist)))
  745. (if slot
  746. (setcdr slot charset)
  747. (setq font-encoding-alist
  748. (cons (cons pattern charset) font-encoding-alist)))))
  749. (defvar x-pixel-size-width-font-regexp)
  750. (defvar vertical-centering-font-regexp)
  751. ;; Setting for suppressing XLoadQueryFont on big fonts.
  752. (setq x-pixel-size-width-font-regexp
  753. (purecopy "gb2312\\|gbk\\|gb18030\\|jisx0208\\|ksc5601\\|cns11643\\|big5"))
  754. ;; These fonts require vertical centering.
  755. (setq vertical-centering-font-regexp
  756. (purecopy "gb2312\\|gbk\\|gb18030\\|jisx0208\\|jisx0212\\|ksc5601\\|cns11643\\|big5"))
  757. ;; CDAC fonts are actually smaller than their design sizes.
  758. (setq face-font-rescale-alist
  759. (list (cons (purecopy "-cdac$") 1.3)))
  760. (defvar x-font-name-charset-alist nil
  761. "This variable has no meaning now. Just kept for backward compatibility.")
  762. ;;; XLFD (X Logical Font Description) format handler.
  763. ;; Define XLFD's field index numbers. ; field name
  764. (defconst xlfd-regexp-family-subnum 0) ; FOUNDRY and FAMILY
  765. (defconst xlfd-regexp-weight-subnum 1) ; WEIGHT_NAME
  766. (defconst xlfd-regexp-slant-subnum 2) ; SLANT
  767. (defconst xlfd-regexp-swidth-subnum 3) ; SETWIDTH_NAME
  768. (defconst xlfd-regexp-adstyle-subnum 4) ; ADD_STYLE_NAME
  769. (defconst xlfd-regexp-pixelsize-subnum 5) ; PIXEL_SIZE
  770. (defconst xlfd-regexp-pointsize-subnum 6) ; POINT_SIZE
  771. (defconst xlfd-regexp-resx-subnum 7) ; RESOLUTION_X
  772. (defconst xlfd-regexp-resy-subnum 8) ; RESOLUTION_Y
  773. (defconst xlfd-regexp-spacing-subnum 8) ; SPACING
  774. (defconst xlfd-regexp-avgwidth-subnum 10) ; AVERAGE_WIDTH
  775. (defconst xlfd-regexp-registry-subnum 11) ; REGISTRY and ENCODING
  776. ;; Regular expression matching against a fontname which conforms to
  777. ;; XLFD (X Logical Font Description). All fields in XLFD should be
  778. ;; not be omitted (but can be a wild card) to be matched.
  779. (defconst xlfd-tight-regexp
  780. "^\
  781. -\\([^-]*-[^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
  782. -\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
  783. -\\([^-]*\\)-\\([^-]*\\)-\\([^-]*-[^-]*\\)$")
  784. ;; Regular expression matching against a fontname which conforms to
  785. ;; XLFD (X Logical Font Description). All fields in XLFD from FOUNDRY
  786. ;; to ADSTYLE, REGISTRY, and ENCODING should be not be omitted (but
  787. ;; can be a wild card) to be matched.
  788. (defconst xlfd-style-regexp
  789. "^\
  790. -\\([^-]*-[^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-.*\
  791. -\\([^-]*-[^-]*\\)$")
  792. ;; List of field numbers of XLFD whose values are numeric.
  793. (defconst xlfd-regexp-numeric-subnums
  794. (list xlfd-regexp-pixelsize-subnum ;5
  795. xlfd-regexp-pointsize-subnum ;6
  796. xlfd-regexp-resx-subnum ;7
  797. xlfd-regexp-resy-subnum ;8
  798. xlfd-regexp-avgwidth-subnum ;10
  799. ))
  800. (defun x-decompose-font-name (pattern)
  801. "Decompose PATTERN into XLFD fields and return a vector of the fields.
  802. The length of the vector is 12.
  803. The FOUNDRY and FAMILY fields are concatenated and stored in the first
  804. element of the vector.
  805. The REGISTRY and ENCODING fields are concatenated and stored in the last
  806. element of the vector.
  807. Return nil if PATTERN doesn't conform to XLFD."
  808. (if (string-match xlfd-tight-regexp pattern)
  809. (let ((xlfd-fields (make-vector 12 nil)))
  810. (dotimes (i 12)
  811. (aset xlfd-fields i (match-string (1+ i) pattern)))
  812. (dotimes (i 12)
  813. (if (string-match "^[*-]+$" (aref xlfd-fields i))
  814. (aset xlfd-fields i nil)))
  815. xlfd-fields)))
  816. (defun x-compose-font-name (fields &optional reduce)
  817. "Compose X fontname from FIELDS.
  818. FIELDS is a vector of XLFD fields, of length 12.
  819. If a field is nil, wild-card letter `*' is embedded.
  820. Optional argument REDUCE exists just for backward compatibility,
  821. and is always ignored."
  822. (concat "-" (mapconcat (lambda (x) (or x "*")) fields "-")))
  823. (defun x-must-resolve-font-name (xlfd-fields)
  824. "Like `x-resolve-font-name', but always return a font name.
  825. XLFD-FIELDS is a vector of XLFD (X Logical Font Description) fields.
  826. If no font matching XLFD-FIELDS is available, successively replace
  827. parts of the font name pattern with \"*\" until some font is found.
  828. Value is name of that font."
  829. (let ((ascii-font nil) (index 0))
  830. (while (and (null ascii-font) (<= index xlfd-regexp-registry-subnum))
  831. (let ((pattern (x-compose-font-name xlfd-fields)))
  832. (condition-case nil
  833. (setq ascii-font (x-resolve-font-name pattern))
  834. (error
  835. (message "Warning: no fonts matching `%s' available" pattern)
  836. (aset xlfd-fields index "*")
  837. (setq index (1+ index))))))
  838. (unless ascii-font
  839. (error "No fonts found"))
  840. ascii-font))
  841. (defun x-complement-fontset-spec (default-spec fontlist)
  842. "Complement elements of FONTLIST based on DEFAULT-SPEC.
  843. DEFAULT-SPEC is a font-spec object providing default font properties.
  844. FONTLIST is an alist of script names vs the corresponding font names.
  845. The font names are parsed and unspecified font properties are
  846. given from DEFAULT-SPEC."
  847. (let ((prop-list '(:foundry :family :weight :slant :width :adstyle :size)))
  848. (dolist (elt fontlist)
  849. (let ((spec (font-spec :name (cadr elt))))
  850. (dolist (prop prop-list)
  851. (let ((val (font-get spec prop)))
  852. (or val
  853. (font-put spec prop (font-get default-spec prop)))))
  854. (setcar (cdr elt) spec)))
  855. fontlist))
  856. (defun fontset-name-p (fontset)
  857. "Return non-nil if FONTSET is valid as fontset name.
  858. A valid fontset name should conform to XLFD (X Logical Font Description)
  859. with \"fontset\" in `<CHARSET_REGISTRY>' field."
  860. (and (string-match xlfd-tight-regexp fontset)
  861. (string= (match-string (1+ xlfd-regexp-registry-subnum) fontset)
  862. "fontset")))
  863. (declare-function fontset-list "fontset.c" ())
  864. (defun generate-fontset-menu ()
  865. "Return list to be appended to `x-fixed-font-alist'.
  866. Done when `mouse-set-font' is called."
  867. (let (l)
  868. (dolist (fontset (fontset-list))
  869. (or (string-match "fontset-default$" fontset)
  870. (string-match "fontset-auto[0-9]+$" fontset)
  871. (push (list (fontset-plain-name fontset) fontset) l)))
  872. (cons "Fontset"
  873. (sort l #'(lambda (x y) (string< (car x) (car y)))))))
  874. (declare-function query-fontset "fontset.c" (pattern &optional regexpp))
  875. (defun fontset-plain-name (fontset)
  876. "Return a plain and descriptive name of FONTSET."
  877. (if (not (setq fontset (query-fontset fontset)))
  878. (error "Invalid fontset: %s" fontset))
  879. (let ((xlfd-fields (x-decompose-font-name fontset)))
  880. (if xlfd-fields
  881. (let ((family (aref xlfd-fields xlfd-regexp-family-subnum))
  882. (weight (aref xlfd-fields xlfd-regexp-weight-subnum))
  883. (slant (aref xlfd-fields xlfd-regexp-slant-subnum))
  884. (swidth (aref xlfd-fields xlfd-regexp-swidth-subnum))
  885. (size (aref xlfd-fields xlfd-regexp-pixelsize-subnum))
  886. (nickname (aref xlfd-fields xlfd-regexp-registry-subnum))
  887. name)
  888. (if (not (string-match "^fontset-\\(.*\\)$" nickname))
  889. (setq nickname family)
  890. (setq nickname (match-string 1 nickname)))
  891. (if (and size (> (string-to-number size) 0))
  892. (setq name (format "%s: %s-dot" nickname size))
  893. (setq name nickname))
  894. (and weight
  895. (cond ((string-match "^medium$" weight)
  896. (setq name (concat name " " "medium")))
  897. ((string-match "^bold$\\|^demibold$" weight)
  898. (setq name (concat name " " weight)))))
  899. (and slant
  900. (cond ((string-match "^i$" slant)
  901. (setq name (concat name " " "italic")))
  902. ((string-match "^o$" slant)
  903. (setq name (concat name " " "slant")))
  904. ((string-match "^ri$" slant)
  905. (setq name (concat name " " "reverse italic")))
  906. ((string-match "^ro$" slant)
  907. (setq name (concat name " " "reverse slant")))))
  908. name)
  909. fontset)))
  910. (defvar charset-script-alist
  911. '((ascii . latin)
  912. (latin-iso8859-1 . latin)
  913. (latin-iso8859-2 . latin)
  914. (latin-iso8859-3 . latin)
  915. (latin-iso8859-4 . latin)
  916. (latin-iso8859-9 . latin)
  917. (latin-iso8859-10 . latin)
  918. (latin-iso8859-13 . latin)
  919. (latin-iso8859-14 . latin)
  920. (latin-iso8859-15 . latin)
  921. (latin-iso8859-16 . latin)
  922. (latin-jisx0201 . latin)
  923. (thai-tis620 . thai)
  924. (cyrillic-iso8859-5 . cyrillic)
  925. (arabic-iso8859-6 . arabic)
  926. (greek-iso8859-7 . latin)
  927. (hebrew-iso8859-8 . latin)
  928. (katakana-jisx0201 . kana)
  929. (chinese-gb2312 . han)
  930. (chinese-gbk . han)
  931. (gb18030-2-byte . han)
  932. (gb18030-4-byte-bmp . han)
  933. (gb18030-4-byte-ext-1 . han)
  934. (gb18030-4-byte-ext-2 . han)
  935. (gb18030-4-byte-smp . han)
  936. (chinese-big5-1 . han)
  937. (chinese-big5-2 . han)
  938. (chinese-cns11643-1 . han)
  939. (chinese-cns11643-2 . han)
  940. (chinese-cns11643-3 . han)
  941. (chinese-cns11643-4 . han)
  942. (chinese-cns11643-5 . han)
  943. (chinese-cns11643-6 . han)
  944. (chinese-cns11643-7 . han)
  945. (japanese-jisx0208 . han)
  946. (japanese-jisx0208-1978 . han)
  947. (japanese-jisx0212 . han)
  948. (japanese-jisx0213-1 . han)
  949. (japanese-jisx0213-2 . han)
  950. (korean-ksc5601 . hangul)
  951. (chinese-sisheng . bopomofo)
  952. (vietnamese-viscii-lower . latin)
  953. (vietnamese-viscii-upper . latin)
  954. (arabic-digit . arabic)
  955. (arabic-1-column . arabic)
  956. (arabic-2-column . arabic)
  957. (indian-is13194 . devanagari)
  958. (indian-glyph . devanagari)
  959. (indian-1-column . devanagari)
  960. (indian-2-column . devanagari)
  961. (tibetan-1-column . tibetan))
  962. "Alist of charsets vs the corresponding most appropriate scripts.
  963. This alist is used by the function `create-fontset-from-fontset-spec'
  964. to map charsets to scripts.")
  965. (defun create-fontset-from-fontset-spec (fontset-spec
  966. &optional style-variant noerror)
  967. "Create a fontset from fontset specification string FONTSET-SPEC.
  968. FONTSET-SPEC is a string of the format:
  969. FONTSET-NAME,SCRIPT-NAME0:FONT-NAME0,SCRIPT-NAME1:FONT-NAME1, ...
  970. Any number of SPACE, TAB, and NEWLINE can be put before and after commas.
  971. When a frame uses the fontset as the `font' parameter, the frame's
  972. default font name is derived from FONTSET-NAME by substituting
  973. \"iso8859-1\" for the tail part \"fontset-XXX\". But, if SCRIPT-NAMEn
  974. is \"ascii\", use the corresponding FONT-NAMEn as the default font
  975. name.
  976. Optional 2nd and 3rd arguments exist just for backward compatibility,
  977. and are ignored.
  978. It returns a name of the created fontset.
  979. For backward compatibility, SCRIPT-NAME may be a charset name, in
  980. which case, the corresponding script is decided by the variable
  981. `charset-script-alist' (which see)."
  982. (or (string-match "^[^,]+" fontset-spec)
  983. (error "Invalid fontset spec: %s" fontset-spec))
  984. (let ((idx (match-end 0))
  985. (name (match-string 0 fontset-spec))
  986. default-spec target script fontlist)
  987. (or (string-match xlfd-tight-regexp name)
  988. (error "Fontset name \"%s\" not conforming to XLFD" name))
  989. (setq default-spec (font-spec :name name))
  990. ;; At first, extract pairs of charset and fontname from FONTSET-SPEC.
  991. (while (string-match "[, \t\n]*\\([^:]+\\):[ \t]*\\([^,]+\\)"
  992. fontset-spec idx)
  993. (setq idx (match-end 0))
  994. (setq target (intern (match-string 1 fontset-spec)))
  995. (cond ((or (eq target 'ascii)
  996. (memq target (char-table-extra-slot char-script-table 0)))
  997. (push (list target (match-string 2 fontset-spec)) fontlist))
  998. ((setq script (cdr (assq target charset-script-alist)))
  999. (push (list script (match-string 2 fontset-spec)) fontlist))
  1000. ((charsetp target)
  1001. (push (list target (match-string 2 fontset-spec)) fontlist))))
  1002. ;; Complement FONTLIST.
  1003. (setq fontlist (x-complement-fontset-spec default-spec fontlist))
  1004. ;; Create a fontset.
  1005. (new-fontset name (nreverse fontlist))))
  1006. (defun create-fontset-from-ascii-font (font &optional resolved-font
  1007. fontset-name)
  1008. "Create a fontset from an ASCII font FONT.
  1009. Optional 2nd arg RESOLVED-FONT is a resolved name of FONT.
  1010. If omitted, `x-resolve-font-name' is called to get the resolved name.
  1011. At this time, if FONT is not available, an error is signaled.
  1012. Optional 3rd arg FONTSET-NAME is a string to be used in
  1013. `<CHARSET_ENCODING>' fields of a new fontset name. If it is omitted,
  1014. an appropriate name is generated automatically.
  1015. It returns a name of the created fontset."
  1016. (setq font (downcase font))
  1017. (setq resolved-font
  1018. (downcase (or resolved-font (x-resolve-font-name font))))
  1019. (let ((xlfd (x-decompose-font-name resolved-font))
  1020. fontset)
  1021. (if fontset-name
  1022. (setq fontset-name (downcase fontset-name))
  1023. (if (query-fontset "fontset-startup")
  1024. (setq fontset-name
  1025. (subst-char-in-string
  1026. ?- ?_ (aref xlfd xlfd-regexp-registry-subnum) t))
  1027. (setq fontset-name "startup")))
  1028. (aset xlfd xlfd-regexp-registry-subnum
  1029. (format "fontset-%s" fontset-name))
  1030. (setq fontset (x-compose-font-name xlfd))
  1031. (or (query-fontset fontset)
  1032. (create-fontset-from-fontset-spec (concat fontset ", ascii:" font)))))
  1033. ;; Create standard fontset from 16 dots fonts which are the most widely
  1034. ;; installed fonts. Fonts for Chinese-GB, Korean, and Chinese-CNS are
  1035. ;; specified here because FAMILY of those fonts are not "fixed" in
  1036. ;; many cases.
  1037. (defvar standard-fontset-spec
  1038. (purecopy "-*-fixed-medium-r-normal-*-16-*-*-*-*-*-fontset-standard")
  1039. "String of fontset spec of the standard fontset.
  1040. You have the biggest chance to display international characters
  1041. with correct glyphs by using the standard fontset.
  1042. See the documentation of `create-fontset-from-fontset-spec' for the format.")
  1043. ;; Create fontsets from X resources of the name `fontset-N (class
  1044. ;; Fontset-N)' where N is integer 0, 1, ...
  1045. ;; The values of the resources the string of the same format as
  1046. ;; `standard-fontset-spec'.
  1047. (declare-function x-get-resource "frame.c"
  1048. (attribute class &optional component subclass))
  1049. (defun create-fontset-from-x-resource ()
  1050. (let ((idx 0)
  1051. fontset-spec)
  1052. (while (setq fontset-spec (x-get-resource (format "fontset-%d" idx)
  1053. (format "Fontset-%d" idx)))
  1054. (condition-case nil
  1055. (create-fontset-from-fontset-spec fontset-spec t)
  1056. (error (display-warning
  1057. 'initialization
  1058. (format "Fontset-%d: invalid specification in X resource" idx)
  1059. :warning)))
  1060. (setq idx (1+ idx)))))
  1061. ;;
  1062. (provide 'fontset)
  1063. ;;; fontset.el ends here