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