Limit <config.h>’s includes
[emacs.git] / src / fontset.c
blobfe595d81a3e95b6be7326cb0bc003ceec3d84784
1 /* Fontset handler.
3 Copyright (C) 2001-2016 Free Software Foundation, Inc.
4 Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5 2005, 2006, 2007, 2008, 2009, 2010, 2011
6 National Institute of Advanced Industrial Science and Technology (AIST)
7 Registration Number H14PRO021
8 Copyright (C) 2003, 2006
9 National Institute of Advanced Industrial Science and Technology (AIST)
10 Registration Number H13PRO009
12 This file is part of GNU Emacs.
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 (at
17 your option) any later version.
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.
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/>. */
27 #include <config.h>
28 #include <stdio.h>
29 #include <stdlib.h>
31 #include "lisp.h"
32 #include "blockinput.h"
33 #include "character.h"
34 #include "charset.h"
35 #include "frame.h"
36 #include "dispextern.h"
37 #include "fontset.h"
38 #ifdef HAVE_WINDOW_SYSTEM
39 #include TERM_HEADER
40 #endif /* HAVE_WINDOW_SYSTEM */
41 #include "font.h"
43 /* FONTSET
45 A fontset is a collection of font related information to give
46 similar appearance (style, etc) of characters. A fontset has two
47 roles. One is to use for the frame parameter `font' as if it is an
48 ASCII font. In that case, Emacs uses the font specified for
49 `ascii' script for the frame's default font.
51 Another role, the more important one, is to provide information
52 about which font to use for each non-ASCII character.
54 There are two kinds of fontsets; base and realized. A base fontset
55 is created by `new-fontset' from Emacs Lisp explicitly. A realized
56 fontset is created implicitly when a face is realized for ASCII
57 characters. A face is also realized for non-ASCII characters based
58 on an ASCII face. All of non-ASCII faces based on the same ASCII
59 face share the same realized fontset.
61 A fontset object is implemented by a char-table whose default value
62 and parent are always nil.
64 An element of a base fontset is a vector of FONT-DEFs which themselves
65 are vectors of the form [ FONT-SPEC ENCODING REPERTORY ].
67 An element of a realized fontset is nil, t, 0, or a cons that has
68 this from:
70 (CHARSET-ORDERED-LIST-TICK . FONT-GROUP)
72 CHARSET_ORDERED_LIST_TICK is the same as charset_ordered_list_tick or -1.
74 FONT-GROUP is a vector of elements that have this form:
76 [ RFONT-DEF0 RFONT-DEF1 ... ]
78 Each RFONT-DEFn (i.e. Realized FONT-DEF) has this form:
80 [ FACE-ID FONT-DEF FONT-OBJECT SORTING-SCORE ]
82 RFONT-DEFn are automatically reordered considering the current
83 charset priority list, the current language environment, and
84 priorities determined by font-backends.
86 RFONT-DEFn may not be a vector in the following cases.
88 The value nil means that we have not yet generated the above vector
89 from the base of the fontset.
91 The value t means that no font is available for the corresponding
92 range of characters.
94 The value 0 means that no font is available for the corresponding
95 range of characters in this fontset, but may be available in the
96 fallback font-group or in the default fontset.
98 A fontset has 8 extra slots.
100 The 1st slot:
101 base: the ID number of the fontset
102 realized: Likewise
104 The 2nd slot:
105 base: the name of the fontset
106 realized: nil
108 The 3rd slot:
109 base: the font name for ASCII characters
110 realized: nil
112 The 4th slot:
113 base: nil
114 realized: the base fontset
116 The 5th slot:
117 base: nil
118 realized: the frame that the fontset belongs to
120 The 6th slot:
121 base: nil
122 realized: the ID number of a face to use for characters that
123 has no font in a realized fontset.
125 The 7th slot:
126 base: nil
127 realized: If the base is not the default fontset, a fontset
128 realized from the default fontset, else nil.
130 The 8th slot:
131 base: Same as element value (but for fallback fonts).
132 realized: Likewise.
134 All fontsets are recorded in the vector Vfontset_table.
137 DEFAULT FONTSET
139 There's a special base fontset named `default fontset' which
140 defines the default font specifications. When a base fontset
141 doesn't specify a font for a specific character, the corresponding
142 value in the default fontset is used.
144 The parent of a realized fontset created for such a face that has
145 no fontset is the default fontset.
148 These structures are hidden from the other codes than this file.
149 The other codes handle fontsets only by their ID numbers. They
150 usually use the variable name `fontset' for IDs. But, in this
151 file, we always use variable name `id' for IDs, and name `fontset'
152 for an actual fontset object, i.e., char-table.
156 /********** VARIABLES and FUNCTION PROTOTYPES **********/
158 /* Vector containing all fontsets. */
159 static Lisp_Object Vfontset_table;
161 /* Next possibly free fontset ID. Usually this keeps the minimum
162 fontset ID not yet used. */
163 static int next_fontset_id;
165 /* The default fontset. This gives default FAMILY and REGISTRY of
166 font for each character. */
167 static Lisp_Object Vdefault_fontset;
169 /* Prototype declarations for static functions. */
170 static Lisp_Object make_fontset (Lisp_Object, Lisp_Object, Lisp_Object);
172 /* Return true if ID is a valid fontset id.
173 Optimized away if ENABLE_CHECKING is not defined. */
175 static bool
176 fontset_id_valid_p (int id)
178 return (id >= 0 && id < ASIZE (Vfontset_table) - 1);
183 /********** MACROS AND FUNCTIONS TO HANDLE FONTSET **********/
185 /* Return the fontset with ID. No check of ID's validness. */
186 #define FONTSET_FROM_ID(id) AREF (Vfontset_table, id)
188 /* Access special values of FONTSET. */
190 #define FONTSET_ID(fontset) XCHAR_TABLE (fontset)->extras[0]
191 static void
192 set_fontset_id (Lisp_Object fontset, Lisp_Object id)
194 set_char_table_extras (fontset, 0, id);
197 /* Access special values of (base) FONTSET. */
199 #define FONTSET_NAME(fontset) XCHAR_TABLE (fontset)->extras[1]
200 static void
201 set_fontset_name (Lisp_Object fontset, Lisp_Object name)
203 set_char_table_extras (fontset, 1, name);
206 #define FONTSET_ASCII(fontset) XCHAR_TABLE (fontset)->extras[2]
207 static void
208 set_fontset_ascii (Lisp_Object fontset, Lisp_Object ascii)
210 set_char_table_extras (fontset, 2, ascii);
213 /* Access special values of (realized) FONTSET. */
215 #define FONTSET_BASE(fontset) XCHAR_TABLE (fontset)->extras[3]
216 static void
217 set_fontset_base (Lisp_Object fontset, Lisp_Object base)
219 set_char_table_extras (fontset, 3, base);
222 #define FONTSET_FRAME(fontset) XCHAR_TABLE (fontset)->extras[4]
223 static void
224 set_fontset_frame (Lisp_Object fontset, Lisp_Object frame)
226 set_char_table_extras (fontset, 4, frame);
229 #define FONTSET_NOFONT_FACE(fontset) XCHAR_TABLE (fontset)->extras[5]
230 static void
231 set_fontset_nofont_face (Lisp_Object fontset, Lisp_Object face)
233 set_char_table_extras (fontset, 5, face);
236 #define FONTSET_DEFAULT(fontset) XCHAR_TABLE (fontset)->extras[6]
237 static void
238 set_fontset_default (Lisp_Object fontset, Lisp_Object def)
240 set_char_table_extras (fontset, 6, def);
243 /* For both base and realized fontset. */
245 #define FONTSET_FALLBACK(fontset) XCHAR_TABLE (fontset)->extras[7]
246 static void
247 set_fontset_fallback (Lisp_Object fontset, Lisp_Object fallback)
249 set_char_table_extras (fontset, 7, fallback);
252 #define BASE_FONTSET_P(fontset) (NILP (FONTSET_BASE (fontset)))
254 /* Macros for FONT-DEF and RFONT-DEF of fontset. */
255 #define FONT_DEF_NEW(font_def, font_spec, encoding, repertory) \
256 do { \
257 (font_def) = make_uninit_vector (3); \
258 ASET ((font_def), 0, font_spec); \
259 ASET ((font_def), 1, encoding); \
260 ASET ((font_def), 2, repertory); \
261 } while (0)
263 #define FONT_DEF_SPEC(font_def) AREF (font_def, 0)
264 #define FONT_DEF_ENCODING(font_def) AREF (font_def, 1)
265 #define FONT_DEF_REPERTORY(font_def) AREF (font_def, 2)
267 #define RFONT_DEF_FACE(rfont_def) AREF (rfont_def, 0)
268 #define RFONT_DEF_SET_FACE(rfont_def, face_id) \
269 ASET ((rfont_def), 0, make_number (face_id))
270 #define RFONT_DEF_FONT_DEF(rfont_def) AREF (rfont_def, 1)
271 #define RFONT_DEF_SPEC(rfont_def) FONT_DEF_SPEC (AREF (rfont_def, 1))
272 #define RFONT_DEF_OBJECT(rfont_def) AREF (rfont_def, 2)
273 #define RFONT_DEF_SET_OBJECT(rfont_def, object) \
274 ASET ((rfont_def), 2, (object))
275 /* Score of RFONT_DEF is an integer value; the lowest 8 bits represent
276 the order of listing by font backends, the higher bits represents
277 the order given by charset priority list. The smaller value is
278 preferable. */
279 #define RFONT_DEF_SCORE(rfont_def) XINT (AREF (rfont_def, 3))
280 #define RFONT_DEF_SET_SCORE(rfont_def, score) \
281 ASET ((rfont_def), 3, make_number (score))
282 #define RFONT_DEF_NEW(rfont_def, font_def) \
283 do { \
284 (rfont_def) = Fmake_vector (make_number (4), Qnil); \
285 ASET ((rfont_def), 1, (font_def)); \
286 RFONT_DEF_SET_SCORE ((rfont_def), 0); \
287 } while (0)
290 /* Return the element of FONTSET for the character C. If FONTSET is a
291 base fontset other then the default fontset and FONTSET doesn't
292 contain information for C, return the information in the default
293 fontset. */
295 #define FONTSET_REF(fontset, c) \
296 (EQ (fontset, Vdefault_fontset) \
297 ? CHAR_TABLE_REF (fontset, c) \
298 : fontset_ref ((fontset), (c)))
300 static Lisp_Object
301 fontset_ref (Lisp_Object fontset, int c)
303 Lisp_Object elt;
305 elt = CHAR_TABLE_REF (fontset, c);
306 if (NILP (elt) && ! EQ (fontset, Vdefault_fontset)
307 /* Don't check Vdefault_fontset for a realized fontset. */
308 && NILP (FONTSET_BASE (fontset)))
309 elt = CHAR_TABLE_REF (Vdefault_fontset, c);
310 return elt;
313 /* Set elements of FONTSET for characters in RANGE to the value ELT.
314 RANGE is a cons (FROM . TO), where FROM and TO are character codes
315 specifying a range. */
317 #define FONTSET_SET(fontset, range, elt) \
318 Fset_char_table_range ((fontset), (range), (elt))
321 /* Modify the elements of FONTSET for characters in RANGE by replacing
322 with ELT or adding ELT. RANGE is a cons (FROM . TO), where FROM
323 and TO are character codes specifying a range. If ADD is nil,
324 replace with ELT, if ADD is `prepend', prepend ELT, otherwise,
325 append ELT. */
327 #define FONTSET_ADD(fontset, range, elt, add) \
328 (NILP (add) \
329 ? (NILP (range) \
330 ? (set_fontset_fallback \
331 (fontset, Fmake_vector (make_number (1), (elt)))) \
332 : ((void) \
333 Fset_char_table_range (fontset, range, \
334 Fmake_vector (make_number (1), elt)))) \
335 : fontset_add ((fontset), (range), (elt), (add)))
337 static void
338 fontset_add (Lisp_Object fontset, Lisp_Object range, Lisp_Object elt, Lisp_Object add)
340 Lisp_Object args[2];
341 int idx = (EQ (add, Qappend) ? 0 : 1);
343 args[1 - idx] = Fmake_vector (make_number (1), elt);
345 if (CONSP (range))
347 int from = XINT (XCAR (range));
348 int to = XINT (XCDR (range));
349 int from1, to1;
351 do {
352 from1 = from, to1 = to;
353 args[idx] = char_table_ref_and_range (fontset, from, &from1, &to1);
354 char_table_set_range (fontset, from, to1,
355 (NILP (args[idx]) ? args[1 - idx]
356 : CALLMANY (Fvconcat, args)));
357 from = to1 + 1;
358 } while (from < to);
360 else
362 args[idx] = FONTSET_FALLBACK (fontset);
363 set_fontset_fallback (fontset,
364 (NILP (args[idx]) ? args[1 - idx]
365 : CALLMANY (Fvconcat, args)));
369 static int
370 fontset_compare_rfontdef (const void *val1, const void *val2)
372 return (RFONT_DEF_SCORE (*(Lisp_Object *) val1)
373 - RFONT_DEF_SCORE (*(Lisp_Object *) val2));
376 /* Update a cons cell which has this form:
377 (CHARSET-ORDERED-LIST-TICK . FONT-GROUP)
378 where FONT-GROUP is of the form
379 [ PREFERRED-RFONT-DEF RFONT-DEF0 RFONT-DEF1 ... ]
380 Reorder RFONT-DEFs according to the current language, and update
381 CHARSET-ORDERED-LIST-TICK. */
383 static void
384 reorder_font_vector (Lisp_Object font_group, struct font *font)
386 Lisp_Object vec, font_object;
387 int size;
388 int i;
389 bool score_changed = false;
391 if (font)
392 XSETFONT (font_object, font);
393 else
394 font_object = Qnil;
396 vec = XCDR (font_group);
397 size = ASIZE (vec);
398 /* Exclude the tailing nil element from the reordering. */
399 if (NILP (AREF (vec, size - 1)))
400 size--;
402 for (i = 0; i < size; i++)
404 Lisp_Object rfont_def = AREF (vec, i);
405 Lisp_Object font_def = RFONT_DEF_FONT_DEF (rfont_def);
406 Lisp_Object font_spec = FONT_DEF_SPEC (font_def);
407 int score = RFONT_DEF_SCORE (rfont_def) & 0xFF;
408 Lisp_Object otf_spec = Ffont_get (font_spec, QCotf);
410 if (! NILP (otf_spec))
411 /* A font-spec with :otf is preferable regardless of encoding
412 and language.. */
414 else if (! font_match_p (font_spec, font_object))
416 Lisp_Object encoding = FONT_DEF_ENCODING (font_def);
418 if (! NILP (encoding))
420 /* This spec specifies an encoding by a charset set
421 name. Reflect the preference order of that charset
422 in the upper bits of SCORE. */
423 Lisp_Object tail;
425 for (tail = Vcharset_ordered_list;
426 ! EQ (tail, Vcharset_non_preferred_head) && CONSP (tail);
427 tail = XCDR (tail))
428 if (EQ (encoding, XCAR (tail)))
429 break;
430 else if (score <= min (INT_MAX, MOST_POSITIVE_FIXNUM) - 0x100)
431 score += 0x100;
433 else
435 /* This spec does not specify an encoding. If the spec
436 specifies a language, and the language is not for the
437 current language environment, make the score
438 larger. */
439 Lisp_Object lang = Ffont_get (font_spec, QClang);
441 if (! NILP (lang)
442 && ! EQ (lang, Vcurrent_iso639_language)
443 && (! CONSP (Vcurrent_iso639_language)
444 || NILP (Fmemq (lang, Vcurrent_iso639_language))))
445 score |= 0x100;
448 if (RFONT_DEF_SCORE (rfont_def) != score)
450 RFONT_DEF_SET_SCORE (rfont_def, score);
451 score_changed = true;
455 if (score_changed)
456 qsort (XVECTOR (vec)->contents, size, word_size,
457 fontset_compare_rfontdef);
458 EMACS_INT low_tick_bits = charset_ordered_list_tick & MOST_POSITIVE_FIXNUM;
459 XSETCAR (font_group, make_number (low_tick_bits));
462 /* Return a font-group (actually a cons (CHARSET_ORDERED_LIST_TICK
463 . FONT-GROUP)) for character C or a fallback font-group in the
464 realized fontset FONTSET. The elements of FONT-GROUP are
465 RFONT-DEFs. The value may not be a cons. See the comment at the
466 head of this file for the detail of the return value. */
468 static Lisp_Object
469 fontset_get_font_group (Lisp_Object fontset, int c)
471 Lisp_Object font_group;
472 Lisp_Object base_fontset;
473 int from = 0, to = MAX_CHAR, i;
475 eassert (! BASE_FONTSET_P (fontset));
476 if (c >= 0)
477 font_group = CHAR_TABLE_REF (fontset, c);
478 else
479 font_group = FONTSET_FALLBACK (fontset);
480 if (! NILP (font_group))
481 /* We have already realized FONT-DEFs of this font group for C or
482 for fallback (FONT_GROUP is a cons), or we have already found
483 that no appropriate font was found (FONT_GROUP is t or 0). */
484 return font_group;
485 base_fontset = FONTSET_BASE (fontset);
486 if (NILP (base_fontset))
487 /* Actually we never come here because FONTSET is a realized one,
488 and thus it should have a base. */
489 font_group = Qnil;
490 else if (c >= 0)
491 font_group = char_table_ref_and_range (base_fontset, c, &from, &to);
492 else
493 font_group = FONTSET_FALLBACK (base_fontset);
495 /* FONT_GROUP not being a vector means that no fonts are specified
496 for C, or the fontset does not have fallback fonts. */
497 if (NILP (font_group))
499 font_group = make_number (0);
500 if (c >= 0)
501 /* Record that FONTSET does not specify fonts for C. As
502 there's a possibility that a font is found in a fallback
503 font group, we set 0 at the moment. */
504 char_table_set_range (fontset, from, to, font_group);
505 return font_group;
507 if (!VECTORP (font_group))
508 return font_group;
510 /* Now realize FONT-DEFs of this font group, and update the realized
511 fontset FONTSET. */
512 font_group = Fcopy_sequence (font_group);
513 for (i = 0; i < ASIZE (font_group); i++)
514 if (! NILP (AREF (font_group, i)))
516 Lisp_Object rfont_def;
518 RFONT_DEF_NEW (rfont_def, AREF (font_group, i));
519 /* Remember the original order. */
520 RFONT_DEF_SET_SCORE (rfont_def, i);
521 ASET (font_group, i, rfont_def);
523 font_group = Fcons (make_number (-1), font_group);
524 if (c >= 0)
525 char_table_set_range (fontset, from, to, font_group);
526 else
527 set_fontset_fallback (fontset, font_group);
528 return font_group;
531 /* Return RFONT-DEF (vector) in the realized fontset FONTSET for the
532 character C. If no font is found, return Qnil or 0 if there's a
533 possibility that the default fontset or the fallback font groups
534 have a proper font, and return Qt if not.
536 If a font is found but is not yet opened, open it (if FACE is not
537 NULL) or return Qnil (if FACE is NULL).
539 CHARSET_ID is a charset-id that must be preferred, or -1 meaning no
540 preference.
542 If FALLBACK, search only fallback fonts. */
544 static Lisp_Object
545 fontset_find_font (Lisp_Object fontset, int c, struct face *face,
546 int charset_id, bool fallback)
548 Lisp_Object vec, font_group;
549 int i, charset_matched = 0, found_index;
550 struct frame *f = (FRAMEP (FONTSET_FRAME (fontset))
551 ? XFRAME (FONTSET_FRAME (fontset))
552 : XFRAME (selected_frame));
553 Lisp_Object rfont_def;
555 font_group = fontset_get_font_group (fontset, fallback ? -1 : c);
556 if (! CONSP (font_group))
557 return font_group;
558 vec = XCDR (font_group);
559 if (ASIZE (vec) == 0)
560 return Qnil;
562 if (ASIZE (vec) > 1)
564 if (XINT (XCAR (font_group)) != charset_ordered_list_tick)
565 /* We have just created the font-group,
566 or the charset priorities were changed. */
567 reorder_font_vector (font_group, face->ascii_face->font);
568 if (charset_id >= 0)
569 /* Find a spec matching with CHARSET_ID to try it at
570 first. */
571 for (i = 0; i < ASIZE (vec); i++)
573 Lisp_Object repertory;
575 rfont_def = AREF (vec, i);
576 if (NILP (rfont_def))
577 break;
578 repertory = FONT_DEF_REPERTORY (RFONT_DEF_FONT_DEF (rfont_def));
580 if (XINT (repertory) == charset_id)
582 charset_matched = i;
583 break;
588 /* Find the first available font in the vector of RFONT-DEF. If
589 CHARSET_MATCHED > 0, try the corresponding RFONT-DEF first, then
590 try the rest. */
591 for (i = 0; i < ASIZE (vec); i++)
593 Lisp_Object font_def;
594 Lisp_Object font_entity, font_object;
596 found_index = i;
597 if (i == 0)
599 if (charset_matched > 0)
601 /* Try the element matching with CHARSET_ID at first. */
602 found_index = charset_matched;
603 /* Make this negative so that we don't come here in the
604 next loop. */
605 charset_matched = - charset_matched;
606 /* We must try the first element in the next loop. */
607 i = -1;
610 else if (i == - charset_matched)
612 /* We have already tried this element and the followings
613 that have the same font specifications in the first
614 iteration. So, skip them all. */
615 rfont_def = AREF (vec, i);
616 font_def = RFONT_DEF_FONT_DEF (rfont_def);
617 for (; i + 1 < ASIZE (vec); i++)
619 rfont_def = AREF (vec, i + 1);
620 if (NILP (rfont_def))
621 break;
622 if (! EQ (RFONT_DEF_FONT_DEF (rfont_def), font_def))
623 break;
625 continue;
628 rfont_def = AREF (vec, found_index);
629 if (NILP (rfont_def))
631 if (i < 0)
632 continue;
633 /* This is a sign of not to try the other fonts. */
634 return Qt;
636 if (INTEGERP (RFONT_DEF_FACE (rfont_def))
637 && XINT (RFONT_DEF_FACE (rfont_def)) < 0)
638 /* We couldn't open this font last time. */
639 continue;
641 font_object = RFONT_DEF_OBJECT (rfont_def);
642 if (NILP (font_object))
644 font_def = RFONT_DEF_FONT_DEF (rfont_def);
646 if (! face)
647 /* We have not yet opened the font. */
648 return Qnil;
649 /* Find a font best-matching with the spec without checking
650 the support of the character C. That checking is costly,
651 and even without the checking, the found font supports C
652 in high possibility. */
653 font_entity = font_find_for_lface (f, face->lface,
654 FONT_DEF_SPEC (font_def), -1);
655 if (NILP (font_entity))
657 /* Record that no font matches the spec. */
658 RFONT_DEF_SET_FACE (rfont_def, -1);
659 continue;
661 font_object = font_open_for_lface (f, font_entity, face->lface,
662 FONT_DEF_SPEC (font_def));
663 if (NILP (font_object))
665 /* Something strange happened, perhaps because of a
666 Font-backend problem. To avoid crashing, record
667 that this spec is unusable. It may be better to find
668 another font of the same spec, but currently we don't
669 have such an API in font-backend. */
670 RFONT_DEF_SET_FACE (rfont_def, -1);
671 continue;
673 RFONT_DEF_SET_OBJECT (rfont_def, font_object);
676 if (font_has_char (f, font_object, c))
677 goto found;
679 /* Find a font already opened, matching with the current spec,
680 and supporting C. */
681 font_def = RFONT_DEF_FONT_DEF (rfont_def);
682 for (; found_index + 1 < ASIZE (vec); found_index++)
684 rfont_def = AREF (vec, found_index + 1);
685 if (NILP (rfont_def))
686 break;
687 if (! EQ (RFONT_DEF_FONT_DEF (rfont_def), font_def))
688 break;
689 font_object = RFONT_DEF_OBJECT (rfont_def);
690 if (! NILP (font_object) && font_has_char (f, font_object, c))
692 found_index++;
693 goto found;
697 /* Find a font-entity with the current spec and supporting C. */
698 font_entity = font_find_for_lface (f, face->lface,
699 FONT_DEF_SPEC (font_def), c);
700 if (! NILP (font_entity))
702 /* We found a font. Open it and insert a new element for
703 that font in VEC. */
704 Lisp_Object new_vec;
705 int j;
707 font_object = font_open_for_lface (f, font_entity, face->lface,
708 Qnil);
709 if (NILP (font_object))
710 continue;
711 RFONT_DEF_NEW (rfont_def, font_def);
712 RFONT_DEF_SET_OBJECT (rfont_def, font_object);
713 RFONT_DEF_SET_SCORE (rfont_def, RFONT_DEF_SCORE (rfont_def));
714 new_vec = Fmake_vector (make_number (ASIZE (vec) + 1), Qnil);
715 found_index++;
716 for (j = 0; j < found_index; j++)
717 ASET (new_vec, j, AREF (vec, j));
718 ASET (new_vec, j, rfont_def);
719 for (j++; j < ASIZE (new_vec); j++)
720 ASET (new_vec, j, AREF (vec, j - 1));
721 XSETCDR (font_group, new_vec);
722 vec = new_vec;
723 goto found;
725 if (i >= 0)
726 i = found_index;
729 /* Record that no font in this font group supports C. */
730 FONTSET_SET (fontset, make_number (c), make_number (0));
731 return Qnil;
733 found:
734 if (fallback && found_index > 0)
736 /* The order of fonts in the fallback font-group is not that
737 important, and it is better to move the found font to the
738 first of the group so that the next try will find it
739 quickly. */
740 for (i = found_index; i > 0; i--)
741 ASET (vec, i, AREF (vec, i - 1));
742 ASET (vec, 0, rfont_def);
744 return rfont_def;
748 /* Return RFONT-DEF (vector) corresponding to the font for character
749 C. The value is not a vector if no font is found for C. */
751 static Lisp_Object
752 fontset_font (Lisp_Object fontset, int c, struct face *face, int id)
754 Lisp_Object rfont_def;
755 Lisp_Object default_rfont_def UNINIT;
756 Lisp_Object base_fontset;
758 /* Try a font-group of FONTSET. */
759 FONT_DEFERRED_LOG ("current fontset: font for", make_number (c), Qnil);
760 rfont_def = fontset_find_font (fontset, c, face, id, 0);
761 if (VECTORP (rfont_def))
762 return rfont_def;
763 if (NILP (rfont_def))
764 FONTSET_SET (fontset, make_number (c), make_number (0));
766 /* Try a font-group of the default fontset. */
767 base_fontset = FONTSET_BASE (fontset);
768 if (! EQ (base_fontset, Vdefault_fontset))
770 if (NILP (FONTSET_DEFAULT (fontset)))
771 set_fontset_default
772 (fontset,
773 make_fontset (FONTSET_FRAME (fontset), Qnil, Vdefault_fontset));
774 FONT_DEFERRED_LOG ("default fontset: font for", make_number (c), Qnil);
775 default_rfont_def
776 = fontset_find_font (FONTSET_DEFAULT (fontset), c, face, id, 0);
777 if (VECTORP (default_rfont_def))
778 return default_rfont_def;
779 if (NILP (default_rfont_def))
780 FONTSET_SET (FONTSET_DEFAULT (fontset), make_number (c),
781 make_number (0));
784 /* Try a fallback font-group of FONTSET. */
785 if (! EQ (rfont_def, Qt))
787 FONT_DEFERRED_LOG ("current fallback: font for", make_number (c), Qnil);
788 rfont_def = fontset_find_font (fontset, c, face, id, 1);
789 if (VECTORP (rfont_def))
790 return rfont_def;
791 /* Remember that FONTSET has no font for C. */
792 FONTSET_SET (fontset, make_number (c), Qt);
795 /* Try a fallback font-group of the default fontset. */
796 if (! EQ (base_fontset, Vdefault_fontset)
797 && ! EQ (default_rfont_def, Qt))
799 FONT_DEFERRED_LOG ("default fallback: font for", make_number (c), Qnil);
800 rfont_def = fontset_find_font (FONTSET_DEFAULT (fontset), c, face, id, 1);
801 if (VECTORP (rfont_def))
802 return rfont_def;
803 /* Remember that the default fontset has no font for C. */
804 FONTSET_SET (FONTSET_DEFAULT (fontset), make_number (c), Qt);
807 return Qnil;
810 /* Return a newly created fontset with NAME. If BASE is nil, make a
811 base fontset. Otherwise make a realized fontset whose base is
812 BASE. */
814 static Lisp_Object
815 make_fontset (Lisp_Object frame, Lisp_Object name, Lisp_Object base)
817 Lisp_Object fontset;
818 int size = ASIZE (Vfontset_table);
819 int id = next_fontset_id;
821 /* Find a free slot in Vfontset_table. Usually, next_fontset_id is
822 the next available fontset ID. So it is expected that this loop
823 terminates quickly. In addition, as the last element of
824 Vfontset_table is always nil, we don't have to check the range of
825 id. */
826 while (!NILP (AREF (Vfontset_table, id))) id++;
828 if (id + 1 == size)
829 Vfontset_table = larger_vector (Vfontset_table, 1, -1);
831 fontset = Fmake_char_table (Qfontset, Qnil);
833 set_fontset_id (fontset, make_number (id));
834 if (NILP (base))
835 set_fontset_name (fontset, name);
836 else
838 set_fontset_name (fontset, Qnil);
839 set_fontset_frame (fontset, frame);
840 set_fontset_base (fontset, base);
843 ASET (Vfontset_table, id, fontset);
844 next_fontset_id = id + 1;
845 return fontset;
849 /********** INTERFACES TO xfaces.c, xfns.c, and dispextern.h **********/
851 /* Return the name of the fontset who has ID. */
853 Lisp_Object
854 fontset_name (int id)
856 Lisp_Object fontset;
858 fontset = FONTSET_FROM_ID (id);
859 return FONTSET_NAME (fontset);
863 /* Return the ASCII font name of the fontset who has ID. */
865 Lisp_Object
866 fontset_ascii (int id)
868 Lisp_Object fontset, elt;
870 fontset= FONTSET_FROM_ID (id);
871 elt = FONTSET_ASCII (fontset);
872 if (CONSP (elt))
873 elt = XCAR (elt);
874 return elt;
877 /* Free fontset of FACE defined on frame F. Called from
878 free_realized_face. */
880 void
881 free_face_fontset (struct frame *f, struct face *face)
883 Lisp_Object fontset;
885 fontset = FONTSET_FROM_ID (face->fontset);
886 if (NILP (fontset))
887 return;
888 eassert (! BASE_FONTSET_P (fontset));
889 eassert (f == XFRAME (FONTSET_FRAME (fontset)));
890 ASET (Vfontset_table, face->fontset, Qnil);
891 if (face->fontset < next_fontset_id)
892 next_fontset_id = face->fontset;
893 if (! NILP (FONTSET_DEFAULT (fontset)))
895 int id = XINT (FONTSET_ID (FONTSET_DEFAULT (fontset)));
897 fontset = AREF (Vfontset_table, id);
898 eassert (!NILP (fontset) && ! BASE_FONTSET_P (fontset));
899 eassert (f == XFRAME (FONTSET_FRAME (fontset)));
900 ASET (Vfontset_table, id, Qnil);
901 if (id < next_fontset_id)
902 next_fontset_id = face->fontset;
904 face->fontset = -1;
907 /* Return ID of face suitable for displaying character C at buffer position
908 POS on frame F. FACE must be realized for ASCII characters in advance.
909 Called from the macro FACE_FOR_CHAR. */
912 face_for_char (struct frame *f, struct face *face, int c,
913 ptrdiff_t pos, Lisp_Object object)
915 Lisp_Object fontset, rfont_def, charset;
916 int face_id;
917 int id;
919 eassert (fontset_id_valid_p (face->fontset));
921 if (ASCII_CHAR_P (c) || CHAR_BYTE8_P (c))
922 return face->ascii_face->id;
924 if (c > 0 && EQ (CHAR_TABLE_REF (Vchar_script_table, c), Qsymbol))
926 /* Fonts often have characters for punctuation and other
927 symbols, even if they don't match the 'symbol' script. So
928 check if the character is present in the current ASCII face
929 first, and if so, use the same font as used by that face.
930 This avoids unnecessarily switching to another font when the
931 frame's default font will do. We only do this for symbols so
932 that users could still setup fontsets to force Emacs to use
933 specific fonts for characters from other scripts, because
934 choice of fonts is frequently affected by cultural
935 preferences and font features, not by font coverage.
936 However, these considerations are unlikely to be relevant to
937 punctuation and other symbols, since the latter generally
938 aren't specific to any culture, and don't require
939 sophisticated OTF features. */
940 Lisp_Object font_object;
942 if (face->ascii_face->font)
944 XSETFONT (font_object, face->ascii_face->font);
945 if (font_has_char (f, font_object, c))
946 return face->ascii_face->id;
949 #if 0
950 /* Try the current face. Disabled because it can cause
951 counter-intuitive results, whereby the font used for some
952 character depends on the characters that precede it on
953 display. See the discussion of bug #15138. Note that the
954 original bug reported in #15138 was in a situation where face
955 == face->ascii_face, so the above code solves that situation
956 without risking the undesirable consequences. */
957 if (face->font)
959 XSETFONT (font_object, face->font);
960 if (font_has_char (f, font_object, c)) return face->id;
962 #endif
965 fontset = FONTSET_FROM_ID (face->fontset);
966 eassert (!BASE_FONTSET_P (fontset));
968 if (pos < 0)
970 id = -1;
971 charset = Qnil;
973 else
975 charset = Fget_char_property (make_number (pos), Qcharset, object);
976 if (CHARSETP (charset))
978 Lisp_Object val;
980 val = assq_no_quit (charset, Vfont_encoding_charset_alist);
981 if (CONSP (val) && CHARSETP (XCDR (val)))
982 charset = XCDR (val);
983 id = XINT (CHARSET_SYMBOL_ID (charset));
985 else
986 id = -1;
989 rfont_def = fontset_font (fontset, c, face, id);
990 if (VECTORP (rfont_def))
992 if (INTEGERP (RFONT_DEF_FACE (rfont_def)))
993 face_id = XINT (RFONT_DEF_FACE (rfont_def));
994 else
996 Lisp_Object font_object;
998 font_object = RFONT_DEF_OBJECT (rfont_def);
999 face_id = face_for_font (f, font_object, face);
1000 RFONT_DEF_SET_FACE (rfont_def, face_id);
1003 else
1005 if (INTEGERP (FONTSET_NOFONT_FACE (fontset)))
1006 face_id = XINT (FONTSET_NOFONT_FACE (fontset));
1007 else
1009 face_id = face_for_font (f, Qnil, face);
1010 set_fontset_nofont_face (fontset, make_number (face_id));
1013 eassert (face_id >= 0);
1014 return face_id;
1018 Lisp_Object
1019 font_for_char (struct face *face, int c, ptrdiff_t pos, Lisp_Object object)
1021 Lisp_Object fontset, rfont_def, charset;
1022 int id;
1024 if (ASCII_CHAR_P (c))
1026 Lisp_Object font_object;
1028 XSETFONT (font_object, face->ascii_face->font);
1029 return font_object;
1032 eassert (fontset_id_valid_p (face->fontset));
1033 fontset = FONTSET_FROM_ID (face->fontset);
1034 eassert (!BASE_FONTSET_P (fontset));
1035 if (pos < 0)
1037 id = -1;
1038 charset = Qnil;
1040 else
1042 charset = Fget_char_property (make_number (pos), Qcharset, object);
1043 if (CHARSETP (charset))
1045 Lisp_Object val;
1047 val = assq_no_quit (charset, Vfont_encoding_charset_alist);
1048 if (CONSP (val) && CHARSETP (XCDR (val)))
1049 charset = XCDR (val);
1050 id = XINT (CHARSET_SYMBOL_ID (charset));
1052 else
1053 id = -1;
1056 rfont_def = fontset_font (fontset, c, face, id);
1057 return (VECTORP (rfont_def)
1058 ? RFONT_DEF_OBJECT (rfont_def)
1059 : Qnil);
1063 /* Make a realized fontset for ASCII face FACE on frame F from the
1064 base fontset BASE_FONTSET_ID. If BASE_FONTSET_ID is -1, use the
1065 default fontset as the base. Value is the id of the new fontset.
1066 Called from realize_x_face. */
1069 make_fontset_for_ascii_face (struct frame *f, int base_fontset_id, struct face *face)
1071 Lisp_Object base_fontset, fontset, frame;
1073 XSETFRAME (frame, f);
1074 if (base_fontset_id >= 0)
1076 base_fontset = FONTSET_FROM_ID (base_fontset_id);
1077 if (!BASE_FONTSET_P (base_fontset))
1078 base_fontset = FONTSET_BASE (base_fontset);
1079 eassert (BASE_FONTSET_P (base_fontset));
1081 else
1082 base_fontset = Vdefault_fontset;
1084 fontset = make_fontset (frame, Qnil, base_fontset);
1085 return XINT (FONTSET_ID (fontset));
1090 /* Cache data used by fontset_pattern_regexp. The car part is a
1091 pattern string containing at least one wild card, the cdr part is
1092 the corresponding regular expression. */
1093 static Lisp_Object Vcached_fontset_data;
1095 #define CACHED_FONTSET_NAME SSDATA (XCAR (Vcached_fontset_data))
1096 #define CACHED_FONTSET_REGEX (XCDR (Vcached_fontset_data))
1098 /* If fontset name PATTERN contains any wild card, return regular
1099 expression corresponding to PATTERN. */
1101 static Lisp_Object
1102 fontset_pattern_regexp (Lisp_Object pattern)
1104 if (!strchr (SSDATA (pattern), '*')
1105 && !strchr (SSDATA (pattern), '?'))
1106 /* PATTERN does not contain any wild cards. */
1107 return Qnil;
1109 if (!CONSP (Vcached_fontset_data)
1110 || strcmp (SSDATA (pattern), CACHED_FONTSET_NAME))
1112 /* We must at first update the cached data. */
1113 unsigned char *regex, *p0, *p1;
1114 int ndashes = 0, nstars = 0, nescs = 0;
1116 for (p0 = SDATA (pattern); *p0; p0++)
1118 if (*p0 == '-')
1119 ndashes++;
1120 else if (*p0 == '*')
1121 nstars++;
1122 else if (*p0 == '['
1123 || *p0 == '.' || *p0 == '\\'
1124 || *p0 == '+' || *p0 == '^'
1125 || *p0 == '$')
1126 nescs++;
1129 /* If PATTERN is not full XLFD we convert "*" to ".*". Otherwise
1130 we convert "*" to "[^-]*" which is much faster in regular
1131 expression matching. */
1132 ptrdiff_t regexsize = (SBYTES (pattern)
1133 + (ndashes < 14 ? 2 : 5) * nstars
1134 + 2 * nescs + 3);
1135 USE_SAFE_ALLOCA;
1136 p1 = regex = SAFE_ALLOCA (regexsize);
1138 *p1++ = '^';
1139 for (p0 = SDATA (pattern); *p0; p0++)
1141 if (*p0 == '*')
1143 if (ndashes < 14)
1144 *p1++ = '.';
1145 else
1146 *p1++ = '[', *p1++ = '^', *p1++ = '-', *p1++ = ']';
1147 *p1++ = '*';
1149 else if (*p0 == '?')
1150 *p1++ = '.';
1151 else if (*p0 == '['
1152 || *p0 == '.' || *p0 == '\\'
1153 || *p0 == '+' || *p0 == '^'
1154 || *p0 == '$')
1155 *p1++ = '\\', *p1++ = *p0;
1156 else
1157 *p1++ = *p0;
1159 *p1++ = '$';
1160 *p1++ = 0;
1162 Vcached_fontset_data = Fcons (build_string (SSDATA (pattern)),
1163 build_string ((char *) regex));
1164 SAFE_FREE ();
1167 return CACHED_FONTSET_REGEX;
1170 /* Return ID of the base fontset named NAME. If there's no such
1171 fontset, return -1. NAME_PATTERN specifies how to treat NAME as this:
1172 0: pattern containing '*' and '?' as wildcards
1173 1: regular expression
1174 2: literal fontset name
1178 fs_query_fontset (Lisp_Object name, int name_pattern)
1180 Lisp_Object tem;
1181 int i;
1183 name = Fdowncase (name);
1184 if (name_pattern != 1)
1186 tem = Frassoc (name, Vfontset_alias_alist);
1187 if (NILP (tem))
1188 tem = Fassoc (name, Vfontset_alias_alist);
1189 if (CONSP (tem) && STRINGP (XCAR (tem)))
1190 name = XCAR (tem);
1191 else if (name_pattern == 0)
1193 tem = fontset_pattern_regexp (name);
1194 if (STRINGP (tem))
1196 name = tem;
1197 name_pattern = 1;
1202 for (i = 0; i < ASIZE (Vfontset_table); i++)
1204 Lisp_Object fontset, this_name;
1206 fontset = FONTSET_FROM_ID (i);
1207 if (NILP (fontset)
1208 || !BASE_FONTSET_P (fontset))
1209 continue;
1211 this_name = FONTSET_NAME (fontset);
1212 if (name_pattern == 1
1213 ? fast_string_match_ignore_case (name, this_name) >= 0
1214 : !xstrcasecmp (SSDATA (name), SSDATA (this_name)))
1215 return i;
1217 return -1;
1221 DEFUN ("query-fontset", Fquery_fontset, Squery_fontset, 1, 2, 0,
1222 doc: /* Return the name of a fontset that matches PATTERN.
1223 The value is nil if there is no matching fontset.
1224 PATTERN can contain `*' or `?' as a wildcard
1225 just as X font name matching algorithm allows.
1226 If REGEXPP is non-nil, PATTERN is a regular expression. */)
1227 (Lisp_Object pattern, Lisp_Object regexpp)
1229 Lisp_Object fontset;
1230 int id;
1232 check_window_system (NULL);
1234 CHECK_STRING (pattern);
1236 if (SCHARS (pattern) == 0)
1237 return Qnil;
1239 id = fs_query_fontset (pattern, !NILP (regexpp));
1240 if (id < 0)
1241 return Qnil;
1243 fontset = FONTSET_FROM_ID (id);
1244 return FONTSET_NAME (fontset);
1247 /* Return a list of base fontset names matching PATTERN on frame F. */
1249 Lisp_Object
1250 list_fontsets (struct frame *f, Lisp_Object pattern, int size)
1252 Lisp_Object frame, regexp, val;
1253 int id;
1255 XSETFRAME (frame, f);
1257 regexp = fontset_pattern_regexp (pattern);
1258 val = Qnil;
1260 for (id = 0; id < ASIZE (Vfontset_table); id++)
1262 Lisp_Object fontset, name;
1264 fontset = FONTSET_FROM_ID (id);
1265 if (NILP (fontset)
1266 || !BASE_FONTSET_P (fontset)
1267 || !EQ (frame, FONTSET_FRAME (fontset)))
1268 continue;
1269 name = FONTSET_NAME (fontset);
1271 if (STRINGP (regexp)
1272 ? (fast_string_match (regexp, name) < 0)
1273 : strcmp (SSDATA (pattern), SSDATA (name)))
1274 continue;
1276 val = Fcons (Fcopy_sequence (FONTSET_NAME (fontset)), val);
1279 return val;
1283 /* Free all realized fontsets whose base fontset is BASE. */
1285 static void
1286 free_realized_fontsets (Lisp_Object base)
1288 int id;
1290 #if 0
1291 /* For the moment, this doesn't work because free_realized_face
1292 doesn't remove FACE from a cache. Until we find a solution, we
1293 suppress this code, and simply use Fclear_face_cache even though
1294 that is not efficient. */
1295 block_input ();
1296 for (id = 0; id < ASIZE (Vfontset_table); id++)
1298 Lisp_Object this = AREF (Vfontset_table, id);
1300 if (EQ (FONTSET_BASE (this), base))
1302 Lisp_Object tail;
1304 for (tail = FONTSET_FACE_ALIST (this); CONSP (tail);
1305 tail = XCDR (tail))
1307 struct frame *f = XFRAME (FONTSET_FRAME (this));
1308 int face_id = XINT (XCDR (XCAR (tail)));
1309 struct face *face = FACE_FROM_ID_OR_NULL (f, face_id);
1311 /* Face THIS itself is also freed by the following call. */
1312 free_realized_face (f, face);
1316 unblock_input ();
1317 #else /* not 0 */
1318 /* But, we don't have to call Fclear_face_cache if no fontset has
1319 been realized from BASE. */
1320 for (id = 0; id < ASIZE (Vfontset_table); id++)
1322 Lisp_Object this = AREF (Vfontset_table, id);
1324 if (CHAR_TABLE_P (this) && EQ (FONTSET_BASE (this), base))
1326 Fclear_face_cache (Qt);
1327 break;
1330 #endif /* not 0 */
1334 /* Check validity of NAME as a fontset name and return the
1335 corresponding fontset. If not valid, signal an error.
1337 If NAME is t, return Vdefault_fontset. If NAME is nil, return the
1338 fontset of *FRAME.
1340 Set *FRAME to the actual frame. */
1342 static Lisp_Object
1343 check_fontset_name (Lisp_Object name, Lisp_Object *frame)
1345 int id;
1346 struct frame *f = decode_live_frame (*frame);
1348 XSETFRAME (*frame, f);
1350 if (EQ (name, Qt))
1351 return Vdefault_fontset;
1352 if (NILP (name))
1353 id = FRAME_FONTSET (f);
1354 else
1356 CHECK_STRING (name);
1357 /* First try NAME as literal. */
1358 id = fs_query_fontset (name, 2);
1359 if (id < 0)
1360 /* For backward compatibility, try again NAME as pattern. */
1361 id = fs_query_fontset (name, 0);
1362 if (id < 0)
1363 error ("Fontset `%s' does not exist", SDATA (name));
1365 return FONTSET_FROM_ID (id);
1368 static void
1369 accumulate_script_ranges (Lisp_Object arg, Lisp_Object range, Lisp_Object val)
1371 if (EQ (XCAR (arg), val))
1373 if (CONSP (range))
1374 XSETCDR (arg, Fcons (Fcons (XCAR (range), XCDR (range)), XCDR (arg)));
1375 else
1376 XSETCDR (arg, Fcons (Fcons (range, range), XCDR (arg)));
1381 /* Callback function for map_charset_chars in Fset_fontset_font.
1382 ARG is a vector [ FONTSET FONT_DEF ADD ASCII SCRIPT_RANGE_LIST ].
1384 In FONTSET, set FONT_DEF in a fashion specified by ADD for
1385 characters in RANGE and ranges in SCRIPT_RANGE_LIST before RANGE.
1386 The consumed ranges are popped up from SCRIPT_RANGE_LIST, and the
1387 new SCRIPT_RANGE_LIST is stored in ARG.
1389 If ASCII is nil, don't set FONT_DEF for ASCII characters. It is
1390 assured that SCRIPT_RANGE_LIST doesn't contain ASCII in that
1391 case. */
1393 static void
1394 set_fontset_font (Lisp_Object arg, Lisp_Object range)
1396 Lisp_Object fontset, font_def, add, ascii, script_range_list;
1397 int from = XINT (XCAR (range)), to = XINT (XCDR (range));
1399 fontset = AREF (arg, 0);
1400 font_def = AREF (arg, 1);
1401 add = AREF (arg, 2);
1402 ascii = AREF (arg, 3);
1403 script_range_list = AREF (arg, 4);
1405 if (NILP (ascii) && from < 0x80)
1407 if (to < 0x80)
1408 return;
1409 from = 0x80;
1410 range = Fcons (make_number (0x80), XCDR (range));
1413 #define SCRIPT_FROM XINT (XCAR (XCAR (script_range_list)))
1414 #define SCRIPT_TO XINT (XCDR (XCAR (script_range_list)))
1415 #define POP_SCRIPT_RANGE() script_range_list = XCDR (script_range_list)
1417 for (; CONSP (script_range_list) && SCRIPT_TO < from; POP_SCRIPT_RANGE ())
1418 FONTSET_ADD (fontset, XCAR (script_range_list), font_def, add);
1419 if (CONSP (script_range_list))
1421 if (SCRIPT_FROM < from)
1422 range = Fcons (make_number (SCRIPT_FROM), XCDR (range));
1423 while (CONSP (script_range_list) && SCRIPT_TO <= to)
1424 POP_SCRIPT_RANGE ();
1425 if (CONSP (script_range_list) && SCRIPT_FROM <= to)
1426 XSETCAR (XCAR (script_range_list), make_number (to + 1));
1429 FONTSET_ADD (fontset, range, font_def, add);
1430 ASET (arg, 4, script_range_list);
1433 static void update_auto_fontset_alist (Lisp_Object, Lisp_Object);
1436 DEFUN ("set-fontset-font", Fset_fontset_font, Sset_fontset_font, 3, 5, 0,
1437 doc: /*
1438 Modify fontset NAME to use FONT-SPEC for TARGET characters.
1440 NAME is a fontset name string, nil for the fontset of FRAME, or t for
1441 the default fontset.
1443 TARGET may be a single character to use FONT-SPEC for.
1445 Target may be a cons (FROM . TO), where FROM and TO are characters.
1446 In that case, use FONT-SPEC for all characters in the range FROM
1447 and TO (inclusive).
1449 TARGET may be a script name symbol. In that case, use FONT-SPEC for
1450 all characters that belong to the script.
1452 TARGET may be a charset. In that case, use FONT-SPEC for all
1453 characters in the charset.
1455 TARGET may be nil. In that case, use FONT-SPEC for any characters for
1456 that no FONT-SPEC is specified.
1458 FONT-SPEC may one of these:
1459 * A font-spec object made by the function `font-spec' (which see).
1460 * A cons (FAMILY . REGISTRY), where FAMILY is a font family name and
1461 REGISTRY is a font registry name. FAMILY may contain foundry
1462 name, and REGISTRY may contain encoding name.
1463 * A font name string.
1464 * nil, which explicitly specifies that there's no font for TARGET.
1466 Optional 4th argument FRAME is a frame or nil for the selected frame
1467 that is concerned in the case that NAME is nil.
1469 Optional 5th argument ADD, if non-nil, specifies how to add FONT-SPEC
1470 to the font specifications for TARGET previously set. If it is
1471 `prepend', FONT-SPEC is prepended. If it is `append', FONT-SPEC is
1472 appended. By default, FONT-SPEC overrides the previous settings. */)
1473 (Lisp_Object name, Lisp_Object target, Lisp_Object font_spec, Lisp_Object frame, Lisp_Object add)
1475 Lisp_Object fontset;
1476 Lisp_Object font_def, registry, family;
1477 Lisp_Object range_list;
1478 struct charset *charset = NULL;
1479 Lisp_Object fontname;
1480 bool ascii_changed = 0;
1482 fontset = check_fontset_name (name, &frame);
1484 fontname = Qnil;
1485 if (CONSP (font_spec))
1487 Lisp_Object spec = Ffont_spec (0, NULL);
1489 font_parse_family_registry (XCAR (font_spec), XCDR (font_spec), spec);
1490 font_spec = spec;
1491 fontname = Ffont_xlfd_name (font_spec, Qnil);
1493 else if (STRINGP (font_spec))
1495 fontname = font_spec;
1496 font_spec = CALLN (Ffont_spec, QCname, fontname);
1498 else if (FONT_SPEC_P (font_spec))
1499 fontname = Ffont_xlfd_name (font_spec, Qnil);
1500 else if (! NILP (font_spec))
1501 Fsignal (Qfont, list2 (build_string ("Invalid font-spec"), font_spec));
1503 if (! NILP (font_spec))
1505 Lisp_Object encoding, repertory;
1507 family = AREF (font_spec, FONT_FAMILY_INDEX);
1508 if (! NILP (family) )
1509 family = SYMBOL_NAME (family);
1510 registry = AREF (font_spec, FONT_REGISTRY_INDEX);
1511 if (! NILP (registry))
1512 registry = Fdowncase (SYMBOL_NAME (registry));
1513 AUTO_STRING (dash, "-");
1514 encoding = find_font_encoding (concat3 (family, dash, registry));
1515 if (NILP (encoding))
1516 encoding = Qascii;
1518 if (SYMBOLP (encoding))
1520 CHECK_CHARSET (encoding);
1521 encoding = repertory = CHARSET_SYMBOL_ID (encoding);
1523 else
1525 repertory = XCDR (encoding);
1526 encoding = XCAR (encoding);
1527 CHECK_CHARSET (encoding);
1528 encoding = CHARSET_SYMBOL_ID (encoding);
1529 if (! NILP (repertory) && SYMBOLP (repertory))
1531 CHECK_CHARSET (repertory);
1532 repertory = CHARSET_SYMBOL_ID (repertory);
1535 FONT_DEF_NEW (font_def, font_spec, encoding, repertory);
1537 else
1538 font_def = Qnil;
1540 if (CHARACTERP (target))
1542 if (XFASTINT (target) < 0x80)
1543 error ("Can't set a font for partial ASCII range");
1544 range_list = list1 (Fcons (target, target));
1546 else if (CONSP (target))
1548 Lisp_Object from, to;
1550 from = Fcar (target);
1551 to = Fcdr (target);
1552 CHECK_CHARACTER (from);
1553 CHECK_CHARACTER (to);
1554 if (XFASTINT (from) < 0x80)
1556 if (XFASTINT (from) != 0 || XFASTINT (to) < 0x7F)
1557 error ("Can't set a font for partial ASCII range");
1558 ascii_changed = 1;
1560 range_list = list1 (target);
1562 else if (SYMBOLP (target) && !NILP (target))
1564 Lisp_Object script_list;
1565 Lisp_Object val;
1567 range_list = Qnil;
1568 script_list = XCHAR_TABLE (Vchar_script_table)->extras[0];
1569 if (! NILP (Fmemq (target, script_list)))
1571 if (EQ (target, Qlatin))
1572 ascii_changed = 1;
1573 val = list1 (target);
1574 map_char_table (accumulate_script_ranges, Qnil, Vchar_script_table,
1575 val);
1576 range_list = Fnreverse (XCDR (val));
1578 if (CHARSETP (target))
1580 CHECK_CHARSET_GET_CHARSET (target, charset);
1581 if (charset->ascii_compatible_p)
1582 ascii_changed = 1;
1584 else if (NILP (range_list))
1585 error ("Invalid script or charset name: %s",
1586 SDATA (SYMBOL_NAME (target)));
1588 else if (NILP (target))
1589 range_list = list1 (Qnil);
1590 else
1591 error ("Invalid target for setting a font");
1593 if (ascii_changed)
1595 Lisp_Object val;
1597 if (NILP (font_spec))
1598 error ("Can't set ASCII font to nil");
1599 val = CHAR_TABLE_REF (fontset, 0);
1600 if (! NILP (val) && EQ (add, Qappend))
1601 /* We are going to change just an additional font for ASCII. */
1602 ascii_changed = 0;
1605 if (charset)
1607 Lisp_Object arg;
1609 arg = make_uninit_vector (5);
1610 ASET (arg, 0, fontset);
1611 ASET (arg, 1, font_def);
1612 ASET (arg, 2, add);
1613 ASET (arg, 3, ascii_changed ? Qt : Qnil);
1614 ASET (arg, 4, range_list);
1616 map_charset_chars (set_fontset_font, Qnil, arg, charset,
1617 CHARSET_MIN_CODE (charset),
1618 CHARSET_MAX_CODE (charset));
1619 range_list = AREF (arg, 4);
1621 for (; CONSP (range_list); range_list = XCDR (range_list))
1622 FONTSET_ADD (fontset, XCAR (range_list), font_def, add);
1624 if (ascii_changed)
1626 Lisp_Object tail, fr;
1627 int fontset_id = XINT (FONTSET_ID (fontset));
1629 set_fontset_ascii (fontset, fontname);
1630 name = FONTSET_NAME (fontset);
1631 FOR_EACH_FRAME (tail, fr)
1633 struct frame *f = XFRAME (fr);
1634 Lisp_Object font_object;
1635 struct face *face;
1637 if (FRAME_INITIAL_P (f) || FRAME_TERMCAP_P (f))
1638 continue;
1639 if (fontset_id != FRAME_FONTSET (f))
1640 continue;
1641 face = FACE_FROM_ID_OR_NULL (f, DEFAULT_FACE_ID);
1642 if (face)
1643 font_object = font_load_for_lface (f, face->lface, font_spec);
1644 else
1645 font_object = font_open_by_spec (f, font_spec);
1646 if (! NILP (font_object))
1648 update_auto_fontset_alist (font_object, fontset);
1649 AUTO_FRAME_ARG (arg, Qfont, Fcons (name, font_object));
1650 Fmodify_frame_parameters (fr, arg);
1655 /* Free all realized fontsets whose base is FONTSET. This way, the
1656 specified character(s) are surely redisplayed by a correct
1657 font. */
1658 free_realized_fontsets (fontset);
1660 return Qnil;
1664 DEFUN ("new-fontset", Fnew_fontset, Snew_fontset, 2, 2, 0,
1665 doc: /* Create a new fontset NAME from font information in FONTLIST.
1667 FONTLIST is an alist of scripts vs the corresponding font specification list.
1668 Each element of FONTLIST has the form (SCRIPT FONT-SPEC ...), where a
1669 character of SCRIPT is displayed by a font that matches one of
1670 FONT-SPEC.
1672 SCRIPT is a symbol that appears in the first extra slot of the
1673 char-table `char-script-table'.
1675 FONT-SPEC is a vector, a cons, or a string. See the documentation of
1676 `set-fontset-font' for the meaning. */)
1677 (Lisp_Object name, Lisp_Object fontlist)
1679 Lisp_Object fontset;
1680 int id;
1682 CHECK_STRING (name);
1683 CHECK_LIST (fontlist);
1685 name = Fdowncase (name);
1686 id = fs_query_fontset (name, 0);
1687 if (id < 0)
1689 Lisp_Object font_spec = Ffont_spec (0, NULL);
1690 Lisp_Object short_name;
1691 char xlfd[256];
1692 int len;
1694 if (font_parse_xlfd (SSDATA (name), SBYTES (name), font_spec) < 0)
1695 error ("Fontset name must be in XLFD format");
1696 short_name = AREF (font_spec, FONT_REGISTRY_INDEX);
1697 if (strncmp (SSDATA (SYMBOL_NAME (short_name)), "fontset-", 8)
1698 || SBYTES (SYMBOL_NAME (short_name)) < 9)
1699 error ("Registry field of fontset name must be \"fontset-*\"");
1700 Vfontset_alias_alist = Fcons (Fcons (name, SYMBOL_NAME (short_name)),
1701 Vfontset_alias_alist);
1702 ASET (font_spec, FONT_REGISTRY_INDEX, Qiso8859_1);
1703 fontset = make_fontset (Qnil, name, Qnil);
1704 len = font_unparse_xlfd (font_spec, 0, xlfd, 256);
1705 if (len < 0)
1706 error ("Invalid fontset name (perhaps too long): %s", SDATA (name));
1707 set_fontset_ascii (fontset, make_unibyte_string (xlfd, len));
1709 else
1711 fontset = FONTSET_FROM_ID (id);
1712 free_realized_fontsets (fontset);
1713 Fset_char_table_range (fontset, Qt, Qnil);
1716 for (; CONSP (fontlist); fontlist = XCDR (fontlist))
1718 Lisp_Object elt, script;
1720 elt = XCAR (fontlist);
1721 script = Fcar (elt);
1722 elt = Fcdr (elt);
1723 if (CONSP (elt) && (NILP (XCDR (elt)) || CONSP (XCDR (elt))))
1724 for (; CONSP (elt); elt = XCDR (elt))
1725 Fset_fontset_font (name, script, XCAR (elt), Qnil, Qappend);
1726 else
1727 Fset_fontset_font (name, script, elt, Qnil, Qappend);
1729 return name;
1733 /* Alist of automatically created fontsets. Each element is a cons
1734 (FONT-SPEC . FONTSET-ID). */
1735 static Lisp_Object auto_fontset_alist;
1737 /* Number of automatically created fontsets. */
1738 static ptrdiff_t num_auto_fontsets;
1740 /* Return a fontset synthesized from FONT-OBJECT. This is called from
1741 x_new_font when FONT-OBJECT is used for the default ASCII font of a
1742 frame, and the returned fontset is used for the default fontset of
1743 that frame. The fontset specifies a font of the same registry as
1744 FONT-OBJECT for all characters in the repertory of the registry
1745 (see Vfont_encoding_alist). If the repertory is not known, the
1746 fontset specifies the font for all Latin characters assuming that a
1747 user intends to use FONT-OBJECT for Latin characters. */
1750 fontset_from_font (Lisp_Object font_object)
1752 Lisp_Object font_name = font_get_name (font_object);
1753 Lisp_Object font_spec = copy_font_spec (font_object);
1754 Lisp_Object registry = AREF (font_spec, FONT_REGISTRY_INDEX);
1755 Lisp_Object fontset_spec, alias, name, fontset;
1756 Lisp_Object val;
1758 val = assoc_no_quit (font_spec, auto_fontset_alist);
1759 if (CONSP (val))
1760 return XINT (FONTSET_ID (XCDR (val)));
1761 if (num_auto_fontsets++ == 0)
1762 alias = intern ("fontset-startup");
1763 else
1765 char temp[sizeof "fontset-auto" + INT_STRLEN_BOUND (ptrdiff_t)];
1767 sprintf (temp, "fontset-auto%"pD"d", num_auto_fontsets - 1);
1768 alias = intern (temp);
1770 fontset_spec = copy_font_spec (font_spec);
1771 ASET (fontset_spec, FONT_REGISTRY_INDEX, alias);
1772 name = Ffont_xlfd_name (fontset_spec, Qnil);
1773 eassert (!NILP (name));
1774 fontset = make_fontset (Qnil, name, Qnil);
1775 Vfontset_alias_alist = Fcons (Fcons (name, SYMBOL_NAME (alias)),
1776 Vfontset_alias_alist);
1777 alias = Fdowncase (AREF (font_object, FONT_NAME_INDEX));
1778 Vfontset_alias_alist = Fcons (Fcons (name, alias), Vfontset_alias_alist);
1779 auto_fontset_alist = Fcons (Fcons (font_spec, fontset), auto_fontset_alist);
1780 font_spec = Ffont_spec (0, NULL);
1781 ASET (font_spec, FONT_REGISTRY_INDEX, registry);
1783 Lisp_Object target = find_font_encoding (SYMBOL_NAME (registry));
1785 if (CONSP (target))
1786 target = XCDR (target);
1787 if (! CHARSETP (target))
1788 target = Qlatin;
1789 Fset_fontset_font (name, target, font_spec, Qnil, Qnil);
1790 Fset_fontset_font (name, Qnil, font_spec, Qnil, Qnil);
1793 set_fontset_ascii (fontset, font_name);
1795 return XINT (FONTSET_ID (fontset));
1799 /* Update auto_fontset_alist for FONTSET. When an ASCII font of
1800 FONTSET is changed, we delete an entry of FONTSET if any from
1801 auto_fontset_alist so that FONTSET is not re-used by
1802 fontset_from_font. */
1804 static void
1805 update_auto_fontset_alist (Lisp_Object font_object, Lisp_Object fontset)
1807 Lisp_Object prev, tail;
1809 for (prev = Qnil, tail = auto_fontset_alist; CONSP (tail);
1810 prev = tail, tail = XCDR (tail))
1811 if (EQ (fontset, XCDR (XCAR (tail))))
1813 if (NILP (prev))
1814 auto_fontset_alist = XCDR (tail);
1815 else
1816 XSETCDR (prev, XCDR (tail));
1817 break;
1822 DEFUN ("fontset-info", Ffontset_info, Sfontset_info, 1, 2, 0,
1823 doc: /* Return information about a fontset FONTSET on frame FRAME.
1825 FONTSET is a fontset name string, nil for the fontset of FRAME, or t
1826 for the default fontset. FRAME nil means the selected frame.
1828 The value is a char-table whose elements have this form:
1830 ((FONT OPENED-FONT ...) ...)
1832 FONT is a name of font specified for a range of characters.
1834 OPENED-FONT is a name of a font actually opened.
1836 The char-table has one extra slot. If FONTSET is not the default
1837 fontset, the value the extra slot is a char-table containing the
1838 information about the derived fonts from the default fontset. The
1839 format is the same as above. */)
1840 (Lisp_Object fontset, Lisp_Object frame)
1842 Lisp_Object *realized[2], fontsets[2], tables[2];
1843 Lisp_Object val, elt;
1844 int c, i, j, k;
1846 check_window_system (NULL);
1847 fontset = check_fontset_name (fontset, &frame);
1849 /* Recode fontsets realized on FRAME from the base fontset FONTSET
1850 in the table `realized'. */
1851 USE_SAFE_ALLOCA;
1852 SAFE_ALLOCA_LISP (realized[0], 2 * ASIZE (Vfontset_table));
1853 realized[1] = realized[0] + ASIZE (Vfontset_table);
1854 for (i = j = 0; i < ASIZE (Vfontset_table); i++)
1856 elt = FONTSET_FROM_ID (i);
1857 if (!NILP (elt)
1858 && EQ (FONTSET_BASE (elt), fontset)
1859 && EQ (FONTSET_FRAME (elt), frame))
1860 realized[0][j++] = elt;
1862 realized[0][j] = Qnil;
1864 for (i = j = 0; ! NILP (realized[0][i]); i++)
1866 elt = FONTSET_DEFAULT (realized[0][i]);
1867 if (! NILP (elt))
1868 realized[1][j++] = elt;
1870 realized[1][j] = Qnil;
1872 tables[0] = Fmake_char_table (Qfontset_info, Qnil);
1873 fontsets[0] = fontset;
1874 if (!EQ (fontset, Vdefault_fontset))
1876 tables[1] = Fmake_char_table (Qnil, Qnil);
1877 set_char_table_extras (tables[0], 0, tables[1]);
1878 fontsets[1] = Vdefault_fontset;
1881 /* Accumulate information of the fontset in TABLE. The format of
1882 each element is ((FONT-SPEC OPENED-FONT ...) ...). */
1883 for (k = 0; k <= 1; k++)
1885 for (c = 0; c <= MAX_CHAR; )
1887 int from = c, to = MAX_5_BYTE_CHAR;
1889 if (c <= MAX_5_BYTE_CHAR)
1891 val = char_table_ref_and_range (fontsets[k], c, &from, &to);
1893 else
1895 val = FONTSET_FALLBACK (fontsets[k]);
1896 to = MAX_CHAR;
1898 if (VECTORP (val))
1900 Lisp_Object alist;
1902 /* At first, set ALIST to ((FONT-SPEC) ...). */
1903 for (alist = Qnil, i = 0; i < ASIZE (val); i++)
1904 if (! NILP (AREF (val, i)))
1905 alist = Fcons (Fcons (FONT_DEF_SPEC (AREF (val, i)), Qnil),
1906 alist);
1907 alist = Fnreverse (alist);
1909 /* Then store opened font names to cdr of each elements. */
1910 for (i = 0; ! NILP (realized[k][i]); i++)
1912 if (c <= MAX_5_BYTE_CHAR)
1913 val = FONTSET_REF (realized[k][i], c);
1914 else
1915 val = FONTSET_FALLBACK (realized[k][i]);
1916 if (! CONSP (val) || ! VECTORP (XCDR (val)))
1917 continue;
1918 /* VAL: (int . [[FACE-ID FONT-DEF FONT-OBJECT int] ... ]) */
1919 val = XCDR (val);
1920 for (j = 0; j < ASIZE (val); j++)
1922 elt = AREF (val, j);
1923 if (!NILP (elt) && FONT_OBJECT_P (RFONT_DEF_OBJECT (elt)))
1925 Lisp_Object font_object = RFONT_DEF_OBJECT (elt);
1926 Lisp_Object slot, name;
1928 slot = Fassq (RFONT_DEF_SPEC (elt), alist);
1929 name = AREF (font_object, FONT_NAME_INDEX);
1930 if (NILP (Fmember (name, XCDR (slot))))
1931 nconc2 (slot, list1 (name));
1936 /* Store ALIST in TBL for characters C..TO. */
1937 if (c <= MAX_5_BYTE_CHAR)
1938 char_table_set_range (tables[k], c, to, alist);
1939 else
1940 set_char_table_defalt (tables[k], alist);
1942 /* At last, change each elements to font names. */
1943 for (; CONSP (alist); alist = XCDR (alist))
1945 elt = XCAR (alist);
1946 XSETCAR (elt, Ffont_xlfd_name (XCAR (elt), Qnil));
1949 c = to + 1;
1951 if (EQ (fontset, Vdefault_fontset))
1952 break;
1955 SAFE_FREE ();
1956 return tables[0];
1960 DEFUN ("fontset-font", Ffontset_font, Sfontset_font, 2, 3, 0,
1961 doc: /* Return a font name pattern for character CH in fontset NAME.
1962 If NAME is t, find a pattern in the default fontset.
1963 If NAME is nil, find a pattern in the fontset of the selected frame.
1965 The value has the form (FAMILY . REGISTRY), where FAMILY is a font
1966 family name and REGISTRY is a font registry name. This is actually
1967 the first font name pattern for CH in the fontset or in the default
1968 fontset.
1970 If the 2nd optional arg ALL is non-nil, return a list of all font name
1971 patterns. */)
1972 (Lisp_Object name, Lisp_Object ch, Lisp_Object all)
1974 int c;
1975 Lisp_Object fontset, elt, list, repertory, val;
1976 int i, j;
1977 Lisp_Object frame;
1979 frame = Qnil;
1980 fontset = check_fontset_name (name, &frame);
1982 CHECK_CHARACTER (ch);
1983 c = XINT (ch);
1984 list = Qnil;
1985 while (1)
1987 for (i = 0, elt = FONTSET_REF (fontset, c); i < 2;
1988 i++, elt = FONTSET_FALLBACK (fontset))
1989 if (VECTORP (elt))
1990 for (j = 0; j < ASIZE (elt); j++)
1992 Lisp_Object family, registry;
1994 val = AREF (elt, j);
1995 if (NILP (val))
1996 return Qnil;
1997 repertory = AREF (val, 1);
1998 if (INTEGERP (repertory))
2000 struct charset *charset = CHARSET_FROM_ID (XINT (repertory));
2002 if (! CHAR_CHARSET_P (c, charset))
2003 continue;
2005 else if (CHAR_TABLE_P (repertory))
2007 if (NILP (CHAR_TABLE_REF (repertory, c)))
2008 continue;
2010 val = AREF (val, 0);
2011 /* VAL is a FONT-SPEC */
2012 family = AREF (val, FONT_FAMILY_INDEX);
2013 if (! NILP (family))
2014 family = SYMBOL_NAME (family);
2015 registry = AREF (val, FONT_REGISTRY_INDEX);
2016 if (! NILP (registry))
2017 registry = SYMBOL_NAME (registry);
2018 val = Fcons (family, registry);
2019 if (NILP (all))
2020 return val;
2021 list = Fcons (val, list);
2023 if (EQ (fontset, Vdefault_fontset))
2024 break;
2025 fontset = Vdefault_fontset;
2027 return (Fnreverse (list));
2030 DEFUN ("fontset-list", Ffontset_list, Sfontset_list, 0, 0, 0,
2031 doc: /* Return a list of all defined fontset names. */)
2032 (void)
2034 Lisp_Object fontset, list;
2035 int i;
2037 list = Qnil;
2038 for (i = 0; i < ASIZE (Vfontset_table); i++)
2040 fontset = FONTSET_FROM_ID (i);
2041 if (!NILP (fontset)
2042 && BASE_FONTSET_P (fontset))
2043 list = Fcons (FONTSET_NAME (fontset), list);
2046 return list;
2050 #ifdef ENABLE_CHECKING
2052 Lisp_Object dump_fontset (Lisp_Object) EXTERNALLY_VISIBLE;
2054 Lisp_Object
2055 dump_fontset (Lisp_Object fontset)
2057 Lisp_Object vec;
2059 vec = Fmake_vector (make_number (3), Qnil);
2060 ASET (vec, 0, FONTSET_ID (fontset));
2062 if (BASE_FONTSET_P (fontset))
2064 ASET (vec, 1, FONTSET_NAME (fontset));
2066 else
2068 Lisp_Object frame;
2070 frame = FONTSET_FRAME (fontset);
2071 if (FRAMEP (frame))
2073 struct frame *f = XFRAME (frame);
2075 if (FRAME_LIVE_P (f))
2076 ASET (vec, 1,
2077 Fcons (FONTSET_NAME (FONTSET_BASE (fontset)),
2078 f->name));
2079 else
2080 ASET (vec, 1,
2081 Fcons (FONTSET_NAME (FONTSET_BASE (fontset)), Qnil));
2083 if (!NILP (FONTSET_DEFAULT (fontset)))
2084 ASET (vec, 2, FONTSET_ID (FONTSET_DEFAULT (fontset)));
2086 return vec;
2089 DEFUN ("fontset-list-all", Ffontset_list_all, Sfontset_list_all, 0, 0, 0,
2090 doc: /* Return a brief summary of all fontsets for debug use. */)
2091 (void)
2093 Lisp_Object val;
2094 int i;
2096 for (i = 0, val = Qnil; i < ASIZE (Vfontset_table); i++)
2097 if (! NILP (AREF (Vfontset_table, i)))
2098 val = Fcons (dump_fontset (AREF (Vfontset_table, i)), val);
2099 return (Fnreverse (val));
2101 #endif /* ENABLE_CHECKING */
2103 void
2104 syms_of_fontset (void)
2106 DEFSYM (Qfontset, "fontset");
2107 Fput (Qfontset, Qchar_table_extra_slots, make_number (8));
2108 DEFSYM (Qfontset_info, "fontset-info");
2109 Fput (Qfontset_info, Qchar_table_extra_slots, make_number (1));
2111 DEFSYM (Qappend, "append");
2112 DEFSYM (Qlatin, "latin");
2114 Vcached_fontset_data = Qnil;
2115 staticpro (&Vcached_fontset_data);
2117 Vfontset_table = Fmake_vector (make_number (32), Qnil);
2118 staticpro (&Vfontset_table);
2120 Vdefault_fontset = Fmake_char_table (Qfontset, Qnil);
2121 staticpro (&Vdefault_fontset);
2122 set_fontset_id (Vdefault_fontset, make_number (0));
2123 set_fontset_name
2124 (Vdefault_fontset,
2125 build_pure_c_string ("-*-*-*-*-*-*-*-*-*-*-*-*-fontset-default"));
2126 ASET (Vfontset_table, 0, Vdefault_fontset);
2127 next_fontset_id = 1;
2129 auto_fontset_alist = Qnil;
2130 staticpro (&auto_fontset_alist);
2132 DEFVAR_LISP ("font-encoding-charset-alist", Vfont_encoding_charset_alist,
2133 doc: /*
2134 Alist of charsets vs the charsets to determine the preferred font encoding.
2135 Each element looks like (CHARSET . ENCODING-CHARSET),
2136 where ENCODING-CHARSET is a charset registered in the variable
2137 `font-encoding-alist' as ENCODING.
2139 When a text has a property `charset' and the value is CHARSET, a font
2140 whose encoding corresponds to ENCODING-CHARSET is preferred. */);
2141 Vfont_encoding_charset_alist = Qnil;
2143 DEFVAR_LISP ("use-default-ascent", Vuse_default_ascent,
2144 doc: /*
2145 Char table of characters whose ascent values should be ignored.
2146 If an entry for a character is non-nil, the ascent value of the glyph
2147 is assumed to be specified by _MULE_DEFAULT_ASCENT property of a font.
2149 This affects how a composite character which contains
2150 such a character is displayed on screen. */);
2151 Vuse_default_ascent = Qnil;
2153 DEFVAR_LISP ("ignore-relative-composition", Vignore_relative_composition,
2154 doc: /*
2155 Char table of characters which are not composed relatively.
2156 If an entry for a character is non-nil, a composition sequence
2157 which contains that character is displayed so that
2158 the glyph of that character is put without considering
2159 an ascent and descent value of a previous character. */);
2160 Vignore_relative_composition = Qnil;
2162 DEFVAR_LISP ("alternate-fontname-alist", Valternate_fontname_alist,
2163 doc: /* Alist of fontname vs list of the alternate fontnames.
2164 When a specified font name is not found, the corresponding
2165 alternate fontnames (if any) are tried instead. */);
2166 Valternate_fontname_alist = Qnil;
2168 DEFVAR_LISP ("fontset-alias-alist", Vfontset_alias_alist,
2169 doc: /* Alist of fontset names vs the aliases. */);
2170 Vfontset_alias_alist
2171 = list1 (Fcons (FONTSET_NAME (Vdefault_fontset),
2172 build_pure_c_string ("fontset-default")));
2174 DEFVAR_LISP ("vertical-centering-font-regexp",
2175 Vvertical_centering_font_regexp,
2176 doc: /* Regexp matching font names that require vertical centering on display.
2177 When a character is displayed with such fonts, the character is displayed
2178 at the vertical center of lines. */);
2179 Vvertical_centering_font_regexp = Qnil;
2181 DEFVAR_LISP ("otf-script-alist", Votf_script_alist,
2182 doc: /* Alist of OpenType script tags vs the corresponding script names. */);
2183 Votf_script_alist = Qnil;
2185 defsubr (&Squery_fontset);
2186 defsubr (&Snew_fontset);
2187 defsubr (&Sset_fontset_font);
2188 defsubr (&Sfontset_info);
2189 defsubr (&Sfontset_font);
2190 defsubr (&Sfontset_list);
2191 #ifdef ENABLE_CHECKING
2192 defsubr (&Sfontset_list_all);
2193 #endif