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