*** empty log message ***
[emacs.git] / src / fontset.c
blob80d4ea7780b5a5092998e5f73fdb6e651d4c56a9
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, or (at your option)
17 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; see the file COPYING. If not, write to
26 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 Boston, MA 02110-1301, USA. */
29 /* #define FONTSET_DEBUG */
31 #include <config.h>
33 #ifdef FONTSET_DEBUG
34 #include <stdio.h>
35 #endif
37 #include "lisp.h"
38 #include "blockinput.h"
39 #include "buffer.h"
40 #include "character.h"
41 #include "charset.h"
42 #include "ccl.h"
43 #include "keyboard.h"
44 #include "frame.h"
45 #include "dispextern.h"
46 #include "intervals.h"
47 #include "fontset.h"
48 #include "window.h"
49 #ifdef HAVE_X_WINDOWS
50 #include "xterm.h"
51 #endif
52 #ifdef WINDOWSNT
53 #include "w32term.h"
54 #endif
55 #ifdef MAC_OS
56 #include "macterm.h"
57 #endif
58 #include "termhooks.h"
60 #include "font.h"
62 #undef xassert
63 #ifdef FONTSET_DEBUG
64 #define xassert(X) do {if (!(X)) abort ();} while (0)
65 #undef INLINE
66 #define INLINE
67 #else /* not FONTSET_DEBUG */
68 #define xassert(X) (void) 0
69 #endif /* not FONTSET_DEBUG */
71 EXFUN (Fclear_face_cache, 1);
73 /* FONTSET
75 A fontset is a collection of font related information to give
76 similar appearance (style, etc) of characters. A fontset has two
77 roles. One is to use for the frame parameter `font' as if it is an
78 ASCII font. In that case, Emacs uses the font specified for
79 `ascii' script for the frame's default font.
81 Another role, the more important one, is to provide information
82 about which font to use for each non-ASCII character.
84 There are two kinds of fontsets; base and realized. A base fontset
85 is created by `new-fontset' from Emacs Lisp explicitly. A realized
86 fontset is created implicitly when a face is realized for ASCII
87 characters. A face is also realized for non-ASCII characters based
88 on an ASCII face. All of non-ASCII faces based on the same ASCII
89 face share the same realized fontset.
91 A fontset object is implemented by a char-table whose default value
92 and parent are always nil.
94 An element of a base fontset is a vector of FONT-DEFs which itself
95 is a vector [ FONT-SPEC ENCODING REPERTORY ].
97 An element of a realized fontset is nil, t, or a vector of this form:
99 [ CHARSET-ORDERED-LIST-TICK PREFERRED-RFONT-DEF
100 RFONT-DEF0 RFONT-DEF1 ... ]
102 RFONT-DEFn (i.e. Realized FONT-DEF) has this form:
104 [ FACE-ID FONT-DEF FONT-OBJECT SORTING-SCORE ]
106 RFONT-DEFn are automatically reordered by the current charset
107 priority list.
109 The value nil means that we have not yet generated the above vector
110 from the base of the fontset.
112 The value t means that no font is available for the corresponding
113 range of characters.
116 A fontset has 9 extra slots.
118 The 1st slot: the ID number of the fontset
120 The 2nd slot:
121 base: the name of the fontset
122 realized: nil
124 The 3rd slot:
125 base: nil
126 realized: the base fontset
128 The 4th slot:
129 base: nil
130 realized: the frame that the fontset belongs to
132 The 5th slot:
133 base: the font name for ASCII characters
134 realized: nil
136 The 6th slot:
137 base: nil
138 realized: the ID number of a face to use for characters that
139 has no font in a realized fontset.
141 The 7th slot:
142 base: nil
143 realized: Alist of font index vs the corresponding repertory
144 char-table.
146 The 8th slot:
147 base: nil
148 realized: If the base is not the default fontset, a fontset
149 realized from the default fontset, else nil.
151 The 9th slot:
152 base: Same as element value (but for fallback fonts).
153 realized: Likewise.
155 All fontsets are recorded in the vector Vfontset_table.
158 DEFAULT FONTSET
160 There's a special base fontset named `default fontset' which
161 defines the default font specifications. When a base fontset
162 doesn't specify a font for a specific character, the corresponding
163 value in the default fontset is used.
165 The parent of a realized fontset created for such a face that has
166 no fontset is the default fontset.
169 These structures are hidden from the other codes than this file.
170 The other codes handle fontsets only by their ID numbers. They
171 usually use the variable name `fontset' for IDs. But, in this
172 file, we always use varialbe name `id' for IDs, and name `fontset'
173 for an actual fontset object, i.e., char-table.
177 /********** VARIABLES and FUNCTION PROTOTYPES **********/
179 extern Lisp_Object Qfont;
180 static Lisp_Object Qfontset;
181 static Lisp_Object Qfontset_info;
182 static Lisp_Object Qprepend, Qappend;
183 static Lisp_Object Qlatin;
185 /* Vector containing all fontsets. */
186 static Lisp_Object Vfontset_table;
188 /* Next possibly free fontset ID. Usually this keeps the minimum
189 fontset ID not yet used. */
190 static int next_fontset_id;
192 /* The default fontset. This gives default FAMILY and REGISTRY of
193 font for each character. */
194 static Lisp_Object Vdefault_fontset;
196 Lisp_Object Vfont_encoding_alist;
197 Lisp_Object Vfont_encoding_charset_alist;
198 Lisp_Object Vuse_default_ascent;
199 Lisp_Object Vignore_relative_composition;
200 Lisp_Object Valternate_fontname_alist;
201 Lisp_Object Vfontset_alias_alist;
202 Lisp_Object Vvertical_centering_font_regexp;
203 Lisp_Object Votf_script_alist;
205 /* Check if any window system is used now. */
206 void (*check_window_system_func) P_ ((void));
209 /* Prototype declarations for static functions. */
210 static Lisp_Object fontset_add P_ ((Lisp_Object, Lisp_Object, Lisp_Object,
211 Lisp_Object));
212 static Lisp_Object fontset_find_font P_ ((Lisp_Object, int, struct face *,
213 int, int));
214 static void reorder_font_vector P_ ((Lisp_Object, Lisp_Object));
215 static Lisp_Object fontset_font P_ ((Lisp_Object, int, struct face *, int));
216 static Lisp_Object make_fontset P_ ((Lisp_Object, Lisp_Object, Lisp_Object));
217 static Lisp_Object fontset_pattern_regexp P_ ((Lisp_Object));
218 static void accumulate_script_ranges P_ ((Lisp_Object, Lisp_Object,
219 Lisp_Object));
220 Lisp_Object find_font_encoding P_ ((Lisp_Object));
222 static void set_fontset_font P_ ((Lisp_Object, Lisp_Object));
224 #ifdef FONTSET_DEBUG
226 /* Return 1 if ID is a valid fontset id, else return 0. */
228 static int
229 fontset_id_valid_p (id)
230 int id;
232 return (id >= 0 && id < ASIZE (Vfontset_table) - 1);
235 #endif
239 /********** MACROS AND FUNCTIONS TO HANDLE FONTSET **********/
241 /* Return the fontset with ID. No check of ID's validness. */
242 #define FONTSET_FROM_ID(id) AREF (Vfontset_table, id)
244 /* Macros to access special values of FONTSET. */
245 #define FONTSET_ID(fontset) XCHAR_TABLE (fontset)->extras[0]
247 /* Macros to access special values of (base) FONTSET. */
248 #define FONTSET_NAME(fontset) XCHAR_TABLE (fontset)->extras[1]
249 #define FONTSET_ASCII(fontset) XCHAR_TABLE (fontset)->extras[4]
250 #define FONTSET_SPEC(fontset) XCHAR_TABLE (fontset)->extras[5]
252 /* Macros to access special values of (realized) FONTSET. */
253 #define FONTSET_BASE(fontset) XCHAR_TABLE (fontset)->extras[2]
254 #define FONTSET_FRAME(fontset) XCHAR_TABLE (fontset)->extras[3]
255 #define FONTSET_OBJLIST(fontset) XCHAR_TABLE (fontset)->extras[4]
256 #define FONTSET_NOFONT_FACE(fontset) XCHAR_TABLE (fontset)->extras[5]
257 #define FONTSET_REPERTORY(fontset) XCHAR_TABLE (fontset)->extras[6]
258 #define FONTSET_DEFAULT(fontset) XCHAR_TABLE (fontset)->extras[7]
260 /* For both base and realized fontset. */
261 #define FONTSET_FALLBACK(fontset) XCHAR_TABLE (fontset)->extras[8]
263 #define BASE_FONTSET_P(fontset) (NILP (FONTSET_BASE (fontset)))
266 /* Macros for FONT-DEF and RFONT-DEF of fontset. */
267 #define FONT_DEF_NEW(font_def, font_spec, encoding, repertory) \
268 do { \
269 (font_def) = Fmake_vector (make_number (3), (font_spec)); \
270 ASET ((font_def), 1, encoding); \
271 ASET ((font_def), 2, repertory); \
272 } while (0)
274 #define FONT_DEF_SPEC(font_def) AREF (font_def, 0)
275 #define FONT_DEF_ENCODING(font_def) AREF (font_def, 1)
276 #define FONT_DEF_REPERTORY(font_def) AREF (font_def, 2)
278 #define RFONT_DEF_FACE(rfont_def) AREF (rfont_def, 0)
279 #define RFONT_DEF_SET_FACE(rfont_def, face_id) \
280 ASET ((rfont_def), 0, make_number (face_id))
281 #define RFONT_DEF_FONT_DEF(rfont_def) AREF (rfont_def, 1)
282 #define RFONT_DEF_SPEC(rfont_def) FONT_DEF_SPEC (AREF (rfont_def, 1))
283 #define RFONT_DEF_REPERTORY(rfont_def) FONT_DEF_REPERTORY (AREF (rfont_def, 1))
284 #define RFONT_DEF_OBJECT(rfont_def) AREF (rfont_def, 2)
285 #define RFONT_DEF_SET_OBJECT(rfont_def, object) \
286 ASET ((rfont_def), 2, (object))
287 #define RFONT_DEF_SCORE(rfont_def) XINT (AREF (rfont_def, 3))
288 #define RFONT_DEF_SET_SCORE(rfont_def, score) \
289 ASET ((rfont_def), 3, make_number (score))
290 #define RFONT_DEF_NEW(rfont_def, font_def) \
291 do { \
292 (rfont_def) = Fmake_vector (make_number (4), Qnil); \
293 ASET ((rfont_def), 1, (font_def)); \
294 RFONT_DEF_SET_SCORE ((rfont_def), 0); \
295 } while (0)
298 /* Return the element of FONTSET for the character C. If FONTSET is a
299 base fontset other then the default fontset and FONTSET doesn't
300 contain information for C, return the information in the default
301 fontset. */
303 #define FONTSET_REF(fontset, c) \
304 (EQ (fontset, Vdefault_fontset) \
305 ? CHAR_TABLE_REF (fontset, c) \
306 : fontset_ref ((fontset), (c)))
308 static Lisp_Object
309 fontset_ref (fontset, c)
310 Lisp_Object fontset;
311 int c;
313 Lisp_Object elt;
315 elt = CHAR_TABLE_REF (fontset, c);
316 if (NILP (elt) && ! EQ (fontset, Vdefault_fontset)
317 /* Don't check Vdefault_fontset for a realized fontset. */
318 && NILP (FONTSET_BASE (fontset)))
319 elt = CHAR_TABLE_REF (Vdefault_fontset, c);
320 return elt;
323 /* Set elements of FONTSET for characters in RANGE to the value ELT.
324 RANGE is a cons (FROM . TO), where FROM and TO are character codes
325 specifying a range. */
327 #define FONTSET_SET(fontset, range, elt) \
328 Fset_char_table_range ((fontset), (range), (elt))
331 /* Modify the elements of FONTSET for characters in RANGE by replacing
332 with ELT or adding ELT. RANGE is a cons (FROM . TO), where FROM
333 and TO are character codes specifying a range. If ADD is nil,
334 replace with ELT, if ADD is `prepend', prepend ELT, otherwise,
335 append ELT. */
337 #define FONTSET_ADD(fontset, range, elt, add) \
338 (NILP (add) \
339 ? (NILP (range) \
340 ? (FONTSET_FALLBACK (fontset) = Fmake_vector (make_number (1), (elt))) \
341 : Fset_char_table_range ((fontset), (range), \
342 Fmake_vector (make_number (1), (elt)))) \
343 : fontset_add ((fontset), (range), (elt), (add)))
345 static Lisp_Object
346 fontset_add (fontset, range, elt, add)
347 Lisp_Object fontset, range, elt, add;
349 Lisp_Object args[2];
350 int idx = (EQ (add, Qappend) ? 0 : 1);
352 args[1 - idx] = Fmake_vector (make_number (1), elt);
354 if (CONSP (range))
356 int from = XINT (XCAR (range));
357 int to = XINT (XCDR (range));
358 int from1, to1;
360 do {
361 args[idx] = char_table_ref_and_range (fontset, from, &from1, &to1);
362 if (to < to1)
363 to1 = to;
364 char_table_set_range (fontset, from, to1,
365 NILP (args[idx]) ? args[1 - idx]
366 : Fvconcat (2, args));
367 from = to1 + 1;
368 } while (from < to);
370 else
372 args[idx] = FONTSET_FALLBACK (fontset);
373 FONTSET_FALLBACK (fontset)
374 = NILP (args[idx]) ? args[1 - idx] : Fvconcat (2, args);
376 return Qnil;
379 static int
380 fontset_compare_rfontdef (val1, val2)
381 const void *val1, *val2;
383 return (RFONT_DEF_SCORE (*(Lisp_Object *) val2)
384 - RFONT_DEF_SCORE (*(Lisp_Object *) val1));
387 /* Update FONT-GROUP which has this form:
388 [ CHARSET-ORDERED-LIST-TICK PREFERRED-RFONT-DEF
389 RFONT-DEF0 RFONT-DEF1 ... ]
390 Reorder RFONT-DEFs according to the current langauge, and update
391 CHARSET-ORDERED-LIST-TICK.
393 If PREFERRED_FAMILY is not nil, that family has the higher priority
394 if the encoding charsets or languages in font-specs are the same. */
396 extern Lisp_Object Fassoc_string ();
398 static void
399 reorder_font_vector (font_group, preferred_family)
400 Lisp_Object font_group;
401 Lisp_Object preferred_family;
403 int size;
404 int i;
405 int score_changed = 0;
407 size = ASIZE (font_group);
408 /* Exclude the tailing nil elements from the reordering. */
409 while (NILP (AREF (font_group, size - 1))) size--;
410 size -= 2;
412 for (i = 0; i < size; i++)
414 Lisp_Object rfont_def = AREF (font_group, i + 2);
415 Lisp_Object font_def = RFONT_DEF_FONT_DEF (rfont_def);
416 Lisp_Object font_spec = FONT_DEF_SPEC (font_def);
417 Lisp_Object lang = Ffont_get (font_spec, QClang);
418 Lisp_Object family = AREF (font_spec, FONT_FAMILY_INDEX);
419 Lisp_Object repertory = FONT_DEF_REPERTORY (font_def);
420 int score = 0;
422 if (! NILP (repertory))
424 Lisp_Object tail;
426 for (score = 0xFFFF, tail = Vcharset_ordered_list;
427 ! EQ (tail, Vcharset_non_preferred_head) && CONSP (tail);
428 score--, tail = XCDR (tail))
429 if (EQ (repertory, XCAR (tail)))
430 break;
431 if (EQ (tail, Vcharset_non_preferred_head))
432 score = 0;
434 else if (! NILP (lang))
436 if (EQ (lang, Vcurrent_iso639_language))
437 score = 0xFFFF;
438 else if (CONSP (Vcurrent_iso639_language))
439 score = ! NILP (Fmemq (lang, Vcurrent_iso639_language));
442 if (! NILP (preferred_family) && ! NILP (family))
444 if (fast_string_match_ignore_case (preferred_family,
445 SYMBOL_NAME (family)) < 0)
446 score |= 0x10000;
448 if (RFONT_DEF_SCORE (rfont_def) != score)
450 RFONT_DEF_SET_SCORE (rfont_def, score);
451 score_changed = 1;
455 if (score_changed)
456 qsort (XVECTOR (font_group)->contents + 2, size, sizeof (Lisp_Object),
457 fontset_compare_rfontdef);
459 ASET (font_group, 0, make_number (charset_ordered_list_tick));
462 /* Return RFONT-DEF (vector) in the realized fontset FONTSET for the
463 character C. If no font is found, return Qnil if there's a
464 possibility that the default fontset or the fallback font groups
465 have a proper font, and return Qt if not.
467 If a font is found but is not yet opened, open it (if FACE is not
468 NULL) or return Qnil (if FACE is NULL).
470 ID is a charset-id that must be preferred, or -1 meaning no
471 preference.
473 If FALLBACK is nonzero, search only fallback fonts. */
475 static Lisp_Object
476 fontset_find_font (fontset, c, face, id, fallback)
477 Lisp_Object fontset;
478 int c;
479 struct face *face;
480 int id, fallback;
482 Lisp_Object base_fontset, elt, vec;
483 int i, from, to;
484 FRAME_PTR f = XFRAME (FONTSET_FRAME (fontset));
486 base_fontset = FONTSET_BASE (fontset);
487 if (! fallback)
488 vec = CHAR_TABLE_REF (fontset, c);
489 else
490 vec = FONTSET_FALLBACK (fontset);
492 if (NILP (vec))
494 Lisp_Object range;
496 /* We have not yet decided a font for C. */
497 if (! face)
498 return Qnil;
499 if (! fallback)
501 elt = char_table_ref_and_range (base_fontset, c, &from, &to);
502 range = Fcons (make_number (from), make_number (to));
504 else
506 elt = FONTSET_FALLBACK (base_fontset);
508 if (NILP (elt))
510 /* This fontset doesn't specify any font for C. */
511 vec = make_number (0);
513 else if (ASIZE (elt) == 1 && NILP (AREF (elt, 0)))
515 /* Explicitly specified no font. */
516 vec = Qt;
518 else
520 /* Build a font-group vector [ -1 nil RFONT-DEF0 RFONT-DEF1 ... ],
521 where the first -1 is to force reordering of RFONT-DEFs. */
522 int size = ASIZE (elt);
523 int j;
525 vec = Fmake_vector (make_number (size + 2), Qnil);
526 ASET (vec, 0, make_number (-1));
527 for (i = j = 0; i < size; i++)
528 if (! NILP (AREF (elt, i)))
530 Lisp_Object rfont_def;
532 RFONT_DEF_NEW (rfont_def, AREF (elt, i));
533 ASET (vec, j + 2, rfont_def);
534 j++;
537 /* Then store it in the fontset. */
538 if (! fallback)
539 FONTSET_SET (fontset, range, vec);
540 else
541 FONTSET_FALLBACK (fontset) = vec;
544 if (! VECTORP (vec))
545 return (EQ (vec, Qt) ? Qt : Qnil);
547 if (ASIZE (vec) > 4 /* multiple RFONT-DEFs */
548 && XINT (AREF (vec, 0)) != charset_ordered_list_tick)
549 /* We have just created VEC,
550 or the charset priorities were changed. */
551 reorder_font_vector (vec, face->lface[LFACE_FAMILY_INDEX]);
552 i = 2;
553 if (id >= 0)
555 elt = AREF (vec, 1);
556 if (! NILP (elt)
557 && EQ (make_number (id), RFONT_DEF_REPERTORY (elt)))
558 i = 1;
559 else
561 for (; i < ASIZE (vec); i++)
563 elt = AREF (vec, i);
564 if (! NILP (elt)
565 && EQ (make_number (id), RFONT_DEF_REPERTORY (elt)))
566 break;
568 if (i < ASIZE (vec))
570 ASET (vec, 1, elt);
571 i = 1;
573 else
575 ASET (vec, 1, Qnil);
576 i = 2;
581 /* Find the first available font in the vector of RFONT-DEF. */
582 for (; i < ASIZE (vec); i++)
584 Lisp_Object font_def, font_entity, font_object;
586 elt = AREF (vec, i);
587 if (NILP (elt))
588 /* This is the sign of not to try fallback fonts. */
589 return Qt;
590 if (id >= 0 && i > 1 && EQ (AREF (vec, 1), elt))
591 /* This is already checked. */
592 continue;
593 if (INTEGERP (RFONT_DEF_FACE (elt))
594 && XINT (AREF (elt, 1)) < 0)
595 /* We couldn't open this font last time. */
596 continue;
598 font_object = RFONT_DEF_OBJECT (elt);
599 if (NILP (font_object))
601 Lisp_Object font_def = RFONT_DEF_FONT_DEF (elt);
603 if (! face)
604 /* We have not yet opened the font. */
605 return Qnil;
606 font_entity = font_find_for_lface (f, face->lface,
607 FONT_DEF_SPEC (font_def), -1);
608 if (NILP (font_entity))
610 /* Record that no font matches the spec. */
611 RFONT_DEF_SET_FACE (elt, -1);
612 continue;
614 font_object = font_open_for_lface (f, font_entity, face->lface, Qnil);
615 if (NILP (font_object))
617 /* Record that the font is unsable. */
618 RFONT_DEF_SET_FACE (elt, -1);
619 continue;
621 RFONT_DEF_SET_OBJECT (elt, font_object);
624 if (font_has_char (f, font_object, c))
625 return elt;
627 #if 0
628 /* The following code makes Emacs to find a font for C by fairly
629 exhausitive search. But, that takes long time especially for
630 X font backend. */
632 /* Try to find the different font maching with the current spec
633 and support C. */
634 font_def = RFONT_DEF_FONT_DEF (elt);
635 for (i++; i < ASIZE (vec); i++)
637 if (! EQ (RFONT_DEF_FONT_DEF (AREF (vec, i)), font_def))
638 break;
639 if (font_has_char (f, RFONT_DEF_OBJECT (AREF (vec, i)), c))
640 return AREF (vec, i);
642 /* Find an font-entity that support C. */
643 font_entity = font_find_for_lface (f, face->lface,
644 FONT_DEF_SPEC (font_def), c);
645 if (! NILP (font_entity))
647 Lisp_Object rfont_def, new_vec;
648 int j;
650 font_object = font_open_for_lface (f, font_entity, face->lface,
651 Qnil);
652 RFONT_DEF_NEW (rfont_def, font_def);
653 RFONT_DEF_SET_OBJECT (rfont_def, font_object);
654 RFONT_DEF_SET_SCORE (rfont_def, RFONT_DEF_SCORE (elt));
655 new_vec = Fmake_vector (make_number (ASIZE (vec) + 1), Qnil);
656 for (j = 0; j < i; j++)
657 ASET (new_vec, j, AREF (vec, j));
658 ASET (new_vec, j, rfont_def);
659 for (j++; j < ASIZE (new_vec); j++)
660 ASET (new_vec, j, AREF (vec, j - 1));
661 vec = new_vec;
662 return rfont_def;
664 i--;
665 #endif /* 0 */
668 FONTSET_SET (fontset, make_number (c), make_number (0));
669 return Qnil;
673 static Lisp_Object
674 fontset_font (fontset, c, face, id)
675 Lisp_Object fontset;
676 int c;
677 struct face *face;
678 int id;
680 Lisp_Object rfont_def;
681 Lisp_Object base_fontset;
683 /* Try a font-group for C. */
684 rfont_def = fontset_find_font (fontset, c, face, id, 0);
685 if (VECTORP (rfont_def))
686 return rfont_def;
687 if (EQ (rfont_def, Qt))
688 return Qnil;
689 base_fontset = FONTSET_BASE (fontset);
690 /* Try a font-group for C of the default fontset. */
691 if (! EQ (base_fontset, Vdefault_fontset))
693 if (NILP (FONTSET_DEFAULT (fontset)))
694 FONTSET_DEFAULT (fontset)
695 = make_fontset (FONTSET_FRAME (fontset), Qnil, Vdefault_fontset);
696 rfont_def = fontset_find_font (FONTSET_DEFAULT (fontset), c, face, id, 0);
697 if (VECTORP (rfont_def))
698 return (rfont_def);
701 /* Try a fallback font-group. */
702 rfont_def = fontset_find_font (fontset, c, face, id, 1);
703 if (! VECTORP (rfont_def)
704 && ! EQ (base_fontset, Vdefault_fontset))
705 /* Try a fallback font-group of the default fontset . */
706 rfont_def = fontset_find_font (FONTSET_DEFAULT (fontset), c, face, id, 1);
708 if (! VECTORP (rfont_def))
709 /* Remeber that we have no font for C. */
710 FONTSET_SET (fontset, make_number (c), Qt);
712 return rfont_def;
715 /* Return a newly created fontset with NAME. If BASE is nil, make a
716 base fontset. Otherwise make a realized fontset whose base is
717 BASE. */
719 static Lisp_Object
720 make_fontset (frame, name, base)
721 Lisp_Object frame, name, base;
723 Lisp_Object fontset;
724 int size = ASIZE (Vfontset_table);
725 int id = next_fontset_id;
727 /* Find a free slot in Vfontset_table. Usually, next_fontset_id is
728 the next available fontset ID. So it is expected that this loop
729 terminates quickly. In addition, as the last element of
730 Vfontset_table is always nil, we don't have to check the range of
731 id. */
732 while (!NILP (AREF (Vfontset_table, id))) id++;
734 if (id + 1 == size)
735 Vfontset_table = larger_vector (Vfontset_table, size + 32, Qnil);
737 fontset = Fmake_char_table (Qfontset, Qnil);
739 FONTSET_ID (fontset) = make_number (id);
740 if (NILP (base))
742 FONTSET_NAME (fontset) = name;
744 else
746 FONTSET_NAME (fontset) = Qnil;
747 FONTSET_FRAME (fontset) = frame;
748 FONTSET_BASE (fontset) = base;
751 ASET (Vfontset_table, id, fontset);
752 next_fontset_id = id + 1;
753 return fontset;
757 /* Set the ASCII font of the default fontset to FONTNAME if that is
758 not yet set. */
759 void
760 set_default_ascii_font (fontname)
761 Lisp_Object fontname;
763 if (! STRINGP (FONTSET_ASCII (Vdefault_fontset)))
765 int id = fs_query_fontset (fontname, 2);
767 if (id >= 0)
768 fontname = FONTSET_ASCII (FONTSET_FROM_ID (id));
769 FONTSET_ASCII (Vdefault_fontset)= fontname;
774 /********** INTERFACES TO xfaces.c, xfns.c, and dispextern.h **********/
776 /* Return the name of the fontset who has ID. */
778 Lisp_Object
779 fontset_name (id)
780 int id;
782 Lisp_Object fontset;
784 fontset = FONTSET_FROM_ID (id);
785 return FONTSET_NAME (fontset);
789 /* Return the ASCII font name of the fontset who has ID. */
791 Lisp_Object
792 fontset_ascii (id)
793 int id;
795 Lisp_Object fontset, elt;
797 fontset= FONTSET_FROM_ID (id);
798 elt = FONTSET_ASCII (fontset);
799 if (CONSP (elt))
800 elt = XCAR (elt);
801 return elt;
804 void
805 free_realized_fontset (f, fontset)
806 FRAME_PTR f;
807 Lisp_Object fontset;
809 Lisp_Object tail;
811 return;
812 for (tail = FONTSET_OBJLIST (fontset); CONSP (tail); tail = XCDR (tail))
814 xassert (FONT_OBJECT_P (XCAR (tail)));
815 font_close_object (f, XCAR (tail));
819 /* Free fontset of FACE defined on frame F. Called from
820 free_realized_face. */
822 void
823 free_face_fontset (f, face)
824 FRAME_PTR f;
825 struct face *face;
827 Lisp_Object fontset;
829 fontset = FONTSET_FROM_ID (face->fontset);
830 if (NILP (fontset))
831 return;
832 xassert (! BASE_FONTSET_P (fontset));
833 xassert (f == XFRAME (FONTSET_FRAME (fontset)));
834 free_realized_fontset (f, fontset);
835 ASET (Vfontset_table, face->fontset, Qnil);
836 if (face->fontset < next_fontset_id)
837 next_fontset_id = face->fontset;
838 if (! NILP (FONTSET_DEFAULT (fontset)))
840 int id = XINT (FONTSET_ID (FONTSET_DEFAULT (fontset)));
842 fontset = AREF (Vfontset_table, id);
843 xassert (!NILP (fontset) && ! BASE_FONTSET_P (fontset));
844 xassert (f == XFRAME (FONTSET_FRAME (fontset)));
845 free_realized_fontset (f, fontset);
846 ASET (Vfontset_table, id, Qnil);
847 if (id < next_fontset_id)
848 next_fontset_id = face->fontset;
850 face->fontset = -1;
854 /* Return 1 if FACE is suitable for displaying character C.
855 Otherwise return 0. Called from the macro FACE_SUITABLE_FOR_CHAR_P
856 when C is not an ASCII character. */
859 face_suitable_for_char_p (face, c)
860 struct face *face;
861 int c;
863 Lisp_Object fontset, rfont_def;
865 fontset = FONTSET_FROM_ID (face->fontset);
866 rfont_def = fontset_font (fontset, c, NULL, -1);
867 return (VECTORP (rfont_def)
868 && INTEGERP (RFONT_DEF_FACE (rfont_def))
869 && face->id == XINT (RFONT_DEF_FACE (rfont_def)));
873 /* Return ID of face suitable for displaying character C on frame F.
874 FACE must be reazlied for ASCII characters in advance. Called from
875 the macro FACE_FOR_CHAR. */
878 face_for_char (f, face, c, pos, object)
879 FRAME_PTR f;
880 struct face *face;
881 int c, pos;
882 Lisp_Object object;
884 Lisp_Object fontset, rfont_def;
885 int face_id;
886 int id;
888 if (ASCII_CHAR_P (c))
889 return face->ascii_face->id;
891 xassert (fontset_id_valid_p (face->fontset));
892 fontset = FONTSET_FROM_ID (face->fontset);
893 xassert (!BASE_FONTSET_P (fontset));
894 if (pos < 0)
895 id = -1;
896 else
898 Lisp_Object charset;
900 charset = Fget_char_property (make_number (pos), Qcharset, object);
901 if (NILP (charset))
902 id = -1;
903 else if (CHARSETP (charset))
905 Lisp_Object val;
907 val = assoc_no_quit (charset, Vfont_encoding_charset_alist);
908 if (CONSP (val) && CHARSETP (XCDR (val)))
909 charset = XCDR (val);
910 id = XINT (CHARSET_SYMBOL_ID (charset));
913 rfont_def = fontset_font (fontset, c, face, id);
914 if (VECTORP (rfont_def))
916 if (INTEGERP (RFONT_DEF_FACE (rfont_def)))
917 face_id = XINT (RFONT_DEF_FACE (rfont_def));
918 else
920 Lisp_Object font_object;
922 font_object = RFONT_DEF_OBJECT (rfont_def);
923 face_id = face_for_font (f, font_object, face);
924 RFONT_DEF_SET_FACE (rfont_def, face_id);
927 else
929 if (INTEGERP (FONTSET_NOFONT_FACE (fontset)))
930 face_id = XINT (FONTSET_NOFONT_FACE (fontset));
931 else
933 face_id = face_for_font (f, Qnil, face);
934 FONTSET_NOFONT_FACE (fontset) = make_number (face_id);
937 xassert (face_id >= 0);
938 return face_id;
942 /* Make a realized fontset for ASCII face FACE on frame F from the
943 base fontset BASE_FONTSET_ID. If BASE_FONTSET_ID is -1, use the
944 default fontset as the base. Value is the id of the new fontset.
945 Called from realize_x_face. */
948 make_fontset_for_ascii_face (f, base_fontset_id, face)
949 FRAME_PTR f;
950 int base_fontset_id;
951 struct face *face;
953 Lisp_Object base_fontset, fontset, frame;
955 XSETFRAME (frame, f);
956 if (base_fontset_id >= 0)
958 base_fontset = FONTSET_FROM_ID (base_fontset_id);
959 if (!BASE_FONTSET_P (base_fontset))
960 base_fontset = FONTSET_BASE (base_fontset);
961 if (! BASE_FONTSET_P (base_fontset))
962 abort ();
964 else
965 base_fontset = Vdefault_fontset;
967 fontset = make_fontset (frame, Qnil, base_fontset);
968 return XINT (FONTSET_ID (fontset));
972 /* Return ENCODING or a cons of ENCODING and REPERTORY of the font
973 FONTNAME. ENCODING is a charset symbol that specifies the encoding
974 of the font. REPERTORY is a charset symbol or nil. */
976 Lisp_Object
977 find_font_encoding (fontname)
978 Lisp_Object fontname;
980 Lisp_Object tail, elt;
982 for (tail = Vfont_encoding_alist; CONSP (tail); tail = XCDR (tail))
984 elt = XCAR (tail);
985 if (CONSP (elt)
986 && STRINGP (XCAR (elt))
987 && fast_string_match_ignore_case (XCAR (elt), fontname) >= 0
988 && (SYMBOLP (XCDR (elt))
989 ? CHARSETP (XCDR (elt))
990 : CONSP (XCDR (elt)) && CHARSETP (XCAR (XCDR (elt)))))
991 return (XCDR (elt));
993 /* We don't know the encoding of this font. Let's assume `ascii'. */
994 return Qascii;
998 /* Cache data used by fontset_pattern_regexp. The car part is a
999 pattern string containing at least one wild card, the cdr part is
1000 the corresponding regular expression. */
1001 static Lisp_Object Vcached_fontset_data;
1003 #define CACHED_FONTSET_NAME (SDATA (XCAR (Vcached_fontset_data)))
1004 #define CACHED_FONTSET_REGEX (XCDR (Vcached_fontset_data))
1006 /* If fontset name PATTERN contains any wild card, return regular
1007 expression corresponding to PATTERN. */
1009 static Lisp_Object
1010 fontset_pattern_regexp (pattern)
1011 Lisp_Object pattern;
1013 if (!index (SDATA (pattern), '*')
1014 && !index (SDATA (pattern), '?'))
1015 /* PATTERN does not contain any wild cards. */
1016 return Qnil;
1018 if (!CONSP (Vcached_fontset_data)
1019 || strcmp (SDATA (pattern), CACHED_FONTSET_NAME))
1021 /* We must at first update the cached data. */
1022 unsigned char *regex, *p0, *p1;
1023 int ndashes = 0, nstars = 0;
1025 for (p0 = SDATA (pattern); *p0; p0++)
1027 if (*p0 == '-')
1028 ndashes++;
1029 else if (*p0 == '*')
1030 nstars++;
1033 /* If PATTERN is not full XLFD we conert "*" to ".*". Otherwise
1034 we convert "*" to "[^-]*" which is much faster in regular
1035 expression matching. */
1036 if (ndashes < 14)
1037 p1 = regex = (unsigned char *) alloca (SBYTES (pattern) + 2 * nstars + 1);
1038 else
1039 p1 = regex = (unsigned char *) alloca (SBYTES (pattern) + 5 * nstars + 1);
1041 *p1++ = '^';
1042 for (p0 = SDATA (pattern); *p0; p0++)
1044 if (*p0 == '*')
1046 if (ndashes < 14)
1047 *p1++ = '.';
1048 else
1049 *p1++ = '[', *p1++ = '^', *p1++ = '-', *p1++ = ']';
1050 *p1++ = '*';
1052 else if (*p0 == '?')
1053 *p1++ = '.';
1054 else
1055 *p1++ = *p0;
1057 *p1++ = '$';
1058 *p1++ = 0;
1060 Vcached_fontset_data = Fcons (build_string (SDATA (pattern)),
1061 build_string (regex));
1064 return CACHED_FONTSET_REGEX;
1067 /* Return ID of the base fontset named NAME. If there's no such
1068 fontset, return -1. NAME_PATTERN specifies how to treat NAME as this:
1069 0: pattern containing '*' and '?' as wildcards
1070 1: regular expression
1071 2: literal fontset name
1075 fs_query_fontset (name, name_pattern)
1076 Lisp_Object name;
1077 int name_pattern;
1079 Lisp_Object tem;
1080 int i;
1082 name = Fdowncase (name);
1083 if (name_pattern != 1)
1085 tem = Frassoc (name, Vfontset_alias_alist);
1086 if (NILP (tem))
1087 tem = Fassoc (name, Vfontset_alias_alist);
1088 if (CONSP (tem) && STRINGP (XCAR (tem)))
1089 name = XCAR (tem);
1090 else if (name_pattern == 0)
1092 tem = fontset_pattern_regexp (name);
1093 if (STRINGP (tem))
1095 name = tem;
1096 name_pattern = 1;
1101 for (i = 0; i < ASIZE (Vfontset_table); i++)
1103 Lisp_Object fontset, this_name;
1105 fontset = FONTSET_FROM_ID (i);
1106 if (NILP (fontset)
1107 || !BASE_FONTSET_P (fontset))
1108 continue;
1110 this_name = FONTSET_NAME (fontset);
1111 if (name_pattern == 1
1112 ? fast_string_match_ignore_case (name, this_name) >= 0
1113 : !strcasecmp (SDATA (name), SDATA (this_name)))
1114 return i;
1116 return -1;
1120 DEFUN ("query-fontset", Fquery_fontset, Squery_fontset, 1, 2, 0,
1121 doc: /* Return the name of a fontset that matches PATTERN.
1122 The value is nil if there is no matching fontset.
1123 PATTERN can contain `*' or `?' as a wildcard
1124 just as X font name matching algorithm allows.
1125 If REGEXPP is non-nil, PATTERN is a regular expression. */)
1126 (pattern, regexpp)
1127 Lisp_Object pattern, regexpp;
1129 Lisp_Object fontset;
1130 int id;
1132 (*check_window_system_func) ();
1134 CHECK_STRING (pattern);
1136 if (SCHARS (pattern) == 0)
1137 return Qnil;
1139 id = fs_query_fontset (pattern, !NILP (regexpp));
1140 if (id < 0)
1141 return Qnil;
1143 fontset = FONTSET_FROM_ID (id);
1144 return FONTSET_NAME (fontset);
1147 /* Return a list of base fontset names matching PATTERN on frame F. */
1149 Lisp_Object
1150 list_fontsets (f, pattern, size)
1151 FRAME_PTR f;
1152 Lisp_Object pattern;
1153 int size;
1155 Lisp_Object frame, regexp, val;
1156 int id;
1158 XSETFRAME (frame, f);
1160 regexp = fontset_pattern_regexp (pattern);
1161 val = Qnil;
1163 for (id = 0; id < ASIZE (Vfontset_table); id++)
1165 Lisp_Object fontset, name;
1167 fontset = FONTSET_FROM_ID (id);
1168 if (NILP (fontset)
1169 || !BASE_FONTSET_P (fontset)
1170 || !EQ (frame, FONTSET_FRAME (fontset)))
1171 continue;
1172 name = FONTSET_NAME (fontset);
1174 if (STRINGP (regexp)
1175 ? (fast_string_match (regexp, name) < 0)
1176 : strcmp (SDATA (pattern), SDATA (name)))
1177 continue;
1179 val = Fcons (Fcopy_sequence (FONTSET_NAME (fontset)), val);
1182 return val;
1186 /* Free all realized fontsets whose base fontset is BASE. */
1188 static void
1189 free_realized_fontsets (base)
1190 Lisp_Object base;
1192 int id;
1194 #if 0
1195 /* For the moment, this doesn't work because free_realized_face
1196 doesn't remove FACE from a cache. Until we find a solution, we
1197 suppress this code, and simply use Fclear_face_cache even though
1198 that is not efficient. */
1199 BLOCK_INPUT;
1200 for (id = 0; id < ASIZE (Vfontset_table); id++)
1202 Lisp_Object this = AREF (Vfontset_table, id);
1204 if (EQ (FONTSET_BASE (this), base))
1206 Lisp_Object tail;
1208 for (tail = FONTSET_FACE_ALIST (this); CONSP (tail);
1209 tail = XCDR (tail))
1211 FRAME_PTR f = XFRAME (FONTSET_FRAME (this));
1212 int face_id = XINT (XCDR (XCAR (tail)));
1213 struct face *face = FACE_FROM_ID (f, face_id);
1215 /* Face THIS itself is also freed by the following call. */
1216 free_realized_face (f, face);
1220 UNBLOCK_INPUT;
1221 #else /* not 0 */
1222 /* But, we don't have to call Fclear_face_cache if no fontset has
1223 been realized from BASE. */
1224 for (id = 0; id < ASIZE (Vfontset_table); id++)
1226 Lisp_Object this = AREF (Vfontset_table, id);
1228 if (CHAR_TABLE_P (this) && EQ (FONTSET_BASE (this), base))
1230 Fclear_face_cache (Qt);
1231 break;
1234 #endif /* not 0 */
1238 /* Check validity of NAME as a fontset name and return the
1239 corresponding fontset. If not valid, signal an error.
1240 If NAME is t, return Vdefault_fontset. */
1242 static Lisp_Object
1243 check_fontset_name (name)
1244 Lisp_Object name;
1246 int id;
1248 if (EQ (name, Qt))
1249 return Vdefault_fontset;
1251 CHECK_STRING (name);
1252 /* First try NAME as literal. */
1253 id = fs_query_fontset (name, 2);
1254 if (id < 0)
1255 /* For backward compatibility, try again NAME as pattern. */
1256 id = fs_query_fontset (name, 0);
1257 if (id < 0)
1258 error ("Fontset `%s' does not exist", SDATA (name));
1259 return FONTSET_FROM_ID (id);
1262 static void
1263 accumulate_script_ranges (arg, range, val)
1264 Lisp_Object arg, range, val;
1266 if (EQ (XCAR (arg), val))
1268 if (CONSP (range))
1269 XSETCDR (arg, Fcons (Fcons (XCAR (range), XCDR (range)), XCDR (arg)));
1270 else
1271 XSETCDR (arg, Fcons (Fcons (range, range), XCDR (arg)));
1276 /* Return an ASCII font name generated from fontset name NAME and
1277 font-spec ASCII_SPEC. NAME is a string conforming to XLFD. */
1279 static INLINE Lisp_Object
1280 generate_ascii_font_name (name, ascii_spec)
1281 Lisp_Object name, ascii_spec;
1283 Lisp_Object font_spec = Ffont_spec (0, NULL);
1284 Lisp_Object vec;
1285 int i;
1286 char xlfd[256];
1288 if (font_parse_xlfd (SDATA (name), font_spec) < 0)
1289 error ("Not an XLFD font name: %s", SDATA (name));
1290 for (i = FONT_FOUNDRY_INDEX; i < FONT_EXTRA_INDEX; i++)
1291 if (! NILP (AREF (ascii_spec, i)))
1292 ASET (font_spec, i, AREF (ascii_spec, i));
1293 i = font_unparse_xlfd (font_spec, 0, xlfd, 256);
1294 if (i < 0)
1295 error ("Not an XLFD font name: %s", SDATA (name));
1296 return make_unibyte_string (xlfd, i);
1299 /* Variables referred in set_fontset_font. They are set before
1300 map_charset_chars is called in Fset_fontset_font. */
1301 static Lisp_Object font_def_arg, add_arg;
1302 static int from_arg, to_arg;
1304 /* Callback function for map_charset_chars in Fset_fontset_font. In
1305 FONTSET, set font_def_arg in a fashion specified by add_arg for
1306 characters in RANGE while ignoring the range between from_arg and
1307 to_arg. */
1309 static void
1310 set_fontset_font (fontset, range)
1311 Lisp_Object fontset, range;
1313 if (from_arg < to_arg)
1315 int from = XINT (XCAR (range)), to = XINT (XCDR (range));
1317 if (from < from_arg)
1319 if (to > to_arg)
1321 Lisp_Object range2;
1323 range2 = Fcons (make_number (to_arg), XCDR (range));
1324 FONTSET_ADD (fontset, range, font_def_arg, add_arg);
1325 to = to_arg;
1327 if (to > from_arg)
1328 range = Fcons (XCAR (range), make_number (from_arg));
1330 else if (to <= to_arg)
1331 return;
1332 else
1334 if (from < to_arg)
1335 range = Fcons (make_number (to_arg), XCDR (range));
1338 FONTSET_ADD (fontset, range, font_def_arg, add_arg);
1341 extern Lisp_Object QCfamily, QCregistry;
1343 DEFUN ("set-fontset-font", Fset_fontset_font, Sset_fontset_font, 3, 5, 0,
1344 doc: /*
1345 Modify fontset NAME to use FONT-SPEC for TARGET characters.
1347 TARGET may be a cons; (FROM . TO), where FROM and TO are characters.
1348 In that case, use FONT-SPEC for all characters in the range FROM and
1349 TO (inclusive).
1351 TARGET may be a script name symbol. In that case, use FONT-SPEC for
1352 all characters that belong to the script.
1354 TARGET may be a charset. In that case, use FONT-SPEC for all
1355 characters in the charset.
1357 TARGET may be nil. In that case, use FONT-SPEC for any characters for
1358 that no FONT-SPEC is specified.
1360 FONT-SPEC may one of these:
1361 * A font-spec object made by the function `font-spec' (which see).
1362 * A cons (FAMILY . REGISTRY), where FAMILY is a font family name and
1363 REGISTRY is a font registry name. FAMILY may contain foundry
1364 name, and REGISTRY may contain encoding name.
1365 * A font name string.
1366 * nil, which explicitly specifies that there's no font for TARGET.
1368 Optional 4th argument FRAME, if non-nil, is a frame. This argument is
1369 kept for backward compatibility and has no meaning.
1371 Optional 5th argument ADD, if non-nil, specifies how to add FONT-SPEC
1372 to the font specifications for TARGET previously set. If it is
1373 `prepend', FONT-SPEC is prepended. If it is `append', FONT-SPEC is
1374 appended. By default, FONT-SPEC overrides the previous settings. */)
1375 (name, target, font_spec, frame, add)
1376 Lisp_Object name, target, font_spec, frame, add;
1378 Lisp_Object fontset;
1379 Lisp_Object font_def, registry, family;
1380 Lisp_Object range_list;
1381 struct charset *charset = NULL;
1383 fontset = check_fontset_name (name);
1385 /* The arg FRAME is kept for backward compatibility. We only check
1386 the validity. */
1387 if (!NILP (frame))
1388 CHECK_LIVE_FRAME (frame);
1390 if (CONSP (font_spec))
1392 Lisp_Object spec = Ffont_spec (0, NULL);
1394 font_parse_family_registry (XCAR (font_spec), XCDR (font_spec), spec);
1395 font_spec = spec;
1397 else if (STRINGP (font_spec))
1399 Lisp_Object args[2];
1400 extern Lisp_Object QCname;
1402 args[0] = QCname;
1403 args[1] = font_spec;
1404 font_spec = Ffont_spec (2, args);
1406 else if (! NILP (font_spec) && ! FONT_SPEC_P (font_spec))
1407 Fsignal (Qfont, list2 (build_string ("Invalid font-spec"), font_spec));
1409 if (! NILP (font_spec))
1411 Lisp_Object encoding, repertory;
1413 family = AREF (font_spec, FONT_FAMILY_INDEX);
1414 if (! NILP (family) )
1415 family = SYMBOL_NAME (family);
1416 registry = AREF (font_spec, FONT_REGISTRY_INDEX);
1417 if (! NILP (registry))
1418 registry = Fdowncase (SYMBOL_NAME (registry));
1419 encoding = find_font_encoding (concat3 (family, build_string ("-"),
1420 registry));
1421 if (NILP (encoding))
1422 encoding = Qascii;
1424 if (SYMBOLP (encoding))
1426 CHECK_CHARSET (encoding);
1427 encoding = repertory = CHARSET_SYMBOL_ID (encoding);
1429 else
1431 repertory = XCDR (encoding);
1432 encoding = XCAR (encoding);
1433 CHECK_CHARSET (encoding);
1434 encoding = CHARSET_SYMBOL_ID (encoding);
1435 if (! NILP (repertory) && SYMBOLP (repertory))
1437 CHECK_CHARSET (repertory);
1438 repertory = CHARSET_SYMBOL_ID (repertory);
1441 FONT_DEF_NEW (font_def, font_spec, encoding, repertory);
1443 else
1444 font_def = Qnil;
1446 if (CHARACTERP (target))
1447 range_list = Fcons (Fcons (target, target), Qnil);
1448 else if (CONSP (target))
1450 Lisp_Object from, to;
1452 from = Fcar (target);
1453 to = Fcdr (target);
1454 CHECK_CHARACTER (from);
1455 CHECK_CHARACTER (to);
1456 range_list = Fcons (target, Qnil);
1458 else if (SYMBOLP (target) && !NILP (target))
1460 Lisp_Object script_list;
1461 Lisp_Object val;
1463 range_list = Qnil;
1464 script_list = XCHAR_TABLE (Vchar_script_table)->extras[0];
1465 if (! NILP (Fmemq (target, script_list)))
1467 val = Fcons (target, Qnil);
1468 map_char_table (accumulate_script_ranges, Qnil, Vchar_script_table,
1469 val);
1470 range_list = XCDR (val);
1471 if (EQ (target, Qlatin) && NILP (FONTSET_ASCII (fontset)))
1473 if (VECTORP (font_spec))
1474 val = generate_ascii_font_name (FONTSET_NAME (fontset),
1475 font_spec);
1476 else
1477 val = font_spec;
1478 FONTSET_ASCII (fontset) = val;
1481 if (CHARSETP (target))
1483 if (EQ (target, Qascii) && NILP (FONTSET_ASCII (fontset)))
1485 if (VECTORP (font_spec))
1486 font_spec = generate_ascii_font_name (FONTSET_NAME (fontset),
1487 font_spec);
1488 FONTSET_ASCII (fontset) = font_spec;
1489 range_list = Fcons (Fcons (make_number (0), make_number (127)),
1490 Qnil);
1492 else
1494 CHECK_CHARSET_GET_CHARSET (target, charset);
1497 else if (NILP (range_list))
1498 error ("Invalid script or charset name: %s",
1499 SDATA (SYMBOL_NAME (target)));
1501 else if (NILP (target))
1502 range_list = Fcons (Qnil, Qnil);
1503 else
1504 error ("Invalid target for setting a font");
1507 if (charset)
1509 font_def_arg = font_def;
1510 add_arg = add;
1511 if (NILP (range_list))
1512 from_arg = to_arg = 0;
1513 else
1514 from_arg = XINT (XCAR (XCAR (range_list))),
1515 to_arg = XINT (XCDR (XCAR (range_list)));
1517 map_charset_chars (set_fontset_font, Qnil, fontset, charset,
1518 CHARSET_MIN_CODE (charset),
1519 CHARSET_MAX_CODE (charset));
1521 for (; CONSP (range_list); range_list = XCDR (range_list))
1522 FONTSET_ADD (fontset, XCAR (range_list), font_def, add);
1524 /* Free all realized fontsets whose base is FONTSET. This way, the
1525 specified character(s) are surely redisplayed by a correct
1526 font. */
1527 free_realized_fontsets (fontset);
1529 return Qnil;
1533 DEFUN ("new-fontset", Fnew_fontset, Snew_fontset, 2, 2, 0,
1534 doc: /* Create a new fontset NAME from font information in FONTLIST.
1536 FONTLIST is an alist of scripts vs the corresponding font specification list.
1537 Each element of FONTLIST has the form (SCRIPT FONT-SPEC ...), where a
1538 character of SCRIPT is displayed by a font that matches one of
1539 FONT-SPEC.
1541 SCRIPT is a symbol that appears in the first extra slot of the
1542 char-table `char-script-table'.
1544 FONT-SPEC is a vector, a cons, or a string. See the documentation of
1545 `set-fontset-font' for the meaning. */)
1546 (name, fontlist)
1547 Lisp_Object name, fontlist;
1549 Lisp_Object fontset;
1550 Lisp_Object val;
1551 int id;
1553 CHECK_STRING (name);
1554 CHECK_LIST (fontlist);
1556 name = Fdowncase (name);
1557 id = fs_query_fontset (name, 0);
1558 if (id < 0)
1560 Lisp_Object font_spec = Ffont_spec (0, NULL);
1561 Lisp_Object short_name;
1562 char *xlfd;
1563 int len;
1565 if (font_parse_xlfd (SDATA (name), font_spec) < 0)
1566 error ("Fontset name must be in XLFD format");
1567 short_name = AREF (font_spec, FONT_REGISTRY_INDEX);
1568 if (strncmp (SDATA (SYMBOL_NAME (short_name)), "fontset-", 8)
1569 || SBYTES (SYMBOL_NAME (short_name)) < 9)
1570 error ("Registry field of fontset name must be \"fontset-*\"");
1571 Vfontset_alias_alist = Fcons (Fcons (name, SYMBOL_NAME (short_name)),
1572 Vfontset_alias_alist);
1573 ASET (font_spec, FONT_REGISTRY_INDEX, Qiso8859_1);
1574 fontset = make_fontset (Qnil, name, Qnil);
1575 xlfd = alloca (SBYTES (name) + 1);
1576 len = font_unparse_xlfd (font_spec, 0, xlfd, SBYTES (name) + 1);
1577 FONTSET_ASCII (fontset) = make_unibyte_string (xlfd, len);
1579 else
1581 fontset = FONTSET_FROM_ID (id);;
1582 free_realized_fontsets (fontset);
1583 Fset_char_table_range (fontset, Qt, Qnil);
1586 for (; ! NILP (fontlist); fontlist = Fcdr (fontlist))
1588 Lisp_Object elt, script;
1590 elt = Fcar (fontlist);
1591 script = Fcar (elt);
1592 elt = Fcdr (elt);
1593 if (CONSP (elt) && (NILP (XCDR (elt)) || CONSP (XCDR (elt))))
1594 for (; CONSP (elt); elt = XCDR (elt))
1595 Fset_fontset_font (name, script, XCAR (elt), Qnil, Qappend);
1596 else
1597 Fset_fontset_font (name, script, elt, Qnil, Qappend);
1599 return name;
1603 /* Alist of automatically created fontsets. Each element is a cons
1604 (FONT-SPEC . FONTSET-ID). */
1605 static Lisp_Object auto_fontset_alist;
1608 fontset_from_font (font_object)
1609 Lisp_Object font_object;
1611 Lisp_Object font_name = font_get_name (font_object);
1612 Lisp_Object font_spec = Fcopy_font_spec (font_object);
1613 Lisp_Object fontset_spec, alias, name, fontset;
1614 Lisp_Object val;
1615 int i;
1617 val = assoc_no_quit (font_spec, auto_fontset_alist);
1618 if (CONSP (val))
1619 return XINT (FONTSET_ID (XCDR (val)));
1620 if (NILP (auto_fontset_alist))
1621 alias = intern ("fontset-startup");
1622 else
1624 char temp[32];
1625 int len = XINT (Flength (auto_fontset_alist));
1627 sprintf (temp, "fontset-auto%d", len);
1628 alias = intern (temp);
1630 fontset_spec = Fcopy_font_spec (font_spec);
1631 ASET (fontset_spec, FONT_REGISTRY_INDEX, alias);
1632 name = Ffont_xlfd_name (fontset_spec);
1633 if (NILP (name))
1634 abort ();
1635 fontset = make_fontset (Qnil, name, Qnil);
1636 Vfontset_alias_alist = Fcons (Fcons (name, SYMBOL_NAME (alias)),
1637 Vfontset_alias_alist);
1638 alias = Fdowncase (AREF (font_object, FONT_NAME_INDEX));
1639 Vfontset_alias_alist = Fcons (Fcons (name, alias), Vfontset_alias_alist);
1640 auto_fontset_alist = Fcons (Fcons (font_spec, fontset), auto_fontset_alist);
1641 FONTSET_ASCII (fontset) = font_name;
1642 ASET (font_spec, FONT_FOUNDRY_INDEX, Qnil);
1643 ASET (font_spec, FONT_ADSTYLE_INDEX, Qnil);
1644 for (i = FONT_WEIGHT_INDEX; i < FONT_EXTRA_INDEX; i++)
1645 ASET (font_spec, i, Qnil);
1646 Fset_fontset_font (name, Qlatin, font_spec, Qnil, Qnil);
1647 font_spec = Fcopy_font_spec (font_spec);
1648 ASET (font_spec, FONT_REGISTRY_INDEX, Qiso10646_1);
1649 Fset_fontset_font (name, Qnil, font_spec, Qnil, Qnil);
1650 return XINT (FONTSET_ID (fontset));
1653 DEFUN ("font-info", Ffont_info, Sfont_info, 1, 2, 0,
1654 doc: /* Return information about a font named NAME on frame FRAME.
1655 If FRAME is omitted or nil, use the selected frame.
1656 The returned value is a vector of OPENED-NAME, FULL-NAME, CHARSET, SIZE,
1657 HEIGHT, BASELINE-OFFSET, RELATIVE-COMPOSE, and DEFAULT-ASCENT,
1658 where
1659 OPENED-NAME is the name used for opening the font,
1660 FULL-NAME is the full name of the font,
1661 SIZE is the maximum bound width of the font,
1662 HEIGHT is the height of the font,
1663 BASELINE-OFFSET is the upward offset pixels from ASCII baseline,
1664 RELATIVE-COMPOSE and DEFAULT-ASCENT are the numbers controlling
1665 how to compose characters.
1666 If the named font is not yet loaded, return nil. */)
1667 (name, frame)
1668 Lisp_Object name, frame;
1670 FRAME_PTR f;
1671 struct font *font;
1672 Lisp_Object info;
1673 Lisp_Object font_object;
1675 (*check_window_system_func) ();
1677 CHECK_STRING (name);
1678 name = Fdowncase (name);
1679 if (NILP (frame))
1680 frame = selected_frame;
1681 CHECK_LIVE_FRAME (frame);
1682 f = XFRAME (frame);
1684 font_object = font_open_by_name (f, SDATA (name));
1685 if (NILP (font_object))
1686 return Qnil;
1687 font = XFONT_OBJECT (font_object);
1689 info = Fmake_vector (make_number (7), Qnil);
1690 XVECTOR (info)->contents[0] = AREF (font_object, FONT_NAME_INDEX);
1691 XVECTOR (info)->contents[1] = AREF (font_object, FONT_NAME_INDEX);
1692 XVECTOR (info)->contents[2] = make_number (font->pixel_size);
1693 XVECTOR (info)->contents[3] = make_number (font->height);
1694 XVECTOR (info)->contents[4] = make_number (font->baseline_offset);
1695 XVECTOR (info)->contents[5] = make_number (font->relative_compose);
1696 XVECTOR (info)->contents[6] = make_number (font->default_ascent);
1698 font_close_object (f, font_object);
1699 return info;
1703 /* Return a cons (FONT-NAME . GLYPH-CODE).
1704 FONT-NAME is the font name for the character at POSITION in the current
1705 buffer. This is computed from all the text properties and overlays
1706 that apply to POSITION. POSTION may be nil, in which case,
1707 FONT-NAME is the font name for display the character CH with the
1708 default face.
1710 GLYPH-CODE is the glyph code in the font to use for the character.
1712 If the 2nd optional arg CH is non-nil, it is a character to check
1713 the font instead of the character at POSITION.
1715 It returns nil in the following cases:
1717 (1) The window system doesn't have a font for the character (thus
1718 it is displayed by an empty box).
1720 (2) The character code is invalid.
1722 (3) If POSITION is not nil, and the current buffer is not displayed
1723 in any window.
1725 In addition, the returned font name may not take into account of
1726 such redisplay engine hooks as what used in jit-lock-mode if
1727 POSITION is currently not visible. */
1730 DEFUN ("internal-char-font", Finternal_char_font, Sinternal_char_font, 1, 2, 0,
1731 doc: /* For internal use only. */)
1732 (position, ch)
1733 Lisp_Object position, ch;
1735 EMACS_INT pos, pos_byte, dummy;
1736 int face_id;
1737 int c;
1738 struct frame *f;
1739 struct face *face;
1740 Lisp_Object rfont_def;
1741 int cs_id;
1743 if (NILP (position))
1745 CHECK_CHARACTER (ch);
1746 c = XINT (ch);
1747 f = XFRAME (selected_frame);
1748 face_id = DEFAULT_FACE_ID;
1749 pos = -1;
1750 cs_id = -1;
1752 else
1754 Lisp_Object window, charset;
1755 struct window *w;
1757 CHECK_NUMBER_COERCE_MARKER (position);
1758 pos = XINT (position);
1759 if (pos < BEGV || pos >= ZV)
1760 args_out_of_range_3 (position, make_number (BEGV), make_number (ZV));
1761 pos_byte = CHAR_TO_BYTE (pos);
1762 if (NILP (ch))
1763 c = FETCH_CHAR (pos_byte);
1764 else
1766 CHECK_NATNUM (ch);
1767 c = XINT (ch);
1769 window = Fget_buffer_window (Fcurrent_buffer (), Qnil);
1770 if (NILP (window))
1771 return Qnil;
1772 w = XWINDOW (window);
1773 f = XFRAME (w->frame);
1774 face_id = face_at_buffer_position (w, pos, -1, -1, &dummy, pos + 100, 0);
1775 charset = Fget_char_property (position, Qcharset, Qnil);
1776 if (CHARSETP (charset))
1777 cs_id = XINT (CHARSET_SYMBOL_ID (charset));
1778 else
1779 cs_id = -1;
1781 if (! CHAR_VALID_P (c, 0))
1782 return Qnil;
1783 face_id = FACE_FOR_CHAR (f, FACE_FROM_ID (f, face_id), c, pos, Qnil);
1784 face = FACE_FROM_ID (f, face_id);
1785 if (face->font)
1787 struct font *font = face->font;
1788 unsigned code = font->driver->encode_char (font, c);
1789 Lisp_Object fontname = font->props[FONT_NAME_INDEX];
1790 /* Assignment to EMACS_INT stops GCC whining about limited range
1791 of data type. */
1792 EMACS_INT cod = code;
1794 if (code == FONT_INVALID_CODE)
1795 return Qnil;
1796 if (cod <= MOST_POSITIVE_FIXNUM)
1797 return Fcons (fontname, make_number (code));
1798 return Fcons (fontname, Fcons (make_number (code >> 16),
1799 make_number (code & 0xFFFF)));
1801 return Qnil;
1805 DEFUN ("fontset-info", Ffontset_info, Sfontset_info, 1, 2, 0,
1806 doc: /* Return information about a fontset FONTSET on frame FRAME.
1807 The value is a char-table of which elements has this form.
1809 ((FONT-PATTERN OPENED-FONT ...) ...)
1811 FONT-PATTERN is a vector:
1813 [ FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY ]
1815 or a string of font name pattern.
1817 OPENED-FONT is a name of a font actually opened.
1819 The char-table has one extra slot. The value is a char-table
1820 containing the information about the derived fonts from the default
1821 fontset. The format is the same as abobe. */)
1822 (fontset, frame)
1823 Lisp_Object fontset, frame;
1825 FRAME_PTR f;
1826 Lisp_Object *realized[2], fontsets[2], tables[2];
1827 Lisp_Object val, elt;
1828 int c, i, j, k;
1830 (*check_window_system_func) ();
1832 fontset = check_fontset_name (fontset);
1834 if (NILP (frame))
1835 frame = selected_frame;
1836 CHECK_LIVE_FRAME (frame);
1837 f = XFRAME (frame);
1839 /* Recode fontsets realized on FRAME from the base fontset FONTSET
1840 in the table `realized'. */
1841 realized[0] = (Lisp_Object *) alloca (sizeof (Lisp_Object)
1842 * ASIZE (Vfontset_table));
1843 for (i = j = 0; i < ASIZE (Vfontset_table); i++)
1845 elt = FONTSET_FROM_ID (i);
1846 if (!NILP (elt)
1847 && EQ (FONTSET_BASE (elt), fontset)
1848 && EQ (FONTSET_FRAME (elt), frame))
1849 realized[0][j++] = elt;
1851 realized[0][j] = Qnil;
1853 realized[1] = (Lisp_Object *) alloca (sizeof (Lisp_Object)
1854 * ASIZE (Vfontset_table));
1855 for (i = j = 0; ! NILP (realized[0][i]); i++)
1857 elt = FONTSET_DEFAULT (realized[0][i]);
1858 if (! NILP (elt))
1859 realized[1][j++] = elt;
1861 realized[1][j] = Qnil;
1863 tables[0] = Fmake_char_table (Qfontset_info, Qnil);
1864 tables[1] = Fmake_char_table (Qnil, Qnil);
1865 XCHAR_TABLE (tables[0])->extras[0] = tables[1];
1866 fontsets[0] = fontset;
1867 fontsets[1] = Vdefault_fontset;
1869 /* Accumulate information of the fontset in TABLE. The format of
1870 each element is ((FONT-SPEC OPENED-FONT ...) ...). */
1871 for (k = 0; k <= 1; k++)
1873 for (c = 0; c <= MAX_CHAR; )
1875 int from, to;
1877 if (c <= MAX_5_BYTE_CHAR)
1879 val = char_table_ref_and_range (fontsets[k], c, &from, &to);
1880 if (to > MAX_5_BYTE_CHAR)
1881 to = MAX_5_BYTE_CHAR;
1883 else
1885 val = FONTSET_FALLBACK (fontsets[k]);
1886 to = MAX_CHAR;
1888 if (VECTORP (val))
1890 Lisp_Object alist;
1892 /* At first, set ALIST to ((FONT-SPEC) ...). */
1893 for (alist = Qnil, i = 0; i < ASIZE (val); i++)
1894 if (! NILP (AREF (val, i)))
1895 alist = Fcons (Fcons (FONT_DEF_SPEC (AREF (val, i)), Qnil),
1896 alist);
1897 alist = Fnreverse (alist);
1899 /* Then store opend font names to cdr of each elements. */
1900 for (i = 0; ! NILP (realized[k][i]); i++)
1902 if (c <= MAX_5_BYTE_CHAR)
1903 val = FONTSET_REF (realized[k][i], c);
1904 else
1905 val = FONTSET_FALLBACK (realized[k][i]);
1906 if (! VECTORP (val))
1907 continue;
1908 /* VAL: [int ? [FACE-ID FONT-DEF FONT-OBJECT int] ... ] */
1909 for (j = 2; j < ASIZE (val); j++)
1911 elt = AREF (val, j);
1912 if (FONT_OBJECT_P (RFONT_DEF_OBJECT (elt)))
1914 Lisp_Object font_object = RFONT_DEF_OBJECT (elt);
1915 Lisp_Object slot, name;
1917 slot = Fassq (RFONT_DEF_SPEC (elt), alist);
1918 name = AREF (font_object, FONT_NAME_INDEX);
1919 if (NILP (Fmember (name, XCDR (slot))))
1920 nconc2 (slot, Fcons (name, Qnil));
1925 /* Store ALIST in TBL for characters C..TO. */
1926 if (c <= MAX_5_BYTE_CHAR)
1927 char_table_set_range (tables[k], c, to, alist);
1928 else
1929 XCHAR_TABLE (tables[k])->defalt = alist;
1931 /* At last, change each elements to font names. */
1932 for (; CONSP (alist); alist = XCDR (alist))
1934 elt = XCAR (alist);
1935 XSETCAR (elt, Ffont_xlfd_name (XCAR (elt)));
1938 c = to + 1;
1942 return tables[0];
1946 DEFUN ("fontset-font", Ffontset_font, Sfontset_font, 2, 3, 0,
1947 doc: /* Return a font name pattern for character CH in fontset NAME.
1948 If NAME is t, find a pattern in the default fontset.
1950 The value has the form (FAMILY . REGISTRY), where FAMILY is a font
1951 family name and REGISTRY is a font registry name. This is actually
1952 the first font name pattern for CH in the fontset or in the default
1953 fontset.
1955 If the 2nd optional arg ALL is non-nil, return a list of all font name
1956 patterns. */)
1957 (name, ch, all)
1958 Lisp_Object name, ch, all;
1960 int c;
1961 Lisp_Object fontset, elt, list, repertory, val;
1962 int i, j;
1964 fontset = check_fontset_name (name);
1966 CHECK_CHARACTER (ch);
1967 c = XINT (ch);
1968 list = Qnil;
1969 while (1)
1971 for (i = 0, elt = FONTSET_REF (fontset, c); i < 2;
1972 i++, elt = FONTSET_FALLBACK (fontset))
1973 if (VECTORP (elt))
1974 for (j = 0; j < ASIZE (elt); j++)
1976 val = AREF (elt, j);
1977 repertory = AREF (val, 1);
1978 if (INTEGERP (repertory))
1980 struct charset *charset = CHARSET_FROM_ID (XINT (repertory));
1982 if (! CHAR_CHARSET_P (c, charset))
1983 continue;
1985 else if (CHAR_TABLE_P (repertory))
1987 if (NILP (CHAR_TABLE_REF (repertory, c)))
1988 continue;
1990 val = AREF (val, 0);
1991 val = Fcons (AREF (val, 0), AREF (val, 5));
1992 if (NILP (all))
1993 return val;
1994 list = Fcons (val, list);
1996 if (EQ (fontset, Vdefault_fontset))
1997 break;
1998 fontset = Vdefault_fontset;
2000 return (Fnreverse (list));
2003 DEFUN ("fontset-list", Ffontset_list, Sfontset_list, 0, 0, 0,
2004 doc: /* Return a list of all defined fontset names. */)
2007 Lisp_Object fontset, list;
2008 int i;
2010 list = Qnil;
2011 for (i = 0; i < ASIZE (Vfontset_table); i++)
2013 fontset = FONTSET_FROM_ID (i);
2014 if (!NILP (fontset)
2015 && BASE_FONTSET_P (fontset))
2016 list = Fcons (FONTSET_NAME (fontset), list);
2019 return list;
2023 #ifdef FONTSET_DEBUG
2025 Lisp_Object
2026 dump_fontset (fontset)
2027 Lisp_Object fontset;
2029 Lisp_Object vec;
2031 vec = Fmake_vector (make_number (3), Qnil);
2032 ASET (vec, 0, FONTSET_ID (fontset));
2034 if (BASE_FONTSET_P (fontset))
2036 ASET (vec, 1, FONTSET_NAME (fontset));
2038 else
2040 Lisp_Object frame;
2042 frame = FONTSET_FRAME (fontset);
2043 if (FRAMEP (frame))
2045 FRAME_PTR f = XFRAME (frame);
2047 if (FRAME_LIVE_P (f))
2048 ASET (vec, 1,
2049 Fcons (FONTSET_NAME (FONTSET_BASE (fontset)), f->name));
2050 else
2051 ASET (vec, 1,
2052 Fcons (FONTSET_NAME (FONTSET_BASE (fontset)), Qnil));
2054 if (!NILP (FONTSET_DEFAULT (fontset)))
2055 ASET (vec, 2, FONTSET_ID (FONTSET_DEFAULT (fontset)));
2057 return vec;
2060 DEFUN ("fontset-list-all", Ffontset_list_all, Sfontset_list_all, 0, 0, 0,
2061 doc: /* Return a brief summary of all fontsets for debug use. */)
2064 Lisp_Object val;
2065 int i;
2067 for (i = 0, val = Qnil; i < ASIZE (Vfontset_table); i++)
2068 if (! NILP (AREF (Vfontset_table, i)))
2069 val = Fcons (dump_fontset (AREF (Vfontset_table, i)), val);
2070 return (Fnreverse (val));
2072 #endif /* FONTSET_DEBUG */
2074 void
2075 syms_of_fontset ()
2077 DEFSYM (Qfontset, "fontset");
2078 Fput (Qfontset, Qchar_table_extra_slots, make_number (9));
2079 DEFSYM (Qfontset_info, "fontset-info");
2080 Fput (Qfontset_info, Qchar_table_extra_slots, make_number (1));
2082 DEFSYM (Qprepend, "prepend");
2083 DEFSYM (Qappend, "append");
2084 DEFSYM (Qlatin, "latin");
2086 Vcached_fontset_data = Qnil;
2087 staticpro (&Vcached_fontset_data);
2089 Vfontset_table = Fmake_vector (make_number (32), Qnil);
2090 staticpro (&Vfontset_table);
2092 Vdefault_fontset = Fmake_char_table (Qfontset, Qnil);
2093 staticpro (&Vdefault_fontset);
2094 FONTSET_ID (Vdefault_fontset) = make_number (0);
2095 FONTSET_NAME (Vdefault_fontset)
2096 = build_string ("-*-*-*-*-*-*-*-*-*-*-*-*-fontset-default");
2097 ASET (Vfontset_table, 0, Vdefault_fontset);
2098 next_fontset_id = 1;
2100 auto_fontset_alist = Qnil;
2101 staticpro (&auto_fontset_alist);
2103 DEFVAR_LISP ("font-encoding-alist", &Vfont_encoding_alist,
2104 doc: /*
2105 Alist of fontname patterns vs the corresponding encoding and repertory info.
2106 Each element looks like (REGEXP . (ENCODING . REPERTORY)),
2107 where ENCODING is a charset or a char-table,
2108 and REPERTORY is a charset, a char-table, or nil.
2110 If ENCDING and REPERTORY are the same, the element can have the form
2111 \(REGEXP . ENCODING).
2113 ENCODING is for converting a character to a glyph code of the font.
2114 If ENCODING is a charset, encoding a character by the charset gives
2115 the corresponding glyph code. If ENCODING is a char-table, looking up
2116 the table by a character gives the corresponding glyph code.
2118 REPERTORY specifies a repertory of characters supported by the font.
2119 If REPERTORY is a charset, all characters beloging to the charset are
2120 supported. If REPERTORY is a char-table, all characters who have a
2121 non-nil value in the table are supported. It REPERTORY is nil, Emacs
2122 gets the repertory information by an opened font and ENCODING. */);
2123 Vfont_encoding_alist = Qnil;
2125 DEFVAR_LISP ("font-encoding-charset-alist", &Vfont_encoding_charset_alist,
2126 doc: /*
2127 Alist of charsets vs the charsets to determine the preferred font encoding.
2128 Each element looks like (CHARSET . ENCDOING-CHARSET),
2129 where ENCODING-CHARSET is a charset registered in the variable
2130 `font-encoding-alist' as ENCODING.
2132 When a text has a property `charset' and the value is CHARSET, a font
2133 whose encoding corresponds to ENCODING-CHARSET is preferred. */);
2134 Vfont_encoding_charset_alist = Qnil;
2136 DEFVAR_LISP ("use-default-ascent", &Vuse_default_ascent,
2137 doc: /*
2138 Char table of characters whose ascent values should be ignored.
2139 If an entry for a character is non-nil, the ascent value of the glyph
2140 is assumed to be what specified by _MULE_DEFAULT_ASCENT property of a font.
2142 This affects how a composite character which contains
2143 such a character is displayed on screen. */);
2144 Vuse_default_ascent = Qnil;
2146 DEFVAR_LISP ("ignore-relative-composition", &Vignore_relative_composition,
2147 doc: /*
2148 Char table of characters which is not composed relatively.
2149 If an entry for a character is non-nil, a composition sequence
2150 which contains that character is displayed so that
2151 the glyph of that character is put without considering
2152 an ascent and descent value of a previous character. */);
2153 Vignore_relative_composition = Qnil;
2155 DEFVAR_LISP ("alternate-fontname-alist", &Valternate_fontname_alist,
2156 doc: /* Alist of fontname vs list of the alternate fontnames.
2157 When a specified font name is not found, the corresponding
2158 alternate fontnames (if any) are tried instead. */);
2159 Valternate_fontname_alist = Qnil;
2161 DEFVAR_LISP ("fontset-alias-alist", &Vfontset_alias_alist,
2162 doc: /* Alist of fontset names vs the aliases. */);
2163 Vfontset_alias_alist = Fcons (Fcons (FONTSET_NAME (Vdefault_fontset),
2164 build_string ("fontset-default")),
2165 Qnil);
2167 DEFVAR_LISP ("vertical-centering-font-regexp",
2168 &Vvertical_centering_font_regexp,
2169 doc: /* *Regexp matching font names that require vertical centering on display.
2170 When a character is displayed with such fonts, the character is displayed
2171 at the vertical center of lines. */);
2172 Vvertical_centering_font_regexp = Qnil;
2174 DEFVAR_LISP ("otf-script-alist", &Votf_script_alist,
2175 doc: /* Alist of OpenType script tags vs the corresponding script names. */);
2176 Votf_script_alist = Qnil;
2178 defsubr (&Squery_fontset);
2179 defsubr (&Snew_fontset);
2180 defsubr (&Sset_fontset_font);
2181 defsubr (&Sfont_info);
2182 defsubr (&Sinternal_char_font);
2183 defsubr (&Sfontset_info);
2184 defsubr (&Sfontset_font);
2185 defsubr (&Sfontset_list);
2186 #ifdef FONTSET_DEBUG
2187 defsubr (&Sfontset_list_all);
2188 #endif
2191 /* arch-tag: ea861585-2f5f-4e5b-9849-d04a9c3a3537
2192 (do not change this comment) */