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