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