(add_font_entity_to_list): Allow non-opentype truetype fonts back
[emacs.git] / src / fontset.c
blobf8c867a6e26441f53fd33293a366d08df65fc8e0
1 /* Fontset handler.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
3 Free Software Foundation, Inc.
4 Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5 2005, 2006, 2007, 2008
6 National Institute of Advanced Industrial Science and Technology (AIST)
7 Registration Number H14PRO021
8 Copyright (C) 2003, 2006
9 National Institute of Advanced Industrial Science and Technology (AIST)
10 Registration Number H13PRO009
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
17 (at 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 /* #define FONTSET_DEBUG */
29 #include <config.h>
31 #ifdef FONTSET_DEBUG
32 #include <stdio.h>
33 #endif
35 #include "lisp.h"
36 #include "blockinput.h"
37 #include "buffer.h"
38 #include "character.h"
39 #include "charset.h"
40 #include "ccl.h"
41 #include "keyboard.h"
42 #include "frame.h"
43 #include "dispextern.h"
44 #include "intervals.h"
45 #include "fontset.h"
46 #include "window.h"
47 #ifdef HAVE_X_WINDOWS
48 #include "xterm.h"
49 #endif
50 #ifdef WINDOWSNT
51 #include "w32term.h"
52 #endif
53 #ifdef MAC_OS
54 #include "macterm.h"
55 #endif
56 #include "termhooks.h"
58 #include "font.h"
60 #undef xassert
61 #ifdef FONTSET_DEBUG
62 #define xassert(X) do {if (!(X)) abort ();} while (0)
63 #undef INLINE
64 #define INLINE
65 #else /* not FONTSET_DEBUG */
66 #define xassert(X) (void) 0
67 #endif /* not FONTSET_DEBUG */
69 EXFUN (Fclear_face_cache, 1);
71 /* FONTSET
73 A fontset is a collection of font related information to give
74 similar appearance (style, etc) of characters. A fontset has two
75 roles. One is to use for the frame parameter `font' as if it is an
76 ASCII font. In that case, Emacs uses the font specified for
77 `ascii' script for the frame's default font.
79 Another role, the more important one, is to provide information
80 about which font to use for each non-ASCII character.
82 There are two kinds of fontsets; base and realized. A base fontset
83 is created by `new-fontset' from Emacs Lisp explicitly. A realized
84 fontset is created implicitly when a face is realized for ASCII
85 characters. A face is also realized for non-ASCII characters based
86 on an ASCII face. All of non-ASCII faces based on the same ASCII
87 face share the same realized fontset.
89 A fontset object is implemented by a char-table whose default value
90 and parent are always nil.
92 An element of a base fontset is a vector of FONT-DEFs which itself
93 is a vector [ FONT-SPEC ENCODING REPERTORY ].
95 An element of a realized fontset is nil, t, or a vector of this form:
97 [ CHARSET-ORDERED-LIST-TICK PREFERRED-RFONT-DEF
98 RFONT-DEF0 RFONT-DEF1 ... ]
100 RFONT-DEFn (i.e. Realized FONT-DEF) has this form:
102 [ FACE-ID FONT-DEF FONT-OBJECT SORTING-SCORE ]
104 RFONT-DEFn are automatically reordered by the current charset
105 priority list.
107 The value nil means that we have not yet generated the above vector
108 from the base of the fontset.
110 The value t means that no font is available for the corresponding
111 range of characters.
114 A fontset has 9 extra slots.
116 The 1st slot: the ID number of the fontset
118 The 2nd slot:
119 base: the name of the fontset
120 realized: nil
122 The 3rd slot:
123 base: nil
124 realized: the base fontset
126 The 4th slot:
127 base: nil
128 realized: the frame that the fontset belongs to
130 The 5th slot:
131 base: the font name for ASCII characters
132 realized: nil
134 The 6th slot:
135 base: nil
136 realized: the ID number of a face to use for characters that
137 has no font in a realized fontset.
139 The 7th slot:
140 base: nil
141 realized: Alist of font index vs the corresponding repertory
142 char-table.
144 The 8th slot:
145 base: nil
146 realized: If the base is not the default fontset, a fontset
147 realized from the default fontset, else nil.
149 The 9th slot:
150 base: Same as element value (but for fallback fonts).
151 realized: Likewise.
153 All fontsets are recorded in the vector Vfontset_table.
156 DEFAULT FONTSET
158 There's a special base fontset named `default fontset' which
159 defines the default font specifications. When a base fontset
160 doesn't specify a font for a specific character, the corresponding
161 value in the default fontset is used.
163 The parent of a realized fontset created for such a face that has
164 no fontset is the default fontset.
167 These structures are hidden from the other codes than this file.
168 The other codes handle fontsets only by their ID numbers. They
169 usually use the variable name `fontset' for IDs. But, in this
170 file, we always use varialbe name `id' for IDs, and name `fontset'
171 for an actual fontset object, i.e., char-table.
175 /********** VARIABLES and FUNCTION PROTOTYPES **********/
177 extern Lisp_Object Qfont;
178 static Lisp_Object Qfontset;
179 static Lisp_Object Qfontset_info;
180 static Lisp_Object Qprepend, Qappend;
181 static Lisp_Object Qlatin;
183 /* Vector containing all fontsets. */
184 static Lisp_Object Vfontset_table;
186 /* Next possibly free fontset ID. Usually this keeps the minimum
187 fontset ID not yet used. */
188 static int next_fontset_id;
190 /* The default fontset. This gives default FAMILY and REGISTRY of
191 font for each character. */
192 static Lisp_Object Vdefault_fontset;
194 Lisp_Object Vfont_encoding_charset_alist;
195 Lisp_Object Vuse_default_ascent;
196 Lisp_Object Vignore_relative_composition;
197 Lisp_Object Valternate_fontname_alist;
198 Lisp_Object Vfontset_alias_alist;
199 Lisp_Object Vvertical_centering_font_regexp;
200 Lisp_Object Votf_script_alist;
202 /* Check if any window system is used now. */
203 void (*check_window_system_func) P_ ((void));
206 /* Prototype declarations for static functions. */
207 static Lisp_Object fontset_add P_ ((Lisp_Object, Lisp_Object, Lisp_Object,
208 Lisp_Object));
209 static Lisp_Object fontset_find_font P_ ((Lisp_Object, int, struct face *,
210 int, int));
211 static void reorder_font_vector P_ ((Lisp_Object, Lisp_Object));
212 static Lisp_Object fontset_font P_ ((Lisp_Object, int, struct face *, int));
213 static Lisp_Object make_fontset P_ ((Lisp_Object, Lisp_Object, Lisp_Object));
214 static Lisp_Object fontset_pattern_regexp P_ ((Lisp_Object));
215 static void accumulate_script_ranges P_ ((Lisp_Object, Lisp_Object,
216 Lisp_Object));
217 Lisp_Object find_font_encoding P_ ((Lisp_Object));
219 static void set_fontset_font P_ ((Lisp_Object, Lisp_Object));
221 #ifdef FONTSET_DEBUG
223 /* Return 1 if ID is a valid fontset id, else return 0. */
225 static int
226 fontset_id_valid_p (id)
227 int id;
229 return (id >= 0 && id < ASIZE (Vfontset_table) - 1);
232 #endif
236 /********** MACROS AND FUNCTIONS TO HANDLE FONTSET **********/
238 /* Return the fontset with ID. No check of ID's validness. */
239 #define FONTSET_FROM_ID(id) AREF (Vfontset_table, id)
241 /* Macros to access special values of FONTSET. */
242 #define FONTSET_ID(fontset) XCHAR_TABLE (fontset)->extras[0]
244 /* Macros to access special values of (base) FONTSET. */
245 #define FONTSET_NAME(fontset) XCHAR_TABLE (fontset)->extras[1]
246 #define FONTSET_ASCII(fontset) XCHAR_TABLE (fontset)->extras[4]
247 #define FONTSET_SPEC(fontset) XCHAR_TABLE (fontset)->extras[5]
249 /* Macros to access special values of (realized) FONTSET. */
250 #define FONTSET_BASE(fontset) XCHAR_TABLE (fontset)->extras[2]
251 #define FONTSET_FRAME(fontset) XCHAR_TABLE (fontset)->extras[3]
252 #define FONTSET_OBJLIST(fontset) XCHAR_TABLE (fontset)->extras[4]
253 #define FONTSET_NOFONT_FACE(fontset) XCHAR_TABLE (fontset)->extras[5]
254 #define FONTSET_REPERTORY(fontset) XCHAR_TABLE (fontset)->extras[6]
255 #define FONTSET_DEFAULT(fontset) XCHAR_TABLE (fontset)->extras[7]
257 /* For both base and realized fontset. */
258 #define FONTSET_FALLBACK(fontset) XCHAR_TABLE (fontset)->extras[8]
260 #define BASE_FONTSET_P(fontset) (NILP (FONTSET_BASE (fontset)))
263 /* Macros for FONT-DEF and RFONT-DEF of fontset. */
264 #define FONT_DEF_NEW(font_def, font_spec, encoding, repertory) \
265 do { \
266 (font_def) = Fmake_vector (make_number (3), (font_spec)); \
267 ASET ((font_def), 1, encoding); \
268 ASET ((font_def), 2, repertory); \
269 } while (0)
271 #define FONT_DEF_SPEC(font_def) AREF (font_def, 0)
272 #define FONT_DEF_ENCODING(font_def) AREF (font_def, 1)
273 #define FONT_DEF_REPERTORY(font_def) AREF (font_def, 2)
275 #define RFONT_DEF_FACE(rfont_def) AREF (rfont_def, 0)
276 #define RFONT_DEF_SET_FACE(rfont_def, face_id) \
277 ASET ((rfont_def), 0, make_number (face_id))
278 #define RFONT_DEF_FONT_DEF(rfont_def) AREF (rfont_def, 1)
279 #define RFONT_DEF_SPEC(rfont_def) FONT_DEF_SPEC (AREF (rfont_def, 1))
280 #define RFONT_DEF_REPERTORY(rfont_def) FONT_DEF_REPERTORY (AREF (rfont_def, 1))
281 #define RFONT_DEF_OBJECT(rfont_def) AREF (rfont_def, 2)
282 #define RFONT_DEF_SET_OBJECT(rfont_def, object) \
283 ASET ((rfont_def), 2, (object))
284 #define RFONT_DEF_SCORE(rfont_def) XINT (AREF (rfont_def, 3))
285 #define RFONT_DEF_SET_SCORE(rfont_def, score) \
286 ASET ((rfont_def), 3, make_number (score))
287 #define RFONT_DEF_NEW(rfont_def, font_def) \
288 do { \
289 (rfont_def) = Fmake_vector (make_number (4), Qnil); \
290 ASET ((rfont_def), 1, (font_def)); \
291 RFONT_DEF_SET_SCORE ((rfont_def), 0); \
292 } while (0)
295 /* Return the element of FONTSET for the character C. If FONTSET is a
296 base fontset other then the default fontset and FONTSET doesn't
297 contain information for C, return the information in the default
298 fontset. */
300 #define FONTSET_REF(fontset, c) \
301 (EQ (fontset, Vdefault_fontset) \
302 ? CHAR_TABLE_REF (fontset, c) \
303 : fontset_ref ((fontset), (c)))
305 static Lisp_Object
306 fontset_ref (fontset, c)
307 Lisp_Object fontset;
308 int c;
310 Lisp_Object elt;
312 elt = CHAR_TABLE_REF (fontset, c);
313 if (NILP (elt) && ! EQ (fontset, Vdefault_fontset)
314 /* Don't check Vdefault_fontset for a realized fontset. */
315 && NILP (FONTSET_BASE (fontset)))
316 elt = CHAR_TABLE_REF (Vdefault_fontset, c);
317 return elt;
320 /* Set elements of FONTSET for characters in RANGE to the value ELT.
321 RANGE is a cons (FROM . TO), where FROM and TO are character codes
322 specifying a range. */
324 #define FONTSET_SET(fontset, range, elt) \
325 Fset_char_table_range ((fontset), (range), (elt))
328 /* Modify the elements of FONTSET for characters in RANGE by replacing
329 with ELT or adding ELT. RANGE is a cons (FROM . TO), where FROM
330 and TO are character codes specifying a range. If ADD is nil,
331 replace with ELT, if ADD is `prepend', prepend ELT, otherwise,
332 append ELT. */
334 #define FONTSET_ADD(fontset, range, elt, add) \
335 (NILP (add) \
336 ? (NILP (range) \
337 ? (FONTSET_FALLBACK (fontset) = Fmake_vector (make_number (1), (elt))) \
338 : Fset_char_table_range ((fontset), (range), \
339 Fmake_vector (make_number (1), (elt)))) \
340 : fontset_add ((fontset), (range), (elt), (add)))
342 static Lisp_Object
343 fontset_add (fontset, range, elt, add)
344 Lisp_Object fontset, range, elt, add;
346 Lisp_Object args[2];
347 int idx = (EQ (add, Qappend) ? 0 : 1);
349 args[1 - idx] = Fmake_vector (make_number (1), elt);
351 if (CONSP (range))
353 int from = XINT (XCAR (range));
354 int to = XINT (XCDR (range));
355 int from1, to1;
357 do {
358 args[idx] = char_table_ref_and_range (fontset, from, &from1, &to1);
359 if (to < to1)
360 to1 = to;
361 char_table_set_range (fontset, from, to1,
362 NILP (args[idx]) ? args[1 - idx]
363 : Fvconcat (2, args));
364 from = to1 + 1;
365 } while (from < to);
367 else
369 args[idx] = FONTSET_FALLBACK (fontset);
370 FONTSET_FALLBACK (fontset)
371 = NILP (args[idx]) ? args[1 - idx] : Fvconcat (2, args);
373 return Qnil;
376 static int
377 fontset_compare_rfontdef (val1, val2)
378 const void *val1, *val2;
380 return (RFONT_DEF_SCORE (*(Lisp_Object *) val2)
381 - RFONT_DEF_SCORE (*(Lisp_Object *) val1));
384 /* Update FONT-GROUP which has this form:
385 [ CHARSET-ORDERED-LIST-TICK PREFERRED-RFONT-DEF
386 RFONT-DEF0 RFONT-DEF1 ... ]
387 Reorder RFONT-DEFs according to the current language, and update
388 CHARSET-ORDERED-LIST-TICK.
390 If PREFERRED_FAMILY is not nil, that family has the higher priority
391 if the encoding charsets or languages in font-specs are the same. */
393 extern Lisp_Object Fassoc_string ();
395 static void
396 reorder_font_vector (font_group, preferred_family)
397 Lisp_Object font_group;
398 Lisp_Object preferred_family;
400 int size;
401 int i;
402 int score_changed = 0;
404 size = ASIZE (font_group);
405 /* Exclude the tailing nil elements from the reordering. */
406 while (NILP (AREF (font_group, size - 1))) size--;
407 size -= 2;
409 for (i = 0; i < size; i++)
411 Lisp_Object rfont_def = AREF (font_group, i + 2);
412 Lisp_Object font_def = RFONT_DEF_FONT_DEF (rfont_def);
413 Lisp_Object font_spec = FONT_DEF_SPEC (font_def);
414 Lisp_Object lang = Ffont_get (font_spec, QClang);
415 Lisp_Object family = AREF (font_spec, FONT_FAMILY_INDEX);
416 Lisp_Object repertory = FONT_DEF_REPERTORY (font_def);
417 int score = 0;
419 if (! NILP (repertory))
421 Lisp_Object tail;
423 for (score = 0xFFFF, tail = Vcharset_ordered_list;
424 ! EQ (tail, Vcharset_non_preferred_head) && CONSP (tail);
425 score--, tail = XCDR (tail))
426 if (EQ (repertory, XCAR (tail)))
427 break;
428 if (EQ (tail, Vcharset_non_preferred_head))
429 score = 0;
431 else if (! NILP (lang))
433 if (EQ (lang, Vcurrent_iso639_language))
434 score = 0xFFFF;
435 else if (CONSP (Vcurrent_iso639_language))
436 score = ! NILP (Fmemq (lang, Vcurrent_iso639_language));
439 if (! NILP (preferred_family) && ! NILP (family))
441 if (fast_string_match_ignore_case (preferred_family,
442 SYMBOL_NAME (family)) < 0)
443 score |= 0x10000;
445 if (RFONT_DEF_SCORE (rfont_def) != score)
447 RFONT_DEF_SET_SCORE (rfont_def, score);
448 score_changed = 1;
452 if (score_changed)
453 qsort (XVECTOR (font_group)->contents + 2, size, sizeof (Lisp_Object),
454 fontset_compare_rfontdef);
456 ASET (font_group, 0, make_number (charset_ordered_list_tick));
459 /* Return RFONT-DEF (vector) in the realized fontset FONTSET for the
460 character C. If no font is found, return Qnil if there's a
461 possibility that the default fontset or the fallback font groups
462 have a proper font, and return Qt if not.
464 If a font is found but is not yet opened, open it (if FACE is not
465 NULL) or return Qnil (if FACE is NULL).
467 ID is a charset-id that must be preferred, or -1 meaning no
468 preference.
470 If FALLBACK is nonzero, search only fallback fonts. */
472 static Lisp_Object
473 fontset_find_font (fontset, c, face, id, fallback)
474 Lisp_Object fontset;
475 int c;
476 struct face *face;
477 int id, fallback;
479 Lisp_Object base_fontset, elt, vec;
480 int i, from, to;
481 FRAME_PTR f = XFRAME (FONTSET_FRAME (fontset));
483 base_fontset = FONTSET_BASE (fontset);
484 if (! fallback)
485 vec = CHAR_TABLE_REF (fontset, c);
486 else
487 vec = FONTSET_FALLBACK (fontset);
489 if (NILP (vec))
491 Lisp_Object range;
493 /* We have not yet decided a font for C. */
494 if (! face)
495 return Qnil;
496 if (! fallback)
498 elt = char_table_ref_and_range (base_fontset, c, &from, &to);
499 range = Fcons (make_number (from), make_number (to));
501 else
503 elt = FONTSET_FALLBACK (base_fontset);
505 if (NILP (elt))
507 /* This fontset doesn't specify any font for C. */
508 vec = make_number (0);
510 else if (ASIZE (elt) == 1 && NILP (AREF (elt, 0)))
512 /* Explicitly specified no font. */
513 vec = Qt;
515 else
517 /* Build a font-group vector [ -1 nil RFONT-DEF0 RFONT-DEF1 ... ],
518 where the first -1 is to force reordering of RFONT-DEFs. */
519 int size = ASIZE (elt);
520 int j;
522 vec = Fmake_vector (make_number (size + 2), Qnil);
523 ASET (vec, 0, make_number (-1));
524 for (i = j = 0; i < size; i++)
525 if (! NILP (AREF (elt, i)))
527 Lisp_Object rfont_def;
529 RFONT_DEF_NEW (rfont_def, AREF (elt, i));
530 ASET (vec, j + 2, rfont_def);
531 j++;
534 /* Then store it in the fontset. */
535 if (! fallback)
536 FONTSET_SET (fontset, range, vec);
537 else
538 FONTSET_FALLBACK (fontset) = vec;
541 if (! VECTORP (vec))
542 return (EQ (vec, Qt) ? Qt : Qnil);
544 if (ASIZE (vec) > 4 /* multiple RFONT-DEFs */
545 && XINT (AREF (vec, 0)) != charset_ordered_list_tick)
546 /* We have just created VEC,
547 or the charset priorities were changed. */
548 reorder_font_vector (vec, face->lface[LFACE_FAMILY_INDEX]);
549 i = 2;
550 if (id >= 0)
552 elt = AREF (vec, 1);
553 if (! NILP (elt)
554 && EQ (make_number (id), RFONT_DEF_REPERTORY (elt)))
555 i = 1;
556 else
558 for (; i < ASIZE (vec); i++)
560 elt = AREF (vec, i);
561 if (! NILP (elt)
562 && EQ (make_number (id), RFONT_DEF_REPERTORY (elt)))
563 break;
565 if (i < ASIZE (vec))
567 ASET (vec, 1, elt);
568 i = 1;
570 else
572 ASET (vec, 1, Qnil);
573 i = 2;
578 /* Find the first available font in the vector of RFONT-DEF. */
579 for (; i < ASIZE (vec); i++)
581 Lisp_Object font_entity, font_object;
583 elt = AREF (vec, i);
584 if (NILP (elt))
585 /* This is the sign of not to try fallback fonts. */
586 return Qt;
587 if (id >= 0 && i > 1 && EQ (AREF (vec, 1), elt))
588 /* This is already checked. */
589 continue;
590 if (INTEGERP (RFONT_DEF_FACE (elt))
591 && XINT (AREF (elt, 1)) < 0)
592 /* We couldn't open this font last time. */
593 continue;
595 font_object = RFONT_DEF_OBJECT (elt);
596 if (NILP (font_object))
598 Lisp_Object font_def = RFONT_DEF_FONT_DEF (elt);
600 if (! face)
601 /* We have not yet opened the font. */
602 return Qnil;
603 font_entity = font_find_for_lface (f, face->lface,
604 FONT_DEF_SPEC (font_def), -1);
605 if (NILP (font_entity))
607 /* Record that no font matches the spec. */
608 RFONT_DEF_SET_FACE (elt, -1);
609 continue;
611 font_object = font_open_for_lface (f, font_entity, face->lface, Qnil);
612 if (NILP (font_object))
614 /* Record that the font is unsable. */
615 RFONT_DEF_SET_FACE (elt, -1);
616 continue;
618 RFONT_DEF_SET_OBJECT (elt, font_object);
621 if (font_has_char (f, font_object, c))
622 return elt;
624 #if 0
625 /* The following code makes Emacs to find a font for C by fairly
626 exhausitive search. But, that takes long time especially for
627 X font backend. */
629 /* Try to find the different font maching with the current spec
630 and support C. */
631 font_def = RFONT_DEF_FONT_DEF (elt);
632 for (i++; i < ASIZE (vec); i++)
634 if (! EQ (RFONT_DEF_FONT_DEF (AREF (vec, i)), font_def))
635 break;
636 if (font_has_char (f, RFONT_DEF_OBJECT (AREF (vec, i)), c))
637 return AREF (vec, i);
639 /* Find an font-entity that support C. */
640 font_entity = font_find_for_lface (f, face->lface,
641 FONT_DEF_SPEC (font_def), c);
642 if (! NILP (font_entity))
644 Lisp_Object rfont_def, new_vec;
645 int j;
647 font_object = font_open_for_lface (f, font_entity, face->lface,
648 Qnil);
649 RFONT_DEF_NEW (rfont_def, font_def);
650 RFONT_DEF_SET_OBJECT (rfont_def, font_object);
651 RFONT_DEF_SET_SCORE (rfont_def, RFONT_DEF_SCORE (elt));
652 new_vec = Fmake_vector (make_number (ASIZE (vec) + 1), Qnil);
653 for (j = 0; j < i; j++)
654 ASET (new_vec, j, AREF (vec, j));
655 ASET (new_vec, j, rfont_def);
656 for (j++; j < ASIZE (new_vec); j++)
657 ASET (new_vec, j, AREF (vec, j - 1));
658 vec = new_vec;
659 return rfont_def;
661 i--;
662 #endif /* 0 */
665 FONTSET_SET (fontset, make_number (c), make_number (0));
666 return Qnil;
670 static Lisp_Object
671 fontset_font (fontset, c, face, id)
672 Lisp_Object fontset;
673 int c;
674 struct face *face;
675 int id;
677 Lisp_Object rfont_def;
678 Lisp_Object base_fontset;
680 /* Try a font-group for C. */
681 rfont_def = fontset_find_font (fontset, c, face, id, 0);
682 if (VECTORP (rfont_def))
683 return rfont_def;
684 if (EQ (rfont_def, Qt))
685 return Qnil;
686 /* Try a fallback font-group. */
687 rfont_def = fontset_find_font (fontset, c, face, id, 1);
688 if (VECTORP (rfont_def))
689 return rfont_def;
690 if (EQ (rfont_def, Qt))
691 return Qnil;
693 base_fontset = FONTSET_BASE (fontset);
694 if (EQ (base_fontset, Vdefault_fontset))
695 return Qnil;
697 /* Try a font-group for C of the default fontset. */
698 if (NILP (FONTSET_DEFAULT (fontset)))
699 FONTSET_DEFAULT (fontset)
700 = make_fontset (FONTSET_FRAME (fontset), Qnil, Vdefault_fontset);
701 rfont_def = fontset_find_font (FONTSET_DEFAULT (fontset), c, face, id, 0);
702 if (VECTORP (rfont_def))
703 return rfont_def;
704 /* Try a fallback font-group of the default fontset . */
705 rfont_def = fontset_find_font (FONTSET_DEFAULT (fontset), c, face, id, 1);
706 if (! VECTORP (rfont_def))
707 /* Remeber that we have no font for C. */
708 FONTSET_SET (fontset, make_number (c), Qt);
710 return rfont_def;
713 /* Return a newly created fontset with NAME. If BASE is nil, make a
714 base fontset. Otherwise make a realized fontset whose base is
715 BASE. */
717 static Lisp_Object
718 make_fontset (frame, name, base)
719 Lisp_Object frame, name, base;
721 Lisp_Object fontset;
722 int size = ASIZE (Vfontset_table);
723 int id = next_fontset_id;
725 /* Find a free slot in Vfontset_table. Usually, next_fontset_id is
726 the next available fontset ID. So it is expected that this loop
727 terminates quickly. In addition, as the last element of
728 Vfontset_table is always nil, we don't have to check the range of
729 id. */
730 while (!NILP (AREF (Vfontset_table, id))) id++;
732 if (id + 1 == size)
733 Vfontset_table = larger_vector (Vfontset_table, size + 32, Qnil);
735 fontset = Fmake_char_table (Qfontset, Qnil);
737 FONTSET_ID (fontset) = make_number (id);
738 if (NILP (base))
740 FONTSET_NAME (fontset) = name;
742 else
744 FONTSET_NAME (fontset) = Qnil;
745 FONTSET_FRAME (fontset) = frame;
746 FONTSET_BASE (fontset) = base;
749 ASET (Vfontset_table, id, fontset);
750 next_fontset_id = id + 1;
751 return fontset;
755 /* Set the ASCII font of the default fontset to FONTNAME if that is
756 not yet set. */
757 void
758 set_default_ascii_font (fontname)
759 Lisp_Object fontname;
761 if (! STRINGP (FONTSET_ASCII (Vdefault_fontset)))
763 int id = fs_query_fontset (fontname, 2);
765 if (id >= 0)
766 fontname = FONTSET_ASCII (FONTSET_FROM_ID (id));
767 FONTSET_ASCII (Vdefault_fontset)= fontname;
772 /********** INTERFACES TO xfaces.c, xfns.c, and dispextern.h **********/
774 /* Return the name of the fontset who has ID. */
776 Lisp_Object
777 fontset_name (id)
778 int id;
780 Lisp_Object fontset;
782 fontset = FONTSET_FROM_ID (id);
783 return FONTSET_NAME (fontset);
787 /* Return the ASCII font name of the fontset who has ID. */
789 Lisp_Object
790 fontset_ascii (id)
791 int id;
793 Lisp_Object fontset, elt;
795 fontset= FONTSET_FROM_ID (id);
796 elt = FONTSET_ASCII (fontset);
797 if (CONSP (elt))
798 elt = XCAR (elt);
799 return elt;
802 void
803 free_realized_fontset (f, fontset)
804 FRAME_PTR f;
805 Lisp_Object fontset;
807 Lisp_Object tail;
809 return;
810 for (tail = FONTSET_OBJLIST (fontset); CONSP (tail); tail = XCDR (tail))
812 xassert (FONT_OBJECT_P (XCAR (tail)));
813 font_close_object (f, XCAR (tail));
817 /* Free fontset of FACE defined on frame F. Called from
818 free_realized_face. */
820 void
821 free_face_fontset (f, face)
822 FRAME_PTR f;
823 struct face *face;
825 Lisp_Object fontset;
827 fontset = FONTSET_FROM_ID (face->fontset);
828 if (NILP (fontset))
829 return;
830 xassert (! BASE_FONTSET_P (fontset));
831 xassert (f == XFRAME (FONTSET_FRAME (fontset)));
832 free_realized_fontset (f, fontset);
833 ASET (Vfontset_table, face->fontset, Qnil);
834 if (face->fontset < next_fontset_id)
835 next_fontset_id = face->fontset;
836 if (! NILP (FONTSET_DEFAULT (fontset)))
838 int id = XINT (FONTSET_ID (FONTSET_DEFAULT (fontset)));
840 fontset = AREF (Vfontset_table, id);
841 xassert (!NILP (fontset) && ! BASE_FONTSET_P (fontset));
842 xassert (f == XFRAME (FONTSET_FRAME (fontset)));
843 free_realized_fontset (f, fontset);
844 ASET (Vfontset_table, id, Qnil);
845 if (id < next_fontset_id)
846 next_fontset_id = face->fontset;
848 face->fontset = -1;
852 /* Return 1 if FACE is suitable for displaying character C.
853 Otherwise return 0. Called from the macro FACE_SUITABLE_FOR_CHAR_P
854 when C is not an ASCII character. */
857 face_suitable_for_char_p (face, c)
858 struct face *face;
859 int c;
861 Lisp_Object fontset, rfont_def;
863 fontset = FONTSET_FROM_ID (face->fontset);
864 rfont_def = fontset_font (fontset, c, NULL, -1);
865 return (VECTORP (rfont_def)
866 && INTEGERP (RFONT_DEF_FACE (rfont_def))
867 && face->id == XINT (RFONT_DEF_FACE (rfont_def)));
871 /* Return ID of face suitable for displaying character C on frame F.
872 FACE must be reazlied for ASCII characters in advance. Called from
873 the macro FACE_FOR_CHAR. */
876 face_for_char (f, face, c, pos, object)
877 FRAME_PTR f;
878 struct face *face;
879 int c, pos;
880 Lisp_Object object;
882 Lisp_Object fontset, rfont_def;
883 int face_id;
884 int id;
886 if (ASCII_CHAR_P (c))
887 return face->ascii_face->id;
889 xassert (fontset_id_valid_p (face->fontset));
890 fontset = FONTSET_FROM_ID (face->fontset);
891 xassert (!BASE_FONTSET_P (fontset));
892 if (pos < 0)
893 id = -1;
894 else
896 Lisp_Object charset;
898 charset = Fget_char_property (make_number (pos), Qcharset, object);
899 if (NILP (charset))
900 id = -1;
901 else if (CHARSETP (charset))
903 Lisp_Object val;
905 val = assoc_no_quit (charset, Vfont_encoding_charset_alist);
906 if (CONSP (val) && CHARSETP (XCDR (val)))
907 charset = XCDR (val);
908 id = XINT (CHARSET_SYMBOL_ID (charset));
911 if (id < 0)
913 struct font *font = face->ascii_face->font;
915 if (font && font->driver->encode_char (font, c) != FONT_INVALID_CODE)
916 return face->ascii_face->id;
917 font = face->font;
918 if (font && font->driver->encode_char (font, c) != FONT_INVALID_CODE)
919 return face->id;
922 rfont_def = fontset_font (fontset, c, face, id);
923 if (VECTORP (rfont_def))
925 if (INTEGERP (RFONT_DEF_FACE (rfont_def)))
926 face_id = XINT (RFONT_DEF_FACE (rfont_def));
927 else
929 Lisp_Object font_object;
931 font_object = RFONT_DEF_OBJECT (rfont_def);
932 face_id = face_for_font (f, font_object, face);
933 RFONT_DEF_SET_FACE (rfont_def, face_id);
936 else
938 if (INTEGERP (FONTSET_NOFONT_FACE (fontset)))
939 face_id = XINT (FONTSET_NOFONT_FACE (fontset));
940 else
942 face_id = face_for_font (f, Qnil, face);
943 FONTSET_NOFONT_FACE (fontset) = make_number (face_id);
946 xassert (face_id >= 0);
947 return face_id;
951 /* Make a realized fontset for ASCII face FACE on frame F from the
952 base fontset BASE_FONTSET_ID. If BASE_FONTSET_ID is -1, use the
953 default fontset as the base. Value is the id of the new fontset.
954 Called from realize_x_face. */
957 make_fontset_for_ascii_face (f, base_fontset_id, face)
958 FRAME_PTR f;
959 int base_fontset_id;
960 struct face *face;
962 Lisp_Object base_fontset, fontset, frame;
964 XSETFRAME (frame, f);
965 if (base_fontset_id >= 0)
967 base_fontset = FONTSET_FROM_ID (base_fontset_id);
968 if (!BASE_FONTSET_P (base_fontset))
969 base_fontset = FONTSET_BASE (base_fontset);
970 if (! BASE_FONTSET_P (base_fontset))
971 abort ();
973 else
974 base_fontset = Vdefault_fontset;
976 fontset = make_fontset (frame, Qnil, base_fontset);
977 return XINT (FONTSET_ID (fontset));
982 /* Cache data used by fontset_pattern_regexp. The car part is a
983 pattern string containing at least one wild card, the cdr part is
984 the corresponding regular expression. */
985 static Lisp_Object Vcached_fontset_data;
987 #define CACHED_FONTSET_NAME ((char *) SDATA (XCAR (Vcached_fontset_data)))
988 #define CACHED_FONTSET_REGEX (XCDR (Vcached_fontset_data))
990 /* If fontset name PATTERN contains any wild card, return regular
991 expression corresponding to PATTERN. */
993 static Lisp_Object
994 fontset_pattern_regexp (pattern)
995 Lisp_Object pattern;
997 if (!index ((char *) SDATA (pattern), '*')
998 && !index ((char *) SDATA (pattern), '?'))
999 /* PATTERN does not contain any wild cards. */
1000 return Qnil;
1002 if (!CONSP (Vcached_fontset_data)
1003 || strcmp ((char *) SDATA (pattern), CACHED_FONTSET_NAME))
1005 /* We must at first update the cached data. */
1006 unsigned char *regex, *p0, *p1;
1007 int ndashes = 0, nstars = 0;
1009 for (p0 = SDATA (pattern); *p0; p0++)
1011 if (*p0 == '-')
1012 ndashes++;
1013 else if (*p0 == '*')
1014 nstars++;
1017 /* If PATTERN is not full XLFD we conert "*" to ".*". Otherwise
1018 we convert "*" to "[^-]*" which is much faster in regular
1019 expression matching. */
1020 if (ndashes < 14)
1021 p1 = regex = (unsigned char *) alloca (SBYTES (pattern) + 2 * nstars + 1);
1022 else
1023 p1 = regex = (unsigned char *) alloca (SBYTES (pattern) + 5 * nstars + 1);
1025 *p1++ = '^';
1026 for (p0 = SDATA (pattern); *p0; p0++)
1028 if (*p0 == '*')
1030 if (ndashes < 14)
1031 *p1++ = '.';
1032 else
1033 *p1++ = '[', *p1++ = '^', *p1++ = '-', *p1++ = ']';
1034 *p1++ = '*';
1036 else if (*p0 == '?')
1037 *p1++ = '.';
1038 else
1039 *p1++ = *p0;
1041 *p1++ = '$';
1042 *p1++ = 0;
1044 Vcached_fontset_data = Fcons (build_string ((char *) SDATA (pattern)),
1045 build_string ((char *) regex));
1048 return CACHED_FONTSET_REGEX;
1051 /* Return ID of the base fontset named NAME. If there's no such
1052 fontset, return -1. NAME_PATTERN specifies how to treat NAME as this:
1053 0: pattern containing '*' and '?' as wildcards
1054 1: regular expression
1055 2: literal fontset name
1059 fs_query_fontset (name, name_pattern)
1060 Lisp_Object name;
1061 int name_pattern;
1063 Lisp_Object tem;
1064 int i;
1066 name = Fdowncase (name);
1067 if (name_pattern != 1)
1069 tem = Frassoc (name, Vfontset_alias_alist);
1070 if (NILP (tem))
1071 tem = Fassoc (name, Vfontset_alias_alist);
1072 if (CONSP (tem) && STRINGP (XCAR (tem)))
1073 name = XCAR (tem);
1074 else if (name_pattern == 0)
1076 tem = fontset_pattern_regexp (name);
1077 if (STRINGP (tem))
1079 name = tem;
1080 name_pattern = 1;
1085 for (i = 0; i < ASIZE (Vfontset_table); i++)
1087 Lisp_Object fontset, this_name;
1089 fontset = FONTSET_FROM_ID (i);
1090 if (NILP (fontset)
1091 || !BASE_FONTSET_P (fontset))
1092 continue;
1094 this_name = FONTSET_NAME (fontset);
1095 if (name_pattern == 1
1096 ? fast_string_match_ignore_case (name, this_name) >= 0
1097 : !xstrcasecmp (SDATA (name), SDATA (this_name)))
1098 return i;
1100 return -1;
1104 DEFUN ("query-fontset", Fquery_fontset, Squery_fontset, 1, 2, 0,
1105 doc: /* Return the name of a fontset that matches PATTERN.
1106 The value is nil if there is no matching fontset.
1107 PATTERN can contain `*' or `?' as a wildcard
1108 just as X font name matching algorithm allows.
1109 If REGEXPP is non-nil, PATTERN is a regular expression. */)
1110 (pattern, regexpp)
1111 Lisp_Object pattern, regexpp;
1113 Lisp_Object fontset;
1114 int id;
1116 (*check_window_system_func) ();
1118 CHECK_STRING (pattern);
1120 if (SCHARS (pattern) == 0)
1121 return Qnil;
1123 id = fs_query_fontset (pattern, !NILP (regexpp));
1124 if (id < 0)
1125 return Qnil;
1127 fontset = FONTSET_FROM_ID (id);
1128 return FONTSET_NAME (fontset);
1131 /* Return a list of base fontset names matching PATTERN on frame F. */
1133 Lisp_Object
1134 list_fontsets (f, pattern, size)
1135 FRAME_PTR f;
1136 Lisp_Object pattern;
1137 int size;
1139 Lisp_Object frame, regexp, val;
1140 int id;
1142 XSETFRAME (frame, f);
1144 regexp = fontset_pattern_regexp (pattern);
1145 val = Qnil;
1147 for (id = 0; id < ASIZE (Vfontset_table); id++)
1149 Lisp_Object fontset, name;
1151 fontset = FONTSET_FROM_ID (id);
1152 if (NILP (fontset)
1153 || !BASE_FONTSET_P (fontset)
1154 || !EQ (frame, FONTSET_FRAME (fontset)))
1155 continue;
1156 name = FONTSET_NAME (fontset);
1158 if (STRINGP (regexp)
1159 ? (fast_string_match (regexp, name) < 0)
1160 : strcmp ((char *) SDATA (pattern), (char *) SDATA (name)))
1161 continue;
1163 val = Fcons (Fcopy_sequence (FONTSET_NAME (fontset)), val);
1166 return val;
1170 /* Free all realized fontsets whose base fontset is BASE. */
1172 static void
1173 free_realized_fontsets (base)
1174 Lisp_Object base;
1176 int id;
1178 #if 0
1179 /* For the moment, this doesn't work because free_realized_face
1180 doesn't remove FACE from a cache. Until we find a solution, we
1181 suppress this code, and simply use Fclear_face_cache even though
1182 that is not efficient. */
1183 BLOCK_INPUT;
1184 for (id = 0; id < ASIZE (Vfontset_table); id++)
1186 Lisp_Object this = AREF (Vfontset_table, id);
1188 if (EQ (FONTSET_BASE (this), base))
1190 Lisp_Object tail;
1192 for (tail = FONTSET_FACE_ALIST (this); CONSP (tail);
1193 tail = XCDR (tail))
1195 FRAME_PTR f = XFRAME (FONTSET_FRAME (this));
1196 int face_id = XINT (XCDR (XCAR (tail)));
1197 struct face *face = FACE_FROM_ID (f, face_id);
1199 /* Face THIS itself is also freed by the following call. */
1200 free_realized_face (f, face);
1204 UNBLOCK_INPUT;
1205 #else /* not 0 */
1206 /* But, we don't have to call Fclear_face_cache if no fontset has
1207 been realized from BASE. */
1208 for (id = 0; id < ASIZE (Vfontset_table); id++)
1210 Lisp_Object this = AREF (Vfontset_table, id);
1212 if (CHAR_TABLE_P (this) && EQ (FONTSET_BASE (this), base))
1214 Fclear_face_cache (Qt);
1215 break;
1218 #endif /* not 0 */
1222 /* Check validity of NAME as a fontset name and return the
1223 corresponding fontset. If not valid, signal an error.
1224 If NAME is t, return Vdefault_fontset. */
1226 static Lisp_Object
1227 check_fontset_name (name)
1228 Lisp_Object name;
1230 int id;
1232 if (EQ (name, Qt))
1233 return Vdefault_fontset;
1235 CHECK_STRING (name);
1236 /* First try NAME as literal. */
1237 id = fs_query_fontset (name, 2);
1238 if (id < 0)
1239 /* For backward compatibility, try again NAME as pattern. */
1240 id = fs_query_fontset (name, 0);
1241 if (id < 0)
1242 error ("Fontset `%s' does not exist", SDATA (name));
1243 return FONTSET_FROM_ID (id);
1246 static void
1247 accumulate_script_ranges (arg, range, val)
1248 Lisp_Object arg, range, val;
1250 if (EQ (XCAR (arg), val))
1252 if (CONSP (range))
1253 XSETCDR (arg, Fcons (Fcons (XCAR (range), XCDR (range)), XCDR (arg)));
1254 else
1255 XSETCDR (arg, Fcons (Fcons (range, range), XCDR (arg)));
1260 /* Return an ASCII font name generated from fontset name NAME and
1261 font-spec ASCII_SPEC. NAME is a string conforming to XLFD. */
1263 static INLINE Lisp_Object
1264 generate_ascii_font_name (name, ascii_spec)
1265 Lisp_Object name, ascii_spec;
1267 Lisp_Object font_spec = Ffont_spec (0, NULL);
1268 int i;
1269 char xlfd[256];
1271 if (font_parse_xlfd ((char *) SDATA (name), font_spec) < 0)
1272 error ("Not an XLFD font name: %s", SDATA (name));
1273 for (i = FONT_FOUNDRY_INDEX; i < FONT_EXTRA_INDEX; i++)
1274 if (! NILP (AREF (ascii_spec, i)))
1275 ASET (font_spec, i, AREF (ascii_spec, i));
1276 i = font_unparse_xlfd (font_spec, 0, xlfd, 256);
1277 if (i < 0)
1278 error ("Not an XLFD font name: %s", SDATA (name));
1279 return make_unibyte_string (xlfd, i);
1282 /* Variables referred in set_fontset_font. They are set before
1283 map_charset_chars is called in Fset_fontset_font. */
1284 static Lisp_Object font_def_arg, add_arg;
1285 static int from_arg, to_arg;
1287 /* Callback function for map_charset_chars in Fset_fontset_font. In
1288 FONTSET, set font_def_arg in a fashion specified by add_arg for
1289 characters in RANGE while ignoring the range between from_arg and
1290 to_arg. */
1292 static void
1293 set_fontset_font (fontset, range)
1294 Lisp_Object fontset, range;
1296 if (from_arg < to_arg)
1298 int from = XINT (XCAR (range)), to = XINT (XCDR (range));
1300 if (from < from_arg)
1302 if (to > to_arg)
1304 Lisp_Object range2;
1306 range2 = Fcons (make_number (to_arg), XCDR (range));
1307 FONTSET_ADD (fontset, range, font_def_arg, add_arg);
1308 to = to_arg;
1310 if (to > from_arg)
1311 range = Fcons (XCAR (range), make_number (from_arg));
1313 else if (to <= to_arg)
1314 return;
1315 else
1317 if (from < to_arg)
1318 range = Fcons (make_number (to_arg), XCDR (range));
1321 FONTSET_ADD (fontset, range, font_def_arg, add_arg);
1324 extern Lisp_Object QCfamily, QCregistry;
1326 DEFUN ("set-fontset-font", Fset_fontset_font, Sset_fontset_font, 3, 5, 0,
1327 doc: /*
1328 Modify fontset NAME to use FONT-SPEC for TARGET characters.
1330 TARGET may be a cons; (FROM . TO), where FROM and TO are characters.
1331 In that case, use FONT-SPEC for all characters in the range FROM and
1332 TO (inclusive).
1334 TARGET may be a script name symbol. In that case, use FONT-SPEC for
1335 all characters that belong to the script.
1337 TARGET may be a charset. In that case, use FONT-SPEC for all
1338 characters in the charset.
1340 TARGET may be nil. In that case, use FONT-SPEC for any characters for
1341 that no FONT-SPEC is specified.
1343 FONT-SPEC may one of these:
1344 * A font-spec object made by the function `font-spec' (which see).
1345 * A cons (FAMILY . REGISTRY), where FAMILY is a font family name and
1346 REGISTRY is a font registry name. FAMILY may contain foundry
1347 name, and REGISTRY may contain encoding name.
1348 * A font name string.
1349 * nil, which explicitly specifies that there's no font for TARGET.
1351 Optional 4th argument FRAME, if non-nil, is a frame. This argument is
1352 kept for backward compatibility and has no meaning.
1354 Optional 5th argument ADD, if non-nil, specifies how to add FONT-SPEC
1355 to the font specifications for TARGET previously set. If it is
1356 `prepend', FONT-SPEC is prepended. If it is `append', FONT-SPEC is
1357 appended. By default, FONT-SPEC overrides the previous settings. */)
1358 (name, target, font_spec, frame, add)
1359 Lisp_Object name, target, font_spec, frame, add;
1361 Lisp_Object fontset;
1362 Lisp_Object font_def, registry, family;
1363 Lisp_Object range_list;
1364 struct charset *charset = NULL;
1366 fontset = check_fontset_name (name);
1368 /* The arg FRAME is kept for backward compatibility. We only check
1369 the validity. */
1370 if (!NILP (frame))
1371 CHECK_LIVE_FRAME (frame);
1373 if (CONSP (font_spec))
1375 Lisp_Object spec = Ffont_spec (0, NULL);
1377 font_parse_family_registry (XCAR (font_spec), XCDR (font_spec), spec);
1378 font_spec = spec;
1380 else if (STRINGP (font_spec))
1382 Lisp_Object args[2];
1383 extern Lisp_Object QCname;
1385 args[0] = QCname;
1386 args[1] = font_spec;
1387 font_spec = Ffont_spec (2, args);
1389 else if (! NILP (font_spec) && ! FONT_SPEC_P (font_spec))
1390 Fsignal (Qfont, list2 (build_string ("Invalid font-spec"), font_spec));
1392 if (! NILP (font_spec))
1394 Lisp_Object encoding, repertory;
1396 family = AREF (font_spec, FONT_FAMILY_INDEX);
1397 if (! NILP (family) )
1398 family = SYMBOL_NAME (family);
1399 registry = AREF (font_spec, FONT_REGISTRY_INDEX);
1400 if (! NILP (registry))
1401 registry = Fdowncase (SYMBOL_NAME (registry));
1402 encoding = find_font_encoding (concat3 (family, build_string ("-"),
1403 registry));
1404 if (NILP (encoding))
1405 encoding = Qascii;
1407 if (SYMBOLP (encoding))
1409 CHECK_CHARSET (encoding);
1410 encoding = repertory = CHARSET_SYMBOL_ID (encoding);
1412 else
1414 repertory = XCDR (encoding);
1415 encoding = XCAR (encoding);
1416 CHECK_CHARSET (encoding);
1417 encoding = CHARSET_SYMBOL_ID (encoding);
1418 if (! NILP (repertory) && SYMBOLP (repertory))
1420 CHECK_CHARSET (repertory);
1421 repertory = CHARSET_SYMBOL_ID (repertory);
1424 FONT_DEF_NEW (font_def, font_spec, encoding, repertory);
1426 else
1427 font_def = Qnil;
1429 if (CHARACTERP (target))
1430 range_list = Fcons (Fcons (target, target), Qnil);
1431 else if (CONSP (target))
1433 Lisp_Object from, to;
1435 from = Fcar (target);
1436 to = Fcdr (target);
1437 CHECK_CHARACTER (from);
1438 CHECK_CHARACTER (to);
1439 range_list = Fcons (target, Qnil);
1441 else if (SYMBOLP (target) && !NILP (target))
1443 Lisp_Object script_list;
1444 Lisp_Object val;
1446 range_list = Qnil;
1447 script_list = XCHAR_TABLE (Vchar_script_table)->extras[0];
1448 if (! NILP (Fmemq (target, script_list)))
1450 val = Fcons (target, Qnil);
1451 map_char_table (accumulate_script_ranges, Qnil, Vchar_script_table,
1452 val);
1453 range_list = XCDR (val);
1454 if (EQ (target, Qlatin) && NILP (FONTSET_ASCII (fontset)))
1456 if (VECTORP (font_spec))
1457 val = generate_ascii_font_name (FONTSET_NAME (fontset),
1458 font_spec);
1459 else
1460 val = font_spec;
1461 FONTSET_ASCII (fontset) = val;
1464 if (CHARSETP (target))
1466 if (EQ (target, Qascii) && NILP (FONTSET_ASCII (fontset)))
1468 if (VECTORP (font_spec))
1469 font_spec = generate_ascii_font_name (FONTSET_NAME (fontset),
1470 font_spec);
1471 FONTSET_ASCII (fontset) = font_spec;
1472 range_list = Fcons (Fcons (make_number (0), make_number (127)),
1473 Qnil);
1475 else
1477 CHECK_CHARSET_GET_CHARSET (target, charset);
1480 else if (NILP (range_list))
1481 error ("Invalid script or charset name: %s",
1482 SDATA (SYMBOL_NAME (target)));
1484 else if (NILP (target))
1485 range_list = Fcons (Qnil, Qnil);
1486 else
1487 error ("Invalid target for setting a font");
1490 if (charset)
1492 font_def_arg = font_def;
1493 add_arg = add;
1494 if (NILP (range_list))
1495 from_arg = to_arg = 0;
1496 else
1497 from_arg = XINT (XCAR (XCAR (range_list))),
1498 to_arg = XINT (XCDR (XCAR (range_list)));
1500 map_charset_chars (set_fontset_font, Qnil, fontset, charset,
1501 CHARSET_MIN_CODE (charset),
1502 CHARSET_MAX_CODE (charset));
1504 for (; CONSP (range_list); range_list = XCDR (range_list))
1505 FONTSET_ADD (fontset, XCAR (range_list), font_def, add);
1507 /* Free all realized fontsets whose base is FONTSET. This way, the
1508 specified character(s) are surely redisplayed by a correct
1509 font. */
1510 free_realized_fontsets (fontset);
1512 return Qnil;
1516 DEFUN ("new-fontset", Fnew_fontset, Snew_fontset, 2, 2, 0,
1517 doc: /* Create a new fontset NAME from font information in FONTLIST.
1519 FONTLIST is an alist of scripts vs the corresponding font specification list.
1520 Each element of FONTLIST has the form (SCRIPT FONT-SPEC ...), where a
1521 character of SCRIPT is displayed by a font that matches one of
1522 FONT-SPEC.
1524 SCRIPT is a symbol that appears in the first extra slot of the
1525 char-table `char-script-table'.
1527 FONT-SPEC is a vector, a cons, or a string. See the documentation of
1528 `set-fontset-font' for the meaning. */)
1529 (name, fontlist)
1530 Lisp_Object name, fontlist;
1532 Lisp_Object fontset;
1533 int id;
1535 CHECK_STRING (name);
1536 CHECK_LIST (fontlist);
1538 name = Fdowncase (name);
1539 id = fs_query_fontset (name, 0);
1540 if (id < 0)
1542 Lisp_Object font_spec = Ffont_spec (0, NULL);
1543 Lisp_Object short_name;
1544 char xlfd[256];
1545 int len;
1547 if (font_parse_xlfd ((char *) SDATA (name), font_spec) < 0)
1548 error ("Fontset name must be in XLFD format");
1549 short_name = AREF (font_spec, FONT_REGISTRY_INDEX);
1550 if (strncmp ((char *) SDATA (SYMBOL_NAME (short_name)), "fontset-", 8)
1551 || SBYTES (SYMBOL_NAME (short_name)) < 9)
1552 error ("Registry field of fontset name must be \"fontset-*\"");
1553 Vfontset_alias_alist = Fcons (Fcons (name, SYMBOL_NAME (short_name)),
1554 Vfontset_alias_alist);
1555 ASET (font_spec, FONT_REGISTRY_INDEX, Qiso8859_1);
1556 fontset = make_fontset (Qnil, name, Qnil);
1557 len = font_unparse_xlfd (font_spec, 0, xlfd, 256);
1558 if (len < 0)
1559 error ("Invalid fontset name (perhaps too long): %s", SDATA (name));
1560 FONTSET_ASCII (fontset) = make_unibyte_string (xlfd, len);
1562 else
1564 fontset = FONTSET_FROM_ID (id);;
1565 free_realized_fontsets (fontset);
1566 Fset_char_table_range (fontset, Qt, Qnil);
1569 for (; ! NILP (fontlist); fontlist = Fcdr (fontlist))
1571 Lisp_Object elt, script;
1573 elt = Fcar (fontlist);
1574 script = Fcar (elt);
1575 elt = Fcdr (elt);
1576 if (CONSP (elt) && (NILP (XCDR (elt)) || CONSP (XCDR (elt))))
1577 for (; CONSP (elt); elt = XCDR (elt))
1578 Fset_fontset_font (name, script, XCAR (elt), Qnil, Qappend);
1579 else
1580 Fset_fontset_font (name, script, elt, Qnil, Qappend);
1582 return name;
1586 /* Alist of automatically created fontsets. Each element is a cons
1587 (FONT-SPEC . FONTSET-ID). */
1588 static Lisp_Object auto_fontset_alist;
1591 fontset_from_font (font_object)
1592 Lisp_Object font_object;
1594 Lisp_Object font_name = font_get_name (font_object);
1595 Lisp_Object font_spec = Fcopy_font_spec (font_object);
1596 Lisp_Object fontset_spec, alias, name, fontset;
1597 Lisp_Object val;
1598 int i;
1600 val = assoc_no_quit (font_spec, auto_fontset_alist);
1601 if (CONSP (val))
1602 return XINT (FONTSET_ID (XCDR (val)));
1603 if (NILP (auto_fontset_alist))
1604 alias = intern ("fontset-startup");
1605 else
1607 char temp[32];
1608 int len = XINT (Flength (auto_fontset_alist));
1610 sprintf (temp, "fontset-auto%d", len);
1611 alias = intern (temp);
1613 fontset_spec = Fcopy_font_spec (font_spec);
1614 ASET (fontset_spec, FONT_REGISTRY_INDEX, alias);
1615 name = Ffont_xlfd_name (fontset_spec, Qnil);
1616 if (NILP (name))
1617 abort ();
1618 fontset = make_fontset (Qnil, name, Qnil);
1619 Vfontset_alias_alist = Fcons (Fcons (name, SYMBOL_NAME (alias)),
1620 Vfontset_alias_alist);
1621 alias = Fdowncase (AREF (font_object, FONT_NAME_INDEX));
1622 Vfontset_alias_alist = Fcons (Fcons (name, alias), Vfontset_alias_alist);
1623 auto_fontset_alist = Fcons (Fcons (font_spec, fontset), auto_fontset_alist);
1624 FONTSET_ASCII (fontset) = font_name;
1625 ASET (font_spec, FONT_FOUNDRY_INDEX, Qnil);
1626 ASET (font_spec, FONT_ADSTYLE_INDEX, Qnil);
1627 for (i = FONT_WEIGHT_INDEX; i < FONT_EXTRA_INDEX; i++)
1628 ASET (font_spec, i, Qnil);
1629 Fset_fontset_font (name, Qlatin, font_spec, Qnil, Qnil);
1630 font_spec = Fcopy_font_spec (font_spec);
1631 ASET (font_spec, FONT_REGISTRY_INDEX, Qiso10646_1);
1632 Fset_fontset_font (name, Qnil, font_spec, Qnil, Qnil);
1633 return XINT (FONTSET_ID (fontset));
1636 DEFUN ("font-info", Ffont_info, Sfont_info, 1, 2, 0,
1637 doc: /* Return information about a font named NAME on frame FRAME.
1638 If FRAME is omitted or nil, use the selected frame.
1639 The returned value is a vector of OPENED-NAME, FULL-NAME, CHARSET, SIZE,
1640 HEIGHT, BASELINE-OFFSET, RELATIVE-COMPOSE, and DEFAULT-ASCENT,
1641 where
1642 OPENED-NAME is the name used for opening the font,
1643 FULL-NAME is the full name of the font,
1644 SIZE is the maximum bound width of the font,
1645 HEIGHT is the height of the font,
1646 BASELINE-OFFSET is the upward offset pixels from ASCII baseline,
1647 RELATIVE-COMPOSE and DEFAULT-ASCENT are the numbers controlling
1648 how to compose characters.
1649 If the named font is not yet loaded, return nil. */)
1650 (name, frame)
1651 Lisp_Object name, frame;
1653 FRAME_PTR f;
1654 struct font *font;
1655 Lisp_Object info;
1656 Lisp_Object font_object;
1658 (*check_window_system_func) ();
1660 CHECK_STRING (name);
1661 name = Fdowncase (name);
1662 if (NILP (frame))
1663 frame = selected_frame;
1664 CHECK_LIVE_FRAME (frame);
1665 f = XFRAME (frame);
1667 font_object = font_open_by_name (f, (char *) SDATA (name));
1668 if (NILP (font_object))
1669 return Qnil;
1670 font = XFONT_OBJECT (font_object);
1672 info = Fmake_vector (make_number (7), Qnil);
1673 XVECTOR (info)->contents[0] = AREF (font_object, FONT_NAME_INDEX);
1674 XVECTOR (info)->contents[1] = AREF (font_object, FONT_NAME_INDEX);
1675 XVECTOR (info)->contents[2] = make_number (font->pixel_size);
1676 XVECTOR (info)->contents[3] = make_number (font->height);
1677 XVECTOR (info)->contents[4] = make_number (font->baseline_offset);
1678 XVECTOR (info)->contents[5] = make_number (font->relative_compose);
1679 XVECTOR (info)->contents[6] = make_number (font->default_ascent);
1681 #if 0
1682 /* As font_object is still in FONT_OBJLIST of the entity, we can't
1683 close it now. Perhaps, we should manage font-objects
1684 by `reference-count'. */
1685 font_close_object (f, font_object);
1686 #endif
1687 return info;
1691 /* Return a cons (FONT-NAME . GLYPH-CODE).
1692 FONT-NAME is the font name for the character at POSITION in the current
1693 buffer. This is computed from all the text properties and overlays
1694 that apply to POSITION. POSTION may be nil, in which case,
1695 FONT-NAME is the font name for display the character CH with the
1696 default face.
1698 GLYPH-CODE is the glyph code in the font to use for the character.
1700 If the 2nd optional arg CH is non-nil, it is a character to check
1701 the font instead of the character at POSITION.
1703 It returns nil in the following cases:
1705 (1) The window system doesn't have a font for the character (thus
1706 it is displayed by an empty box).
1708 (2) The character code is invalid.
1710 (3) If POSITION is not nil, and the current buffer is not displayed
1711 in any window.
1713 In addition, the returned font name may not take into account of
1714 such redisplay engine hooks as what used in jit-lock-mode if
1715 POSITION is currently not visible. */
1718 DEFUN ("internal-char-font", Finternal_char_font, Sinternal_char_font, 1, 2, 0,
1719 doc: /* For internal use only. */)
1720 (position, ch)
1721 Lisp_Object position, ch;
1723 EMACS_INT pos, pos_byte, dummy;
1724 int face_id;
1725 int c;
1726 struct frame *f;
1727 struct face *face;
1728 int cs_id;
1730 if (NILP (position))
1732 CHECK_CHARACTER (ch);
1733 c = XINT (ch);
1734 f = XFRAME (selected_frame);
1735 face_id = DEFAULT_FACE_ID;
1736 pos = -1;
1737 cs_id = -1;
1739 else
1741 Lisp_Object window, charset;
1742 struct window *w;
1744 CHECK_NUMBER_COERCE_MARKER (position);
1745 pos = XINT (position);
1746 if (pos < BEGV || pos >= ZV)
1747 args_out_of_range_3 (position, make_number (BEGV), make_number (ZV));
1748 pos_byte = CHAR_TO_BYTE (pos);
1749 if (NILP (ch))
1750 c = FETCH_CHAR (pos_byte);
1751 else
1753 CHECK_NATNUM (ch);
1754 c = XINT (ch);
1756 window = Fget_buffer_window (Fcurrent_buffer (), Qnil);
1757 if (NILP (window))
1758 return Qnil;
1759 w = XWINDOW (window);
1760 f = XFRAME (w->frame);
1761 face_id = face_at_buffer_position (w, pos, -1, -1, &dummy, pos + 100, 0);
1762 charset = Fget_char_property (position, Qcharset, Qnil);
1763 if (CHARSETP (charset))
1764 cs_id = XINT (CHARSET_SYMBOL_ID (charset));
1765 else
1766 cs_id = -1;
1768 if (! CHAR_VALID_P (c, 0))
1769 return Qnil;
1770 face_id = FACE_FOR_CHAR (f, FACE_FROM_ID (f, face_id), c, pos, Qnil);
1771 face = FACE_FROM_ID (f, face_id);
1772 if (face->font)
1774 struct font *font = face->font;
1775 unsigned code = font->driver->encode_char (font, c);
1776 Lisp_Object fontname = font->props[FONT_NAME_INDEX];
1777 /* Assignment to EMACS_INT stops GCC whining about limited range
1778 of data type. */
1779 EMACS_INT cod = code;
1781 if (code == FONT_INVALID_CODE)
1782 return Qnil;
1783 if (cod <= MOST_POSITIVE_FIXNUM)
1784 return Fcons (fontname, make_number (code));
1785 return Fcons (fontname, Fcons (make_number (code >> 16),
1786 make_number (code & 0xFFFF)));
1788 return Qnil;
1792 DEFUN ("fontset-info", Ffontset_info, Sfontset_info, 1, 2, 0,
1793 doc: /* Return information about a fontset FONTSET on frame FRAME.
1794 The value is a char-table whose elements have this form:
1796 ((FONT-PATTERN OPENED-FONT ...) ...)
1798 FONT-PATTERN is a vector:
1800 [ FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY ]
1802 or a string of font name pattern.
1804 OPENED-FONT is a name of a font actually opened.
1806 The char-table has one extra slot. The value is a char-table
1807 containing the information about the derived fonts from the default
1808 fontset. The format is the same as above. */)
1809 (fontset, frame)
1810 Lisp_Object fontset, frame;
1812 FRAME_PTR f;
1813 Lisp_Object *realized[2], fontsets[2], tables[2];
1814 Lisp_Object val, elt;
1815 int c, i, j, k;
1817 (*check_window_system_func) ();
1819 fontset = check_fontset_name (fontset);
1821 if (NILP (frame))
1822 frame = selected_frame;
1823 CHECK_LIVE_FRAME (frame);
1824 f = XFRAME (frame);
1826 /* Recode fontsets realized on FRAME from the base fontset FONTSET
1827 in the table `realized'. */
1828 realized[0] = (Lisp_Object *) alloca (sizeof (Lisp_Object)
1829 * ASIZE (Vfontset_table));
1830 for (i = j = 0; i < ASIZE (Vfontset_table); i++)
1832 elt = FONTSET_FROM_ID (i);
1833 if (!NILP (elt)
1834 && EQ (FONTSET_BASE (elt), fontset)
1835 && EQ (FONTSET_FRAME (elt), frame))
1836 realized[0][j++] = elt;
1838 realized[0][j] = Qnil;
1840 realized[1] = (Lisp_Object *) alloca (sizeof (Lisp_Object)
1841 * ASIZE (Vfontset_table));
1842 for (i = j = 0; ! NILP (realized[0][i]); i++)
1844 elt = FONTSET_DEFAULT (realized[0][i]);
1845 if (! NILP (elt))
1846 realized[1][j++] = elt;
1848 realized[1][j] = Qnil;
1850 tables[0] = Fmake_char_table (Qfontset_info, Qnil);
1851 tables[1] = Fmake_char_table (Qnil, Qnil);
1852 XCHAR_TABLE (tables[0])->extras[0] = tables[1];
1853 fontsets[0] = fontset;
1854 fontsets[1] = Vdefault_fontset;
1856 /* Accumulate information of the fontset in TABLE. The format of
1857 each element is ((FONT-SPEC OPENED-FONT ...) ...). */
1858 for (k = 0; k <= 1; k++)
1860 for (c = 0; c <= MAX_CHAR; )
1862 int from, to;
1864 if (c <= MAX_5_BYTE_CHAR)
1866 val = char_table_ref_and_range (fontsets[k], c, &from, &to);
1867 if (to > MAX_5_BYTE_CHAR)
1868 to = MAX_5_BYTE_CHAR;
1870 else
1872 val = FONTSET_FALLBACK (fontsets[k]);
1873 to = MAX_CHAR;
1875 if (VECTORP (val))
1877 Lisp_Object alist;
1879 /* At first, set ALIST to ((FONT-SPEC) ...). */
1880 for (alist = Qnil, i = 0; i < ASIZE (val); i++)
1881 if (! NILP (AREF (val, i)))
1882 alist = Fcons (Fcons (FONT_DEF_SPEC (AREF (val, i)), Qnil),
1883 alist);
1884 alist = Fnreverse (alist);
1886 /* Then store opend font names to cdr of each elements. */
1887 for (i = 0; ! NILP (realized[k][i]); i++)
1889 if (c <= MAX_5_BYTE_CHAR)
1890 val = FONTSET_REF (realized[k][i], c);
1891 else
1892 val = FONTSET_FALLBACK (realized[k][i]);
1893 if (! VECTORP (val))
1894 continue;
1895 /* VAL: [int ? [FACE-ID FONT-DEF FONT-OBJECT int] ... ] */
1896 for (j = 2; j < ASIZE (val); j++)
1898 elt = AREF (val, j);
1899 if (FONT_OBJECT_P (RFONT_DEF_OBJECT (elt)))
1901 Lisp_Object font_object = RFONT_DEF_OBJECT (elt);
1902 Lisp_Object slot, name;
1904 slot = Fassq (RFONT_DEF_SPEC (elt), alist);
1905 name = AREF (font_object, FONT_NAME_INDEX);
1906 if (NILP (Fmember (name, XCDR (slot))))
1907 nconc2 (slot, Fcons (name, Qnil));
1912 /* Store ALIST in TBL for characters C..TO. */
1913 if (c <= MAX_5_BYTE_CHAR)
1914 char_table_set_range (tables[k], c, to, alist);
1915 else
1916 XCHAR_TABLE (tables[k])->defalt = alist;
1918 /* At last, change each elements to font names. */
1919 for (; CONSP (alist); alist = XCDR (alist))
1921 elt = XCAR (alist);
1922 XSETCAR (elt, Ffont_xlfd_name (XCAR (elt), Qnil));
1925 c = to + 1;
1929 return tables[0];
1933 DEFUN ("fontset-font", Ffontset_font, Sfontset_font, 2, 3, 0,
1934 doc: /* Return a font name pattern for character CH in fontset NAME.
1935 If NAME is t, find a pattern in the default fontset.
1937 The value has the form (FAMILY . REGISTRY), where FAMILY is a font
1938 family name and REGISTRY is a font registry name. This is actually
1939 the first font name pattern for CH in the fontset or in the default
1940 fontset.
1942 If the 2nd optional arg ALL is non-nil, return a list of all font name
1943 patterns. */)
1944 (name, ch, all)
1945 Lisp_Object name, ch, all;
1947 int c;
1948 Lisp_Object fontset, elt, list, repertory, val;
1949 int i, j;
1951 fontset = check_fontset_name (name);
1953 CHECK_CHARACTER (ch);
1954 c = XINT (ch);
1955 list = Qnil;
1956 while (1)
1958 for (i = 0, elt = FONTSET_REF (fontset, c); i < 2;
1959 i++, elt = FONTSET_FALLBACK (fontset))
1960 if (VECTORP (elt))
1961 for (j = 0; j < ASIZE (elt); j++)
1963 val = AREF (elt, j);
1964 repertory = AREF (val, 1);
1965 if (INTEGERP (repertory))
1967 struct charset *charset = CHARSET_FROM_ID (XINT (repertory));
1969 if (! CHAR_CHARSET_P (c, charset))
1970 continue;
1972 else if (CHAR_TABLE_P (repertory))
1974 if (NILP (CHAR_TABLE_REF (repertory, c)))
1975 continue;
1977 val = AREF (val, 0);
1978 val = Fcons (AREF (val, 0), AREF (val, 5));
1979 if (NILP (all))
1980 return val;
1981 list = Fcons (val, list);
1983 if (EQ (fontset, Vdefault_fontset))
1984 break;
1985 fontset = Vdefault_fontset;
1987 return (Fnreverse (list));
1990 DEFUN ("fontset-list", Ffontset_list, Sfontset_list, 0, 0, 0,
1991 doc: /* Return a list of all defined fontset names. */)
1994 Lisp_Object fontset, list;
1995 int i;
1997 list = Qnil;
1998 for (i = 0; i < ASIZE (Vfontset_table); i++)
2000 fontset = FONTSET_FROM_ID (i);
2001 if (!NILP (fontset)
2002 && BASE_FONTSET_P (fontset))
2003 list = Fcons (FONTSET_NAME (fontset), list);
2006 return list;
2010 #ifdef FONTSET_DEBUG
2012 Lisp_Object
2013 dump_fontset (fontset)
2014 Lisp_Object fontset;
2016 Lisp_Object vec;
2018 vec = Fmake_vector (make_number (3), Qnil);
2019 ASET (vec, 0, FONTSET_ID (fontset));
2021 if (BASE_FONTSET_P (fontset))
2023 ASET (vec, 1, FONTSET_NAME (fontset));
2025 else
2027 Lisp_Object frame;
2029 frame = FONTSET_FRAME (fontset);
2030 if (FRAMEP (frame))
2032 FRAME_PTR f = XFRAME (frame);
2034 if (FRAME_LIVE_P (f))
2035 ASET (vec, 1,
2036 Fcons (FONTSET_NAME (FONTSET_BASE (fontset)), f->name));
2037 else
2038 ASET (vec, 1,
2039 Fcons (FONTSET_NAME (FONTSET_BASE (fontset)), Qnil));
2041 if (!NILP (FONTSET_DEFAULT (fontset)))
2042 ASET (vec, 2, FONTSET_ID (FONTSET_DEFAULT (fontset)));
2044 return vec;
2047 DEFUN ("fontset-list-all", Ffontset_list_all, Sfontset_list_all, 0, 0, 0,
2048 doc: /* Return a brief summary of all fontsets for debug use. */)
2051 Lisp_Object val;
2052 int i;
2054 for (i = 0, val = Qnil; i < ASIZE (Vfontset_table); i++)
2055 if (! NILP (AREF (Vfontset_table, i)))
2056 val = Fcons (dump_fontset (AREF (Vfontset_table, i)), val);
2057 return (Fnreverse (val));
2059 #endif /* FONTSET_DEBUG */
2061 void
2062 syms_of_fontset ()
2064 DEFSYM (Qfontset, "fontset");
2065 Fput (Qfontset, Qchar_table_extra_slots, make_number (9));
2066 DEFSYM (Qfontset_info, "fontset-info");
2067 Fput (Qfontset_info, Qchar_table_extra_slots, make_number (1));
2069 DEFSYM (Qprepend, "prepend");
2070 DEFSYM (Qappend, "append");
2071 DEFSYM (Qlatin, "latin");
2073 Vcached_fontset_data = Qnil;
2074 staticpro (&Vcached_fontset_data);
2076 Vfontset_table = Fmake_vector (make_number (32), Qnil);
2077 staticpro (&Vfontset_table);
2079 Vdefault_fontset = Fmake_char_table (Qfontset, Qnil);
2080 staticpro (&Vdefault_fontset);
2081 FONTSET_ID (Vdefault_fontset) = make_number (0);
2082 FONTSET_NAME (Vdefault_fontset)
2083 = build_string ("-*-*-*-*-*-*-*-*-*-*-*-*-fontset-default");
2084 ASET (Vfontset_table, 0, Vdefault_fontset);
2085 next_fontset_id = 1;
2087 auto_fontset_alist = Qnil;
2088 staticpro (&auto_fontset_alist);
2090 DEFVAR_LISP ("font-encoding-charset-alist", &Vfont_encoding_charset_alist,
2091 doc: /*
2092 Alist of charsets vs the charsets to determine the preferred font encoding.
2093 Each element looks like (CHARSET . ENCODING-CHARSET),
2094 where ENCODING-CHARSET is a charset registered in the variable
2095 `font-encoding-alist' as ENCODING.
2097 When a text has a property `charset' and the value is CHARSET, a font
2098 whose encoding corresponds to ENCODING-CHARSET is preferred. */);
2099 Vfont_encoding_charset_alist = Qnil;
2101 DEFVAR_LISP ("use-default-ascent", &Vuse_default_ascent,
2102 doc: /*
2103 Char table of characters whose ascent values should be ignored.
2104 If an entry for a character is non-nil, the ascent value of the glyph
2105 is assumed to be specified by _MULE_DEFAULT_ASCENT property of a font.
2107 This affects how a composite character which contains
2108 such a character is displayed on screen. */);
2109 Vuse_default_ascent = Qnil;
2111 DEFVAR_LISP ("ignore-relative-composition", &Vignore_relative_composition,
2112 doc: /*
2113 Char table of characters which are not composed relatively.
2114 If an entry for a character is non-nil, a composition sequence
2115 which contains that character is displayed so that
2116 the glyph of that character is put without considering
2117 an ascent and descent value of a previous character. */);
2118 Vignore_relative_composition = Qnil;
2120 DEFVAR_LISP ("alternate-fontname-alist", &Valternate_fontname_alist,
2121 doc: /* Alist of fontname vs list of the alternate fontnames.
2122 When a specified font name is not found, the corresponding
2123 alternate fontnames (if any) are tried instead. */);
2124 Valternate_fontname_alist = Qnil;
2126 DEFVAR_LISP ("fontset-alias-alist", &Vfontset_alias_alist,
2127 doc: /* Alist of fontset names vs the aliases. */);
2128 Vfontset_alias_alist = Fcons (Fcons (FONTSET_NAME (Vdefault_fontset),
2129 build_string ("fontset-default")),
2130 Qnil);
2132 DEFVAR_LISP ("vertical-centering-font-regexp",
2133 &Vvertical_centering_font_regexp,
2134 doc: /* *Regexp matching font names that require vertical centering on display.
2135 When a character is displayed with such fonts, the character is displayed
2136 at the vertical center of lines. */);
2137 Vvertical_centering_font_regexp = Qnil;
2139 DEFVAR_LISP ("otf-script-alist", &Votf_script_alist,
2140 doc: /* Alist of OpenType script tags vs the corresponding script names. */);
2141 Votf_script_alist = Qnil;
2143 defsubr (&Squery_fontset);
2144 defsubr (&Snew_fontset);
2145 defsubr (&Sset_fontset_font);
2146 defsubr (&Sfont_info);
2147 defsubr (&Sinternal_char_font);
2148 defsubr (&Sfontset_info);
2149 defsubr (&Sfontset_font);
2150 defsubr (&Sfontset_list);
2151 #ifdef FONTSET_DEBUG
2152 defsubr (&Sfontset_list_all);
2153 #endif
2156 /* arch-tag: ea861585-2f5f-4e5b-9849-d04a9c3a3537
2157 (do not change this comment) */