1 ;;; fontset.el --- commands for handling fontset
3 ;; Copyright (C) 1997-2011 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5 ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011
6 ;; National Institute of Advanced Industrial Science and Technology (AIST)
7 ;; Registration Number H14PRO021
8 ;; Copyright (C) 2003, 2006
9 ;; National Institute of Advanced Industrial Science and Technology (AIST)
10 ;; Registration Number H13PRO009
12 ;; Keywords: mule, i18n, fontset
14 ;; This file is part of GNU Emacs.
16 ;; GNU Emacs is free software: you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation, either version 3 of the License, or
19 ;; (at your option) any later version.
21 ;; GNU Emacs is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
33 ;; Setup font-encoding-alist for all known encodings.
35 (setq font-encoding-alist
37 (cons (purecopy (car arg
)) (cdr arg
)))
38 '(("iso8859-1$" . iso-8859-1
)
39 ("iso8859-2$" . iso-8859-2
)
40 ("iso8859-3$" . iso-8859-3
)
41 ("iso8859-4$" . iso-8859-4
)
42 ("iso8859-5$" . iso-8859-5
)
43 ("iso8859-6$" . iso-8859-6
)
44 ("iso8859-7$" . iso-8859-7
)
45 ("iso8859-8$" . iso-8859-8
)
46 ("iso8859-9$" . iso-8859-9
)
47 ("iso8859-10$" . iso-8859-10
)
48 ("iso8859-11$" . iso-8859-11
)
49 ("iso8859-13$" . iso-8859-13
)
50 ("iso8859-14$" . iso-8859-14
)
51 ("iso8859-15$" . iso-8859-15
)
52 ("iso8859-16$" . iso-8859-16
)
54 ("gb2312.1980" . chinese-gb2312
)
56 ("gb18030" .
(unicode . nil
))
57 ("jisx0208.1978" . japanese-jisx0208-1978
)
58 ("jisx0208" . japanese-jisx0208
)
59 ("jisx0201" . jisx0201
)
60 ("jisx0212" . japanese-jisx0212
)
61 ("ksc5601.1987" . korean-ksc5601
)
62 ("cns11643.1992.*1" . chinese-cns11643-1
)
63 ("cns11643.1992.*2" . chinese-cns11643-2
)
64 ("cns11643.1992.*3" . chinese-cns11643-3
)
65 ("cns11643.1992.*4" . chinese-cns11643-4
)
66 ("cns11643.1992.*5" . chinese-cns11643-5
)
67 ("cns11643.1992.*6" . chinese-cns11643-6
)
68 ("cns11643.1992.*7" . chinese-cns11643-7
)
69 ("cns11643.92p1-0" . chinese-cns11643-1
)
70 ("cns11643.92p2-0" . chinese-cns11643-2
)
71 ("cns11643.92p3-0" . chinese-cns11643-3
)
72 ("cns11643.92p4-0" . chinese-cns11643-4
)
73 ("cns11643.92p5-0" . chinese-cns11643-5
)
74 ("cns11643.92p6-0" . chinese-cns11643-6
)
75 ("cns11643.92p7-0" . chinese-cns11643-7
)
78 ("tis620" . tis620-2533
)
79 ("microsoft-cp1251" . windows-1251
)
81 ("jisx0213.2000-1" . japanese-jisx0213-1
)
82 ("jisx0213.2000-2" . japanese-jisx0213-2
)
83 ("jisx0213.2004-1" . japanese-jisx0213.2004-
1)
84 ("iso10646-1$" .
(unicode-bmp . nil
))
85 ("iso10646.indian-1" .
(unicode-bmp . nil
))
86 ("unicode-bmp" .
(unicode-bmp . nil
))
87 ("abobe-symbol" . symbol
)
88 ("sisheng_cwnn" . chinese-sisheng
)
89 ("mulearabic-0" . arabic-digit
)
90 ("mulearabic-1" . arabic-1-column
)
91 ("mulearabic-2" . arabic-2-column
)
93 ("ethiopic-unicode" .
(unicode-bmp . ethiopic
))
94 ("is13194-devanagari" . indian-is13194
)
95 ("Devanagari-CDAC" . devanagari-cdac
)
96 ("Sanskrit-CDAC" . sanskrit-cdac
)
97 ("Bengali-CDAC" . bengali-cdac
)
98 ("Assamese-CDAC" . assamese-cdac
)
99 ("Punjabi-CDAC" . punjabi-cdac
)
100 ("Gujarati-CDAC" . gujarati-cdac
)
101 ("Oriya-CDAC" . oriya-cdac
)
102 ("Tamil-CDAC" . tamil-cdac
)
103 ("Telugu-CDAC" . telugu-cdac
)
104 ("Kannada-CDAC" . kannada-cdac
)
105 ("Malayalam-CDAC" . malayalam-cdac
)
106 ("Devanagari-Akruti" . devanagari-akruti
)
107 ("Bengali-Akruti" . bengali-akruti
)
108 ("Punjabi-Akruti" . punjabi-akruti
)
109 ("Gujarati-Akruti" . gujarati-akruti
)
110 ("Oriya-Akruti" . oriya-akruti
)
111 ("Tamil-Akruti" . tamil-akruti
)
112 ("Telugu-Akruti" . telugu-akruti
)
113 ("Kannada-Akruti" . kannada-akruti
)
114 ("Malayalam-Akruti" . malayalam-akruti
)
115 ("muleindian-2" . indian-2-column
)
116 ("muleindian-1" . indian-1-column
)
117 ("mulelao-1" . mule-lao
)
118 ("muletibetan-2" . tibetan
)
119 ("muletibetan-0" . tibetan
)
120 ("muletibetan-1" . tibetan-1-column
))))
122 (defvar font-encoding-charset-alist
)
124 (setq font-encoding-charset-alist
125 '((latin-iso8859-1 . iso-8859-1
)
126 (latin-iso8859-2 . iso-8859-2
)
127 (latin-iso8859-3 . iso-8859-3
)
128 (latin-iso8859-4 . iso-8859-4
)
129 (latin-iso8859-9 . iso-8859-9
)
130 (latin-iso8859-10 . iso-8859-10
)
131 (latin-iso8859-13 . iso-8859-13
)
132 (latin-iso8859-14 . iso-8859-14
)
133 (latin-iso8859-15 . iso-8859-15
)
134 (latin-iso8859-16 . iso-8859-16
)
135 (cyrillic-iso8859-5 . iso-8859-5
)
136 (greek-iso8859-7 . iso-8859-7
)
137 (arabic-iso8859-6 . iso-8859-6
)
138 (thai-tis620 . tis620-2533
)
139 (latin-jisx0201 . jisx0201
)
140 (katakana-jisx0201 . jisx0201
)
141 (chinese-big5-1 . big5
)
142 (chinese-big5-2 . big5
)
143 (vietnamese-viscii-lower . viscii
)
144 (vietnamese-viscii-upper . viscii
)
145 (tibetan . unicode-bmp
)))
147 (setq script-representative-chars
148 '((latin ?A ?Z ?a ?z
#x00C0
#x0100
#x0180
#x1e00
)
149 (phonetic #x250
#x283
)
175 (canadian-aboriginal #x14C0
)
180 (symbol .
[#x201C
#x2200
#x2500
])
182 (ideographic-description #x2FF0
)
193 (aegean-number #x10100
)
194 (ancient-greek-number #x10140
)
195 (ancient-symbol #x10190
)
196 (phaistos-disc #x101D0
)
201 (old-persian #x103A0
)
205 (cypriot-syllabary #x10800
)
210 (cuneiform-numbers-and-punctuation #x12400
)
211 (byzantine-musical-symbol #x1D000
)
212 (musical-symbol #x1D100
)
213 (ancient-greek-musical-notation #x1D200
)
214 (tai-xuan-jing-symbol #x1D300
)
215 (counting-rod-numeral #x1D360
)
216 (mahjong-tile #x1F000
)
217 (domino-tile #x1F030
)))
219 (defvar otf-script-alist
)
221 (setq otf-script-alist
230 (byzm . byzantine-musical-symbol
)
231 (cans . canadian-aboriginal
)
259 (math . mathematical
)
261 (musc . musical-symbol
)
274 (sylo . syloti_nagri
)
288 ;; Set standard fontname specification of characters in the default
289 ;; fontset to find an appropriate font for each script/charset. The
290 ;; specification has the form ((SCRIPT FONT-SPEC ...) ...), where
292 ;; a cons (FAMILY . REGISTRY),
293 ;; or a string FONT-NAME,
294 ;; or an object created by `font-spec'.
296 ;; FAMILY may be nil, in which case, the corresponding name of
297 ;; default face is used. If REGISTRY contains a character `-', the
298 ;; string before that is embedded in `CHARSET_REGISTRY' field, and the
299 ;; string after that is embedded in `CHARSET_ENCODING' field. If it
300 ;; does not contain `-', the whole string is embedded in
301 ;; `CHARSET_REGISTRY' field, and a wild card character `*' is embedded
302 ;; in `CHARSET_ENCODING' field.
304 ;; SCRIPT is a symbol that appears as an element of the char table
305 ;; `char-script-table'. SCRIPT may be a charset specifying the range
308 (declare-function new-fontset
"fontset.c" (name fontlist
))
309 (declare-function set-fontset-font
"fontset.c"
310 (name target font-spec
&optional frame add
))
314 ;; Build a data to initialize the default fontset at compile time to
315 ;; avoid loading charsets that won't be necessary at runtime.
317 ;; The value is (CJK-REGISTRY-VECTOR TARGET-SPEC ...), where
318 ;; CJK-REGISTRY-VECTOR is ["JISX0208.1983-0" "GB2312.1980-0" ...],
319 ;; TARGET-SPEC is (TARGET . BITMASK) or (TARGET SPEC ...),
320 ;; TARGET is CHAR or (FROM-CHAR . TO-CHAR),
321 ;; BITMASK is a bitmask of indices to CJK-REGISTRY-VECTOR,
322 ;; SPEC is a list of arguments to font-spec.
324 (defmacro build-default-fontset-data
()
325 (let* (;; CHARSET-REGISTRY CHARSET FROM-CODE TO-CODE
326 (cjk '(("JISX0208.1983-0" japanese-jisx0208
#x2121
#x287E
)
327 ("GB2312.1980-0" chinese-gb2312
#x2121
#x297E
)
328 ("BIG5-0" big5
#xA140
#xA3FE
)
329 ("CNS11643.1992-1" chinese-cns11643-1
#x2121
#x427E
)
330 ("KSC5601.1987-0" korean-ksc5601
#x2121
#x2C7E
)))
332 (:registry
"iso10646-1" :otf
(tibt nil
(ccmp blws abvs
)))
333 (:family
"mtib" :registry
"iso10646-1")
334 (:registry
"muletibetan-2"))
336 (:registry
"iso10646-1" :script ethiopic
)
337 (:registry
"ethiopic-unicode"))
339 (:registry
"iso10646-1" :script phonetic
)
340 (:registry
"MuleIPA-1")
341 (:registry
"iso10646-1"))))
342 (cjk-table (make-char-table nil
))
347 #'(lambda (range val
)
348 (when (eq val script
)
350 (setq range
(cons (car range
) (cdr range
))))
351 (push range coverage
)))
354 (data (list (vconcat (mapcar 'car cjk
))))
357 (let ((mask (lsh 1 i
)))
359 #'(lambda (range arg
)
360 (let ((from (car range
)) (to (cdr range
)))
363 (or (memq (aref char-script-table from
)
364 '(kana hangul han cjk-misc
))
366 (logior (or (aref cjk-table from
) 0) mask
)))
367 (setq from
(1+ from
))))))
368 (nth 1 elt
) nil
(nth 2 elt
) (nth 3 elt
)))
371 #'(lambda (range val
)
373 (setq range
(cons (car range
) (cdr range
))))
374 (push (cons range val
) data
))
376 (dolist (script scripts
)
377 (dolist (range (funcall script-coverage
(car script
)))
378 (push (cons range
(cdr script
)) data
)))
379 `(quote ,(nreverse data
))))
382 (defun setup-default-fontset ()
383 "Setup the default fontset."
387 (latin (nil .
"ISO8859-1")
397 (nil .
"VISCII1.1-1")
398 ,(font-spec :registry
"iso10646-1" :script
'latin
))
400 (thai ,(font-spec :registry
"iso10646-1" :otf
'(thai nil nil
(mark)))
401 ,(font-spec :registry
"iso10646-1" :script
'thai
)
403 (nil .
"ISO8859-11"))
405 (devanagari ,(font-spec :registry
"iso10646-1" :otf
'(deva nil
(rphf)))
406 (nil .
"iso10646.indian-1"))
407 (bengali ,(font-spec :registry
"iso10646-1" :otf
'(beng nil
(rphf))))
408 (gurmukhi ,(font-spec :registry
"iso10646-1" :otf
'(guru nil
(blwf))))
409 (gujarati ,(font-spec :registry
"iso10646-1" :otf
'(gujr nil
(rphf))))
410 (oriya ,(font-spec :registry
"iso10646-1" :otf
'(orya nil
(rphf))))
411 (tamil ,(font-spec :registry
"iso10646-1" :otf
'(taml nil
(akhn))))
412 (telugu ,(font-spec :registry
"iso10646-1" :otf
'(telu nil
(blwf))))
413 (kannada ,(font-spec :registry
"iso10646-1" :otf
'(knda nil
(rphf))))
414 (sinhala ,(font-spec :registry
"iso10646-1" :otf
'(sinh nil
(akhn))))
415 (malayalam ,(font-spec :registry
"iso10646-1" :otf
'(mlym nil
(akhn))))
417 (burmese ,(font-spec :registry
"iso10646-1" :otf
'(mymr nil nil
))
418 ,(font-spec :registry
"iso10646-1" :script
'burmese
))
420 (lao ,(font-spec :registry
"iso10646-1" :otf
'(lao\ nil nil
(mark)))
421 ,(font-spec :registry
"iso10646-1" :script
'lao
)
424 (tai-viet ("TaiViet" .
"iso10646-1"))
426 (greek ,(font-spec :registry
"iso10646-1" :script
'greek
)
429 (cyrillic ,(font-spec :registry
"iso10646-1" :script
'cyrillic
)
431 (nil .
"microsoft-cp1251")
434 (arabic ,(font-spec :registry
"iso10646-1"
435 :otf
'(arab nil
(init medi fina liga
)))
436 (nil .
"MuleArabic-0")
437 (nil .
"MuleArabic-1")
438 (nil .
"MuleArabic-2")
441 (hebrew ,(font-spec :registry
"iso10646-1" :script
'hebrew
)
444 (khmer ,(font-spec :registry
"iso10646-1" :otf
'(khmr nil
(pres))))
446 (kana (nil .
"JISX0208*")
447 (nil .
"GB2312.1980-0")
448 (nil .
"KSC5601.1987*")
450 (nil .
"JISX0213.2000-1")
451 (nil .
"JISX0213.2004-1")
452 ,(font-spec :registry
"iso10646-1" :script
'kana
))
454 (bopomofo ,(font-spec :registry
"iso10646-1" :script
'bopomofo
)
455 (nil .
"sisheng_cwnn-0"))
457 (han (nil .
"GB2312.1980-0")
461 (nil .
"KSC5601.1987*")
462 (nil .
"CNS11643.1992-1")
463 (nil .
"CNS11643.1992-2")
464 (nil .
"CNS11643.1992-3")
465 (nil .
"CNS11643.1992-4")
466 (nil .
"CNS11643.1992-5")
467 (nil .
"CNS11643.1992-6")
468 (nil .
"CNS11643.1992-7")
471 (nil .
"JISX0213.2000-1")
472 (nil .
"JISX0213.2000-2")
473 (nil .
"JISX0213.2004-1")
474 ,(font-spec :registry
"iso10646-1" :lang
'ja
)
475 ,(font-spec :registry
"iso10646-1" :lang
'zh
))
477 (cjk-misc (nil .
"GB2312.1980-0")
481 (nil .
"KSC5601.1987*")
482 (nil .
"CNS11643.1992-1")
483 (nil .
"CNS11643.1992-2")
484 (nil .
"CNS11643.1992-3")
485 (nil .
"CNS11643.1992-4")
486 (nil .
"CNS11643.1992-5")
487 (nil .
"CNS11643.1992-6")
488 (nil .
"CNS11643.1992-7")
491 (nil .
"JISX0213.2000-1")
492 (nil .
"JISX0213.2000-2")
493 ,(font-spec :registry
"iso10646-1" :lang
'ja
)
494 ,(font-spec :registry
"iso10646-1" :lang
'zh
))
496 (hangul (nil .
"KSC5601.1987-0")
497 ,(font-spec :registry
"iso10646-1" :lang
'ko
))
500 (ascii (nil .
"ISO8859-1"))
501 (arabic-digit ("*" .
"MuleArabic-0"))
502 (arabic-1-column ("*" .
"MuleArabic-1"))
503 (arabic-2-column ("*" .
"MuleArabic-2"))
504 (indian-is13194 (nil .
"is13194-devanagari"))
505 (indian-1-column ("*" .
"muleindian-2"))
507 (devanagari-cdac (nil .
"Devanagari-CDAC"))
508 (sanskrit-cdac (nil .
"Sanskrit-CDAC"))
509 (bengali-cdac (nil .
"Bengali-CDAC"))
510 (assamese-cdac (nil .
"Assamese-CDAC"))
511 (punjabi-cdac (nil .
"Punjabi-CDAC"))
512 (gujarati-cdac (nil .
"Gujarati-CDAC"))
513 (oriya-cdac (nil .
"Oriya-CDAC"))
514 (tamil-cdac (nil .
"Tamil-CDAC"))
515 (telugu-cdac (nil .
"Telugu-CDAC"))
516 (kannada-cdac (nil .
"Kannada-CDAC"))
517 (malayalam-cdac (nil .
"Malayalam-CDAC"))
519 (devanagari-akruti (nil .
"Devanagari-Akruti"))
520 (bengali-akruti (nil .
"Bengali-Akruti"))
521 (punjabi-akruti (nil .
"Punjabi-Akruti"))
522 (gujarati-akruti (nil .
"Gujarati-Akruti"))
523 (oriya-akruti (nil .
"Oriya-Akruti"))
524 (tamil-akruti (nil .
"Tamil-Akruti"))
525 (telugu-akruti (nil .
"Telugu-Akruti"))
526 (kannada-akruti (nil .
"Kannada-Akruti"))
527 (malayalam-akruti (nil .
"Malayalam-Akruti"))
530 (nil (nil .
"gb2312.1980")
534 (nil .
"ksc5601.1987")
535 (nil .
"CNS11643.1992-1")
536 (nil .
"CNS11643.1992-2")
537 (nil .
"CNS11643.1992-3")
538 (nil .
"CNS11643.1992-4")
539 (nil .
"CNS11643.1992-5")
540 (nil .
"CNS11643.1992-6")
541 (nil .
"CNS11643.1992-7")
543 (nil .
"jisx0213.2000-1")
544 (nil .
"jisx0213.2004-1")
548 ;; For simple scripts
549 (dolist (script '(phonetic
578 cuneiform-numbers-and-punctuation
579 byzantine-musical-symbol
581 ancient-greek-musical-notation
586 (set-fontset-font "fontset-default"
587 script
(font-spec :registry
"iso10646-1" :script script
)
590 ;; Special settings for `MATHEMATICAL (U+1D400..U+1D7FF)'.
591 (dolist (math-subgroup '((#x1D400
#x1D433 mathematical-bold
)
592 (#x1D434
#x1D467 mathematical-italic
)
593 (#x1D468
#x1D49B mathematical-bold-italic
)
594 (#x1D49C
#x1D4CF mathematical-script
)
595 (#x1D4D0
#x1D503 mathematical-bold-script
)
596 (#x1D504
#x1D537 mathematical-fraktur
)
597 (#x1D538
#x1D56B mathematical-double-struck
)
598 (#x1D56C
#x1D59F mathematical-bold-fraktur
)
599 (#x1D5A0
#x1D5D3 mathematical-sans-serif
)
600 (#x1D5D4
#x1D607 mathematical-sans-serif-bold
)
601 (#x1D608
#x1D63B mathematical-sans-serif-italic
)
602 (#x1D63C
#x1D66F mathematical-sans-serif-bold-italic
)
603 (#x1D670
#x1D6A3 mathematical-monospace
)
604 (#x1D6A4
#x1D6A5 mathematical-italic
)
605 (#x1D6A8
#x1D6E1 mathematical-bold
)
606 (#x1D6E2
#x1D71B mathematical-italic
)
607 (#x1D71C
#x1D755 mathematical-bold-italic
)
608 (#x1D756
#x1D78F mathematical-sans-serif-bold
)
609 (#x1D790
#x1D7C9 mathematical-sans-serif-bold-italic
)
610 (#x1D7CA
#x1D7D7 mathematical-bold
)
611 (#x1D7D8
#x1D7E1 mathematical-double-struck
)
612 (#x1D7E2
#x1D7EB mathematical-sans-serif
)
613 (#x1D7EC
#x1D7F5 mathematical-sans-serif-bold
)
614 (#x1D7F6
#x1D7FF mathematical-monospace
)))
615 (let ((slot (assq (nth 2 math-subgroup
) script-representative-chars
)))
617 (if (vectorp (cdr slot
))
618 (setcdr slot
(vconcat (cdr slot
) (vector (car math-subgroup
))))
619 (setcdr slot
(vector (cadr slot
) (car math-subgroup
))))
620 (setq slot
(list (nth 2 math-subgroup
) (car math-subgroup
)))
621 (nconc script-representative-chars
(list slot
))))
624 (cons (car math-subgroup
) (nth 1 math-subgroup
))
625 (font-spec :registry
"iso10646-1" :script
(nth 2 math-subgroup
))))
627 ;; Append CJK fonts for characters other than han, kana, cjk-misc.
628 ;; Append fonts for scripts whose name is also a charset name.
629 (let* ((data (build-default-fontset-data))
630 (registries (car data
)))
631 (dolist (target-spec (cdr data
))
632 (let ((target (car target-spec
))
633 (spec (cdr target-spec
)))
635 (dotimes (i (length registries
))
636 (if (> (logand spec
(lsh 1 i
)) 0)
637 (set-fontset-font "fontset-default" target
638 (cons nil
(aref registries i
))
641 (set-fontset-font "fontset-default" target
642 (apply 'font-spec args
) nil
'append
))))))
644 ;; Append Unicode fonts.
645 ;; This may find fonts with more variants (bold, italic) but which
646 ;; don't cover many characters.
647 (set-fontset-font "fontset-default" nil
648 '(nil .
"iso10646-1") nil
'prepend
)
649 ;; These may find fonts that cover many characters but with fewer
651 (set-fontset-font "fontset-default" nil
652 '("gnu-unifont" .
"iso10646-1") nil
'prepend
)
653 (set-fontset-font "fontset-default" nil
654 '("mutt-clearlyu" .
"iso10646-1") nil
'prepend
)
655 (set-fontset-font "fontset-default" '(#x20000 .
#x2FFFF
)
656 '(nil .
"unicode-sip"))
658 (set-fontset-font "fontset-default" '(#xE000 .
#xF8FF
)
659 '(nil .
"iso10646-1"))
660 ;; Don't try the fallback fonts even if no suitable font was found
661 ;; by the above font-spec.
662 (set-fontset-font "fontset-default" '(#xE000 .
#xF8FF
) nil nil
'append
))
664 (defun create-default-fontset ()
665 "Create the default fontset.
666 Internal use only. Should be called at startup time."
668 (setup-default-fontset)
669 (error (display-warning
671 (format "Creation of the default fontsets failed: %s" err
)
674 ;; These are the registered registries/encodings from
675 ;; ftp://ftp.x.org/pub/DOCS/registry 2001/06/01
681 ;; "DEC.CNS11643.1986-2" [53]
682 ;; CNS11643 2-plane using the encoding
683 ;; suggested in that standard
684 ;; "DEC.DTSCS.1990-2" [54]
685 ;; DEC Taiwan Supplemental Character Set
686 ;; "fujitsu.u90x01.1991-0" [87]
687 ;; "fujitsu.u90x03.1991-0" [87]
688 ;; "GB2312.1980-0" [39],[12]
689 ;; China (PRC) Hanzi, GL encoding
690 ;; "GB2312.1980-1" [39]
692 ;; China (PRC) Hanzi, GR encoding
694 ;; HPARABIC8 8-bit character set
696 ;; HPEAST8 8-bit character set
698 ;; HPGREEK8 8-bit character set
700 ;; HPHEBREW8 8-bit character set
701 ;; "HP-Japanese15" [36]
702 ;; HPJAPAN15 15-bit character set,
703 ;; modified from industry defacto
704 ;; standard Shift-JIS
706 ;; HPKANA8 8-bit character set
707 ;; "HP-Korean15" [36]
708 ;; HPKOREAN15 15-bit character set
710 ;; HPROMAN8 8-bit character set
711 ;; "HP-SChinese15" [36]
712 ;; HPSCHINA15 15-bit character set for
713 ;; support of Simplified Chinese
714 ;; "HP-TChinese15" [36]
715 ;; HPTCHINA15 15-bit character set for
716 ;; support of Traditional Chinese
717 ;; "HP-Turkish8" [36]
718 ;; HPTURKISH8 8-bit character set
722 ;; "ISO2022"<REG>"-"<ENC> [44]
723 ;; "ISO646.1991-IRV" [107]
724 ;; ISO 646 International Reference Version
725 ;; "ISO8859-1" [15],[12]
726 ;; ISO Latin alphabet No. 1
727 ;; "ISO8859-2" [15],[12]
728 ;; ISO Latin alphabet No. 2
729 ;; "ISO8859-3" [15],[12]
730 ;; ISO Latin alphabet No. 3
731 ;; "ISO8859-4" [15],[12]
732 ;; ISO Latin alphabet No. 4
733 ;; "ISO8859-5" [15],[12]
734 ;; ISO Latin/Cyrillic alphabet
735 ;; "ISO8859-6" [15],[12]
736 ;; ISO Latin/Arabic alphabet
737 ;; "ISO8859-7" [15],[12]
738 ;; ISO Latin/Greek alphabet
739 ;; "ISO8859-8" [15],[12]
740 ;; ISO Latin/Hebrew alphabet
741 ;; "ISO8859-9" [15],[12]
742 ;; ISO Latin alphabet No. 5
743 ;; "ISO8859-10" [15],[12]
744 ;; ISO Latin alphabet No. 6
745 ;; "ISO8859-13" [15],[12]
746 ;; ISO Latin alphabet No. 7
747 ;; "ISO8859-14" [15],[12]
748 ;; ISO Latin alphabet No. 8
749 ;; "ISO8859-15" [15],[12]
750 ;; ISO Latin alphabet No. 9
753 ;; ISO Latin alphabet No. 9, Final Committee Draft
754 ;; "ISO10646-1" [133]
755 ;; Unicode Universal Multiple-Octet Coded Character Set
756 ;; "ISO10646-MES" [133]
758 ;; Unicode Minimum European Subset
759 ;; "JISX0201.1976-0" [38],[12]
760 ;; 8-Bit Alphanumeric-Katakana Code
761 ;; "JISX0208.1983-0" [40],[12]
762 ;; Japanese Graphic Character Set,
764 ;; "JISX0208.1990-0" [71]
765 ;; Japanese Graphic Character Set,
767 ;; "JISX0208.1983-1" [40]
769 ;; Japanese Graphic Character Set,
771 ;; "JISX0212.1990-0" [72]
772 ;; Supplementary Japanese Graphic Character Set,
776 ;; "KSC5601.1987-0" [41],[12]
777 ;; Korean Graphic Character Set,
779 ;; "KSC5601.1987-1" [41]
781 ;; Korean Graphic Character Set,
783 ;; "omron_CNS11643-0" [45]
784 ;; "omron_CNS11643-1" [45]
785 ;; "omron_BIG5-0" [45]
786 ;; "omron_BIG5-1" [45]
787 ;; "wn.tamil.1993" [103]
789 (defun set-font-encoding (pattern charset
)
790 "Set arguments in `font-encoding-alist' (which see)."
791 (let ((slot (assoc pattern font-encoding-alist
)))
793 (setcdr slot charset
)
794 (setq font-encoding-alist
795 (cons (cons pattern charset
) font-encoding-alist
)))))
797 (defvar x-pixel-size-width-font-regexp
)
798 (defvar vertical-centering-font-regexp
)
800 ;; Setting for suppressing XLoadQueryFont on big fonts.
801 (setq x-pixel-size-width-font-regexp
802 (purecopy "gb2312\\|gbk\\|gb18030\\|jisx0208\\|ksc5601\\|cns11643\\|big5"))
804 ;; These fonts require vertical centering.
805 (setq vertical-centering-font-regexp
806 (purecopy "gb2312\\|gbk\\|gb18030\\|jisx0208\\|jisx0212\\|ksc5601\\|cns11643\\|big5"))
808 ;; CDAC fonts are actually smaller than their design sizes.
809 (setq face-font-rescale-alist
810 (list (cons (purecopy "-cdac$") 1.3)))
812 (defvar x-font-name-charset-alist nil
813 "This variable has no meaning now. Just kept for backward compatibility.")
815 ;;; XLFD (X Logical Font Description) format handler.
817 ;; Define XLFD's field index numbers. ; field name
818 (defconst xlfd-regexp-family-subnum
0) ; FOUNDRY and FAMILY
819 (defconst xlfd-regexp-weight-subnum
1) ; WEIGHT_NAME
820 (defconst xlfd-regexp-slant-subnum
2) ; SLANT
821 (defconst xlfd-regexp-swidth-subnum
3) ; SETWIDTH_NAME
822 (defconst xlfd-regexp-adstyle-subnum
4) ; ADD_STYLE_NAME
823 (defconst xlfd-regexp-pixelsize-subnum
5) ; PIXEL_SIZE
824 (defconst xlfd-regexp-pointsize-subnum
6) ; POINT_SIZE
825 (defconst xlfd-regexp-resx-subnum
7) ; RESOLUTION_X
826 (defconst xlfd-regexp-resy-subnum
8) ; RESOLUTION_Y
827 (defconst xlfd-regexp-spacing-subnum
8) ; SPACING
828 (defconst xlfd-regexp-avgwidth-subnum
10) ; AVERAGE_WIDTH
829 (defconst xlfd-regexp-registry-subnum
11) ; REGISTRY and ENCODING
831 ;; Regular expression matching against a fontname which conforms to
832 ;; XLFD (X Logical Font Description). All fields in XLFD should be
833 ;; not be omitted (but can be a wild card) to be matched.
834 (defconst xlfd-tight-regexp
836 -\\([^-]*-[^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
837 -\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
838 -\\([^-]*\\)-\\([^-]*\\)-\\([^-]*-[^-]*\\)$")
840 ;; Regular expression matching against a fontname which conforms to
841 ;; XLFD (X Logical Font Description). All fields in XLFD from FOUNDRY
842 ;; to ADSTYLE, REGISTRY, and ENCODING should be not be omitted (but
843 ;; can be a wild card) to be matched.
844 (defconst xlfd-style-regexp
846 -\\([^-]*-[^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-.*\
847 -\\([^-]*-[^-]*\\)$")
849 ;; List of field numbers of XLFD whose values are numeric.
850 (defconst xlfd-regexp-numeric-subnums
851 (list xlfd-regexp-pixelsize-subnum
;5
852 xlfd-regexp-pointsize-subnum
;6
853 xlfd-regexp-resx-subnum
;7
854 xlfd-regexp-resy-subnum
;8
855 xlfd-regexp-avgwidth-subnum
;10
858 (defun x-decompose-font-name (pattern)
859 "Decompose PATTERN into XLFD fields and return a vector of the fields.
860 The length of the vector is 12.
861 The FOUNDRY and FAMILY fields are concatinated and stored in the first
862 element of the vector.
863 The REGISTRY and ENCODING fields are concatinated and stored in the last
864 element of the vector.
866 Return nil if PATTERN doesn't conform to XLFD."
867 (if (string-match xlfd-tight-regexp pattern
)
868 (let ((xlfd-fields (make-vector 12 nil
)))
870 (aset xlfd-fields i
(match-string (1+ i
) pattern
)))
872 (if (string-match "^[*-]+$" (aref xlfd-fields i
))
873 (aset xlfd-fields i nil
)))
876 (defun x-compose-font-name (fields &optional reduce
)
877 "Compose X fontname from FIELDS.
878 FIELDS is a vector of XLFD fields, of length 12.
879 If a field is nil, wild-card letter `*' is embedded.
880 Optional argument REDUCE exists just for backward compatibility,
881 and is always ignored."
882 (concat "-" (mapconcat (lambda (x) (or x
"*")) fields
"-")))
885 (defun x-must-resolve-font-name (xlfd-fields)
886 "Like `x-resolve-font-name', but always return a font name.
887 XLFD-FIELDS is a vector of XLFD (X Logical Font Description) fields.
888 If no font matching XLFD-FIELDS is available, successively replace
889 parts of the font name pattern with \"*\" until some font is found.
890 Value is name of that font."
891 (let ((ascii-font nil
) (index 0))
892 (while (and (null ascii-font
) (<= index xlfd-regexp-registry-subnum
))
893 (let ((pattern (x-compose-font-name xlfd-fields
)))
895 (setq ascii-font
(x-resolve-font-name pattern
))
897 (message "Warning: no fonts matching `%s' available" pattern
)
898 (aset xlfd-fields index
"*")
899 (setq index
(1+ index
))))))
901 (error "No fonts found"))
905 (defun x-complement-fontset-spec (default-spec fontlist
)
906 "Complement elements of FONTLIST based on DEFAULT-SPEC.
907 DEFAULT-SPEC is a font-spec object providing default font properties.
908 FONTLIST is an alist of script names vs the corresponding font names.
910 The font names are parsed and unspecified font properties are
911 given from DEFAULT-SPEC."
912 (let ((prop-list '(:foundry
:family
:weight
:slant
:width
:adstyle
:size
)))
913 (dolist (elt fontlist
)
914 (let ((spec (font-spec :name
(cadr elt
))))
915 (dolist (prop prop-list
)
916 (let ((val (font-get spec prop
)))
918 (font-put spec prop
(font-get default-spec prop
)))))
919 (setcar (cdr elt
) spec
)))
922 (defun fontset-name-p (fontset)
923 "Return non-nil if FONTSET is valid as fontset name.
924 A valid fontset name should conform to XLFD (X Logical Font Description)
925 with \"fontset\" in `<CHARSET_REGISTRY>' field."
926 (and (string-match xlfd-tight-regexp fontset
)
927 (string= (match-string (1+ xlfd-regexp-registry-subnum
) fontset
)
930 (declare-function fontset-list
"fontset.c" ())
932 (defun generate-fontset-menu ()
933 "Return list to be appended to `x-fixed-font-alist'.
934 Done when `mouse-set-font' is called."
936 (dolist (fontset (fontset-list))
937 (or (string-match "fontset-default$" fontset
)
938 (string-match "fontset-auto[0-9]+$" fontset
)
939 (push (list (fontset-plain-name fontset
) fontset
) l
)))
941 (sort l
#'(lambda (x y
) (string< (car x
) (car y
)))))))
943 (declare-function query-fontset
"fontset.c" (pattern &optional regexpp
))
945 (defun fontset-plain-name (fontset)
946 "Return a plain and descriptive name of FONTSET."
947 (if (not (setq fontset
(query-fontset fontset
)))
948 (error "Invalid fontset: %s" fontset
))
949 (let ((xlfd-fields (x-decompose-font-name fontset
)))
951 (let ((family (aref xlfd-fields xlfd-regexp-family-subnum
))
952 (weight (aref xlfd-fields xlfd-regexp-weight-subnum
))
953 (slant (aref xlfd-fields xlfd-regexp-slant-subnum
))
954 (swidth (aref xlfd-fields xlfd-regexp-swidth-subnum
))
955 (size (aref xlfd-fields xlfd-regexp-pixelsize-subnum
))
956 (nickname (aref xlfd-fields xlfd-regexp-registry-subnum
))
958 (if (not (string-match "^fontset-\\(.*\\)$" nickname
))
959 (setq nickname family
)
960 (setq nickname
(match-string 1 nickname
)))
961 (if (and size
(> (string-to-number size
) 0))
962 (setq name
(format "%s: %s-dot" nickname size
))
963 (setq name nickname
))
965 (cond ((string-match "^medium$" weight
)
966 (setq name
(concat name
" " "medium")))
967 ((string-match "^bold$\\|^demibold$" weight
)
968 (setq name
(concat name
" " weight
)))))
970 (cond ((string-match "^i$" slant
)
971 (setq name
(concat name
" " "italic")))
972 ((string-match "^o$" slant
)
973 (setq name
(concat name
" " "slant")))
974 ((string-match "^ri$" slant
)
975 (setq name
(concat name
" " "reverse italic")))
976 ((string-match "^ro$" slant
)
977 (setq name
(concat name
" " "reverse slant")))))
981 (defvar charset-script-alist
983 (latin-iso8859-1 . latin
)
984 (latin-iso8859-2 . latin
)
985 (latin-iso8859-3 . latin
)
986 (latin-iso8859-4 . latin
)
987 (latin-iso8859-9 . latin
)
988 (latin-iso8859-10 . latin
)
989 (latin-iso8859-13 . latin
)
990 (latin-iso8859-14 . latin
)
991 (latin-iso8859-15 . latin
)
992 (latin-iso8859-16 . latin
)
993 (latin-jisx0201 . latin
)
995 (cyrillic-iso8859-5 . cyrillic
)
996 (arabic-iso8859-6 . arabic
)
997 (greek-iso8859-7 . latin
)
998 (hebrew-iso8859-8 . latin
)
999 (katakana-jisx0201 . kana
)
1000 (chinese-gb2312 . han
)
1002 (gb18030-2-byte . han
)
1003 (gb18030-4-byte-bmp . han
)
1004 (gb18030-4-byte-ext-1 . han
)
1005 (gb18030-4-byte-ext-2 . han
)
1006 (gb18030-4-byte-smp . han
)
1007 (chinese-big5-1 . han
)
1008 (chinese-big5-2 . han
)
1009 (chinese-cns11643-1 . han
)
1010 (chinese-cns11643-2 . han
)
1011 (chinese-cns11643-3 . han
)
1012 (chinese-cns11643-4 . han
)
1013 (chinese-cns11643-5 . han
)
1014 (chinese-cns11643-6 . han
)
1015 (chinese-cns11643-7 . han
)
1016 (japanese-jisx0208 . han
)
1017 (japanese-jisx0208-1978 . han
)
1018 (japanese-jisx0212 . han
)
1019 (japanese-jisx0213-1 . han
)
1020 (japanese-jisx0213-2 . han
)
1021 (korean-ksc5601 . hangul
)
1022 (chinese-sisheng . bopomofo
)
1023 (vietnamese-viscii-lower . latin
)
1024 (vietnamese-viscii-upper . latin
)
1025 (arabic-digit . arabic
)
1026 (arabic-1-column . arabic
)
1027 (arabic-2-column . arabic
)
1028 (indian-is13194 . devanagari
)
1029 (indian-glyph . devanagari
)
1030 (indian-1-column . devanagari
)
1031 (indian-2-column . devanagari
)
1032 (tibetan-1-column . tibetan
))
1033 "Alist of charsets vs the corresponding most appropriate scripts.
1035 This alist is used by the function `create-fontset-from-fontset-spec'
1036 to map charsets to scripts.")
1038 (defun create-fontset-from-fontset-spec (fontset-spec
1039 &optional style-variant noerror
)
1040 "Create a fontset from fontset specification string FONTSET-SPEC.
1041 FONTSET-SPEC is a string of the format:
1042 FONTSET-NAME,SCRIPT-NAME0:FONT-NAME0,SCRIPT-NAME1:FONT-NAME1, ...
1043 Any number of SPACE, TAB, and NEWLINE can be put before and after commas.
1045 When a frame uses the fontset as the `font' parameter, the frame's
1046 default font name is derived from FONTSET-NAME by substituting
1047 \"iso8859-1\" for the tail part \"fontset-XXX\". But, if SCRIPT-NAMEn
1048 is \"ascii\", use the corresponding FONT-NAMEn as the default font
1051 Optional 2nd and 3rd arguments exist just for backward compatibility,
1054 It returns a name of the created fontset.
1056 For backward compatibility, SCRIPT-NAME may be a charset name, in
1057 which case, the corresponding script is decided by the variable
1058 `charset-script-alist' (which see)."
1059 (or (string-match "^[^,]+" fontset-spec
)
1060 (error "Invalid fontset spec: %s" fontset-spec
))
1061 (let ((idx (match-end 0))
1062 (name (match-string 0 fontset-spec
))
1063 default-spec target script fontlist
)
1064 (or (string-match xlfd-tight-regexp name
)
1065 (error "Fontset name \"%s\" not conforming to XLFD" name
))
1066 (setq default-spec
(font-spec :name name
))
1067 ;; At first, extract pairs of charset and fontname from FONTSET-SPEC.
1068 (while (string-match "[, \t\n]*\\([^:]+\\):[ \t]*\\([^,]+\\)"
1070 (setq idx
(match-end 0))
1071 (setq target
(intern (match-string 1 fontset-spec
)))
1072 (cond ((or (eq target
'ascii
)
1073 (memq target
(char-table-extra-slot char-script-table
0)))
1074 (push (list target
(match-string 2 fontset-spec
)) fontlist
))
1075 ((setq script
(cdr (assq target charset-script-alist
)))
1076 (push (list script
(match-string 2 fontset-spec
)) fontlist
))
1078 (push (list target
(match-string 2 fontset-spec
)) fontlist
))))
1080 ;; Complement FONTLIST.
1081 (setq fontlist
(x-complement-fontset-spec default-spec fontlist
))
1083 ;; Create a fontset.
1084 (new-fontset name
(nreverse fontlist
))))
1086 (defun create-fontset-from-ascii-font (font &optional resolved-font
1088 "Create a fontset from an ASCII font FONT.
1090 Optional 2nd arg RESOLVED-FONT is a resolved name of FONT.
1091 If omitted, `x-resolve-font-name' is called to get the resolved name.
1092 At this time, if FONT is not available, an error is signaled.
1094 Optional 3rd arg FONTSET-NAME is a string to be used in
1095 `<CHARSET_ENCODING>' fields of a new fontset name. If it is omitted,
1096 an appropriate name is generated automatically.
1098 It returns a name of the created fontset."
1099 (setq font
(downcase font
))
1101 (downcase (or resolved-font
(x-resolve-font-name font
))))
1102 (let ((xlfd (x-decompose-font-name resolved-font
))
1105 (setq fontset-name
(downcase fontset-name
))
1106 (if (query-fontset "fontset-startup")
1108 (subst-char-in-string
1109 ?- ?_
(aref xlfd xlfd-regexp-registry-subnum
) t
))
1110 (setq fontset-name
"startup")))
1111 (aset xlfd xlfd-regexp-registry-subnum
1112 (format "fontset-%s" fontset-name
))
1113 (setq fontset
(x-compose-font-name xlfd
))
1114 (or (query-fontset fontset
)
1115 (create-fontset-from-fontset-spec (concat fontset
", ascii:" font
)))))
1118 ;; Create standard fontset from 16 dots fonts which are the most widely
1119 ;; installed fonts. Fonts for Chinese-GB, Korean, and Chinese-CNS are
1120 ;; specified here because FAMILY of those fonts are not "fixed" in
1122 (defvar standard-fontset-spec
1123 (purecopy "-*-fixed-medium-r-normal-*-16-*-*-*-*-*-fontset-standard")
1124 "String of fontset spec of the standard fontset.
1125 You have the biggest chance to display international characters
1126 with correct glyphs by using the standard fontset.
1127 See the documentation of `create-fontset-from-fontset-spec' for the format.")
1130 ;; Create fontsets from X resources of the name `fontset-N (class
1131 ;; Fontset-N)' where N is integer 0, 1, ...
1132 ;; The values of the resources the string of the same format as
1133 ;; `standard-fontset-spec'.
1135 (declare-function x-get-resource
"frame.c"
1136 (attribute class
&optional component subclass
))
1138 (defun create-fontset-from-x-resource ()
1141 (while (setq fontset-spec
(x-get-resource (format "fontset-%d" idx
)
1142 (format "Fontset-%d" idx
)))
1144 (create-fontset-from-fontset-spec fontset-spec t
)
1145 (error (display-warning
1147 (format "Fontset-%d: invalid specification in X resource" idx
)
1149 (setq idx
(1+ idx
)))))
1154 ;;; fontset.el ends here