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