]> code.delx.au - gnu-emacs/blob - src/fontset.c
Include "intervals.h".
[gnu-emacs] / src / fontset.c
1 /* Fontset handler.
2 Copyright (C) 1995, 1997, 2000 Electrotechnical Laboratory, JAPAN.
3 Licensed to the Free Software Foundation.
4 Copyright (C) 2003
5 National Institute of Advanced Industrial Science and Technology (AIST)
6 Registration Number H13PRO009
7
8 This file is part of GNU Emacs.
9
10 GNU Emacs is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
13 any later version.
14
15 GNU Emacs is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with GNU Emacs; see the file COPYING. If not, write to
22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
24
25 /* #define FONTSET_DEBUG */
26
27 #include <config.h>
28
29 #ifdef FONTSET_DEBUG
30 #include <stdio.h>
31 #endif
32
33 #include "lisp.h"
34 #include "blockinput.h"
35 #include "buffer.h"
36 #include "character.h"
37 #include "charset.h"
38 #include "ccl.h"
39 #include "keyboard.h"
40 #include "frame.h"
41 #include "dispextern.h"
42 #include "intervals.h"
43 #include "fontset.h"
44 #include "window.h"
45
46 #undef xassert
47 #ifdef FONTSET_DEBUG
48 #define xassert(X) do {if (!(X)) abort ();} while (0)
49 #undef INLINE
50 #define INLINE
51 #else /* not FONTSET_DEBUG */
52 #define xassert(X) (void) 0
53 #endif /* not FONTSET_DEBUG */
54
55 EXFUN (Fclear_face_cache, 1);
56
57 /* FONTSET
58
59 A fontset is a collection of font related information to give
60 similar appearance (style, etc) of characters. A fontset has two
61 roles. One is to use for the frame parameter `font' as if it is an
62 ASCII font. In that case, Emacs uses the font specified for
63 `ascii' script for the frame's default font.
64
65 Another role, the more important one, is to provide information
66 about which font to use for each non-ASCII character.
67
68 There are two kinds of fontsets; base and realized. A base fontset
69 is created by `new-fontset' from Emacs Lisp explicitly. A realized
70 fontset is created implicitly when a face is realized for ASCII
71 characters. A face is also realized for non-ASCII characters based
72 on an ASCII face. All of non-ASCII faces based on the same ASCII
73 face share the same realized fontset.
74
75 A fontset object is implemented by a char-table whose default value
76 and parent are always nil.
77
78 An element of a base fontset is a vector of FONT-DEFs which itself
79 is a vector [ FONT-SPEC ENCODING REPERTORY ].
80
81 FONT-SPEC is:
82 [ FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY ]
83 or
84 FONT-NAME
85 where FAMILY, WEIGHT, SLANT, SWIDTH, ADSTYLE, REGISTRY, and
86 FONT-NAME are strings.
87
88 ENCODING is a charset ID that can convert characters to glyph codes
89 of the corresponding font.
90
91 REPERTORY is a charset ID, a char-table, or nil. If REPERTORY is a
92 charset ID, the repertory of the charset exactly matches with that
93 of the font. If REPERTORY is a char-table, all characters who have
94 a non-nil value in the table are supported. If REPERTORY is nil,
95 we consult with the font itself to get the repertory.
96
97 ENCODING and REPERTORY are extracted from the variable
98 Vfont_encoding_alist by using a font name generated from FONT-SPEC
99 (if it is a vector) or FONT-NAME as a key.
100
101
102 An element of a realized fontset is nil or t, or has this form:
103
104 [CHARSET-PRIORITY-LIST-TICK PREFERRED-CHARSET-ID PREFERRED-FONT-DEF
105 FONT-DEF0 FONT-DEF1 ...].
106
107 FONT-DEFn has this form:
108
109 [ FACE-ID FONT-INDEX FONT-DEF ]
110
111 FONT-DEFn is automatically reordered by the current charset
112 priority list.
113
114 The value nil means that we have not yet generated FONT-VECTOR from
115 the base of the fontset.
116
117 The value t means that no font is available for the corresponding
118 range of characters.
119
120
121 A fontset has 9 extra slots.
122
123 The 1st slot: the ID number of the fontset
124
125 The 2nd slot:
126 base: the name of the fontset
127 realized: nil
128
129 The 3rd slot:
130 base: nil
131 realized: the base fontset
132
133 The 4th slot:
134 base: nil
135 realized: the frame that the fontset belongs to
136
137 The 5th slot:
138 base: the font name for ASCII characters
139 realized: nil
140
141 The 6th slot:
142 base: nil
143 realized: the ID number of a face to use for characters that
144 has no font in a realized fontset.
145
146 The 7th slot:
147 base: nil
148 realized: Alist of font index vs the corresponding repertory
149 char-table.
150
151 The 8th slot:
152 base: nil
153 realized: If the base is not the default fontset, a fontset
154 realized from the default fontset, else nil.
155
156 The 9th slot:
157 base: Same as element value (but for fallback fonts).
158 realized: Likewise.
159
160 All fontsets are recorded in the vector Vfontset_table.
161
162
163 DEFAULT FONTSET
164
165 There's a special base fontset named `default fontset' which
166 defines the default font specifications. When a base fontset
167 doesn't specify a font for a specific character, the corresponding
168 value in the default fontset is used.
169
170 The parent of a realized fontset created for such a face that has
171 no fontset is the default fontset.
172
173
174 These structures are hidden from the other codes than this file.
175 The other codes handle fontsets only by their ID numbers. They
176 usually use the variable name `fontset' for IDs. But, in this
177 file, we always use varialbe name `id' for IDs, and name `fontset'
178 for an actual fontset object, i.e., char-table.
179
180 */
181
182 /********** VARIABLES and FUNCTION PROTOTYPES **********/
183
184 extern Lisp_Object Qfont;
185 static Lisp_Object Qfontset;
186 static Lisp_Object Qfontset_info;
187 static Lisp_Object Qprepend, Qappend;
188
189 /* Vector containing all fontsets. */
190 static Lisp_Object Vfontset_table;
191
192 /* Next possibly free fontset ID. Usually this keeps the minimum
193 fontset ID not yet used. */
194 static int next_fontset_id;
195
196 /* The default fontset. This gives default FAMILY and REGISTRY of
197 font for each character. */
198 static Lisp_Object Vdefault_fontset;
199
200 Lisp_Object Vfont_encoding_alist;
201 Lisp_Object Vuse_default_ascent;
202 Lisp_Object Vignore_relative_composition;
203 Lisp_Object Valternate_fontname_alist;
204 Lisp_Object Vfontset_alias_alist;
205 Lisp_Object Vvertical_centering_font_regexp;
206
207 /* The following six are declarations of callback functions depending
208 on window system. See the comments in src/fontset.h for more
209 detail. */
210
211 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
212 struct font_info *(*get_font_info_func) P_ ((FRAME_PTR f, int font_idx));
213
214 /* Return a list of font names which matches PATTERN. See the documentation
215 of `x-list-fonts' for more details. */
216 Lisp_Object (*list_fonts_func) P_ ((struct frame *f,
217 Lisp_Object pattern,
218 int size,
219 int maxnames));
220
221 /* Load a font named NAME for frame F and return a pointer to the
222 information of the loaded font. If loading is failed, return 0. */
223 struct font_info *(*load_font_func) P_ ((FRAME_PTR f, char *name, int));
224
225 /* Return a pointer to struct font_info of a font named NAME for frame F. */
226 struct font_info *(*query_font_func) P_ ((FRAME_PTR f, char *name));
227
228 /* Additional function for setting fontset or changing fontset
229 contents of frame F. */
230 void (*set_frame_fontset_func) P_ ((FRAME_PTR f, Lisp_Object arg,
231 Lisp_Object oldval));
232
233 /* To find a CCL program, fs_load_font calls this function.
234 The argument is a pointer to the struct font_info.
235 This function set the member `encoder' of the structure. */
236 void (*find_ccl_program_func) P_ ((struct font_info *));
237
238 Lisp_Object (*get_font_repertory_func) P_ ((struct frame *,
239 struct font_info *));
240
241 /* Check if any window system is used now. */
242 void (*check_window_system_func) P_ ((void));
243
244
245 /* Prototype declarations for static functions. */
246 static Lisp_Object fontset_add P_ ((Lisp_Object, Lisp_Object, Lisp_Object,
247 Lisp_Object));
248 static Lisp_Object make_fontset P_ ((Lisp_Object, Lisp_Object, Lisp_Object));
249 static Lisp_Object fontset_pattern_regexp P_ ((Lisp_Object));
250 static void accumulate_script_ranges P_ ((Lisp_Object, Lisp_Object,
251 Lisp_Object));
252 static Lisp_Object find_font_encoding P_ ((char *));
253
254 static void set_fontset_font P_ ((Lisp_Object, Lisp_Object));
255
256 #ifdef FONTSET_DEBUG
257
258 /* Return 1 if ID is a valid fontset id, else return 0. */
259
260 static int
261 fontset_id_valid_p (id)
262 int id;
263 {
264 return (id >= 0 && id < ASIZE (Vfontset_table) - 1);
265 }
266
267 #endif
268
269
270 \f
271 /********** MACROS AND FUNCTIONS TO HANDLE FONTSET **********/
272
273 /* Return the fontset with ID. No check of ID's validness. */
274 #define FONTSET_FROM_ID(id) AREF (Vfontset_table, id)
275
276 /* Macros to access special values of FONTSET. */
277 #define FONTSET_ID(fontset) XCHAR_TABLE (fontset)->extras[0]
278
279 /* Macros to access special values of (base) FONTSET. */
280 #define FONTSET_NAME(fontset) XCHAR_TABLE (fontset)->extras[1]
281 #define FONTSET_ASCII(fontset) XCHAR_TABLE (fontset)->extras[4]
282
283 /* Macros to access special values of (realized) FONTSET. */
284 #define FONTSET_BASE(fontset) XCHAR_TABLE (fontset)->extras[2]
285 #define FONTSET_FRAME(fontset) XCHAR_TABLE (fontset)->extras[3]
286 #define FONTSET_NOFONT_FACE(fontset) XCHAR_TABLE (fontset)->extras[5]
287 #define FONTSET_REPERTORY(fontset) XCHAR_TABLE (fontset)->extras[6]
288 #define FONTSET_DEFAULT(fontset) XCHAR_TABLE (fontset)->extras[7]
289
290 /* For both base and realized fontset. */
291 #define FONTSET_FALLBACK(fontset) XCHAR_TABLE (fontset)->extras[8]
292
293 #define BASE_FONTSET_P(fontset) (NILP (FONTSET_BASE (fontset)))
294
295
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. */
300
301 #define FONTSET_REF(fontset, c) \
302 (EQ (fontset, Vdefault_fontset) \
303 ? CHAR_TABLE_REF (fontset, c) \
304 : fontset_ref ((fontset), (c)))
305
306 static Lisp_Object
307 fontset_ref (fontset, c)
308 Lisp_Object fontset;
309 int c;
310 {
311 Lisp_Object elt;
312
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;
319 }
320
321
322 /* Return the element of FONTSET for the character C, set FROM and TO
323 to the range of characters around C that have the same value as C.
324 If FONTSET is a base fontset other then the default fontset and
325 FONTSET doesn't contain information for C, return the information
326 in the default fontset. */
327
328 #define FONTSET_REF_AND_RANGE(fontset, c, form, to) \
329 (EQ (fontset, Vdefault_fontset) \
330 ? char_table_ref_and_range (fontset, c, &from, &to) \
331 : fontset_ref_and_range (fontset, c, &from, &to))
332
333 static Lisp_Object
334 fontset_ref_and_range (fontset, c, from, to)
335 Lisp_Object fontset;
336 int c;
337 int *from, *to;
338 {
339 Lisp_Object elt;
340
341 elt = char_table_ref_and_range (fontset, c, from, to);
342 if (NILP (elt) && ! EQ (fontset, Vdefault_fontset)
343 /* Don't check Vdefault_fontset for a realized fontset. */
344 && NILP (FONTSET_BASE (fontset)))
345 {
346 int from1, to1;
347
348 elt = char_table_ref_and_range (Vdefault_fontset, c, &from1, &to1);
349 if (*from < from1)
350 *from = from1;
351 if (*to > to1)
352 *to = to1;
353 }
354 return elt;
355 }
356
357
358 /* Set elements of FONTSET for characters in RANGE to the value ELT.
359 RANGE is a cons (FROM . TO), where FROM and TO are character codes
360 specifying a range. */
361
362 #define FONTSET_SET(fontset, range, elt) \
363 Fset_char_table_range ((fontset), (range), (elt))
364
365
366 /* Modify the elements of FONTSET for characters in RANGE by replacing
367 with ELT or adding ELT. RANGE is a cons (FROM . TO), where FROM
368 and TO are character codes specifying a range. If ADD is nil,
369 replace with ELT, if ADD is `prepend', prepend ELT, otherwise,
370 append ELT. */
371
372 #define FONTSET_ADD(fontset, range, elt, add) \
373 (NILP (add) \
374 ? (NILP (range) \
375 ? (FONTSET_FALLBACK (fontset) = Fmake_vector (make_number (1), (elt))) \
376 : Fset_char_table_range ((fontset), (range), \
377 Fmake_vector (make_number (1), (elt)))) \
378 : fontset_add ((fontset), (range), (elt), (add)))
379
380 static Lisp_Object
381 fontset_add (fontset, range, elt, add)
382 Lisp_Object fontset, range, elt, add;
383 {
384 Lisp_Object args[2];
385 int idx = (EQ (add, Qappend) ? 0 : 1);
386
387 args[1 - idx] = Fmake_vector (make_number (1), elt);
388
389 if (CONSP (range))
390 {
391 int from = XINT (XCAR (range));
392 int to = XINT (XCDR (range));
393 int from1, to1;
394
395 do {
396 args[idx] = char_table_ref_and_range (fontset, from, &from1, &to1);
397 if (to < to1)
398 to1 = to;
399 char_table_set_range (fontset, from, to1,
400 NILP (args[idx]) ? args[1 - idx]
401 : Fvconcat (2, args));
402 from = to1 + 1;
403 } while (from < to);
404 }
405 else
406 {
407 args[idx] = FONTSET_FALLBACK (fontset);
408 FONTSET_FALLBACK (fontset)
409 = NILP (args[idx]) ? args[1 - idx] : Fvconcat (2, args);
410 }
411 return Qnil;
412 }
413
414
415 /* Update FONTSET_ELEMENT which has this form:
416 [CHARSET-PRIORITY-LIST-TICK PREFERRED-CHARSET-ID INDEX
417 FONT-DEF0 FONT-DEF1 ...].
418 Reorder FONT-DEFs according to the current order of charset
419 (Vcharset_ordered_list), and update CHARSET-PRIORITY-LIST-TICK to
420 the latest value. */
421
422 static void
423 reorder_font_vector (fontset_element)
424 Lisp_Object fontset_element;
425 {
426 Lisp_Object vec, list, *new_vec;
427 Lisp_Object font_def;
428 int size;
429 int *charset_id_table;
430 int i, idx;
431
432 ASET (fontset_element, 0, make_number (charset_ordered_list_tick));
433 size = ASIZE (fontset_element) - 3;
434 if (size <= 1)
435 /* No need of reordering VEC. */
436 return;
437 charset_id_table = (int *) alloca (sizeof (int) * size);
438 new_vec = (Lisp_Object *) alloca (sizeof (Lisp_Object) * size);
439
440 /* At first, extract ENCODING (a chaset ID) from each FONT-DEF.
441 FONT-DEF has this form:
442 [FACE-ID FONT-INDEX [ FONT-SPEC ENCODING REPERTORY ]] */
443 for (i = 0; i < size; i++)
444 {
445 font_def = AREF (fontset_element, i + 3);
446 charset_id_table[i] = XINT (AREF (AREF (font_def, 2), 1));
447 }
448
449 /* Then, store FONT-DEFs in NEW_VEC in the correct order. */
450 for (idx = 0, list = Vcharset_ordered_list;
451 idx < size && CONSP (list); list = XCDR (list))
452 {
453 for (i = 0; i < size; i++)
454 if (charset_id_table[i] == XINT (XCAR (list)))
455 new_vec[idx++] = AREF (fontset_element, i + 3);
456 }
457
458 /* At last, update FONT-DEFs. */
459 for (i = 0; i < size; i++)
460 ASET (fontset_element, i + 3, new_vec[i]);
461 }
462
463
464 /* Load a font matching the font related attributes in FACE->lface and
465 font pattern in FONT_DEF of FONTSET, and return an index of the
466 font. FONT_DEF has this form:
467 [ FONT-SPEC ENCODING REPERTORY ]
468 If REPERTORY is nil, generate a char-table representing the font
469 repertory by looking into the font itself. */
470
471 static int
472 load_font_get_repertory (f, face, font_def, fontset)
473 FRAME_PTR f;
474 struct face *face;
475 Lisp_Object font_def;
476 Lisp_Object fontset;
477 {
478 char *font_name;
479 struct font_info *font_info;
480 int charset;
481
482 font_name = choose_face_font (f, face->lface, AREF (font_def, 0), NULL);
483 if (NATNUMP (AREF (font_def, 1)))
484 charset = XINT (AREF (font_def, 1));
485 else
486 charset = -1;
487 if (! (font_info = fs_load_font (f, font_name, charset)))
488 return -1;
489
490 if (NILP (AREF (font_def, 2))
491 && NILP (Fassq (make_number (font_info->font_idx),
492 FONTSET_REPERTORY (fontset))))
493 {
494 /* We must look into the font to get the correct repertory as a
495 char-table. */
496 Lisp_Object repertory;
497
498 repertory = (*get_font_repertory_func) (f, font_info);
499 FONTSET_REPERTORY (fontset)
500 = Fcons (Fcons (make_number (font_info->font_idx), repertory),
501 FONTSET_REPERTORY (fontset));
502 }
503
504 return font_info->font_idx;
505 }
506
507
508 /* Return a face ID registerd in the realized fontset FONTSET for the
509 character C. If a face is not yet set, return -1 (if FACE is NULL)
510 or realize a proper face from FACE and return it. */
511
512 static int
513 fontset_face (fontset, c, face, id)
514 Lisp_Object fontset;
515 int c;
516 struct face *face;
517 int id;
518 {
519 Lisp_Object base_fontset, elt, vec;
520 int i, from, to;
521 int font_idx;
522 FRAME_PTR f = XFRAME (FONTSET_FRAME (fontset));
523
524 base_fontset = FONTSET_BASE (fontset);
525 vec = CHAR_TABLE_REF (fontset, c);
526 if (EQ (vec, Qt))
527 goto try_fallback;
528
529 if (NILP (vec))
530 {
531 /* We have not yet decided a face for C. */
532 Lisp_Object range;
533
534 if (! face)
535 return -1;
536 elt = FONTSET_REF_AND_RANGE (base_fontset, c, from, to);
537 range = Fcons (make_number (from), make_number (to));
538 if (NILP (elt))
539 {
540 /* Record that we have no font for characters of this
541 range. */
542 vec = Qt;
543 FONTSET_SET (fontset, range, vec);
544 goto try_fallback;
545 }
546 /* Build a vector [ -1 -1 nil NEW-ELT0 NEW-ELT1 NEW-ELT2 ... ],
547 where the first -1 is to force reordering of NEW-ELTn,
548 NEW-ETLn is [nil nil AREF (elt, n)]. */
549 vec = Fmake_vector (make_number (ASIZE (elt) + 3), make_number (-1));
550 ASET (vec, 2, Qnil);
551 for (i = 0; i < ASIZE (elt); i++)
552 {
553 Lisp_Object tmp;
554
555 tmp = Fmake_vector (make_number (3), Qnil);
556 ASET (tmp, 2, AREF (elt, i));
557 ASET (vec, 3 + i, tmp);
558 }
559 /* Then store it in the fontset. */
560 FONTSET_SET (fontset, range, vec);
561 }
562
563 retry:
564 if (XINT (AREF (vec, 0)) != charset_ordered_list_tick)
565 /* The priority of charsets is changed after we selected a face
566 for C last time. */
567 reorder_font_vector (vec);
568
569 if (id < 0)
570 i = 3;
571 else if (id == XFASTINT (AREF (vec, 1)))
572 i = 2;
573 else
574 {
575 ASET (vec, 1, make_number (id));
576 for (i = 3; i < ASIZE (vec); i++)
577 if (id == XFASTINT (AREF (AREF (AREF (vec, i), 2), 1)))
578 break;
579 if (i < ASIZE (vec))
580 {
581 ASET (vec, 2, AREF (vec, i));
582 i = 2;
583 }
584 else
585 {
586 ASET (vec, 2, Qnil);
587 i = 3;
588 }
589 }
590
591 /* Find the first available font in the font vector VEC. */
592 for (; i < ASIZE (vec); i++)
593 {
594 Lisp_Object font_def;
595
596 elt = AREF (vec, i);
597 if (NILP (elt))
598 continue;
599 /* ELT == [ FACE-ID FONT-INDEX [ FONT-SPEC ENCODING REPERTORY ] ] */
600 font_def = AREF (elt, 2);
601 if (INTEGERP (AREF (elt, 1)) && XINT (AREF (elt, 1)) < 0)
602 /* We couldn't open this font last time. */
603 continue;
604
605 if (!face && (NILP (AREF (elt, 1)) || NILP (AREF (elt, 0))))
606 /* We have not yet opened the font, or we have not yet made a
607 realized face for the font. */
608 return -1;
609
610 if (INTEGERP (AREF (font_def, 2)))
611 {
612 /* The repertory is specified by charset ID. */
613 struct charset *charset
614 = CHARSET_FROM_ID (XINT (AREF (font_def, 2)));
615
616 if (! CHAR_CHARSET_P (c, charset))
617 /* This font can't display C. */
618 continue;
619 }
620 else if (CHAR_TABLE_P (AREF (font_def, 2)))
621 {
622 /* The repertory is specified by a char table. */
623 if (NILP (CHAR_TABLE_REF (AREF (font_def, 2), c)))
624 /* This font can't display C. */
625 continue;
626 }
627 else
628 {
629 Lisp_Object slot;
630
631 if (! INTEGERP (AREF (elt, 1)))
632 {
633 /* We have not yet opened a font matching this spec.
634 Open the best matching font now and register the
635 repertory. */
636 font_idx = load_font_get_repertory (f, face, font_def, fontset);
637 ASET (elt, 1, make_number (font_idx));
638 if (font_idx < 0)
639 /* This means that we couldn't find a font matching
640 FONT_DEF. */
641 continue;
642 }
643
644 slot = Fassq (AREF (elt, 1), FONTSET_REPERTORY (fontset));
645 if (! CONSP (slot))
646 abort ();
647 if (NILP (CHAR_TABLE_REF (XCDR (slot), c)))
648 /* This fond can't display C. */
649 continue;
650 }
651
652 /* Now we have decided to use this font spec to display C. */
653 if (INTEGERP (AREF (elt, 1)))
654 font_idx = XINT (AREF (elt, 1));
655 else
656 {
657 /* But not yet opened the best matching font. */
658 font_idx = load_font_get_repertory (f, face, font_def, fontset);
659 ASET (elt, 1, make_number (font_idx));
660 if (font_idx < 0)
661 continue;
662 }
663
664 /* Now we have the opened font. */
665 if (NILP (AREF (elt, 0)))
666 {
667 /* But not yet made a realized face that uses this font. */
668 int face_id = lookup_non_ascii_face (f, font_idx, face);
669
670 ASET (elt, 0, make_number (face_id));
671 }
672
673 /* Ok, this face can display C. */
674 return XINT (AREF (elt, 0));
675 }
676
677 try_fallback:
678 if (! EQ (vec, FONTSET_FALLBACK (fontset)))
679 {
680 vec = FONTSET_FALLBACK (fontset);
681 if (VECTORP (vec))
682 goto retry;
683 if (EQ (vec, Qt))
684 goto try_default;
685 elt = FONTSET_FALLBACK (base_fontset);
686 if (! NILP (elt))
687 {
688 vec = Fmake_vector (make_number (ASIZE (elt) + 3), make_number (-1));
689 ASET (vec, 2, Qnil);
690 for (i = 0; i < ASIZE (elt); i++)
691 {
692 Lisp_Object tmp;
693
694 tmp = Fmake_vector (make_number (3), Qnil);
695 ASET (tmp, 2, AREF (elt, i));
696 ASET (vec, 3 + i, tmp);
697 }
698 FONTSET_FALLBACK (fontset) = vec;
699 goto retry;
700 }
701 /* Record that this fontset has no fallback fonts. */
702 FONTSET_FALLBACK (fontset) = Qt;
703 }
704
705 /* Try the default fontset. */
706 try_default:
707 if (! EQ (base_fontset, Vdefault_fontset))
708 {
709 if (NILP (FONTSET_DEFAULT (fontset)))
710 FONTSET_DEFAULT (fontset)
711 = make_fontset (FONTSET_FRAME (fontset), Qnil, Vdefault_fontset);
712 return fontset_face (FONTSET_DEFAULT (fontset), c, face, id);
713 }
714
715 /* We have tried all the fonts for C, but none of them can be opened
716 nor can display C. */
717 if (NILP (FONTSET_NOFONT_FACE (fontset)))
718 {
719 int face_id;
720
721 if (! face)
722 return -1;
723 face_id = lookup_non_ascii_face (f, -1, face);
724 FONTSET_NOFONT_FACE (fontset) = make_number (face_id);
725 }
726 return XINT (FONTSET_NOFONT_FACE (fontset));
727 }
728
729
730 /* Return a newly created fontset with NAME. If BASE is nil, make a
731 base fontset. Otherwise make a realized fontset whose base is
732 BASE. */
733
734 static Lisp_Object
735 make_fontset (frame, name, base)
736 Lisp_Object frame, name, base;
737 {
738 Lisp_Object fontset;
739 int size = ASIZE (Vfontset_table);
740 int id = next_fontset_id;
741
742 /* Find a free slot in Vfontset_table. Usually, next_fontset_id is
743 the next available fontset ID. So it is expected that this loop
744 terminates quickly. In addition, as the last element of
745 Vfontset_table is always nil, we don't have to check the range of
746 id. */
747 while (!NILP (AREF (Vfontset_table, id))) id++;
748
749 if (id + 1 == size)
750 {
751 /* We must grow Vfontset_table. */
752 Lisp_Object tem;
753 int i;
754
755 tem = Fmake_vector (make_number (size + 32), Qnil);
756 for (i = 0; i < size; i++)
757 AREF (tem, i) = AREF (Vfontset_table, i);
758 Vfontset_table = tem;
759 }
760
761 fontset = Fmake_char_table (Qfontset, Qnil);
762
763 FONTSET_ID (fontset) = make_number (id);
764 if (NILP (base))
765 {
766 FONTSET_NAME (fontset) = name;
767 }
768 else
769 {
770 FONTSET_NAME (fontset) = Qnil;
771 FONTSET_FRAME (fontset) = frame;
772 FONTSET_BASE (fontset) = base;
773 }
774
775 ASET (Vfontset_table, id, fontset);
776 next_fontset_id = id + 1;
777 return fontset;
778 }
779
780
781 \f
782 /********** INTERFACES TO xfaces.c, xfns.c, and dispextern.h **********/
783
784 /* Return the name of the fontset who has ID. */
785
786 Lisp_Object
787 fontset_name (id)
788 int id;
789 {
790 Lisp_Object fontset;
791
792 fontset = FONTSET_FROM_ID (id);
793 return FONTSET_NAME (fontset);
794 }
795
796
797 /* Return the ASCII font name of the fontset who has ID. */
798
799 Lisp_Object
800 fontset_ascii (id)
801 int id;
802 {
803 Lisp_Object fontset, elt;
804
805 fontset= FONTSET_FROM_ID (id);
806 elt = FONTSET_ASCII (fontset);
807 /* It is assured that ELT is always a string (i.e. fontname
808 pattern). */
809 return elt;
810 }
811
812
813 /* Free fontset of FACE defined on frame F. Called from
814 free_realized_face. */
815
816 void
817 free_face_fontset (f, face)
818 FRAME_PTR f;
819 struct face *face;
820 {
821 Lisp_Object fontset;
822
823 fontset = AREF (Vfontset_table, face->fontset);
824 xassert (!NILP (fontset) && ! BASE_FONTSET_P (fontset));
825 xassert (f == XFRAME (FONTSET_FRAME (fontset)));
826 ASET (Vfontset_table, face->fontset, Qnil);
827 if (face->fontset < next_fontset_id)
828 next_fontset_id = face->fontset;
829 if (! NILP (FONTSET_DEFAULT (fontset)))
830 {
831 int id = XINT (FONTSET_ID (FONTSET_DEFAULT (fontset)));
832
833 fontset = AREF (Vfontset_table, id);
834 xassert (!NILP (fontset) && ! BASE_FONTSET_P (fontset));
835 xassert (f == XFRAME (FONTSET_FRAME (fontset)));
836 ASET (Vfontset_table, id, Qnil);
837 if (id < next_fontset_id)
838 next_fontset_id = face->fontset;
839 }
840 }
841
842
843 /* Return 1 iff FACE is suitable for displaying character C.
844 Otherwise return 0. Called from the macro FACE_SUITABLE_FOR_CHAR_P
845 when C is not an ASCII character. */
846
847 int
848 face_suitable_for_char_p (face, c)
849 struct face *face;
850 int c;
851 {
852 Lisp_Object fontset;
853
854 fontset = FONTSET_FROM_ID (face->fontset);
855 return (face->id == fontset_face (fontset, c, NULL, -1));
856 }
857
858
859 /* Return ID of face suitable for displaying character C on frame F.
860 FACE must be reazlied for ASCII characters in advance. Called from
861 the macro FACE_FOR_CHAR. */
862
863 int
864 face_for_char (f, face, c, pos, object)
865 FRAME_PTR f;
866 struct face *face;
867 int c, pos;
868 Lisp_Object object;
869 {
870 Lisp_Object fontset, charset;
871 int id;
872
873 if (ASCII_CHAR_P (c))
874 return face->ascii_face->id;
875
876 xassert (fontset_id_valid_p (face->fontset));
877 fontset = FONTSET_FROM_ID (face->fontset);
878 xassert (!BASE_FONTSET_P (fontset));
879 if (pos < 0)
880 id = -1;
881 else
882 {
883 charset = Fget_char_property (make_number (pos), Qcharset, object);
884 if (NILP (charset))
885 id = -1;
886 else if (CHARSETP (charset))
887 id = XINT (CHARSET_SYMBOL_ID (charset));
888 }
889 return fontset_face (fontset, c, face, id);
890 }
891
892
893 /* Make a realized fontset for ASCII face FACE on frame F from the
894 base fontset BASE_FONTSET_ID. If BASE_FONTSET_ID is -1, use the
895 default fontset as the base. Value is the id of the new fontset.
896 Called from realize_x_face. */
897
898 int
899 make_fontset_for_ascii_face (f, base_fontset_id, face)
900 FRAME_PTR f;
901 int base_fontset_id;
902 struct face *face;
903 {
904 Lisp_Object base_fontset, fontset, frame;
905
906 XSETFRAME (frame, f);
907 if (base_fontset_id >= 0)
908 {
909 base_fontset = FONTSET_FROM_ID (base_fontset_id);
910 if (!BASE_FONTSET_P (base_fontset))
911 base_fontset = FONTSET_BASE (base_fontset);
912 xassert (BASE_FONTSET_P (base_fontset));
913 if (! BASE_FONTSET_P (base_fontset))
914 abort ();
915 }
916 else
917 base_fontset = Vdefault_fontset;
918
919 fontset = make_fontset (frame, Qnil, base_fontset);
920 {
921 Lisp_Object elt;
922
923 elt = FONTSET_REF (base_fontset, 0);
924 elt = Fmake_vector (make_number (4), AREF (elt, 0));
925 ASET (elt, 0, make_number (charset_ordered_list_tick));
926 ASET (elt, 1, make_number (face->id));
927 ASET (elt, 2, make_number (face->font_info_id));
928 char_table_set_range (fontset, 0, 127, elt);
929 }
930 return XINT (FONTSET_ID (fontset));
931 }
932
933
934 #if defined(WINDOWSNT) && defined (_MSC_VER)
935 #pragma optimize("", off)
936 #endif
937
938 /* Load a font named FONTNAME on frame F. Return a pointer to the
939 struct font_info of the loaded font. If loading fails, return
940 NULL. CHARSET is an ID of charset to encode characters for this
941 font. If it is -1, find one from Vfont_encoding_alist. */
942
943 struct font_info *
944 fs_load_font (f, fontname, charset)
945 FRAME_PTR f;
946 char *fontname;
947 int charset;
948 {
949 struct font_info *fontp;
950
951 if (!fontname)
952 /* No way to get fontname. */
953 return NULL;
954
955 fontp = (*load_font_func) (f, fontname, 0);
956 if (! fontp || fontp->charset >= 0)
957 return fontp;
958
959 fontname = fontp->full_name;
960
961 if (charset < 0)
962 {
963 Lisp_Object charset_symbol;
964
965 charset_symbol = find_font_encoding (fontname);
966 if (CONSP (charset_symbol))
967 charset_symbol = XCAR (charset_symbol);
968 charset = XINT (CHARSET_SYMBOL_ID (charset_symbol));
969 }
970 fontp->charset = charset;
971 fontp->vertical_centering = 0;
972 fontp->font_encoder = NULL;
973
974 if (charset != charset_ascii)
975 {
976 fontp->vertical_centering
977 = (STRINGP (Vvertical_centering_font_regexp)
978 && (fast_c_string_match_ignore_case
979 (Vvertical_centering_font_regexp, fontname) >= 0));
980
981 if (find_ccl_program_func)
982 (*find_ccl_program_func) (fontp);
983 }
984
985 return fontp;
986 }
987
988 #if defined(WINDOWSNT) && defined (_MSC_VER)
989 #pragma optimize("", on)
990 #endif
991
992 \f
993 /* Return ENCODING or a cons of ENCODING and REPERTORY of the font
994 FONTNAME. ENCODING is a charset symbol that specifies the encoding
995 of the font. REPERTORY is a charset symbol or nil. */
996
997
998 static Lisp_Object
999 find_font_encoding (fontname)
1000 char *fontname;
1001 {
1002 Lisp_Object tail, elt;
1003
1004 for (tail = Vfont_encoding_alist; CONSP (tail); tail = XCDR (tail))
1005 {
1006 elt = XCAR (tail);
1007 if (CONSP (elt)
1008 && STRINGP (XCAR (elt))
1009 && fast_c_string_match_ignore_case (XCAR (elt), fontname) >= 0
1010 && (SYMBOLP (XCDR (elt))
1011 ? CHARSETP (XCDR (elt))
1012 : CONSP (XCDR (elt)) && CHARSETP (XCAR (XCDR (elt)))))
1013 return (XCDR (elt));
1014 }
1015 /* We don't know the encoding of this font. */
1016 return Qnil;
1017 }
1018
1019
1020 /* Cache data used by fontset_pattern_regexp. The car part is a
1021 pattern string containing at least one wild card, the cdr part is
1022 the corresponding regular expression. */
1023 static Lisp_Object Vcached_fontset_data;
1024
1025 #define CACHED_FONTSET_NAME (SDATA (XCAR (Vcached_fontset_data)))
1026 #define CACHED_FONTSET_REGEX (XCDR (Vcached_fontset_data))
1027
1028 /* If fontset name PATTERN contains any wild card, return regular
1029 expression corresponding to PATTERN. */
1030
1031 static Lisp_Object
1032 fontset_pattern_regexp (pattern)
1033 Lisp_Object pattern;
1034 {
1035 if (!index (SDATA (pattern), '*')
1036 && !index (SDATA (pattern), '?'))
1037 /* PATTERN does not contain any wild cards. */
1038 return Qnil;
1039
1040 if (!CONSP (Vcached_fontset_data)
1041 || strcmp (SDATA (pattern), CACHED_FONTSET_NAME))
1042 {
1043 /* We must at first update the cached data. */
1044 char *regex = (char *) alloca (SCHARS (pattern) * 2 + 3);
1045 char *p0, *p1 = regex;
1046
1047 /* Convert "*" to ".*", "?" to ".". */
1048 *p1++ = '^';
1049 for (p0 = (char *) SDATA (pattern); *p0; p0++)
1050 {
1051 if (*p0 == '*')
1052 {
1053 *p1++ = '.';
1054 *p1++ = '*';
1055 }
1056 else if (*p0 == '?')
1057 *p1++ = '.';
1058 else
1059 *p1++ = *p0;
1060 }
1061 *p1++ = '$';
1062 *p1++ = 0;
1063
1064 Vcached_fontset_data = Fcons (build_string (SDATA (pattern)),
1065 build_string (regex));
1066 }
1067
1068 return CACHED_FONTSET_REGEX;
1069 }
1070
1071 /* Return ID of the base fontset named NAME. If there's no such
1072 fontset, return -1. */
1073
1074 int
1075 fs_query_fontset (name, regexpp)
1076 Lisp_Object name;
1077 int regexpp;
1078 {
1079 Lisp_Object tem;
1080 int i;
1081
1082 name = Fdowncase (name);
1083 if (!regexpp)
1084 {
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
1091 {
1092 tem = fontset_pattern_regexp (name);
1093 if (STRINGP (tem))
1094 {
1095 name = tem;
1096 regexpp = 1;
1097 }
1098 }
1099 }
1100
1101 for (i = 0; i < ASIZE (Vfontset_table); i++)
1102 {
1103 Lisp_Object fontset;
1104 unsigned char *this_name;
1105
1106 fontset = FONTSET_FROM_ID (i);
1107 if (NILP (fontset)
1108 || !BASE_FONTSET_P (fontset))
1109 continue;
1110
1111 this_name = SDATA (FONTSET_NAME (fontset));
1112 if (regexpp
1113 ? fast_c_string_match_ignore_case (name, this_name) >= 0
1114 : !strcmp (SDATA (name), this_name))
1115 return i;
1116 }
1117 return -1;
1118 }
1119
1120
1121 DEFUN ("query-fontset", Fquery_fontset, Squery_fontset, 1, 2, 0,
1122 doc: /* Return the name of a fontset that matches PATTERN.
1123 The value is nil if there is no matching fontset.
1124 PATTERN can contain `*' or `?' as a wildcard
1125 just as X font name matching algorithm allows.
1126 If REGEXPP is non-nil, PATTERN is a regular expression. */)
1127 (pattern, regexpp)
1128 Lisp_Object pattern, regexpp;
1129 {
1130 Lisp_Object fontset;
1131 int id;
1132
1133 (*check_window_system_func) ();
1134
1135 CHECK_STRING (pattern);
1136
1137 if (SCHARS (pattern) == 0)
1138 return Qnil;
1139
1140 id = fs_query_fontset (pattern, !NILP (regexpp));
1141 if (id < 0)
1142 return Qnil;
1143
1144 fontset = FONTSET_FROM_ID (id);
1145 return FONTSET_NAME (fontset);
1146 }
1147
1148 /* Return a list of base fontset names matching PATTERN on frame F. */
1149
1150 Lisp_Object
1151 list_fontsets (f, pattern, size)
1152 FRAME_PTR f;
1153 Lisp_Object pattern;
1154 int size;
1155 {
1156 Lisp_Object frame, regexp, val;
1157 int id;
1158
1159 XSETFRAME (frame, f);
1160
1161 regexp = fontset_pattern_regexp (pattern);
1162 val = Qnil;
1163
1164 for (id = 0; id < ASIZE (Vfontset_table); id++)
1165 {
1166 Lisp_Object fontset;
1167 unsigned char *name;
1168
1169 fontset = FONTSET_FROM_ID (id);
1170 if (NILP (fontset)
1171 || !BASE_FONTSET_P (fontset)
1172 || !EQ (frame, FONTSET_FRAME (fontset)))
1173 continue;
1174 name = SDATA (FONTSET_NAME (fontset));
1175
1176 if (STRINGP (regexp)
1177 ? (fast_c_string_match_ignore_case (regexp, name) < 0)
1178 : strcmp (SDATA (pattern), name))
1179 continue;
1180
1181 val = Fcons (Fcopy_sequence (FONTSET_NAME (fontset)), val);
1182 }
1183
1184 return val;
1185 }
1186
1187
1188 /* Free all realized fontsets whose base fontset is BASE. */
1189
1190 static void
1191 free_realized_fontsets (base)
1192 Lisp_Object base;
1193 {
1194 #if 0
1195 int id;
1196
1197 /* For the moment, this doesn't work because free_realized_face
1198 doesn't remove FACE from a cache. Until we find a solution, we
1199 suppress this code, and simply use Fclear_face_cache even though
1200 that is not efficient. */
1201 BLOCK_INPUT;
1202 for (id = 0; id < ASIZE (Vfontset_table); id++)
1203 {
1204 Lisp_Object this = AREF (Vfontset_table, id);
1205
1206 if (EQ (FONTSET_BASE (this), base))
1207 {
1208 Lisp_Object tail;
1209
1210 for (tail = FONTSET_FACE_ALIST (this); CONSP (tail);
1211 tail = XCDR (tail))
1212 {
1213 FRAME_PTR f = XFRAME (FONTSET_FRAME (this));
1214 int face_id = XINT (XCDR (XCAR (tail)));
1215 struct face *face = FACE_FROM_ID (f, face_id);
1216
1217 /* Face THIS itself is also freed by the following call. */
1218 free_realized_face (f, face);
1219 }
1220 }
1221 }
1222 UNBLOCK_INPUT;
1223 #else /* not 0 */
1224 Fclear_face_cache (Qt);
1225 #endif /* not 0 */
1226 }
1227
1228
1229 /* Check validity of NAME as a fontset name and return the
1230 corresponding fontset. If not valid, signal an error.
1231 If NAME is t, return Vdefault_fontset. */
1232
1233 static Lisp_Object
1234 check_fontset_name (name)
1235 Lisp_Object name;
1236 {
1237 int id;
1238
1239 if (EQ (name, Qt))
1240 return Vdefault_fontset;
1241
1242 CHECK_STRING (name);
1243 id = fs_query_fontset (name, 0);
1244 if (id < 0)
1245 error ("Fontset `%s' does not exist", SDATA (name));
1246 return FONTSET_FROM_ID (id);
1247 }
1248
1249 static void
1250 accumulate_script_ranges (arg, range, val)
1251 Lisp_Object arg, range, val;
1252 {
1253 if (EQ (XCAR (arg), val))
1254 {
1255 if (CONSP (range))
1256 XSETCDR (arg, Fcons (Fcons (XCAR (range), XCDR (range)), XCDR (arg)));
1257 else
1258 XSETCDR (arg, Fcons (Fcons (range, range), XCDR (arg)));
1259 }
1260 }
1261
1262
1263 /* Return an ASCII font name generated from fontset name NAME and
1264 ASCII font specification ASCII_SPEC. NAME is a string conforming
1265 to XLFD. ASCII_SPEC is a vector:
1266 [FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY]. */
1267
1268 static INLINE Lisp_Object
1269 generate_ascii_font_name (name, ascii_spec)
1270 Lisp_Object name, ascii_spec;
1271 {
1272 Lisp_Object vec;
1273 int i;
1274
1275 vec = split_font_name_into_vector (name);
1276 for (i = FONT_SPEC_FAMILY_INDEX; i <= FONT_SPEC_ADSTYLE_INDEX; i++)
1277 if (! NILP (AREF (ascii_spec, i)))
1278 ASET (vec, 1 + i, AREF (ascii_spec, i));
1279 if (! NILP (AREF (ascii_spec, FONT_SPEC_REGISTRY_INDEX)))
1280 ASET (vec, 12, AREF (ascii_spec, FONT_SPEC_REGISTRY_INDEX));
1281 return build_font_name_from_vector (vec);
1282 }
1283
1284 static void
1285 set_fontset_font (arg, range)
1286 Lisp_Object arg, range;
1287 {
1288 Lisp_Object fontset, font_def, add;
1289
1290 fontset = XCAR (arg);
1291 font_def = XCAR (XCDR (arg));
1292 add = XCAR (XCDR (XCDR (arg)));
1293 FONTSET_ADD (fontset, range, font_def, add);
1294 free_realized_fontsets (fontset);
1295 }
1296
1297
1298 DEFUN ("set-fontset-font", Fset_fontset_font, Sset_fontset_font, 3, 5, 0,
1299 doc: /*
1300 Modify fontset NAME to use FONT-SPEC for TARGET characters.
1301
1302 TARGET may be a cons; (FROM . TO), where FROM and TO are characters.
1303 In that case, use FONT-SPEC for all characters in the range FROM and
1304 TO (inclusive).
1305
1306 TARGET may be a script name symbol. In that case, use FONT-SPEC for
1307 all characters that belong to the script.
1308
1309 TARGET may be a charset. In that case, use FONT-SPEC for all
1310 characters in the charset.
1311
1312 TARGET may be nil. In that case, use FONT-SPEC for any characters for
1313 that no FONT-SPEC is specified.
1314
1315 FONT-SPEC may be:
1316 * A vector [ FAMILY WEIGHT SLANT WIDTH ADSTYLE REGISTRY ].
1317 See the documentation of `set-face-attribute' for the detail of
1318 these vector elements;
1319 * A cons (FAMILY . REGISTRY), where FAMILY is a font family name and
1320 REGISTRY is a font registry name;
1321 * A font name string.
1322
1323 Optional 4th argument FRAME, if non-nil, is a frame. This argument is
1324 kept for backward compatibility and has no meaning.
1325
1326 Optional 5th argument ADD, if non-nil, specifies how to add FONT-SPEC
1327 to the font specifications for TARGET previously set. If it is
1328 `prepend', FONT-SPEC is prepended. If it is `append', FONT-SPEC is
1329 appended. By default, FONT-SPEC overrides the previous settings. */)
1330 (name, target, font_spec, frame, add)
1331 Lisp_Object name, target, font_spec, frame, add;
1332 {
1333 Lisp_Object fontset;
1334 Lisp_Object font_def, registry;
1335 Lisp_Object encoding, repertory;
1336 Lisp_Object range_list;
1337
1338 fontset = check_fontset_name (name);
1339
1340 /* The arg FRAME is kept for backward compatibility. We only check
1341 the validity. */
1342 if (!NILP (frame))
1343 CHECK_LIVE_FRAME (frame);
1344
1345 if (VECTORP (font_spec))
1346 {
1347 int j;
1348
1349 if (ASIZE (font_spec) != FONT_SPEC_MAX_INDEX)
1350 args_out_of_range (make_number (FONT_SPEC_MAX_INDEX),
1351 make_number (ASIZE (font_spec)));
1352
1353 font_spec = Fcopy_sequence (font_spec);
1354 for (j = 0; j < FONT_SPEC_MAX_INDEX - 1; j++)
1355 if (! NILP (AREF (font_spec, j)))
1356 {
1357 CHECK_STRING (AREF (font_spec, j));
1358 ASET (font_spec, j, Fdowncase (AREF (font_spec, j)));
1359 }
1360 /* REGISTRY should not be omitted. */
1361 CHECK_STRING (AREF (font_spec, FONT_SPEC_REGISTRY_INDEX));
1362 registry = Fdowncase (AREF (font_spec, FONT_SPEC_REGISTRY_INDEX));
1363 ASET (font_spec, FONT_SPEC_REGISTRY_INDEX, registry);
1364
1365 }
1366 else if (CONSP (font_spec))
1367 {
1368 Lisp_Object family;
1369
1370 family = XCAR (font_spec);
1371 registry = XCDR (font_spec);
1372
1373 if (! NILP (family))
1374 {
1375 CHECK_STRING (family);
1376 family = Fdowncase (family);
1377 }
1378 CHECK_STRING (registry);
1379 registry = Fdowncase (registry);
1380 font_spec = Fmake_vector (make_number (FONT_SPEC_MAX_INDEX), Qnil);
1381 ASET (font_spec, FONT_SPEC_FAMILY_INDEX, family);
1382 ASET (font_spec, FONT_SPEC_REGISTRY_INDEX, registry);
1383 }
1384 else
1385 {
1386 CHECK_STRING (font_spec);
1387 font_spec = Fdowncase (font_spec);
1388 }
1389
1390 if (STRINGP (font_spec))
1391 encoding = find_font_encoding ((char *) SDATA (font_spec));
1392 else
1393 encoding = find_font_encoding ((char *) SDATA (registry));
1394 if (NILP (encoding))
1395 /* We don't know how to use this font. */
1396 return Qnil;
1397 if (SYMBOLP (encoding))
1398 {
1399 CHECK_CHARSET (encoding);
1400 encoding = repertory = CHARSET_SYMBOL_ID (encoding);
1401 }
1402 else
1403 {
1404 repertory = XCDR (encoding);
1405 encoding = XCAR (encoding);
1406 CHECK_CHARSET (encoding);
1407 encoding = CHARSET_SYMBOL_ID (encoding);
1408 if (! NILP (repertory) && SYMBOLP (repertory))
1409 {
1410 CHECK_CHARSET (repertory);
1411 repertory = CHARSET_SYMBOL_ID (repertory);
1412 }
1413 }
1414 font_def = Fmake_vector (make_number (3), font_spec);
1415 ASET (font_def, 1, encoding);
1416 ASET (font_def, 2, repertory);
1417
1418 if (CHARACTERP (target))
1419 range_list = Fcons (Fcons (target, target), Qnil);
1420 else if (CONSP (target))
1421 {
1422 Lisp_Object from, to;
1423
1424 from = Fcar (target);
1425 to = Fcdr (target);
1426 CHECK_CHARACTER (from);
1427 CHECK_CHARACTER (to);
1428 range_list = Fcons (target, Qnil);
1429 }
1430 else if (SYMBOLP (target) && !NILP (target))
1431 {
1432 Lisp_Object script_list;
1433 Lisp_Object val;
1434
1435 range_list = Qnil;
1436 script_list = XCHAR_TABLE (Vchar_script_table)->extras[0];
1437 if (! NILP (Fmemq (target, script_list)))
1438 {
1439 val = Fcons (target, Qnil);
1440 map_char_table (accumulate_script_ranges, Qnil, Vchar_script_table,
1441 val);
1442 range_list = XCDR (val);
1443 }
1444 else if (CHARSETP (target))
1445 {
1446 struct charset *charset;
1447
1448 CHECK_CHARSET_GET_CHARSET (target, charset);
1449 if (EQ (target, Qascii))
1450 {
1451 if (VECTORP (font_spec))
1452 font_spec = generate_ascii_font_name (FONTSET_NAME (fontset),
1453 font_spec);
1454 FONTSET_ASCII (fontset) = font_spec;
1455 range_list = Fcons (Fcons (make_number (0), make_number (127)),
1456 Qnil);
1457 }
1458 else
1459 {
1460 map_charset_chars (set_fontset_font, Qnil,
1461 list3 (fontset, font_def, add), charset,
1462 CHARSET_MIN_CODE (charset),
1463 CHARSET_MAX_CODE (charset));
1464 return Qnil;
1465 }
1466 }
1467
1468 if (NILP (range_list))
1469 error ("Invalid script or charset name: %s",
1470 SDATA (SYMBOL_NAME (target)));
1471 }
1472 else if (NILP (target))
1473 range_list = Fcons (Qnil, Qnil);
1474 else
1475 error ("Invalid target for setting a font");
1476
1477 for (; CONSP (range_list); range_list = XCDR (range_list))
1478 FONTSET_ADD (fontset, XCAR (range_list), font_def, add);
1479
1480 /* Free all realized fontsets whose base is FONTSET. This way, the
1481 specified character(s) are surely redisplayed by a correct
1482 font. */
1483 free_realized_fontsets (fontset);
1484
1485 return Qnil;
1486 }
1487
1488
1489 DEFUN ("new-fontset", Fnew_fontset, Snew_fontset, 2, 2, 0,
1490 doc: /* Create a new fontset NAME from font information in FONTLIST.
1491
1492 FONTLIST is an alist of scripts vs the corresponding font specification list.
1493 Each element of FONTLIST has the form (SCRIPT FONT-SPEC ...), where a
1494 character of SCRIPT is displayed by a font that matches one of
1495 FONT-SPEC.
1496
1497 SCRIPT is a symbol that appears in the first extra slot of the
1498 char-table `char-script-table'.
1499
1500 FONT-SPEC is a vector, a cons, or a string. See the documentation of
1501 `set-fontset-font' for the meaning. */)
1502 (name, fontlist)
1503 Lisp_Object name, fontlist;
1504 {
1505 Lisp_Object fontset;
1506 Lisp_Object val;
1507 int id;
1508
1509 CHECK_STRING (name);
1510 CHECK_LIST (fontlist);
1511
1512 id = fs_query_fontset (name, 0);
1513 if (id < 0)
1514 {
1515 name = Fdowncase (name);
1516 val = split_font_name_into_vector (name);
1517 if (NILP (val) || NILP (AREF (val, 12)) || NILP (AREF (val, 13)))
1518 error ("Fontset name must be in XLFD format");
1519 if (strcmp (SDATA (AREF (val, 12)), "fontset"))
1520 error ("Registry field of fontset name must be \"fontset\"");
1521 Vfontset_alias_alist
1522 = Fcons (Fcons (name,
1523 concat2 (concat2 (AREF (val, 12), build_string ("-")),
1524 AREF (val, 13))),
1525 Vfontset_alias_alist);
1526 ASET (val, 12, build_string ("iso8859-1"));
1527 fontset = make_fontset (Qnil, name, Qnil);
1528 FONTSET_ASCII (fontset) = build_font_name_from_vector (val);
1529 }
1530 else
1531 {
1532 fontset = FONTSET_FROM_ID (id);;
1533 free_realized_fontsets (fontset);
1534 Fset_char_table_range (fontset, Qt, Qnil);
1535 }
1536
1537 for (; ! NILP (fontlist); fontlist = Fcdr (fontlist))
1538 {
1539 Lisp_Object elt, script;
1540
1541 elt = Fcar (fontlist);
1542 script = Fcar (elt);
1543 elt = Fcdr (elt);
1544 if (CONSP (elt) && (NILP (XCDR (elt)) || CONSP (XCDR (elt))))
1545 for (; CONSP (elt); elt = XCDR (elt))
1546 Fset_fontset_font (name, script, XCAR (elt), Qnil, Qappend);
1547 else
1548 Fset_fontset_font (name, script, elt, Qnil, Qappend);
1549 }
1550 return name;
1551 }
1552
1553
1554 /* Alist of automatically created fontsets. Each element is a cons
1555 (FONTNAME . FONTSET-ID). */
1556 static Lisp_Object auto_fontset_alist;
1557
1558 int
1559 new_fontset_from_font_name (Lisp_Object fontname)
1560 {
1561 Lisp_Object val;
1562 Lisp_Object name;
1563 Lisp_Object vec;
1564 int id;
1565
1566 fontname = Fdowncase (fontname);
1567 val = Fassoc (fontname, auto_fontset_alist);
1568 if (CONSP (val))
1569 return XINT (XCDR (val));
1570
1571 vec = split_font_name_into_vector (fontname);
1572 if ( NILP (vec))
1573 vec = Fmake_vector (make_number (14), build_string (""));
1574 ASET (vec, 12, build_string ("fontset"));
1575 if (NILP (auto_fontset_alist))
1576 {
1577 ASET (vec, 13, build_string ("startup"));
1578 name = build_font_name_from_vector (vec);
1579 }
1580 else
1581 {
1582 char temp[20];
1583 int len = XINT (Flength (auto_fontset_alist));
1584
1585 sprintf (temp, "auto%d", len);
1586 ASET (vec, 13, build_string (temp));
1587 name = build_font_name_from_vector (vec);
1588 }
1589 name = Fnew_fontset (name, Fcons (Fcons (Fcons (make_number (0),
1590 make_number (MAX_CHAR)),
1591 Fcons (fontname, Qnil)),
1592 Qnil));
1593 id = fs_query_fontset (name, 0);
1594 auto_fontset_alist
1595 = Fcons (Fcons (fontname, make_number (id)), auto_fontset_alist);
1596 return id;
1597 }
1598
1599
1600 DEFUN ("font-info", Ffont_info, Sfont_info, 1, 2, 0,
1601 doc: /* Return information about a font named NAME on frame FRAME.
1602 If FRAME is omitted or nil, use the selected frame.
1603 The returned value is a vector of OPENED-NAME, FULL-NAME, CHARSET, SIZE,
1604 HEIGHT, BASELINE-OFFSET, RELATIVE-COMPOSE, and DEFAULT-ASCENT,
1605 where
1606 OPENED-NAME is the name used for opening the font,
1607 FULL-NAME is the full name of the font,
1608 SIZE is the maximum bound width of the font,
1609 HEIGHT is the height of the font,
1610 BASELINE-OFFSET is the upward offset pixels from ASCII baseline,
1611 RELATIVE-COMPOSE and DEFAULT-ASCENT are the numbers controlling
1612 how to compose characters.
1613 If the named font is not yet loaded, return nil. */)
1614 (name, frame)
1615 Lisp_Object name, frame;
1616 {
1617 FRAME_PTR f;
1618 struct font_info *fontp;
1619 Lisp_Object info;
1620
1621 (*check_window_system_func) ();
1622
1623 CHECK_STRING (name);
1624 name = Fdowncase (name);
1625 if (NILP (frame))
1626 frame = selected_frame;
1627 CHECK_LIVE_FRAME (frame);
1628 f = XFRAME (frame);
1629
1630 if (!query_font_func)
1631 error ("Font query function is not supported");
1632
1633 fontp = (*query_font_func) (f, SDATA (name));
1634 if (!fontp)
1635 return Qnil;
1636
1637 info = Fmake_vector (make_number (7), Qnil);
1638
1639 XVECTOR (info)->contents[0] = build_string (fontp->name);
1640 XVECTOR (info)->contents[1] = build_string (fontp->full_name);
1641 XVECTOR (info)->contents[2] = make_number (fontp->size);
1642 XVECTOR (info)->contents[3] = make_number (fontp->height);
1643 XVECTOR (info)->contents[4] = make_number (fontp->baseline_offset);
1644 XVECTOR (info)->contents[5] = make_number (fontp->relative_compose);
1645 XVECTOR (info)->contents[6] = make_number (fontp->default_ascent);
1646
1647 return info;
1648 }
1649
1650
1651 /* Return the font name for the character at POSITION in the current
1652 buffer. This is computed from all the text properties and overlays
1653 that apply to POSITION. It returns nil in the following cases:
1654
1655 (1) The window system doesn't have a font for the character (thus
1656 it is displayed by an empty box).
1657
1658 (2) The character code is invalid.
1659
1660 (3) The current buffer is not displayed in any window.
1661
1662 In addition, the returned font name may not take into account of
1663 such redisplay engine hooks as what used in jit-lock-mode if
1664 POSITION is currently not visible. */
1665
1666
1667 DEFUN ("internal-char-font", Finternal_char_font, Sinternal_char_font, 1, 1, 0,
1668 doc: /* For internal use only. */)
1669 (position)
1670 Lisp_Object position;
1671 {
1672 int pos, pos_byte, dummy;
1673 int face_id;
1674 int c;
1675 Lisp_Object window;
1676 struct window *w;
1677 struct frame *f;
1678 struct face *face;
1679
1680 CHECK_NUMBER_COERCE_MARKER (position);
1681 pos = XINT (position);
1682 if (pos < BEGV || pos >= ZV)
1683 args_out_of_range_3 (position, make_number (BEGV), make_number (ZV));
1684 pos_byte = CHAR_TO_BYTE (pos);
1685 c = FETCH_CHAR (pos_byte);
1686 window = Fget_buffer_window (Fcurrent_buffer (), Qnil);
1687 if (NILP (window))
1688 return Qnil;
1689 w = XWINDOW (window);
1690 f = XFRAME (w->frame);
1691 face_id = face_at_buffer_position (w, pos, -1, -1, &dummy, pos + 100, 0);
1692 face_id = FACE_FOR_CHAR (f, FACE_FROM_ID (f, face_id), c, pos, Qnil);
1693 face = FACE_FROM_ID (f, face_id);
1694 return (face->font && face->font_name
1695 ? build_string (face->font_name)
1696 : Qnil);
1697 }
1698
1699
1700 DEFUN ("fontset-info", Ffontset_info, Sfontset_info, 1, 2, 0,
1701 doc: /* Return information about a fontset FONTSET on frame FRAME.
1702 The value is a char-table of which elements has this form.
1703
1704 ((FONT-PATTERN OPENED-FONT ...) ...)
1705
1706 FONT-PATTERN is a vector:
1707
1708 [ FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY ]
1709
1710 or a string of font name pattern.
1711
1712 OPENED-FONT is a name of a font actually opened.
1713
1714 The char-table has one extra slot. The value is a char-table
1715 containing the information about the derived fonts from the default
1716 fontset. The format is the same as abobe. */)
1717 (fontset, frame)
1718 Lisp_Object fontset, frame;
1719 {
1720 FRAME_PTR f;
1721 Lisp_Object *realized[2], fontsets[2], tables[2];
1722 Lisp_Object val, elt;
1723 int c, i, j, k;
1724
1725 (*check_window_system_func) ();
1726
1727 fontset = check_fontset_name (fontset);
1728
1729 if (NILP (frame))
1730 frame = selected_frame;
1731 CHECK_LIVE_FRAME (frame);
1732 f = XFRAME (frame);
1733
1734 /* Recode fontsets realized on FRAME from the base fontset FONTSET
1735 in the table `realized'. */
1736 realized[0] = (Lisp_Object *) alloca (sizeof (Lisp_Object)
1737 * ASIZE (Vfontset_table));
1738 for (i = j = 0; i < ASIZE (Vfontset_table); i++)
1739 {
1740 elt = FONTSET_FROM_ID (i);
1741 if (!NILP (elt)
1742 && EQ (FONTSET_BASE (elt), fontset)
1743 && EQ (FONTSET_FRAME (elt), frame))
1744 realized[0][j++] = elt;
1745 }
1746 realized[0][j] = Qnil;
1747
1748 realized[1] = (Lisp_Object *) alloca (sizeof (Lisp_Object)
1749 * ASIZE (Vfontset_table));
1750 for (i = j = 0; ! NILP (realized[0][i]); i++)
1751 {
1752 elt = FONTSET_DEFAULT (realized[0][i]);
1753 if (! NILP (elt))
1754 realized[1][j++] = elt;
1755 }
1756 realized[1][j] = Qnil;
1757
1758 tables[0] = Fmake_char_table (Qfontset_info, Qnil);
1759 tables[1] = Fmake_char_table (Qnil, Qnil);
1760 XCHAR_TABLE (tables[0])->extras[0] = tables[1];
1761 fontsets[0] = fontset;
1762 fontsets[1] = Vdefault_fontset;
1763
1764 /* Accumulate information of the fontset in TABLE. The format of
1765 each element is ((FONT-SPEC OPENED-FONT ...) ...). */
1766 for (k = 0; k <= 1; k++)
1767 {
1768 for (c = 0; c <= MAX_CHAR; )
1769 {
1770 int from, to;
1771
1772 if (c <= MAX_5_BYTE_CHAR)
1773 {
1774 val = char_table_ref_and_range (fontsets[k], c, &from, &to);
1775 if (to > MAX_5_BYTE_CHAR)
1776 to = MAX_5_BYTE_CHAR;
1777 }
1778 else
1779 {
1780 val = FONTSET_FALLBACK (fontsets[k]);
1781 to = MAX_CHAR;
1782 }
1783 if (VECTORP (val))
1784 {
1785 Lisp_Object alist;
1786
1787 /* At first, set ALIST to ((FONT-SPEC) ...). */
1788 for (alist = Qnil, i = 0; i < ASIZE (val); i++)
1789 alist = Fcons (Fcons (AREF (AREF (val, i), 0), Qnil), alist);
1790 alist = Fnreverse (alist);
1791
1792 /* Then store opend font names to cdr of each elements. */
1793 for (i = 0; ! NILP (realized[k][i]); i++)
1794 {
1795 if (c <= MAX_5_BYTE_CHAR)
1796 val = FONTSET_REF (realized[k][i], c);
1797 else
1798 val = FONTSET_FALLBACK (realized[k][i]);
1799 if (! VECTORP (val))
1800 continue;
1801 /* VAL is [int int int [FACE-ID FONT-INDEX FONT-DEF] ...].
1802 If a font of an element is already opened,
1803 FONT-INDEX of the element is integer. */
1804 for (j = 3; j < ASIZE (val); j++)
1805 if (INTEGERP (AREF (AREF (val, j), 0)))
1806 {
1807 Lisp_Object font_idx;
1808
1809 font_idx = AREF (AREF (val, j), 1);
1810 elt = Fassq (AREF (AREF (AREF (val, j), 2), 0), alist);
1811 if (CONSP (elt)
1812 && NILP (Fmemq (font_idx, XCDR(elt))))
1813 nconc2 (elt, Fcons (font_idx, Qnil));
1814 }
1815 }
1816 for (val = alist; CONSP (val); val = XCDR (val))
1817 for (elt = XCDR (XCAR (val)); CONSP (elt); elt = XCDR (elt))
1818 {
1819 struct font_info *font_info
1820 = (*get_font_info_func) (f, XINT (XCAR (elt)));
1821 XSETCAR (elt, build_string (font_info->full_name));
1822 }
1823
1824 /* Store ALIST in TBL for characters C..TO. */
1825 if (c <= MAX_5_BYTE_CHAR)
1826 char_table_set_range (tables[k], c, to, alist);
1827 else
1828 XCHAR_TABLE (tables[k])->defalt = alist;
1829 }
1830 c = to + 1;
1831 }
1832 }
1833
1834 return tables[0];
1835 }
1836
1837
1838 DEFUN ("fontset-font", Ffontset_font, Sfontset_font, 2, 2, 0,
1839 doc: /* Return a font name pattern for character CH in fontset NAME.
1840 If NAME is t, find a font name pattern in the default fontset. */)
1841 (name, ch)
1842 Lisp_Object name, ch;
1843 {
1844 int c;
1845 Lisp_Object fontset, elt;
1846
1847 fontset = check_fontset_name (name);
1848
1849 CHECK_CHARACTER (ch);
1850 c = XINT (ch);
1851 elt = FONTSET_REF (fontset, c);
1852 return Fcopy_sequence (elt);
1853 }
1854
1855 DEFUN ("fontset-list", Ffontset_list, Sfontset_list, 0, 0, 0,
1856 doc: /* Return a list of all defined fontset names. */)
1857 ()
1858 {
1859 Lisp_Object fontset, list;
1860 int i;
1861
1862 list = Qnil;
1863 for (i = 0; i < ASIZE (Vfontset_table); i++)
1864 {
1865 fontset = FONTSET_FROM_ID (i);
1866 if (!NILP (fontset)
1867 && BASE_FONTSET_P (fontset))
1868 list = Fcons (FONTSET_NAME (fontset), list);
1869 }
1870
1871 return list;
1872 }
1873
1874
1875 #ifdef FONTSET_DEBUG
1876
1877 Lisp_Object
1878 dump_fontset (fontset)
1879 Lisp_Object fontset;
1880 {
1881 Lisp_Object vec;
1882
1883 vec = Fmake_vector (make_number (3), Qnil);
1884 ASET (vec, 0, FONTSET_ID (fontset));
1885
1886 if (BASE_FONTSET_P (fontset))
1887 {
1888 ASET (vec, 1, FONTSET_NAME (fontset));
1889 }
1890 else
1891 {
1892 Lisp_Object frame;
1893
1894 frame = FONTSET_FRAME (fontset);
1895 if (FRAMEP (frame))
1896 {
1897 FRAME_PTR f = XFRAME (frame);
1898
1899 if (FRAME_LIVE_P (f))
1900 ASET (vec, 1, f->name);
1901 else
1902 ASET (vec, 1, Qt);
1903 }
1904 if (!NILP (FONTSET_DEFAULT (fontset)))
1905 ASET (vec, 2, FONTSET_ID (FONTSET_DEFAULT (fontset)));
1906 }
1907 return vec;
1908 }
1909
1910 DEFUN ("fontset-list-all", Ffontset_list_all, Sfontset_list_all, 0, 0, 0,
1911 doc: /* Return a brief summary of all fontsets for debug use. */)
1912 ()
1913 {
1914 Lisp_Object val;
1915 int i;
1916
1917 for (i = 0, val = Qnil; i < ASIZE (Vfontset_table); i++)
1918 if (! NILP (AREF (Vfontset_table, i)))
1919 val = Fcons (dump_fontset (AREF (Vfontset_table, i)), val);
1920 return (Fnreverse (val));
1921 }
1922 #endif /* FONTSET_DEBUG */
1923
1924 void
1925 syms_of_fontset ()
1926 {
1927 if (!load_font_func)
1928 /* Window system initializer should have set proper functions. */
1929 abort ();
1930
1931 DEFSYM (Qfontset, "fontset");
1932 Fput (Qfontset, Qchar_table_extra_slots, make_number (9));
1933 DEFSYM (Qfontset_info, "fontset-info");
1934 Fput (Qfontset_info, Qchar_table_extra_slots, make_number (1));
1935
1936 DEFSYM (Qprepend, "prepend");
1937 DEFSYM (Qappend, "append");
1938
1939 Vcached_fontset_data = Qnil;
1940 staticpro (&Vcached_fontset_data);
1941
1942 Vfontset_table = Fmake_vector (make_number (32), Qnil);
1943 staticpro (&Vfontset_table);
1944
1945 Vdefault_fontset = Fmake_char_table (Qfontset, Qnil);
1946 staticpro (&Vdefault_fontset);
1947 FONTSET_ID (Vdefault_fontset) = make_number (0);
1948 FONTSET_NAME (Vdefault_fontset)
1949 = build_string ("-*-*-*-*-*-*-*-*-*-*-*-*-fontset-default");
1950 {
1951 Lisp_Object default_ascii_font;
1952
1953 #if defined (macintosh)
1954 default_ascii_font
1955 = build_string ("-apple-monaco-medium-r-*--*-120-*-*-*-*-mac-roman");
1956 #elif defined (WINDOWSNT)
1957 default_ascii_font
1958 = build_string ("-*-courier new-normal-r-*-*-*-100-*-*-*-*-iso8859-1");
1959 #else
1960 default_ascii_font
1961 = build_string ("-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1");
1962 #endif
1963 FONTSET_ASCII (Vdefault_fontset) = default_ascii_font;
1964 }
1965 AREF (Vfontset_table, 0) = Vdefault_fontset;
1966 next_fontset_id = 1;
1967
1968 auto_fontset_alist = Qnil;
1969 staticpro (&auto_fontset_alist);
1970
1971 DEFVAR_LISP ("font-encoding-alist", &Vfont_encoding_alist,
1972 doc: /*
1973 Alist of fontname patterns vs the corresponding encoding and repertory info.
1974 Each element looks like (REGEXP . (ENCODING . REPERTORY)),
1975 where ENCODING is a charset or a char-table,
1976 and REPERTORY is a charset, a char-table, or nil.
1977
1978 ENCODING is for converting a character to a glyph code of the font.
1979 If ENCODING is a charset, encoding a character by the charset gives
1980 the corresponding glyph code. If ENCODING is a char-table, looking up
1981 the table by a character gives the corresponding glyph code.
1982
1983 REPERTORY specifies a repertory of characters supported by the font.
1984 If REPERTORY is a charset, all characters beloging to the charset are
1985 supported. If REPERTORY is a char-table, all characters who have a
1986 non-nil value in the table are supported. It REPERTORY is nil, Emacs
1987 gets the repertory information by an opened font and ENCODING. */);
1988 Vfont_encoding_alist = Qnil;
1989
1990 DEFVAR_LISP ("use-default-ascent", &Vuse_default_ascent,
1991 doc: /*
1992 Char table of characters whose ascent values should be ignored.
1993 If an entry for a character is non-nil, the ascent value of the glyph
1994 is assumed to be what specified by _MULE_DEFAULT_ASCENT property of a font.
1995
1996 This affects how a composite character which contains
1997 such a character is displayed on screen. */);
1998 Vuse_default_ascent = Qnil;
1999
2000 DEFVAR_LISP ("ignore-relative-composition", &Vignore_relative_composition,
2001 doc: /*
2002 Char table of characters which is not composed relatively.
2003 If an entry for a character is non-nil, a composition sequence
2004 which contains that character is displayed so that
2005 the glyph of that character is put without considering
2006 an ascent and descent value of a previous character. */);
2007 Vignore_relative_composition = Qnil;
2008
2009 DEFVAR_LISP ("alternate-fontname-alist", &Valternate_fontname_alist,
2010 doc: /* Alist of fontname vs list of the alternate fontnames.
2011 When a specified font name is not found, the corresponding
2012 alternate fontnames (if any) are tried instead. */);
2013 Valternate_fontname_alist = Qnil;
2014
2015 DEFVAR_LISP ("fontset-alias-alist", &Vfontset_alias_alist,
2016 doc: /* Alist of fontset names vs the aliases. */);
2017 Vfontset_alias_alist = Fcons (Fcons (FONTSET_NAME (Vdefault_fontset),
2018 build_string ("fontset-default")),
2019 Qnil);
2020
2021 DEFVAR_LISP ("vertical-centering-font-regexp",
2022 &Vvertical_centering_font_regexp,
2023 doc: /* *Regexp matching font names that require vertical centering on display.
2024 When a character is displayed with such fonts, the character is displayed
2025 at the vertical center of lines. */);
2026 Vvertical_centering_font_regexp = Qnil;
2027
2028 defsubr (&Squery_fontset);
2029 defsubr (&Snew_fontset);
2030 defsubr (&Sset_fontset_font);
2031 defsubr (&Sfont_info);
2032 defsubr (&Sinternal_char_font);
2033 defsubr (&Sfontset_info);
2034 defsubr (&Sfontset_font);
2035 defsubr (&Sfontset_list);
2036 #ifdef FONTSET_DEBUG
2037 defsubr (&Sfontset_list_all);
2038 #endif
2039 }