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