(archive-add-new-member): Use `derived-mode-p'.
[emacs.git] / src / fontset.c
blob82e5b4e65dee2023d553e4d71a3ec723fec59842
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_alist;
195 Lisp_Object Vfont_encoding_charset_alist;
196 Lisp_Object Vuse_default_ascent;
197 Lisp_Object Vignore_relative_composition;
198 Lisp_Object Valternate_fontname_alist;
199 Lisp_Object Vfontset_alias_alist;
200 Lisp_Object Vvertical_centering_font_regexp;
201 Lisp_Object Votf_script_alist;
203 /* Check if any window system is used now. */
204 void (*check_window_system_func) P_ ((void));
207 /* Prototype declarations for static functions. */
208 static Lisp_Object fontset_add P_ ((Lisp_Object, Lisp_Object, Lisp_Object,
209 Lisp_Object));
210 static Lisp_Object fontset_find_font P_ ((Lisp_Object, int, struct face *,
211 int, int));
212 static void reorder_font_vector P_ ((Lisp_Object, Lisp_Object));
213 static Lisp_Object fontset_font P_ ((Lisp_Object, int, struct face *, int));
214 static Lisp_Object make_fontset P_ ((Lisp_Object, Lisp_Object, Lisp_Object));
215 static Lisp_Object fontset_pattern_regexp P_ ((Lisp_Object));
216 static void accumulate_script_ranges P_ ((Lisp_Object, Lisp_Object,
217 Lisp_Object));
218 Lisp_Object find_font_encoding P_ ((Lisp_Object));
220 static void set_fontset_font P_ ((Lisp_Object, Lisp_Object));
222 #ifdef FONTSET_DEBUG
224 /* Return 1 if ID is a valid fontset id, else return 0. */
226 static int
227 fontset_id_valid_p (id)
228 int id;
230 return (id >= 0 && id < ASIZE (Vfontset_table) - 1);
233 #endif
237 /********** MACROS AND FUNCTIONS TO HANDLE FONTSET **********/
239 /* Return the fontset with ID. No check of ID's validness. */
240 #define FONTSET_FROM_ID(id) AREF (Vfontset_table, id)
242 /* Macros to access special values of FONTSET. */
243 #define FONTSET_ID(fontset) XCHAR_TABLE (fontset)->extras[0]
245 /* Macros to access special values of (base) FONTSET. */
246 #define FONTSET_NAME(fontset) XCHAR_TABLE (fontset)->extras[1]
247 #define FONTSET_ASCII(fontset) XCHAR_TABLE (fontset)->extras[4]
248 #define FONTSET_SPEC(fontset) XCHAR_TABLE (fontset)->extras[5]
250 /* Macros to access special values of (realized) FONTSET. */
251 #define FONTSET_BASE(fontset) XCHAR_TABLE (fontset)->extras[2]
252 #define FONTSET_FRAME(fontset) XCHAR_TABLE (fontset)->extras[3]
253 #define FONTSET_OBJLIST(fontset) XCHAR_TABLE (fontset)->extras[4]
254 #define FONTSET_NOFONT_FACE(fontset) XCHAR_TABLE (fontset)->extras[5]
255 #define FONTSET_REPERTORY(fontset) XCHAR_TABLE (fontset)->extras[6]
256 #define FONTSET_DEFAULT(fontset) XCHAR_TABLE (fontset)->extras[7]
258 /* For both base and realized fontset. */
259 #define FONTSET_FALLBACK(fontset) XCHAR_TABLE (fontset)->extras[8]
261 #define BASE_FONTSET_P(fontset) (NILP (FONTSET_BASE (fontset)))
264 /* Macros for FONT-DEF and RFONT-DEF of fontset. */
265 #define FONT_DEF_NEW(font_def, font_spec, encoding, repertory) \
266 do { \
267 (font_def) = Fmake_vector (make_number (3), (font_spec)); \
268 ASET ((font_def), 1, encoding); \
269 ASET ((font_def), 2, repertory); \
270 } while (0)
272 #define FONT_DEF_SPEC(font_def) AREF (font_def, 0)
273 #define FONT_DEF_ENCODING(font_def) AREF (font_def, 1)
274 #define FONT_DEF_REPERTORY(font_def) AREF (font_def, 2)
276 #define RFONT_DEF_FACE(rfont_def) AREF (rfont_def, 0)
277 #define RFONT_DEF_SET_FACE(rfont_def, face_id) \
278 ASET ((rfont_def), 0, make_number (face_id))
279 #define RFONT_DEF_FONT_DEF(rfont_def) AREF (rfont_def, 1)
280 #define RFONT_DEF_SPEC(rfont_def) FONT_DEF_SPEC (AREF (rfont_def, 1))
281 #define RFONT_DEF_REPERTORY(rfont_def) FONT_DEF_REPERTORY (AREF (rfont_def, 1))
282 #define RFONT_DEF_OBJECT(rfont_def) AREF (rfont_def, 2)
283 #define RFONT_DEF_SET_OBJECT(rfont_def, object) \
284 ASET ((rfont_def), 2, (object))
285 #define RFONT_DEF_SCORE(rfont_def) XINT (AREF (rfont_def, 3))
286 #define RFONT_DEF_SET_SCORE(rfont_def, score) \
287 ASET ((rfont_def), 3, make_number (score))
288 #define RFONT_DEF_NEW(rfont_def, font_def) \
289 do { \
290 (rfont_def) = Fmake_vector (make_number (4), Qnil); \
291 ASET ((rfont_def), 1, (font_def)); \
292 RFONT_DEF_SET_SCORE ((rfont_def), 0); \
293 } while (0)
296 /* Return the element of FONTSET for the character C. If FONTSET is a
297 base fontset other then the default fontset and FONTSET doesn't
298 contain information for C, return the information in the default
299 fontset. */
301 #define FONTSET_REF(fontset, c) \
302 (EQ (fontset, Vdefault_fontset) \
303 ? CHAR_TABLE_REF (fontset, c) \
304 : fontset_ref ((fontset), (c)))
306 static Lisp_Object
307 fontset_ref (fontset, c)
308 Lisp_Object fontset;
309 int c;
311 Lisp_Object elt;
313 elt = CHAR_TABLE_REF (fontset, c);
314 if (NILP (elt) && ! EQ (fontset, Vdefault_fontset)
315 /* Don't check Vdefault_fontset for a realized fontset. */
316 && NILP (FONTSET_BASE (fontset)))
317 elt = CHAR_TABLE_REF (Vdefault_fontset, c);
318 return elt;
321 /* Set elements of FONTSET for characters in RANGE to the value ELT.
322 RANGE is a cons (FROM . TO), where FROM and TO are character codes
323 specifying a range. */
325 #define FONTSET_SET(fontset, range, elt) \
326 Fset_char_table_range ((fontset), (range), (elt))
329 /* Modify the elements of FONTSET for characters in RANGE by replacing
330 with ELT or adding ELT. RANGE is a cons (FROM . TO), where FROM
331 and TO are character codes specifying a range. If ADD is nil,
332 replace with ELT, if ADD is `prepend', prepend ELT, otherwise,
333 append ELT. */
335 #define FONTSET_ADD(fontset, range, elt, add) \
336 (NILP (add) \
337 ? (NILP (range) \
338 ? (FONTSET_FALLBACK (fontset) = Fmake_vector (make_number (1), (elt))) \
339 : Fset_char_table_range ((fontset), (range), \
340 Fmake_vector (make_number (1), (elt)))) \
341 : fontset_add ((fontset), (range), (elt), (add)))
343 static Lisp_Object
344 fontset_add (fontset, range, elt, add)
345 Lisp_Object fontset, range, elt, add;
347 Lisp_Object args[2];
348 int idx = (EQ (add, Qappend) ? 0 : 1);
350 args[1 - idx] = Fmake_vector (make_number (1), elt);
352 if (CONSP (range))
354 int from = XINT (XCAR (range));
355 int to = XINT (XCDR (range));
356 int from1, to1;
358 do {
359 args[idx] = char_table_ref_and_range (fontset, from, &from1, &to1);
360 if (to < to1)
361 to1 = to;
362 char_table_set_range (fontset, from, to1,
363 NILP (args[idx]) ? args[1 - idx]
364 : Fvconcat (2, args));
365 from = to1 + 1;
366 } while (from < to);
368 else
370 args[idx] = FONTSET_FALLBACK (fontset);
371 FONTSET_FALLBACK (fontset)
372 = NILP (args[idx]) ? args[1 - idx] : Fvconcat (2, args);
374 return Qnil;
377 static int
378 fontset_compare_rfontdef (val1, val2)
379 const void *val1, *val2;
381 return (RFONT_DEF_SCORE (*(Lisp_Object *) val2)
382 - RFONT_DEF_SCORE (*(Lisp_Object *) val1));
385 /* Update FONT-GROUP which has this form:
386 [ CHARSET-ORDERED-LIST-TICK PREFERRED-RFONT-DEF
387 RFONT-DEF0 RFONT-DEF1 ... ]
388 Reorder RFONT-DEFs according to the current langauge, and update
389 CHARSET-ORDERED-LIST-TICK.
391 If PREFERRED_FAMILY is not nil, that family has the higher priority
392 if the encoding charsets or languages in font-specs are the same. */
394 extern Lisp_Object Fassoc_string ();
396 static void
397 reorder_font_vector (font_group, preferred_family)
398 Lisp_Object font_group;
399 Lisp_Object preferred_family;
401 int size;
402 int i;
403 int score_changed = 0;
405 size = ASIZE (font_group);
406 /* Exclude the tailing nil elements from the reordering. */
407 while (NILP (AREF (font_group, size - 1))) size--;
408 size -= 2;
410 for (i = 0; i < size; i++)
412 Lisp_Object rfont_def = AREF (font_group, i + 2);
413 Lisp_Object font_def = RFONT_DEF_FONT_DEF (rfont_def);
414 Lisp_Object font_spec = FONT_DEF_SPEC (font_def);
415 Lisp_Object lang = Ffont_get (font_spec, QClang);
416 Lisp_Object family = AREF (font_spec, FONT_FAMILY_INDEX);
417 Lisp_Object repertory = FONT_DEF_REPERTORY (font_def);
418 int score = 0;
420 if (! NILP (repertory))
422 Lisp_Object tail;
424 for (score = 0xFFFF, tail = Vcharset_ordered_list;
425 ! EQ (tail, Vcharset_non_preferred_head) && CONSP (tail);
426 score--, tail = XCDR (tail))
427 if (EQ (repertory, XCAR (tail)))
428 break;
429 if (EQ (tail, Vcharset_non_preferred_head))
430 score = 0;
432 else if (! NILP (lang))
434 if (EQ (lang, Vcurrent_iso639_language))
435 score = 0xFFFF;
436 else if (CONSP (Vcurrent_iso639_language))
437 score = ! NILP (Fmemq (lang, Vcurrent_iso639_language));
440 if (! NILP (preferred_family) && ! NILP (family))
442 if (fast_string_match_ignore_case (preferred_family,
443 SYMBOL_NAME (family)) < 0)
444 score |= 0x10000;
446 if (RFONT_DEF_SCORE (rfont_def) != score)
448 RFONT_DEF_SET_SCORE (rfont_def, score);
449 score_changed = 1;
453 if (score_changed)
454 qsort (XVECTOR (font_group)->contents + 2, size, sizeof (Lisp_Object),
455 fontset_compare_rfontdef);
457 ASET (font_group, 0, make_number (charset_ordered_list_tick));
460 /* Return RFONT-DEF (vector) in the realized fontset FONTSET for the
461 character C. If no font is found, return Qnil if there's a
462 possibility that the default fontset or the fallback font groups
463 have a proper font, and return Qt if not.
465 If a font is found but is not yet opened, open it (if FACE is not
466 NULL) or return Qnil (if FACE is NULL).
468 ID is a charset-id that must be preferred, or -1 meaning no
469 preference.
471 If FALLBACK is nonzero, search only fallback fonts. */
473 static Lisp_Object
474 fontset_find_font (fontset, c, face, id, fallback)
475 Lisp_Object fontset;
476 int c;
477 struct face *face;
478 int id, fallback;
480 Lisp_Object base_fontset, elt, vec;
481 int i, from, to;
482 FRAME_PTR f = XFRAME (FONTSET_FRAME (fontset));
484 base_fontset = FONTSET_BASE (fontset);
485 if (! fallback)
486 vec = CHAR_TABLE_REF (fontset, c);
487 else
488 vec = FONTSET_FALLBACK (fontset);
490 if (NILP (vec))
492 Lisp_Object range;
494 /* We have not yet decided a font for C. */
495 if (! face)
496 return Qnil;
497 if (! fallback)
499 elt = char_table_ref_and_range (base_fontset, c, &from, &to);
500 range = Fcons (make_number (from), make_number (to));
502 else
504 elt = FONTSET_FALLBACK (base_fontset);
506 if (NILP (elt))
508 /* This fontset doesn't specify any font for C. */
509 vec = make_number (0);
511 else if (ASIZE (elt) == 1 && NILP (AREF (elt, 0)))
513 /* Explicitly specified no font. */
514 vec = Qt;
516 else
518 /* Build a font-group vector [ -1 nil RFONT-DEF0 RFONT-DEF1 ... ],
519 where the first -1 is to force reordering of RFONT-DEFs. */
520 int size = ASIZE (elt);
521 int j;
523 vec = Fmake_vector (make_number (size + 2), Qnil);
524 ASET (vec, 0, make_number (-1));
525 for (i = j = 0; i < size; i++)
526 if (! NILP (AREF (elt, i)))
528 Lisp_Object rfont_def;
530 RFONT_DEF_NEW (rfont_def, AREF (elt, i));
531 ASET (vec, j + 2, rfont_def);
532 j++;
535 /* Then store it in the fontset. */
536 if (! fallback)
537 FONTSET_SET (fontset, range, vec);
538 else
539 FONTSET_FALLBACK (fontset) = vec;
542 if (! VECTORP (vec))
543 return (EQ (vec, Qt) ? Qt : Qnil);
545 if (ASIZE (vec) > 4 /* multiple RFONT-DEFs */
546 && XINT (AREF (vec, 0)) != charset_ordered_list_tick)
547 /* We have just created VEC,
548 or the charset priorities were changed. */
549 reorder_font_vector (vec, face->lface[LFACE_FAMILY_INDEX]);
550 i = 2;
551 if (id >= 0)
553 elt = AREF (vec, 1);
554 if (! NILP (elt)
555 && EQ (make_number (id), RFONT_DEF_REPERTORY (elt)))
556 i = 1;
557 else
559 for (; i < ASIZE (vec); i++)
561 elt = AREF (vec, i);
562 if (! NILP (elt)
563 && EQ (make_number (id), RFONT_DEF_REPERTORY (elt)))
564 break;
566 if (i < ASIZE (vec))
568 ASET (vec, 1, elt);
569 i = 1;
571 else
573 ASET (vec, 1, Qnil);
574 i = 2;
579 /* Find the first available font in the vector of RFONT-DEF. */
580 for (; i < ASIZE (vec); i++)
582 Lisp_Object font_def, font_entity, font_object;
584 elt = AREF (vec, i);
585 if (NILP (elt))
586 /* This is the sign of not to try fallback fonts. */
587 return Qt;
588 if (id >= 0 && i > 1 && EQ (AREF (vec, 1), elt))
589 /* This is already checked. */
590 continue;
591 if (INTEGERP (RFONT_DEF_FACE (elt))
592 && XINT (AREF (elt, 1)) < 0)
593 /* We couldn't open this font last time. */
594 continue;
596 font_object = RFONT_DEF_OBJECT (elt);
597 if (NILP (font_object))
599 Lisp_Object font_def = RFONT_DEF_FONT_DEF (elt);
601 if (! face)
602 /* We have not yet opened the font. */
603 return Qnil;
604 font_entity = font_find_for_lface (f, face->lface,
605 FONT_DEF_SPEC (font_def), -1);
606 if (NILP (font_entity))
608 /* Record that no font matches the spec. */
609 RFONT_DEF_SET_FACE (elt, -1);
610 continue;
612 font_object = font_open_for_lface (f, font_entity, face->lface, Qnil);
613 if (NILP (font_object))
615 /* Record that the font is unsable. */
616 RFONT_DEF_SET_FACE (elt, -1);
617 continue;
619 RFONT_DEF_SET_OBJECT (elt, font_object);
622 if (font_has_char (f, font_object, c))
623 return elt;
625 #if 0
626 /* The following code makes Emacs to find a font for C by fairly
627 exhausitive search. But, that takes long time especially for
628 X font backend. */
630 /* Try to find the different font maching with the current spec
631 and support C. */
632 font_def = RFONT_DEF_FONT_DEF (elt);
633 for (i++; i < ASIZE (vec); i++)
635 if (! EQ (RFONT_DEF_FONT_DEF (AREF (vec, i)), font_def))
636 break;
637 if (font_has_char (f, RFONT_DEF_OBJECT (AREF (vec, i)), c))
638 return AREF (vec, i);
640 /* Find an font-entity that support C. */
641 font_entity = font_find_for_lface (f, face->lface,
642 FONT_DEF_SPEC (font_def), c);
643 if (! NILP (font_entity))
645 Lisp_Object rfont_def, new_vec;
646 int j;
648 font_object = font_open_for_lface (f, font_entity, face->lface,
649 Qnil);
650 RFONT_DEF_NEW (rfont_def, font_def);
651 RFONT_DEF_SET_OBJECT (rfont_def, font_object);
652 RFONT_DEF_SET_SCORE (rfont_def, RFONT_DEF_SCORE (elt));
653 new_vec = Fmake_vector (make_number (ASIZE (vec) + 1), Qnil);
654 for (j = 0; j < i; j++)
655 ASET (new_vec, j, AREF (vec, j));
656 ASET (new_vec, j, rfont_def);
657 for (j++; j < ASIZE (new_vec); j++)
658 ASET (new_vec, j, AREF (vec, j - 1));
659 vec = new_vec;
660 return rfont_def;
662 i--;
663 #endif /* 0 */
666 FONTSET_SET (fontset, make_number (c), make_number (0));
667 return Qnil;
671 static Lisp_Object
672 fontset_font (fontset, c, face, id)
673 Lisp_Object fontset;
674 int c;
675 struct face *face;
676 int id;
678 Lisp_Object rfont_def;
679 Lisp_Object base_fontset;
681 /* Try a font-group for C. */
682 rfont_def = fontset_find_font (fontset, c, face, id, 0);
683 if (VECTORP (rfont_def))
684 return rfont_def;
685 if (EQ (rfont_def, Qt))
686 return Qnil;
687 base_fontset = FONTSET_BASE (fontset);
688 /* Try a font-group for C of the default fontset. */
689 if (! EQ (base_fontset, Vdefault_fontset))
691 if (NILP (FONTSET_DEFAULT (fontset)))
692 FONTSET_DEFAULT (fontset)
693 = make_fontset (FONTSET_FRAME (fontset), Qnil, Vdefault_fontset);
694 rfont_def = fontset_find_font (FONTSET_DEFAULT (fontset), c, face, id, 0);
695 if (VECTORP (rfont_def))
696 return (rfont_def);
699 /* Try a fallback font-group. */
700 rfont_def = fontset_find_font (fontset, c, face, id, 1);
701 if (! VECTORP (rfont_def)
702 && ! EQ (base_fontset, Vdefault_fontset))
703 /* Try a fallback font-group of the default fontset . */
704 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 rfont_def = fontset_font (fontset, c, face, id);
912 if (VECTORP (rfont_def))
914 if (INTEGERP (RFONT_DEF_FACE (rfont_def)))
915 face_id = XINT (RFONT_DEF_FACE (rfont_def));
916 else
918 Lisp_Object font_object;
920 font_object = RFONT_DEF_OBJECT (rfont_def);
921 face_id = face_for_font (f, font_object, face);
922 RFONT_DEF_SET_FACE (rfont_def, face_id);
925 else
927 if (INTEGERP (FONTSET_NOFONT_FACE (fontset)))
928 face_id = XINT (FONTSET_NOFONT_FACE (fontset));
929 else
931 face_id = face_for_font (f, Qnil, face);
932 FONTSET_NOFONT_FACE (fontset) = make_number (face_id);
935 xassert (face_id >= 0);
936 return face_id;
940 /* Make a realized fontset for ASCII face FACE on frame F from the
941 base fontset BASE_FONTSET_ID. If BASE_FONTSET_ID is -1, use the
942 default fontset as the base. Value is the id of the new fontset.
943 Called from realize_x_face. */
946 make_fontset_for_ascii_face (f, base_fontset_id, face)
947 FRAME_PTR f;
948 int base_fontset_id;
949 struct face *face;
951 Lisp_Object base_fontset, fontset, frame;
953 XSETFRAME (frame, f);
954 if (base_fontset_id >= 0)
956 base_fontset = FONTSET_FROM_ID (base_fontset_id);
957 if (!BASE_FONTSET_P (base_fontset))
958 base_fontset = FONTSET_BASE (base_fontset);
959 if (! BASE_FONTSET_P (base_fontset))
960 abort ();
962 else
963 base_fontset = Vdefault_fontset;
965 fontset = make_fontset (frame, Qnil, base_fontset);
966 return XINT (FONTSET_ID (fontset));
970 /* Return ENCODING or a cons of ENCODING and REPERTORY of the font
971 FONTNAME. ENCODING is a charset symbol that specifies the encoding
972 of the font. REPERTORY is a charset symbol or nil. */
974 Lisp_Object
975 find_font_encoding (fontname)
976 Lisp_Object fontname;
978 Lisp_Object tail, elt;
980 for (tail = Vfont_encoding_alist; CONSP (tail); tail = XCDR (tail))
982 elt = XCAR (tail);
983 if (CONSP (elt)
984 && STRINGP (XCAR (elt))
985 && fast_string_match_ignore_case (XCAR (elt), fontname) >= 0
986 && (SYMBOLP (XCDR (elt))
987 ? CHARSETP (XCDR (elt))
988 : CONSP (XCDR (elt)) && CHARSETP (XCAR (XCDR (elt)))))
989 return (XCDR (elt));
991 /* We don't know the encoding of this font. Let's assume `ascii'. */
992 return Qascii;
996 /* Cache data used by fontset_pattern_regexp. The car part is a
997 pattern string containing at least one wild card, the cdr part is
998 the corresponding regular expression. */
999 static Lisp_Object Vcached_fontset_data;
1001 #define CACHED_FONTSET_NAME (SDATA (XCAR (Vcached_fontset_data)))
1002 #define CACHED_FONTSET_REGEX (XCDR (Vcached_fontset_data))
1004 /* If fontset name PATTERN contains any wild card, return regular
1005 expression corresponding to PATTERN. */
1007 static Lisp_Object
1008 fontset_pattern_regexp (pattern)
1009 Lisp_Object pattern;
1011 if (!index (SDATA (pattern), '*')
1012 && !index (SDATA (pattern), '?'))
1013 /* PATTERN does not contain any wild cards. */
1014 return Qnil;
1016 if (!CONSP (Vcached_fontset_data)
1017 || strcmp (SDATA (pattern), CACHED_FONTSET_NAME))
1019 /* We must at first update the cached data. */
1020 unsigned char *regex, *p0, *p1;
1021 int ndashes = 0, nstars = 0;
1023 for (p0 = SDATA (pattern); *p0; p0++)
1025 if (*p0 == '-')
1026 ndashes++;
1027 else if (*p0 == '*')
1028 nstars++;
1031 /* If PATTERN is not full XLFD we conert "*" to ".*". Otherwise
1032 we convert "*" to "[^-]*" which is much faster in regular
1033 expression matching. */
1034 if (ndashes < 14)
1035 p1 = regex = (unsigned char *) alloca (SBYTES (pattern) + 2 * nstars + 1);
1036 else
1037 p1 = regex = (unsigned char *) alloca (SBYTES (pattern) + 5 * nstars + 1);
1039 *p1++ = '^';
1040 for (p0 = SDATA (pattern); *p0; p0++)
1042 if (*p0 == '*')
1044 if (ndashes < 14)
1045 *p1++ = '.';
1046 else
1047 *p1++ = '[', *p1++ = '^', *p1++ = '-', *p1++ = ']';
1048 *p1++ = '*';
1050 else if (*p0 == '?')
1051 *p1++ = '.';
1052 else
1053 *p1++ = *p0;
1055 *p1++ = '$';
1056 *p1++ = 0;
1058 Vcached_fontset_data = Fcons (build_string (SDATA (pattern)),
1059 build_string (regex));
1062 return CACHED_FONTSET_REGEX;
1065 /* Return ID of the base fontset named NAME. If there's no such
1066 fontset, return -1. NAME_PATTERN specifies how to treat NAME as this:
1067 0: pattern containing '*' and '?' as wildcards
1068 1: regular expression
1069 2: literal fontset name
1073 fs_query_fontset (name, name_pattern)
1074 Lisp_Object name;
1075 int name_pattern;
1077 Lisp_Object tem;
1078 int i;
1080 name = Fdowncase (name);
1081 if (name_pattern != 1)
1083 tem = Frassoc (name, Vfontset_alias_alist);
1084 if (NILP (tem))
1085 tem = Fassoc (name, Vfontset_alias_alist);
1086 if (CONSP (tem) && STRINGP (XCAR (tem)))
1087 name = XCAR (tem);
1088 else if (name_pattern == 0)
1090 tem = fontset_pattern_regexp (name);
1091 if (STRINGP (tem))
1093 name = tem;
1094 name_pattern = 1;
1099 for (i = 0; i < ASIZE (Vfontset_table); i++)
1101 Lisp_Object fontset, this_name;
1103 fontset = FONTSET_FROM_ID (i);
1104 if (NILP (fontset)
1105 || !BASE_FONTSET_P (fontset))
1106 continue;
1108 this_name = FONTSET_NAME (fontset);
1109 if (name_pattern == 1
1110 ? fast_string_match_ignore_case (name, this_name) >= 0
1111 : !strcasecmp (SDATA (name), SDATA (this_name)))
1112 return i;
1114 return -1;
1118 DEFUN ("query-fontset", Fquery_fontset, Squery_fontset, 1, 2, 0,
1119 doc: /* Return the name of a fontset that matches PATTERN.
1120 The value is nil if there is no matching fontset.
1121 PATTERN can contain `*' or `?' as a wildcard
1122 just as X font name matching algorithm allows.
1123 If REGEXPP is non-nil, PATTERN is a regular expression. */)
1124 (pattern, regexpp)
1125 Lisp_Object pattern, regexpp;
1127 Lisp_Object fontset;
1128 int id;
1130 (*check_window_system_func) ();
1132 CHECK_STRING (pattern);
1134 if (SCHARS (pattern) == 0)
1135 return Qnil;
1137 id = fs_query_fontset (pattern, !NILP (regexpp));
1138 if (id < 0)
1139 return Qnil;
1141 fontset = FONTSET_FROM_ID (id);
1142 return FONTSET_NAME (fontset);
1145 /* Return a list of base fontset names matching PATTERN on frame F. */
1147 Lisp_Object
1148 list_fontsets (f, pattern, size)
1149 FRAME_PTR f;
1150 Lisp_Object pattern;
1151 int size;
1153 Lisp_Object frame, regexp, val;
1154 int id;
1156 XSETFRAME (frame, f);
1158 regexp = fontset_pattern_regexp (pattern);
1159 val = Qnil;
1161 for (id = 0; id < ASIZE (Vfontset_table); id++)
1163 Lisp_Object fontset, name;
1165 fontset = FONTSET_FROM_ID (id);
1166 if (NILP (fontset)
1167 || !BASE_FONTSET_P (fontset)
1168 || !EQ (frame, FONTSET_FRAME (fontset)))
1169 continue;
1170 name = FONTSET_NAME (fontset);
1172 if (STRINGP (regexp)
1173 ? (fast_string_match (regexp, name) < 0)
1174 : strcmp (SDATA (pattern), SDATA (name)))
1175 continue;
1177 val = Fcons (Fcopy_sequence (FONTSET_NAME (fontset)), val);
1180 return val;
1184 /* Free all realized fontsets whose base fontset is BASE. */
1186 static void
1187 free_realized_fontsets (base)
1188 Lisp_Object base;
1190 int id;
1192 #if 0
1193 /* For the moment, this doesn't work because free_realized_face
1194 doesn't remove FACE from a cache. Until we find a solution, we
1195 suppress this code, and simply use Fclear_face_cache even though
1196 that is not efficient. */
1197 BLOCK_INPUT;
1198 for (id = 0; id < ASIZE (Vfontset_table); id++)
1200 Lisp_Object this = AREF (Vfontset_table, id);
1202 if (EQ (FONTSET_BASE (this), base))
1204 Lisp_Object tail;
1206 for (tail = FONTSET_FACE_ALIST (this); CONSP (tail);
1207 tail = XCDR (tail))
1209 FRAME_PTR f = XFRAME (FONTSET_FRAME (this));
1210 int face_id = XINT (XCDR (XCAR (tail)));
1211 struct face *face = FACE_FROM_ID (f, face_id);
1213 /* Face THIS itself is also freed by the following call. */
1214 free_realized_face (f, face);
1218 UNBLOCK_INPUT;
1219 #else /* not 0 */
1220 /* But, we don't have to call Fclear_face_cache if no fontset has
1221 been realized from BASE. */
1222 for (id = 0; id < ASIZE (Vfontset_table); id++)
1224 Lisp_Object this = AREF (Vfontset_table, id);
1226 if (CHAR_TABLE_P (this) && EQ (FONTSET_BASE (this), base))
1228 Fclear_face_cache (Qt);
1229 break;
1232 #endif /* not 0 */
1236 /* Check validity of NAME as a fontset name and return the
1237 corresponding fontset. If not valid, signal an error.
1238 If NAME is t, return Vdefault_fontset. */
1240 static Lisp_Object
1241 check_fontset_name (name)
1242 Lisp_Object name;
1244 int id;
1246 if (EQ (name, Qt))
1247 return Vdefault_fontset;
1249 CHECK_STRING (name);
1250 /* First try NAME as literal. */
1251 id = fs_query_fontset (name, 2);
1252 if (id < 0)
1253 /* For backward compatibility, try again NAME as pattern. */
1254 id = fs_query_fontset (name, 0);
1255 if (id < 0)
1256 error ("Fontset `%s' does not exist", SDATA (name));
1257 return FONTSET_FROM_ID (id);
1260 static void
1261 accumulate_script_ranges (arg, range, val)
1262 Lisp_Object arg, range, val;
1264 if (EQ (XCAR (arg), val))
1266 if (CONSP (range))
1267 XSETCDR (arg, Fcons (Fcons (XCAR (range), XCDR (range)), XCDR (arg)));
1268 else
1269 XSETCDR (arg, Fcons (Fcons (range, range), XCDR (arg)));
1274 /* Return an ASCII font name generated from fontset name NAME and
1275 font-spec ASCII_SPEC. NAME is a string conforming to XLFD. */
1277 static INLINE Lisp_Object
1278 generate_ascii_font_name (name, ascii_spec)
1279 Lisp_Object name, ascii_spec;
1281 Lisp_Object font_spec = Ffont_spec (0, NULL);
1282 Lisp_Object vec;
1283 int i;
1284 char xlfd[256];
1286 if (font_parse_xlfd (SDATA (name), font_spec) < 0)
1287 error ("Not an XLFD font name: %s", SDATA (name));
1288 for (i = FONT_FOUNDRY_INDEX; i < FONT_EXTRA_INDEX; i++)
1289 if (! NILP (AREF (ascii_spec, i)))
1290 ASET (font_spec, i, AREF (ascii_spec, i));
1291 i = font_unparse_xlfd (font_spec, 0, xlfd, 256);
1292 if (i < 0)
1293 error ("Not an XLFD font name: %s", SDATA (name));
1294 return make_unibyte_string (xlfd, i);
1297 /* Variables referred in set_fontset_font. They are set before
1298 map_charset_chars is called in Fset_fontset_font. */
1299 static Lisp_Object font_def_arg, add_arg;
1300 static int from_arg, to_arg;
1302 /* Callback function for map_charset_chars in Fset_fontset_font. In
1303 FONTSET, set font_def_arg in a fashion specified by add_arg for
1304 characters in RANGE while ignoring the range between from_arg and
1305 to_arg. */
1307 static void
1308 set_fontset_font (fontset, range)
1309 Lisp_Object fontset, range;
1311 if (from_arg < to_arg)
1313 int from = XINT (XCAR (range)), to = XINT (XCDR (range));
1315 if (from < from_arg)
1317 if (to > to_arg)
1319 Lisp_Object range2;
1321 range2 = Fcons (make_number (to_arg), XCDR (range));
1322 FONTSET_ADD (fontset, range, font_def_arg, add_arg);
1323 to = to_arg;
1325 if (to > from_arg)
1326 range = Fcons (XCAR (range), make_number (from_arg));
1328 else if (to <= to_arg)
1329 return;
1330 else
1332 if (from < to_arg)
1333 range = Fcons (make_number (to_arg), XCDR (range));
1336 FONTSET_ADD (fontset, range, font_def_arg, add_arg);
1339 extern Lisp_Object QCfamily, QCregistry;
1341 DEFUN ("set-fontset-font", Fset_fontset_font, Sset_fontset_font, 3, 5, 0,
1342 doc: /*
1343 Modify fontset NAME to use FONT-SPEC for TARGET characters.
1345 TARGET may be a cons; (FROM . TO), where FROM and TO are characters.
1346 In that case, use FONT-SPEC for all characters in the range FROM and
1347 TO (inclusive).
1349 TARGET may be a script name symbol. In that case, use FONT-SPEC for
1350 all characters that belong to the script.
1352 TARGET may be a charset. In that case, use FONT-SPEC for all
1353 characters in the charset.
1355 TARGET may be nil. In that case, use FONT-SPEC for any characters for
1356 that no FONT-SPEC is specified.
1358 FONT-SPEC may one of these:
1359 * A font-spec object made by the function `font-spec' (which see).
1360 * A cons (FAMILY . REGISTRY), where FAMILY is a font family name and
1361 REGISTRY is a font registry name. FAMILY may contain foundry
1362 name, and REGISTRY may contain encoding name.
1363 * A font name string.
1364 * nil, which explicitly specifies that there's no font for TARGET.
1366 Optional 4th argument FRAME, if non-nil, is a frame. This argument is
1367 kept for backward compatibility and has no meaning.
1369 Optional 5th argument ADD, if non-nil, specifies how to add FONT-SPEC
1370 to the font specifications for TARGET previously set. If it is
1371 `prepend', FONT-SPEC is prepended. If it is `append', FONT-SPEC is
1372 appended. By default, FONT-SPEC overrides the previous settings. */)
1373 (name, target, font_spec, frame, add)
1374 Lisp_Object name, target, font_spec, frame, add;
1376 Lisp_Object fontset;
1377 Lisp_Object font_def, registry, family;
1378 Lisp_Object range_list;
1379 struct charset *charset = NULL;
1381 fontset = check_fontset_name (name);
1383 /* The arg FRAME is kept for backward compatibility. We only check
1384 the validity. */
1385 if (!NILP (frame))
1386 CHECK_LIVE_FRAME (frame);
1388 if (CONSP (font_spec))
1390 Lisp_Object spec = Ffont_spec (0, NULL);
1392 font_parse_family_registry (XCAR (font_spec), XCDR (font_spec), spec);
1393 font_spec = spec;
1395 else if (STRINGP (font_spec))
1397 Lisp_Object args[2];
1398 extern Lisp_Object QCname;
1400 args[0] = QCname;
1401 args[1] = font_spec;
1402 font_spec = Ffont_spec (2, args);
1404 else if (! NILP (font_spec) && ! FONT_SPEC_P (font_spec))
1405 Fsignal (Qfont, list2 (build_string ("Invalid font-spec"), font_spec));
1407 if (! NILP (font_spec))
1409 Lisp_Object encoding, repertory;
1411 family = AREF (font_spec, FONT_FAMILY_INDEX);
1412 if (! NILP (family) )
1413 family = SYMBOL_NAME (family);
1414 registry = AREF (font_spec, FONT_REGISTRY_INDEX);
1415 if (! NILP (registry))
1416 registry = Fdowncase (SYMBOL_NAME (registry));
1417 encoding = find_font_encoding (concat3 (family, build_string ("-"),
1418 registry));
1419 if (NILP (encoding))
1420 encoding = Qascii;
1422 if (SYMBOLP (encoding))
1424 CHECK_CHARSET (encoding);
1425 encoding = repertory = CHARSET_SYMBOL_ID (encoding);
1427 else
1429 repertory = XCDR (encoding);
1430 encoding = XCAR (encoding);
1431 CHECK_CHARSET (encoding);
1432 encoding = CHARSET_SYMBOL_ID (encoding);
1433 if (! NILP (repertory) && SYMBOLP (repertory))
1435 CHECK_CHARSET (repertory);
1436 repertory = CHARSET_SYMBOL_ID (repertory);
1439 FONT_DEF_NEW (font_def, font_spec, encoding, repertory);
1441 else
1442 font_def = Qnil;
1444 if (CHARACTERP (target))
1445 range_list = Fcons (Fcons (target, target), Qnil);
1446 else if (CONSP (target))
1448 Lisp_Object from, to;
1450 from = Fcar (target);
1451 to = Fcdr (target);
1452 CHECK_CHARACTER (from);
1453 CHECK_CHARACTER (to);
1454 range_list = Fcons (target, Qnil);
1456 else if (SYMBOLP (target) && !NILP (target))
1458 Lisp_Object script_list;
1459 Lisp_Object val;
1461 range_list = Qnil;
1462 script_list = XCHAR_TABLE (Vchar_script_table)->extras[0];
1463 if (! NILP (Fmemq (target, script_list)))
1465 val = Fcons (target, Qnil);
1466 map_char_table (accumulate_script_ranges, Qnil, Vchar_script_table,
1467 val);
1468 range_list = XCDR (val);
1469 if (EQ (target, Qlatin) && NILP (FONTSET_ASCII (fontset)))
1471 if (VECTORP (font_spec))
1472 val = generate_ascii_font_name (FONTSET_NAME (fontset),
1473 font_spec);
1474 else
1475 val = font_spec;
1476 FONTSET_ASCII (fontset) = val;
1479 if (CHARSETP (target))
1481 if (EQ (target, Qascii) && NILP (FONTSET_ASCII (fontset)))
1483 if (VECTORP (font_spec))
1484 font_spec = generate_ascii_font_name (FONTSET_NAME (fontset),
1485 font_spec);
1486 FONTSET_ASCII (fontset) = font_spec;
1487 range_list = Fcons (Fcons (make_number (0), make_number (127)),
1488 Qnil);
1490 else
1492 CHECK_CHARSET_GET_CHARSET (target, charset);
1495 else if (NILP (range_list))
1496 error ("Invalid script or charset name: %s",
1497 SDATA (SYMBOL_NAME (target)));
1499 else if (NILP (target))
1500 range_list = Fcons (Qnil, Qnil);
1501 else
1502 error ("Invalid target for setting a font");
1505 if (charset)
1507 font_def_arg = font_def;
1508 add_arg = add;
1509 if (NILP (range_list))
1510 from_arg = to_arg = 0;
1511 else
1512 from_arg = XINT (XCAR (XCAR (range_list))),
1513 to_arg = XINT (XCDR (XCAR (range_list)));
1515 map_charset_chars (set_fontset_font, Qnil, fontset, charset,
1516 CHARSET_MIN_CODE (charset),
1517 CHARSET_MAX_CODE (charset));
1519 for (; CONSP (range_list); range_list = XCDR (range_list))
1520 FONTSET_ADD (fontset, XCAR (range_list), font_def, add);
1522 /* Free all realized fontsets whose base is FONTSET. This way, the
1523 specified character(s) are surely redisplayed by a correct
1524 font. */
1525 free_realized_fontsets (fontset);
1527 return Qnil;
1531 DEFUN ("new-fontset", Fnew_fontset, Snew_fontset, 2, 2, 0,
1532 doc: /* Create a new fontset NAME from font information in FONTLIST.
1534 FONTLIST is an alist of scripts vs the corresponding font specification list.
1535 Each element of FONTLIST has the form (SCRIPT FONT-SPEC ...), where a
1536 character of SCRIPT is displayed by a font that matches one of
1537 FONT-SPEC.
1539 SCRIPT is a symbol that appears in the first extra slot of the
1540 char-table `char-script-table'.
1542 FONT-SPEC is a vector, a cons, or a string. See the documentation of
1543 `set-fontset-font' for the meaning. */)
1544 (name, fontlist)
1545 Lisp_Object name, fontlist;
1547 Lisp_Object fontset;
1548 Lisp_Object val;
1549 int id;
1551 CHECK_STRING (name);
1552 CHECK_LIST (fontlist);
1554 name = Fdowncase (name);
1555 id = fs_query_fontset (name, 0);
1556 if (id < 0)
1558 Lisp_Object font_spec = Ffont_spec (0, NULL);
1559 Lisp_Object short_name;
1560 char xlfd[256];
1561 int len;
1563 if (font_parse_xlfd (SDATA (name), font_spec) < 0)
1564 error ("Fontset name must be in XLFD format");
1565 short_name = AREF (font_spec, FONT_REGISTRY_INDEX);
1566 if (strncmp (SDATA (SYMBOL_NAME (short_name)), "fontset-", 8)
1567 || SBYTES (SYMBOL_NAME (short_name)) < 9)
1568 error ("Registry field of fontset name must be \"fontset-*\"");
1569 Vfontset_alias_alist = Fcons (Fcons (name, SYMBOL_NAME (short_name)),
1570 Vfontset_alias_alist);
1571 ASET (font_spec, FONT_REGISTRY_INDEX, Qiso8859_1);
1572 fontset = make_fontset (Qnil, name, Qnil);
1573 len = font_unparse_xlfd (font_spec, 0, xlfd, 256);
1574 if (len < 0)
1575 error ("Invalid fontset name (perhaps too long): %s", SDATA (name));
1576 FONTSET_ASCII (fontset) = make_unibyte_string (xlfd, len);
1578 else
1580 fontset = FONTSET_FROM_ID (id);;
1581 free_realized_fontsets (fontset);
1582 Fset_char_table_range (fontset, Qt, Qnil);
1585 for (; ! NILP (fontlist); fontlist = Fcdr (fontlist))
1587 Lisp_Object elt, script;
1589 elt = Fcar (fontlist);
1590 script = Fcar (elt);
1591 elt = Fcdr (elt);
1592 if (CONSP (elt) && (NILP (XCDR (elt)) || CONSP (XCDR (elt))))
1593 for (; CONSP (elt); elt = XCDR (elt))
1594 Fset_fontset_font (name, script, XCAR (elt), Qnil, Qappend);
1595 else
1596 Fset_fontset_font (name, script, elt, Qnil, Qappend);
1598 return name;
1602 /* Alist of automatically created fontsets. Each element is a cons
1603 (FONT-SPEC . FONTSET-ID). */
1604 static Lisp_Object auto_fontset_alist;
1607 fontset_from_font (font_object)
1608 Lisp_Object font_object;
1610 Lisp_Object font_name = font_get_name (font_object);
1611 Lisp_Object font_spec = Fcopy_font_spec (font_object);
1612 Lisp_Object fontset_spec, alias, name, fontset;
1613 Lisp_Object val;
1614 int i;
1616 val = assoc_no_quit (font_spec, auto_fontset_alist);
1617 if (CONSP (val))
1618 return XINT (FONTSET_ID (XCDR (val)));
1619 if (NILP (auto_fontset_alist))
1620 alias = intern ("fontset-startup");
1621 else
1623 char temp[32];
1624 int len = XINT (Flength (auto_fontset_alist));
1626 sprintf (temp, "fontset-auto%d", len);
1627 alias = intern (temp);
1629 fontset_spec = Fcopy_font_spec (font_spec);
1630 ASET (fontset_spec, FONT_REGISTRY_INDEX, alias);
1631 name = Ffont_xlfd_name (fontset_spec);
1632 if (NILP (name))
1633 abort ();
1634 fontset = make_fontset (Qnil, name, Qnil);
1635 Vfontset_alias_alist = Fcons (Fcons (name, SYMBOL_NAME (alias)),
1636 Vfontset_alias_alist);
1637 alias = Fdowncase (AREF (font_object, FONT_NAME_INDEX));
1638 Vfontset_alias_alist = Fcons (Fcons (name, alias), Vfontset_alias_alist);
1639 auto_fontset_alist = Fcons (Fcons (font_spec, fontset), auto_fontset_alist);
1640 FONTSET_ASCII (fontset) = font_name;
1641 ASET (font_spec, FONT_FOUNDRY_INDEX, Qnil);
1642 ASET (font_spec, FONT_ADSTYLE_INDEX, Qnil);
1643 for (i = FONT_WEIGHT_INDEX; i < FONT_EXTRA_INDEX; i++)
1644 ASET (font_spec, i, Qnil);
1645 Fset_fontset_font (name, Qlatin, font_spec, Qnil, Qnil);
1646 font_spec = Fcopy_font_spec (font_spec);
1647 ASET (font_spec, FONT_REGISTRY_INDEX, Qiso10646_1);
1648 Fset_fontset_font (name, Qnil, font_spec, Qnil, Qnil);
1649 return XINT (FONTSET_ID (fontset));
1652 DEFUN ("font-info", Ffont_info, Sfont_info, 1, 2, 0,
1653 doc: /* Return information about a font named NAME on frame FRAME.
1654 If FRAME is omitted or nil, use the selected frame.
1655 The returned value is a vector of OPENED-NAME, FULL-NAME, CHARSET, SIZE,
1656 HEIGHT, BASELINE-OFFSET, RELATIVE-COMPOSE, and DEFAULT-ASCENT,
1657 where
1658 OPENED-NAME is the name used for opening the font,
1659 FULL-NAME is the full name of the font,
1660 SIZE is the maximum bound width of the font,
1661 HEIGHT is the height of the font,
1662 BASELINE-OFFSET is the upward offset pixels from ASCII baseline,
1663 RELATIVE-COMPOSE and DEFAULT-ASCENT are the numbers controlling
1664 how to compose characters.
1665 If the named font is not yet loaded, return nil. */)
1666 (name, frame)
1667 Lisp_Object name, frame;
1669 FRAME_PTR f;
1670 struct font *font;
1671 Lisp_Object info;
1672 Lisp_Object font_object;
1674 (*check_window_system_func) ();
1676 CHECK_STRING (name);
1677 name = Fdowncase (name);
1678 if (NILP (frame))
1679 frame = selected_frame;
1680 CHECK_LIVE_FRAME (frame);
1681 f = XFRAME (frame);
1683 font_object = font_open_by_name (f, SDATA (name));
1684 if (NILP (font_object))
1685 return Qnil;
1686 font = XFONT_OBJECT (font_object);
1688 info = Fmake_vector (make_number (7), Qnil);
1689 XVECTOR (info)->contents[0] = AREF (font_object, FONT_NAME_INDEX);
1690 XVECTOR (info)->contents[1] = AREF (font_object, FONT_NAME_INDEX);
1691 XVECTOR (info)->contents[2] = make_number (font->pixel_size);
1692 XVECTOR (info)->contents[3] = make_number (font->height);
1693 XVECTOR (info)->contents[4] = make_number (font->baseline_offset);
1694 XVECTOR (info)->contents[5] = make_number (font->relative_compose);
1695 XVECTOR (info)->contents[6] = make_number (font->default_ascent);
1697 font_close_object (f, font_object);
1698 return info;
1702 /* Return a cons (FONT-NAME . GLYPH-CODE).
1703 FONT-NAME is the font name for the character at POSITION in the current
1704 buffer. This is computed from all the text properties and overlays
1705 that apply to POSITION. POSTION may be nil, in which case,
1706 FONT-NAME is the font name for display the character CH with the
1707 default face.
1709 GLYPH-CODE is the glyph code in the font to use for the character.
1711 If the 2nd optional arg CH is non-nil, it is a character to check
1712 the font instead of the character at POSITION.
1714 It returns nil in the following cases:
1716 (1) The window system doesn't have a font for the character (thus
1717 it is displayed by an empty box).
1719 (2) The character code is invalid.
1721 (3) If POSITION is not nil, and the current buffer is not displayed
1722 in any window.
1724 In addition, the returned font name may not take into account of
1725 such redisplay engine hooks as what used in jit-lock-mode if
1726 POSITION is currently not visible. */
1729 DEFUN ("internal-char-font", Finternal_char_font, Sinternal_char_font, 1, 2, 0,
1730 doc: /* For internal use only. */)
1731 (position, ch)
1732 Lisp_Object position, ch;
1734 EMACS_INT pos, pos_byte, dummy;
1735 int face_id;
1736 int c;
1737 struct frame *f;
1738 struct face *face;
1739 Lisp_Object rfont_def;
1740 int cs_id;
1742 if (NILP (position))
1744 CHECK_CHARACTER (ch);
1745 c = XINT (ch);
1746 f = XFRAME (selected_frame);
1747 face_id = DEFAULT_FACE_ID;
1748 pos = -1;
1749 cs_id = -1;
1751 else
1753 Lisp_Object window, charset;
1754 struct window *w;
1756 CHECK_NUMBER_COERCE_MARKER (position);
1757 pos = XINT (position);
1758 if (pos < BEGV || pos >= ZV)
1759 args_out_of_range_3 (position, make_number (BEGV), make_number (ZV));
1760 pos_byte = CHAR_TO_BYTE (pos);
1761 if (NILP (ch))
1762 c = FETCH_CHAR (pos_byte);
1763 else
1765 CHECK_NATNUM (ch);
1766 c = XINT (ch);
1768 window = Fget_buffer_window (Fcurrent_buffer (), Qnil);
1769 if (NILP (window))
1770 return Qnil;
1771 w = XWINDOW (window);
1772 f = XFRAME (w->frame);
1773 face_id = face_at_buffer_position (w, pos, -1, -1, &dummy, pos + 100, 0);
1774 charset = Fget_char_property (position, Qcharset, Qnil);
1775 if (CHARSETP (charset))
1776 cs_id = XINT (CHARSET_SYMBOL_ID (charset));
1777 else
1778 cs_id = -1;
1780 if (! CHAR_VALID_P (c, 0))
1781 return Qnil;
1782 face_id = FACE_FOR_CHAR (f, FACE_FROM_ID (f, face_id), c, pos, Qnil);
1783 face = FACE_FROM_ID (f, face_id);
1784 if (face->font)
1786 struct font *font = face->font;
1787 unsigned code = font->driver->encode_char (font, c);
1788 Lisp_Object fontname = font->props[FONT_NAME_INDEX];
1789 /* Assignment to EMACS_INT stops GCC whining about limited range
1790 of data type. */
1791 EMACS_INT cod = code;
1793 if (code == FONT_INVALID_CODE)
1794 return Qnil;
1795 if (cod <= MOST_POSITIVE_FIXNUM)
1796 return Fcons (fontname, make_number (code));
1797 return Fcons (fontname, Fcons (make_number (code >> 16),
1798 make_number (code & 0xFFFF)));
1800 return Qnil;
1804 DEFUN ("fontset-info", Ffontset_info, Sfontset_info, 1, 2, 0,
1805 doc: /* Return information about a fontset FONTSET on frame FRAME.
1806 The value is a char-table of which elements has this form.
1808 ((FONT-PATTERN OPENED-FONT ...) ...)
1810 FONT-PATTERN is a vector:
1812 [ FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY ]
1814 or a string of font name pattern.
1816 OPENED-FONT is a name of a font actually opened.
1818 The char-table has one extra slot. The value is a char-table
1819 containing the information about the derived fonts from the default
1820 fontset. The format is the same as abobe. */)
1821 (fontset, frame)
1822 Lisp_Object fontset, frame;
1824 FRAME_PTR f;
1825 Lisp_Object *realized[2], fontsets[2], tables[2];
1826 Lisp_Object val, elt;
1827 int c, i, j, k;
1829 (*check_window_system_func) ();
1831 fontset = check_fontset_name (fontset);
1833 if (NILP (frame))
1834 frame = selected_frame;
1835 CHECK_LIVE_FRAME (frame);
1836 f = XFRAME (frame);
1838 /* Recode fontsets realized on FRAME from the base fontset FONTSET
1839 in the table `realized'. */
1840 realized[0] = (Lisp_Object *) alloca (sizeof (Lisp_Object)
1841 * ASIZE (Vfontset_table));
1842 for (i = j = 0; i < ASIZE (Vfontset_table); i++)
1844 elt = FONTSET_FROM_ID (i);
1845 if (!NILP (elt)
1846 && EQ (FONTSET_BASE (elt), fontset)
1847 && EQ (FONTSET_FRAME (elt), frame))
1848 realized[0][j++] = elt;
1850 realized[0][j] = Qnil;
1852 realized[1] = (Lisp_Object *) alloca (sizeof (Lisp_Object)
1853 * ASIZE (Vfontset_table));
1854 for (i = j = 0; ! NILP (realized[0][i]); i++)
1856 elt = FONTSET_DEFAULT (realized[0][i]);
1857 if (! NILP (elt))
1858 realized[1][j++] = elt;
1860 realized[1][j] = Qnil;
1862 tables[0] = Fmake_char_table (Qfontset_info, Qnil);
1863 tables[1] = Fmake_char_table (Qnil, Qnil);
1864 XCHAR_TABLE (tables[0])->extras[0] = tables[1];
1865 fontsets[0] = fontset;
1866 fontsets[1] = Vdefault_fontset;
1868 /* Accumulate information of the fontset in TABLE. The format of
1869 each element is ((FONT-SPEC OPENED-FONT ...) ...). */
1870 for (k = 0; k <= 1; k++)
1872 for (c = 0; c <= MAX_CHAR; )
1874 int from, to;
1876 if (c <= MAX_5_BYTE_CHAR)
1878 val = char_table_ref_and_range (fontsets[k], c, &from, &to);
1879 if (to > MAX_5_BYTE_CHAR)
1880 to = MAX_5_BYTE_CHAR;
1882 else
1884 val = FONTSET_FALLBACK (fontsets[k]);
1885 to = MAX_CHAR;
1887 if (VECTORP (val))
1889 Lisp_Object alist;
1891 /* At first, set ALIST to ((FONT-SPEC) ...). */
1892 for (alist = Qnil, i = 0; i < ASIZE (val); i++)
1893 if (! NILP (AREF (val, i)))
1894 alist = Fcons (Fcons (FONT_DEF_SPEC (AREF (val, i)), Qnil),
1895 alist);
1896 alist = Fnreverse (alist);
1898 /* Then store opend font names to cdr of each elements. */
1899 for (i = 0; ! NILP (realized[k][i]); i++)
1901 if (c <= MAX_5_BYTE_CHAR)
1902 val = FONTSET_REF (realized[k][i], c);
1903 else
1904 val = FONTSET_FALLBACK (realized[k][i]);
1905 if (! VECTORP (val))
1906 continue;
1907 /* VAL: [int ? [FACE-ID FONT-DEF FONT-OBJECT int] ... ] */
1908 for (j = 2; j < ASIZE (val); j++)
1910 elt = AREF (val, j);
1911 if (FONT_OBJECT_P (RFONT_DEF_OBJECT (elt)))
1913 Lisp_Object font_object = RFONT_DEF_OBJECT (elt);
1914 Lisp_Object slot, name;
1916 slot = Fassq (RFONT_DEF_SPEC (elt), alist);
1917 name = AREF (font_object, FONT_NAME_INDEX);
1918 if (NILP (Fmember (name, XCDR (slot))))
1919 nconc2 (slot, Fcons (name, Qnil));
1924 /* Store ALIST in TBL for characters C..TO. */
1925 if (c <= MAX_5_BYTE_CHAR)
1926 char_table_set_range (tables[k], c, to, alist);
1927 else
1928 XCHAR_TABLE (tables[k])->defalt = alist;
1930 /* At last, change each elements to font names. */
1931 for (; CONSP (alist); alist = XCDR (alist))
1933 elt = XCAR (alist);
1934 XSETCAR (elt, Ffont_xlfd_name (XCAR (elt)));
1937 c = to + 1;
1941 return tables[0];
1945 DEFUN ("fontset-font", Ffontset_font, Sfontset_font, 2, 3, 0,
1946 doc: /* Return a font name pattern for character CH in fontset NAME.
1947 If NAME is t, find a pattern in the default fontset.
1949 The value has the form (FAMILY . REGISTRY), where FAMILY is a font
1950 family name and REGISTRY is a font registry name. This is actually
1951 the first font name pattern for CH in the fontset or in the default
1952 fontset.
1954 If the 2nd optional arg ALL is non-nil, return a list of all font name
1955 patterns. */)
1956 (name, ch, all)
1957 Lisp_Object name, ch, all;
1959 int c;
1960 Lisp_Object fontset, elt, list, repertory, val;
1961 int i, j;
1963 fontset = check_fontset_name (name);
1965 CHECK_CHARACTER (ch);
1966 c = XINT (ch);
1967 list = Qnil;
1968 while (1)
1970 for (i = 0, elt = FONTSET_REF (fontset, c); i < 2;
1971 i++, elt = FONTSET_FALLBACK (fontset))
1972 if (VECTORP (elt))
1973 for (j = 0; j < ASIZE (elt); j++)
1975 val = AREF (elt, j);
1976 repertory = AREF (val, 1);
1977 if (INTEGERP (repertory))
1979 struct charset *charset = CHARSET_FROM_ID (XINT (repertory));
1981 if (! CHAR_CHARSET_P (c, charset))
1982 continue;
1984 else if (CHAR_TABLE_P (repertory))
1986 if (NILP (CHAR_TABLE_REF (repertory, c)))
1987 continue;
1989 val = AREF (val, 0);
1990 val = Fcons (AREF (val, 0), AREF (val, 5));
1991 if (NILP (all))
1992 return val;
1993 list = Fcons (val, list);
1995 if (EQ (fontset, Vdefault_fontset))
1996 break;
1997 fontset = Vdefault_fontset;
1999 return (Fnreverse (list));
2002 DEFUN ("fontset-list", Ffontset_list, Sfontset_list, 0, 0, 0,
2003 doc: /* Return a list of all defined fontset names. */)
2006 Lisp_Object fontset, list;
2007 int i;
2009 list = Qnil;
2010 for (i = 0; i < ASIZE (Vfontset_table); i++)
2012 fontset = FONTSET_FROM_ID (i);
2013 if (!NILP (fontset)
2014 && BASE_FONTSET_P (fontset))
2015 list = Fcons (FONTSET_NAME (fontset), list);
2018 return list;
2022 #ifdef FONTSET_DEBUG
2024 Lisp_Object
2025 dump_fontset (fontset)
2026 Lisp_Object fontset;
2028 Lisp_Object vec;
2030 vec = Fmake_vector (make_number (3), Qnil);
2031 ASET (vec, 0, FONTSET_ID (fontset));
2033 if (BASE_FONTSET_P (fontset))
2035 ASET (vec, 1, FONTSET_NAME (fontset));
2037 else
2039 Lisp_Object frame;
2041 frame = FONTSET_FRAME (fontset);
2042 if (FRAMEP (frame))
2044 FRAME_PTR f = XFRAME (frame);
2046 if (FRAME_LIVE_P (f))
2047 ASET (vec, 1,
2048 Fcons (FONTSET_NAME (FONTSET_BASE (fontset)), f->name));
2049 else
2050 ASET (vec, 1,
2051 Fcons (FONTSET_NAME (FONTSET_BASE (fontset)), Qnil));
2053 if (!NILP (FONTSET_DEFAULT (fontset)))
2054 ASET (vec, 2, FONTSET_ID (FONTSET_DEFAULT (fontset)));
2056 return vec;
2059 DEFUN ("fontset-list-all", Ffontset_list_all, Sfontset_list_all, 0, 0, 0,
2060 doc: /* Return a brief summary of all fontsets for debug use. */)
2063 Lisp_Object val;
2064 int i;
2066 for (i = 0, val = Qnil; i < ASIZE (Vfontset_table); i++)
2067 if (! NILP (AREF (Vfontset_table, i)))
2068 val = Fcons (dump_fontset (AREF (Vfontset_table, i)), val);
2069 return (Fnreverse (val));
2071 #endif /* FONTSET_DEBUG */
2073 void
2074 syms_of_fontset ()
2076 DEFSYM (Qfontset, "fontset");
2077 Fput (Qfontset, Qchar_table_extra_slots, make_number (9));
2078 DEFSYM (Qfontset_info, "fontset-info");
2079 Fput (Qfontset_info, Qchar_table_extra_slots, make_number (1));
2081 DEFSYM (Qprepend, "prepend");
2082 DEFSYM (Qappend, "append");
2083 DEFSYM (Qlatin, "latin");
2085 Vcached_fontset_data = Qnil;
2086 staticpro (&Vcached_fontset_data);
2088 Vfontset_table = Fmake_vector (make_number (32), Qnil);
2089 staticpro (&Vfontset_table);
2091 Vdefault_fontset = Fmake_char_table (Qfontset, Qnil);
2092 staticpro (&Vdefault_fontset);
2093 FONTSET_ID (Vdefault_fontset) = make_number (0);
2094 FONTSET_NAME (Vdefault_fontset)
2095 = build_string ("-*-*-*-*-*-*-*-*-*-*-*-*-fontset-default");
2096 ASET (Vfontset_table, 0, Vdefault_fontset);
2097 next_fontset_id = 1;
2099 auto_fontset_alist = Qnil;
2100 staticpro (&auto_fontset_alist);
2102 DEFVAR_LISP ("font-encoding-alist", &Vfont_encoding_alist,
2103 doc: /*
2104 Alist of fontname patterns vs the corresponding encoding and repertory info.
2105 Each element looks like (REGEXP . (ENCODING . REPERTORY)),
2106 where ENCODING is a charset or a char-table,
2107 and REPERTORY is a charset, a char-table, or nil.
2109 If ENCDING and REPERTORY are the same, the element can have the form
2110 \(REGEXP . ENCODING).
2112 ENCODING is for converting a character to a glyph code of the font.
2113 If ENCODING is a charset, encoding a character by the charset gives
2114 the corresponding glyph code. If ENCODING is a char-table, looking up
2115 the table by a character gives the corresponding glyph code.
2117 REPERTORY specifies a repertory of characters supported by the font.
2118 If REPERTORY is a charset, all characters beloging to the charset are
2119 supported. If REPERTORY is a char-table, all characters who have a
2120 non-nil value in the table are supported. It REPERTORY is nil, Emacs
2121 gets the repertory information by an opened font and ENCODING. */);
2122 Vfont_encoding_alist = Qnil;
2124 DEFVAR_LISP ("font-encoding-charset-alist", &Vfont_encoding_charset_alist,
2125 doc: /*
2126 Alist of charsets vs the charsets to determine the preferred font encoding.
2127 Each element looks like (CHARSET . ENCDOING-CHARSET),
2128 where ENCODING-CHARSET is a charset registered in the variable
2129 `font-encoding-alist' as ENCODING.
2131 When a text has a property `charset' and the value is CHARSET, a font
2132 whose encoding corresponds to ENCODING-CHARSET is preferred. */);
2133 Vfont_encoding_charset_alist = Qnil;
2135 DEFVAR_LISP ("use-default-ascent", &Vuse_default_ascent,
2136 doc: /*
2137 Char table of characters whose ascent values should be ignored.
2138 If an entry for a character is non-nil, the ascent value of the glyph
2139 is assumed to be what specified by _MULE_DEFAULT_ASCENT property of a font.
2141 This affects how a composite character which contains
2142 such a character is displayed on screen. */);
2143 Vuse_default_ascent = Qnil;
2145 DEFVAR_LISP ("ignore-relative-composition", &Vignore_relative_composition,
2146 doc: /*
2147 Char table of characters which is not composed relatively.
2148 If an entry for a character is non-nil, a composition sequence
2149 which contains that character is displayed so that
2150 the glyph of that character is put without considering
2151 an ascent and descent value of a previous character. */);
2152 Vignore_relative_composition = Qnil;
2154 DEFVAR_LISP ("alternate-fontname-alist", &Valternate_fontname_alist,
2155 doc: /* Alist of fontname vs list of the alternate fontnames.
2156 When a specified font name is not found, the corresponding
2157 alternate fontnames (if any) are tried instead. */);
2158 Valternate_fontname_alist = Qnil;
2160 DEFVAR_LISP ("fontset-alias-alist", &Vfontset_alias_alist,
2161 doc: /* Alist of fontset names vs the aliases. */);
2162 Vfontset_alias_alist = Fcons (Fcons (FONTSET_NAME (Vdefault_fontset),
2163 build_string ("fontset-default")),
2164 Qnil);
2166 DEFVAR_LISP ("vertical-centering-font-regexp",
2167 &Vvertical_centering_font_regexp,
2168 doc: /* *Regexp matching font names that require vertical centering on display.
2169 When a character is displayed with such fonts, the character is displayed
2170 at the vertical center of lines. */);
2171 Vvertical_centering_font_regexp = Qnil;
2173 DEFVAR_LISP ("otf-script-alist", &Votf_script_alist,
2174 doc: /* Alist of OpenType script tags vs the corresponding script names. */);
2175 Votf_script_alist = Qnil;
2177 defsubr (&Squery_fontset);
2178 defsubr (&Snew_fontset);
2179 defsubr (&Sset_fontset_font);
2180 defsubr (&Sfont_info);
2181 defsubr (&Sinternal_char_font);
2182 defsubr (&Sfontset_info);
2183 defsubr (&Sfontset_font);
2184 defsubr (&Sfontset_list);
2185 #ifdef FONTSET_DEBUG
2186 defsubr (&Sfontset_list_all);
2187 #endif
2190 /* arch-tag: ea861585-2f5f-4e5b-9849-d04a9c3a3537
2191 (do not change this comment) */