Commit | Line | Data |
---|---|---|
4ed46869 | 1 | /* Fontset handler. |
76b6f707 | 2 | Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 |
429ab54e | 3 | Free Software Foundation, Inc. |
7976eda0 | 4 | Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, |
76b6f707 | 5 | 2005, 2006, 2007, 2008, 2009 |
ce03bf76 KH |
6 | National Institute of Advanced Industrial Science and Technology (AIST) |
7 | Registration Number H14PRO021 | |
8aa07a8d | 8 | Copyright (C) 2003, 2006 |
06f76f0d KH |
9 | National Institute of Advanced Industrial Science and Technology (AIST) |
10 | Registration Number H13PRO009 | |
eb152aa9 | 11 | |
369314dc KH |
12 | This file is part of GNU Emacs. |
13 | ||
9ec0b715 | 14 | GNU Emacs is free software: you can redistribute it and/or modify |
369314dc | 15 | it under the terms of the GNU General Public License as published by |
9ec0b715 GM |
16 | the Free Software Foundation, either version 3 of the License, or |
17 | (at your option) any later version. | |
4ed46869 | 18 | |
369314dc KH |
19 | GNU Emacs is distributed in the hope that it will be useful, |
20 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 | GNU General Public License for more details. | |
4ed46869 | 23 | |
369314dc | 24 | You should have received a copy of the GNU General Public License |
9ec0b715 | 25 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
4ed46869 | 26 | |
0d407d77 KH |
27 | /* #define FONTSET_DEBUG */ |
28 | ||
4ed46869 | 29 | #include <config.h> |
0d407d77 | 30 | #include <stdio.h> |
0d407d77 | 31 | |
4ed46869 | 32 | #include "lisp.h" |
06f76f0d | 33 | #include "blockinput.h" |
1ff005e1 | 34 | #include "buffer.h" |
06f76f0d | 35 | #include "character.h" |
4ed46869 KH |
36 | #include "charset.h" |
37 | #include "ccl.h" | |
2538fae4 | 38 | #include "keyboard.h" |
4ed46869 | 39 | #include "frame.h" |
0d407d77 | 40 | #include "dispextern.h" |
e1a14cdc | 41 | #include "intervals.h" |
3541bb8f | 42 | #include "fontset.h" |
0d407d77 | 43 | #include "window.h" |
92c15c34 KH |
44 | #ifdef HAVE_X_WINDOWS |
45 | #include "xterm.h" | |
46 | #endif | |
47 | #ifdef WINDOWSNT | |
48 | #include "w32term.h" | |
49 | #endif | |
edfda783 AR |
50 | #ifdef HAVE_NS |
51 | #include "nsterm.h" | |
52 | #endif | |
fa971ac3 | 53 | #include "termhooks.h" |
0d407d77 | 54 | |
8aa07a8d | 55 | #include "font.h" |
8aa07a8d | 56 | |
0d407d77 | 57 | #undef xassert |
8f924df7 | 58 | #ifdef FONTSET_DEBUG |
0d407d77 KH |
59 | #define xassert(X) do {if (!(X)) abort ();} while (0) |
60 | #undef INLINE | |
61 | #define INLINE | |
8f924df7 KH |
62 | #else /* not FONTSET_DEBUG */ |
63 | #define xassert(X) (void) 0 | |
64 | #endif /* not FONTSET_DEBUG */ | |
0d407d77 | 65 | |
a980c932 | 66 | EXFUN (Fclear_face_cache, 1); |
0d407d77 KH |
67 | |
68 | /* FONTSET | |
69 | ||
70 | A fontset is a collection of font related information to give | |
1d5d7200 KH |
71 | similar appearance (style, etc) of characters. A fontset has two |
72 | roles. One is to use for the frame parameter `font' as if it is an | |
73 | ASCII font. In that case, Emacs uses the font specified for | |
74 | `ascii' script for the frame's default font. | |
75 | ||
76 | Another role, the more important one, is to provide information | |
77 | about which font to use for each non-ASCII character. | |
78 | ||
79 | There are two kinds of fontsets; base and realized. A base fontset | |
80 | is created by `new-fontset' from Emacs Lisp explicitly. A realized | |
81 | fontset is created implicitly when a face is realized for ASCII | |
82 | characters. A face is also realized for non-ASCII characters based | |
83 | on an ASCII face. All of non-ASCII faces based on the same ASCII | |
84 | face share the same realized fontset. | |
8f924df7 | 85 | |
06f76f0d KH |
86 | A fontset object is implemented by a char-table whose default value |
87 | and parent are always nil. | |
fc8865fc | 88 | |
1d5d7200 KH |
89 | An element of a base fontset is a vector of FONT-DEFs which itself |
90 | is a vector [ FONT-SPEC ENCODING REPERTORY ]. | |
91 | ||
f088b054 KH |
92 | An element of a realized fontset is nil, t, 0, or a vector of this |
93 | form: | |
7e1a1cd9 | 94 | |
581f7ac7 KH |
95 | [ CHARSET-ORDERED-LIST-TICK PREFERRED-RFONT-DEF |
96 | RFONT-DEF0 RFONT-DEF1 ... ] | |
0d407d77 | 97 | |
7e1a1cd9 | 98 | RFONT-DEFn (i.e. Realized FONT-DEF) has this form: |
0d407d77 | 99 | |
581f7ac7 | 100 | [ FACE-ID FONT-DEF FONT-OBJECT SORTING-SCORE ] |
0d407d77 | 101 | |
581f7ac7 | 102 | RFONT-DEFn are automatically reordered by the current charset |
1d5d7200 | 103 | priority list. |
0d407d77 | 104 | |
7e1a1cd9 KH |
105 | The value nil means that we have not yet generated the above vector |
106 | from the base of the fontset. | |
0d407d77 | 107 | |
1d5d7200 KH |
108 | The value t means that no font is available for the corresponding |
109 | range of characters. | |
0d407d77 | 110 | |
f088b054 KH |
111 | The value 0 means that no font is available for the corresponding |
112 | range of characters in this fontset, but may be available in the | |
113 | default fontset. | |
114 | ||
0d407d77 | 115 | |
eb36588a | 116 | A fontset has 9 extra slots. |
0d407d77 | 117 | |
1d5d7200 | 118 | The 1st slot: the ID number of the fontset |
0d407d77 | 119 | |
1d5d7200 KH |
120 | The 2nd slot: |
121 | base: the name of the fontset | |
122 | realized: nil | |
0d407d77 | 123 | |
1d5d7200 | 124 | The 3rd slot: |
d6aaac9e | 125 | base: nil |
1d5d7200 | 126 | realized: the base fontset |
06f76f0d | 127 | |
1d5d7200 KH |
128 | The 4th slot: |
129 | base: nil | |
130 | realized: the frame that the fontset belongs to | |
0d407d77 | 131 | |
1d5d7200 KH |
132 | The 5th slot: |
133 | base: the font name for ASCII characters | |
134 | realized: nil | |
0d407d77 | 135 | |
1d5d7200 KH |
136 | The 6th slot: |
137 | base: nil | |
138 | realized: the ID number of a face to use for characters that | |
139 | has no font in a realized fontset. | |
0d407d77 | 140 | |
1d5d7200 KH |
141 | The 7th slot: |
142 | base: nil | |
143 | realized: Alist of font index vs the corresponding repertory | |
144 | char-table. | |
eb152aa9 | 145 | |
d6aaac9e KH |
146 | The 8th slot: |
147 | base: nil | |
148 | realized: If the base is not the default fontset, a fontset | |
149 | realized from the default fontset, else nil. | |
1d5d7200 | 150 | |
eb36588a | 151 | The 9th slot: |
cc7b6145 KH |
152 | base: Same as element value (but for fallback fonts). |
153 | realized: Likewise. | |
eb36588a | 154 | |
1d5d7200 | 155 | All fontsets are recorded in the vector Vfontset_table. |
0d407d77 KH |
156 | |
157 | ||
158 | DEFAULT FONTSET | |
159 | ||
1d5d7200 KH |
160 | There's a special base fontset named `default fontset' which |
161 | defines the default font specifications. When a base fontset | |
162 | doesn't specify a font for a specific character, the corresponding | |
163 | value in the default fontset is used. | |
0d407d77 | 164 | |
afe93d01 KH |
165 | The parent of a realized fontset created for such a face that has |
166 | no fontset is the default fontset. | |
0d407d77 KH |
167 | |
168 | ||
169 | These structures are hidden from the other codes than this file. | |
170 | The other codes handle fontsets only by their ID numbers. They | |
06f76f0d KH |
171 | usually use the variable name `fontset' for IDs. But, in this |
172 | file, we always use varialbe name `id' for IDs, and name `fontset' | |
1d5d7200 | 173 | for an actual fontset object, i.e., char-table. |
0d407d77 KH |
174 | |
175 | */ | |
176 | ||
177 | /********** VARIABLES and FUNCTION PROTOTYPES **********/ | |
178 | ||
179 | extern Lisp_Object Qfont; | |
d6aaac9e KH |
180 | static Lisp_Object Qfontset; |
181 | static Lisp_Object Qfontset_info; | |
1d5d7200 | 182 | static Lisp_Object Qprepend, Qappend; |
ef6e0694 | 183 | Lisp_Object Qlatin; |
0d407d77 KH |
184 | |
185 | /* Vector containing all fontsets. */ | |
186 | static Lisp_Object Vfontset_table; | |
187 | ||
fc8865fc | 188 | /* Next possibly free fontset ID. Usually this keeps the minimum |
0d407d77 KH |
189 | fontset ID not yet used. */ |
190 | static int next_fontset_id; | |
191 | ||
192 | /* The default fontset. This gives default FAMILY and REGISTRY of | |
06f76f0d | 193 | font for each character. */ |
0d407d77 | 194 | static Lisp_Object Vdefault_fontset; |
4ed46869 | 195 | |
28e2436a | 196 | Lisp_Object Vfont_encoding_charset_alist; |
6a7e6d80 | 197 | Lisp_Object Vuse_default_ascent; |
2aeafb78 | 198 | Lisp_Object Vignore_relative_composition; |
01d4b817 | 199 | Lisp_Object Valternate_fontname_alist; |
1c283e35 | 200 | Lisp_Object Vfontset_alias_alist; |
810abb87 | 201 | Lisp_Object Vvertical_centering_font_regexp; |
21ff5ed6 | 202 | Lisp_Object Votf_script_alist; |
4ed46869 | 203 | |
4ed46869 | 204 | /* Check if any window system is used now. */ |
5771dcf4 | 205 | void (*check_window_system_func) P_ ((void)); |
4ed46869 | 206 | |
0d407d77 KH |
207 | |
208 | /* Prototype declarations for static functions. */ | |
b11a4ed7 DL |
209 | static Lisp_Object fontset_add P_ ((Lisp_Object, Lisp_Object, Lisp_Object, |
210 | Lisp_Object)); | |
581f7ac7 KH |
211 | static Lisp_Object fontset_find_font P_ ((Lisp_Object, int, struct face *, |
212 | int, int)); | |
41ad6003 | 213 | static void reorder_font_vector P_ ((Lisp_Object, struct font *)); |
7e1a1cd9 | 214 | static Lisp_Object fontset_font P_ ((Lisp_Object, int, struct face *, int)); |
0d407d77 | 215 | static Lisp_Object make_fontset P_ ((Lisp_Object, Lisp_Object, Lisp_Object)); |
0d407d77 | 216 | static Lisp_Object fontset_pattern_regexp P_ ((Lisp_Object)); |
1d5d7200 KH |
217 | static void accumulate_script_ranges P_ ((Lisp_Object, Lisp_Object, |
218 | Lisp_Object)); | |
8aa07a8d | 219 | Lisp_Object find_font_encoding P_ ((Lisp_Object)); |
0d407d77 | 220 | |
2449d4d0 KH |
221 | static void set_fontset_font P_ ((Lisp_Object, Lisp_Object)); |
222 | ||
556383ac KH |
223 | #ifdef FONTSET_DEBUG |
224 | ||
225 | /* Return 1 if ID is a valid fontset id, else return 0. */ | |
226 | ||
227 | static int | |
228 | fontset_id_valid_p (id) | |
229 | int id; | |
230 | { | |
231 | return (id >= 0 && id < ASIZE (Vfontset_table) - 1); | |
232 | } | |
233 | ||
234 | #endif | |
235 | ||
0d407d77 KH |
236 | |
237 | \f | |
238 | /********** MACROS AND FUNCTIONS TO HANDLE FONTSET **********/ | |
239 | ||
0d407d77 KH |
240 | /* Return the fontset with ID. No check of ID's validness. */ |
241 | #define FONTSET_FROM_ID(id) AREF (Vfontset_table, id) | |
242 | ||
afe93d01 | 243 | /* Macros to access special values of FONTSET. */ |
0d407d77 | 244 | #define FONTSET_ID(fontset) XCHAR_TABLE (fontset)->extras[0] |
06f76f0d KH |
245 | |
246 | /* Macros to access special values of (base) FONTSET. */ | |
0d407d77 | 247 | #define FONTSET_NAME(fontset) XCHAR_TABLE (fontset)->extras[1] |
06f76f0d | 248 | #define FONTSET_ASCII(fontset) XCHAR_TABLE (fontset)->extras[4] |
581f7ac7 | 249 | #define FONTSET_SPEC(fontset) XCHAR_TABLE (fontset)->extras[5] |
06f76f0d | 250 | |
06f76f0d KH |
251 | /* Macros to access special values of (realized) FONTSET. */ |
252 | #define FONTSET_BASE(fontset) XCHAR_TABLE (fontset)->extras[2] | |
253 | #define FONTSET_FRAME(fontset) XCHAR_TABLE (fontset)->extras[3] | |
9459b1e9 | 254 | #define FONTSET_OBJLIST(fontset) XCHAR_TABLE (fontset)->extras[4] |
1d5d7200 KH |
255 | #define FONTSET_NOFONT_FACE(fontset) XCHAR_TABLE (fontset)->extras[5] |
256 | #define FONTSET_REPERTORY(fontset) XCHAR_TABLE (fontset)->extras[6] | |
eb36588a KH |
257 | #define FONTSET_DEFAULT(fontset) XCHAR_TABLE (fontset)->extras[7] |
258 | ||
cc7b6145 | 259 | /* For both base and realized fontset. */ |
eb36588a | 260 | #define FONTSET_FALLBACK(fontset) XCHAR_TABLE (fontset)->extras[8] |
0d407d77 | 261 | |
e3400864 | 262 | #define BASE_FONTSET_P(fontset) (NILP (FONTSET_BASE (fontset))) |
0d407d77 KH |
263 | |
264 | ||
581f7ac7 KH |
265 | /* Macros for FONT-DEF and RFONT-DEF of fontset. */ |
266 | #define FONT_DEF_NEW(font_def, font_spec, encoding, repertory) \ | |
267 | do { \ | |
268 | (font_def) = Fmake_vector (make_number (3), (font_spec)); \ | |
269 | ASET ((font_def), 1, encoding); \ | |
270 | ASET ((font_def), 2, repertory); \ | |
271 | } while (0) | |
272 | ||
273 | #define FONT_DEF_SPEC(font_def) AREF (font_def, 0) | |
274 | #define FONT_DEF_ENCODING(font_def) AREF (font_def, 1) | |
275 | #define FONT_DEF_REPERTORY(font_def) AREF (font_def, 2) | |
276 | ||
277 | #define RFONT_DEF_FACE(rfont_def) AREF (rfont_def, 0) | |
278 | #define RFONT_DEF_SET_FACE(rfont_def, face_id) \ | |
279 | ASET ((rfont_def), 0, make_number (face_id)) | |
280 | #define RFONT_DEF_FONT_DEF(rfont_def) AREF (rfont_def, 1) | |
281 | #define RFONT_DEF_SPEC(rfont_def) FONT_DEF_SPEC (AREF (rfont_def, 1)) | |
282 | #define RFONT_DEF_REPERTORY(rfont_def) FONT_DEF_REPERTORY (AREF (rfont_def, 1)) | |
283 | #define RFONT_DEF_OBJECT(rfont_def) AREF (rfont_def, 2) | |
284 | #define RFONT_DEF_SET_OBJECT(rfont_def, object) \ | |
285 | ASET ((rfont_def), 2, (object)) | |
286 | #define RFONT_DEF_SCORE(rfont_def) XINT (AREF (rfont_def, 3)) | |
287 | #define RFONT_DEF_SET_SCORE(rfont_def, score) \ | |
288 | ASET ((rfont_def), 3, make_number (score)) | |
289 | #define RFONT_DEF_NEW(rfont_def, font_def) \ | |
290 | do { \ | |
291 | (rfont_def) = Fmake_vector (make_number (4), Qnil); \ | |
292 | ASET ((rfont_def), 1, (font_def)); \ | |
293 | RFONT_DEF_SET_SCORE ((rfont_def), 0); \ | |
294 | } while (0) | |
295 | ||
296 | ||
1d5d7200 KH |
297 | /* Return the element of FONTSET for the character C. If FONTSET is a |
298 | base fontset other then the default fontset and FONTSET doesn't | |
299 | contain information for C, return the information in the default | |
300 | fontset. */ | |
0d407d77 | 301 | |
1d5d7200 KH |
302 | #define FONTSET_REF(fontset, c) \ |
303 | (EQ (fontset, Vdefault_fontset) \ | |
304 | ? CHAR_TABLE_REF (fontset, c) \ | |
305 | : fontset_ref ((fontset), (c))) | |
0d407d77 | 306 | |
afe93d01 | 307 | static Lisp_Object |
0d407d77 KH |
308 | fontset_ref (fontset, c) |
309 | Lisp_Object fontset; | |
310 | int c; | |
311 | { | |
06f76f0d KH |
312 | Lisp_Object elt; |
313 | ||
1d5d7200 KH |
314 | elt = CHAR_TABLE_REF (fontset, c); |
315 | if (NILP (elt) && ! EQ (fontset, Vdefault_fontset) | |
316 | /* Don't check Vdefault_fontset for a realized fontset. */ | |
317 | && NILP (FONTSET_BASE (fontset))) | |
318 | elt = CHAR_TABLE_REF (Vdefault_fontset, c); | |
0d407d77 KH |
319 | return elt; |
320 | } | |
321 | ||
1d5d7200 KH |
322 | /* Set elements of FONTSET for characters in RANGE to the value ELT. |
323 | RANGE is a cons (FROM . TO), where FROM and TO are character codes | |
324 | specifying a range. */ | |
325 | ||
326 | #define FONTSET_SET(fontset, range, elt) \ | |
327 | Fset_char_table_range ((fontset), (range), (elt)) | |
328 | ||
0d407d77 | 329 | |
1d5d7200 | 330 | /* Modify the elements of FONTSET for characters in RANGE by replacing |
6bad8007 | 331 | with ELT or adding ELT. RANGE is a cons (FROM . TO), where FROM |
1d5d7200 KH |
332 | and TO are character codes specifying a range. If ADD is nil, |
333 | replace with ELT, if ADD is `prepend', prepend ELT, otherwise, | |
334 | append ELT. */ | |
335 | ||
cc7b6145 KH |
336 | #define FONTSET_ADD(fontset, range, elt, add) \ |
337 | (NILP (add) \ | |
338 | ? (NILP (range) \ | |
339 | ? (FONTSET_FALLBACK (fontset) = Fmake_vector (make_number (1), (elt))) \ | |
340 | : Fset_char_table_range ((fontset), (range), \ | |
341 | Fmake_vector (make_number (1), (elt)))) \ | |
1d5d7200 | 342 | : fontset_add ((fontset), (range), (elt), (add))) |
0d407d77 | 343 | |
b11a4ed7 | 344 | static Lisp_Object |
1d5d7200 | 345 | fontset_add (fontset, range, elt, add) |
00c4da0f | 346 | Lisp_Object fontset, range, elt, add; |
06f76f0d | 347 | { |
eb36588a KH |
348 | Lisp_Object args[2]; |
349 | int idx = (EQ (add, Qappend) ? 0 : 1); | |
350 | ||
351 | args[1 - idx] = Fmake_vector (make_number (1), elt); | |
352 | ||
353 | if (CONSP (range)) | |
354 | { | |
355 | int from = XINT (XCAR (range)); | |
356 | int to = XINT (XCDR (range)); | |
357 | int from1, to1; | |
358 | ||
359 | do { | |
5b30be1a | 360 | from1 = from, to1 = to; |
eb36588a | 361 | args[idx] = char_table_ref_and_range (fontset, from, &from1, &to1); |
eb36588a KH |
362 | char_table_set_range (fontset, from, to1, |
363 | NILP (args[idx]) ? args[1 - idx] | |
364 | : Fvconcat (2, args)); | |
365 | from = to1 + 1; | |
366 | } while (from < to); | |
367 | } | |
368 | else | |
369 | { | |
370 | args[idx] = FONTSET_FALLBACK (fontset); | |
371 | FONTSET_FALLBACK (fontset) | |
372 | = NILP (args[idx]) ? args[1 - idx] : Fvconcat (2, args); | |
373 | } | |
b11a4ed7 | 374 | return Qnil; |
1d5d7200 KH |
375 | } |
376 | ||
581f7ac7 KH |
377 | static int |
378 | fontset_compare_rfontdef (val1, val2) | |
379 | const void *val1, *val2; | |
380 | { | |
41ad6003 KH |
381 | return (RFONT_DEF_SCORE (*(Lisp_Object *) val1) |
382 | - RFONT_DEF_SCORE (*(Lisp_Object *) val2)); | |
581f7ac7 | 383 | } |
1d5d7200 | 384 | |
ea0162a6 | 385 | /* Update FONT-GROUP which has this form: |
581f7ac7 KH |
386 | [ CHARSET-ORDERED-LIST-TICK PREFERRED-RFONT-DEF |
387 | RFONT-DEF0 RFONT-DEF1 ... ] | |
20746fe4 | 388 | Reorder RFONT-DEFs according to the current language, and update |
581f7ac7 KH |
389 | CHARSET-ORDERED-LIST-TICK. |
390 | ||
391 | If PREFERRED_FAMILY is not nil, that family has the higher priority | |
392 | if the encoding charsets or languages in font-specs are the same. */ | |
393 | ||
394 | extern Lisp_Object Fassoc_string (); | |
0d407d77 KH |
395 | |
396 | static void | |
41ad6003 | 397 | reorder_font_vector (font_group, font) |
ea0162a6 | 398 | Lisp_Object font_group; |
41ad6003 | 399 | struct font *font; |
1d5d7200 | 400 | { |
41ad6003 | 401 | Lisp_Object vec, font_object; |
1d5d7200 | 402 | int size; |
581f7ac7 KH |
403 | int i; |
404 | int score_changed = 0; | |
1d5d7200 | 405 | |
41ad6003 KH |
406 | if (font) |
407 | XSETFONT (font_object, font); | |
408 | else | |
409 | font_object = Qnil; | |
410 | ||
411 | vec = XCDR (font_group); | |
412 | size = ASIZE (vec); | |
413 | /* Exclude the tailing nil element from the reordering. */ | |
414 | if (NILP (AREF (vec, size - 1))) | |
415 | size--; | |
581f7ac7 KH |
416 | |
417 | for (i = 0; i < size; i++) | |
6bad8007 | 418 | { |
41ad6003 | 419 | Lisp_Object rfont_def = AREF (vec, i); |
581f7ac7 KH |
420 | Lisp_Object font_def = RFONT_DEF_FONT_DEF (rfont_def); |
421 | Lisp_Object font_spec = FONT_DEF_SPEC (font_def); | |
41ad6003 | 422 | int score = RFONT_DEF_SCORE (rfont_def) & 0xFF; |
581f7ac7 | 423 | |
41ad6003 | 424 | if (! font_match_p (font_spec, font_object)) |
eb152aa9 | 425 | { |
cd872f08 | 426 | Lisp_Object encoding = FONT_DEF_ENCODING (font_def); |
581f7ac7 | 427 | |
cd872f08 | 428 | if (! NILP (encoding)) |
41ad6003 KH |
429 | { |
430 | Lisp_Object tail; | |
581f7ac7 | 431 | |
41ad6003 KH |
432 | for (tail = Vcharset_ordered_list; |
433 | ! EQ (tail, Vcharset_non_preferred_head) && CONSP (tail); | |
434 | score += 0x100, tail = XCDR (tail)) | |
cd872f08 | 435 | if (EQ (encoding, XCAR (tail))) |
41ad6003 KH |
436 | break; |
437 | } | |
438 | else | |
439 | { | |
440 | Lisp_Object lang = Ffont_get (font_spec, QClang); | |
441 | ||
442 | if (! NILP (lang) | |
443 | && ! EQ (lang, Vcurrent_iso639_language) | |
444 | && (! CONSP (Vcurrent_iso639_language) | |
445 | || NILP (Fmemq (lang, Vcurrent_iso639_language)))) | |
446 | score |= 0x100; | |
447 | } | |
ea0162a6 | 448 | } |
581f7ac7 | 449 | if (RFONT_DEF_SCORE (rfont_def) != score) |
ea0162a6 | 450 | { |
581f7ac7 KH |
451 | RFONT_DEF_SET_SCORE (rfont_def, score); |
452 | score_changed = 1; | |
ea0162a6 | 453 | } |
6bad8007 | 454 | } |
1d5d7200 | 455 | |
581f7ac7 | 456 | if (score_changed) |
41ad6003 | 457 | qsort (XVECTOR (vec)->contents, size, sizeof (Lisp_Object), |
581f7ac7 | 458 | fontset_compare_rfontdef); |
41ad6003 KH |
459 | XSETCAR (font_group, make_number (charset_ordered_list_tick)); |
460 | } | |
461 | ||
f084f942 KH |
462 | /* Return a font-group (actually a cons (-1 . FONT-GROUP-VECTOR)) for |
463 | character C in FONTSET. If C is -1, return a fallback font-group. | |
464 | If C is not -1, the value may be Qt (FONTSET doesn't have a font | |
465 | for C even in the fallback group, or 0 (a font for C may be found | |
466 | only in the fallback group). */ | |
467 | ||
41ad6003 | 468 | static Lisp_Object |
3cba9369 | 469 | fontset_get_font_group (Lisp_Object fontset, int c) |
41ad6003 KH |
470 | { |
471 | Lisp_Object font_group; | |
472 | Lisp_Object base_fontset; | |
5b30be1a | 473 | int from = 0, to = MAX_CHAR, i; |
28e2436a | 474 | |
41ad6003 KH |
475 | xassert (! BASE_FONTSET_P (fontset)); |
476 | if (c >= 0) | |
477 | font_group = CHAR_TABLE_REF (fontset, c); | |
478 | else | |
479 | font_group = FONTSET_FALLBACK (fontset); | |
480 | if (! NILP (font_group)) | |
481 | return font_group; | |
482 | base_fontset = FONTSET_BASE (fontset); | |
483 | if (c >= 0) | |
484 | font_group = char_table_ref_and_range (base_fontset, c, &from, &to); | |
485 | else | |
486 | font_group = FONTSET_FALLBACK (base_fontset); | |
487 | if (NILP (font_group)) | |
f088b054 | 488 | { |
f084f942 | 489 | font_group = make_number (0); |
f088b054 | 490 | if (c >= 0) |
f084f942 KH |
491 | char_table_set_range (fontset, from, to, font_group); |
492 | return font_group; | |
f088b054 | 493 | } |
41ad6003 KH |
494 | font_group = Fcopy_sequence (font_group); |
495 | for (i = 0; i < ASIZE (font_group); i++) | |
496 | if (! NILP (AREF (font_group, i))) | |
497 | { | |
498 | Lisp_Object rfont_def; | |
499 | ||
500 | RFONT_DEF_NEW (rfont_def, AREF (font_group, i)); | |
501 | /* Remember the original order. */ | |
502 | RFONT_DEF_SET_SCORE (rfont_def, i); | |
503 | ASET (font_group, i, rfont_def); | |
504 | } | |
505 | font_group = Fcons (make_number (-1), font_group); | |
506 | if (c >= 0) | |
507 | char_table_set_range (fontset, from, to, font_group); | |
508 | else | |
509 | FONTSET_FALLBACK (fontset) = font_group; | |
510 | return font_group; | |
0d407d77 KH |
511 | } |
512 | ||
7e1a1cd9 | 513 | /* Return RFONT-DEF (vector) in the realized fontset FONTSET for the |
d67f7f1a KH |
514 | character C. If no font is found, return Qnil if there's a |
515 | possibility that the default fontset or the fallback font groups | |
516 | have a proper font, and return Qt if not. | |
517 | ||
518 | If a font is found but is not yet opened, open it (if FACE is not | |
519 | NULL) or return Qnil (if FACE is NULL). | |
520 | ||
1c82b4b3 KH |
521 | ID is a charset-id that must be preferred, or -1 meaning no |
522 | preference. | |
d67f7f1a | 523 | |
ea0162a6 | 524 | If FALLBACK is nonzero, search only fallback fonts. */ |
0d407d77 | 525 | |
7e1a1cd9 | 526 | static Lisp_Object |
1c82b4b3 | 527 | fontset_find_font (fontset, c, face, id, fallback) |
0d407d77 KH |
528 | Lisp_Object fontset; |
529 | int c; | |
1d5d7200 | 530 | struct face *face; |
1c82b4b3 | 531 | int id, fallback; |
0d407d77 | 532 | { |
162f5458 | 533 | Lisp_Object vec, font_group; |
f3d29551 CY |
534 | int i, charset_matched = -1; |
535 | FRAME_PTR f = (FRAMEP (FONTSET_FRAME (fontset))) | |
536 | ? XFRAME (selected_frame) : XFRAME (FONTSET_FRAME (fontset)); | |
0d407d77 | 537 | |
41ad6003 KH |
538 | font_group = fontset_get_font_group (fontset, fallback ? -1 : c); |
539 | if (! CONSP (font_group)) | |
bf86d09c | 540 | return font_group; |
41ad6003 KH |
541 | vec = XCDR (font_group); |
542 | if (ASIZE (vec) == 0) | |
543 | return Qnil; | |
eaa0402c | 544 | |
41ad6003 | 545 | if (ASIZE (vec) > 1) |
1d5d7200 | 546 | { |
41ad6003 KH |
547 | if (XINT (XCAR (font_group)) != charset_ordered_list_tick) |
548 | /* We have just created the font-group, | |
549 | or the charset priorities were changed. */ | |
550 | reorder_font_vector (font_group, face->ascii_face->font); | |
551 | if (id >= 0) | |
552 | /* Find a spec matching with the charset ID to try at | |
553 | first. */ | |
554 | for (i = 0; i < ASIZE (vec); i++) | |
555 | { | |
556 | Lisp_Object rfont_def = AREF (vec, i); | |
0ff75233 KH |
557 | Lisp_Object repertory; |
558 | ||
559 | if (NILP (rfont_def)) | |
560 | break; | |
561 | repertory = FONT_DEF_REPERTORY (RFONT_DEF_FONT_DEF (rfont_def)); | |
41ad6003 KH |
562 | |
563 | if (XINT (repertory) == id) | |
eaa0402c | 564 | { |
41ad6003 | 565 | charset_matched = i; |
581f7ac7 | 566 | break; |
41ad6003 KH |
567 | } |
568 | } | |
581f7ac7 | 569 | } |
1d5d7200 | 570 | |
7e1a1cd9 | 571 | /* Find the first available font in the vector of RFONT-DEF. */ |
41ad6003 | 572 | for (i = 0; i < ASIZE (vec); i++) |
0d407d77 | 573 | { |
162f5458 | 574 | Lisp_Object rfont_def, font_def; |
dbf46ba6 | 575 | Lisp_Object font_entity, font_object; |
581f7ac7 | 576 | |
41ad6003 KH |
577 | if (i == 0 && charset_matched >= 0) |
578 | { | |
579 | /* Try the element matching with the charset ID at first. */ | |
162f5458 | 580 | rfont_def = AREF (vec, charset_matched); |
41ad6003 KH |
581 | charset_matched = -1; |
582 | i--; | |
583 | } | |
584 | else if (i != charset_matched) | |
162f5458 | 585 | rfont_def = AREF (vec, i); |
41ad6003 KH |
586 | else |
587 | continue; | |
588 | ||
162f5458 | 589 | if (NILP (rfont_def)) |
41ad6003 | 590 | /* This is a sign of not to try the other fonts. */ |
eaa0402c | 591 | return Qt; |
162f5458 KH |
592 | if (INTEGERP (RFONT_DEF_FACE (rfont_def)) |
593 | && XINT (RFONT_DEF_FACE (rfont_def)) < 0) | |
1d5d7200 KH |
594 | /* We couldn't open this font last time. */ |
595 | continue; | |
596 | ||
162f5458 | 597 | font_object = RFONT_DEF_OBJECT (rfont_def); |
581f7ac7 | 598 | if (NILP (font_object)) |
8aa07a8d | 599 | { |
162f5458 | 600 | font_def = RFONT_DEF_FONT_DEF (rfont_def); |
d67f7f1a | 601 | |
581f7ac7 KH |
602 | if (! face) |
603 | /* We have not yet opened the font. */ | |
604 | return Qnil; | |
162f5458 KH |
605 | /* Find a font best-matching with the spec without checking |
606 | the support of the character C. That checking is costly, | |
607 | and even without the checking, the found font supports C | |
608 | in high possibility. */ | |
581f7ac7 KH |
609 | font_entity = font_find_for_lface (f, face->lface, |
610 | FONT_DEF_SPEC (font_def), -1); | |
d67f7f1a | 611 | if (NILP (font_entity)) |
8b67c40a | 612 | { |
581f7ac7 | 613 | /* Record that no font matches the spec. */ |
162f5458 | 614 | RFONT_DEF_SET_FACE (rfont_def, -1); |
581f7ac7 | 615 | continue; |
d67f7f1a | 616 | } |
ca2b2cde KH |
617 | font_object = font_open_for_lface (f, font_entity, face->lface, |
618 | FONT_DEF_SPEC (font_def)); | |
581f7ac7 | 619 | if (NILP (font_object)) |
d67f7f1a | 620 | { |
162f5458 KH |
621 | /* Something strange happened, perhaps because of a |
622 | Font-backend problem. Too avoid crashing, record | |
623 | that this spec is unsable. It may be better to find | |
624 | another font of the same spec, but currently we don't | |
625 | have such an API. */ | |
626 | RFONT_DEF_SET_FACE (rfont_def, -1); | |
581f7ac7 | 627 | continue; |
8aa07a8d | 628 | } |
162f5458 | 629 | RFONT_DEF_SET_OBJECT (rfont_def, font_object); |
8aa07a8d | 630 | } |
eb152aa9 | 631 | |
581f7ac7 | 632 | if (font_has_char (f, font_object, c)) |
162f5458 | 633 | return rfont_def; |
581f7ac7 | 634 | |
162f5458 KH |
635 | /* Find a font already opened, maching with the current spec, |
636 | and supporting C. */ | |
637 | font_def = RFONT_DEF_FONT_DEF (rfont_def); | |
581f7ac7 | 638 | for (i++; i < ASIZE (vec); i++) |
57e13af9 | 639 | { |
162f5458 | 640 | rfont_def = AREF (vec, i); |
7d72bb82 KH |
641 | if (NILP (rfont_def)) |
642 | return Qt; | |
162f5458 | 643 | if (! EQ (RFONT_DEF_FONT_DEF (rfont_def), font_def)) |
581f7ac7 | 644 | break; |
162f5458 | 645 | font_object = RFONT_DEF_OBJECT (AREF (vec, i)); |
69a8e484 | 646 | if (! NILP (font_object) && font_has_char (f, font_object, c)) |
162f5458 | 647 | return rfont_def; |
57e13af9 | 648 | } |
162f5458 KH |
649 | |
650 | /* Find a font-entity with the current spec and supporting C. */ | |
581f7ac7 KH |
651 | font_entity = font_find_for_lface (f, face->lface, |
652 | FONT_DEF_SPEC (font_def), c); | |
653 | if (! NILP (font_entity)) | |
1d5d7200 | 654 | { |
162f5458 KH |
655 | /* We found a font. Open it and insert a new element for |
656 | that font in VEC. */ | |
657 | Lisp_Object new_vec; | |
581f7ac7 | 658 | int j; |
1d5d7200 | 659 | |
581f7ac7 KH |
660 | font_object = font_open_for_lface (f, font_entity, face->lface, |
661 | Qnil); | |
162f5458 KH |
662 | if (NILP (font_object)) |
663 | continue; | |
581f7ac7 KH |
664 | RFONT_DEF_NEW (rfont_def, font_def); |
665 | RFONT_DEF_SET_OBJECT (rfont_def, font_object); | |
162f5458 | 666 | RFONT_DEF_SET_SCORE (rfont_def, RFONT_DEF_SCORE (rfont_def)); |
581f7ac7 KH |
667 | new_vec = Fmake_vector (make_number (ASIZE (vec) + 1), Qnil); |
668 | for (j = 0; j < i; j++) | |
669 | ASET (new_vec, j, AREF (vec, j)); | |
670 | ASET (new_vec, j, rfont_def); | |
671 | for (j++; j < ASIZE (new_vec); j++) | |
672 | ASET (new_vec, j, AREF (vec, j - 1)); | |
162f5458 | 673 | XSETCDR (font_group, new_vec); |
581f7ac7 | 674 | return rfont_def; |
1d5d7200 | 675 | } |
162f5458 KH |
676 | |
677 | /* No font of the current spec for C. Try the next spec. */ | |
581f7ac7 | 678 | i--; |
0d407d77 | 679 | } |
d67f7f1a | 680 | |
581f7ac7 | 681 | FONTSET_SET (fontset, make_number (c), make_number (0)); |
eaa0402c | 682 | return Qnil; |
1c82b4b3 | 683 | } |
0d407d77 | 684 | |
cc7b6145 | 685 | |
1c82b4b3 KH |
686 | static Lisp_Object |
687 | fontset_font (fontset, c, face, id) | |
688 | Lisp_Object fontset; | |
689 | int c; | |
690 | struct face *face; | |
691 | int id; | |
692 | { | |
f084f942 | 693 | Lisp_Object rfont_def, default_rfont_def; |
1c82b4b3 | 694 | Lisp_Object base_fontset; |
cc7b6145 | 695 | |
41ad6003 | 696 | /* Try a font-group of FONTSET. */ |
b23bf85a | 697 | FONT_DEFERRED_LOG ("current fontset: font for", make_number (c), Qnil); |
1c82b4b3 | 698 | rfont_def = fontset_find_font (fontset, c, face, id, 0); |
eaa0402c KH |
699 | if (VECTORP (rfont_def)) |
700 | return rfont_def; | |
f084f942 KH |
701 | if (NILP (rfont_def)) |
702 | FONTSET_SET (fontset, make_number (c), make_number (0)); | |
41ad6003 KH |
703 | |
704 | /* Try a font-group of the default fontset. */ | |
705 | base_fontset = FONTSET_BASE (fontset); | |
706 | if (! EQ (base_fontset, Vdefault_fontset)) | |
707 | { | |
708 | if (NILP (FONTSET_DEFAULT (fontset))) | |
709 | FONTSET_DEFAULT (fontset) | |
710 | = make_fontset (FONTSET_FRAME (fontset), Qnil, Vdefault_fontset); | |
b23bf85a | 711 | FONT_DEFERRED_LOG ("default fontset: font for", make_number (c), Qnil); |
f084f942 KH |
712 | default_rfont_def |
713 | = fontset_find_font (FONTSET_DEFAULT (fontset), c, face, id, 0); | |
714 | if (VECTORP (default_rfont_def)) | |
715 | return default_rfont_def; | |
716 | if (NILP (default_rfont_def)) | |
717 | FONTSET_SET (FONTSET_DEFAULT (fontset), make_number (c), | |
718 | make_number (0)); | |
41ad6003 KH |
719 | } |
720 | ||
721 | /* Try a fallback font-group of FONTSET. */ | |
f084f942 KH |
722 | if (! EQ (rfont_def, Qt)) |
723 | { | |
724 | FONT_DEFERRED_LOG ("current fallback: font for", make_number (c), Qnil); | |
725 | rfont_def = fontset_find_font (fontset, c, face, id, 1); | |
726 | if (VECTORP (rfont_def)) | |
727 | return rfont_def; | |
728 | /* Remember that FONTSET has no font for C. */ | |
729 | FONTSET_SET (fontset, make_number (c), Qt); | |
730 | } | |
d67f7f1a | 731 | |
f084f942 KH |
732 | /* Try a fallback font-group of the default fontset. */ |
733 | if (! EQ (base_fontset, Vdefault_fontset) | |
734 | && ! EQ (default_rfont_def, Qt)) | |
41ad6003 | 735 | { |
b23bf85a | 736 | FONT_DEFERRED_LOG ("default fallback: font for", make_number (c), Qnil); |
41ad6003 KH |
737 | rfont_def = fontset_find_font (FONTSET_DEFAULT (fontset), c, face, id, 1); |
738 | if (VECTORP (rfont_def)) | |
739 | return rfont_def; | |
f084f942 KH |
740 | /* Remember that the default fontset has no font for C. */ |
741 | FONTSET_SET (FONTSET_DEFAULT (fontset), make_number (c), Qt); | |
41ad6003 KH |
742 | } |
743 | ||
41ad6003 | 744 | return Qnil; |
0d407d77 KH |
745 | } |
746 | ||
0d407d77 | 747 | /* Return a newly created fontset with NAME. If BASE is nil, make a |
06f76f0d | 748 | base fontset. Otherwise make a realized fontset whose base is |
0d407d77 KH |
749 | BASE. */ |
750 | ||
751 | static Lisp_Object | |
752 | make_fontset (frame, name, base) | |
753 | Lisp_Object frame, name, base; | |
4ed46869 | 754 | { |
1337ac77 | 755 | Lisp_Object fontset; |
0d407d77 KH |
756 | int size = ASIZE (Vfontset_table); |
757 | int id = next_fontset_id; | |
0d407d77 KH |
758 | |
759 | /* Find a free slot in Vfontset_table. Usually, next_fontset_id is | |
760 | the next available fontset ID. So it is expected that this loop | |
761 | terminates quickly. In addition, as the last element of | |
fc8865fc | 762 | Vfontset_table is always nil, we don't have to check the range of |
0d407d77 KH |
763 | id. */ |
764 | while (!NILP (AREF (Vfontset_table, id))) id++; | |
765 | ||
766 | if (id + 1 == size) | |
63655c83 | 767 | Vfontset_table = larger_vector (Vfontset_table, size + 32, Qnil); |
4ed46869 | 768 | |
11d9bd93 | 769 | fontset = Fmake_char_table (Qfontset, Qnil); |
0d407d77 KH |
770 | |
771 | FONTSET_ID (fontset) = make_number (id); | |
06f76f0d KH |
772 | if (NILP (base)) |
773 | { | |
774 | FONTSET_NAME (fontset) = name; | |
775 | } | |
776 | else | |
777 | { | |
778 | FONTSET_NAME (fontset) = Qnil; | |
779 | FONTSET_FRAME (fontset) = frame; | |
780 | FONTSET_BASE (fontset) = base; | |
781 | } | |
0d407d77 | 782 | |
06f76f0d | 783 | ASET (Vfontset_table, id, fontset); |
0d407d77 KH |
784 | next_fontset_id = id + 1; |
785 | return fontset; | |
4ed46869 KH |
786 | } |
787 | ||
0d407d77 | 788 | \f |
1d5d7200 | 789 | /********** INTERFACES TO xfaces.c, xfns.c, and dispextern.h **********/ |
0d407d77 | 790 | |
1d5d7200 | 791 | /* Return the name of the fontset who has ID. */ |
0d407d77 KH |
792 | |
793 | Lisp_Object | |
794 | fontset_name (id) | |
795 | int id; | |
796 | { | |
797 | Lisp_Object fontset; | |
06f76f0d | 798 | |
0d407d77 KH |
799 | fontset = FONTSET_FROM_ID (id); |
800 | return FONTSET_NAME (fontset); | |
801 | } | |
802 | ||
803 | ||
1d5d7200 | 804 | /* Return the ASCII font name of the fontset who has ID. */ |
0d407d77 KH |
805 | |
806 | Lisp_Object | |
807 | fontset_ascii (id) | |
808 | int id; | |
809 | { | |
810 | Lisp_Object fontset, elt; | |
06f76f0d | 811 | |
0d407d77 KH |
812 | fontset= FONTSET_FROM_ID (id); |
813 | elt = FONTSET_ASCII (fontset); | |
8aa07a8d KH |
814 | if (CONSP (elt)) |
815 | elt = XCAR (elt); | |
1d5d7200 | 816 | return elt; |
0d407d77 KH |
817 | } |
818 | ||
9459b1e9 KH |
819 | void |
820 | free_realized_fontset (f, fontset) | |
821 | FRAME_PTR f; | |
822 | Lisp_Object fontset; | |
823 | { | |
9459b1e9 KH |
824 | Lisp_Object tail; |
825 | ||
826 | return; | |
827 | for (tail = FONTSET_OBJLIST (fontset); CONSP (tail); tail = XCDR (tail)) | |
828 | { | |
829 | xassert (FONT_OBJECT_P (XCAR (tail))); | |
830 | font_close_object (f, XCAR (tail)); | |
831 | } | |
832 | } | |
0d407d77 | 833 | |
06f76f0d KH |
834 | /* Free fontset of FACE defined on frame F. Called from |
835 | free_realized_face. */ | |
0d407d77 | 836 | |
4ed46869 | 837 | void |
0d407d77 KH |
838 | free_face_fontset (f, face) |
839 | FRAME_PTR f; | |
840 | struct face *face; | |
4ed46869 | 841 | { |
452a78e0 KH |
842 | Lisp_Object fontset; |
843 | ||
ff7a2223 | 844 | fontset = FONTSET_FROM_ID (face->fontset); |
581f7ac7 KH |
845 | if (NILP (fontset)) |
846 | return; | |
847 | xassert (! BASE_FONTSET_P (fontset)); | |
452a78e0 | 848 | xassert (f == XFRAME (FONTSET_FRAME (fontset))); |
9459b1e9 | 849 | free_realized_fontset (f, fontset); |
1d5d7200 | 850 | ASET (Vfontset_table, face->fontset, Qnil); |
06f76f0d KH |
851 | if (face->fontset < next_fontset_id) |
852 | next_fontset_id = face->fontset; | |
eb36588a | 853 | if (! NILP (FONTSET_DEFAULT (fontset))) |
452a78e0 | 854 | { |
e1a14cdc | 855 | int id = XINT (FONTSET_ID (FONTSET_DEFAULT (fontset))); |
eb152aa9 | 856 | |
452a78e0 KH |
857 | fontset = AREF (Vfontset_table, id); |
858 | xassert (!NILP (fontset) && ! BASE_FONTSET_P (fontset)); | |
859 | xassert (f == XFRAME (FONTSET_FRAME (fontset))); | |
9459b1e9 | 860 | free_realized_fontset (f, fontset); |
452a78e0 KH |
861 | ASET (Vfontset_table, id, Qnil); |
862 | if (id < next_fontset_id) | |
863 | next_fontset_id = face->fontset; | |
864 | } | |
581f7ac7 | 865 | face->fontset = -1; |
0d407d77 | 866 | } |
18998710 | 867 | |
0d407d77 | 868 | |
e0f24100 | 869 | /* Return 1 if FACE is suitable for displaying character C. |
0d407d77 | 870 | Otherwise return 0. Called from the macro FACE_SUITABLE_FOR_CHAR_P |
06f76f0d | 871 | when C is not an ASCII character. */ |
0d407d77 KH |
872 | |
873 | int | |
874 | face_suitable_for_char_p (face, c) | |
875 | struct face *face; | |
876 | int c; | |
877 | { | |
7e1a1cd9 | 878 | Lisp_Object fontset, rfont_def; |
0d407d77 | 879 | |
0d407d77 | 880 | fontset = FONTSET_FROM_ID (face->fontset); |
7e1a1cd9 KH |
881 | rfont_def = fontset_font (fontset, c, NULL, -1); |
882 | return (VECTORP (rfont_def) | |
581f7ac7 KH |
883 | && INTEGERP (RFONT_DEF_FACE (rfont_def)) |
884 | && face->id == XINT (RFONT_DEF_FACE (rfont_def))); | |
0d407d77 KH |
885 | } |
886 | ||
887 | ||
888 | /* Return ID of face suitable for displaying character C on frame F. | |
1d5d7200 KH |
889 | FACE must be reazlied for ASCII characters in advance. Called from |
890 | the macro FACE_FOR_CHAR. */ | |
0d407d77 KH |
891 | |
892 | int | |
6bad8007 | 893 | face_for_char (f, face, c, pos, object) |
0d407d77 KH |
894 | FRAME_PTR f; |
895 | struct face *face; | |
6bad8007 KH |
896 | int c, pos; |
897 | Lisp_Object object; | |
0d407d77 | 898 | { |
303d5190 | 899 | Lisp_Object fontset, rfont_def, charset; |
7e1a1cd9 | 900 | int face_id; |
6bad8007 | 901 | int id; |
1d5d7200 | 902 | |
ea217c11 KH |
903 | /* If face->fontset is negative (that happens when no font is found |
904 | for face), just return face->ascii_face because we can't do | |
905 | anything. Perhaps, we should fix the callers to assure | |
906 | that face->fontset is always valid. */ | |
907 | if (ASCII_CHAR_P (c) || face->fontset < 0) | |
1d5d7200 | 908 | return face->ascii_face->id; |
0d407d77 KH |
909 | |
910 | xassert (fontset_id_valid_p (face->fontset)); | |
911 | fontset = FONTSET_FROM_ID (face->fontset); | |
912 | xassert (!BASE_FONTSET_P (fontset)); | |
41ad6003 | 913 | |
6bad8007 | 914 | if (pos < 0) |
303d5190 KH |
915 | { |
916 | id = -1; | |
917 | charset = Qnil; | |
918 | } | |
6bad8007 KH |
919 | else |
920 | { | |
921 | charset = Fget_char_property (make_number (pos), Qcharset, object); | |
b1bde622 | 922 | if (CHARSETP (charset)) |
28e2436a KH |
923 | { |
924 | Lisp_Object val; | |
925 | ||
a124bbb6 | 926 | val = assq_no_quit (charset, Vfont_encoding_charset_alist); |
28e2436a KH |
927 | if (CONSP (val) && CHARSETP (XCDR (val))) |
928 | charset = XCDR (val); | |
929 | id = XINT (CHARSET_SYMBOL_ID (charset)); | |
930 | } | |
b1bde622 KH |
931 | else |
932 | id = -1; | |
6bad8007 | 933 | } |
b59e66b3 | 934 | |
7e1a1cd9 KH |
935 | rfont_def = fontset_font (fontset, c, face, id); |
936 | if (VECTORP (rfont_def)) | |
937 | { | |
581f7ac7 KH |
938 | if (INTEGERP (RFONT_DEF_FACE (rfont_def))) |
939 | face_id = XINT (RFONT_DEF_FACE (rfont_def)); | |
8aa07a8d | 940 | else |
7e1a1cd9 | 941 | { |
581f7ac7 | 942 | Lisp_Object font_object; |
7e1a1cd9 | 943 | |
581f7ac7 KH |
944 | font_object = RFONT_DEF_OBJECT (rfont_def); |
945 | face_id = face_for_font (f, font_object, face); | |
946 | RFONT_DEF_SET_FACE (rfont_def, face_id); | |
7e1a1cd9 | 947 | } |
7e1a1cd9 | 948 | } |
581f7ac7 | 949 | else |
7e1a1cd9 | 950 | { |
581f7ac7 KH |
951 | if (INTEGERP (FONTSET_NOFONT_FACE (fontset))) |
952 | face_id = XINT (FONTSET_NOFONT_FACE (fontset)); | |
953 | else | |
954 | { | |
955 | face_id = face_for_font (f, Qnil, face); | |
956 | FONTSET_NOFONT_FACE (fontset) = make_number (face_id); | |
957 | } | |
7e1a1cd9 | 958 | } |
581f7ac7 KH |
959 | xassert (face_id >= 0); |
960 | return face_id; | |
0d407d77 KH |
961 | } |
962 | ||
963 | ||
514cf218 KH |
964 | Lisp_Object |
965 | font_for_char (face, c, pos, object) | |
966 | struct face *face; | |
967 | int c, pos; | |
968 | Lisp_Object object; | |
969 | { | |
970 | Lisp_Object fontset, rfont_def, charset; | |
971 | int face_id; | |
972 | int id; | |
973 | ||
974 | if (ASCII_CHAR_P (c)) | |
975 | { | |
976 | Lisp_Object font_object; | |
977 | ||
978 | XSETFONT (font_object, face->ascii_face->font); | |
979 | return font_object; | |
980 | } | |
981 | ||
982 | xassert (fontset_id_valid_p (face->fontset)); | |
983 | fontset = FONTSET_FROM_ID (face->fontset); | |
984 | xassert (!BASE_FONTSET_P (fontset)); | |
985 | if (pos < 0) | |
986 | { | |
987 | id = -1; | |
988 | charset = Qnil; | |
989 | } | |
990 | else | |
991 | { | |
992 | charset = Fget_char_property (make_number (pos), Qcharset, object); | |
b1bde622 | 993 | if (CHARSETP (charset)) |
514cf218 KH |
994 | { |
995 | Lisp_Object val; | |
996 | ||
9fe78804 | 997 | val = assq_no_quit (charset, Vfont_encoding_charset_alist); |
514cf218 KH |
998 | if (CONSP (val) && CHARSETP (XCDR (val))) |
999 | charset = XCDR (val); | |
1000 | id = XINT (CHARSET_SYMBOL_ID (charset)); | |
1001 | } | |
b1bde622 KH |
1002 | else |
1003 | id = -1; | |
514cf218 KH |
1004 | } |
1005 | ||
514cf218 KH |
1006 | rfont_def = fontset_font (fontset, c, face, id); |
1007 | return (VECTORP (rfont_def) | |
1008 | ? RFONT_DEF_OBJECT (rfont_def) | |
1009 | : Qnil); | |
1010 | } | |
1011 | ||
1012 | ||
0d407d77 KH |
1013 | /* Make a realized fontset for ASCII face FACE on frame F from the |
1014 | base fontset BASE_FONTSET_ID. If BASE_FONTSET_ID is -1, use the | |
1015 | default fontset as the base. Value is the id of the new fontset. | |
1016 | Called from realize_x_face. */ | |
1017 | ||
1018 | int | |
1d5d7200 | 1019 | make_fontset_for_ascii_face (f, base_fontset_id, face) |
0d407d77 KH |
1020 | FRAME_PTR f; |
1021 | int base_fontset_id; | |
1d5d7200 | 1022 | struct face *face; |
0d407d77 | 1023 | { |
1337ac77 | 1024 | Lisp_Object base_fontset, fontset, frame; |
0d407d77 KH |
1025 | |
1026 | XSETFRAME (frame, f); | |
1027 | if (base_fontset_id >= 0) | |
1028 | { | |
1029 | base_fontset = FONTSET_FROM_ID (base_fontset_id); | |
1030 | if (!BASE_FONTSET_P (base_fontset)) | |
1031 | base_fontset = FONTSET_BASE (base_fontset); | |
1d5d7200 KH |
1032 | if (! BASE_FONTSET_P (base_fontset)) |
1033 | abort (); | |
4ed46869 | 1034 | } |
0d407d77 KH |
1035 | else |
1036 | base_fontset = Vdefault_fontset; | |
1037 | ||
1038 | fontset = make_fontset (frame, Qnil, base_fontset); | |
f3231837 | 1039 | return XINT (FONTSET_ID (fontset)); |
0d407d77 KH |
1040 | } |
1041 | ||
0d407d77 | 1042 | \f |
1d5d7200 | 1043 | |
4ed46869 KH |
1044 | /* Cache data used by fontset_pattern_regexp. The car part is a |
1045 | pattern string containing at least one wild card, the cdr part is | |
1046 | the corresponding regular expression. */ | |
1047 | static Lisp_Object Vcached_fontset_data; | |
1048 | ||
dbf46ba6 | 1049 | #define CACHED_FONTSET_NAME ((char *) SDATA (XCAR (Vcached_fontset_data))) |
7539e11f | 1050 | #define CACHED_FONTSET_REGEX (XCDR (Vcached_fontset_data)) |
4ed46869 KH |
1051 | |
1052 | /* If fontset name PATTERN contains any wild card, return regular | |
1053 | expression corresponding to PATTERN. */ | |
1054 | ||
0d407d77 | 1055 | static Lisp_Object |
4ed46869 KH |
1056 | fontset_pattern_regexp (pattern) |
1057 | Lisp_Object pattern; | |
1058 | { | |
dbf46ba6 KH |
1059 | if (!index ((char *) SDATA (pattern), '*') |
1060 | && !index ((char *) SDATA (pattern), '?')) | |
4ed46869 | 1061 | /* PATTERN does not contain any wild cards. */ |
1c283e35 | 1062 | return Qnil; |
4ed46869 KH |
1063 | |
1064 | if (!CONSP (Vcached_fontset_data) | |
dbf46ba6 | 1065 | || strcmp ((char *) SDATA (pattern), CACHED_FONTSET_NAME)) |
4ed46869 KH |
1066 | { |
1067 | /* We must at first update the cached data. */ | |
6cc06608 | 1068 | unsigned char *regex, *p0, *p1; |
821bc4db | 1069 | int ndashes = 0, nstars = 0, nescs = 0; |
6cc06608 | 1070 | |
fc1062f5 KH |
1071 | for (p0 = SDATA (pattern); *p0; p0++) |
1072 | { | |
1073 | if (*p0 == '-') | |
1074 | ndashes++; | |
a653f812 | 1075 | else if (*p0 == '*') |
fc1062f5 | 1076 | nstars++; |
821bc4db KH |
1077 | else if (*p0 == '[' |
1078 | || *p0 == '.' || *p0 == '\\' | |
8510724d | 1079 | || *p0 == '+' || *p0 == '^' |
821bc4db KH |
1080 | || *p0 == '$') |
1081 | nescs++; | |
fc1062f5 KH |
1082 | } |
1083 | ||
1084 | /* If PATTERN is not full XLFD we conert "*" to ".*". Otherwise | |
1085 | we convert "*" to "[^-]*" which is much faster in regular | |
1086 | expression matching. */ | |
1087 | if (ndashes < 14) | |
821bc4db | 1088 | p1 = regex = (unsigned char *) alloca (SBYTES (pattern) + 2 * nstars + 2 * nescs + 1); |
fc1062f5 | 1089 | else |
821bc4db | 1090 | p1 = regex = (unsigned char *) alloca (SBYTES (pattern) + 5 * nstars + 2 * nescs + 1); |
4ed46869 | 1091 | |
1c283e35 | 1092 | *p1++ = '^'; |
6cc06608 | 1093 | for (p0 = SDATA (pattern); *p0; p0++) |
4ed46869 | 1094 | { |
a653f812 | 1095 | if (*p0 == '*') |
4ed46869 | 1096 | { |
fc1062f5 KH |
1097 | if (ndashes < 14) |
1098 | *p1++ = '.'; | |
1099 | else | |
1100 | *p1++ = '[', *p1++ = '^', *p1++ = '-', *p1++ = ']'; | |
1c283e35 | 1101 | *p1++ = '*'; |
4ed46869 | 1102 | } |
1c283e35 | 1103 | else if (*p0 == '?') |
d96d677d | 1104 | *p1++ = '.'; |
821bc4db KH |
1105 | else if (*p0 == '[' |
1106 | || *p0 == '.' || *p0 == '\\' | |
8510724d | 1107 | || *p0 == '+' || *p0 == '^' |
821bc4db KH |
1108 | || *p0 == '$') |
1109 | *p1++ = '\\', *p1++ = *p0; | |
1c283e35 KH |
1110 | else |
1111 | *p1++ = *p0; | |
4ed46869 KH |
1112 | } |
1113 | *p1++ = '$'; | |
1114 | *p1++ = 0; | |
1115 | ||
dbf46ba6 KH |
1116 | Vcached_fontset_data = Fcons (build_string ((char *) SDATA (pattern)), |
1117 | build_string ((char *) regex)); | |
4ed46869 KH |
1118 | } |
1119 | ||
1120 | return CACHED_FONTSET_REGEX; | |
1121 | } | |
1122 | ||
0d407d77 | 1123 | /* Return ID of the base fontset named NAME. If there's no such |
a653f812 KH |
1124 | fontset, return -1. NAME_PATTERN specifies how to treat NAME as this: |
1125 | 0: pattern containing '*' and '?' as wildcards | |
1126 | 1: regular expression | |
1127 | 2: literal fontset name | |
1128 | */ | |
0d407d77 KH |
1129 | |
1130 | int | |
a653f812 | 1131 | fs_query_fontset (name, name_pattern) |
0d407d77 | 1132 | Lisp_Object name; |
a653f812 | 1133 | int name_pattern; |
0d407d77 | 1134 | { |
1337ac77 | 1135 | Lisp_Object tem; |
0d407d77 KH |
1136 | int i; |
1137 | ||
1138 | name = Fdowncase (name); | |
a653f812 | 1139 | if (name_pattern != 1) |
0d407d77 KH |
1140 | { |
1141 | tem = Frassoc (name, Vfontset_alias_alist); | |
6bad8007 KH |
1142 | if (NILP (tem)) |
1143 | tem = Fassoc (name, Vfontset_alias_alist); | |
0d407d77 KH |
1144 | if (CONSP (tem) && STRINGP (XCAR (tem))) |
1145 | name = XCAR (tem); | |
a653f812 | 1146 | else if (name_pattern == 0) |
0d407d77 KH |
1147 | { |
1148 | tem = fontset_pattern_regexp (name); | |
1149 | if (STRINGP (tem)) | |
1150 | { | |
1151 | name = tem; | |
a653f812 | 1152 | name_pattern = 1; |
0d407d77 KH |
1153 | } |
1154 | } | |
1155 | } | |
1156 | ||
1157 | for (i = 0; i < ASIZE (Vfontset_table); i++) | |
1158 | { | |
6e1b0d8c | 1159 | Lisp_Object fontset, this_name; |
0d407d77 KH |
1160 | |
1161 | fontset = FONTSET_FROM_ID (i); | |
1162 | if (NILP (fontset) | |
1163 | || !BASE_FONTSET_P (fontset)) | |
1164 | continue; | |
1165 | ||
6e1b0d8c | 1166 | this_name = FONTSET_NAME (fontset); |
a653f812 | 1167 | if (name_pattern == 1 |
581f7ac7 | 1168 | ? fast_string_match_ignore_case (name, this_name) >= 0 |
05131107 | 1169 | : !xstrcasecmp (SDATA (name), SDATA (this_name))) |
0d407d77 KH |
1170 | return i; |
1171 | } | |
1172 | return -1; | |
1173 | } | |
1174 | ||
1175 | ||
727fb790 | 1176 | DEFUN ("query-fontset", Fquery_fontset, Squery_fontset, 1, 2, 0, |
335c5470 PJ |
1177 | doc: /* Return the name of a fontset that matches PATTERN. |
1178 | The value is nil if there is no matching fontset. | |
1179 | PATTERN can contain `*' or `?' as a wildcard | |
1180 | just as X font name matching algorithm allows. | |
1181 | If REGEXPP is non-nil, PATTERN is a regular expression. */) | |
1182 | (pattern, regexpp) | |
727fb790 | 1183 | Lisp_Object pattern, regexpp; |
4ed46869 | 1184 | { |
0d407d77 KH |
1185 | Lisp_Object fontset; |
1186 | int id; | |
4ed46869 KH |
1187 | |
1188 | (*check_window_system_func) (); | |
1189 | ||
b7826503 | 1190 | CHECK_STRING (pattern); |
4ed46869 | 1191 | |
d5db4077 | 1192 | if (SCHARS (pattern) == 0) |
4ed46869 KH |
1193 | return Qnil; |
1194 | ||
0d407d77 KH |
1195 | id = fs_query_fontset (pattern, !NILP (regexpp)); |
1196 | if (id < 0) | |
1197 | return Qnil; | |
4ed46869 | 1198 | |
0d407d77 KH |
1199 | fontset = FONTSET_FROM_ID (id); |
1200 | return FONTSET_NAME (fontset); | |
4ed46869 KH |
1201 | } |
1202 | ||
06f76f0d | 1203 | /* Return a list of base fontset names matching PATTERN on frame F. */ |
4ed46869 KH |
1204 | |
1205 | Lisp_Object | |
1206 | list_fontsets (f, pattern, size) | |
1207 | FRAME_PTR f; | |
1208 | Lisp_Object pattern; | |
1209 | int size; | |
1210 | { | |
1337ac77 | 1211 | Lisp_Object frame, regexp, val; |
0d407d77 | 1212 | int id; |
4ed46869 | 1213 | |
0d407d77 | 1214 | XSETFRAME (frame, f); |
4ed46869 | 1215 | |
0d407d77 | 1216 | regexp = fontset_pattern_regexp (pattern); |
4ed46869 | 1217 | val = Qnil; |
4ed46869 | 1218 | |
0d407d77 KH |
1219 | for (id = 0; id < ASIZE (Vfontset_table); id++) |
1220 | { | |
6e1b0d8c | 1221 | Lisp_Object fontset, name; |
0d407d77 KH |
1222 | |
1223 | fontset = FONTSET_FROM_ID (id); | |
1224 | if (NILP (fontset) | |
1225 | || !BASE_FONTSET_P (fontset) | |
1226 | || !EQ (frame, FONTSET_FRAME (fontset))) | |
1227 | continue; | |
6e1b0d8c | 1228 | name = FONTSET_NAME (fontset); |
0d407d77 | 1229 | |
1d5d7200 | 1230 | if (STRINGP (regexp) |
6e1b0d8c | 1231 | ? (fast_string_match (regexp, name) < 0) |
dbf46ba6 | 1232 | : strcmp ((char *) SDATA (pattern), (char *) SDATA (name))) |
0d407d77 KH |
1233 | continue; |
1234 | ||
0d407d77 | 1235 | val = Fcons (Fcopy_sequence (FONTSET_NAME (fontset)), val); |
4ed46869 KH |
1236 | } |
1237 | ||
1238 | return val; | |
1239 | } | |
1240 | ||
4ed46869 | 1241 | |
8f924df7 | 1242 | /* Free all realized fontsets whose base fontset is BASE. */ |
4ed46869 | 1243 | |
06f76f0d KH |
1244 | static void |
1245 | free_realized_fontsets (base) | |
1246 | Lisp_Object base; | |
1247 | { | |
1248 | int id; | |
4ed46869 | 1249 | |
2f034212 | 1250 | #if 0 |
27e20b2f KH |
1251 | /* For the moment, this doesn't work because free_realized_face |
1252 | doesn't remove FACE from a cache. Until we find a solution, we | |
1253 | suppress this code, and simply use Fclear_face_cache even though | |
1254 | that is not efficient. */ | |
06f76f0d KH |
1255 | BLOCK_INPUT; |
1256 | for (id = 0; id < ASIZE (Vfontset_table); id++) | |
4ed46869 | 1257 | { |
06f76f0d | 1258 | Lisp_Object this = AREF (Vfontset_table, id); |
0d407d77 | 1259 | |
06f76f0d | 1260 | if (EQ (FONTSET_BASE (this), base)) |
0d407d77 | 1261 | { |
06f76f0d | 1262 | Lisp_Object tail; |
4ed46869 | 1263 | |
06f76f0d KH |
1264 | for (tail = FONTSET_FACE_ALIST (this); CONSP (tail); |
1265 | tail = XCDR (tail)) | |
1266 | { | |
1267 | FRAME_PTR f = XFRAME (FONTSET_FRAME (this)); | |
1268 | int face_id = XINT (XCDR (XCAR (tail))); | |
1269 | struct face *face = FACE_FROM_ID (f, face_id); | |
4ed46869 | 1270 | |
06f76f0d KH |
1271 | /* Face THIS itself is also freed by the following call. */ |
1272 | free_realized_face (f, face); | |
1273 | } | |
1274 | } | |
0d407d77 | 1275 | } |
06f76f0d | 1276 | UNBLOCK_INPUT; |
27e20b2f | 1277 | #else /* not 0 */ |
2f034212 KH |
1278 | /* But, we don't have to call Fclear_face_cache if no fontset has |
1279 | been realized from BASE. */ | |
1280 | for (id = 0; id < ASIZE (Vfontset_table); id++) | |
1281 | { | |
1282 | Lisp_Object this = AREF (Vfontset_table, id); | |
1283 | ||
985773c9 | 1284 | if (CHAR_TABLE_P (this) && EQ (FONTSET_BASE (this), base)) |
2f034212 KH |
1285 | { |
1286 | Fclear_face_cache (Qt); | |
1287 | break; | |
1288 | } | |
1289 | } | |
27e20b2f | 1290 | #endif /* not 0 */ |
0d407d77 | 1291 | } |
4ed46869 | 1292 | |
4ed46869 | 1293 | |
0d407d77 KH |
1294 | /* Check validity of NAME as a fontset name and return the |
1295 | corresponding fontset. If not valid, signal an error. | |
a3d16f39 KH |
1296 | |
1297 | If NAME is t, return Vdefault_fontset. If NAME is nil, return the | |
1298 | fontset of *FRAME. | |
1299 | ||
1300 | Set *FRAME to the actual frame. */ | |
0d407d77 KH |
1301 | |
1302 | static Lisp_Object | |
a3d16f39 KH |
1303 | check_fontset_name (name, frame) |
1304 | Lisp_Object name, *frame; | |
0d407d77 KH |
1305 | { |
1306 | int id; | |
1307 | ||
a3d16f39 KH |
1308 | if (NILP (*frame)) |
1309 | *frame = selected_frame; | |
1310 | CHECK_LIVE_FRAME (*frame); | |
1311 | ||
0d407d77 KH |
1312 | if (EQ (name, Qt)) |
1313 | return Vdefault_fontset; | |
a3d16f39 KH |
1314 | if (NILP (name)) |
1315 | { | |
1316 | id = FRAME_FONTSET (XFRAME (*frame)); | |
1317 | } | |
1318 | else | |
1319 | { | |
1320 | CHECK_STRING (name); | |
1321 | /* First try NAME as literal. */ | |
1322 | id = fs_query_fontset (name, 2); | |
1323 | if (id < 0) | |
1324 | /* For backward compatibility, try again NAME as pattern. */ | |
1325 | id = fs_query_fontset (name, 0); | |
1326 | if (id < 0) | |
1327 | error ("Fontset `%s' does not exist", SDATA (name)); | |
1328 | } | |
0d407d77 KH |
1329 | return FONTSET_FROM_ID (id); |
1330 | } | |
4ed46869 | 1331 | |
1d5d7200 KH |
1332 | static void |
1333 | accumulate_script_ranges (arg, range, val) | |
1334 | Lisp_Object arg, range, val; | |
1335 | { | |
1336 | if (EQ (XCAR (arg), val)) | |
1337 | { | |
1338 | if (CONSP (range)) | |
1339 | XSETCDR (arg, Fcons (Fcons (XCAR (range), XCDR (range)), XCDR (arg))); | |
1340 | else | |
1341 | XSETCDR (arg, Fcons (Fcons (range, range), XCDR (arg))); | |
1342 | } | |
1343 | } | |
1344 | ||
1345 | ||
d6aaac9e | 1346 | /* Return an ASCII font name generated from fontset name NAME and |
7ff614ed | 1347 | font-spec ASCII_SPEC. NAME is a string conforming to XLFD. */ |
d6aaac9e KH |
1348 | |
1349 | static INLINE Lisp_Object | |
1350 | generate_ascii_font_name (name, ascii_spec) | |
1351 | Lisp_Object name, ascii_spec; | |
1352 | { | |
7ff614ed | 1353 | Lisp_Object font_spec = Ffont_spec (0, NULL); |
d6aaac9e | 1354 | int i; |
7ff614ed | 1355 | char xlfd[256]; |
d6aaac9e | 1356 | |
dbf46ba6 | 1357 | if (font_parse_xlfd ((char *) SDATA (name), font_spec) < 0) |
7ff614ed | 1358 | error ("Not an XLFD font name: %s", SDATA (name)); |
581f7ac7 | 1359 | for (i = FONT_FOUNDRY_INDEX; i < FONT_EXTRA_INDEX; i++) |
d6aaac9e | 1360 | if (! NILP (AREF (ascii_spec, i))) |
7ff614ed KH |
1361 | ASET (font_spec, i, AREF (ascii_spec, i)); |
1362 | i = font_unparse_xlfd (font_spec, 0, xlfd, 256); | |
1363 | if (i < 0) | |
1364 | error ("Not an XLFD font name: %s", SDATA (name)); | |
1365 | return make_unibyte_string (xlfd, i); | |
d6aaac9e KH |
1366 | } |
1367 | ||
a3d16f39 KH |
1368 | /* Callback function for map_charset_chars in Fset_fontset_font. |
1369 | ARG is a vector [ FONTSET FONT_DEF ADD ASCII SCRIPT_RANGE_LIST ]. | |
fb78e2ed | 1370 | |
a3d16f39 KH |
1371 | In FONTSET, set FONT_DEF in a fashion specified by ADD for |
1372 | characters in RANGE and ranges in SCRIPT_RANGE_LIST before RANGE. | |
1373 | The consumed ranges are poped up from SCRIPT_RANGE_LIST, and the | |
1374 | new SCRIPT_RANGE_LIST is stored in ARG. | |
1375 | ||
1376 | If ASCII is nil, don't set FONT_DEF for ASCII characters. It is | |
1377 | assured that SCRIPT_RANGE_LIST doesn't contain ASCII in that | |
1378 | case. */ | |
fb78e2ed | 1379 | |
2449d4d0 | 1380 | static void |
a3d16f39 KH |
1381 | set_fontset_font (arg, range) |
1382 | Lisp_Object arg, range; | |
2449d4d0 | 1383 | { |
a3d16f39 KH |
1384 | Lisp_Object fontset, font_def, add, ascii, script_range_list; |
1385 | int from = XINT (XCAR (range)), to = XINT (XCDR (range)); | |
2449d4d0 | 1386 | |
a3d16f39 KH |
1387 | fontset = AREF (arg, 0); |
1388 | font_def = AREF (arg, 1); | |
1389 | add = AREF (arg, 2); | |
1390 | ascii = AREF (arg, 3); | |
1391 | script_range_list = AREF (arg, 4); | |
fb78e2ed | 1392 | |
a3d16f39 KH |
1393 | if (NILP (ascii) && from < 0x80) |
1394 | { | |
1395 | if (to < 0x80) | |
fb78e2ed | 1396 | return; |
a3d16f39 KH |
1397 | from = 0x80; |
1398 | range = Fcons (make_number (0x80), XCDR (range)); | |
1399 | } | |
1400 | ||
1401 | #define SCRIPT_FROM XINT (XCAR (XCAR (script_range_list))) | |
1402 | #define SCRIPT_TO XINT (XCDR (XCAR (script_range_list))) | |
1403 | #define POP_SCRIPT_RANGE() script_range_list = XCDR (script_range_list) | |
1404 | ||
1405 | for (; CONSP (script_range_list) && SCRIPT_TO < from; POP_SCRIPT_RANGE ()) | |
1406 | FONTSET_ADD (fontset, XCAR (script_range_list), font_def, add); | |
1407 | if (CONSP (script_range_list)) | |
1408 | { | |
1409 | if (SCRIPT_FROM < from) | |
1410 | range = Fcons (make_number (SCRIPT_FROM), XCDR (range)); | |
1411 | while (CONSP (script_range_list) && SCRIPT_TO <= to) | |
1412 | POP_SCRIPT_RANGE (); | |
1413 | if (CONSP (script_range_list) && SCRIPT_FROM <= to) | |
1414 | XSETCAR (XCAR (script_range_list), make_number (to + 1)); | |
fb78e2ed | 1415 | } |
a3d16f39 KH |
1416 | |
1417 | FONTSET_ADD (fontset, range, font_def, add); | |
1418 | ASET (arg, 4, script_range_list); | |
2449d4d0 KH |
1419 | } |
1420 | ||
8b67c40a | 1421 | extern Lisp_Object QCfamily, QCregistry; |
d6490542 KH |
1422 | static void update_auto_fontset_alist P_ ((Lisp_Object, Lisp_Object)); |
1423 | ||
d6aaac9e | 1424 | |
1d5d7200 | 1425 | DEFUN ("set-fontset-font", Fset_fontset_font, Sset_fontset_font, 3, 5, 0, |
8f924df7 | 1426 | doc: /* |
eb36588a | 1427 | Modify fontset NAME to use FONT-SPEC for TARGET characters. |
335c5470 | 1428 | |
a3d16f39 KH |
1429 | NAME is a fontset name string, nil for the fontset of FRAME, or t for |
1430 | the default fontset. | |
1431 | ||
eb36588a KH |
1432 | TARGET may be a cons; (FROM . TO), where FROM and TO are characters. |
1433 | In that case, use FONT-SPEC for all characters in the range FROM and | |
1434 | TO (inclusive). | |
06f76f0d | 1435 | |
eb36588a KH |
1436 | TARGET may be a script name symbol. In that case, use FONT-SPEC for |
1437 | all characters that belong to the script. | |
06f76f0d | 1438 | |
eb36588a | 1439 | TARGET may be a charset. In that case, use FONT-SPEC for all |
95318a38 | 1440 | characters in the charset. |
1d5d7200 | 1441 | |
eb36588a KH |
1442 | TARGET may be nil. In that case, use FONT-SPEC for any characters for |
1443 | that no FONT-SPEC is specified. | |
1444 | ||
0fdf26e6 | 1445 | FONT-SPEC may one of these: |
581f7ac7 | 1446 | * A font-spec object made by the function `font-spec' (which see). |
3dcd48dd | 1447 | * A cons (FAMILY . REGISTRY), where FAMILY is a font family name and |
581f7ac7 KH |
1448 | REGISTRY is a font registry name. FAMILY may contain foundry |
1449 | name, and REGISTRY may contain encoding name. | |
00c4da0f | 1450 | * A font name string. |
eaa0402c | 1451 | * nil, which explicitly specifies that there's no font for TARGET. |
1d5d7200 | 1452 | |
a3d16f39 KH |
1453 | Optional 4th argument FRAME is a frame or nil for the selected frame |
1454 | that is concerned in the case that NAME is nil. | |
1d5d7200 KH |
1455 | |
1456 | Optional 5th argument ADD, if non-nil, specifies how to add FONT-SPEC | |
eb36588a | 1457 | to the font specifications for TARGET previously set. If it is |
1d5d7200 KH |
1458 | `prepend', FONT-SPEC is prepended. If it is `append', FONT-SPEC is |
1459 | appended. By default, FONT-SPEC overrides the previous settings. */) | |
eb36588a KH |
1460 | (name, target, font_spec, frame, add) |
1461 | Lisp_Object name, target, font_spec, frame, add; | |
0d407d77 | 1462 | { |
06f76f0d | 1463 | Lisp_Object fontset; |
9683749a | 1464 | Lisp_Object font_def, registry, family; |
1d5d7200 | 1465 | Lisp_Object range_list; |
fb78e2ed | 1466 | struct charset *charset = NULL; |
d6490542 KH |
1467 | Lisp_Object fontname; |
1468 | int ascii_changed = 0; | |
0d407d77 | 1469 | |
a3d16f39 | 1470 | fontset = check_fontset_name (name, &frame); |
1d5d7200 | 1471 | |
d6490542 | 1472 | fontname = Qnil; |
581f7ac7 | 1473 | if (CONSP (font_spec)) |
0d407d77 | 1474 | { |
581f7ac7 | 1475 | Lisp_Object spec = Ffont_spec (0, NULL); |
1d5d7200 | 1476 | |
581f7ac7 KH |
1477 | font_parse_family_registry (XCAR (font_spec), XCDR (font_spec), spec); |
1478 | font_spec = spec; | |
d6490542 | 1479 | fontname = Ffont_xlfd_name (font_spec, Qnil); |
0890801b | 1480 | } |
d67f7f1a | 1481 | else if (STRINGP (font_spec)) |
4ed46869 | 1482 | { |
ea0162a6 | 1483 | Lisp_Object args[2]; |
581f7ac7 | 1484 | extern Lisp_Object QCname; |
ea0162a6 | 1485 | |
d6490542 | 1486 | fontname = font_spec; |
ea0162a6 KH |
1487 | args[0] = QCname; |
1488 | args[1] = font_spec; | |
1489 | font_spec = Ffont_spec (2, args); | |
0d407d77 | 1490 | } |
d6490542 KH |
1491 | else if (FONT_SPEC_P (font_spec)) |
1492 | fontname = Ffont_xlfd_name (font_spec, Qnil); | |
1493 | else if (! NILP (font_spec)) | |
581f7ac7 | 1494 | Fsignal (Qfont, list2 (build_string ("Invalid font-spec"), font_spec)); |
1d5d7200 | 1495 | |
d67f7f1a | 1496 | if (! NILP (font_spec)) |
57e13af9 | 1497 | { |
581f7ac7 KH |
1498 | Lisp_Object encoding, repertory; |
1499 | ||
d67f7f1a | 1500 | family = AREF (font_spec, FONT_FAMILY_INDEX); |
581f7ac7 | 1501 | if (! NILP (family) ) |
d67f7f1a KH |
1502 | family = SYMBOL_NAME (family); |
1503 | registry = AREF (font_spec, FONT_REGISTRY_INDEX); | |
581f7ac7 KH |
1504 | if (! NILP (registry)) |
1505 | registry = Fdowncase (SYMBOL_NAME (registry)); | |
1506 | encoding = find_font_encoding (concat3 (family, build_string ("-"), | |
1507 | registry)); | |
d67f7f1a KH |
1508 | if (NILP (encoding)) |
1509 | encoding = Qascii; | |
1510 | ||
1511 | if (SYMBOLP (encoding)) | |
1512 | { | |
1513 | CHECK_CHARSET (encoding); | |
1514 | encoding = repertory = CHARSET_SYMBOL_ID (encoding); | |
1515 | } | |
1516 | else | |
57e13af9 | 1517 | { |
d67f7f1a KH |
1518 | repertory = XCDR (encoding); |
1519 | encoding = XCAR (encoding); | |
1520 | CHECK_CHARSET (encoding); | |
1521 | encoding = CHARSET_SYMBOL_ID (encoding); | |
1522 | if (! NILP (repertory) && SYMBOLP (repertory)) | |
1523 | { | |
1524 | CHECK_CHARSET (repertory); | |
1525 | repertory = CHARSET_SYMBOL_ID (repertory); | |
1526 | } | |
57e13af9 | 1527 | } |
581f7ac7 | 1528 | FONT_DEF_NEW (font_def, font_spec, encoding, repertory); |
0d407d77 | 1529 | } |
d67f7f1a KH |
1530 | else |
1531 | font_def = Qnil; | |
4ed46869 | 1532 | |
eb36588a | 1533 | if (CHARACTERP (target)) |
d6490542 KH |
1534 | { |
1535 | if (XFASTINT (target) < 0x80) | |
1536 | error ("Can't set a font for partial ASCII range."); | |
1537 | range_list = Fcons (Fcons (target, target), Qnil); | |
1538 | } | |
eb36588a | 1539 | else if (CONSP (target)) |
0d407d77 | 1540 | { |
06f76f0d KH |
1541 | Lisp_Object from, to; |
1542 | ||
eb36588a KH |
1543 | from = Fcar (target); |
1544 | to = Fcdr (target); | |
06f76f0d KH |
1545 | CHECK_CHARACTER (from); |
1546 | CHECK_CHARACTER (to); | |
d6490542 KH |
1547 | if (XFASTINT (from) < 0x80) |
1548 | { | |
1549 | if (XFASTINT (from) != 0 || XFASTINT (to) < 0x7F) | |
1550 | error ("Can't set a font for partial ASCII range."); | |
1551 | ascii_changed = 1; | |
1552 | } | |
eb36588a | 1553 | range_list = Fcons (target, Qnil); |
4ed46869 | 1554 | } |
eb36588a | 1555 | else if (SYMBOLP (target) && !NILP (target)) |
8a9be3ac | 1556 | { |
1d5d7200 KH |
1557 | Lisp_Object script_list; |
1558 | Lisp_Object val; | |
0d407d77 | 1559 | |
1d5d7200 KH |
1560 | range_list = Qnil; |
1561 | script_list = XCHAR_TABLE (Vchar_script_table)->extras[0]; | |
eb36588a | 1562 | if (! NILP (Fmemq (target, script_list))) |
afe93d01 | 1563 | { |
d6490542 KH |
1564 | if (EQ (target, Qlatin)) |
1565 | ascii_changed = 1; | |
eb36588a | 1566 | val = Fcons (target, Qnil); |
1d5d7200 | 1567 | map_char_table (accumulate_script_ranges, Qnil, Vchar_script_table, |
8f924df7 | 1568 | val); |
a3d16f39 | 1569 | range_list = Fnreverse (XCDR (val)); |
afe93d01 | 1570 | } |
fb78e2ed | 1571 | if (CHARSETP (target)) |
afe93d01 | 1572 | { |
d6490542 KH |
1573 | CHECK_CHARSET_GET_CHARSET (target, charset); |
1574 | if (charset->ascii_compatible_p) | |
1575 | ascii_changed = 1; | |
afe93d01 | 1576 | } |
fb78e2ed | 1577 | else if (NILP (range_list)) |
1d5d7200 | 1578 | error ("Invalid script or charset name: %s", |
eb36588a | 1579 | SDATA (SYMBOL_NAME (target))); |
8a9be3ac | 1580 | } |
eb36588a KH |
1581 | else if (NILP (target)) |
1582 | range_list = Fcons (Qnil, Qnil); | |
1583 | else | |
1584 | error ("Invalid target for setting a font"); | |
0d407d77 | 1585 | |
a3d16f39 KH |
1586 | if (ascii_changed) |
1587 | { | |
1588 | Lisp_Object val; | |
1589 | ||
1590 | if (NILP (font_spec)) | |
1591 | error ("Can't set ASCII font to nil"); | |
1592 | val = CHAR_TABLE_REF (fontset, 0); | |
1593 | if (! NILP (val) && EQ (add, Qappend)) | |
1594 | /* We are going to change just an additional font for ASCII. */ | |
1595 | ascii_changed = 0; | |
1596 | } | |
fb78e2ed KH |
1597 | |
1598 | if (charset) | |
1599 | { | |
a3d16f39 KH |
1600 | Lisp_Object arg; |
1601 | ||
1602 | arg = Fmake_vector (make_number (5), Qnil); | |
1603 | ASET (arg, 0, fontset); | |
1604 | ASET (arg, 1, font_def); | |
1605 | ASET (arg, 2, add); | |
1606 | ASET (arg, 3, ascii_changed ? Qt : Qnil); | |
1607 | ASET (arg, 4, range_list); | |
fb78e2ed | 1608 | |
a3d16f39 | 1609 | map_charset_chars (set_fontset_font, Qnil, arg, charset, |
fb78e2ed KH |
1610 | CHARSET_MIN_CODE (charset), |
1611 | CHARSET_MAX_CODE (charset)); | |
a3d16f39 | 1612 | range_list = AREF (arg, 4); |
fb78e2ed | 1613 | } |
1d5d7200 KH |
1614 | for (; CONSP (range_list); range_list = XCDR (range_list)) |
1615 | FONTSET_ADD (fontset, XCAR (range_list), font_def, add); | |
4ed46869 | 1616 | |
d6490542 KH |
1617 | if (ascii_changed) |
1618 | { | |
1619 | Lisp_Object tail, frame, alist; | |
1620 | int fontset_id = XINT (FONTSET_ID (fontset)); | |
1621 | ||
d6490542 KH |
1622 | FONTSET_ASCII (fontset) = fontname; |
1623 | name = FONTSET_NAME (fontset); | |
1624 | FOR_EACH_FRAME (tail, frame) | |
1625 | { | |
1626 | FRAME_PTR f = XFRAME (frame); | |
1627 | Lisp_Object font_object; | |
0875632e | 1628 | struct face *face; |
d6490542 | 1629 | |
0875632e | 1630 | if (FRAME_INITIAL_P (f) || FRAME_TERMCAP_P (f)) |
d6490542 KH |
1631 | continue; |
1632 | if (fontset_id != FRAME_FONTSET (f)) | |
1633 | continue; | |
0875632e KH |
1634 | face = FACE_FROM_ID (f, DEFAULT_FACE_ID); |
1635 | if (face) | |
1636 | font_object = font_load_for_lface (f, face->lface, font_spec); | |
1637 | else | |
1638 | font_object = font_open_by_spec (f, font_spec); | |
d6490542 KH |
1639 | if (! NILP (font_object)) |
1640 | { | |
1641 | update_auto_fontset_alist (font_object, fontset); | |
0875632e | 1642 | alist = Fcons (Fcons (Qfont, Fcons (name, font_object)), Qnil); |
d6490542 KH |
1643 | Fmodify_frame_parameters (frame, alist); |
1644 | } | |
1645 | } | |
1646 | } | |
1647 | ||
0875632e KH |
1648 | /* Free all realized fontsets whose base is FONTSET. This way, the |
1649 | specified character(s) are surely redisplayed by a correct | |
1650 | font. */ | |
1651 | free_realized_fontsets (fontset); | |
1652 | ||
4ed46869 KH |
1653 | return Qnil; |
1654 | } | |
1655 | ||
06f76f0d KH |
1656 | |
1657 | DEFUN ("new-fontset", Fnew_fontset, Snew_fontset, 2, 2, 0, | |
1658 | doc: /* Create a new fontset NAME from font information in FONTLIST. | |
1659 | ||
1d5d7200 | 1660 | FONTLIST is an alist of scripts vs the corresponding font specification list. |
d6aaac9e KH |
1661 | Each element of FONTLIST has the form (SCRIPT FONT-SPEC ...), where a |
1662 | character of SCRIPT is displayed by a font that matches one of | |
1663 | FONT-SPEC. | |
06f76f0d | 1664 | |
d6aaac9e KH |
1665 | SCRIPT is a symbol that appears in the first extra slot of the |
1666 | char-table `char-script-table'. | |
06f76f0d | 1667 | |
1d5d7200 KH |
1668 | FONT-SPEC is a vector, a cons, or a string. See the documentation of |
1669 | `set-fontset-font' for the meaning. */) | |
06f76f0d KH |
1670 | (name, fontlist) |
1671 | Lisp_Object name, fontlist; | |
1672 | { | |
1d5d7200 | 1673 | Lisp_Object fontset; |
1d5d7200 | 1674 | int id; |
06f76f0d KH |
1675 | |
1676 | CHECK_STRING (name); | |
1677 | CHECK_LIST (fontlist); | |
1678 | ||
581f7ac7 | 1679 | name = Fdowncase (name); |
1d5d7200 KH |
1680 | id = fs_query_fontset (name, 0); |
1681 | if (id < 0) | |
0d407d77 | 1682 | { |
581f7ac7 KH |
1683 | Lisp_Object font_spec = Ffont_spec (0, NULL); |
1684 | Lisp_Object short_name; | |
5f2d79e0 | 1685 | char xlfd[256]; |
581f7ac7 KH |
1686 | int len; |
1687 | ||
dbf46ba6 | 1688 | if (font_parse_xlfd ((char *) SDATA (name), font_spec) < 0) |
d6aaac9e | 1689 | error ("Fontset name must be in XLFD format"); |
581f7ac7 | 1690 | short_name = AREF (font_spec, FONT_REGISTRY_INDEX); |
dbf46ba6 | 1691 | if (strncmp ((char *) SDATA (SYMBOL_NAME (short_name)), "fontset-", 8) |
581f7ac7 KH |
1692 | || SBYTES (SYMBOL_NAME (short_name)) < 9) |
1693 | error ("Registry field of fontset name must be \"fontset-*\""); | |
1694 | Vfontset_alias_alist = Fcons (Fcons (name, SYMBOL_NAME (short_name)), | |
1695 | Vfontset_alias_alist); | |
1696 | ASET (font_spec, FONT_REGISTRY_INDEX, Qiso8859_1); | |
d6aaac9e | 1697 | fontset = make_fontset (Qnil, name, Qnil); |
5f2d79e0 KH |
1698 | len = font_unparse_xlfd (font_spec, 0, xlfd, 256); |
1699 | if (len < 0) | |
1700 | error ("Invalid fontset name (perhaps too long): %s", SDATA (name)); | |
581f7ac7 | 1701 | FONTSET_ASCII (fontset) = make_unibyte_string (xlfd, len); |
d6aaac9e | 1702 | } |
1d5d7200 KH |
1703 | else |
1704 | { | |
8510724d | 1705 | fontset = FONTSET_FROM_ID (id); |
1d5d7200 KH |
1706 | free_realized_fontsets (fontset); |
1707 | Fset_char_table_range (fontset, Qt, Qnil); | |
0d407d77 | 1708 | } |
4ed46869 | 1709 | |
1d5d7200 KH |
1710 | for (; ! NILP (fontlist); fontlist = Fcdr (fontlist)) |
1711 | { | |
1712 | Lisp_Object elt, script; | |
1713 | ||
1714 | elt = Fcar (fontlist); | |
1715 | script = Fcar (elt); | |
cc36ddbf KH |
1716 | elt = Fcdr (elt); |
1717 | if (CONSP (elt) && (NILP (XCDR (elt)) || CONSP (XCDR (elt)))) | |
1718 | for (; CONSP (elt); elt = XCDR (elt)) | |
1719 | Fset_fontset_font (name, script, XCAR (elt), Qnil, Qappend); | |
1720 | else | |
1721 | Fset_fontset_font (name, script, elt, Qnil, Qappend); | |
1d5d7200 | 1722 | } |
06f76f0d KH |
1723 | return name; |
1724 | } | |
1725 | ||
1726 | ||
452a78e0 | 1727 | /* Alist of automatically created fontsets. Each element is a cons |
581f7ac7 | 1728 | (FONT-SPEC . FONTSET-ID). */ |
452a78e0 | 1729 | static Lisp_Object auto_fontset_alist; |
d6aaac9e | 1730 | |
d6490542 KH |
1731 | /* Number of automatically created fontsets. */ |
1732 | static int num_auto_fontsets; | |
1733 | ||
d8d2f142 KH |
1734 | /* Retun a fontset synthesized from FONT-OBJECT. This is called from |
1735 | x_new_font when FONT-OBJECT is used for the default ASCII font of a | |
1736 | frame, and the returned fontset is used for the default fontset of | |
1737 | that frame. The fontset specifies a font of the same registry as | |
1738 | FONT-OBJECT for all characters in the repertory of the registry | |
1739 | (see Vfont_encoding_alist). If the repertory is not known, the | |
1740 | fontset specifies the font for all Latin characters assuming that a | |
1741 | user intends to use FONT-OBJECT for Latin characters. */ | |
d6490542 | 1742 | |
d6aaac9e | 1743 | int |
581f7ac7 | 1744 | fontset_from_font (font_object) |
8aa07a8d KH |
1745 | Lisp_Object font_object; |
1746 | { | |
03ef560c | 1747 | Lisp_Object font_name = font_get_name (font_object); |
581f7ac7 | 1748 | Lisp_Object font_spec = Fcopy_font_spec (font_object); |
d6490542 | 1749 | Lisp_Object registry = AREF (font_spec, FONT_REGISTRY_INDEX); |
581f7ac7 KH |
1750 | Lisp_Object fontset_spec, alias, name, fontset; |
1751 | Lisp_Object val; | |
1752 | int i; | |
8aa07a8d | 1753 | |
581f7ac7 KH |
1754 | val = assoc_no_quit (font_spec, auto_fontset_alist); |
1755 | if (CONSP (val)) | |
1756 | return XINT (FONTSET_ID (XCDR (val))); | |
d6490542 | 1757 | if (num_auto_fontsets++ == 0) |
581f7ac7 | 1758 | alias = intern ("fontset-startup"); |
03ef560c KH |
1759 | else |
1760 | { | |
1761 | char temp[32]; | |
8aa07a8d | 1762 | |
d6490542 | 1763 | sprintf (temp, "fontset-auto%d", num_auto_fontsets - 1); |
581f7ac7 | 1764 | alias = intern (temp); |
03ef560c | 1765 | } |
581f7ac7 KH |
1766 | fontset_spec = Fcopy_font_spec (font_spec); |
1767 | ASET (fontset_spec, FONT_REGISTRY_INDEX, alias); | |
7ae2e7f0 | 1768 | name = Ffont_xlfd_name (fontset_spec, Qnil); |
03ef560c | 1769 | if (NILP (name)) |
581f7ac7 | 1770 | abort (); |
03ef560c | 1771 | fontset = make_fontset (Qnil, name, Qnil); |
581f7ac7 KH |
1772 | Vfontset_alias_alist = Fcons (Fcons (name, SYMBOL_NAME (alias)), |
1773 | Vfontset_alias_alist); | |
1774 | alias = Fdowncase (AREF (font_object, FONT_NAME_INDEX)); | |
1775 | Vfontset_alias_alist = Fcons (Fcons (name, alias), Vfontset_alias_alist); | |
1776 | auto_fontset_alist = Fcons (Fcons (font_spec, fontset), auto_fontset_alist); | |
d8d2f142 KH |
1777 | font_spec = Ffont_spec (0, NULL); |
1778 | ASET (font_spec, FONT_REGISTRY_INDEX, registry); | |
1779 | { | |
1780 | Lisp_Object target = find_font_encoding (SYMBOL_NAME (registry)); | |
1781 | ||
1782 | if (CONSP (target)) | |
1783 | target = XCDR (target); | |
1784 | if (! CHARSETP (target)) | |
1785 | target = Qlatin; | |
1786 | Fset_fontset_font (name, target, font_spec, Qnil, Qnil); | |
1787 | Fset_fontset_font (name, Qnil, font_spec, Qnil, Qnil); | |
1788 | } | |
1789 | ||
d6490542 | 1790 | FONTSET_ASCII (fontset) = font_name; |
edfda783 | 1791 | |
03ef560c | 1792 | return XINT (FONTSET_ID (fontset)); |
8aa07a8d KH |
1793 | } |
1794 | ||
d6490542 KH |
1795 | |
1796 | /* Update auto_fontset_alist for FONTSET. When an ASCII font of | |
1797 | FONTSET is changed, we delete an entry of FONTSET if any from | |
1798 | auto_fontset_alist so that FONTSET is not re-used by | |
1799 | fontset_from_font. */ | |
1800 | ||
1801 | static void | |
1802 | update_auto_fontset_alist (font_object, fontset) | |
1803 | Lisp_Object font_object, fontset; | |
1804 | { | |
1805 | Lisp_Object prev, tail; | |
1806 | ||
1807 | for (prev = Qnil, tail = auto_fontset_alist; CONSP (tail); | |
1808 | prev = tail, tail = XCDR (tail)) | |
1809 | if (EQ (fontset, XCDR (XCAR (tail)))) | |
1810 | { | |
1811 | if (NILP (prev)) | |
1812 | auto_fontset_alist = XCDR (tail); | |
1813 | else | |
1814 | XSETCDR (prev, XCDR (tail)); | |
1815 | break; | |
1816 | } | |
1817 | } | |
1818 | ||
1819 | ||
fe44f009 KH |
1820 | /* Return a cons (FONT-OBJECT . GLYPH-CODE). |
1821 | FONT-OBJECT is the font for the character at POSITION in the current | |
1ff005e1 | 1822 | buffer. This is computed from all the text properties and overlays |
cf14fd6e | 1823 | that apply to POSITION. POSTION may be nil, in which case, |
fe44f009 | 1824 | FONT-SPEC is the font for displaying the character CH with the |
cf14fd6e KH |
1825 | default face. |
1826 | ||
92c15c34 KH |
1827 | GLYPH-CODE is the glyph code in the font to use for the character. |
1828 | ||
1829 | If the 2nd optional arg CH is non-nil, it is a character to check | |
1830 | the font instead of the character at POSITION. | |
1831 | ||
1832 | It returns nil in the following cases: | |
1ff005e1 KH |
1833 | |
1834 | (1) The window system doesn't have a font for the character (thus | |
1835 | it is displayed by an empty box). | |
1836 | ||
1837 | (2) The character code is invalid. | |
1838 | ||
cf14fd6e KH |
1839 | (3) If POSITION is not nil, and the current buffer is not displayed |
1840 | in any window. | |
1ff005e1 KH |
1841 | |
1842 | In addition, the returned font name may not take into account of | |
1843 | such redisplay engine hooks as what used in jit-lock-mode if | |
1844 | POSITION is currently not visible. */ | |
1845 | ||
1846 | ||
92c15c34 | 1847 | DEFUN ("internal-char-font", Finternal_char_font, Sinternal_char_font, 1, 2, 0, |
335c5470 | 1848 | doc: /* For internal use only. */) |
92c15c34 KH |
1849 | (position, ch) |
1850 | Lisp_Object position, ch; | |
1ff005e1 | 1851 | { |
0f8b27ea | 1852 | EMACS_INT pos, pos_byte, dummy; |
1ff005e1 KH |
1853 | int face_id; |
1854 | int c; | |
1ff005e1 KH |
1855 | struct frame *f; |
1856 | struct face *face; | |
f0be8ea0 | 1857 | int cs_id; |
1ff005e1 | 1858 | |
cf14fd6e | 1859 | if (NILP (position)) |
92c15c34 KH |
1860 | { |
1861 | CHECK_CHARACTER (ch); | |
1862 | c = XINT (ch); | |
cf14fd6e | 1863 | f = XFRAME (selected_frame); |
f2cec7a9 | 1864 | face_id = lookup_basic_face (f, DEFAULT_FACE_ID); |
327719ee | 1865 | pos = -1; |
f0be8ea0 | 1866 | cs_id = -1; |
cf14fd6e KH |
1867 | } |
1868 | else | |
1869 | { | |
2f80c0a2 | 1870 | Lisp_Object window, charset; |
cf14fd6e KH |
1871 | struct window *w; |
1872 | ||
1873 | CHECK_NUMBER_COERCE_MARKER (position); | |
1874 | pos = XINT (position); | |
1875 | if (pos < BEGV || pos >= ZV) | |
1876 | args_out_of_range_3 (position, make_number (BEGV), make_number (ZV)); | |
1877 | pos_byte = CHAR_TO_BYTE (pos); | |
1878 | if (NILP (ch)) | |
1879 | c = FETCH_CHAR (pos_byte); | |
1880 | else | |
1881 | { | |
1882 | CHECK_NATNUM (ch); | |
1883 | c = XINT (ch); | |
1884 | } | |
1885 | window = Fget_buffer_window (Fcurrent_buffer (), Qnil); | |
1886 | if (NILP (window)) | |
1887 | return Qnil; | |
1888 | w = XWINDOW (window); | |
1889 | f = XFRAME (w->frame); | |
6970f632 CY |
1890 | face_id = face_at_buffer_position (w, pos, -1, -1, &dummy, |
1891 | pos + 100, 0, -1); | |
2f80c0a2 KH |
1892 | charset = Fget_char_property (position, Qcharset, Qnil); |
1893 | if (CHARSETP (charset)) | |
f0be8ea0 | 1894 | cs_id = XINT (CHARSET_SYMBOL_ID (charset)); |
2f80c0a2 | 1895 | else |
f0be8ea0 | 1896 | cs_id = -1; |
92c15c34 | 1897 | } |
1ff005e1 | 1898 | if (! CHAR_VALID_P (c, 0)) |
1ff005e1 | 1899 | return Qnil; |
327719ee | 1900 | face_id = FACE_FOR_CHAR (f, FACE_FROM_ID (f, face_id), c, pos, Qnil); |
1ff005e1 | 1901 | face = FACE_FROM_ID (f, face_id); |
581f7ac7 | 1902 | if (face->font) |
8aa07a8d | 1903 | { |
fe44f009 KH |
1904 | unsigned code = face->font->driver->encode_char (face->font, c); |
1905 | Lisp_Object font_object; | |
581f7ac7 KH |
1906 | /* Assignment to EMACS_INT stops GCC whining about limited range |
1907 | of data type. */ | |
1908 | EMACS_INT cod = code; | |
1909 | ||
1910 | if (code == FONT_INVALID_CODE) | |
1911 | return Qnil; | |
fe44f009 | 1912 | XSETFONT (font_object, face->font); |
581f7ac7 | 1913 | if (cod <= MOST_POSITIVE_FIXNUM) |
fe44f009 KH |
1914 | return Fcons (font_object, make_number (code)); |
1915 | return Fcons (font_object, Fcons (make_number (code >> 16), | |
581f7ac7 | 1916 | make_number (code & 0xFFFF))); |
92c15c34 KH |
1917 | } |
1918 | return Qnil; | |
1ff005e1 KH |
1919 | } |
1920 | ||
1921 | ||
1d5d7200 KH |
1922 | DEFUN ("fontset-info", Ffontset_info, Sfontset_info, 1, 2, 0, |
1923 | doc: /* Return information about a fontset FONTSET on frame FRAME. | |
e2b45cf9 | 1924 | |
a3d16f39 KH |
1925 | FONTSET is a fontset name string, nil for the fontset of FRAME, or t |
1926 | for the default fontset. FRAME nil means the selected frame. | |
1ff005e1 | 1927 | |
a3d16f39 | 1928 | The value is a char-table whose elements have this form: |
1ff005e1 | 1929 | |
a3d16f39 | 1930 | ((FONT OPENED-FONT ...) ...) |
1ff005e1 | 1931 | |
a3d16f39 | 1932 | FONT is a name of font specified for a range of characters. |
1ff005e1 | 1933 | |
d6aaac9e | 1934 | OPENED-FONT is a name of a font actually opened. |
1ff005e1 | 1935 | |
a3d16f39 KH |
1936 | The char-table has one extra slot. If FONTSET is not the default |
1937 | fontset, the value the extra slot is a char-table containing the | |
1938 | information about the derived fonts from the default fontset. The | |
1939 | format is the same as above. */) | |
1d5d7200 KH |
1940 | (fontset, frame) |
1941 | Lisp_Object fontset, frame; | |
4ed46869 KH |
1942 | { |
1943 | FRAME_PTR f; | |
cc7b6145 KH |
1944 | Lisp_Object *realized[2], fontsets[2], tables[2]; |
1945 | Lisp_Object val, elt; | |
1946 | int c, i, j, k; | |
fc8865fc | 1947 | |
4ed46869 KH |
1948 | (*check_window_system_func) (); |
1949 | ||
a3d16f39 | 1950 | fontset = check_fontset_name (fontset, &frame); |
18f39d0e | 1951 | f = XFRAME (frame); |
4ed46869 | 1952 | |
1d5d7200 KH |
1953 | /* Recode fontsets realized on FRAME from the base fontset FONTSET |
1954 | in the table `realized'. */ | |
cc7b6145 KH |
1955 | realized[0] = (Lisp_Object *) alloca (sizeof (Lisp_Object) |
1956 | * ASIZE (Vfontset_table)); | |
1957 | for (i = j = 0; i < ASIZE (Vfontset_table); i++) | |
0d407d77 | 1958 | { |
1ff005e1 KH |
1959 | elt = FONTSET_FROM_ID (i); |
1960 | if (!NILP (elt) | |
1d5d7200 KH |
1961 | && EQ (FONTSET_BASE (elt), fontset) |
1962 | && EQ (FONTSET_FRAME (elt), frame)) | |
cc7b6145 | 1963 | realized[0][j++] = elt; |
0d407d77 | 1964 | } |
cc7b6145 | 1965 | realized[0][j] = Qnil; |
4ed46869 | 1966 | |
cc7b6145 KH |
1967 | realized[1] = (Lisp_Object *) alloca (sizeof (Lisp_Object) |
1968 | * ASIZE (Vfontset_table)); | |
1969 | for (i = j = 0; ! NILP (realized[0][i]); i++) | |
1970 | { | |
1971 | elt = FONTSET_DEFAULT (realized[0][i]); | |
1972 | if (! NILP (elt)) | |
1973 | realized[1][j++] = elt; | |
1974 | } | |
1975 | realized[1][j] = Qnil; | |
1976 | ||
1977 | tables[0] = Fmake_char_table (Qfontset_info, Qnil); | |
cc7b6145 | 1978 | fontsets[0] = fontset; |
348db3dd | 1979 | if (!EQ (fontset, Vdefault_fontset)) |
a3d16f39 KH |
1980 | { |
1981 | tables[1] = Fmake_char_table (Qnil, Qnil); | |
1982 | XCHAR_TABLE (tables[0])->extras[0] = tables[1]; | |
1983 | fontsets[1] = Vdefault_fontset; | |
1984 | } | |
e2b45cf9 | 1985 | |
1d5d7200 KH |
1986 | /* Accumulate information of the fontset in TABLE. The format of |
1987 | each element is ((FONT-SPEC OPENED-FONT ...) ...). */ | |
cc7b6145 | 1988 | for (k = 0; k <= 1; k++) |
0d407d77 | 1989 | { |
cc7b6145 | 1990 | for (c = 0; c <= MAX_CHAR; ) |
d6aaac9e | 1991 | { |
5b30be1a | 1992 | int from = c, to = MAX_5_BYTE_CHAR; |
0d407d77 | 1993 | |
cc7b6145 KH |
1994 | if (c <= MAX_5_BYTE_CHAR) |
1995 | { | |
1996 | val = char_table_ref_and_range (fontsets[k], c, &from, &to); | |
cc7b6145 KH |
1997 | } |
1998 | else | |
1999 | { | |
2000 | val = FONTSET_FALLBACK (fontsets[k]); | |
2001 | to = MAX_CHAR; | |
2002 | } | |
d6aaac9e | 2003 | if (VECTORP (val)) |
0d407d77 | 2004 | { |
d6aaac9e KH |
2005 | Lisp_Object alist; |
2006 | ||
2007 | /* At first, set ALIST to ((FONT-SPEC) ...). */ | |
2008 | for (alist = Qnil, i = 0; i < ASIZE (val); i++) | |
581f7ac7 KH |
2009 | if (! NILP (AREF (val, i))) |
2010 | alist = Fcons (Fcons (FONT_DEF_SPEC (AREF (val, i)), Qnil), | |
2011 | alist); | |
d6aaac9e KH |
2012 | alist = Fnreverse (alist); |
2013 | ||
660100f3 | 2014 | /* Then store opened font names to cdr of each elements. */ |
cc7b6145 | 2015 | for (i = 0; ! NILP (realized[k][i]); i++) |
1ff005e1 | 2016 | { |
cc7b6145 KH |
2017 | if (c <= MAX_5_BYTE_CHAR) |
2018 | val = FONTSET_REF (realized[k][i], c); | |
2019 | else | |
2020 | val = FONTSET_FALLBACK (realized[k][i]); | |
a3d16f39 | 2021 | if (! CONSP (val) || ! VECTORP (XCDR (val))) |
d6aaac9e | 2022 | continue; |
a3d16f39 KH |
2023 | /* VAL: (int . [[FACE-ID FONT-DEF FONT-OBJECT int] ... ]) */ |
2024 | val = XCDR (val); | |
2025 | for (j = 0; j < ASIZE (val); j++) | |
3d4448a8 | 2026 | { |
581f7ac7 KH |
2027 | elt = AREF (val, j); |
2028 | if (FONT_OBJECT_P (RFONT_DEF_OBJECT (elt))) | |
2029 | { | |
2030 | Lisp_Object font_object = RFONT_DEF_OBJECT (elt); | |
2031 | Lisp_Object slot, name; | |
2032 | ||
2033 | slot = Fassq (RFONT_DEF_SPEC (elt), alist); | |
2034 | name = AREF (font_object, FONT_NAME_INDEX); | |
2035 | if (NILP (Fmember (name, XCDR (slot)))) | |
2036 | nconc2 (slot, Fcons (name, Qnil)); | |
2037 | } | |
3d4448a8 | 2038 | } |
1ff005e1 | 2039 | } |
d6aaac9e KH |
2040 | |
2041 | /* Store ALIST in TBL for characters C..TO. */ | |
cc7b6145 KH |
2042 | if (c <= MAX_5_BYTE_CHAR) |
2043 | char_table_set_range (tables[k], c, to, alist); | |
2044 | else | |
2045 | XCHAR_TABLE (tables[k])->defalt = alist; | |
581f7ac7 KH |
2046 | |
2047 | /* At last, change each elements to font names. */ | |
2048 | for (; CONSP (alist); alist = XCDR (alist)) | |
2049 | { | |
2050 | elt = XCAR (alist); | |
7ae2e7f0 | 2051 | XSETCAR (elt, Ffont_xlfd_name (XCAR (elt), Qnil)); |
581f7ac7 | 2052 | } |
0d407d77 | 2053 | } |
d6aaac9e | 2054 | c = to + 1; |
0d407d77 | 2055 | } |
348db3dd | 2056 | if (EQ (fontset, Vdefault_fontset)) |
a3d16f39 | 2057 | break; |
0d407d77 | 2058 | } |
a921395d | 2059 | |
cc7b6145 | 2060 | return tables[0]; |
4ed46869 KH |
2061 | } |
2062 | ||
1d5d7200 | 2063 | |
0fdf26e6 | 2064 | DEFUN ("fontset-font", Ffontset_font, Sfontset_font, 2, 3, 0, |
335c5470 | 2065 | doc: /* Return a font name pattern for character CH in fontset NAME. |
0fdf26e6 KH |
2066 | If NAME is t, find a pattern in the default fontset. |
2067 | ||
2068 | The value has the form (FAMILY . REGISTRY), where FAMILY is a font | |
2069 | family name and REGISTRY is a font registry name. This is actually | |
2070 | the first font name pattern for CH in the fontset or in the default | |
2071 | fontset. | |
2072 | ||
2073 | If the 2nd optional arg ALL is non-nil, return a list of all font name | |
2074 | patterns. */) | |
2075 | (name, ch, all) | |
2076 | Lisp_Object name, ch, all; | |
0d407d77 | 2077 | { |
1337ac77 | 2078 | int c; |
0fdf26e6 KH |
2079 | Lisp_Object fontset, elt, list, repertory, val; |
2080 | int i, j; | |
a3d16f39 | 2081 | Lisp_Object frame; |
0d407d77 | 2082 | |
a3d16f39 KH |
2083 | frame = Qnil; |
2084 | fontset = check_fontset_name (name, &frame); | |
0d407d77 | 2085 | |
06f76f0d | 2086 | CHECK_CHARACTER (ch); |
0d407d77 | 2087 | c = XINT (ch); |
0fdf26e6 KH |
2088 | list = Qnil; |
2089 | while (1) | |
2090 | { | |
2091 | for (i = 0, elt = FONTSET_REF (fontset, c); i < 2; | |
2092 | i++, elt = FONTSET_FALLBACK (fontset)) | |
2093 | if (VECTORP (elt)) | |
2094 | for (j = 0; j < ASIZE (elt); j++) | |
2095 | { | |
a124bbb6 KH |
2096 | Lisp_Object family, registry; |
2097 | ||
0fdf26e6 KH |
2098 | val = AREF (elt, j); |
2099 | repertory = AREF (val, 1); | |
2100 | if (INTEGERP (repertory)) | |
2101 | { | |
2102 | struct charset *charset = CHARSET_FROM_ID (XINT (repertory)); | |
2103 | ||
2104 | if (! CHAR_CHARSET_P (c, charset)) | |
2105 | continue; | |
2106 | } | |
2107 | else if (CHAR_TABLE_P (repertory)) | |
2108 | { | |
2109 | if (NILP (CHAR_TABLE_REF (repertory, c))) | |
2110 | continue; | |
2111 | } | |
2112 | val = AREF (val, 0); | |
a124bbb6 KH |
2113 | /* VAL is a FONT-SPEC */ |
2114 | family = AREF (val, FONT_FAMILY_INDEX); | |
2115 | if (! NILP (family)) | |
2116 | family = SYMBOL_NAME (family); | |
2117 | registry = AREF (val, FONT_REGISTRY_INDEX); | |
2118 | if (! NILP (registry)) | |
2119 | registry = SYMBOL_NAME (registry); | |
2120 | val = Fcons (family, registry); | |
0fdf26e6 KH |
2121 | if (NILP (all)) |
2122 | return val; | |
2123 | list = Fcons (val, list); | |
2124 | } | |
2125 | if (EQ (fontset, Vdefault_fontset)) | |
2126 | break; | |
2127 | fontset = Vdefault_fontset; | |
2128 | } | |
2129 | return (Fnreverse (list)); | |
0d407d77 | 2130 | } |
0d407d77 KH |
2131 | |
2132 | DEFUN ("fontset-list", Ffontset_list, Sfontset_list, 0, 0, 0, | |
335c5470 PJ |
2133 | doc: /* Return a list of all defined fontset names. */) |
2134 | () | |
0d407d77 KH |
2135 | { |
2136 | Lisp_Object fontset, list; | |
2137 | int i; | |
2138 | ||
2139 | list = Qnil; | |
2140 | for (i = 0; i < ASIZE (Vfontset_table); i++) | |
2141 | { | |
2142 | fontset = FONTSET_FROM_ID (i); | |
2143 | if (!NILP (fontset) | |
2144 | && BASE_FONTSET_P (fontset)) | |
2145 | list = Fcons (FONTSET_NAME (fontset), list); | |
2146 | } | |
1ff005e1 | 2147 | |
0d407d77 KH |
2148 | return list; |
2149 | } | |
2150 | ||
452a78e0 KH |
2151 | |
2152 | #ifdef FONTSET_DEBUG | |
2153 | ||
2154 | Lisp_Object | |
2155 | dump_fontset (fontset) | |
2156 | Lisp_Object fontset; | |
2157 | { | |
2158 | Lisp_Object vec; | |
2159 | ||
2160 | vec = Fmake_vector (make_number (3), Qnil); | |
2161 | ASET (vec, 0, FONTSET_ID (fontset)); | |
2162 | ||
2163 | if (BASE_FONTSET_P (fontset)) | |
2164 | { | |
2165 | ASET (vec, 1, FONTSET_NAME (fontset)); | |
2166 | } | |
2167 | else | |
2168 | { | |
2169 | Lisp_Object frame; | |
2170 | ||
2171 | frame = FONTSET_FRAME (fontset); | |
2172 | if (FRAMEP (frame)) | |
2173 | { | |
2174 | FRAME_PTR f = XFRAME (frame); | |
2175 | ||
2176 | if (FRAME_LIVE_P (f)) | |
1c82b4b3 KH |
2177 | ASET (vec, 1, |
2178 | Fcons (FONTSET_NAME (FONTSET_BASE (fontset)), f->name)); | |
452a78e0 | 2179 | else |
1c82b4b3 KH |
2180 | ASET (vec, 1, |
2181 | Fcons (FONTSET_NAME (FONTSET_BASE (fontset)), Qnil)); | |
452a78e0 | 2182 | } |
eb36588a KH |
2183 | if (!NILP (FONTSET_DEFAULT (fontset))) |
2184 | ASET (vec, 2, FONTSET_ID (FONTSET_DEFAULT (fontset))); | |
452a78e0 KH |
2185 | } |
2186 | return vec; | |
2187 | } | |
2188 | ||
2189 | DEFUN ("fontset-list-all", Ffontset_list_all, Sfontset_list_all, 0, 0, 0, | |
2190 | doc: /* Return a brief summary of all fontsets for debug use. */) | |
2191 | () | |
2192 | { | |
2193 | Lisp_Object val; | |
2194 | int i; | |
2195 | ||
2196 | for (i = 0, val = Qnil; i < ASIZE (Vfontset_table); i++) | |
2197 | if (! NILP (AREF (Vfontset_table, i))) | |
2198 | val = Fcons (dump_fontset (AREF (Vfontset_table, i)), val); | |
2199 | return (Fnreverse (val)); | |
2200 | } | |
2201 | #endif /* FONTSET_DEBUG */ | |
2202 | ||
dfcf069d | 2203 | void |
4ed46869 KH |
2204 | syms_of_fontset () |
2205 | { | |
1d5d7200 | 2206 | DEFSYM (Qfontset, "fontset"); |
eb36588a | 2207 | Fput (Qfontset, Qchar_table_extra_slots, make_number (9)); |
d6aaac9e KH |
2208 | DEFSYM (Qfontset_info, "fontset-info"); |
2209 | Fput (Qfontset_info, Qchar_table_extra_slots, make_number (1)); | |
4ed46869 | 2210 | |
1d5d7200 KH |
2211 | DEFSYM (Qprepend, "prepend"); |
2212 | DEFSYM (Qappend, "append"); | |
c3fb88cc | 2213 | DEFSYM (Qlatin, "latin"); |
4ed46869 KH |
2214 | |
2215 | Vcached_fontset_data = Qnil; | |
2216 | staticpro (&Vcached_fontset_data); | |
2217 | ||
0d407d77 KH |
2218 | Vfontset_table = Fmake_vector (make_number (32), Qnil); |
2219 | staticpro (&Vfontset_table); | |
0d407d77 KH |
2220 | |
2221 | Vdefault_fontset = Fmake_char_table (Qfontset, Qnil); | |
2222 | staticpro (&Vdefault_fontset); | |
1ff005e1 KH |
2223 | FONTSET_ID (Vdefault_fontset) = make_number (0); |
2224 | FONTSET_NAME (Vdefault_fontset) | |
2225 | = build_string ("-*-*-*-*-*-*-*-*-*-*-*-*-fontset-default"); | |
ff7a2223 | 2226 | ASET (Vfontset_table, 0, Vdefault_fontset); |
1ff005e1 | 2227 | next_fontset_id = 1; |
4ed46869 | 2228 | |
452a78e0 KH |
2229 | auto_fontset_alist = Qnil; |
2230 | staticpro (&auto_fontset_alist); | |
2231 | ||
28e2436a KH |
2232 | DEFVAR_LISP ("font-encoding-charset-alist", &Vfont_encoding_charset_alist, |
2233 | doc: /* | |
2234 | Alist of charsets vs the charsets to determine the preferred font encoding. | |
eb152aa9 | 2235 | Each element looks like (CHARSET . ENCODING-CHARSET), |
28e2436a KH |
2236 | where ENCODING-CHARSET is a charset registered in the variable |
2237 | `font-encoding-alist' as ENCODING. | |
2238 | ||
2239 | When a text has a property `charset' and the value is CHARSET, a font | |
2240 | whose encoding corresponds to ENCODING-CHARSET is preferred. */); | |
2241 | Vfont_encoding_charset_alist = Qnil; | |
2242 | ||
6a7e6d80 | 2243 | DEFVAR_LISP ("use-default-ascent", &Vuse_default_ascent, |
1d5d7200 KH |
2244 | doc: /* |
2245 | Char table of characters whose ascent values should be ignored. | |
335c5470 | 2246 | If an entry for a character is non-nil, the ascent value of the glyph |
eb152aa9 | 2247 | is assumed to be specified by _MULE_DEFAULT_ASCENT property of a font. |
335c5470 PJ |
2248 | |
2249 | This affects how a composite character which contains | |
2250 | such a character is displayed on screen. */); | |
2aeafb78 KH |
2251 | Vuse_default_ascent = Qnil; |
2252 | ||
2253 | DEFVAR_LISP ("ignore-relative-composition", &Vignore_relative_composition, | |
1d5d7200 | 2254 | doc: /* |
eb152aa9 | 2255 | Char table of characters which are not composed relatively. |
335c5470 PJ |
2256 | If an entry for a character is non-nil, a composition sequence |
2257 | which contains that character is displayed so that | |
2258 | the glyph of that character is put without considering | |
2259 | an ascent and descent value of a previous character. */); | |
810abb87 | 2260 | Vignore_relative_composition = Qnil; |
6a7e6d80 | 2261 | |
01d4b817 | 2262 | DEFVAR_LISP ("alternate-fontname-alist", &Valternate_fontname_alist, |
335c5470 PJ |
2263 | doc: /* Alist of fontname vs list of the alternate fontnames. |
2264 | When a specified font name is not found, the corresponding | |
2265 | alternate fontnames (if any) are tried instead. */); | |
01d4b817 | 2266 | Valternate_fontname_alist = Qnil; |
8c83e4f9 | 2267 | |
1c283e35 | 2268 | DEFVAR_LISP ("fontset-alias-alist", &Vfontset_alias_alist, |
335c5470 | 2269 | doc: /* Alist of fontset names vs the aliases. */); |
1ff005e1 KH |
2270 | Vfontset_alias_alist = Fcons (Fcons (FONTSET_NAME (Vdefault_fontset), |
2271 | build_string ("fontset-default")), | |
2272 | Qnil); | |
1c283e35 | 2273 | |
810abb87 KH |
2274 | DEFVAR_LISP ("vertical-centering-font-regexp", |
2275 | &Vvertical_centering_font_regexp, | |
335c5470 PJ |
2276 | doc: /* *Regexp matching font names that require vertical centering on display. |
2277 | When a character is displayed with such fonts, the character is displayed | |
fc8865fc | 2278 | at the vertical center of lines. */); |
810abb87 KH |
2279 | Vvertical_centering_font_regexp = Qnil; |
2280 | ||
21ff5ed6 KH |
2281 | DEFVAR_LISP ("otf-script-alist", &Votf_script_alist, |
2282 | doc: /* Alist of OpenType script tags vs the corresponding script names. */); | |
2283 | Votf_script_alist = Qnil; | |
2284 | ||
4ed46869 KH |
2285 | defsubr (&Squery_fontset); |
2286 | defsubr (&Snew_fontset); | |
2287 | defsubr (&Sset_fontset_font); | |
1ff005e1 | 2288 | defsubr (&Sinternal_char_font); |
4ed46869 | 2289 | defsubr (&Sfontset_info); |
0d407d77 KH |
2290 | defsubr (&Sfontset_font); |
2291 | defsubr (&Sfontset_list); | |
452a78e0 KH |
2292 | #ifdef FONTSET_DEBUG |
2293 | defsubr (&Sfontset_list_all); | |
2294 | #endif | |
e3400864 | 2295 | } |
92c15c34 KH |
2296 | |
2297 | /* arch-tag: ea861585-2f5f-4e5b-9849-d04a9c3a3537 | |
2298 | (do not change this comment) */ |