2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
3 Free Software Foundation, Inc.
4 Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
6 National Institute of Advanced Industrial Science and Technology (AIST)
7 Registration Number H14PRO021
8 Copyright (C) 2003, 2006
9 National Institute of Advanced Industrial Science and Technology (AIST)
10 Registration Number H13PRO009
12 This file is part of GNU Emacs.
14 GNU Emacs is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3, or (at your option)
19 GNU Emacs is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with GNU Emacs; see the file COPYING. If not, write to
26 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 Boston, MA 02110-1301, USA. */
29 /* #define FONTSET_DEBUG */
38 #include "blockinput.h"
40 #include "character.h"
45 #include "dispextern.h"
46 #include "intervals.h"
58 #include "termhooks.h"
64 #define xassert(X) do {if (!(X)) abort ();} while (0)
67 #else /* not FONTSET_DEBUG */
68 #define xassert(X) (void) 0
69 #endif /* not FONTSET_DEBUG */
71 EXFUN (Fclear_face_cache
, 1);
75 A fontset is a collection of font related information to give
76 similar appearance (style, etc) of characters. A fontset has two
77 roles. One is to use for the frame parameter `font' as if it is an
78 ASCII font. In that case, Emacs uses the font specified for
79 `ascii' script for the frame's default font.
81 Another role, the more important one, is to provide information
82 about which font to use for each non-ASCII character.
84 There are two kinds of fontsets; base and realized. A base fontset
85 is created by `new-fontset' from Emacs Lisp explicitly. A realized
86 fontset is created implicitly when a face is realized for ASCII
87 characters. A face is also realized for non-ASCII characters based
88 on an ASCII face. All of non-ASCII faces based on the same ASCII
89 face share the same realized fontset.
91 A fontset object is implemented by a char-table whose default value
92 and parent are always nil.
94 An element of a base fontset is a vector of FONT-DEFs which itself
95 is a vector [ FONT-SPEC ENCODING REPERTORY ].
97 FONT-SPEC is a font-spec created by `font-spec' or
101 where FAMILY, REGISTRY, and FONT-NAME are strings.
103 ENCODING is a charset ID that can convert characters to glyph codes
104 of the corresponding font.
106 REPERTORY is a charset ID, a char-table, or nil. If REPERTORY is a
107 charset ID, the repertory of the charset exactly matches with that
108 of the font. If REPERTORY is a char-table, all characters who have
109 a non-nil value in the table are supported. If REPERTORY is nil,
110 we consult with the font itself to get the repertory.
112 ENCODING and REPERTORY are extracted from the variable
113 Vfont_encoding_alist by using a font name generated from FONT-SPEC
114 (if it is a vector) or FONT-NAME as a matching target.
117 An element of a realized fontset is nil or t, or has this form:
119 [CHARSET-ORDERED-LIST-TICK PREFERRED-CHARSET-ID PREFERRED-FAMILY
120 RFONT-DEF0 RFONT-DEF1 ...].
122 RFONT-DEFn (i.e. Realized FONT-DEF) has this form:
124 [ FACE-ID FONT-INDEX FONT-DEF OPENED-FONT-NAME ]
126 RFONT-DEFn is automatically reordered by the current charset
129 The value nil means that we have not yet generated the above vector
130 from the base of the fontset.
132 The value t means that no font is available for the corresponding
136 A fontset has 9 extra slots.
138 The 1st slot: the ID number of the fontset
141 base: the name of the fontset
146 realized: the base fontset
150 realized: the frame that the fontset belongs to
153 base: the font name for ASCII characters
158 realized: the ID number of a face to use for characters that
159 has no font in a realized fontset.
163 realized: Alist of font index vs the corresponding repertory
168 realized: If the base is not the default fontset, a fontset
169 realized from the default fontset, else nil.
172 base: Same as element value (but for fallback fonts).
175 All fontsets are recorded in the vector Vfontset_table.
180 There's a special base fontset named `default fontset' which
181 defines the default font specifications. When a base fontset
182 doesn't specify a font for a specific character, the corresponding
183 value in the default fontset is used.
185 The parent of a realized fontset created for such a face that has
186 no fontset is the default fontset.
189 These structures are hidden from the other codes than this file.
190 The other codes handle fontsets only by their ID numbers. They
191 usually use the variable name `fontset' for IDs. But, in this
192 file, we always use varialbe name `id' for IDs, and name `fontset'
193 for an actual fontset object, i.e., char-table.
197 /********** VARIABLES and FUNCTION PROTOTYPES **********/
199 extern Lisp_Object Qfont
;
200 static Lisp_Object Qfontset
;
201 static Lisp_Object Qfontset_info
;
202 static Lisp_Object Qprepend
, Qappend
;
203 static Lisp_Object Qlatin
;
205 /* Vector containing all fontsets. */
206 static Lisp_Object Vfontset_table
;
208 /* Next possibly free fontset ID. Usually this keeps the minimum
209 fontset ID not yet used. */
210 static int next_fontset_id
;
212 /* The default fontset. This gives default FAMILY and REGISTRY of
213 font for each character. */
214 static Lisp_Object Vdefault_fontset
;
216 Lisp_Object Vfont_encoding_alist
;
217 Lisp_Object Vfont_encoding_charset_alist
;
218 Lisp_Object Vuse_default_ascent
;
219 Lisp_Object Vignore_relative_composition
;
220 Lisp_Object Valternate_fontname_alist
;
221 Lisp_Object Vfontset_alias_alist
;
222 Lisp_Object Vvertical_centering_font_regexp
;
223 Lisp_Object Votf_script_alist
;
225 /* The following six are declarations of callback functions depending
226 on window system. See the comments in src/fontset.h for more
229 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
230 struct font_info
*(*get_font_info_func
) P_ ((FRAME_PTR f
, int font_idx
));
232 /* Return a list of font names which matches PATTERN. See the documentation
233 of `x-list-fonts' for more details. */
234 Lisp_Object (*list_fonts_func
) P_ ((struct frame
*f
,
239 /* Load a font named NAME for frame F and return a pointer to the
240 information of the loaded font. If loading is failed, return 0. */
241 struct font_info
*(*load_font_func
) P_ ((FRAME_PTR f
, char *name
, int));
243 /* Return a pointer to struct font_info of a font named NAME for frame F. */
244 struct font_info
*(*query_font_func
) P_ ((FRAME_PTR f
, char *name
));
246 /* Additional function for setting fontset or changing fontset
247 contents of frame F. */
248 void (*set_frame_fontset_func
) P_ ((FRAME_PTR f
, Lisp_Object arg
,
249 Lisp_Object oldval
));
251 /* To find a CCL program, fs_load_font calls this function.
252 The argument is a pointer to the struct font_info.
253 This function set the member `encoder' of the structure. */
254 void (*find_ccl_program_func
) P_ ((struct font_info
*));
256 Lisp_Object (*get_font_repertory_func
) P_ ((struct frame
*,
257 struct font_info
*));
259 /* Check if any window system is used now. */
260 void (*check_window_system_func
) P_ ((void));
263 /* Prototype declarations for static functions. */
264 static Lisp_Object fontset_add
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
,
266 static void reorder_font_vector
P_ ((Lisp_Object
, int, Lisp_Object
));
267 static Lisp_Object fontset_font
P_ ((Lisp_Object
, int, struct face
*, int));
268 static Lisp_Object make_fontset
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
));
269 static Lisp_Object fontset_pattern_regexp
P_ ((Lisp_Object
));
270 static void accumulate_script_ranges
P_ ((Lisp_Object
, Lisp_Object
,
272 Lisp_Object find_font_encoding
P_ ((Lisp_Object
));
274 static void set_fontset_font
P_ ((Lisp_Object
, Lisp_Object
));
278 /* Return 1 if ID is a valid fontset id, else return 0. */
281 fontset_id_valid_p (id
)
284 return (id
>= 0 && id
< ASIZE (Vfontset_table
) - 1);
291 /********** MACROS AND FUNCTIONS TO HANDLE FONTSET **********/
293 /* Return the fontset with ID. No check of ID's validness. */
294 #define FONTSET_FROM_ID(id) AREF (Vfontset_table, id)
296 /* Macros to access special values of FONTSET. */
297 #define FONTSET_ID(fontset) XCHAR_TABLE (fontset)->extras[0]
299 /* Macros to access special values of (base) FONTSET. */
300 #define FONTSET_NAME(fontset) XCHAR_TABLE (fontset)->extras[1]
301 #define FONTSET_ASCII(fontset) XCHAR_TABLE (fontset)->extras[4]
303 /* Macros to access special values of (realized) FONTSET. */
304 #define FONTSET_BASE(fontset) XCHAR_TABLE (fontset)->extras[2]
305 #define FONTSET_FRAME(fontset) XCHAR_TABLE (fontset)->extras[3]
306 #define FONTSET_NOFONT_FACE(fontset) XCHAR_TABLE (fontset)->extras[5]
307 #define FONTSET_REPERTORY(fontset) XCHAR_TABLE (fontset)->extras[6]
308 #define FONTSET_DEFAULT(fontset) XCHAR_TABLE (fontset)->extras[7]
310 /* For both base and realized fontset. */
311 #define FONTSET_FALLBACK(fontset) XCHAR_TABLE (fontset)->extras[8]
313 #define BASE_FONTSET_P(fontset) (NILP (FONTSET_BASE (fontset)))
316 /* Return the element of FONTSET for the character C. If FONTSET is a
317 base fontset other then the default fontset and FONTSET doesn't
318 contain information for C, return the information in the default
321 #define FONTSET_REF(fontset, c) \
322 (EQ (fontset, Vdefault_fontset) \
323 ? CHAR_TABLE_REF (fontset, c) \
324 : fontset_ref ((fontset), (c)))
327 fontset_ref (fontset
, c
)
333 elt
= CHAR_TABLE_REF (fontset
, c
);
334 if (NILP (elt
) && ! EQ (fontset
, Vdefault_fontset
)
335 /* Don't check Vdefault_fontset for a realized fontset. */
336 && NILP (FONTSET_BASE (fontset
)))
337 elt
= CHAR_TABLE_REF (Vdefault_fontset
, c
);
342 /* Return the element of FONTSET for the character C, set FROM and TO
343 to the range of characters around C that have the same value as C.
344 If FONTSET is a base fontset other then the default fontset and
345 FONTSET doesn't contain information for C, return the information
346 in the default fontset. */
348 #define FONTSET_REF_AND_RANGE(fontset, c, form, to) \
349 (EQ (fontset, Vdefault_fontset) \
350 ? char_table_ref_and_range (fontset, c, &from, &to) \
351 : fontset_ref_and_range (fontset, c, &from, &to))
354 fontset_ref_and_range (fontset
, c
, from
, to
)
361 elt
= char_table_ref_and_range (fontset
, c
, from
, to
);
362 if (NILP (elt
) && ! EQ (fontset
, Vdefault_fontset
)
363 /* Don't check Vdefault_fontset for a realized fontset. */
364 && NILP (FONTSET_BASE (fontset
)))
368 elt
= char_table_ref_and_range (Vdefault_fontset
, c
, &from1
, &to1
);
378 /* Set elements of FONTSET for characters in RANGE to the value ELT.
379 RANGE is a cons (FROM . TO), where FROM and TO are character codes
380 specifying a range. */
382 #define FONTSET_SET(fontset, range, elt) \
383 Fset_char_table_range ((fontset), (range), (elt))
386 /* Modify the elements of FONTSET for characters in RANGE by replacing
387 with ELT or adding ELT. RANGE is a cons (FROM . TO), where FROM
388 and TO are character codes specifying a range. If ADD is nil,
389 replace with ELT, if ADD is `prepend', prepend ELT, otherwise,
392 #define FONTSET_ADD(fontset, range, elt, add) \
395 ? (FONTSET_FALLBACK (fontset) = Fmake_vector (make_number (1), (elt))) \
396 : Fset_char_table_range ((fontset), (range), \
397 Fmake_vector (make_number (1), (elt)))) \
398 : fontset_add ((fontset), (range), (elt), (add)))
401 fontset_add (fontset
, range
, elt
, add
)
402 Lisp_Object fontset
, range
, elt
, add
;
405 int idx
= (EQ (add
, Qappend
) ? 0 : 1);
407 args
[1 - idx
] = Fmake_vector (make_number (1), elt
);
411 int from
= XINT (XCAR (range
));
412 int to
= XINT (XCDR (range
));
416 args
[idx
] = char_table_ref_and_range (fontset
, from
, &from1
, &to1
);
419 char_table_set_range (fontset
, from
, to1
,
420 NILP (args
[idx
]) ? args
[1 - idx
]
421 : Fvconcat (2, args
));
427 args
[idx
] = FONTSET_FALLBACK (fontset
);
428 FONTSET_FALLBACK (fontset
)
429 = NILP (args
[idx
]) ? args
[1 - idx
] : Fvconcat (2, args
);
435 /* Update FONT-GROUP which has this form:
436 [CHARSET-ORDERED-LIST-TICK PREFERRED-CHARSET-ID PREFERRED-FAMILY
437 RFONT-DEF0 RFONT-DEF1 ...].
438 Reorder RFONT-DEFs according to the current order of charset
439 (Vcharset_ordered_list), and update CHARSET-ORDERED-LIST-TICK to
443 reorder_font_vector (font_group
, charset_id
, family
)
444 Lisp_Object font_group
;
448 Lisp_Object list
, *new_vec
;
450 int *charset_id_table
;
452 Lisp_Object preferred_by_charset
, preferred_by_family
;
454 size
= ASIZE (font_group
) - 3;
455 charset_id_table
= (int *) alloca (sizeof (int) * size
);
456 new_vec
= (Lisp_Object
*) alloca (sizeof (Lisp_Object
) * size
);
458 /* At first, extract ENCODING (a chaset ID) from RFONT_DEF which
460 [FACE-ID FONT-INDEX [ FONT-SPEC ENCODING REPERTORY ]]
461 In addtion, if RFONT_DEF is preferred by family or charset, store
462 it from the start of new_vec. */
463 for (i
= 0, idx
= 0; i
< size
; i
++)
465 Lisp_Object rfont_def
= AREF (font_group
, i
+ 3);
466 Lisp_Object font_spec
= AREF (AREF (rfont_def
, 2), 0);
467 Lisp_Object this_family
= AREF (font_spec
, FONT_FAMILY_INDEX
);
468 int id
= XINT (AREF (AREF (rfont_def
, 2), 1));
469 struct charset
*charset
= CHARSET_FROM_ID (id
);
471 charset_id_table
[i
] = -1;
472 if (! NILP (this_family
)
473 && (fast_string_match_ignore_case (family
, SYMBOL_NAME (this_family
))
477 memmove (new_vec
+ 1, new_vec
, sizeof (Lisp_Object
) * idx
);
478 new_vec
[0] = rfont_def
;
480 ASET (font_group
, i
+ 3, Qnil
);
482 else if (id
== charset_id
)
484 new_vec
[idx
++] = rfont_def
;
485 ASET (font_group
, i
+ 3, Qnil
);
487 else if (! charset
->supplementary_p
)
488 charset_id_table
[i
] = id
;
492 && (XINT (AREF (font_group
, 0)) == charset_ordered_list_tick
))
493 /* No need of reordering. */
496 ASET (font_group
, 0, make_number (charset_ordered_list_tick
));
497 ASET (font_group
, 1, make_number (charset_id
));
498 ASET (font_group
, 2, family
);
500 /* Then, store the remaining RFONT-DEFs in NEW_VEC in the correct
502 for (list
= Vcharset_ordered_list
; idx
< size
; list
= XCDR (list
))
504 int id
= XINT (XCAR (list
));
505 struct charset
*charset
= CHARSET_FROM_ID (id
);
507 if (charset
->supplementary_p
)
509 for (i
= 0; i
< size
; i
++)
510 if (charset_id_table
[i
] == XINT (XCAR (list
))
511 && ! NILP (AREF (font_group
, i
+ 2)))
513 new_vec
[idx
++] = AREF (font_group
, i
+ 3);
514 ASET (font_group
, i
+ 3, Qnil
);
517 for (i
= 0; i
< size
; i
++)
518 if (! NILP (AREF (font_group
, i
+ 3)))
519 new_vec
[idx
++] = AREF (font_group
, i
+ 3);
521 /* At last, update elements of FONT-GROUP. */
522 for (i
= 0; i
< size
; i
++)
523 ASET (font_group
, i
+ 3, new_vec
[i
]);
527 /* Load a font matching the font related attributes in FACE->lface and
528 font pattern in FONT_DEF of FONTSET, and return an index of the
529 font. FONT_DEF has this form:
530 [ FONT-SPEC ENCODING REPERTORY ]
531 If REPERTORY is nil, generate a char-table representing the font
532 repertory by looking into the font itself. */
534 extern Lisp_Object QCname
;
537 load_font_get_repertory (f
, face
, font_def
, fontset
)
540 Lisp_Object font_def
;
544 struct font_info
*font_info
;
546 Lisp_Object font_spec
, name
;
548 font_spec
= AREF (font_def
, 0);
549 name
= Ffont_get (font_spec
, QCname
);
551 font_name
= choose_face_font (f
, face
->lface
, name
, NULL
);
553 font_name
= choose_face_font (f
, face
->lface
, font_spec
, NULL
);
554 charset
= XINT (AREF (font_def
, 1));
555 if (! (font_info
= fs_load_font (f
, font_name
, charset
)))
558 if (NILP (AREF (font_def
, 2))
559 && NILP (Fassq (make_number (font_info
->font_idx
),
560 FONTSET_REPERTORY (fontset
))))
562 /* We must look into the font to get the correct repertory as a
564 Lisp_Object repertory
;
566 repertory
= (*get_font_repertory_func
) (f
, font_info
);
567 FONTSET_REPERTORY (fontset
)
568 = Fcons (Fcons (make_number (font_info
->font_idx
), repertory
),
569 FONTSET_REPERTORY (fontset
));
572 return font_info
->font_idx
;
575 static Lisp_Object fontset_find_font
P_ ((Lisp_Object
, int, struct face
*,
578 /* Return RFONT-DEF (vector) in the realized fontset FONTSET for the
579 character C. If the corresponding font is not yet opened, open it
580 (if FACE is not NULL) or return Qnil (if FACE is NULL).
581 If no proper font is found for C, return Qnil.
582 ID is a charset-id that must be preferred, or -1 meaning no
584 If FALLBACK is nonzero, search only fallback fonts. */
587 fontset_find_font (fontset
, c
, face
, id
, fallback
)
593 Lisp_Object base_fontset
, elt
, vec
, font_def
;
596 FRAME_PTR f
= XFRAME (FONTSET_FRAME (fontset
));
598 base_fontset
= FONTSET_BASE (fontset
);
600 vec
= CHAR_TABLE_REF (fontset
, c
);
602 vec
= FONTSET_FALLBACK (fontset
);
607 /* We have not yet decided a font for C. */
612 elt
= FONTSET_REF_AND_RANGE (base_fontset
, c
, from
, to
);
613 range
= Fcons (make_number (from
), make_number (to
));
614 if (EQ (base_fontset
, Vdefault_fontset
))
616 Lisp_Object script
= CHAR_TABLE_REF (Vchar_script_table
, c
);
620 Lisp_Object font_spec
= Ffont_spec (0, NULL
);
621 Lisp_Object args
[2], tmp
;
623 ASET (font_spec
, FONT_REGISTRY_INDEX
, Qiso10646_1
);
624 ASET (font_spec
, FONT_EXTRA_INDEX
,
625 Fcons (Fcons (QCscript
, script
), Qnil
));
627 tmp
= Fmake_vector (make_number (3), Qnil
);
628 ASET (tmp
, 0, font_spec
);
629 ASET (tmp
, 1, CHARSET_SYMBOL_ID (Qunicode_bmp
));
630 args
[1] = Fvector (1, &tmp
);
631 elt
= Fvconcat (2, args
);
637 elt
= FONTSET_FALLBACK (base_fontset
);
641 /* Qt means we have no font for characters of this range. */
646 /* Build a vector [ -1 -1 nil NEW-ELT0 NEW-ELT1 NEW-ELT2 ... ],
647 where the first -1 is to force reordering of NEW-ELTn,
648 NEW-ELTn is [nil nil AREF (elt, n) nil]. */
649 vec
= Fmake_vector (make_number (ASIZE (elt
) + 3), Qnil
);
650 ASET (vec
, 0, make_number (-1));
651 ASET (vec
, 1, make_number (-1));
652 for (i
= 0; i
< ASIZE (elt
); i
++)
655 tmp
= Fmake_vector (make_number (5), Qnil
);
656 ASET (tmp
, 2, AREF (elt
, i
));
657 ASET (vec
, i
+ 3, tmp
);
660 /* Then store it in the fontset. */
662 FONTSET_SET (fontset
, range
, vec
);
664 FONTSET_FALLBACK (fontset
) = vec
;
670 && (XINT (AREF (vec
, 0)) != charset_ordered_list_tick
671 || (id
>= 0 && XINT (AREF (vec
, 1)) != id
)
672 || NILP (Fequal (AREF (vec
, 2), face
->lface
[LFACE_FAMILY_INDEX
]))))
673 /* We have just created VEC,
674 or the charset priorities were changed,
675 or the preferred charset was changed,
676 or the preferred family was changed. */
677 reorder_font_vector (vec
, id
, face
->lface
[LFACE_FAMILY_INDEX
]);
679 /* Find the first available font in the vector of RFONT-DEF. */
680 for (i
= 3; i
< ASIZE (vec
); i
++)
685 /* ELT == [ FACE-ID FONT-INDEX FONT-DEF ... ] */
686 if (INTEGERP (AREF (elt
, 1)) && XINT (AREF (elt
, 1)) < 0)
687 /* We couldn't open this font last time. */
690 if (!face
&& NILP (AREF (elt
, 1)))
691 /* We have not yet opened the font. */
694 font_def
= AREF (elt
, 2);
695 /* FONT_DEF == [ FONT-SPEC ENCODING REPERTORY ] */
697 #ifdef USE_FONT_BACKEND
698 if (enable_font_backend
)
700 /* ELT == [ FACE-ID FONT-INDEX FONT-DEF FONT-LIST ]
701 where FONT-LIST is a list of font-entity or font-object. */
702 Lisp_Object font_list
= AREF (elt
, 3), prev
= Qnil
;
703 Lisp_Object font_object
;
706 for (; CONSP (font_list
);
707 prev
= font_list
, font_list
= XCDR (font_list
))
709 font_object
= XCAR (font_list
);
710 if (! (FONT_ENTITY_P (font_object
)
711 && FONT_ENTITY_NOT_LOADABLE (font_object
))
712 && (has_char
= font_has_char (f
, font_object
, c
)) != 0)
716 Lisp_Object obj
= font_open_for_lface (f
, font_object
,
720 FONT_ENTITY_SET_NOT_LOADABLE (font_object
);
724 XSETCAR (font_list
, font_object
);
725 if (! font_has_char (f
, font_object
, c
))
730 /* Move this element to the head. */
731 XSETCDR (prev
, XCDR (font_list
));
732 ASET (elt
, 3, Fcons (XCAR (font_list
), AREF (elt
, 3)));
737 if (NILP (font_list
))
739 Lisp_Object font_spec
= AREF (font_def
, 0);
740 Lisp_Object font_entity
;
742 font_entity
= font_find_for_lface (f
, face
->lface
, font_spec
, c
);
743 if (NILP (font_entity
))
745 font_list
= Fcons (font_entity
, AREF (elt
, 3));
746 ASET (elt
, 3, font_list
);
748 font_object
= XCAR (font_list
);
749 if (FONT_ENTITY_P (font_object
))
751 font_object
= font_open_for_lface (f
, font_object
,
753 if (NILP (font_object
))
755 FONT_ENTITY_SET_NOT_LOADABLE (XCAR (font_list
));
758 XSETCAR (font_list
, font_object
);
760 ASET (elt
, 1, make_number (0));
763 #endif /* USE_FONT_BACKEND */
765 if (INTEGERP (AREF (font_def
, 2)))
767 /* The repertory is specified by charset ID. */
768 struct charset
*charset
769 = CHARSET_FROM_ID (XINT (AREF (font_def
, 2)));
771 if (! CHAR_CHARSET_P (c
, charset
))
772 /* This font can't display C. */
775 else if (CHAR_TABLE_P (AREF (font_def
, 2)))
777 /* The repertory is specified by a char table. */
778 if (NILP (CHAR_TABLE_REF (AREF (font_def
, 2), c
)))
779 /* This font can't display C. */
786 if (! INTEGERP (AREF (elt
, 1)))
788 /* We have not yet opened a font matching this spec.
789 Open the best matching font now and register the
791 struct font_info
*font_info
;
793 font_idx
= load_font_get_repertory (f
, face
, font_def
, fontset
);
794 ASET (elt
, 1, make_number (font_idx
));
796 /* This means that we couldn't find a font matching
799 font_info
= (*get_font_info_func
) (f
, font_idx
);
800 ASET (elt
, 3, build_string (font_info
->full_name
));
803 slot
= Fassq (AREF (elt
, 1), FONTSET_REPERTORY (fontset
));
804 xassert (CONSP (slot
));
805 if (NILP (CHAR_TABLE_REF (XCDR (slot
), c
)))
806 /* This font can't display C. */
810 /* Now we have decided to use this font spec to display C. */
811 if (! INTEGERP (AREF (elt
, 1)))
813 /* But not yet opened the best matching font. */
814 struct font_info
*font_info
;
816 font_idx
= load_font_get_repertory (f
, face
, font_def
, fontset
);
817 ASET (elt
, 1, make_number (font_idx
));
819 /* Can't open it. Try the other one. */
821 font_info
= (*get_font_info_func
) (f
, font_idx
);
822 ASET (elt
, 3, build_string (font_info
->full_name
));
825 /* Now we have the opened font. */
833 fontset_font (fontset
, c
, face
, id
)
839 Lisp_Object rfont_def
;
840 Lisp_Object base_fontset
;
842 /* Try a font-group for C. */
843 rfont_def
= fontset_find_font (fontset
, c
, face
, id
, 0);
844 if (! NILP (rfont_def
))
846 base_fontset
= FONTSET_BASE (fontset
);
847 /* Try a font-group for C of the default fontset. */
848 if (! EQ (base_fontset
, Vdefault_fontset
))
850 if (NILP (FONTSET_DEFAULT (fontset
)))
851 FONTSET_DEFAULT (fontset
)
852 = make_fontset (FONTSET_FRAME (fontset
), Qnil
, Vdefault_fontset
);
853 rfont_def
= fontset_find_font (FONTSET_DEFAULT (fontset
), c
, face
, id
, 0);
855 if (! NILP (rfont_def
))
857 /* Try a fallback font-group. */
858 rfont_def
= fontset_find_font (fontset
, c
, face
, id
, 1);
859 if (! NILP (rfont_def
))
861 /* Try a fallback font-group of the default fontset . */
862 if (! EQ (base_fontset
, Vdefault_fontset
))
863 rfont_def
= fontset_find_font (FONTSET_DEFAULT (fontset
), c
, face
, id
, 1);
867 /* Return a newly created fontset with NAME. If BASE is nil, make a
868 base fontset. Otherwise make a realized fontset whose base is
872 make_fontset (frame
, name
, base
)
873 Lisp_Object frame
, name
, base
;
876 int size
= ASIZE (Vfontset_table
);
877 int id
= next_fontset_id
;
879 /* Find a free slot in Vfontset_table. Usually, next_fontset_id is
880 the next available fontset ID. So it is expected that this loop
881 terminates quickly. In addition, as the last element of
882 Vfontset_table is always nil, we don't have to check the range of
884 while (!NILP (AREF (Vfontset_table
, id
))) id
++;
887 Vfontset_table
= larger_vector (Vfontset_table
, size
+ 32, Qnil
);
889 fontset
= Fmake_char_table (Qfontset
, Qnil
);
891 FONTSET_ID (fontset
) = make_number (id
);
894 FONTSET_NAME (fontset
) = name
;
898 FONTSET_NAME (fontset
) = Qnil
;
899 FONTSET_FRAME (fontset
) = frame
;
900 FONTSET_BASE (fontset
) = base
;
903 ASET (Vfontset_table
, id
, fontset
);
904 next_fontset_id
= id
+ 1;
909 /* Set the ASCII font of the default fontset to FONTNAME if that is
912 set_default_ascii_font (fontname
)
913 Lisp_Object fontname
;
915 if (! STRINGP (FONTSET_ASCII (Vdefault_fontset
)))
917 int id
= fs_query_fontset (fontname
, 2);
920 fontname
= FONTSET_ASCII (FONTSET_FROM_ID (id
));
921 FONTSET_ASCII (Vdefault_fontset
)= fontname
;
926 /********** INTERFACES TO xfaces.c, xfns.c, and dispextern.h **********/
928 /* Return the name of the fontset who has ID. */
936 fontset
= FONTSET_FROM_ID (id
);
937 return FONTSET_NAME (fontset
);
941 /* Return the ASCII font name of the fontset who has ID. */
947 Lisp_Object fontset
, elt
;
949 fontset
= FONTSET_FROM_ID (id
);
950 elt
= FONTSET_ASCII (fontset
);
951 #ifdef USE_FONT_BACKEND
954 #endif /* USE_FONT_BACKEND */
955 /* It is assured that ELT is always a string (i.e. fontname
961 /* Free fontset of FACE defined on frame F. Called from
962 free_realized_face. */
965 free_face_fontset (f
, face
)
971 fontset
= AREF (Vfontset_table
, face
->fontset
);
972 xassert (!NILP (fontset
) && ! BASE_FONTSET_P (fontset
));
973 xassert (f
== XFRAME (FONTSET_FRAME (fontset
)));
974 ASET (Vfontset_table
, face
->fontset
, Qnil
);
975 if (face
->fontset
< next_fontset_id
)
976 next_fontset_id
= face
->fontset
;
977 if (! NILP (FONTSET_DEFAULT (fontset
)))
979 int id
= XINT (FONTSET_ID (FONTSET_DEFAULT (fontset
)));
981 fontset
= AREF (Vfontset_table
, id
);
982 xassert (!NILP (fontset
) && ! BASE_FONTSET_P (fontset
));
983 xassert (f
== XFRAME (FONTSET_FRAME (fontset
)));
984 ASET (Vfontset_table
, id
, Qnil
);
985 if (id
< next_fontset_id
)
986 next_fontset_id
= face
->fontset
;
991 /* Return 1 if FACE is suitable for displaying character C.
992 Otherwise return 0. Called from the macro FACE_SUITABLE_FOR_CHAR_P
993 when C is not an ASCII character. */
996 face_suitable_for_char_p (face
, c
)
1000 Lisp_Object fontset
, rfont_def
;
1002 fontset
= FONTSET_FROM_ID (face
->fontset
);
1003 rfont_def
= fontset_font (fontset
, c
, NULL
, -1);
1004 return (VECTORP (rfont_def
)
1005 && INTEGERP (AREF (rfont_def
, 0))
1006 && face
->id
== XINT (AREF (rfont_def
, 0)));
1010 /* Return ID of face suitable for displaying character C on frame F.
1011 FACE must be reazlied for ASCII characters in advance. Called from
1012 the macro FACE_FOR_CHAR. */
1015 face_for_char (f
, face
, c
, pos
, object
)
1021 Lisp_Object fontset
, charset
, rfont_def
;
1025 if (ASCII_CHAR_P (c
))
1026 return face
->ascii_face
->id
;
1028 xassert (fontset_id_valid_p (face
->fontset
));
1029 fontset
= FONTSET_FROM_ID (face
->fontset
);
1030 xassert (!BASE_FONTSET_P (fontset
));
1035 charset
= Fget_char_property (make_number (pos
), Qcharset
, object
);
1038 else if (CHARSETP (charset
))
1042 val
= assoc_no_quit (charset
, Vfont_encoding_charset_alist
);
1043 if (CONSP (val
) && CHARSETP (XCDR (val
)))
1044 charset
= XCDR (val
);
1045 id
= XINT (CHARSET_SYMBOL_ID (charset
));
1048 rfont_def
= fontset_font (fontset
, c
, face
, id
);
1049 if (VECTORP (rfont_def
))
1051 #ifdef USE_FONT_BACKEND
1052 if (enable_font_backend
1053 && NILP (AREF (rfont_def
, 0)))
1055 struct font
*font
= XSAVE_VALUE (XCAR (AREF (rfont_def
, 3)))->pointer
;
1057 face_id
= face_for_font (f
, font
, face
);
1058 ASET (rfont_def
, 0, make_number (face_id
));
1061 #endif /* USE_FONT_BACKEND */
1062 if (NILP (AREF (rfont_def
, 0)))
1064 /* We have not yet made a realized face that uses this font. */
1065 int font_idx
= XINT (AREF (rfont_def
, 1));
1067 face_id
= lookup_non_ascii_face (f
, font_idx
, face
);
1068 ASET (rfont_def
, 0, make_number (face_id
));
1070 return XINT (AREF (rfont_def
, 0));
1073 if (NILP (FONTSET_NOFONT_FACE (fontset
)))
1075 face_id
= lookup_non_ascii_face (f
, -1, face
);
1076 FONTSET_NOFONT_FACE (fontset
) = make_number (face_id
);
1078 return XINT (FONTSET_NOFONT_FACE (fontset
));
1082 /* Make a realized fontset for ASCII face FACE on frame F from the
1083 base fontset BASE_FONTSET_ID. If BASE_FONTSET_ID is -1, use the
1084 default fontset as the base. Value is the id of the new fontset.
1085 Called from realize_x_face. */
1088 make_fontset_for_ascii_face (f
, base_fontset_id
, face
)
1090 int base_fontset_id
;
1093 Lisp_Object base_fontset
, fontset
, frame
;
1095 XSETFRAME (frame
, f
);
1096 if (base_fontset_id
>= 0)
1098 base_fontset
= FONTSET_FROM_ID (base_fontset_id
);
1099 if (!BASE_FONTSET_P (base_fontset
))
1100 base_fontset
= FONTSET_BASE (base_fontset
);
1101 xassert (BASE_FONTSET_P (base_fontset
));
1102 if (! BASE_FONTSET_P (base_fontset
))
1106 base_fontset
= Vdefault_fontset
;
1108 fontset
= make_fontset (frame
, Qnil
, base_fontset
);
1110 Lisp_Object elt
, rfont_def
, val
;
1112 elt
= FONTSET_REF (base_fontset
, 0);
1113 xassert (VECTORP (elt
) && ASIZE (elt
) > 0);
1114 rfont_def
= Fmake_vector (make_number (4), Qnil
);
1115 #ifdef USE_FONT_BACKEND
1116 if (enable_font_backend
&& face
->font_info
)
1118 struct font
*font
= (struct font
*) face
->font_info
;
1120 ASET (rfont_def
, 3, Fcons (font
->entity
, Qnil
));
1123 #endif /* USE_FONT_BACKEND */
1125 ASET (rfont_def
, 3, build_string (face
->font_name
));
1127 ASET (rfont_def
, 1, make_number (face
->font_info_id
));
1128 ASET (rfont_def
, 2, AREF (elt
, 0));
1129 elt
= Fmake_vector (make_number (4), Qnil
);
1130 ASET (elt
, 0, make_number (charset_ordered_list_tick
));
1131 ASET (elt
, 1, make_number (charset_ascii
));
1132 ASET (elt
, 2, rfont_def
);
1133 ASET (elt
, 3, rfont_def
);
1135 val
= Fcons (Qlatin
, Qnil
);
1136 map_char_table (accumulate_script_ranges
, Qnil
, Vchar_script_table
, val
);
1137 for (val
= XCDR (val
); CONSP (val
); val
= XCDR (val
))
1138 char_table_set_range (fontset
, XINT (XCAR (XCAR (val
))),
1139 XINT (XCDR (XCAR (val
))), elt
);
1140 FONTSET_FALLBACK (fontset
) = elt
;
1142 return XINT (FONTSET_ID (fontset
));
1146 #if defined(WINDOWSNT) && defined (_MSC_VER)
1147 #pragma optimize("", off)
1150 /* Load a font named FONTNAME on frame F. Return a pointer to the
1151 struct font_info of the loaded font. If loading fails, return
1152 NULL. CHARSET is an ID of charset to encode characters for this
1153 font. If it is -1, find one from Vfont_encoding_alist. */
1156 fs_load_font (f
, fontname
, charset
)
1161 struct font_info
*fontp
;
1162 Lisp_Object fullname
;
1165 /* No way to get fontname. */
1168 fontp
= (*load_font_func
) (f
, fontname
, 0);
1169 if (! fontp
|| fontp
->charset
>= 0)
1172 fontname
= fontp
->full_name
;
1173 fullname
= build_string (fontp
->full_name
);
1177 Lisp_Object charset_symbol
;
1179 charset_symbol
= find_font_encoding (fullname
);
1180 if (CONSP (charset_symbol
))
1181 charset_symbol
= XCAR (charset_symbol
);
1182 if (NILP (charset_symbol
))
1183 charset_symbol
= Qascii
;
1184 charset
= XINT (CHARSET_SYMBOL_ID (charset_symbol
));
1186 fontp
->charset
= charset
;
1187 fontp
->vertical_centering
= 0;
1188 fontp
->font_encoder
= NULL
;
1190 if (charset
!= charset_ascii
)
1192 fontp
->vertical_centering
1193 = (STRINGP (Vvertical_centering_font_regexp
)
1194 && (fast_string_match_ignore_case
1195 (Vvertical_centering_font_regexp
, fullname
) >= 0));
1197 if (find_ccl_program_func
)
1198 (*find_ccl_program_func
) (fontp
);
1204 #if defined(WINDOWSNT) && defined (_MSC_VER)
1205 #pragma optimize("", on)
1209 /* Return ENCODING or a cons of ENCODING and REPERTORY of the font
1210 FONTNAME. ENCODING is a charset symbol that specifies the encoding
1211 of the font. REPERTORY is a charset symbol or nil. */
1215 find_font_encoding (fontname
)
1216 Lisp_Object fontname
;
1218 Lisp_Object tail
, elt
;
1220 for (tail
= Vfont_encoding_alist
; CONSP (tail
); tail
= XCDR (tail
))
1224 && STRINGP (XCAR (elt
))
1225 && fast_string_match_ignore_case (XCAR (elt
), fontname
) >= 0
1226 && (SYMBOLP (XCDR (elt
))
1227 ? CHARSETP (XCDR (elt
))
1228 : CONSP (XCDR (elt
)) && CHARSETP (XCAR (XCDR (elt
)))))
1229 return (XCDR (elt
));
1231 /* We don't know the encoding of this font. Let's assume `ascii'. */
1236 /* Cache data used by fontset_pattern_regexp. The car part is a
1237 pattern string containing at least one wild card, the cdr part is
1238 the corresponding regular expression. */
1239 static Lisp_Object Vcached_fontset_data
;
1241 #define CACHED_FONTSET_NAME (SDATA (XCAR (Vcached_fontset_data)))
1242 #define CACHED_FONTSET_REGEX (XCDR (Vcached_fontset_data))
1244 /* If fontset name PATTERN contains any wild card, return regular
1245 expression corresponding to PATTERN. */
1248 fontset_pattern_regexp (pattern
)
1249 Lisp_Object pattern
;
1251 if (!index (SDATA (pattern
), '*')
1252 && !index (SDATA (pattern
), '?'))
1253 /* PATTERN does not contain any wild cards. */
1256 if (!CONSP (Vcached_fontset_data
)
1257 || strcmp (SDATA (pattern
), CACHED_FONTSET_NAME
))
1259 /* We must at first update the cached data. */
1260 unsigned char *regex
, *p0
, *p1
;
1261 int ndashes
= 0, nstars
= 0;
1263 for (p0
= SDATA (pattern
); *p0
; p0
++)
1267 else if (*p0
== '*')
1271 /* If PATTERN is not full XLFD we conert "*" to ".*". Otherwise
1272 we convert "*" to "[^-]*" which is much faster in regular
1273 expression matching. */
1275 p1
= regex
= (unsigned char *) alloca (SBYTES (pattern
) + 2 * nstars
+ 1);
1277 p1
= regex
= (unsigned char *) alloca (SBYTES (pattern
) + 5 * nstars
+ 1);
1280 for (p0
= SDATA (pattern
); *p0
; p0
++)
1287 *p1
++ = '[', *p1
++ = '^', *p1
++ = '-', *p1
++ = ']';
1290 else if (*p0
== '?')
1298 Vcached_fontset_data
= Fcons (build_string (SDATA (pattern
)),
1299 build_string (regex
));
1302 return CACHED_FONTSET_REGEX
;
1305 /* Return ID of the base fontset named NAME. If there's no such
1306 fontset, return -1. NAME_PATTERN specifies how to treat NAME as this:
1307 0: pattern containing '*' and '?' as wildcards
1308 1: regular expression
1309 2: literal fontset name
1313 fs_query_fontset (name
, name_pattern
)
1320 name
= Fdowncase (name
);
1321 if (name_pattern
!= 1)
1323 tem
= Frassoc (name
, Vfontset_alias_alist
);
1325 tem
= Fassoc (name
, Vfontset_alias_alist
);
1326 if (CONSP (tem
) && STRINGP (XCAR (tem
)))
1328 else if (name_pattern
== 0)
1330 tem
= fontset_pattern_regexp (name
);
1339 for (i
= 0; i
< ASIZE (Vfontset_table
); i
++)
1341 Lisp_Object fontset
, this_name
;
1343 fontset
= FONTSET_FROM_ID (i
);
1345 || !BASE_FONTSET_P (fontset
))
1348 this_name
= FONTSET_NAME (fontset
);
1349 if (name_pattern
== 1
1350 ? fast_string_match (name
, this_name
) >= 0
1351 : !strcmp (SDATA (name
), SDATA (this_name
)))
1358 DEFUN ("query-fontset", Fquery_fontset
, Squery_fontset
, 1, 2, 0,
1359 doc
: /* Return the name of a fontset that matches PATTERN.
1360 The value is nil if there is no matching fontset.
1361 PATTERN can contain `*' or `?' as a wildcard
1362 just as X font name matching algorithm allows.
1363 If REGEXPP is non-nil, PATTERN is a regular expression. */)
1365 Lisp_Object pattern
, regexpp
;
1367 Lisp_Object fontset
;
1370 (*check_window_system_func
) ();
1372 CHECK_STRING (pattern
);
1374 if (SCHARS (pattern
) == 0)
1377 id
= fs_query_fontset (pattern
, !NILP (regexpp
));
1381 fontset
= FONTSET_FROM_ID (id
);
1382 return FONTSET_NAME (fontset
);
1385 /* Return a list of base fontset names matching PATTERN on frame F. */
1388 list_fontsets (f
, pattern
, size
)
1390 Lisp_Object pattern
;
1393 Lisp_Object frame
, regexp
, val
;
1396 XSETFRAME (frame
, f
);
1398 regexp
= fontset_pattern_regexp (pattern
);
1401 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
1403 Lisp_Object fontset
, name
;
1405 fontset
= FONTSET_FROM_ID (id
);
1407 || !BASE_FONTSET_P (fontset
)
1408 || !EQ (frame
, FONTSET_FRAME (fontset
)))
1410 name
= FONTSET_NAME (fontset
);
1412 if (STRINGP (regexp
)
1413 ? (fast_string_match (regexp
, name
) < 0)
1414 : strcmp (SDATA (pattern
), SDATA (name
)))
1417 val
= Fcons (Fcopy_sequence (FONTSET_NAME (fontset
)), val
);
1424 /* Free all realized fontsets whose base fontset is BASE. */
1427 free_realized_fontsets (base
)
1433 /* For the moment, this doesn't work because free_realized_face
1434 doesn't remove FACE from a cache. Until we find a solution, we
1435 suppress this code, and simply use Fclear_face_cache even though
1436 that is not efficient. */
1438 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
1440 Lisp_Object
this = AREF (Vfontset_table
, id
);
1442 if (EQ (FONTSET_BASE (this), base
))
1446 for (tail
= FONTSET_FACE_ALIST (this); CONSP (tail
);
1449 FRAME_PTR f
= XFRAME (FONTSET_FRAME (this));
1450 int face_id
= XINT (XCDR (XCAR (tail
)));
1451 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1453 /* Face THIS itself is also freed by the following call. */
1454 free_realized_face (f
, face
);
1460 /* But, we don't have to call Fclear_face_cache if no fontset has
1461 been realized from BASE. */
1462 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
1464 Lisp_Object
this = AREF (Vfontset_table
, id
);
1466 if (CHAR_TABLE_P (this) && EQ (FONTSET_BASE (this), base
))
1468 Fclear_face_cache (Qt
);
1476 /* Check validity of NAME as a fontset name and return the
1477 corresponding fontset. If not valid, signal an error.
1478 If NAME is t, return Vdefault_fontset. */
1481 check_fontset_name (name
)
1487 return Vdefault_fontset
;
1489 CHECK_STRING (name
);
1490 /* First try NAME as literal. */
1491 id
= fs_query_fontset (name
, 2);
1493 /* For backward compatibility, try again NAME as pattern. */
1494 id
= fs_query_fontset (name
, 0);
1496 error ("Fontset `%s' does not exist", SDATA (name
));
1497 return FONTSET_FROM_ID (id
);
1501 accumulate_script_ranges (arg
, range
, val
)
1502 Lisp_Object arg
, range
, val
;
1504 if (EQ (XCAR (arg
), val
))
1507 XSETCDR (arg
, Fcons (Fcons (XCAR (range
), XCDR (range
)), XCDR (arg
)));
1509 XSETCDR (arg
, Fcons (Fcons (range
, range
), XCDR (arg
)));
1514 /* Return an ASCII font name generated from fontset name NAME and
1515 font-spec ASCII_SPEC. NAME is a string conforming to XLFD. */
1517 static INLINE Lisp_Object
1518 generate_ascii_font_name (name
, ascii_spec
)
1519 Lisp_Object name
, ascii_spec
;
1521 Lisp_Object font_spec
= Ffont_spec (0, NULL
);
1526 if (font_parse_xlfd (SDATA (name
), font_spec
) < 0)
1527 error ("Not an XLFD font name: %s", SDATA (name
));
1528 for (i
= FONT_FOUNDRY_INDEX
; i
<= FONT_WIDTH_INDEX
; i
++)
1529 if (! NILP (AREF (ascii_spec
, i
)))
1530 ASET (font_spec
, i
, AREF (ascii_spec
, i
));
1531 i
= font_unparse_xlfd (font_spec
, 0, xlfd
, 256);
1533 error ("Not an XLFD font name: %s", SDATA (name
));
1534 return make_unibyte_string (xlfd
, i
);
1537 /* Variables referred in set_fontset_font. They are set before
1538 map_charset_chars is called in Fset_fontset_font. */
1539 static Lisp_Object font_def_arg
, add_arg
;
1540 static int from_arg
, to_arg
;
1542 /* Callback function for map_charset_chars in Fset_fontset_font. In
1543 FONTSET, set font_def_arg in a fashion specified by add_arg for
1544 characters in RANGE while ignoring the range between from_arg and
1548 set_fontset_font (fontset
, range
)
1549 Lisp_Object fontset
, range
;
1551 if (from_arg
< to_arg
)
1553 int from
= XINT (XCAR (range
)), to
= XINT (XCDR (range
));
1555 if (from
< from_arg
)
1561 range2
= Fcons (make_number (to_arg
), XCDR (range
));
1562 FONTSET_ADD (fontset
, range
, font_def_arg
, add_arg
);
1566 range
= Fcons (XCAR (range
), make_number (from_arg
));
1568 else if (to
<= to_arg
)
1573 range
= Fcons (make_number (to_arg
), XCDR (range
));
1576 FONTSET_ADD (fontset
, range
, font_def_arg
, add_arg
);
1579 extern Lisp_Object QCfamily
, QCregistry
;
1581 DEFUN ("set-fontset-font", Fset_fontset_font
, Sset_fontset_font
, 3, 5, 0,
1583 Modify fontset NAME to use FONT-SPEC for TARGET characters.
1585 TARGET may be a cons; (FROM . TO), where FROM and TO are characters.
1586 In that case, use FONT-SPEC for all characters in the range FROM and
1589 TARGET may be a script name symbol. In that case, use FONT-SPEC for
1590 all characters that belong to the script.
1592 TARGET may be a charset. In that case, use FONT-SPEC for all
1593 characters in the charset.
1595 TARGET may be nil. In that case, use FONT-SPEC for any characters for
1596 that no FONT-SPEC is specified.
1598 FONT-SPEC may one of these:
1599 * A cons (FAMILY . REGISTRY), where FAMILY is a font family name and
1600 REGISTRY is a font registry name. FAMILY may contains foundry
1601 name, and REGISTRY may contains encoding name.
1602 * A font name string.
1604 Optional 4th argument FRAME, if non-nil, is a frame. This argument is
1605 kept for backward compatibility and has no meaning.
1607 Optional 5th argument ADD, if non-nil, specifies how to add FONT-SPEC
1608 to the font specifications for TARGET previously set. If it is
1609 `prepend', FONT-SPEC is prepended. If it is `append', FONT-SPEC is
1610 appended. By default, FONT-SPEC overrides the previous settings. */)
1611 (name
, target
, font_spec
, frame
, add
)
1612 Lisp_Object name
, target
, font_spec
, frame
, add
;
1614 Lisp_Object fontset
;
1615 Lisp_Object font_def
, registry
, family
;
1616 Lisp_Object encoding
, repertory
;
1617 Lisp_Object range_list
;
1618 struct charset
*charset
= NULL
;
1620 fontset
= check_fontset_name (name
);
1622 /* The arg FRAME is kept for backward compatibility. We only check
1625 CHECK_LIVE_FRAME (frame
);
1627 if (VECTORP (font_spec
))
1629 if (! FONT_SPEC_P (font_spec
))
1630 Fsignal (Qfont
, list2 (build_string ("invalid font-spec"), font_spec
));
1632 else if (CONSP (font_spec
))
1634 Lisp_Object args
[4];
1637 family
= XCAR (font_spec
);
1638 registry
= XCDR (font_spec
);
1640 if (! NILP (family
))
1642 CHECK_STRING (family
);
1643 args
[i
++] = QCfamily
;
1646 CHECK_STRING (registry
);
1647 args
[i
++] = QCregistry
;
1648 args
[i
++] = registry
;
1649 font_spec
= Ffont_spec (i
, args
);
1653 Lisp_Object args
[2];
1655 CHECK_STRING (font_spec
);
1657 args
[1] = font_spec
;
1658 font_spec
= Ffont_spec (2, args
);
1661 family
= AREF (font_spec
, FONT_FAMILY_INDEX
);
1662 if (! NILP (family
) && SYMBOLP (family
))
1663 family
= SYMBOL_NAME (family
);
1664 registry
= AREF (font_spec
, FONT_REGISTRY_INDEX
);
1665 if (! NILP (registry
) && SYMBOLP (registry
))
1666 registry
= SYMBOL_NAME (registry
);
1668 encoding
= find_font_encoding (concat2 (family
, registry
));
1669 if (NILP (encoding
))
1672 if (SYMBOLP (encoding
))
1674 CHECK_CHARSET (encoding
);
1675 encoding
= repertory
= CHARSET_SYMBOL_ID (encoding
);
1679 repertory
= XCDR (encoding
);
1680 encoding
= XCAR (encoding
);
1681 CHECK_CHARSET (encoding
);
1682 encoding
= CHARSET_SYMBOL_ID (encoding
);
1683 if (! NILP (repertory
) && SYMBOLP (repertory
))
1685 CHECK_CHARSET (repertory
);
1686 repertory
= CHARSET_SYMBOL_ID (repertory
);
1689 font_def
= Fmake_vector (make_number (3), font_spec
);
1690 ASET (font_def
, 1, encoding
);
1691 ASET (font_def
, 2, repertory
);
1693 if (CHARACTERP (target
))
1694 range_list
= Fcons (Fcons (target
, target
), Qnil
);
1695 else if (CONSP (target
))
1697 Lisp_Object from
, to
;
1699 from
= Fcar (target
);
1701 CHECK_CHARACTER (from
);
1702 CHECK_CHARACTER (to
);
1703 range_list
= Fcons (target
, Qnil
);
1705 else if (SYMBOLP (target
) && !NILP (target
))
1707 Lisp_Object script_list
;
1711 script_list
= XCHAR_TABLE (Vchar_script_table
)->extras
[0];
1712 if (! NILP (Fmemq (target
, script_list
)))
1714 val
= Fcons (target
, Qnil
);
1715 map_char_table (accumulate_script_ranges
, Qnil
, Vchar_script_table
,
1717 range_list
= XCDR (val
);
1718 if (EQ (target
, Qlatin
))
1720 if (VECTORP (font_spec
))
1721 val
= generate_ascii_font_name (FONTSET_NAME (fontset
),
1725 FONTSET_ASCII (fontset
) = val
;
1728 if (CHARSETP (target
))
1730 if (EQ (target
, Qascii
))
1732 if (VECTORP (font_spec
))
1733 font_spec
= generate_ascii_font_name (FONTSET_NAME (fontset
),
1735 FONTSET_ASCII (fontset
) = font_spec
;
1736 range_list
= Fcons (Fcons (make_number (0), make_number (127)),
1741 CHECK_CHARSET_GET_CHARSET (target
, charset
);
1744 else if (NILP (range_list
))
1745 error ("Invalid script or charset name: %s",
1746 SDATA (SYMBOL_NAME (target
)));
1748 else if (NILP (target
))
1749 range_list
= Fcons (Qnil
, Qnil
);
1751 error ("Invalid target for setting a font");
1756 font_def_arg
= font_def
;
1758 if (NILP (range_list
))
1759 from_arg
= to_arg
= 0;
1761 from_arg
= XINT (XCAR (XCAR (range_list
))),
1762 to_arg
= XINT (XCDR (XCAR (range_list
)));
1764 map_charset_chars (set_fontset_font
, Qnil
, fontset
, charset
,
1765 CHARSET_MIN_CODE (charset
),
1766 CHARSET_MAX_CODE (charset
));
1768 for (; CONSP (range_list
); range_list
= XCDR (range_list
))
1769 FONTSET_ADD (fontset
, XCAR (range_list
), font_def
, add
);
1771 /* Free all realized fontsets whose base is FONTSET. This way, the
1772 specified character(s) are surely redisplayed by a correct
1774 free_realized_fontsets (fontset
);
1780 DEFUN ("new-fontset", Fnew_fontset
, Snew_fontset
, 2, 2, 0,
1781 doc
: /* Create a new fontset NAME from font information in FONTLIST.
1783 FONTLIST is an alist of scripts vs the corresponding font specification list.
1784 Each element of FONTLIST has the form (SCRIPT FONT-SPEC ...), where a
1785 character of SCRIPT is displayed by a font that matches one of
1788 SCRIPT is a symbol that appears in the first extra slot of the
1789 char-table `char-script-table'.
1791 FONT-SPEC is a vector, a cons, or a string. See the documentation of
1792 `set-fontset-font' for the meaning. */)
1794 Lisp_Object name
, fontlist
;
1796 Lisp_Object fontset
;
1800 CHECK_STRING (name
);
1801 CHECK_LIST (fontlist
);
1803 id
= fs_query_fontset (name
, 0);
1806 name
= Fdowncase (name
);
1807 val
= split_font_name_into_vector (name
);
1808 if (NILP (val
) || NILP (AREF (val
, 12)) || NILP (AREF (val
, 13)))
1809 error ("Fontset name must be in XLFD format");
1810 if (strcmp (SDATA (AREF (val
, 12)), "fontset"))
1811 error ("Registry field of fontset name must be \"fontset\"");
1812 Vfontset_alias_alist
1813 = Fcons (Fcons (name
,
1814 concat2 (concat2 (AREF (val
, 12), build_string ("-")),
1816 Vfontset_alias_alist
);
1817 ASET (val
, 12, build_string ("iso8859-1"));
1818 fontset
= make_fontset (Qnil
, name
, Qnil
);
1819 FONTSET_ASCII (fontset
) = build_font_name_from_vector (val
);
1823 fontset
= FONTSET_FROM_ID (id
);;
1824 free_realized_fontsets (fontset
);
1825 Fset_char_table_range (fontset
, Qt
, Qnil
);
1828 for (; ! NILP (fontlist
); fontlist
= Fcdr (fontlist
))
1830 Lisp_Object elt
, script
;
1832 elt
= Fcar (fontlist
);
1833 script
= Fcar (elt
);
1835 if (CONSP (elt
) && (NILP (XCDR (elt
)) || CONSP (XCDR (elt
))))
1836 for (; CONSP (elt
); elt
= XCDR (elt
))
1837 Fset_fontset_font (name
, script
, XCAR (elt
), Qnil
, Qappend
);
1839 Fset_fontset_font (name
, script
, elt
, Qnil
, Qappend
);
1845 /* Alist of automatically created fontsets. Each element is a cons
1846 (FONTNAME . FONTSET-ID). */
1847 static Lisp_Object auto_fontset_alist
;
1850 new_fontset_from_font_name (Lisp_Object fontname
)
1857 fontname
= Fdowncase (fontname
);
1858 val
= Fassoc (fontname
, auto_fontset_alist
);
1860 return XINT (XCDR (val
));
1862 vec
= split_font_name_into_vector (fontname
);
1864 vec
= Fmake_vector (make_number (14), build_string (""));
1865 ASET (vec
, 12, build_string ("fontset"));
1866 if (NILP (auto_fontset_alist
))
1868 ASET (vec
, 13, build_string ("startup"));
1869 name
= build_font_name_from_vector (vec
);
1874 int len
= XINT (Flength (auto_fontset_alist
));
1876 sprintf (temp
, "auto%d", len
);
1877 ASET (vec
, 13, build_string (temp
));
1878 name
= build_font_name_from_vector (vec
);
1880 name
= Fnew_fontset (name
, list2 (list2 (Qascii
, fontname
),
1881 list2 (Fcons (make_number (0),
1882 make_number (MAX_CHAR
)),
1884 id
= fs_query_fontset (name
, 0);
1886 = Fcons (Fcons (fontname
, make_number (id
)), auto_fontset_alist
);
1890 #ifdef USE_FONT_BACKEND
1892 new_fontset_from_font (font_object
)
1893 Lisp_Object font_object
;
1895 Lisp_Object font_name
= font_get_name (font_object
);
1896 Lisp_Object font_spec
= font_get_spec (font_object
);
1897 Lisp_Object fontset_spec
, short_name
, name
, fontset
;
1899 if (NILP (auto_fontset_alist
))
1900 short_name
= build_string ("fontset-startup");
1904 int len
= XINT (Flength (auto_fontset_alist
));
1906 sprintf (temp
, "fontset-auto%d", len
);
1907 short_name
= build_string (temp
);
1909 fontset_spec
= Fcopy_sequence (font_spec
);
1910 ASET (fontset_spec
, FONT_REGISTRY_INDEX
, short_name
);
1911 name
= Ffont_xlfd_name (fontset_spec
);
1916 for (i
= 0; i
< FONT_SIZE_INDEX
; i
++)
1917 if ((i
!= FONT_FAMILY_INDEX
) && (i
!= FONT_REGISTRY_INDEX
))
1918 ASET (fontset_spec
, i
, Qnil
);
1919 name
= Ffont_xlfd_name (fontset_spec
);
1923 fontset
= make_fontset (Qnil
, name
, Qnil
);
1924 FONTSET_ASCII (fontset
) = font_name
;
1925 font_spec
= Fcons (SYMBOL_NAME (AREF (font_spec
, FONT_FAMILY_INDEX
)),
1926 SYMBOL_NAME (AREF (font_spec
, FONT_REGISTRY_INDEX
)));
1927 Fset_fontset_font (name
, Qlatin
, font_spec
, Qnil
, Qnil
);
1928 Fset_fontset_font (name
, Qnil
, font_spec
, Qnil
, Qnil
);
1929 return XINT (FONTSET_ID (fontset
));
1933 fontset_ascii_font (f
, id
)
1937 Lisp_Object fontset
= FONTSET_FROM_ID (id
);
1938 Lisp_Object ascii_slot
= FONTSET_ASCII (fontset
);
1939 Lisp_Object val
, font_object
;
1941 if (CONSP (ascii_slot
))
1943 Lisp_Object ascii_font_name
= XCAR (ascii_slot
);
1946 for (val
= XCDR (ascii_slot
); ! NILP (val
); val
= XCDR (val
))
1948 Lisp_Object frame
= font_get_frame (XCAR (val
));
1950 if (NILP (frame
) || XFRAME (frame
) == f
)
1952 font_object
= XCAR (val
);
1953 if (XSAVE_VALUE (font_object
)->integer
== 0)
1955 font_object
= font_open_by_name (f
, SDATA (ascii_font_name
));
1956 XSETCAR (val
, font_object
);
1961 if (NILP (font_object
))
1963 font_object
= font_open_by_name (f
, SDATA (ascii_font_name
));
1964 XSETCDR (ascii_slot
, Fcons (font_object
, XCDR (ascii_slot
)));
1969 font_object
= font_open_by_name (f
, SDATA (ascii_slot
));
1970 FONTSET_ASCII (fontset
) = Fcons (ascii_slot
, Fcons (font_object
, Qnil
));
1972 if (NILP (font_object
))
1974 return XSAVE_VALUE (font_object
)->pointer
;
1977 #endif /* USE_FONT_BACKEND */
1979 DEFUN ("font-info", Ffont_info
, Sfont_info
, 1, 2, 0,
1980 doc
: /* Return information about a font named NAME on frame FRAME.
1981 If FRAME is omitted or nil, use the selected frame.
1982 The returned value is a vector of OPENED-NAME, FULL-NAME, CHARSET, SIZE,
1983 HEIGHT, BASELINE-OFFSET, RELATIVE-COMPOSE, and DEFAULT-ASCENT,
1985 OPENED-NAME is the name used for opening the font,
1986 FULL-NAME is the full name of the font,
1987 SIZE is the maximum bound width of the font,
1988 HEIGHT is the height of the font,
1989 BASELINE-OFFSET is the upward offset pixels from ASCII baseline,
1990 RELATIVE-COMPOSE and DEFAULT-ASCENT are the numbers controlling
1991 how to compose characters.
1992 If the named font is not yet loaded, return nil. */)
1994 Lisp_Object name
, frame
;
1997 struct font_info
*fontp
;
1999 Lisp_Object font_object
;
2001 (*check_window_system_func
) ();
2003 CHECK_STRING (name
);
2004 name
= Fdowncase (name
);
2006 frame
= selected_frame
;
2007 CHECK_LIVE_FRAME (frame
);
2010 if (!query_font_func
)
2011 error ("Font query function is not supported");
2013 #ifdef USE_FONT_BACKEND
2014 if (enable_font_backend
)
2016 font_object
= font_open_by_name (f
, SDATA (name
));
2017 if (NILP (font_object
))
2020 fontp
= (struct font_info
*) XSAVE_VALUE (font_object
)->pointer
;
2023 #endif /* USE_FONT_BACKEND */
2024 fontp
= (*query_font_func
) (f
, SDATA (name
));
2028 info
= Fmake_vector (make_number (7), Qnil
);
2030 XVECTOR (info
)->contents
[0] = build_string (fontp
->name
);
2031 XVECTOR (info
)->contents
[1] = build_string (fontp
->full_name
);
2032 XVECTOR (info
)->contents
[2] = make_number (fontp
->size
);
2033 XVECTOR (info
)->contents
[3] = make_number (fontp
->height
);
2034 XVECTOR (info
)->contents
[4] = make_number (fontp
->baseline_offset
);
2035 XVECTOR (info
)->contents
[5] = make_number (fontp
->relative_compose
);
2036 XVECTOR (info
)->contents
[6] = make_number (fontp
->default_ascent
);
2038 #ifdef USE_FONT_BACKEND
2039 if (! NILP (font_object
))
2040 font_close_object (f
, font_object
);
2041 #endif /* USE_FONT_BACKEND */
2046 /* Return a cons (FONT-NAME . GLYPH-CODE).
2047 FONT-NAME is the font name for the character at POSITION in the current
2048 buffer. This is computed from all the text properties and overlays
2049 that apply to POSITION. POSTION may be nil, in which case,
2050 FONT-NAME is the font name for display the character CH with the
2053 GLYPH-CODE is the glyph code in the font to use for the character.
2055 If the 2nd optional arg CH is non-nil, it is a character to check
2056 the font instead of the character at POSITION.
2058 It returns nil in the following cases:
2060 (1) The window system doesn't have a font for the character (thus
2061 it is displayed by an empty box).
2063 (2) The character code is invalid.
2065 (3) If POSITION is not nil, and the current buffer is not displayed
2068 In addition, the returned font name may not take into account of
2069 such redisplay engine hooks as what used in jit-lock-mode if
2070 POSITION is currently not visible. */
2073 DEFUN ("internal-char-font", Finternal_char_font
, Sinternal_char_font
, 1, 2, 0,
2074 doc
: /* For internal use only. */)
2076 Lisp_Object position
, ch
;
2078 int pos
, pos_byte
, dummy
;
2083 Lisp_Object charset
, rfont_def
;
2086 if (NILP (position
))
2088 CHECK_CHARACTER (ch
);
2090 f
= XFRAME (selected_frame
);
2091 face_id
= DEFAULT_FACE_ID
;
2097 Lisp_Object window
, charset
;
2100 CHECK_NUMBER_COERCE_MARKER (position
);
2101 pos
= XINT (position
);
2102 if (pos
< BEGV
|| pos
>= ZV
)
2103 args_out_of_range_3 (position
, make_number (BEGV
), make_number (ZV
));
2104 pos_byte
= CHAR_TO_BYTE (pos
);
2106 c
= FETCH_CHAR (pos_byte
);
2112 window
= Fget_buffer_window (Fcurrent_buffer (), Qnil
);
2115 w
= XWINDOW (window
);
2116 f
= XFRAME (w
->frame
);
2117 face_id
= face_at_buffer_position (w
, pos
, -1, -1, &dummy
, pos
+ 100, 0);
2118 charset
= Fget_char_property (position
, Qcharset
, Qnil
);
2119 if (CHARSETP (charset
))
2120 cs_id
= XINT (CHARSET_SYMBOL_ID (charset
));
2124 if (! CHAR_VALID_P (c
, 0))
2126 face_id
= FACE_FOR_CHAR (f
, FACE_FROM_ID (f
, face_id
), c
, pos
, Qnil
);
2127 face
= FACE_FROM_ID (f
, face_id
);
2128 rfont_def
= fontset_font (FONTSET_FROM_ID (face
->fontset
), c
, face
, cs_id
);
2129 #ifdef USE_FONT_BACKEND
2130 if (enable_font_backend
)
2132 if (VECTORP (rfont_def
) && ! NILP (AREF (rfont_def
, 3)))
2134 Lisp_Object font_object
= XCAR (AREF (rfont_def
, 3));
2135 struct font
*font
= XSAVE_VALUE (font_object
)->pointer
;
2136 unsigned code
= font
->driver
->encode_char (font
, c
);
2137 Lisp_Object fontname
= font_get_name (font_object
);
2139 if (code
== FONT_INVALID_CODE
)
2140 return Fcons (fontname
, Qnil
);
2141 if (code
<= MOST_POSITIVE_FIXNUM
)
2142 return Fcons (fontname
, make_number (code
));
2143 return Fcons (fontname
, Fcons (make_number (code
>> 16),
2144 make_number (code
& 0xFFFF)));
2148 #endif /* USE_FONT_BACKEND */
2149 if (VECTORP (rfont_def
) && STRINGP (AREF (rfont_def
, 3)))
2151 Lisp_Object font_def
;
2152 struct font_info
*fontp
;
2153 struct charset
*charset
;
2157 font_def
= AREF (rfont_def
, 2);
2158 charset
= CHARSET_FROM_ID (XINT (AREF (font_def
, 1)));
2159 code
= ENCODE_CHAR (charset
, c
);
2160 if (code
== CHARSET_INVALID_CODE (charset
))
2161 return (Fcons (AREF (rfont_def
, 3), Qnil
));
2162 STORE_XCHAR2B (&char2b
, ((code
>> 8) & 0xFF), (code
& 0xFF));
2163 fontp
= (*get_font_info_func
) (f
, XINT (AREF (rfont_def
, 1)));
2164 FRAME_RIF (f
)->encode_char (c
, &char2b
, fontp
, charset
, NULL
);
2165 code
= (XCHAR2B_BYTE1 (&char2b
) << 8) | XCHAR2B_BYTE2 (&char2b
);
2166 return (Fcons (AREF (rfont_def
, 3), make_number (code
)));
2172 DEFUN ("fontset-info", Ffontset_info
, Sfontset_info
, 1, 2, 0,
2173 doc
: /* Return information about a fontset FONTSET on frame FRAME.
2174 The value is a char-table of which elements has this form.
2176 ((FONT-PATTERN OPENED-FONT ...) ...)
2178 FONT-PATTERN is a vector:
2180 [ FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY ]
2182 or a string of font name pattern.
2184 OPENED-FONT is a name of a font actually opened.
2186 The char-table has one extra slot. The value is a char-table
2187 containing the information about the derived fonts from the default
2188 fontset. The format is the same as abobe. */)
2190 Lisp_Object fontset
, frame
;
2193 Lisp_Object
*realized
[2], fontsets
[2], tables
[2];
2194 Lisp_Object val
, elt
;
2197 (*check_window_system_func
) ();
2199 fontset
= check_fontset_name (fontset
);
2202 frame
= selected_frame
;
2203 CHECK_LIVE_FRAME (frame
);
2206 /* Recode fontsets realized on FRAME from the base fontset FONTSET
2207 in the table `realized'. */
2208 realized
[0] = (Lisp_Object
*) alloca (sizeof (Lisp_Object
)
2209 * ASIZE (Vfontset_table
));
2210 for (i
= j
= 0; i
< ASIZE (Vfontset_table
); i
++)
2212 elt
= FONTSET_FROM_ID (i
);
2214 && EQ (FONTSET_BASE (elt
), fontset
)
2215 && EQ (FONTSET_FRAME (elt
), frame
))
2216 realized
[0][j
++] = elt
;
2218 realized
[0][j
] = Qnil
;
2220 realized
[1] = (Lisp_Object
*) alloca (sizeof (Lisp_Object
)
2221 * ASIZE (Vfontset_table
));
2222 for (i
= j
= 0; ! NILP (realized
[0][i
]); i
++)
2224 elt
= FONTSET_DEFAULT (realized
[0][i
]);
2226 realized
[1][j
++] = elt
;
2228 realized
[1][j
] = Qnil
;
2230 tables
[0] = Fmake_char_table (Qfontset_info
, Qnil
);
2231 tables
[1] = Fmake_char_table (Qnil
, Qnil
);
2232 XCHAR_TABLE (tables
[0])->extras
[0] = tables
[1];
2233 fontsets
[0] = fontset
;
2234 fontsets
[1] = Vdefault_fontset
;
2236 /* Accumulate information of the fontset in TABLE. The format of
2237 each element is ((FONT-SPEC OPENED-FONT ...) ...). */
2238 for (k
= 0; k
<= 1; k
++)
2240 for (c
= 0; c
<= MAX_CHAR
; )
2244 if (c
<= MAX_5_BYTE_CHAR
)
2246 val
= char_table_ref_and_range (fontsets
[k
], c
, &from
, &to
);
2247 if (to
> MAX_5_BYTE_CHAR
)
2248 to
= MAX_5_BYTE_CHAR
;
2252 val
= FONTSET_FALLBACK (fontsets
[k
]);
2259 /* At first, set ALIST to ((FONT-SPEC) ...). */
2260 for (alist
= Qnil
, i
= 0; i
< ASIZE (val
); i
++)
2261 alist
= Fcons (Fcons (AREF (AREF (val
, i
), 0), Qnil
), alist
);
2262 alist
= Fnreverse (alist
);
2264 /* Then store opend font names to cdr of each elements. */
2265 for (i
= 0; ! NILP (realized
[k
][i
]); i
++)
2267 if (c
<= MAX_5_BYTE_CHAR
)
2268 val
= FONTSET_REF (realized
[k
][i
], c
);
2270 val
= FONTSET_FALLBACK (realized
[k
][i
]);
2271 if (! VECTORP (val
))
2273 /* VAL is [int int ?
2274 [FACE-ID FONT-INDEX FONT-DEF FONT-NAME] ...].
2275 If a font of an element is already opened,
2276 FONT-NAME is the name of a opened font. */
2277 for (j
= 3; j
< ASIZE (val
); j
++)
2278 if (STRINGP (AREF (AREF (val
, j
), 3)))
2280 Lisp_Object font_idx
;
2282 font_idx
= AREF (AREF (val
, j
), 1);
2283 elt
= Fassq (AREF (AREF (AREF (val
, j
), 2), 0), alist
);
2285 && NILP (Fmemq (font_idx
, XCDR(elt
))))
2286 nconc2 (elt
, Fcons (font_idx
, Qnil
));
2289 for (val
= alist
; CONSP (val
); val
= XCDR (val
))
2290 for (elt
= XCDR (XCAR (val
)); CONSP (elt
); elt
= XCDR (elt
))
2292 struct font_info
*font_info
2293 = (*get_font_info_func
) (f
, XINT (XCAR (elt
)));
2294 XSETCAR (elt
, build_string (font_info
->full_name
));
2297 /* Store ALIST in TBL for characters C..TO. */
2298 if (c
<= MAX_5_BYTE_CHAR
)
2299 char_table_set_range (tables
[k
], c
, to
, alist
);
2301 XCHAR_TABLE (tables
[k
])->defalt
= alist
;
2311 DEFUN ("fontset-font", Ffontset_font
, Sfontset_font
, 2, 3, 0,
2312 doc
: /* Return a font name pattern for character CH in fontset NAME.
2313 If NAME is t, find a pattern in the default fontset.
2315 The value has the form (FAMILY . REGISTRY), where FAMILY is a font
2316 family name and REGISTRY is a font registry name. This is actually
2317 the first font name pattern for CH in the fontset or in the default
2320 If the 2nd optional arg ALL is non-nil, return a list of all font name
2323 Lisp_Object name
, ch
, all
;
2326 Lisp_Object fontset
, elt
, list
, repertory
, val
;
2329 fontset
= check_fontset_name (name
);
2331 CHECK_CHARACTER (ch
);
2336 for (i
= 0, elt
= FONTSET_REF (fontset
, c
); i
< 2;
2337 i
++, elt
= FONTSET_FALLBACK (fontset
))
2339 for (j
= 0; j
< ASIZE (elt
); j
++)
2341 val
= AREF (elt
, j
);
2342 repertory
= AREF (val
, 1);
2343 if (INTEGERP (repertory
))
2345 struct charset
*charset
= CHARSET_FROM_ID (XINT (repertory
));
2347 if (! CHAR_CHARSET_P (c
, charset
))
2350 else if (CHAR_TABLE_P (repertory
))
2352 if (NILP (CHAR_TABLE_REF (repertory
, c
)))
2355 val
= AREF (val
, 0);
2356 val
= Fcons (AREF (val
, 0), AREF (val
, 5));
2359 list
= Fcons (val
, list
);
2361 if (EQ (fontset
, Vdefault_fontset
))
2363 fontset
= Vdefault_fontset
;
2365 return (Fnreverse (list
));
2368 DEFUN ("fontset-list", Ffontset_list
, Sfontset_list
, 0, 0, 0,
2369 doc
: /* Return a list of all defined fontset names. */)
2372 Lisp_Object fontset
, list
;
2376 for (i
= 0; i
< ASIZE (Vfontset_table
); i
++)
2378 fontset
= FONTSET_FROM_ID (i
);
2380 && BASE_FONTSET_P (fontset
))
2381 list
= Fcons (FONTSET_NAME (fontset
), list
);
2388 #ifdef FONTSET_DEBUG
2391 dump_fontset (fontset
)
2392 Lisp_Object fontset
;
2396 vec
= Fmake_vector (make_number (3), Qnil
);
2397 ASET (vec
, 0, FONTSET_ID (fontset
));
2399 if (BASE_FONTSET_P (fontset
))
2401 ASET (vec
, 1, FONTSET_NAME (fontset
));
2407 frame
= FONTSET_FRAME (fontset
);
2410 FRAME_PTR f
= XFRAME (frame
);
2412 if (FRAME_LIVE_P (f
))
2414 Fcons (FONTSET_NAME (FONTSET_BASE (fontset
)), f
->name
));
2417 Fcons (FONTSET_NAME (FONTSET_BASE (fontset
)), Qnil
));
2419 if (!NILP (FONTSET_DEFAULT (fontset
)))
2420 ASET (vec
, 2, FONTSET_ID (FONTSET_DEFAULT (fontset
)));
2425 DEFUN ("fontset-list-all", Ffontset_list_all
, Sfontset_list_all
, 0, 0, 0,
2426 doc
: /* Return a brief summary of all fontsets for debug use. */)
2432 for (i
= 0, val
= Qnil
; i
< ASIZE (Vfontset_table
); i
++)
2433 if (! NILP (AREF (Vfontset_table
, i
)))
2434 val
= Fcons (dump_fontset (AREF (Vfontset_table
, i
)), val
);
2435 return (Fnreverse (val
));
2437 #endif /* FONTSET_DEBUG */
2442 if (!load_font_func
)
2443 /* Window system initializer should have set proper functions. */
2446 DEFSYM (Qfontset
, "fontset");
2447 Fput (Qfontset
, Qchar_table_extra_slots
, make_number (9));
2448 DEFSYM (Qfontset_info
, "fontset-info");
2449 Fput (Qfontset_info
, Qchar_table_extra_slots
, make_number (1));
2451 DEFSYM (Qprepend
, "prepend");
2452 DEFSYM (Qappend
, "append");
2453 DEFSYM (Qlatin
, "latin");
2455 Vcached_fontset_data
= Qnil
;
2456 staticpro (&Vcached_fontset_data
);
2458 Vfontset_table
= Fmake_vector (make_number (32), Qnil
);
2459 staticpro (&Vfontset_table
);
2461 Vdefault_fontset
= Fmake_char_table (Qfontset
, Qnil
);
2462 staticpro (&Vdefault_fontset
);
2463 FONTSET_ID (Vdefault_fontset
) = make_number (0);
2464 FONTSET_NAME (Vdefault_fontset
)
2465 = build_string ("-*-*-*-*-*-*-*-*-*-*-*-*-fontset-default");
2466 AREF (Vfontset_table
, 0) = Vdefault_fontset
;
2467 next_fontset_id
= 1;
2469 auto_fontset_alist
= Qnil
;
2470 staticpro (&auto_fontset_alist
);
2472 DEFVAR_LISP ("font-encoding-alist", &Vfont_encoding_alist
,
2474 Alist of fontname patterns vs the corresponding encoding and repertory info.
2475 Each element looks like (REGEXP . (ENCODING . REPERTORY)),
2476 where ENCODING is a charset or a char-table,
2477 and REPERTORY is a charset, a char-table, or nil.
2479 If ENCDING and REPERTORY are the same, the element can have the form
2480 \(REGEXP . ENCODING).
2482 ENCODING is for converting a character to a glyph code of the font.
2483 If ENCODING is a charset, encoding a character by the charset gives
2484 the corresponding glyph code. If ENCODING is a char-table, looking up
2485 the table by a character gives the corresponding glyph code.
2487 REPERTORY specifies a repertory of characters supported by the font.
2488 If REPERTORY is a charset, all characters beloging to the charset are
2489 supported. If REPERTORY is a char-table, all characters who have a
2490 non-nil value in the table are supported. It REPERTORY is nil, Emacs
2491 gets the repertory information by an opened font and ENCODING. */);
2492 Vfont_encoding_alist
= Qnil
;
2494 DEFVAR_LISP ("font-encoding-charset-alist", &Vfont_encoding_charset_alist
,
2496 Alist of charsets vs the charsets to determine the preferred font encoding.
2497 Each element looks like (CHARSET . ENCDOING-CHARSET),
2498 where ENCODING-CHARSET is a charset registered in the variable
2499 `font-encoding-alist' as ENCODING.
2501 When a text has a property `charset' and the value is CHARSET, a font
2502 whose encoding corresponds to ENCODING-CHARSET is preferred. */);
2503 Vfont_encoding_charset_alist
= Qnil
;
2505 DEFVAR_LISP ("use-default-ascent", &Vuse_default_ascent
,
2507 Char table of characters whose ascent values should be ignored.
2508 If an entry for a character is non-nil, the ascent value of the glyph
2509 is assumed to be what specified by _MULE_DEFAULT_ASCENT property of a font.
2511 This affects how a composite character which contains
2512 such a character is displayed on screen. */);
2513 Vuse_default_ascent
= Qnil
;
2515 DEFVAR_LISP ("ignore-relative-composition", &Vignore_relative_composition
,
2517 Char table of characters which is not composed relatively.
2518 If an entry for a character is non-nil, a composition sequence
2519 which contains that character is displayed so that
2520 the glyph of that character is put without considering
2521 an ascent and descent value of a previous character. */);
2522 Vignore_relative_composition
= Qnil
;
2524 DEFVAR_LISP ("alternate-fontname-alist", &Valternate_fontname_alist
,
2525 doc
: /* Alist of fontname vs list of the alternate fontnames.
2526 When a specified font name is not found, the corresponding
2527 alternate fontnames (if any) are tried instead. */);
2528 Valternate_fontname_alist
= Qnil
;
2530 DEFVAR_LISP ("fontset-alias-alist", &Vfontset_alias_alist
,
2531 doc
: /* Alist of fontset names vs the aliases. */);
2532 Vfontset_alias_alist
= Fcons (Fcons (FONTSET_NAME (Vdefault_fontset
),
2533 build_string ("fontset-default")),
2536 DEFVAR_LISP ("vertical-centering-font-regexp",
2537 &Vvertical_centering_font_regexp
,
2538 doc
: /* *Regexp matching font names that require vertical centering on display.
2539 When a character is displayed with such fonts, the character is displayed
2540 at the vertical center of lines. */);
2541 Vvertical_centering_font_regexp
= Qnil
;
2543 DEFVAR_LISP ("otf-script-alist", &Votf_script_alist
,
2544 doc
: /* Alist of OpenType script tags vs the corresponding script names. */);
2545 Votf_script_alist
= Qnil
;
2547 defsubr (&Squery_fontset
);
2548 defsubr (&Snew_fontset
);
2549 defsubr (&Sset_fontset_font
);
2550 defsubr (&Sfont_info
);
2551 defsubr (&Sinternal_char_font
);
2552 defsubr (&Sfontset_info
);
2553 defsubr (&Sfontset_font
);
2554 defsubr (&Sfontset_list
);
2555 #ifdef FONTSET_DEBUG
2556 defsubr (&Sfontset_list_all
);
2560 /* arch-tag: ea861585-2f5f-4e5b-9849-d04a9c3a3537
2561 (do not change this comment) */