Improve doc string of 'completion-at-point-functions'
[emacs.git] / src / fontset.c
blob74e7df5ae0968f19dd7523d530153a9d9abb31f1
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>
30 #include "lisp.h"
31 #include "blockinput.h"
32 #include "character.h"
33 #include "charset.h"
34 #include "frame.h"
35 #include "dispextern.h"
36 #include "fontset.h"
37 #ifdef HAVE_WINDOW_SYSTEM
38 #include TERM_HEADER
39 #endif /* HAVE_WINDOW_SYSTEM */
40 #include "font.h"
42 /* FONTSET
44 A fontset is a collection of font related information to give
45 similar appearance (style, etc) of characters. A fontset has two
46 roles. One is to use for the frame parameter `font' as if it is an
47 ASCII font. In that case, Emacs uses the font specified for
48 `ascii' script for the frame's default font.
50 Another role, the more important one, is to provide information
51 about which font to use for each non-ASCII character.
53 There are two kinds of fontsets; base and realized. A base fontset
54 is created by `new-fontset' from Emacs Lisp explicitly. A realized
55 fontset is created implicitly when a face is realized for ASCII
56 characters. A face is also realized for non-ASCII characters based
57 on an ASCII face. All of non-ASCII faces based on the same ASCII
58 face share the same realized fontset.
60 A fontset object is implemented by a char-table whose default value
61 and parent are always nil.
63 An element of a base fontset is a vector of FONT-DEFs which themselves
64 are vectors of the form [ FONT-SPEC ENCODING REPERTORY ].
66 An element of a realized fontset is nil, t, 0, or a vector of this
67 form:
69 [ PREFERRED-RFONT-DEF RFONT-DEF0 RFONT-DEF1 ... ]
71 Each RFONT-DEFn (i.e. Realized FONT-DEF) has this form:
73 [ FACE-ID FONT-DEF FONT-OBJECT SORTING-SCORE ]
75 RFONT-DEFn are automatically reordered by the current charset
76 priority list.
78 The value nil means that we have not yet generated the above vector
79 from the base of the fontset.
81 The value t means that no font is available for the corresponding
82 range of characters.
84 The value 0 means that no font is available for the corresponding
85 range of characters in this fontset, but may be available in the
86 default fontset.
88 A fontset has 8 extra slots.
90 The 1st slot:
91 base: the ID number of the fontset
92 realized: Likewise
94 The 2nd slot:
95 base: the name of the fontset
96 realized: nil
98 The 3rd slot:
99 base: the font name for ASCII characters
100 realized: nil
102 The 4th slot:
103 base: nil
104 realized: the base fontset
106 The 5th slot:
107 base: nil
108 realized: the frame that the fontset belongs to
110 The 6th slot:
111 base: nil
112 realized: the ID number of a face to use for characters that
113 has no font in a realized fontset.
115 The 7th slot:
116 base: nil
117 realized: If the base is not the default fontset, a fontset
118 realized from the default fontset, else nil.
120 The 8th slot:
121 base: Same as element value (but for fallback fonts).
122 realized: Likewise.
124 All fontsets are recorded in the vector Vfontset_table.
127 DEFAULT FONTSET
129 There's a special base fontset named `default fontset' which
130 defines the default font specifications. When a base fontset
131 doesn't specify a font for a specific character, the corresponding
132 value in the default fontset is used.
134 The parent of a realized fontset created for such a face that has
135 no fontset is the default fontset.
138 These structures are hidden from the other codes than this file.
139 The other codes handle fontsets only by their ID numbers. They
140 usually use the variable name `fontset' for IDs. But, in this
141 file, we always use variable name `id' for IDs, and name `fontset'
142 for an actual fontset object, i.e., char-table.
146 /********** VARIABLES and FUNCTION PROTOTYPES **********/
148 /* Vector containing all fontsets. */
149 static Lisp_Object Vfontset_table;
151 /* Next possibly free fontset ID. Usually this keeps the minimum
152 fontset ID not yet used. */
153 static int next_fontset_id;
155 /* The default fontset. This gives default FAMILY and REGISTRY of
156 font for each character. */
157 static Lisp_Object Vdefault_fontset;
159 /* Prototype declarations for static functions. */
160 static Lisp_Object make_fontset (Lisp_Object, Lisp_Object, Lisp_Object);
162 /* Return true if ID is a valid fontset id.
163 Optimized away if ENABLE_CHECKING is not defined. */
165 static bool
166 fontset_id_valid_p (int id)
168 return (id >= 0 && id < ASIZE (Vfontset_table) - 1);
173 /********** MACROS AND FUNCTIONS TO HANDLE FONTSET **********/
175 /* Return the fontset with ID. No check of ID's validness. */
176 #define FONTSET_FROM_ID(id) AREF (Vfontset_table, id)
178 /* Access special values of FONTSET. */
180 #define FONTSET_ID(fontset) XCHAR_TABLE (fontset)->extras[0]
181 static void
182 set_fontset_id (Lisp_Object fontset, Lisp_Object id)
184 set_char_table_extras (fontset, 0, id);
187 /* Access special values of (base) FONTSET. */
189 #define FONTSET_NAME(fontset) XCHAR_TABLE (fontset)->extras[1]
190 static void
191 set_fontset_name (Lisp_Object fontset, Lisp_Object name)
193 set_char_table_extras (fontset, 1, name);
196 #define FONTSET_ASCII(fontset) XCHAR_TABLE (fontset)->extras[2]
197 static void
198 set_fontset_ascii (Lisp_Object fontset, Lisp_Object ascii)
200 set_char_table_extras (fontset, 2, ascii);
203 /* Access special values of (realized) FONTSET. */
205 #define FONTSET_BASE(fontset) XCHAR_TABLE (fontset)->extras[3]
206 static void
207 set_fontset_base (Lisp_Object fontset, Lisp_Object base)
209 set_char_table_extras (fontset, 3, base);
212 #define FONTSET_FRAME(fontset) XCHAR_TABLE (fontset)->extras[4]
213 static void
214 set_fontset_frame (Lisp_Object fontset, Lisp_Object frame)
216 set_char_table_extras (fontset, 4, frame);
219 #define FONTSET_NOFONT_FACE(fontset) XCHAR_TABLE (fontset)->extras[5]
220 static void
221 set_fontset_nofont_face (Lisp_Object fontset, Lisp_Object face)
223 set_char_table_extras (fontset, 5, face);
226 #define FONTSET_DEFAULT(fontset) XCHAR_TABLE (fontset)->extras[6]
227 static void
228 set_fontset_default (Lisp_Object fontset, Lisp_Object def)
230 set_char_table_extras (fontset, 6, def);
233 /* For both base and realized fontset. */
235 #define FONTSET_FALLBACK(fontset) XCHAR_TABLE (fontset)->extras[7]
236 static void
237 set_fontset_fallback (Lisp_Object fontset, Lisp_Object fallback)
239 set_char_table_extras (fontset, 7, fallback);
242 #define BASE_FONTSET_P(fontset) (NILP (FONTSET_BASE (fontset)))
244 /* Macros for FONT-DEF and RFONT-DEF of fontset. */
245 #define FONT_DEF_NEW(font_def, font_spec, encoding, repertory) \
246 do { \
247 (font_def) = make_uninit_vector (3); \
248 ASET ((font_def), 0, font_spec); \
249 ASET ((font_def), 1, encoding); \
250 ASET ((font_def), 2, repertory); \
251 } while (0)
253 #define FONT_DEF_SPEC(font_def) AREF (font_def, 0)
254 #define FONT_DEF_ENCODING(font_def) AREF (font_def, 1)
255 #define FONT_DEF_REPERTORY(font_def) AREF (font_def, 2)
257 #define RFONT_DEF_FACE(rfont_def) AREF (rfont_def, 0)
258 #define RFONT_DEF_SET_FACE(rfont_def, face_id) \
259 ASET ((rfont_def), 0, make_number (face_id))
260 #define RFONT_DEF_FONT_DEF(rfont_def) AREF (rfont_def, 1)
261 #define RFONT_DEF_SPEC(rfont_def) FONT_DEF_SPEC (AREF (rfont_def, 1))
262 #define RFONT_DEF_OBJECT(rfont_def) AREF (rfont_def, 2)
263 #define RFONT_DEF_SET_OBJECT(rfont_def, object) \
264 ASET ((rfont_def), 2, (object))
265 /* Score of RFONT_DEF is an integer value; the lowest 8 bits represent
266 the order of listing by font backends, the higher bits represents
267 the order given by charset priority list. The smaller value is
268 preferable. */
269 #define RFONT_DEF_SCORE(rfont_def) XINT (AREF (rfont_def, 3))
270 #define RFONT_DEF_SET_SCORE(rfont_def, score) \
271 ASET ((rfont_def), 3, make_number (score))
272 #define RFONT_DEF_NEW(rfont_def, font_def) \
273 do { \
274 (rfont_def) = Fmake_vector (make_number (4), Qnil); \
275 ASET ((rfont_def), 1, (font_def)); \
276 RFONT_DEF_SET_SCORE ((rfont_def), 0); \
277 } while (0)
280 /* Return the element of FONTSET for the character C. If FONTSET is a
281 base fontset other then the default fontset and FONTSET doesn't
282 contain information for C, return the information in the default
283 fontset. */
285 #define FONTSET_REF(fontset, c) \
286 (EQ (fontset, Vdefault_fontset) \
287 ? CHAR_TABLE_REF (fontset, c) \
288 : fontset_ref ((fontset), (c)))
290 static Lisp_Object
291 fontset_ref (Lisp_Object fontset, int c)
293 Lisp_Object elt;
295 elt = CHAR_TABLE_REF (fontset, c);
296 if (NILP (elt) && ! EQ (fontset, Vdefault_fontset)
297 /* Don't check Vdefault_fontset for a realized fontset. */
298 && NILP (FONTSET_BASE (fontset)))
299 elt = CHAR_TABLE_REF (Vdefault_fontset, c);
300 return elt;
303 /* Set elements of FONTSET for characters in RANGE to the value ELT.
304 RANGE is a cons (FROM . TO), where FROM and TO are character codes
305 specifying a range. */
307 #define FONTSET_SET(fontset, range, elt) \
308 Fset_char_table_range ((fontset), (range), (elt))
311 /* Modify the elements of FONTSET for characters in RANGE by replacing
312 with ELT or adding ELT. RANGE is a cons (FROM . TO), where FROM
313 and TO are character codes specifying a range. If ADD is nil,
314 replace with ELT, if ADD is `prepend', prepend ELT, otherwise,
315 append ELT. */
317 #define FONTSET_ADD(fontset, range, elt, add) \
318 (NILP (add) \
319 ? (NILP (range) \
320 ? (set_fontset_fallback \
321 (fontset, Fmake_vector (make_number (1), (elt)))) \
322 : ((void) \
323 Fset_char_table_range (fontset, range, \
324 Fmake_vector (make_number (1), elt)))) \
325 : fontset_add ((fontset), (range), (elt), (add)))
327 static void
328 fontset_add (Lisp_Object fontset, Lisp_Object range, Lisp_Object elt, Lisp_Object add)
330 Lisp_Object args[2];
331 int idx = (EQ (add, Qappend) ? 0 : 1);
333 args[1 - idx] = Fmake_vector (make_number (1), elt);
335 if (CONSP (range))
337 int from = XINT (XCAR (range));
338 int to = XINT (XCDR (range));
339 int from1, to1;
341 do {
342 from1 = from, to1 = to;
343 args[idx] = char_table_ref_and_range (fontset, from, &from1, &to1);
344 char_table_set_range (fontset, from, to1,
345 (NILP (args[idx]) ? args[1 - idx]
346 : CALLMANY (Fvconcat, args)));
347 from = to1 + 1;
348 } while (from < to);
350 else
352 args[idx] = FONTSET_FALLBACK (fontset);
353 set_fontset_fallback (fontset,
354 (NILP (args[idx]) ? args[1 - idx]
355 : CALLMANY (Fvconcat, args)));
359 static int
360 fontset_compare_rfontdef (const void *val1, const void *val2)
362 return (RFONT_DEF_SCORE (*(Lisp_Object *) val1)
363 - RFONT_DEF_SCORE (*(Lisp_Object *) val2));
366 /* Update a cons cell which has this form:
367 (CHARSET-ORDERED-LIST-TICK . FONT-GROUP)
368 where FONT-GROUP is of the form
369 [ PREFERRED-RFONT-DEF RFONT-DEF0 RFONT-DEF1 ... ]
370 Reorder RFONT-DEFs according to the current language, and update
371 CHARSET-ORDERED-LIST-TICK. */
373 static void
374 reorder_font_vector (Lisp_Object font_group, struct font *font)
376 Lisp_Object vec, font_object;
377 int size;
378 int i;
379 bool score_changed = false;
381 if (font)
382 XSETFONT (font_object, font);
383 else
384 font_object = Qnil;
386 vec = XCDR (font_group);
387 size = ASIZE (vec);
388 /* Exclude the tailing nil element from the reordering. */
389 if (NILP (AREF (vec, size - 1)))
390 size--;
392 for (i = 0; i < size; i++)
394 Lisp_Object rfont_def = AREF (vec, i);
395 Lisp_Object font_def = RFONT_DEF_FONT_DEF (rfont_def);
396 Lisp_Object font_spec = FONT_DEF_SPEC (font_def);
397 int score = RFONT_DEF_SCORE (rfont_def) & 0xFF;
398 Lisp_Object otf_spec = Ffont_get (font_spec, QCotf);
400 if (! NILP (otf_spec))
401 /* A font-spec with :otf is preferable regardless of encoding
402 and language.. */
404 else if (! font_match_p (font_spec, font_object))
406 Lisp_Object encoding = FONT_DEF_ENCODING (font_def);
408 if (! NILP (encoding))
410 Lisp_Object tail;
412 for (tail = Vcharset_ordered_list;
413 ! EQ (tail, Vcharset_non_preferred_head) && CONSP (tail);
414 tail = XCDR (tail))
415 if (EQ (encoding, XCAR (tail)))
416 break;
417 else if (score <= min (INT_MAX, MOST_POSITIVE_FIXNUM) - 0x100)
418 score += 0x100;
420 else
422 Lisp_Object lang = Ffont_get (font_spec, QClang);
424 if (! NILP (lang)
425 && ! EQ (lang, Vcurrent_iso639_language)
426 && (! CONSP (Vcurrent_iso639_language)
427 || NILP (Fmemq (lang, Vcurrent_iso639_language))))
428 score |= 0x100;
431 if (RFONT_DEF_SCORE (rfont_def) != score)
433 RFONT_DEF_SET_SCORE (rfont_def, score);
434 score_changed = true;
438 if (score_changed)
439 qsort (XVECTOR (vec)->contents, size, word_size,
440 fontset_compare_rfontdef);
441 EMACS_INT low_tick_bits = charset_ordered_list_tick & MOST_POSITIVE_FIXNUM;
442 XSETCAR (font_group, make_number (low_tick_bits));
445 /* Return a font-group (actually a cons (-1 . FONT-GROUP-VECTOR)) for
446 character C in FONTSET. If C is -1, return a fallback font-group.
447 If C is not -1, the value may be Qt (FONTSET doesn't have a font
448 for C even in the fallback group), or 0 (a font for C may be found
449 only in the fallback group). */
451 static Lisp_Object
452 fontset_get_font_group (Lisp_Object fontset, int c)
454 Lisp_Object font_group;
455 Lisp_Object base_fontset;
456 int from = 0, to = MAX_CHAR, i;
458 eassert (! BASE_FONTSET_P (fontset));
459 if (c >= 0)
460 font_group = CHAR_TABLE_REF (fontset, c);
461 else
462 font_group = FONTSET_FALLBACK (fontset);
463 if (! NILP (font_group))
464 return font_group;
465 base_fontset = FONTSET_BASE (fontset);
466 if (NILP (base_fontset))
467 font_group = Qnil;
468 else if (c >= 0)
469 font_group = char_table_ref_and_range (base_fontset, c, &from, &to);
470 else
471 font_group = FONTSET_FALLBACK (base_fontset);
472 if (NILP (font_group))
474 font_group = make_number (0);
475 if (c >= 0)
476 char_table_set_range (fontset, from, to, font_group);
477 return font_group;
479 if (!VECTORP (font_group))
480 return font_group;
481 font_group = Fcopy_sequence (font_group);
482 for (i = 0; i < ASIZE (font_group); i++)
483 if (! NILP (AREF (font_group, i)))
485 Lisp_Object rfont_def;
487 RFONT_DEF_NEW (rfont_def, AREF (font_group, i));
488 /* Remember the original order. */
489 RFONT_DEF_SET_SCORE (rfont_def, i);
490 ASET (font_group, i, rfont_def);
492 font_group = Fcons (make_number (-1), font_group);
493 if (c >= 0)
494 char_table_set_range (fontset, from, to, font_group);
495 else
496 set_fontset_fallback (fontset, font_group);
497 return font_group;
500 /* Return RFONT-DEF (vector) in the realized fontset FONTSET for the
501 character C. If no font is found, return Qnil if there's a
502 possibility that the default fontset or the fallback font groups
503 have a proper font, and return Qt if not.
505 If a font is found but is not yet opened, open it (if FACE is not
506 NULL) or return Qnil (if FACE is NULL).
508 ID is a charset-id that must be preferred, or -1 meaning no
509 preference.
511 If FALLBACK, search only fallback fonts. */
513 static Lisp_Object
514 fontset_find_font (Lisp_Object fontset, int c, struct face *face, int id,
515 bool fallback)
517 Lisp_Object vec, font_group;
518 int i, charset_matched = 0, found_index;
519 struct frame *f = (FRAMEP (FONTSET_FRAME (fontset))
520 ? XFRAME (FONTSET_FRAME (fontset))
521 : XFRAME (selected_frame));
522 Lisp_Object rfont_def;
524 font_group = fontset_get_font_group (fontset, fallback ? -1 : c);
525 if (! CONSP (font_group))
526 return font_group;
527 vec = XCDR (font_group);
528 if (ASIZE (vec) == 0)
529 return Qnil;
531 if (ASIZE (vec) > 1)
533 if (XINT (XCAR (font_group)) != charset_ordered_list_tick)
534 /* We have just created the font-group,
535 or the charset priorities were changed. */
536 reorder_font_vector (font_group, face->ascii_face->font);
537 if (id >= 0)
538 /* Find a spec matching with the charset ID to try at
539 first. */
540 for (i = 0; i < ASIZE (vec); i++)
542 Lisp_Object repertory;
544 rfont_def = AREF (vec, i);
545 if (NILP (rfont_def))
546 break;
547 repertory = FONT_DEF_REPERTORY (RFONT_DEF_FONT_DEF (rfont_def));
549 if (XINT (repertory) == id)
551 charset_matched = i;
552 break;
557 /* Find the first available font in the vector of RFONT-DEF. */
558 for (i = 0; i < ASIZE (vec); i++)
560 Lisp_Object font_def;
561 Lisp_Object font_entity, font_object;
563 found_index = i;
564 if (i == 0)
566 if (charset_matched > 0)
568 /* Try the element matching with the charset ID at first. */
569 found_index = charset_matched;
570 /* Make this negative so that we don't come here in the
571 next loop. */
572 charset_matched = - charset_matched;
573 /* We must try the first element in the next loop. */
574 i--;
577 else if (i == - charset_matched)
579 /* We have already tried this element and the followings
580 that have the same font specifications in the first
581 iteration. So, skip them all. */
582 rfont_def = AREF (vec, i);
583 font_def = RFONT_DEF_FONT_DEF (rfont_def);
584 for (; i + 1 < ASIZE (vec); i++)
586 rfont_def = AREF (vec, i + 1);
587 if (NILP (rfont_def))
588 break;
589 if (! EQ (RFONT_DEF_FONT_DEF (rfont_def), font_def))
590 break;
592 continue;
595 rfont_def = AREF (vec, found_index);
596 if (NILP (rfont_def))
598 if (i < 0)
599 continue;
600 /* This is a sign of not to try the other fonts. */
601 return Qt;
603 if (INTEGERP (RFONT_DEF_FACE (rfont_def))
604 && XINT (RFONT_DEF_FACE (rfont_def)) < 0)
605 /* We couldn't open this font last time. */
606 continue;
608 font_object = RFONT_DEF_OBJECT (rfont_def);
609 if (NILP (font_object))
611 font_def = RFONT_DEF_FONT_DEF (rfont_def);
613 if (! face)
614 /* We have not yet opened the font. */
615 return Qnil;
616 /* Find a font best-matching with the spec without checking
617 the support of the character C. That checking is costly,
618 and even without the checking, the found font supports C
619 in high possibility. */
620 font_entity = font_find_for_lface (f, face->lface,
621 FONT_DEF_SPEC (font_def), -1);
622 if (NILP (font_entity))
624 /* Record that no font matches the spec. */
625 RFONT_DEF_SET_FACE (rfont_def, -1);
626 continue;
628 font_object = font_open_for_lface (f, font_entity, face->lface,
629 FONT_DEF_SPEC (font_def));
630 if (NILP (font_object))
632 /* Something strange happened, perhaps because of a
633 Font-backend problem. Too avoid crashing, record
634 that this spec is unusable. It may be better to find
635 another font of the same spec, but currently we don't
636 have such an API. */
637 RFONT_DEF_SET_FACE (rfont_def, -1);
638 continue;
640 RFONT_DEF_SET_OBJECT (rfont_def, font_object);
643 if (font_has_char (f, font_object, c))
644 goto found;
646 /* Find a font already opened, matching with the current spec,
647 and supporting C. */
648 font_def = RFONT_DEF_FONT_DEF (rfont_def);
649 for (; found_index + 1 < ASIZE (vec); found_index++)
651 rfont_def = AREF (vec, found_index + 1);
652 if (NILP (rfont_def))
653 break;
654 if (! EQ (RFONT_DEF_FONT_DEF (rfont_def), font_def))
655 break;
656 font_object = RFONT_DEF_OBJECT (rfont_def);
657 if (! NILP (font_object) && font_has_char (f, font_object, c))
659 found_index++;
660 goto found;
664 /* Find a font-entity with the current spec and supporting C. */
665 font_entity = font_find_for_lface (f, face->lface,
666 FONT_DEF_SPEC (font_def), c);
667 if (! NILP (font_entity))
669 /* We found a font. Open it and insert a new element for
670 that font in VEC. */
671 Lisp_Object new_vec;
672 int j;
674 font_object = font_open_for_lface (f, font_entity, face->lface,
675 Qnil);
676 if (NILP (font_object))
677 continue;
678 RFONT_DEF_NEW (rfont_def, font_def);
679 RFONT_DEF_SET_OBJECT (rfont_def, font_object);
680 RFONT_DEF_SET_SCORE (rfont_def, RFONT_DEF_SCORE (rfont_def));
681 new_vec = Fmake_vector (make_number (ASIZE (vec) + 1), Qnil);
682 found_index++;
683 for (j = 0; j < found_index; j++)
684 ASET (new_vec, j, AREF (vec, j));
685 ASET (new_vec, j, rfont_def);
686 for (j++; j < ASIZE (new_vec); j++)
687 ASET (new_vec, j, AREF (vec, j - 1));
688 XSETCDR (font_group, new_vec);
689 vec = new_vec;
690 goto found;
692 if (i >= 0)
693 i = found_index;
696 FONTSET_SET (fontset, make_number (c), make_number (0));
697 return Qnil;
699 found:
700 if (fallback && found_index > 0)
702 /* The order of fonts in the fallback font-group is not that
703 important, and it is better to move the found font to the
704 first of the group so that the next try will find it
705 quickly. */
706 for (i = found_index; i > 0; i--)
707 ASET (vec, i, AREF (vec, i - 1));
708 ASET (vec, 0, rfont_def);
710 return rfont_def;
714 static Lisp_Object
715 fontset_font (Lisp_Object fontset, int c, struct face *face, int id)
717 Lisp_Object rfont_def, default_rfont_def IF_LINT (= Qnil);
718 Lisp_Object base_fontset;
720 /* Try a font-group of FONTSET. */
721 FONT_DEFERRED_LOG ("current fontset: font for", make_number (c), Qnil);
722 rfont_def = fontset_find_font (fontset, c, face, id, 0);
723 if (VECTORP (rfont_def))
724 return rfont_def;
725 if (NILP (rfont_def))
726 FONTSET_SET (fontset, make_number (c), make_number (0));
728 /* Try a font-group of the default fontset. */
729 base_fontset = FONTSET_BASE (fontset);
730 if (! EQ (base_fontset, Vdefault_fontset))
732 if (NILP (FONTSET_DEFAULT (fontset)))
733 set_fontset_default
734 (fontset,
735 make_fontset (FONTSET_FRAME (fontset), Qnil, Vdefault_fontset));
736 FONT_DEFERRED_LOG ("default fontset: font for", make_number (c), Qnil);
737 default_rfont_def
738 = fontset_find_font (FONTSET_DEFAULT (fontset), c, face, id, 0);
739 if (VECTORP (default_rfont_def))
740 return default_rfont_def;
741 if (NILP (default_rfont_def))
742 FONTSET_SET (FONTSET_DEFAULT (fontset), make_number (c),
743 make_number (0));
746 /* Try a fallback font-group of FONTSET. */
747 if (! EQ (rfont_def, Qt))
749 FONT_DEFERRED_LOG ("current fallback: font for", make_number (c), Qnil);
750 rfont_def = fontset_find_font (fontset, c, face, id, 1);
751 if (VECTORP (rfont_def))
752 return rfont_def;
753 /* Remember that FONTSET has no font for C. */
754 FONTSET_SET (fontset, make_number (c), Qt);
757 /* Try a fallback font-group of the default fontset. */
758 if (! EQ (base_fontset, Vdefault_fontset)
759 && ! EQ (default_rfont_def, Qt))
761 FONT_DEFERRED_LOG ("default fallback: font for", make_number (c), Qnil);
762 rfont_def = fontset_find_font (FONTSET_DEFAULT (fontset), c, face, id, 1);
763 if (VECTORP (rfont_def))
764 return rfont_def;
765 /* Remember that the default fontset has no font for C. */
766 FONTSET_SET (FONTSET_DEFAULT (fontset), make_number (c), Qt);
769 return Qnil;
772 /* Return a newly created fontset with NAME. If BASE is nil, make a
773 base fontset. Otherwise make a realized fontset whose base is
774 BASE. */
776 static Lisp_Object
777 make_fontset (Lisp_Object frame, Lisp_Object name, Lisp_Object base)
779 Lisp_Object fontset;
780 int size = ASIZE (Vfontset_table);
781 int id = next_fontset_id;
783 /* Find a free slot in Vfontset_table. Usually, next_fontset_id is
784 the next available fontset ID. So it is expected that this loop
785 terminates quickly. In addition, as the last element of
786 Vfontset_table is always nil, we don't have to check the range of
787 id. */
788 while (!NILP (AREF (Vfontset_table, id))) id++;
790 if (id + 1 == size)
791 Vfontset_table = larger_vector (Vfontset_table, 1, -1);
793 fontset = Fmake_char_table (Qfontset, Qnil);
795 set_fontset_id (fontset, make_number (id));
796 if (NILP (base))
797 set_fontset_name (fontset, name);
798 else
800 set_fontset_name (fontset, Qnil);
801 set_fontset_frame (fontset, frame);
802 set_fontset_base (fontset, base);
805 ASET (Vfontset_table, id, fontset);
806 next_fontset_id = id + 1;
807 return fontset;
811 /********** INTERFACES TO xfaces.c, xfns.c, and dispextern.h **********/
813 /* Return the name of the fontset who has ID. */
815 Lisp_Object
816 fontset_name (int id)
818 Lisp_Object fontset;
820 fontset = FONTSET_FROM_ID (id);
821 return FONTSET_NAME (fontset);
825 /* Return the ASCII font name of the fontset who has ID. */
827 Lisp_Object
828 fontset_ascii (int id)
830 Lisp_Object fontset, elt;
832 fontset= FONTSET_FROM_ID (id);
833 elt = FONTSET_ASCII (fontset);
834 if (CONSP (elt))
835 elt = XCAR (elt);
836 return elt;
839 /* Free fontset of FACE defined on frame F. Called from
840 free_realized_face. */
842 void
843 free_face_fontset (struct frame *f, struct face *face)
845 Lisp_Object fontset;
847 fontset = FONTSET_FROM_ID (face->fontset);
848 if (NILP (fontset))
849 return;
850 eassert (! BASE_FONTSET_P (fontset));
851 eassert (f == XFRAME (FONTSET_FRAME (fontset)));
852 ASET (Vfontset_table, face->fontset, Qnil);
853 if (face->fontset < next_fontset_id)
854 next_fontset_id = face->fontset;
855 if (! NILP (FONTSET_DEFAULT (fontset)))
857 int id = XINT (FONTSET_ID (FONTSET_DEFAULT (fontset)));
859 fontset = AREF (Vfontset_table, id);
860 eassert (!NILP (fontset) && ! BASE_FONTSET_P (fontset));
861 eassert (f == XFRAME (FONTSET_FRAME (fontset)));
862 ASET (Vfontset_table, id, Qnil);
863 if (id < next_fontset_id)
864 next_fontset_id = face->fontset;
866 face->fontset = -1;
869 /* Return ID of face suitable for displaying character C at buffer position
870 POS on frame F. FACE must be realized for ASCII characters in advance.
871 Called from the macro FACE_FOR_CHAR. */
874 face_for_char (struct frame *f, struct face *face, int c,
875 ptrdiff_t pos, Lisp_Object object)
877 Lisp_Object fontset, rfont_def, charset;
878 int face_id;
879 int id;
881 eassert (fontset_id_valid_p (face->fontset));
883 if (ASCII_CHAR_P (c) || CHAR_BYTE8_P (c))
884 return face->ascii_face->id;
886 if (use_default_font_for_symbols /* let the user disable this feature */
887 && c > 0 && EQ (CHAR_TABLE_REF (Vchar_script_table, c), Qsymbol))
889 /* Fonts often have characters for punctuation and other
890 symbols, even if they don't match the 'symbol' script. So
891 check if the character is present in the current ASCII face
892 first, and if so, use the same font as used by that face.
893 This avoids unnecessarily switching to another font when the
894 frame's default font will do. We only do this for symbols so
895 that users could still setup fontsets to force Emacs to use
896 specific fonts for characters from other scripts, because
897 choice of fonts is frequently affected by cultural
898 preferences and font features, not by font coverage.
899 However, these considerations are unlikely to be relevant to
900 punctuation and other symbols, since the latter generally
901 aren't specific to any culture, and don't require
902 sophisticated OTF features. */
903 Lisp_Object font_object;
905 if (face->ascii_face->font)
907 XSETFONT (font_object, face->ascii_face->font);
908 if (font_has_char (f, font_object, c))
909 return face->ascii_face->id;
912 #if 0
913 /* Try the current face. Disabled because it can cause
914 counter-intuitive results, whereby the font used for some
915 character depends on the characters that precede it on
916 display. See the discussion of bug #15138. Note that the
917 original bug reported in #15138 was in a situation where face
918 == face->ascii_face, so the above code solves that situation
919 without risking the undesirable consequences. */
920 if (face->font)
922 XSETFONT (font_object, face->font);
923 if (font_has_char (f, font_object, c)) return face->id;
925 #endif
928 fontset = FONTSET_FROM_ID (face->fontset);
929 eassert (!BASE_FONTSET_P (fontset));
931 if (pos < 0)
933 id = -1;
934 charset = Qnil;
936 else
938 charset = Fget_char_property (make_number (pos), Qcharset, object);
939 if (CHARSETP (charset))
941 Lisp_Object val;
943 val = assq_no_quit (charset, Vfont_encoding_charset_alist);
944 if (CONSP (val) && CHARSETP (XCDR (val)))
945 charset = XCDR (val);
946 id = XINT (CHARSET_SYMBOL_ID (charset));
948 else
949 id = -1;
952 rfont_def = fontset_font (fontset, c, face, id);
953 if (VECTORP (rfont_def))
955 if (INTEGERP (RFONT_DEF_FACE (rfont_def)))
956 face_id = XINT (RFONT_DEF_FACE (rfont_def));
957 else
959 Lisp_Object font_object;
961 font_object = RFONT_DEF_OBJECT (rfont_def);
962 face_id = face_for_font (f, font_object, face);
963 RFONT_DEF_SET_FACE (rfont_def, face_id);
966 else
968 if (INTEGERP (FONTSET_NOFONT_FACE (fontset)))
969 face_id = XINT (FONTSET_NOFONT_FACE (fontset));
970 else
972 face_id = face_for_font (f, Qnil, face);
973 set_fontset_nofont_face (fontset, make_number (face_id));
976 eassert (face_id >= 0);
977 return face_id;
981 Lisp_Object
982 font_for_char (struct face *face, int c, ptrdiff_t pos, Lisp_Object object)
984 Lisp_Object fontset, rfont_def, charset;
985 int id;
987 if (ASCII_CHAR_P (c))
989 Lisp_Object font_object;
991 XSETFONT (font_object, face->ascii_face->font);
992 return font_object;
995 eassert (fontset_id_valid_p (face->fontset));
996 fontset = FONTSET_FROM_ID (face->fontset);
997 eassert (!BASE_FONTSET_P (fontset));
998 if (pos < 0)
1000 id = -1;
1001 charset = Qnil;
1003 else
1005 charset = Fget_char_property (make_number (pos), Qcharset, object);
1006 if (CHARSETP (charset))
1008 Lisp_Object val;
1010 val = assq_no_quit (charset, Vfont_encoding_charset_alist);
1011 if (CONSP (val) && CHARSETP (XCDR (val)))
1012 charset = XCDR (val);
1013 id = XINT (CHARSET_SYMBOL_ID (charset));
1015 else
1016 id = -1;
1019 rfont_def = fontset_font (fontset, c, face, id);
1020 return (VECTORP (rfont_def)
1021 ? RFONT_DEF_OBJECT (rfont_def)
1022 : Qnil);
1026 /* Make a realized fontset for ASCII face FACE on frame F from the
1027 base fontset BASE_FONTSET_ID. If BASE_FONTSET_ID is -1, use the
1028 default fontset as the base. Value is the id of the new fontset.
1029 Called from realize_x_face. */
1032 make_fontset_for_ascii_face (struct frame *f, int base_fontset_id, struct face *face)
1034 Lisp_Object base_fontset, fontset, frame;
1036 XSETFRAME (frame, f);
1037 if (base_fontset_id >= 0)
1039 base_fontset = FONTSET_FROM_ID (base_fontset_id);
1040 if (!BASE_FONTSET_P (base_fontset))
1041 base_fontset = FONTSET_BASE (base_fontset);
1042 eassert (BASE_FONTSET_P (base_fontset));
1044 else
1045 base_fontset = Vdefault_fontset;
1047 fontset = make_fontset (frame, Qnil, base_fontset);
1048 return XINT (FONTSET_ID (fontset));
1053 /* Cache data used by fontset_pattern_regexp. The car part is a
1054 pattern string containing at least one wild card, the cdr part is
1055 the corresponding regular expression. */
1056 static Lisp_Object Vcached_fontset_data;
1058 #define CACHED_FONTSET_NAME SSDATA (XCAR (Vcached_fontset_data))
1059 #define CACHED_FONTSET_REGEX (XCDR (Vcached_fontset_data))
1061 /* If fontset name PATTERN contains any wild card, return regular
1062 expression corresponding to PATTERN. */
1064 static Lisp_Object
1065 fontset_pattern_regexp (Lisp_Object pattern)
1067 if (!strchr (SSDATA (pattern), '*')
1068 && !strchr (SSDATA (pattern), '?'))
1069 /* PATTERN does not contain any wild cards. */
1070 return Qnil;
1072 if (!CONSP (Vcached_fontset_data)
1073 || strcmp (SSDATA (pattern), CACHED_FONTSET_NAME))
1075 /* We must at first update the cached data. */
1076 unsigned char *regex, *p0, *p1;
1077 int ndashes = 0, nstars = 0, nescs = 0;
1079 for (p0 = SDATA (pattern); *p0; p0++)
1081 if (*p0 == '-')
1082 ndashes++;
1083 else if (*p0 == '*')
1084 nstars++;
1085 else if (*p0 == '['
1086 || *p0 == '.' || *p0 == '\\'
1087 || *p0 == '+' || *p0 == '^'
1088 || *p0 == '$')
1089 nescs++;
1092 /* If PATTERN is not full XLFD we convert "*" to ".*". Otherwise
1093 we convert "*" to "[^-]*" which is much faster in regular
1094 expression matching. */
1095 ptrdiff_t regexsize = (SBYTES (pattern)
1096 + (ndashes < 14 ? 2 : 5) * nstars
1097 + 2 * nescs + 3);
1098 USE_SAFE_ALLOCA;
1099 p1 = regex = SAFE_ALLOCA (regexsize);
1101 *p1++ = '^';
1102 for (p0 = SDATA (pattern); *p0; p0++)
1104 if (*p0 == '*')
1106 if (ndashes < 14)
1107 *p1++ = '.';
1108 else
1109 *p1++ = '[', *p1++ = '^', *p1++ = '-', *p1++ = ']';
1110 *p1++ = '*';
1112 else if (*p0 == '?')
1113 *p1++ = '.';
1114 else if (*p0 == '['
1115 || *p0 == '.' || *p0 == '\\'
1116 || *p0 == '+' || *p0 == '^'
1117 || *p0 == '$')
1118 *p1++ = '\\', *p1++ = *p0;
1119 else
1120 *p1++ = *p0;
1122 *p1++ = '$';
1123 *p1++ = 0;
1125 Vcached_fontset_data = Fcons (build_string (SSDATA (pattern)),
1126 build_string ((char *) regex));
1127 SAFE_FREE ();
1130 return CACHED_FONTSET_REGEX;
1133 /* Return ID of the base fontset named NAME. If there's no such
1134 fontset, return -1. NAME_PATTERN specifies how to treat NAME as this:
1135 0: pattern containing '*' and '?' as wildcards
1136 1: regular expression
1137 2: literal fontset name
1141 fs_query_fontset (Lisp_Object name, int name_pattern)
1143 Lisp_Object tem;
1144 int i;
1146 name = Fdowncase (name);
1147 if (name_pattern != 1)
1149 tem = Frassoc (name, Vfontset_alias_alist);
1150 if (NILP (tem))
1151 tem = Fassoc (name, Vfontset_alias_alist);
1152 if (CONSP (tem) && STRINGP (XCAR (tem)))
1153 name = XCAR (tem);
1154 else if (name_pattern == 0)
1156 tem = fontset_pattern_regexp (name);
1157 if (STRINGP (tem))
1159 name = tem;
1160 name_pattern = 1;
1165 for (i = 0; i < ASIZE (Vfontset_table); i++)
1167 Lisp_Object fontset, this_name;
1169 fontset = FONTSET_FROM_ID (i);
1170 if (NILP (fontset)
1171 || !BASE_FONTSET_P (fontset))
1172 continue;
1174 this_name = FONTSET_NAME (fontset);
1175 if (name_pattern == 1
1176 ? fast_string_match_ignore_case (name, this_name) >= 0
1177 : !xstrcasecmp (SSDATA (name), SSDATA (this_name)))
1178 return i;
1180 return -1;
1184 DEFUN ("query-fontset", Fquery_fontset, Squery_fontset, 1, 2, 0,
1185 doc: /* Return the name of a fontset that matches PATTERN.
1186 The value is nil if there is no matching fontset.
1187 PATTERN can contain `*' or `?' as a wildcard
1188 just as X font name matching algorithm allows.
1189 If REGEXPP is non-nil, PATTERN is a regular expression. */)
1190 (Lisp_Object pattern, Lisp_Object regexpp)
1192 Lisp_Object fontset;
1193 int id;
1195 check_window_system (NULL);
1197 CHECK_STRING (pattern);
1199 if (SCHARS (pattern) == 0)
1200 return Qnil;
1202 id = fs_query_fontset (pattern, !NILP (regexpp));
1203 if (id < 0)
1204 return Qnil;
1206 fontset = FONTSET_FROM_ID (id);
1207 return FONTSET_NAME (fontset);
1210 /* Return a list of base fontset names matching PATTERN on frame F. */
1212 Lisp_Object
1213 list_fontsets (struct frame *f, Lisp_Object pattern, int size)
1215 Lisp_Object frame, regexp, val;
1216 int id;
1218 XSETFRAME (frame, f);
1220 regexp = fontset_pattern_regexp (pattern);
1221 val = Qnil;
1223 for (id = 0; id < ASIZE (Vfontset_table); id++)
1225 Lisp_Object fontset, name;
1227 fontset = FONTSET_FROM_ID (id);
1228 if (NILP (fontset)
1229 || !BASE_FONTSET_P (fontset)
1230 || !EQ (frame, FONTSET_FRAME (fontset)))
1231 continue;
1232 name = FONTSET_NAME (fontset);
1234 if (STRINGP (regexp)
1235 ? (fast_string_match (regexp, name) < 0)
1236 : strcmp (SSDATA (pattern), SSDATA (name)))
1237 continue;
1239 val = Fcons (Fcopy_sequence (FONTSET_NAME (fontset)), val);
1242 return val;
1246 /* Free all realized fontsets whose base fontset is BASE. */
1248 static void
1249 free_realized_fontsets (Lisp_Object base)
1251 int id;
1253 #if 0
1254 /* For the moment, this doesn't work because free_realized_face
1255 doesn't remove FACE from a cache. Until we find a solution, we
1256 suppress this code, and simply use Fclear_face_cache even though
1257 that is not efficient. */
1258 block_input ();
1259 for (id = 0; id < ASIZE (Vfontset_table); id++)
1261 Lisp_Object this = AREF (Vfontset_table, id);
1263 if (EQ (FONTSET_BASE (this), base))
1265 Lisp_Object tail;
1267 for (tail = FONTSET_FACE_ALIST (this); CONSP (tail);
1268 tail = XCDR (tail))
1270 struct frame *f = XFRAME (FONTSET_FRAME (this));
1271 int face_id = XINT (XCDR (XCAR (tail)));
1272 struct face *face = FACE_FROM_ID (f, face_id);
1274 /* Face THIS itself is also freed by the following call. */
1275 free_realized_face (f, face);
1279 unblock_input ();
1280 #else /* not 0 */
1281 /* But, we don't have to call Fclear_face_cache if no fontset has
1282 been realized from BASE. */
1283 for (id = 0; id < ASIZE (Vfontset_table); id++)
1285 Lisp_Object this = AREF (Vfontset_table, id);
1287 if (CHAR_TABLE_P (this) && EQ (FONTSET_BASE (this), base))
1289 Fclear_face_cache (Qt);
1290 break;
1293 #endif /* not 0 */
1297 /* Check validity of NAME as a fontset name and return the
1298 corresponding fontset. If not valid, signal an error.
1300 If NAME is t, return Vdefault_fontset. If NAME is nil, return the
1301 fontset of *FRAME.
1303 Set *FRAME to the actual frame. */
1305 static Lisp_Object
1306 check_fontset_name (Lisp_Object name, Lisp_Object *frame)
1308 int id;
1309 struct frame *f = decode_live_frame (*frame);
1311 XSETFRAME (*frame, f);
1313 if (EQ (name, Qt))
1314 return Vdefault_fontset;
1315 if (NILP (name))
1316 id = FRAME_FONTSET (f);
1317 else
1319 CHECK_STRING (name);
1320 /* First try NAME as literal. */
1321 id = fs_query_fontset (name, 2);
1322 if (id < 0)
1323 /* For backward compatibility, try again NAME as pattern. */
1324 id = fs_query_fontset (name, 0);
1325 if (id < 0)
1326 error ("Fontset `%s' does not exist", SDATA (name));
1328 return FONTSET_FROM_ID (id);
1331 static void
1332 accumulate_script_ranges (Lisp_Object arg, Lisp_Object range, Lisp_Object val)
1334 if (EQ (XCAR (arg), val))
1336 if (CONSP (range))
1337 XSETCDR (arg, Fcons (Fcons (XCAR (range), XCDR (range)), XCDR (arg)));
1338 else
1339 XSETCDR (arg, Fcons (Fcons (range, range), XCDR (arg)));
1344 /* Callback function for map_charset_chars in Fset_fontset_font.
1345 ARG is a vector [ FONTSET FONT_DEF ADD ASCII SCRIPT_RANGE_LIST ].
1347 In FONTSET, set FONT_DEF in a fashion specified by ADD for
1348 characters in RANGE and ranges in SCRIPT_RANGE_LIST before RANGE.
1349 The consumed ranges are popped up from SCRIPT_RANGE_LIST, and the
1350 new SCRIPT_RANGE_LIST is stored in ARG.
1352 If ASCII is nil, don't set FONT_DEF for ASCII characters. It is
1353 assured that SCRIPT_RANGE_LIST doesn't contain ASCII in that
1354 case. */
1356 static void
1357 set_fontset_font (Lisp_Object arg, Lisp_Object range)
1359 Lisp_Object fontset, font_def, add, ascii, script_range_list;
1360 int from = XINT (XCAR (range)), to = XINT (XCDR (range));
1362 fontset = AREF (arg, 0);
1363 font_def = AREF (arg, 1);
1364 add = AREF (arg, 2);
1365 ascii = AREF (arg, 3);
1366 script_range_list = AREF (arg, 4);
1368 if (NILP (ascii) && from < 0x80)
1370 if (to < 0x80)
1371 return;
1372 from = 0x80;
1373 range = Fcons (make_number (0x80), XCDR (range));
1376 #define SCRIPT_FROM XINT (XCAR (XCAR (script_range_list)))
1377 #define SCRIPT_TO XINT (XCDR (XCAR (script_range_list)))
1378 #define POP_SCRIPT_RANGE() script_range_list = XCDR (script_range_list)
1380 for (; CONSP (script_range_list) && SCRIPT_TO < from; POP_SCRIPT_RANGE ())
1381 FONTSET_ADD (fontset, XCAR (script_range_list), font_def, add);
1382 if (CONSP (script_range_list))
1384 if (SCRIPT_FROM < from)
1385 range = Fcons (make_number (SCRIPT_FROM), XCDR (range));
1386 while (CONSP (script_range_list) && SCRIPT_TO <= to)
1387 POP_SCRIPT_RANGE ();
1388 if (CONSP (script_range_list) && SCRIPT_FROM <= to)
1389 XSETCAR (XCAR (script_range_list), make_number (to + 1));
1392 FONTSET_ADD (fontset, range, font_def, add);
1393 ASET (arg, 4, script_range_list);
1396 static void update_auto_fontset_alist (Lisp_Object, Lisp_Object);
1399 DEFUN ("set-fontset-font", Fset_fontset_font, Sset_fontset_font, 3, 5, 0,
1400 doc: /*
1401 Modify fontset NAME to use FONT-SPEC for TARGET characters.
1403 NAME is a fontset name string, nil for the fontset of FRAME, or t for
1404 the default fontset.
1406 TARGET may be a single character to use FONT-SPEC for.
1408 Target may be a cons (FROM . TO), where FROM and TO are characters.
1409 In that case, use FONT-SPEC for all characters in the range FROM
1410 and TO (inclusive).
1412 TARGET may be a script name symbol. In that case, use FONT-SPEC for
1413 all characters that belong to the script.
1415 TARGET may be a charset. In that case, use FONT-SPEC for all
1416 characters in the charset.
1418 TARGET may be nil. In that case, use FONT-SPEC for any characters for
1419 that no FONT-SPEC is specified.
1421 FONT-SPEC may one of these:
1422 * A font-spec object made by the function `font-spec' (which see).
1423 * A cons (FAMILY . REGISTRY), where FAMILY is a font family name and
1424 REGISTRY is a font registry name. FAMILY may contain foundry
1425 name, and REGISTRY may contain encoding name.
1426 * A font name string.
1427 * nil, which explicitly specifies that there's no font for TARGET.
1429 Optional 4th argument FRAME is a frame or nil for the selected frame
1430 that is concerned in the case that NAME is nil.
1432 Optional 5th argument ADD, if non-nil, specifies how to add FONT-SPEC
1433 to the font specifications for TARGET previously set. If it is
1434 `prepend', FONT-SPEC is prepended. If it is `append', FONT-SPEC is
1435 appended. By default, FONT-SPEC overrides the previous settings. */)
1436 (Lisp_Object name, Lisp_Object target, Lisp_Object font_spec, Lisp_Object frame, Lisp_Object add)
1438 Lisp_Object fontset;
1439 Lisp_Object font_def, registry, family;
1440 Lisp_Object range_list;
1441 struct charset *charset = NULL;
1442 Lisp_Object fontname;
1443 bool ascii_changed = 0;
1445 fontset = check_fontset_name (name, &frame);
1447 fontname = Qnil;
1448 if (CONSP (font_spec))
1450 Lisp_Object spec = Ffont_spec (0, NULL);
1452 font_parse_family_registry (XCAR (font_spec), XCDR (font_spec), spec);
1453 font_spec = spec;
1454 fontname = Ffont_xlfd_name (font_spec, Qnil);
1456 else if (STRINGP (font_spec))
1458 fontname = font_spec;
1459 font_spec = CALLN (Ffont_spec, QCname, fontname);
1461 else if (FONT_SPEC_P (font_spec))
1462 fontname = Ffont_xlfd_name (font_spec, Qnil);
1463 else if (! NILP (font_spec))
1464 Fsignal (Qfont, list2 (build_string ("Invalid font-spec"), font_spec));
1466 if (! NILP (font_spec))
1468 Lisp_Object encoding, repertory;
1470 family = AREF (font_spec, FONT_FAMILY_INDEX);
1471 if (! NILP (family) )
1472 family = SYMBOL_NAME (family);
1473 registry = AREF (font_spec, FONT_REGISTRY_INDEX);
1474 if (! NILP (registry))
1475 registry = Fdowncase (SYMBOL_NAME (registry));
1476 AUTO_STRING (dash, "-");
1477 encoding = find_font_encoding (concat3 (family, dash, registry));
1478 if (NILP (encoding))
1479 encoding = Qascii;
1481 if (SYMBOLP (encoding))
1483 CHECK_CHARSET (encoding);
1484 encoding = repertory = CHARSET_SYMBOL_ID (encoding);
1486 else
1488 repertory = XCDR (encoding);
1489 encoding = XCAR (encoding);
1490 CHECK_CHARSET (encoding);
1491 encoding = CHARSET_SYMBOL_ID (encoding);
1492 if (! NILP (repertory) && SYMBOLP (repertory))
1494 CHECK_CHARSET (repertory);
1495 repertory = CHARSET_SYMBOL_ID (repertory);
1498 FONT_DEF_NEW (font_def, font_spec, encoding, repertory);
1500 else
1501 font_def = Qnil;
1503 if (CHARACTERP (target))
1505 if (XFASTINT (target) < 0x80)
1506 error ("Can't set a font for partial ASCII range");
1507 range_list = list1 (Fcons (target, target));
1509 else if (CONSP (target))
1511 Lisp_Object from, to;
1513 from = Fcar (target);
1514 to = Fcdr (target);
1515 CHECK_CHARACTER (from);
1516 CHECK_CHARACTER (to);
1517 if (XFASTINT (from) < 0x80)
1519 if (XFASTINT (from) != 0 || XFASTINT (to) < 0x7F)
1520 error ("Can't set a font for partial ASCII range");
1521 ascii_changed = 1;
1523 range_list = list1 (target);
1525 else if (SYMBOLP (target) && !NILP (target))
1527 Lisp_Object script_list;
1528 Lisp_Object val;
1530 range_list = Qnil;
1531 script_list = XCHAR_TABLE (Vchar_script_table)->extras[0];
1532 if (! NILP (Fmemq (target, script_list)))
1534 if (EQ (target, Qlatin))
1535 ascii_changed = 1;
1536 val = list1 (target);
1537 map_char_table (accumulate_script_ranges, Qnil, Vchar_script_table,
1538 val);
1539 range_list = Fnreverse (XCDR (val));
1541 if (CHARSETP (target))
1543 CHECK_CHARSET_GET_CHARSET (target, charset);
1544 if (charset->ascii_compatible_p)
1545 ascii_changed = 1;
1547 else if (NILP (range_list))
1548 error ("Invalid script or charset name: %s",
1549 SDATA (SYMBOL_NAME (target)));
1551 else if (NILP (target))
1552 range_list = list1 (Qnil);
1553 else
1554 error ("Invalid target for setting a font");
1556 if (ascii_changed)
1558 Lisp_Object val;
1560 if (NILP (font_spec))
1561 error ("Can't set ASCII font to nil");
1562 val = CHAR_TABLE_REF (fontset, 0);
1563 if (! NILP (val) && EQ (add, Qappend))
1564 /* We are going to change just an additional font for ASCII. */
1565 ascii_changed = 0;
1568 if (charset)
1570 Lisp_Object arg;
1572 arg = make_uninit_vector (5);
1573 ASET (arg, 0, fontset);
1574 ASET (arg, 1, font_def);
1575 ASET (arg, 2, add);
1576 ASET (arg, 3, ascii_changed ? Qt : Qnil);
1577 ASET (arg, 4, range_list);
1579 map_charset_chars (set_fontset_font, Qnil, arg, charset,
1580 CHARSET_MIN_CODE (charset),
1581 CHARSET_MAX_CODE (charset));
1582 range_list = AREF (arg, 4);
1584 for (; CONSP (range_list); range_list = XCDR (range_list))
1585 FONTSET_ADD (fontset, XCAR (range_list), font_def, add);
1587 if (ascii_changed)
1589 Lisp_Object tail, fr;
1590 int fontset_id = XINT (FONTSET_ID (fontset));
1592 set_fontset_ascii (fontset, fontname);
1593 name = FONTSET_NAME (fontset);
1594 FOR_EACH_FRAME (tail, fr)
1596 struct frame *f = XFRAME (fr);
1597 Lisp_Object font_object;
1598 struct face *face;
1600 if (FRAME_INITIAL_P (f) || FRAME_TERMCAP_P (f))
1601 continue;
1602 if (fontset_id != FRAME_FONTSET (f))
1603 continue;
1604 face = FACE_FROM_ID (f, DEFAULT_FACE_ID);
1605 if (face)
1606 font_object = font_load_for_lface (f, face->lface, font_spec);
1607 else
1608 font_object = font_open_by_spec (f, font_spec);
1609 if (! NILP (font_object))
1611 update_auto_fontset_alist (font_object, fontset);
1612 AUTO_FRAME_ARG (arg, Qfont, Fcons (name, font_object));
1613 Fmodify_frame_parameters (fr, arg);
1618 /* Free all realized fontsets whose base is FONTSET. This way, the
1619 specified character(s) are surely redisplayed by a correct
1620 font. */
1621 free_realized_fontsets (fontset);
1623 return Qnil;
1627 DEFUN ("new-fontset", Fnew_fontset, Snew_fontset, 2, 2, 0,
1628 doc: /* Create a new fontset NAME from font information in FONTLIST.
1630 FONTLIST is an alist of scripts vs the corresponding font specification list.
1631 Each element of FONTLIST has the form (SCRIPT FONT-SPEC ...), where a
1632 character of SCRIPT is displayed by a font that matches one of
1633 FONT-SPEC.
1635 SCRIPT is a symbol that appears in the first extra slot of the
1636 char-table `char-script-table'.
1638 FONT-SPEC is a vector, a cons, or a string. See the documentation of
1639 `set-fontset-font' for the meaning. */)
1640 (Lisp_Object name, Lisp_Object fontlist)
1642 Lisp_Object fontset;
1643 int id;
1645 CHECK_STRING (name);
1646 CHECK_LIST (fontlist);
1648 name = Fdowncase (name);
1649 id = fs_query_fontset (name, 0);
1650 if (id < 0)
1652 Lisp_Object font_spec = Ffont_spec (0, NULL);
1653 Lisp_Object short_name;
1654 char xlfd[256];
1655 int len;
1657 if (font_parse_xlfd (SSDATA (name), SBYTES (name), font_spec) < 0)
1658 error ("Fontset name must be in XLFD format");
1659 short_name = AREF (font_spec, FONT_REGISTRY_INDEX);
1660 if (strncmp (SSDATA (SYMBOL_NAME (short_name)), "fontset-", 8)
1661 || SBYTES (SYMBOL_NAME (short_name)) < 9)
1662 error ("Registry field of fontset name must be \"fontset-*\"");
1663 Vfontset_alias_alist = Fcons (Fcons (name, SYMBOL_NAME (short_name)),
1664 Vfontset_alias_alist);
1665 ASET (font_spec, FONT_REGISTRY_INDEX, Qiso8859_1);
1666 fontset = make_fontset (Qnil, name, Qnil);
1667 len = font_unparse_xlfd (font_spec, 0, xlfd, 256);
1668 if (len < 0)
1669 error ("Invalid fontset name (perhaps too long): %s", SDATA (name));
1670 set_fontset_ascii (fontset, make_unibyte_string (xlfd, len));
1672 else
1674 fontset = FONTSET_FROM_ID (id);
1675 free_realized_fontsets (fontset);
1676 Fset_char_table_range (fontset, Qt, Qnil);
1679 for (; CONSP (fontlist); fontlist = XCDR (fontlist))
1681 Lisp_Object elt, script;
1683 elt = XCAR (fontlist);
1684 script = Fcar (elt);
1685 elt = Fcdr (elt);
1686 if (CONSP (elt) && (NILP (XCDR (elt)) || CONSP (XCDR (elt))))
1687 for (; CONSP (elt); elt = XCDR (elt))
1688 Fset_fontset_font (name, script, XCAR (elt), Qnil, Qappend);
1689 else
1690 Fset_fontset_font (name, script, elt, Qnil, Qappend);
1692 return name;
1696 /* Alist of automatically created fontsets. Each element is a cons
1697 (FONT-SPEC . FONTSET-ID). */
1698 static Lisp_Object auto_fontset_alist;
1700 /* Number of automatically created fontsets. */
1701 static ptrdiff_t num_auto_fontsets;
1703 /* Return a fontset synthesized from FONT-OBJECT. This is called from
1704 x_new_font when FONT-OBJECT is used for the default ASCII font of a
1705 frame, and the returned fontset is used for the default fontset of
1706 that frame. The fontset specifies a font of the same registry as
1707 FONT-OBJECT for all characters in the repertory of the registry
1708 (see Vfont_encoding_alist). If the repertory is not known, the
1709 fontset specifies the font for all Latin characters assuming that a
1710 user intends to use FONT-OBJECT for Latin characters. */
1713 fontset_from_font (Lisp_Object font_object)
1715 Lisp_Object font_name = font_get_name (font_object);
1716 Lisp_Object font_spec = copy_font_spec (font_object);
1717 Lisp_Object registry = AREF (font_spec, FONT_REGISTRY_INDEX);
1718 Lisp_Object fontset_spec, alias, name, fontset;
1719 Lisp_Object val;
1721 val = assoc_no_quit (font_spec, auto_fontset_alist);
1722 if (CONSP (val))
1723 return XINT (FONTSET_ID (XCDR (val)));
1724 if (num_auto_fontsets++ == 0)
1725 alias = intern ("fontset-startup");
1726 else
1728 char temp[sizeof "fontset-auto" + INT_STRLEN_BOUND (ptrdiff_t)];
1730 sprintf (temp, "fontset-auto%"pD"d", num_auto_fontsets - 1);
1731 alias = intern (temp);
1733 fontset_spec = copy_font_spec (font_spec);
1734 ASET (fontset_spec, FONT_REGISTRY_INDEX, alias);
1735 name = Ffont_xlfd_name (fontset_spec, Qnil);
1736 eassert (!NILP (name));
1737 fontset = make_fontset (Qnil, name, Qnil);
1738 Vfontset_alias_alist = Fcons (Fcons (name, SYMBOL_NAME (alias)),
1739 Vfontset_alias_alist);
1740 alias = Fdowncase (AREF (font_object, FONT_NAME_INDEX));
1741 Vfontset_alias_alist = Fcons (Fcons (name, alias), Vfontset_alias_alist);
1742 auto_fontset_alist = Fcons (Fcons (font_spec, fontset), auto_fontset_alist);
1743 font_spec = Ffont_spec (0, NULL);
1744 ASET (font_spec, FONT_REGISTRY_INDEX, registry);
1746 Lisp_Object target = find_font_encoding (SYMBOL_NAME (registry));
1748 if (CONSP (target))
1749 target = XCDR (target);
1750 if (! CHARSETP (target))
1751 target = Qlatin;
1752 Fset_fontset_font (name, target, font_spec, Qnil, Qnil);
1753 Fset_fontset_font (name, Qnil, font_spec, Qnil, Qnil);
1756 set_fontset_ascii (fontset, font_name);
1758 return XINT (FONTSET_ID (fontset));
1762 /* Update auto_fontset_alist for FONTSET. When an ASCII font of
1763 FONTSET is changed, we delete an entry of FONTSET if any from
1764 auto_fontset_alist so that FONTSET is not re-used by
1765 fontset_from_font. */
1767 static void
1768 update_auto_fontset_alist (Lisp_Object font_object, Lisp_Object fontset)
1770 Lisp_Object prev, tail;
1772 for (prev = Qnil, tail = auto_fontset_alist; CONSP (tail);
1773 prev = tail, tail = XCDR (tail))
1774 if (EQ (fontset, XCDR (XCAR (tail))))
1776 if (NILP (prev))
1777 auto_fontset_alist = XCDR (tail);
1778 else
1779 XSETCDR (prev, XCDR (tail));
1780 break;
1785 DEFUN ("fontset-info", Ffontset_info, Sfontset_info, 1, 2, 0,
1786 doc: /* Return information about a fontset FONTSET on frame FRAME.
1788 FONTSET is a fontset name string, nil for the fontset of FRAME, or t
1789 for the default fontset. FRAME nil means the selected frame.
1791 The value is a char-table whose elements have this form:
1793 ((FONT OPENED-FONT ...) ...)
1795 FONT is a name of font specified for a range of characters.
1797 OPENED-FONT is a name of a font actually opened.
1799 The char-table has one extra slot. If FONTSET is not the default
1800 fontset, the value the extra slot is a char-table containing the
1801 information about the derived fonts from the default fontset. The
1802 format is the same as above. */)
1803 (Lisp_Object fontset, Lisp_Object frame)
1805 Lisp_Object *realized[2], fontsets[2], tables[2];
1806 Lisp_Object val, elt;
1807 int c, i, j, k;
1809 check_window_system (NULL);
1810 fontset = check_fontset_name (fontset, &frame);
1812 /* Recode fontsets realized on FRAME from the base fontset FONTSET
1813 in the table `realized'. */
1814 USE_SAFE_ALLOCA;
1815 SAFE_ALLOCA_LISP (realized[0], 2 * ASIZE (Vfontset_table));
1816 realized[1] = realized[0] + ASIZE (Vfontset_table);
1817 for (i = j = 0; i < ASIZE (Vfontset_table); i++)
1819 elt = FONTSET_FROM_ID (i);
1820 if (!NILP (elt)
1821 && EQ (FONTSET_BASE (elt), fontset)
1822 && EQ (FONTSET_FRAME (elt), frame))
1823 realized[0][j++] = elt;
1825 realized[0][j] = Qnil;
1827 for (i = j = 0; ! NILP (realized[0][i]); i++)
1829 elt = FONTSET_DEFAULT (realized[0][i]);
1830 if (! NILP (elt))
1831 realized[1][j++] = elt;
1833 realized[1][j] = Qnil;
1835 tables[0] = Fmake_char_table (Qfontset_info, Qnil);
1836 fontsets[0] = fontset;
1837 if (!EQ (fontset, Vdefault_fontset))
1839 tables[1] = Fmake_char_table (Qnil, Qnil);
1840 set_char_table_extras (tables[0], 0, tables[1]);
1841 fontsets[1] = Vdefault_fontset;
1844 /* Accumulate information of the fontset in TABLE. The format of
1845 each element is ((FONT-SPEC OPENED-FONT ...) ...). */
1846 for (k = 0; k <= 1; k++)
1848 for (c = 0; c <= MAX_CHAR; )
1850 int from = c, to = MAX_5_BYTE_CHAR;
1852 if (c <= MAX_5_BYTE_CHAR)
1854 val = char_table_ref_and_range (fontsets[k], c, &from, &to);
1856 else
1858 val = FONTSET_FALLBACK (fontsets[k]);
1859 to = MAX_CHAR;
1861 if (VECTORP (val))
1863 Lisp_Object alist;
1865 /* At first, set ALIST to ((FONT-SPEC) ...). */
1866 for (alist = Qnil, i = 0; i < ASIZE (val); i++)
1867 if (! NILP (AREF (val, i)))
1868 alist = Fcons (Fcons (FONT_DEF_SPEC (AREF (val, i)), Qnil),
1869 alist);
1870 alist = Fnreverse (alist);
1872 /* Then store opened font names to cdr of each elements. */
1873 for (i = 0; ! NILP (realized[k][i]); i++)
1875 if (c <= MAX_5_BYTE_CHAR)
1876 val = FONTSET_REF (realized[k][i], c);
1877 else
1878 val = FONTSET_FALLBACK (realized[k][i]);
1879 if (! CONSP (val) || ! VECTORP (XCDR (val)))
1880 continue;
1881 /* VAL: (int . [[FACE-ID FONT-DEF FONT-OBJECT int] ... ]) */
1882 val = XCDR (val);
1883 for (j = 0; j < ASIZE (val); j++)
1885 elt = AREF (val, j);
1886 if (!NILP (elt) && FONT_OBJECT_P (RFONT_DEF_OBJECT (elt)))
1888 Lisp_Object font_object = RFONT_DEF_OBJECT (elt);
1889 Lisp_Object slot, name;
1891 slot = Fassq (RFONT_DEF_SPEC (elt), alist);
1892 name = AREF (font_object, FONT_NAME_INDEX);
1893 if (NILP (Fmember (name, XCDR (slot))))
1894 nconc2 (slot, list1 (name));
1899 /* Store ALIST in TBL for characters C..TO. */
1900 if (c <= MAX_5_BYTE_CHAR)
1901 char_table_set_range (tables[k], c, to, alist);
1902 else
1903 set_char_table_defalt (tables[k], alist);
1905 /* At last, change each elements to font names. */
1906 for (; CONSP (alist); alist = XCDR (alist))
1908 elt = XCAR (alist);
1909 XSETCAR (elt, Ffont_xlfd_name (XCAR (elt), Qnil));
1912 c = to + 1;
1914 if (EQ (fontset, Vdefault_fontset))
1915 break;
1918 SAFE_FREE ();
1919 return tables[0];
1923 DEFUN ("fontset-font", Ffontset_font, Sfontset_font, 2, 3, 0,
1924 doc: /* Return a font name pattern for character CH in fontset NAME.
1925 If NAME is t, find a pattern in the default fontset.
1926 If NAME is nil, find a pattern in the fontset of the selected frame.
1928 The value has the form (FAMILY . REGISTRY), where FAMILY is a font
1929 family name and REGISTRY is a font registry name. This is actually
1930 the first font name pattern for CH in the fontset or in the default
1931 fontset.
1933 If the 2nd optional arg ALL is non-nil, return a list of all font name
1934 patterns. */)
1935 (Lisp_Object name, Lisp_Object ch, Lisp_Object all)
1937 int c;
1938 Lisp_Object fontset, elt, list, repertory, val;
1939 int i, j;
1940 Lisp_Object frame;
1942 frame = Qnil;
1943 fontset = check_fontset_name (name, &frame);
1945 CHECK_CHARACTER (ch);
1946 c = XINT (ch);
1947 list = Qnil;
1948 while (1)
1950 for (i = 0, elt = FONTSET_REF (fontset, c); i < 2;
1951 i++, elt = FONTSET_FALLBACK (fontset))
1952 if (VECTORP (elt))
1953 for (j = 0; j < ASIZE (elt); j++)
1955 Lisp_Object family, registry;
1957 val = AREF (elt, j);
1958 if (NILP (val))
1959 return Qnil;
1960 repertory = AREF (val, 1);
1961 if (INTEGERP (repertory))
1963 struct charset *charset = CHARSET_FROM_ID (XINT (repertory));
1965 if (! CHAR_CHARSET_P (c, charset))
1966 continue;
1968 else if (CHAR_TABLE_P (repertory))
1970 if (NILP (CHAR_TABLE_REF (repertory, c)))
1971 continue;
1973 val = AREF (val, 0);
1974 /* VAL is a FONT-SPEC */
1975 family = AREF (val, FONT_FAMILY_INDEX);
1976 if (! NILP (family))
1977 family = SYMBOL_NAME (family);
1978 registry = AREF (val, FONT_REGISTRY_INDEX);
1979 if (! NILP (registry))
1980 registry = SYMBOL_NAME (registry);
1981 val = Fcons (family, registry);
1982 if (NILP (all))
1983 return val;
1984 list = Fcons (val, list);
1986 if (EQ (fontset, Vdefault_fontset))
1987 break;
1988 fontset = Vdefault_fontset;
1990 return (Fnreverse (list));
1993 DEFUN ("fontset-list", Ffontset_list, Sfontset_list, 0, 0, 0,
1994 doc: /* Return a list of all defined fontset names. */)
1995 (void)
1997 Lisp_Object fontset, list;
1998 int i;
2000 list = Qnil;
2001 for (i = 0; i < ASIZE (Vfontset_table); i++)
2003 fontset = FONTSET_FROM_ID (i);
2004 if (!NILP (fontset)
2005 && BASE_FONTSET_P (fontset))
2006 list = Fcons (FONTSET_NAME (fontset), list);
2009 return list;
2013 #ifdef ENABLE_CHECKING
2015 Lisp_Object dump_fontset (Lisp_Object) EXTERNALLY_VISIBLE;
2017 Lisp_Object
2018 dump_fontset (Lisp_Object fontset)
2020 Lisp_Object vec;
2022 vec = Fmake_vector (make_number (3), Qnil);
2023 ASET (vec, 0, FONTSET_ID (fontset));
2025 if (BASE_FONTSET_P (fontset))
2027 ASET (vec, 1, FONTSET_NAME (fontset));
2029 else
2031 Lisp_Object frame;
2033 frame = FONTSET_FRAME (fontset);
2034 if (FRAMEP (frame))
2036 struct frame *f = XFRAME (frame);
2038 if (FRAME_LIVE_P (f))
2039 ASET (vec, 1,
2040 Fcons (FONTSET_NAME (FONTSET_BASE (fontset)),
2041 f->name));
2042 else
2043 ASET (vec, 1,
2044 Fcons (FONTSET_NAME (FONTSET_BASE (fontset)), Qnil));
2046 if (!NILP (FONTSET_DEFAULT (fontset)))
2047 ASET (vec, 2, FONTSET_ID (FONTSET_DEFAULT (fontset)));
2049 return vec;
2052 DEFUN ("fontset-list-all", Ffontset_list_all, Sfontset_list_all, 0, 0, 0,
2053 doc: /* Return a brief summary of all fontsets for debug use. */)
2054 (void)
2056 Lisp_Object val;
2057 int i;
2059 for (i = 0, val = Qnil; i < ASIZE (Vfontset_table); i++)
2060 if (! NILP (AREF (Vfontset_table, i)))
2061 val = Fcons (dump_fontset (AREF (Vfontset_table, i)), val);
2062 return (Fnreverse (val));
2064 #endif /* ENABLE_CHECKING */
2066 void
2067 syms_of_fontset (void)
2069 DEFSYM (Qfontset, "fontset");
2070 Fput (Qfontset, Qchar_table_extra_slots, make_number (8));
2071 DEFSYM (Qfontset_info, "fontset-info");
2072 Fput (Qfontset_info, Qchar_table_extra_slots, make_number (1));
2074 DEFSYM (Qappend, "append");
2075 DEFSYM (Qlatin, "latin");
2077 Vcached_fontset_data = Qnil;
2078 staticpro (&Vcached_fontset_data);
2080 Vfontset_table = Fmake_vector (make_number (32), Qnil);
2081 staticpro (&Vfontset_table);
2083 Vdefault_fontset = Fmake_char_table (Qfontset, Qnil);
2084 staticpro (&Vdefault_fontset);
2085 set_fontset_id (Vdefault_fontset, make_number (0));
2086 set_fontset_name
2087 (Vdefault_fontset,
2088 build_pure_c_string ("-*-*-*-*-*-*-*-*-*-*-*-*-fontset-default"));
2089 ASET (Vfontset_table, 0, Vdefault_fontset);
2090 next_fontset_id = 1;
2092 auto_fontset_alist = Qnil;
2093 staticpro (&auto_fontset_alist);
2095 DEFVAR_LISP ("font-encoding-charset-alist", Vfont_encoding_charset_alist,
2096 doc: /*
2097 Alist of charsets vs the charsets to determine the preferred font encoding.
2098 Each element looks like (CHARSET . ENCODING-CHARSET),
2099 where ENCODING-CHARSET is a charset registered in the variable
2100 `font-encoding-alist' as ENCODING.
2102 When a text has a property `charset' and the value is CHARSET, a font
2103 whose encoding corresponds to ENCODING-CHARSET is preferred. */);
2104 Vfont_encoding_charset_alist = Qnil;
2106 DEFVAR_LISP ("use-default-ascent", Vuse_default_ascent,
2107 doc: /*
2108 Char table of characters whose ascent values should be ignored.
2109 If an entry for a character is non-nil, the ascent value of the glyph
2110 is assumed to be specified by _MULE_DEFAULT_ASCENT property of a font.
2112 This affects how a composite character which contains
2113 such a character is displayed on screen. */);
2114 Vuse_default_ascent = Qnil;
2116 DEFVAR_BOOL ("use-default-font-for-symbols", use_default_font_for_symbols,
2117 doc: /*
2118 If non-nil, use the default face's font for symbols and punctuation.
2120 By default, Emacs will try to use the default face's font for
2121 displaying symbol and punctuation characters, disregarding the
2122 fontsets, if the default font can display the character.
2123 Set this to nil to make Emacs honor the fontsets instead. */);
2124 use_default_font_for_symbols = 1;
2126 DEFVAR_LISP ("ignore-relative-composition", Vignore_relative_composition,
2127 doc: /*
2128 Char table of characters which are not composed relatively.
2129 If an entry for a character is non-nil, a composition sequence
2130 which contains that character is displayed so that
2131 the glyph of that character is put without considering
2132 an ascent and descent value of a previous character. */);
2133 Vignore_relative_composition = Qnil;
2135 DEFVAR_LISP ("alternate-fontname-alist", Valternate_fontname_alist,
2136 doc: /* Alist of fontname vs list of the alternate fontnames.
2137 When a specified font name is not found, the corresponding
2138 alternate fontnames (if any) are tried instead. */);
2139 Valternate_fontname_alist = Qnil;
2141 DEFVAR_LISP ("fontset-alias-alist", Vfontset_alias_alist,
2142 doc: /* Alist of fontset names vs the aliases. */);
2143 Vfontset_alias_alist
2144 = list1 (Fcons (FONTSET_NAME (Vdefault_fontset),
2145 build_pure_c_string ("fontset-default")));
2147 DEFVAR_LISP ("vertical-centering-font-regexp",
2148 Vvertical_centering_font_regexp,
2149 doc: /* Regexp matching font names that require vertical centering on display.
2150 When a character is displayed with such fonts, the character is displayed
2151 at the vertical center of lines. */);
2152 Vvertical_centering_font_regexp = Qnil;
2154 DEFVAR_LISP ("otf-script-alist", Votf_script_alist,
2155 doc: /* Alist of OpenType script tags vs the corresponding script names. */);
2156 Votf_script_alist = Qnil;
2158 defsubr (&Squery_fontset);
2159 defsubr (&Snew_fontset);
2160 defsubr (&Sset_fontset_font);
2161 defsubr (&Sfontset_info);
2162 defsubr (&Sfontset_font);
2163 defsubr (&Sfontset_list);
2164 #ifdef ENABLE_CHECKING
2165 defsubr (&Sfontset_list_all);
2166 #endif