2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
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"
60 #ifdef USE_FONT_BACKEND
62 #endif /* USE_FONT_BACKEND */
66 #define xassert(X) do {if (!(X)) abort ();} while (0)
69 #else /* not FONTSET_DEBUG */
70 #define xassert(X) (void) 0
71 #endif /* not FONTSET_DEBUG */
73 EXFUN (Fclear_face_cache
, 1);
77 A fontset is a collection of font related information to give
78 similar appearance (style, etc) of characters. A fontset has two
79 roles. One is to use for the frame parameter `font' as if it is an
80 ASCII font. In that case, Emacs uses the font specified for
81 `ascii' script for the frame's default font.
83 Another role, the more important one, is to provide information
84 about which font to use for each non-ASCII character.
86 There are two kinds of fontsets; base and realized. A base fontset
87 is created by `new-fontset' from Emacs Lisp explicitly. A realized
88 fontset is created implicitly when a face is realized for ASCII
89 characters. A face is also realized for non-ASCII characters based
90 on an ASCII face. All of non-ASCII faces based on the same ASCII
91 face share the same realized fontset.
93 A fontset object is implemented by a char-table whose default value
94 and parent are always nil.
96 An element of a base fontset is a vector of FONT-DEFs which itself
97 is a vector [ FONT-SPEC ENCODING REPERTORY ].
100 [ FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY ]
103 where FAMILY, WEIGHT, SLANT, SWIDTH, ADSTYLE, REGISTRY, and
104 FONT-NAME are strings.
106 Note: Currently WEIGHT through ADSTYLE are ignored.
108 ENCODING is a charset ID that can convert characters to glyph codes
109 of the corresponding font.
111 REPERTORY is a charset ID, a char-table, or nil. If REPERTORY is a
112 charset ID, the repertory of the charset exactly matches with that
113 of the font. If REPERTORY is a char-table, all characters who have
114 a non-nil value in the table are supported. If REPERTORY is nil,
115 we consult with the font itself to get the repertory.
117 ENCODING and REPERTORY are extracted from the variable
118 Vfont_encoding_alist by using a font name generated from FONT-SPEC
119 (if it is a vector) or FONT-NAME as a matching target.
122 An element of a realized fontset is nil or t, or has this form:
124 [CHARSET-ORDERED-LIST-TICK PREFERRED-CHARSET-ID
125 PREFERRED-RFONT-DEF RFONT-DEF0 RFONT-DEF1 ...].
127 RFONT-DEFn (i.e. Realized FONT-DEF) has this form:
129 [ FACE-ID FONT-INDEX FONT-DEF OPENED-FONT-NAME ]
131 RFONT-DEFn is automatically reordered by the current charset
134 The value nil means that we have not yet generated the above vector
135 from the base of the fontset.
137 The value t means that no font is available for the corresponding
141 A fontset has 9 extra slots.
143 The 1st slot: the ID number of the fontset
146 base: the name of the fontset
151 realized: the base fontset
155 realized: the frame that the fontset belongs to
158 base: the font name for ASCII characters
163 realized: the ID number of a face to use for characters that
164 has no font in a realized fontset.
168 realized: Alist of font index vs the corresponding repertory
173 realized: If the base is not the default fontset, a fontset
174 realized from the default fontset, else nil.
177 base: Same as element value (but for fallback fonts).
180 All fontsets are recorded in the vector Vfontset_table.
185 There's a special base fontset named `default fontset' which
186 defines the default font specifications. When a base fontset
187 doesn't specify a font for a specific character, the corresponding
188 value in the default fontset is used.
190 The parent of a realized fontset created for such a face that has
191 no fontset is the default fontset.
194 These structures are hidden from the other codes than this file.
195 The other codes handle fontsets only by their ID numbers. They
196 usually use the variable name `fontset' for IDs. But, in this
197 file, we always use varialbe name `id' for IDs, and name `fontset'
198 for an actual fontset object, i.e., char-table.
202 /********** VARIABLES and FUNCTION PROTOTYPES **********/
204 extern Lisp_Object Qfont
;
205 static Lisp_Object Qfontset
;
206 static Lisp_Object Qfontset_info
;
207 static Lisp_Object Qprepend
, Qappend
;
208 static Lisp_Object Qlatin
;
210 /* Vector containing all fontsets. */
211 static Lisp_Object Vfontset_table
;
213 /* Next possibly free fontset ID. Usually this keeps the minimum
214 fontset ID not yet used. */
215 static int next_fontset_id
;
217 /* The default fontset. This gives default FAMILY and REGISTRY of
218 font for each character. */
219 static Lisp_Object Vdefault_fontset
;
221 Lisp_Object Vfont_encoding_alist
;
222 Lisp_Object Vuse_default_ascent
;
223 Lisp_Object Vignore_relative_composition
;
224 Lisp_Object Valternate_fontname_alist
;
225 Lisp_Object Vfontset_alias_alist
;
226 Lisp_Object Vvertical_centering_font_regexp
;
227 Lisp_Object Votf_script_alist
;
229 /* The following six are declarations of callback functions depending
230 on window system. See the comments in src/fontset.h for more
233 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
234 struct font_info
*(*get_font_info_func
) P_ ((FRAME_PTR f
, int font_idx
));
236 /* Return a list of font names which matches PATTERN. See the documentation
237 of `x-list-fonts' for more details. */
238 Lisp_Object (*list_fonts_func
) P_ ((struct frame
*f
,
243 /* Load a font named NAME for frame F and return a pointer to the
244 information of the loaded font. If loading is failed, return 0. */
245 struct font_info
*(*load_font_func
) P_ ((FRAME_PTR f
, char *name
, int));
247 /* Return a pointer to struct font_info of a font named NAME for frame F. */
248 struct font_info
*(*query_font_func
) P_ ((FRAME_PTR f
, char *name
));
250 /* Additional function for setting fontset or changing fontset
251 contents of frame F. */
252 void (*set_frame_fontset_func
) P_ ((FRAME_PTR f
, Lisp_Object arg
,
253 Lisp_Object oldval
));
255 /* To find a CCL program, fs_load_font calls this function.
256 The argument is a pointer to the struct font_info.
257 This function set the member `encoder' of the structure. */
258 void (*find_ccl_program_func
) P_ ((struct font_info
*));
260 Lisp_Object (*get_font_repertory_func
) P_ ((struct frame
*,
261 struct font_info
*));
263 /* Check if any window system is used now. */
264 void (*check_window_system_func
) P_ ((void));
267 /* Prototype declarations for static functions. */
268 static Lisp_Object fontset_add
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
,
270 static Lisp_Object fontset_font
P_ ((Lisp_Object
, int, struct face
*, int));
271 static Lisp_Object make_fontset
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
));
272 static Lisp_Object fontset_pattern_regexp
P_ ((Lisp_Object
));
273 static void accumulate_script_ranges
P_ ((Lisp_Object
, Lisp_Object
,
275 Lisp_Object find_font_encoding
P_ ((Lisp_Object
));
277 static void set_fontset_font
P_ ((Lisp_Object
, Lisp_Object
));
281 /* Return 1 if ID is a valid fontset id, else return 0. */
284 fontset_id_valid_p (id
)
287 return (id
>= 0 && id
< ASIZE (Vfontset_table
) - 1);
294 /********** MACROS AND FUNCTIONS TO HANDLE FONTSET **********/
296 /* Return the fontset with ID. No check of ID's validness. */
297 #define FONTSET_FROM_ID(id) AREF (Vfontset_table, id)
299 /* Macros to access special values of FONTSET. */
300 #define FONTSET_ID(fontset) XCHAR_TABLE (fontset)->extras[0]
302 /* Macros to access special values of (base) FONTSET. */
303 #define FONTSET_NAME(fontset) XCHAR_TABLE (fontset)->extras[1]
304 #define FONTSET_ASCII(fontset) XCHAR_TABLE (fontset)->extras[4]
306 /* Macros to access special values of (realized) FONTSET. */
307 #define FONTSET_BASE(fontset) XCHAR_TABLE (fontset)->extras[2]
308 #define FONTSET_FRAME(fontset) XCHAR_TABLE (fontset)->extras[3]
309 #define FONTSET_NOFONT_FACE(fontset) XCHAR_TABLE (fontset)->extras[5]
310 #define FONTSET_REPERTORY(fontset) XCHAR_TABLE (fontset)->extras[6]
311 #define FONTSET_DEFAULT(fontset) XCHAR_TABLE (fontset)->extras[7]
313 /* For both base and realized fontset. */
314 #define FONTSET_FALLBACK(fontset) XCHAR_TABLE (fontset)->extras[8]
316 #define BASE_FONTSET_P(fontset) (NILP (FONTSET_BASE (fontset)))
319 /* Return the element of FONTSET for the character C. If FONTSET is a
320 base fontset other then the default fontset and FONTSET doesn't
321 contain information for C, return the information in the default
324 #define FONTSET_REF(fontset, c) \
325 (EQ (fontset, Vdefault_fontset) \
326 ? CHAR_TABLE_REF (fontset, c) \
327 : fontset_ref ((fontset), (c)))
330 fontset_ref (fontset
, c
)
336 elt
= CHAR_TABLE_REF (fontset
, c
);
337 if (NILP (elt
) && ! EQ (fontset
, Vdefault_fontset
)
338 /* Don't check Vdefault_fontset for a realized fontset. */
339 && NILP (FONTSET_BASE (fontset
)))
340 elt
= CHAR_TABLE_REF (Vdefault_fontset
, c
);
345 /* Return the element of FONTSET for the character C, set FROM and TO
346 to the range of characters around C that have the same value as C.
347 If FONTSET is a base fontset other then the default fontset and
348 FONTSET doesn't contain information for C, return the information
349 in the default fontset. */
351 #define FONTSET_REF_AND_RANGE(fontset, c, form, to) \
352 (EQ (fontset, Vdefault_fontset) \
353 ? char_table_ref_and_range (fontset, c, &from, &to) \
354 : fontset_ref_and_range (fontset, c, &from, &to))
357 fontset_ref_and_range (fontset
, c
, from
, to
)
364 elt
= char_table_ref_and_range (fontset
, c
, from
, to
);
365 if (NILP (elt
) && ! EQ (fontset
, Vdefault_fontset
)
366 /* Don't check Vdefault_fontset for a realized fontset. */
367 && NILP (FONTSET_BASE (fontset
)))
371 elt
= char_table_ref_and_range (Vdefault_fontset
, c
, &from1
, &to1
);
381 /* Set elements of FONTSET for characters in RANGE to the value ELT.
382 RANGE is a cons (FROM . TO), where FROM and TO are character codes
383 specifying a range. */
385 #define FONTSET_SET(fontset, range, elt) \
386 Fset_char_table_range ((fontset), (range), (elt))
389 /* Modify the elements of FONTSET for characters in RANGE by replacing
390 with ELT or adding ELT. RANGE is a cons (FROM . TO), where FROM
391 and TO are character codes specifying a range. If ADD is nil,
392 replace with ELT, if ADD is `prepend', prepend ELT, otherwise,
395 #define FONTSET_ADD(fontset, range, elt, add) \
398 ? (FONTSET_FALLBACK (fontset) = Fmake_vector (make_number (1), (elt))) \
399 : Fset_char_table_range ((fontset), (range), \
400 Fmake_vector (make_number (1), (elt)))) \
401 : fontset_add ((fontset), (range), (elt), (add)))
404 fontset_add (fontset
, range
, elt
, add
)
405 Lisp_Object fontset
, range
, elt
, add
;
408 int idx
= (EQ (add
, Qappend
) ? 0 : 1);
410 args
[1 - idx
] = Fmake_vector (make_number (1), elt
);
414 int from
= XINT (XCAR (range
));
415 int to
= XINT (XCDR (range
));
419 args
[idx
] = char_table_ref_and_range (fontset
, from
, &from1
, &to1
);
422 char_table_set_range (fontset
, from
, to1
,
423 NILP (args
[idx
]) ? args
[1 - idx
]
424 : Fvconcat (2, args
));
430 args
[idx
] = FONTSET_FALLBACK (fontset
);
431 FONTSET_FALLBACK (fontset
)
432 = NILP (args
[idx
]) ? args
[1 - idx
] : Fvconcat (2, args
);
438 /* Update FONTSET_ELEMENT which has this form:
439 [CHARSET-ORDERED-LIST-TICK PREFERRED-CHARSET-ID PREFERRED-RFONT-DEF
440 RFONT-DEF0 RFONT-DEF1 ...].
441 Reorder RFONT-DEFs according to the current order of charset
442 (Vcharset_ordered_list), and update CHARSET-ORDERED-LIST-TICK to
446 reorder_font_vector (fontset_element
)
447 Lisp_Object fontset_element
;
449 Lisp_Object list
, *new_vec
;
450 Lisp_Object font_def
;
452 int *charset_id_table
;
455 ASET (fontset_element
, 0, make_number (charset_ordered_list_tick
));
456 size
= ASIZE (fontset_element
) - 3;
458 /* No need to reorder VEC. */
460 charset_id_table
= (int *) alloca (sizeof (int) * size
);
461 new_vec
= (Lisp_Object
*) alloca (sizeof (Lisp_Object
) * size
);
463 /* At first, extract ENCODING (a chaset ID) from each FONT-DEF.
464 FONT-DEF has this form:
465 [FACE-ID FONT-INDEX [ FONT-SPEC ENCODING REPERTORY ]] */
466 for (i
= 0; i
< size
; i
++)
468 font_def
= AREF (fontset_element
, i
+ 3);
469 if (VECTORP (AREF (font_def
, 2))
470 && INTEGERP (AREF (AREF (font_def
, 2), 1)))
471 charset_id_table
[i
] = XINT (AREF (AREF (font_def
, 2), 1));
473 charset_id_table
[i
] = -1;
476 /* Then, store FONT-DEFs in NEW_VEC in the correct order. */
477 for (idx
= 0, list
= Vcharset_ordered_list
;
478 idx
< size
&& CONSP (list
); list
= XCDR (list
))
480 for (i
= 0; i
< size
; i
++)
481 if (charset_id_table
[i
] == XINT (XCAR (list
)))
482 new_vec
[idx
++] = AREF (fontset_element
, i
+ 3);
484 for (i
= 0; i
< size
; i
++)
485 if (charset_id_table
[i
] < 0)
486 new_vec
[idx
++] = AREF (fontset_element
, i
+ 3);
488 /* At last, update FONT-DEFs. */
489 for (i
= 0; i
< size
; i
++)
490 ASET (fontset_element
, i
+ 3, new_vec
[i
]);
494 /* Load a font matching the font related attributes in FACE->lface and
495 font pattern in FONT_DEF of FONTSET, and return an index of the
496 font. FONT_DEF has this form:
497 [ FONT-SPEC ENCODING REPERTORY ]
498 If REPERTORY is nil, generate a char-table representing the font
499 repertory by looking into the font itself. */
502 load_font_get_repertory (f
, face
, font_def
, fontset
)
505 Lisp_Object font_def
;
509 struct font_info
*font_info
;
512 font_name
= choose_face_font (f
, face
->lface
, AREF (font_def
, 0), NULL
);
513 charset
= XINT (AREF (font_def
, 1));
514 if (! (font_info
= fs_load_font (f
, font_name
, charset
)))
517 if (NILP (AREF (font_def
, 2))
518 && NILP (Fassq (make_number (font_info
->font_idx
),
519 FONTSET_REPERTORY (fontset
))))
521 /* We must look into the font to get the correct repertory as a
523 Lisp_Object repertory
;
525 repertory
= (*get_font_repertory_func
) (f
, font_info
);
526 FONTSET_REPERTORY (fontset
)
527 = Fcons (Fcons (make_number (font_info
->font_idx
), repertory
),
528 FONTSET_REPERTORY (fontset
));
531 return font_info
->font_idx
;
534 static Lisp_Object fontset_find_font
P_ ((Lisp_Object
, int, struct face
*,
537 /* Return RFONT-DEF (vector) in the realized fontset FONTSET for the
538 character C. If the corresponding font is not yet opened, open it
539 (if FACE is not NULL) or return Qnil (if FACE is NULL).
540 If no proper font is found for C, return Qnil.
541 ID is a charset-id that must be preferred, or -1 meaning no
543 If FALLBACK if nonzero, search only fallback fonts. */
546 fontset_find_font (fontset
, c
, face
, id
, fallback
)
552 Lisp_Object base_fontset
, elt
, vec
, font_def
;
555 FRAME_PTR f
= XFRAME (FONTSET_FRAME (fontset
));
557 base_fontset
= FONTSET_BASE (fontset
);
559 vec
= CHAR_TABLE_REF (fontset
, c
);
561 vec
= FONTSET_FALLBACK (fontset
);
564 /* We have not yet decided a font for C. */
570 elt
= FONTSET_REF_AND_RANGE (base_fontset
, c
, from
, to
);
572 elt
= FONTSET_FALLBACK (base_fontset
);
573 range
= Fcons (make_number (from
), make_number (to
));
576 /* Qt means we have no font for characters of this range. */
581 /* Build a vector [ -1 -1 nil NEW-ELT0 NEW-ELT1 NEW-ELT2 ... ],
582 where the first -1 is to force reordering of NEW-ELTn,
583 NEW-ELTn is [nil nil AREF (elt, n) nil]. */
584 #ifdef USE_FONT_BACKEND
586 && enable_font_backend
587 && EQ (base_fontset
, Vdefault_fontset
))
588 /* Extra one element is for an automatically added
589 font-def specifying only a script. */
590 vec
= Fmake_vector (make_number (ASIZE (elt
) + 4), Qnil
);
592 #endif /* not USE_FONT_BACKEND */
593 vec
= Fmake_vector (make_number (ASIZE (elt
) + 3), Qnil
);
594 ASET (vec
, 0, make_number (-1));
595 ASET (vec
, 1, make_number (-1));
596 for (i
= 0; i
< ASIZE (elt
); i
++)
600 tmp
= Fmake_vector (make_number (5), Qnil
);
601 ASET (tmp
, 2, AREF (elt
, i
));
602 ASET (vec
, 3 + i
, tmp
);
604 #ifdef USE_FONT_BACKEND
606 && enable_font_backend
607 && EQ (base_fontset
, Vdefault_fontset
))
609 Lisp_Object script
, font_spec
;
611 script
= CHAR_TABLE_REF (Vchar_script_table
, c
);
613 script
= intern ("latin");
614 font_spec
= Ffont_spec (0, NULL
);
615 ASET (font_spec
, FONT_REGISTRY_INDEX
, Qiso10646_1
);
616 ASET (font_spec
, FONT_EXTRA_INDEX
,
617 Fcons (Fcons (QCscript
, script
), Qnil
));
618 font_def
= Fmake_vector (make_number (3), Qnil
);
619 ASET (font_def
, 0, font_spec
);
620 elt
= Fmake_vector (make_number (5), Qnil
);
621 ASET (elt
, 2, font_def
);
622 ASET (vec
, 3 + i
, elt
);
624 #endif /* USE_FONT_BACKEND */
626 /* Then store it in the fontset. */
628 FONTSET_SET (fontset
, range
, vec
);
630 FONTSET_FALLBACK (fontset
) = vec
;
636 if (XINT (AREF (vec
, 0)) != charset_ordered_list_tick
)
637 /* The priority of charsets is changed after we selected a face
639 reorder_font_vector (vec
);
643 else if (id
== XFASTINT (AREF (vec
, 1)))
647 ASET (vec
, 1, make_number (id
));
648 for (i
= 3; i
< ASIZE (vec
); i
++)
649 if (id
== XFASTINT (AREF (AREF (AREF (vec
, i
), 2), 1)))
653 ASET (vec
, 2, AREF (vec
, i
));
663 /* Find the first available font in the vector of RFONT-DEF. */
664 for (; i
< ASIZE (vec
); i
++)
669 /* ELT == [ FACE-ID FONT-INDEX FONT-DEF OPENED-FONT-NAME ] */
670 if (INTEGERP (AREF (elt
, 1)) && XINT (AREF (elt
, 1)) < 0)
671 /* We couldn't open this font last time. */
674 if (!face
&& NILP (AREF (elt
, 1)))
675 /* We have not yet opened the font. */
678 font_def
= AREF (elt
, 2);
679 /* FONT_DEF == [ FONT-SPEC ENCODING REPERTORY ] */
681 #ifdef USE_FONT_BACKEND
682 if (enable_font_backend
)
684 /* ELT == [ FACE-ID FONT-INDEX FONT-DEF FONT-ENTITY FONT-OBJECT ] */
685 Lisp_Object font_entity
= AREF (elt
, 3);
686 Lisp_Object font_object
= AREF (elt
, 4);
687 Lisp_Object font_spec
= AREF (font_def
, 0);
690 if (NILP (font_entity
))
692 if (! FONT_SPEC_P (font_spec
))
694 /* FONT_SPEC is FONT-NAME or (FAMILY . REGISTRY). */
695 font_spec
= Ffont_spec (0, NULL
);
696 if (STRINGP (AREF (font_def
, 0)))
697 font_merge_old_spec (AREF (font_def
, 0), Qnil
, Qnil
,
701 Lisp_Object family
= AREF (AREF (font_def
, 0), 0);
702 Lisp_Object registry
= AREF (AREF (font_def
, 0), 5);;
704 font_merge_old_spec (Qnil
, family
, registry
, font_spec
);
706 ASET (font_def
, 0, font_spec
);
708 font_entity
= font_find_for_lface (f
, face
->lface
, font_spec
);
709 ASET (elt
, 3, font_entity
);
710 if (NILP (font_entity
))
712 ASET (elt
, 1, make_number (-1));
717 has_char
= font_has_char (f
, font_entity
, c
);
720 if (NILP (font_object
))
722 font_object
= font_open_for_lface (f
, font_entity
,
723 face
->lface
, font_spec
);
724 ASET (elt
, 4, font_object
);
725 if (NILP (font_object
))
727 ASET (elt
, 1, make_number (-1));
731 ASET (elt
, 1, make_number (0));
732 ASET (elt
, 4, font_object
);
734 && font_encode_char (font_object
, c
) == FONT_INVALID_CODE
)
738 #endif /* USE_FONT_BACKEND */
740 if (INTEGERP (AREF (font_def
, 2)))
742 /* The repertory is specified by charset ID. */
743 struct charset
*charset
744 = CHARSET_FROM_ID (XINT (AREF (font_def
, 2)));
746 if (! CHAR_CHARSET_P (c
, charset
))
747 /* This font can't display C. */
750 else if (CHAR_TABLE_P (AREF (font_def
, 2)))
752 /* The repertory is specified by a char table. */
753 if (NILP (CHAR_TABLE_REF (AREF (font_def
, 2), c
)))
754 /* This font can't display C. */
761 if (! INTEGERP (AREF (elt
, 1)))
763 /* We have not yet opened a font matching this spec.
764 Open the best matching font now and register the
766 struct font_info
*font_info
;
768 font_idx
= load_font_get_repertory (f
, face
, font_def
, fontset
);
769 ASET (elt
, 1, make_number (font_idx
));
771 /* This means that we couldn't find a font matching
774 font_info
= (*get_font_info_func
) (f
, font_idx
);
775 ASET (elt
, 3, build_string (font_info
->full_name
));
778 slot
= Fassq (AREF (elt
, 1), FONTSET_REPERTORY (fontset
));
779 xassert (CONSP (slot
));
780 if (NILP (CHAR_TABLE_REF (XCDR (slot
), c
)))
781 /* This font can't display C. */
785 /* Now we have decided to use this font spec to display C. */
786 if (! INTEGERP (AREF (elt
, 1)))
788 /* But not yet opened the best matching font. */
789 struct font_info
*font_info
;
791 font_idx
= load_font_get_repertory (f
, face
, font_def
, fontset
);
792 ASET (elt
, 1, make_number (font_idx
));
794 /* Can't open it. Try the other one. */
796 font_info
= (*get_font_info_func
) (f
, font_idx
);
797 ASET (elt
, 3, build_string (font_info
->full_name
));
800 /* Now we have the opened font. */
808 fontset_font (fontset
, c
, face
, id
)
814 Lisp_Object rfont_def
;
815 Lisp_Object base_fontset
;
817 /* Try a font-group for C. */
818 rfont_def
= fontset_find_font (fontset
, c
, face
, id
, 0);
819 if (! NILP (rfont_def
))
821 base_fontset
= FONTSET_BASE (fontset
);
822 /* Try a font-group for C of the default fontset. */
823 if (! EQ (base_fontset
, Vdefault_fontset
))
825 if (NILP (FONTSET_DEFAULT (fontset
)))
826 FONTSET_DEFAULT (fontset
)
827 = make_fontset (FONTSET_FRAME (fontset
), Qnil
, Vdefault_fontset
);
828 rfont_def
= fontset_find_font (FONTSET_DEFAULT (fontset
), c
, face
, id
, 0);
830 if (! NILP (rfont_def
))
832 /* Try a fallback font-group. */
833 rfont_def
= fontset_find_font (fontset
, c
, face
, id
, 1);
834 if (! NILP (rfont_def
))
836 /* Try a fallback font-group of the default fontset . */
837 if (! EQ (base_fontset
, Vdefault_fontset
))
838 rfont_def
= fontset_find_font (FONTSET_DEFAULT (fontset
), c
, face
, id
, 1);
842 /* Return a newly created fontset with NAME. If BASE is nil, make a
843 base fontset. Otherwise make a realized fontset whose base is
847 make_fontset (frame
, name
, base
)
848 Lisp_Object frame
, name
, base
;
851 int size
= ASIZE (Vfontset_table
);
852 int id
= next_fontset_id
;
854 /* Find a free slot in Vfontset_table. Usually, next_fontset_id is
855 the next available fontset ID. So it is expected that this loop
856 terminates quickly. In addition, as the last element of
857 Vfontset_table is always nil, we don't have to check the range of
859 while (!NILP (AREF (Vfontset_table
, id
))) id
++;
863 /* We must grow Vfontset_table. */
867 tem
= Fmake_vector (make_number (size
+ 32), Qnil
);
868 for (i
= 0; i
< size
; i
++)
869 AREF (tem
, i
) = AREF (Vfontset_table
, i
);
870 Vfontset_table
= tem
;
873 fontset
= Fmake_char_table (Qfontset
, Qnil
);
875 FONTSET_ID (fontset
) = make_number (id
);
878 FONTSET_NAME (fontset
) = name
;
882 FONTSET_NAME (fontset
) = Qnil
;
883 FONTSET_FRAME (fontset
) = frame
;
884 FONTSET_BASE (fontset
) = base
;
887 ASET (Vfontset_table
, id
, fontset
);
888 next_fontset_id
= id
+ 1;
893 /* Set the ASCII font of the default fontset to FONTNAME if that is
896 set_default_ascii_font (fontname
)
897 Lisp_Object fontname
;
899 if (! STRINGP (FONTSET_ASCII (Vdefault_fontset
)))
901 int id
= fs_query_fontset (fontname
, 2);
904 fontname
= FONTSET_ASCII (FONTSET_FROM_ID (id
));
905 FONTSET_ASCII (Vdefault_fontset
)= fontname
;
910 /********** INTERFACES TO xfaces.c, xfns.c, and dispextern.h **********/
912 /* Return the name of the fontset who has ID. */
920 fontset
= FONTSET_FROM_ID (id
);
921 return FONTSET_NAME (fontset
);
925 /* Return the ASCII font name of the fontset who has ID. */
931 Lisp_Object fontset
, elt
;
933 fontset
= FONTSET_FROM_ID (id
);
934 elt
= FONTSET_ASCII (fontset
);
935 #ifdef USE_FONT_BACKEND
938 #endif /* USE_FONT_BACKEND */
939 /* It is assured that ELT is always a string (i.e. fontname
945 /* Free fontset of FACE defined on frame F. Called from
946 free_realized_face. */
949 free_face_fontset (f
, face
)
955 fontset
= AREF (Vfontset_table
, face
->fontset
);
956 xassert (!NILP (fontset
) && ! BASE_FONTSET_P (fontset
));
957 xassert (f
== XFRAME (FONTSET_FRAME (fontset
)));
958 ASET (Vfontset_table
, face
->fontset
, Qnil
);
959 if (face
->fontset
< next_fontset_id
)
960 next_fontset_id
= face
->fontset
;
961 if (! NILP (FONTSET_DEFAULT (fontset
)))
963 int id
= XINT (FONTSET_ID (FONTSET_DEFAULT (fontset
)));
965 fontset
= AREF (Vfontset_table
, id
);
966 xassert (!NILP (fontset
) && ! BASE_FONTSET_P (fontset
));
967 xassert (f
== XFRAME (FONTSET_FRAME (fontset
)));
968 ASET (Vfontset_table
, id
, Qnil
);
969 if (id
< next_fontset_id
)
970 next_fontset_id
= face
->fontset
;
975 /* Return 1 if FACE is suitable for displaying character C.
976 Otherwise return 0. Called from the macro FACE_SUITABLE_FOR_CHAR_P
977 when C is not an ASCII character. */
980 face_suitable_for_char_p (face
, c
)
984 Lisp_Object fontset
, rfont_def
;
986 fontset
= FONTSET_FROM_ID (face
->fontset
);
987 rfont_def
= fontset_font (fontset
, c
, NULL
, -1);
988 return (VECTORP (rfont_def
)
989 && INTEGERP (AREF (rfont_def
, 0))
990 && face
->id
== XINT (AREF (rfont_def
, 0)));
994 /* Return ID of face suitable for displaying character C on frame F.
995 FACE must be reazlied for ASCII characters in advance. Called from
996 the macro FACE_FOR_CHAR. */
999 face_for_char (f
, face
, c
, pos
, object
)
1005 Lisp_Object fontset
, charset
, rfont_def
;
1009 if (ASCII_CHAR_P (c
))
1010 return face
->ascii_face
->id
;
1012 xassert (fontset_id_valid_p (face
->fontset
));
1013 fontset
= FONTSET_FROM_ID (face
->fontset
);
1014 xassert (!BASE_FONTSET_P (fontset
));
1019 charset
= Fget_char_property (make_number (pos
), Qcharset
, object
);
1022 else if (CHARSETP (charset
))
1023 id
= XINT (CHARSET_SYMBOL_ID (charset
));
1025 rfont_def
= fontset_font (fontset
, c
, face
, id
);
1026 if (VECTORP (rfont_def
))
1028 #ifdef USE_FONT_BACKEND
1029 if (enable_font_backend
1030 && NILP (AREF (rfont_def
, 0)))
1032 struct font
*font
= XSAVE_VALUE (AREF (rfont_def
, 4))->pointer
;
1034 face_id
= face_for_font (f
, font
, face
);
1035 ASET (rfont_def
, 0, make_number (face_id
));
1038 #endif /* USE_FONT_BACKEND */
1039 if (NILP (AREF (rfont_def
, 0)))
1041 /* We have not yet made a realized face that uses this font. */
1042 int font_idx
= XINT (AREF (rfont_def
, 1));
1044 face_id
= lookup_non_ascii_face (f
, font_idx
, face
);
1045 ASET (rfont_def
, 0, make_number (face_id
));
1047 return XINT (AREF (rfont_def
, 0));
1050 if (NILP (FONTSET_NOFONT_FACE (fontset
)))
1052 face_id
= lookup_non_ascii_face (f
, -1, face
);
1053 FONTSET_NOFONT_FACE (fontset
) = make_number (face_id
);
1055 return XINT (FONTSET_NOFONT_FACE (fontset
));
1059 /* Make a realized fontset for ASCII face FACE on frame F from the
1060 base fontset BASE_FONTSET_ID. If BASE_FONTSET_ID is -1, use the
1061 default fontset as the base. Value is the id of the new fontset.
1062 Called from realize_x_face. */
1065 make_fontset_for_ascii_face (f
, base_fontset_id
, face
)
1067 int base_fontset_id
;
1070 Lisp_Object base_fontset
, fontset
, frame
;
1072 XSETFRAME (frame
, f
);
1073 if (base_fontset_id
>= 0)
1075 base_fontset
= FONTSET_FROM_ID (base_fontset_id
);
1076 if (!BASE_FONTSET_P (base_fontset
))
1077 base_fontset
= FONTSET_BASE (base_fontset
);
1078 xassert (BASE_FONTSET_P (base_fontset
));
1079 if (! BASE_FONTSET_P (base_fontset
))
1083 base_fontset
= Vdefault_fontset
;
1085 fontset
= make_fontset (frame
, Qnil
, base_fontset
);
1087 Lisp_Object elt
, rfont_def
, val
;
1089 elt
= FONTSET_REF (base_fontset
, 0);
1090 xassert (VECTORP (elt
) && ASIZE (elt
) > 0);
1091 #ifdef USE_FONT_BACKEND
1092 rfont_def
= Fmake_vector (make_number (5), Qnil
);
1093 if (enable_font_backend
&& face
->font_info
)
1095 struct font
*font
= (struct font
*) face
->font_info
;
1097 ASET (rfont_def
, 3, font
->entity
);
1098 ASET (rfont_def
, 4, font_find_object (font
));
1101 #endif /* USE_FONT_BACKEND */
1103 rfont_def
= Fmake_vector (make_number (4), Qnil
);
1104 ASET (rfont_def
, 3, build_string (face
->font_name
));
1106 ASET (rfont_def
, 1, make_number (face
->font_info_id
));
1107 ASET (rfont_def
, 2, AREF (elt
, 0));
1108 elt
= Fmake_vector (make_number (4), Qnil
);
1109 ASET (elt
, 0, make_number (charset_ordered_list_tick
));
1110 ASET (elt
, 1, make_number (charset_ascii
));
1111 ASET (elt
, 2, rfont_def
);
1112 ASET (elt
, 3, rfont_def
);
1114 val
= Fcons (Qlatin
, Qnil
);
1115 map_char_table (accumulate_script_ranges
, Qnil
, Vchar_script_table
, val
);
1116 for (val
= XCDR (val
); CONSP (val
); val
= XCDR (val
))
1117 char_table_set_range (fontset
, XINT (XCAR (XCAR (val
))),
1118 XINT (XCDR (XCAR (val
))), elt
);
1119 FONTSET_FALLBACK (fontset
) = elt
;
1121 return XINT (FONTSET_ID (fontset
));
1125 #if defined(WINDOWSNT) && defined (_MSC_VER)
1126 #pragma optimize("", off)
1129 /* Load a font named FONTNAME on frame F. Return a pointer to the
1130 struct font_info of the loaded font. If loading fails, return
1131 NULL. CHARSET is an ID of charset to encode characters for this
1132 font. If it is -1, find one from Vfont_encoding_alist. */
1135 fs_load_font (f
, fontname
, charset
)
1140 struct font_info
*fontp
;
1141 Lisp_Object fullname
;
1144 /* No way to get fontname. */
1147 fontp
= (*load_font_func
) (f
, fontname
, 0);
1148 if (! fontp
|| fontp
->charset
>= 0)
1151 fontname
= fontp
->full_name
;
1152 fullname
= build_string (fontp
->full_name
);
1156 Lisp_Object charset_symbol
;
1158 charset_symbol
= find_font_encoding (fullname
);
1159 if (CONSP (charset_symbol
))
1160 charset_symbol
= XCAR (charset_symbol
);
1161 if (NILP (charset_symbol
))
1162 charset_symbol
= Qascii
;
1163 charset
= XINT (CHARSET_SYMBOL_ID (charset_symbol
));
1165 fontp
->charset
= charset
;
1166 fontp
->vertical_centering
= 0;
1167 fontp
->font_encoder
= NULL
;
1169 if (charset
!= charset_ascii
)
1171 fontp
->vertical_centering
1172 = (STRINGP (Vvertical_centering_font_regexp
)
1173 && (fast_string_match_ignore_case
1174 (Vvertical_centering_font_regexp
, fullname
) >= 0));
1176 if (find_ccl_program_func
)
1177 (*find_ccl_program_func
) (fontp
);
1183 #if defined(WINDOWSNT) && defined (_MSC_VER)
1184 #pragma optimize("", on)
1188 /* Return ENCODING or a cons of ENCODING and REPERTORY of the font
1189 FONTNAME. ENCODING is a charset symbol that specifies the encoding
1190 of the font. REPERTORY is a charset symbol or nil. */
1194 find_font_encoding (fontname
)
1195 Lisp_Object fontname
;
1197 Lisp_Object tail
, elt
;
1199 for (tail
= Vfont_encoding_alist
; CONSP (tail
); tail
= XCDR (tail
))
1203 && STRINGP (XCAR (elt
))
1204 && fast_string_match_ignore_case (XCAR (elt
), fontname
) >= 0
1205 && (SYMBOLP (XCDR (elt
))
1206 ? CHARSETP (XCDR (elt
))
1207 : CONSP (XCDR (elt
)) && CHARSETP (XCAR (XCDR (elt
)))))
1208 return (XCDR (elt
));
1210 /* We don't know the encoding of this font. Let's assume `ascii'. */
1215 /* Cache data used by fontset_pattern_regexp. The car part is a
1216 pattern string containing at least one wild card, the cdr part is
1217 the corresponding regular expression. */
1218 static Lisp_Object Vcached_fontset_data
;
1220 #define CACHED_FONTSET_NAME (SDATA (XCAR (Vcached_fontset_data)))
1221 #define CACHED_FONTSET_REGEX (XCDR (Vcached_fontset_data))
1223 /* If fontset name PATTERN contains any wild card, return regular
1224 expression corresponding to PATTERN. */
1227 fontset_pattern_regexp (pattern
)
1228 Lisp_Object pattern
;
1230 if (!index (SDATA (pattern
), '*')
1231 && !index (SDATA (pattern
), '?'))
1232 /* PATTERN does not contain any wild cards. */
1235 if (!CONSP (Vcached_fontset_data
)
1236 || strcmp (SDATA (pattern
), CACHED_FONTSET_NAME
))
1238 /* We must at first update the cached data. */
1239 unsigned char *regex
, *p0
, *p1
;
1240 int ndashes
= 0, nstars
= 0;
1242 for (p0
= SDATA (pattern
); *p0
; p0
++)
1246 else if (*p0
== '*')
1250 /* If PATTERN is not full XLFD we conert "*" to ".*". Otherwise
1251 we convert "*" to "[^-]*" which is much faster in regular
1252 expression matching. */
1254 p1
= regex
= (unsigned char *) alloca (SBYTES (pattern
) + 2 * nstars
+ 1);
1256 p1
= regex
= (unsigned char *) alloca (SBYTES (pattern
) + 5 * nstars
+ 1);
1259 for (p0
= SDATA (pattern
); *p0
; p0
++)
1266 *p1
++ = '[', *p1
++ = '^', *p1
++ = '-', *p1
++ = ']';
1269 else if (*p0
== '?')
1277 Vcached_fontset_data
= Fcons (build_string (SDATA (pattern
)),
1278 build_string (regex
));
1281 return CACHED_FONTSET_REGEX
;
1284 /* Return ID of the base fontset named NAME. If there's no such
1285 fontset, return -1. NAME_PATTERN specifies how to treat NAME as this:
1286 0: pattern containing '*' and '?' as wildcards
1287 1: regular expression
1288 2: literal fontset name
1292 fs_query_fontset (name
, name_pattern
)
1299 name
= Fdowncase (name
);
1300 if (name_pattern
!= 1)
1302 tem
= Frassoc (name
, Vfontset_alias_alist
);
1304 tem
= Fassoc (name
, Vfontset_alias_alist
);
1305 if (CONSP (tem
) && STRINGP (XCAR (tem
)))
1307 else if (name_pattern
== 0)
1309 tem
= fontset_pattern_regexp (name
);
1318 for (i
= 0; i
< ASIZE (Vfontset_table
); i
++)
1320 Lisp_Object fontset
, this_name
;
1322 fontset
= FONTSET_FROM_ID (i
);
1324 || !BASE_FONTSET_P (fontset
))
1327 this_name
= FONTSET_NAME (fontset
);
1328 if (name_pattern
== 1
1329 ? fast_string_match (name
, this_name
) >= 0
1330 : !strcmp (SDATA (name
), SDATA (this_name
)))
1337 DEFUN ("query-fontset", Fquery_fontset
, Squery_fontset
, 1, 2, 0,
1338 doc
: /* Return the name of a fontset that matches PATTERN.
1339 The value is nil if there is no matching fontset.
1340 PATTERN can contain `*' or `?' as a wildcard
1341 just as X font name matching algorithm allows.
1342 If REGEXPP is non-nil, PATTERN is a regular expression. */)
1344 Lisp_Object pattern
, regexpp
;
1346 Lisp_Object fontset
;
1349 (*check_window_system_func
) ();
1351 CHECK_STRING (pattern
);
1353 if (SCHARS (pattern
) == 0)
1356 id
= fs_query_fontset (pattern
, !NILP (regexpp
));
1360 fontset
= FONTSET_FROM_ID (id
);
1361 return FONTSET_NAME (fontset
);
1364 /* Return a list of base fontset names matching PATTERN on frame F. */
1367 list_fontsets (f
, pattern
, size
)
1369 Lisp_Object pattern
;
1372 Lisp_Object frame
, regexp
, val
;
1375 XSETFRAME (frame
, f
);
1377 regexp
= fontset_pattern_regexp (pattern
);
1380 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
1382 Lisp_Object fontset
, name
;
1384 fontset
= FONTSET_FROM_ID (id
);
1386 || !BASE_FONTSET_P (fontset
)
1387 || !EQ (frame
, FONTSET_FRAME (fontset
)))
1389 name
= FONTSET_NAME (fontset
);
1391 if (STRINGP (regexp
)
1392 ? (fast_string_match (regexp
, name
) < 0)
1393 : strcmp (SDATA (pattern
), SDATA (name
)))
1396 val
= Fcons (Fcopy_sequence (FONTSET_NAME (fontset
)), val
);
1403 /* Free all realized fontsets whose base fontset is BASE. */
1406 free_realized_fontsets (base
)
1412 /* For the moment, this doesn't work because free_realized_face
1413 doesn't remove FACE from a cache. Until we find a solution, we
1414 suppress this code, and simply use Fclear_face_cache even though
1415 that is not efficient. */
1417 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
1419 Lisp_Object
this = AREF (Vfontset_table
, id
);
1421 if (EQ (FONTSET_BASE (this), base
))
1425 for (tail
= FONTSET_FACE_ALIST (this); CONSP (tail
);
1428 FRAME_PTR f
= XFRAME (FONTSET_FRAME (this));
1429 int face_id
= XINT (XCDR (XCAR (tail
)));
1430 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1432 /* Face THIS itself is also freed by the following call. */
1433 free_realized_face (f
, face
);
1439 /* But, we don't have to call Fclear_face_cache if no fontset has
1440 been realized from BASE. */
1441 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
1443 Lisp_Object
this = AREF (Vfontset_table
, id
);
1445 if (CHAR_TABLE_P (this) && EQ (FONTSET_BASE (this), base
))
1447 Fclear_face_cache (Qt
);
1455 /* Check validity of NAME as a fontset name and return the
1456 corresponding fontset. If not valid, signal an error.
1457 If NAME is t, return Vdefault_fontset. */
1460 check_fontset_name (name
)
1466 return Vdefault_fontset
;
1468 CHECK_STRING (name
);
1469 /* First try NAME as literal. */
1470 id
= fs_query_fontset (name
, 2);
1472 /* For backward compatibility, try again NAME as pattern. */
1473 id
= fs_query_fontset (name
, 0);
1475 error ("Fontset `%s' does not exist", SDATA (name
));
1476 return FONTSET_FROM_ID (id
);
1480 accumulate_script_ranges (arg
, range
, val
)
1481 Lisp_Object arg
, range
, val
;
1483 if (EQ (XCAR (arg
), val
))
1486 XSETCDR (arg
, Fcons (Fcons (XCAR (range
), XCDR (range
)), XCDR (arg
)));
1488 XSETCDR (arg
, Fcons (Fcons (range
, range
), XCDR (arg
)));
1493 /* Return an ASCII font name generated from fontset name NAME and
1494 ASCII font specification ASCII_SPEC. NAME is a string conforming
1495 to XLFD. ASCII_SPEC is a vector:
1496 [FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY]. */
1498 static INLINE Lisp_Object
1499 generate_ascii_font_name (name
, ascii_spec
)
1500 Lisp_Object name
, ascii_spec
;
1505 vec
= split_font_name_into_vector (name
);
1506 for (i
= FONT_SPEC_FAMILY_INDEX
; i
<= FONT_SPEC_ADSTYLE_INDEX
; i
++)
1507 if (! NILP (AREF (ascii_spec
, i
)))
1508 ASET (vec
, 1 + i
, AREF (ascii_spec
, i
));
1509 if (! NILP (AREF (ascii_spec
, FONT_SPEC_REGISTRY_INDEX
)))
1510 ASET (vec
, 12, AREF (ascii_spec
, FONT_SPEC_REGISTRY_INDEX
));
1511 return build_font_name_from_vector (vec
);
1514 /* Variables referred in set_fontset_font. They are set before
1515 map_charset_chars is called in Fset_fontset_font. */
1516 static Lisp_Object font_def_arg
, add_arg
;
1517 static int from_arg
, to_arg
;
1519 /* Callback function for map_charset_chars in Fset_fontset_font. In
1520 FONTSET, set font_def_arg in a fashion specified by add_arg for
1521 characters in RANGE while ignoring the range between from_arg and
1525 set_fontset_font (fontset
, range
)
1526 Lisp_Object fontset
, range
;
1528 if (from_arg
< to_arg
)
1530 int from
= XINT (XCAR (range
)), to
= XINT (XCDR (range
));
1532 if (from
< from_arg
)
1538 range2
= Fcons (make_number (to_arg
), XCDR (range
));
1539 FONTSET_ADD (fontset
, range
, font_def_arg
, add_arg
);
1543 range
= Fcons (XCAR (range
), make_number (from_arg
));
1545 else if (to
<= to_arg
)
1550 range
= Fcons (make_number (to_arg
), XCDR (range
));
1553 FONTSET_ADD (fontset
, range
, font_def_arg
, add_arg
);
1557 DEFUN ("set-fontset-font", Fset_fontset_font
, Sset_fontset_font
, 3, 5, 0,
1559 Modify fontset NAME to use FONT-SPEC for TARGET characters.
1561 TARGET may be a cons; (FROM . TO), where FROM and TO are characters.
1562 In that case, use FONT-SPEC for all characters in the range FROM and
1565 TARGET may be a script name symbol. In that case, use FONT-SPEC for
1566 all characters that belong to the script.
1568 TARGET may be a charset. In that case, use FONT-SPEC for all
1569 characters in the charset.
1571 TARGET may be nil. In that case, use FONT-SPEC for any characters for
1572 that no FONT-SPEC is specified.
1574 FONT-SPEC may one of these:
1575 * A cons (FAMILY . REGISTRY), where FAMILY is a font family name and
1576 REGISTRY is a font registry name. FAMILY may contains foundry
1577 name, and REGISTRY may contains encoding name.
1578 * A font name string.
1580 Optional 4th argument FRAME, if non-nil, is a frame. This argument is
1581 kept for backward compatibility and has no meaning.
1583 Optional 5th argument ADD, if non-nil, specifies how to add FONT-SPEC
1584 to the font specifications for TARGET previously set. If it is
1585 `prepend', FONT-SPEC is prepended. If it is `append', FONT-SPEC is
1586 appended. By default, FONT-SPEC overrides the previous settings. */)
1587 (name
, target
, font_spec
, frame
, add
)
1588 Lisp_Object name
, target
, font_spec
, frame
, add
;
1590 Lisp_Object fontset
;
1591 Lisp_Object font_def
, registry
, family
;
1592 Lisp_Object encoding
, repertory
;
1593 Lisp_Object range_list
;
1594 struct charset
*charset
= NULL
;
1596 fontset
= check_fontset_name (name
);
1598 /* The arg FRAME is kept for backward compatibility. We only check
1601 CHECK_LIVE_FRAME (frame
);
1603 if (VECTORP (font_spec
))
1605 /* FONT_SPEC should have this form:
1606 [ FAMILY WEIGHT SLANT WIDTH ADSTYLE REGISTRY ]
1607 This is a feature not yet documented because WEIGHT thru
1608 ADSTYLE are ignored for the moment. */
1611 if (ASIZE (font_spec
) != FONT_SPEC_MAX_INDEX
)
1612 args_out_of_range (make_number (FONT_SPEC_MAX_INDEX
),
1613 make_number (ASIZE (font_spec
)));
1615 font_spec
= Fcopy_sequence (font_spec
);
1616 for (j
= 0; j
< FONT_SPEC_MAX_INDEX
- 1; j
++)
1617 if (! NILP (AREF (font_spec
, j
)))
1619 CHECK_STRING (AREF (font_spec
, j
));
1620 ASET (font_spec
, j
, Fdowncase (AREF (font_spec
, j
)));
1622 family
= AREF (font_spec
, FONT_SPEC_FAMILY_INDEX
);
1623 /* REGISTRY should not be omitted. */
1624 CHECK_STRING (AREF (font_spec
, FONT_SPEC_REGISTRY_INDEX
));
1625 registry
= AREF (font_spec
, FONT_SPEC_REGISTRY_INDEX
);
1627 else if (CONSP (font_spec
))
1629 family
= XCAR (font_spec
);
1630 registry
= XCDR (font_spec
);
1632 if (! NILP (family
))
1634 CHECK_STRING (family
);
1635 family
= Fdowncase (family
);
1637 CHECK_STRING (registry
);
1638 registry
= Fdowncase (registry
);
1639 font_spec
= Fmake_vector (make_number (FONT_SPEC_MAX_INDEX
), Qnil
);
1640 ASET (font_spec
, FONT_SPEC_FAMILY_INDEX
, family
);
1641 ASET (font_spec
, FONT_SPEC_REGISTRY_INDEX
, registry
);
1645 CHECK_STRING (font_spec
);
1646 font_spec
= Fdowncase (font_spec
);
1649 if (STRINGP (font_spec
))
1650 encoding
= find_font_encoding (font_spec
);
1652 encoding
= find_font_encoding (concat2 (family
, registry
));
1653 if (NILP (encoding
))
1656 if (SYMBOLP (encoding
))
1658 CHECK_CHARSET (encoding
);
1659 encoding
= repertory
= CHARSET_SYMBOL_ID (encoding
);
1663 repertory
= XCDR (encoding
);
1664 encoding
= XCAR (encoding
);
1665 CHECK_CHARSET (encoding
);
1666 encoding
= CHARSET_SYMBOL_ID (encoding
);
1667 if (! NILP (repertory
) && SYMBOLP (repertory
))
1669 CHECK_CHARSET (repertory
);
1670 repertory
= CHARSET_SYMBOL_ID (repertory
);
1673 font_def
= Fmake_vector (make_number (3), font_spec
);
1674 ASET (font_def
, 1, encoding
);
1675 ASET (font_def
, 2, repertory
);
1677 if (CHARACTERP (target
))
1678 range_list
= Fcons (Fcons (target
, target
), Qnil
);
1679 else if (CONSP (target
))
1681 Lisp_Object from
, to
;
1683 from
= Fcar (target
);
1685 CHECK_CHARACTER (from
);
1686 CHECK_CHARACTER (to
);
1687 range_list
= Fcons (target
, Qnil
);
1689 else if (SYMBOLP (target
) && !NILP (target
))
1691 Lisp_Object script_list
;
1695 script_list
= XCHAR_TABLE (Vchar_script_table
)->extras
[0];
1696 if (! NILP (Fmemq (target
, script_list
)))
1698 val
= Fcons (target
, Qnil
);
1699 map_char_table (accumulate_script_ranges
, Qnil
, Vchar_script_table
,
1701 range_list
= XCDR (val
);
1702 if (EQ (target
, Qlatin
))
1704 if (VECTORP (font_spec
))
1705 val
= generate_ascii_font_name (FONTSET_NAME (fontset
),
1709 FONTSET_ASCII (fontset
) = val
;
1712 if (CHARSETP (target
))
1714 if (EQ (target
, Qascii
))
1716 if (VECTORP (font_spec
))
1717 font_spec
= generate_ascii_font_name (FONTSET_NAME (fontset
),
1719 FONTSET_ASCII (fontset
) = font_spec
;
1720 range_list
= Fcons (Fcons (make_number (0), make_number (127)),
1725 CHECK_CHARSET_GET_CHARSET (target
, charset
);
1728 else if (NILP (range_list
))
1729 error ("Invalid script or charset name: %s",
1730 SDATA (SYMBOL_NAME (target
)));
1732 else if (NILP (target
))
1733 range_list
= Fcons (Qnil
, Qnil
);
1735 error ("Invalid target for setting a font");
1740 font_def_arg
= font_def
;
1742 if (NILP (range_list
))
1743 from_arg
= to_arg
= 0;
1745 from_arg
= XINT (XCAR (XCAR (range_list
))),
1746 to_arg
= XINT (XCDR (XCAR (range_list
)));
1748 map_charset_chars (set_fontset_font
, Qnil
, fontset
, charset
,
1749 CHARSET_MIN_CODE (charset
),
1750 CHARSET_MAX_CODE (charset
));
1752 for (; CONSP (range_list
); range_list
= XCDR (range_list
))
1753 FONTSET_ADD (fontset
, XCAR (range_list
), font_def
, add
);
1755 /* Free all realized fontsets whose base is FONTSET. This way, the
1756 specified character(s) are surely redisplayed by a correct
1758 free_realized_fontsets (fontset
);
1764 DEFUN ("new-fontset", Fnew_fontset
, Snew_fontset
, 2, 2, 0,
1765 doc
: /* Create a new fontset NAME from font information in FONTLIST.
1767 FONTLIST is an alist of scripts vs the corresponding font specification list.
1768 Each element of FONTLIST has the form (SCRIPT FONT-SPEC ...), where a
1769 character of SCRIPT is displayed by a font that matches one of
1772 SCRIPT is a symbol that appears in the first extra slot of the
1773 char-table `char-script-table'.
1775 FONT-SPEC is a vector, a cons, or a string. See the documentation of
1776 `set-fontset-font' for the meaning. */)
1778 Lisp_Object name
, fontlist
;
1780 Lisp_Object fontset
;
1784 CHECK_STRING (name
);
1785 CHECK_LIST (fontlist
);
1787 id
= fs_query_fontset (name
, 0);
1790 name
= Fdowncase (name
);
1791 val
= split_font_name_into_vector (name
);
1792 if (NILP (val
) || NILP (AREF (val
, 12)) || NILP (AREF (val
, 13)))
1793 error ("Fontset name must be in XLFD format");
1794 if (strcmp (SDATA (AREF (val
, 12)), "fontset"))
1795 error ("Registry field of fontset name must be \"fontset\"");
1796 Vfontset_alias_alist
1797 = Fcons (Fcons (name
,
1798 concat2 (concat2 (AREF (val
, 12), build_string ("-")),
1800 Vfontset_alias_alist
);
1801 ASET (val
, 12, build_string ("iso8859-1"));
1802 fontset
= make_fontset (Qnil
, name
, Qnil
);
1803 FONTSET_ASCII (fontset
) = build_font_name_from_vector (val
);
1807 fontset
= FONTSET_FROM_ID (id
);;
1808 free_realized_fontsets (fontset
);
1809 Fset_char_table_range (fontset
, Qt
, Qnil
);
1812 for (; ! NILP (fontlist
); fontlist
= Fcdr (fontlist
))
1814 Lisp_Object elt
, script
;
1816 elt
= Fcar (fontlist
);
1817 script
= Fcar (elt
);
1819 if (CONSP (elt
) && (NILP (XCDR (elt
)) || CONSP (XCDR (elt
))))
1820 for (; CONSP (elt
); elt
= XCDR (elt
))
1821 Fset_fontset_font (name
, script
, XCAR (elt
), Qnil
, Qappend
);
1823 Fset_fontset_font (name
, script
, elt
, Qnil
, Qappend
);
1829 /* Alist of automatically created fontsets. Each element is a cons
1830 (FONTNAME . FONTSET-ID). */
1831 static Lisp_Object auto_fontset_alist
;
1834 new_fontset_from_font_name (Lisp_Object fontname
)
1841 fontname
= Fdowncase (fontname
);
1842 val
= Fassoc (fontname
, auto_fontset_alist
);
1844 return XINT (XCDR (val
));
1846 vec
= split_font_name_into_vector (fontname
);
1848 vec
= Fmake_vector (make_number (14), build_string (""));
1849 ASET (vec
, 12, build_string ("fontset"));
1850 if (NILP (auto_fontset_alist
))
1852 ASET (vec
, 13, build_string ("startup"));
1853 name
= build_font_name_from_vector (vec
);
1858 int len
= XINT (Flength (auto_fontset_alist
));
1860 sprintf (temp
, "auto%d", len
);
1861 ASET (vec
, 13, build_string (temp
));
1862 name
= build_font_name_from_vector (vec
);
1864 name
= Fnew_fontset (name
, list2 (list2 (Qascii
, fontname
),
1865 list2 (Fcons (make_number (0),
1866 make_number (MAX_CHAR
)),
1868 id
= fs_query_fontset (name
, 0);
1870 = Fcons (Fcons (fontname
, make_number (id
)), auto_fontset_alist
);
1874 #ifdef USE_FONT_BACKEND
1876 new_fontset_from_font (font_object
)
1877 Lisp_Object font_object
;
1879 Lisp_Object font_name
= font_get_name (font_object
);
1880 Lisp_Object font_spec
= font_get_spec (font_object
);
1881 Lisp_Object fontset_spec
, short_name
, name
, fontset
;
1883 if (NILP (auto_fontset_alist
))
1884 short_name
= build_string ("fontset-startup");
1888 int len
= XINT (Flength (auto_fontset_alist
));
1890 sprintf (temp
, "fontset-auto%d", len
);
1891 short_name
= build_string (temp
);
1893 fontset_spec
= Fcopy_sequence (font_spec
);
1894 ASET (fontset_spec
, FONT_REGISTRY_INDEX
, short_name
);
1895 name
= Ffont_xlfd_name (fontset_spec
);
1900 for (i
= 0; i
< FONT_SIZE_INDEX
; i
++)
1901 if ((i
!= FONT_FAMILY_INDEX
) && (i
!= FONT_REGISTRY_INDEX
))
1902 ASET (fontset_spec
, i
, Qnil
);
1903 name
= Ffont_xlfd_name (fontset_spec
);
1907 fontset
= make_fontset (Qnil
, name
, Qnil
);
1908 FONTSET_ASCII (fontset
) = font_name
;
1909 font_spec
= Fcons (SYMBOL_NAME (AREF (font_spec
, FONT_FAMILY_INDEX
)),
1910 SYMBOL_NAME (AREF (font_spec
, FONT_REGISTRY_INDEX
)));
1911 Fset_fontset_font (name
, Qlatin
, font_spec
, Qnil
, Qnil
);
1912 Fset_fontset_font (name
, Qnil
, font_spec
, Qnil
, Qnil
);
1913 return XINT (FONTSET_ID (fontset
));
1917 fontset_ascii_font (f
, id
)
1921 Lisp_Object fontset
= FONTSET_FROM_ID (id
);
1922 Lisp_Object ascii_slot
= FONTSET_ASCII (fontset
);
1923 Lisp_Object val
, font_object
;
1925 if (CONSP (ascii_slot
))
1927 Lisp_Object ascii_font_name
= XCAR (ascii_slot
);
1930 for (val
= XCDR (ascii_slot
); ! NILP (val
); val
= XCDR (val
))
1932 Lisp_Object frame
= font_get_frame (XCAR (val
));
1934 if (NILP (frame
) || XFRAME (frame
) == f
)
1936 font_object
= XCAR (val
);
1937 if (XSAVE_VALUE (font_object
)->integer
== 0)
1939 font_object
= font_open_by_name (f
, SDATA (ascii_font_name
));
1940 XSETCAR (val
, font_object
);
1945 if (NILP (font_object
))
1947 font_object
= font_open_by_name (f
, SDATA (ascii_font_name
));
1948 XSETCDR (ascii_slot
, Fcons (font_object
, XCDR (ascii_slot
)));
1953 font_object
= font_open_by_name (f
, SDATA (ascii_slot
));
1954 FONTSET_ASCII (fontset
) = Fcons (ascii_slot
, Fcons (font_object
, Qnil
));
1956 if (NILP (font_object
))
1958 return XSAVE_VALUE (font_object
)->pointer
;
1961 #endif /* USE_FONT_BACKEND */
1963 DEFUN ("font-info", Ffont_info
, Sfont_info
, 1, 2, 0,
1964 doc
: /* Return information about a font named NAME on frame FRAME.
1965 If FRAME is omitted or nil, use the selected frame.
1966 The returned value is a vector of OPENED-NAME, FULL-NAME, CHARSET, SIZE,
1967 HEIGHT, BASELINE-OFFSET, RELATIVE-COMPOSE, and DEFAULT-ASCENT,
1969 OPENED-NAME is the name used for opening the font,
1970 FULL-NAME is the full name of the font,
1971 SIZE is the maximum bound width of the font,
1972 HEIGHT is the height of the font,
1973 BASELINE-OFFSET is the upward offset pixels from ASCII baseline,
1974 RELATIVE-COMPOSE and DEFAULT-ASCENT are the numbers controlling
1975 how to compose characters.
1976 If the named font is not yet loaded, return nil. */)
1978 Lisp_Object name
, frame
;
1981 struct font_info
*fontp
;
1983 Lisp_Object font_object
;
1985 (*check_window_system_func
) ();
1987 CHECK_STRING (name
);
1988 name
= Fdowncase (name
);
1990 frame
= selected_frame
;
1991 CHECK_LIVE_FRAME (frame
);
1994 if (!query_font_func
)
1995 error ("Font query function is not supported");
1997 #ifdef USE_FONT_BACKEND
1998 if (enable_font_backend
)
2000 font_object
= font_open_by_name (f
, SDATA (name
));
2001 if (NILP (font_object
))
2004 fontp
= (struct font_info
*) XSAVE_VALUE (font_object
)->pointer
;
2007 #endif /* USE_FONT_BACKEND */
2008 fontp
= (*query_font_func
) (f
, SDATA (name
));
2012 info
= Fmake_vector (make_number (7), Qnil
);
2014 XVECTOR (info
)->contents
[0] = build_string (fontp
->name
);
2015 XVECTOR (info
)->contents
[1] = build_string (fontp
->full_name
);
2016 XVECTOR (info
)->contents
[2] = make_number (fontp
->size
);
2017 XVECTOR (info
)->contents
[3] = make_number (fontp
->height
);
2018 XVECTOR (info
)->contents
[4] = make_number (fontp
->baseline_offset
);
2019 XVECTOR (info
)->contents
[5] = make_number (fontp
->relative_compose
);
2020 XVECTOR (info
)->contents
[6] = make_number (fontp
->default_ascent
);
2022 #ifdef USE_FONT_BACKEND
2023 if (! NILP (font_object
))
2024 font_close_object (f
, font_object
);
2025 #endif /* USE_FONT_BACKEND */
2030 /* Return a cons (FONT-NAME . GLYPH-CODE).
2031 FONT-NAME is the font name for the character at POSITION in the current
2032 buffer. This is computed from all the text properties and overlays
2033 that apply to POSITION. POSTION may be nil, in which case,
2034 FONT-NAME is the font name for display the character CH with the
2037 GLYPH-CODE is the glyph code in the font to use for the character.
2039 If the 2nd optional arg CH is non-nil, it is a character to check
2040 the font instead of the character at POSITION.
2042 It returns nil in the following cases:
2044 (1) The window system doesn't have a font for the character (thus
2045 it is displayed by an empty box).
2047 (2) The character code is invalid.
2049 (3) If POSITION is not nil, and the current buffer is not displayed
2052 In addition, the returned font name may not take into account of
2053 such redisplay engine hooks as what used in jit-lock-mode if
2054 POSITION is currently not visible. */
2057 DEFUN ("internal-char-font", Finternal_char_font
, Sinternal_char_font
, 1, 2, 0,
2058 doc
: /* For internal use only. */)
2060 Lisp_Object position
, ch
;
2062 int pos
, pos_byte
, dummy
;
2067 Lisp_Object charset
, rfont_def
;
2070 if (NILP (position
))
2072 CHECK_CHARACTER (ch
);
2074 f
= XFRAME (selected_frame
);
2075 face_id
= DEFAULT_FACE_ID
;
2081 Lisp_Object window
, charset
;
2084 CHECK_NUMBER_COERCE_MARKER (position
);
2085 pos
= XINT (position
);
2086 if (pos
< BEGV
|| pos
>= ZV
)
2087 args_out_of_range_3 (position
, make_number (BEGV
), make_number (ZV
));
2088 pos_byte
= CHAR_TO_BYTE (pos
);
2090 c
= FETCH_CHAR (pos_byte
);
2096 window
= Fget_buffer_window (Fcurrent_buffer (), Qnil
);
2099 w
= XWINDOW (window
);
2100 f
= XFRAME (w
->frame
);
2101 face_id
= face_at_buffer_position (w
, pos
, -1, -1, &dummy
, pos
+ 100, 0);
2102 charset
= Fget_char_property (position
, Qcharset
, Qnil
);
2103 if (CHARSETP (charset
))
2104 cs_id
= XINT (CHARSET_SYMBOL_ID (charset
));
2108 if (! CHAR_VALID_P (c
, 0))
2110 face_id
= FACE_FOR_CHAR (f
, FACE_FROM_ID (f
, face_id
), c
, pos
, Qnil
);
2111 face
= FACE_FROM_ID (f
, face_id
);
2112 rfont_def
= fontset_font (FONTSET_FROM_ID (face
->fontset
), c
, face
, cs_id
);
2113 #ifdef USE_FONT_BACKEND
2114 if (enable_font_backend
)
2116 if (VECTORP (rfont_def
) && ! NILP (AREF (rfont_def
, 4)))
2118 Lisp_Object font_object
= AREF (rfont_def
, 4);
2119 struct font
*font
= XSAVE_VALUE (font_object
)->pointer
;
2120 unsigned code
= font
->driver
->encode_char (font
, c
);
2121 Lisp_Object fontname
= font_get_name (font_object
);
2123 if (code
== FONT_INVALID_CODE
)
2124 return Fcons (fontname
, Qnil
);
2125 if (code
<= MOST_POSITIVE_FIXNUM
)
2126 return Fcons (fontname
, make_number (code
));
2127 return Fcons (fontname
, Fcons (make_number (code
>> 16),
2128 make_number (code
& 0xFFFF)));
2132 #endif /* USE_FONT_BACKEND */
2133 if (VECTORP (rfont_def
) && STRINGP (AREF (rfont_def
, 3)))
2135 Lisp_Object font_def
;
2136 struct font_info
*fontp
;
2137 struct charset
*charset
;
2141 font_def
= AREF (rfont_def
, 2);
2142 charset
= CHARSET_FROM_ID (XINT (AREF (font_def
, 1)));
2143 code
= ENCODE_CHAR (charset
, c
);
2144 if (code
== CHARSET_INVALID_CODE (charset
))
2145 return (Fcons (AREF (rfont_def
, 3), Qnil
));
2146 STORE_XCHAR2B (&char2b
, ((code
>> 8) & 0xFF), (code
& 0xFF));
2147 fontp
= (*get_font_info_func
) (f
, XINT (AREF (rfont_def
, 1)));
2148 FRAME_RIF (f
)->encode_char (c
, &char2b
, fontp
, charset
, NULL
);
2149 code
= (XCHAR2B_BYTE1 (&char2b
) << 8) | XCHAR2B_BYTE2 (&char2b
);
2150 return (Fcons (AREF (rfont_def
, 3), make_number (code
)));
2156 DEFUN ("fontset-info", Ffontset_info
, Sfontset_info
, 1, 2, 0,
2157 doc
: /* Return information about a fontset FONTSET on frame FRAME.
2158 The value is a char-table of which elements has this form.
2160 ((FONT-PATTERN OPENED-FONT ...) ...)
2162 FONT-PATTERN is a vector:
2164 [ FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY ]
2166 or a string of font name pattern.
2168 OPENED-FONT is a name of a font actually opened.
2170 The char-table has one extra slot. The value is a char-table
2171 containing the information about the derived fonts from the default
2172 fontset. The format is the same as abobe. */)
2174 Lisp_Object fontset
, frame
;
2177 Lisp_Object
*realized
[2], fontsets
[2], tables
[2];
2178 Lisp_Object val
, elt
;
2181 (*check_window_system_func
) ();
2183 fontset
= check_fontset_name (fontset
);
2186 frame
= selected_frame
;
2187 CHECK_LIVE_FRAME (frame
);
2190 /* Recode fontsets realized on FRAME from the base fontset FONTSET
2191 in the table `realized'. */
2192 realized
[0] = (Lisp_Object
*) alloca (sizeof (Lisp_Object
)
2193 * ASIZE (Vfontset_table
));
2194 for (i
= j
= 0; i
< ASIZE (Vfontset_table
); i
++)
2196 elt
= FONTSET_FROM_ID (i
);
2198 && EQ (FONTSET_BASE (elt
), fontset
)
2199 && EQ (FONTSET_FRAME (elt
), frame
))
2200 realized
[0][j
++] = elt
;
2202 realized
[0][j
] = Qnil
;
2204 realized
[1] = (Lisp_Object
*) alloca (sizeof (Lisp_Object
)
2205 * ASIZE (Vfontset_table
));
2206 for (i
= j
= 0; ! NILP (realized
[0][i
]); i
++)
2208 elt
= FONTSET_DEFAULT (realized
[0][i
]);
2210 realized
[1][j
++] = elt
;
2212 realized
[1][j
] = Qnil
;
2214 tables
[0] = Fmake_char_table (Qfontset_info
, Qnil
);
2215 tables
[1] = Fmake_char_table (Qnil
, Qnil
);
2216 XCHAR_TABLE (tables
[0])->extras
[0] = tables
[1];
2217 fontsets
[0] = fontset
;
2218 fontsets
[1] = Vdefault_fontset
;
2220 /* Accumulate information of the fontset in TABLE. The format of
2221 each element is ((FONT-SPEC OPENED-FONT ...) ...). */
2222 for (k
= 0; k
<= 1; k
++)
2224 for (c
= 0; c
<= MAX_CHAR
; )
2228 if (c
<= MAX_5_BYTE_CHAR
)
2230 val
= char_table_ref_and_range (fontsets
[k
], c
, &from
, &to
);
2231 if (to
> MAX_5_BYTE_CHAR
)
2232 to
= MAX_5_BYTE_CHAR
;
2236 val
= FONTSET_FALLBACK (fontsets
[k
]);
2243 /* At first, set ALIST to ((FONT-SPEC) ...). */
2244 for (alist
= Qnil
, i
= 0; i
< ASIZE (val
); i
++)
2245 alist
= Fcons (Fcons (AREF (AREF (val
, i
), 0), Qnil
), alist
);
2246 alist
= Fnreverse (alist
);
2248 /* Then store opend font names to cdr of each elements. */
2249 for (i
= 0; ! NILP (realized
[k
][i
]); i
++)
2251 if (c
<= MAX_5_BYTE_CHAR
)
2252 val
= FONTSET_REF (realized
[k
][i
], c
);
2254 val
= FONTSET_FALLBACK (realized
[k
][i
]);
2255 if (! VECTORP (val
))
2257 /* VAL is [int int ?
2258 [FACE-ID FONT-INDEX FONT-DEF FONT-NAME] ...].
2259 If a font of an element is already opened,
2260 FONT-NAME is the name of a opened font. */
2261 for (j
= 3; j
< ASIZE (val
); j
++)
2262 if (STRINGP (AREF (AREF (val
, j
), 3)))
2264 Lisp_Object font_idx
;
2266 font_idx
= AREF (AREF (val
, j
), 1);
2267 elt
= Fassq (AREF (AREF (AREF (val
, j
), 2), 0), alist
);
2269 && NILP (Fmemq (font_idx
, XCDR(elt
))))
2270 nconc2 (elt
, Fcons (font_idx
, Qnil
));
2273 for (val
= alist
; CONSP (val
); val
= XCDR (val
))
2274 for (elt
= XCDR (XCAR (val
)); CONSP (elt
); elt
= XCDR (elt
))
2276 struct font_info
*font_info
2277 = (*get_font_info_func
) (f
, XINT (XCAR (elt
)));
2278 XSETCAR (elt
, build_string (font_info
->full_name
));
2281 /* Store ALIST in TBL for characters C..TO. */
2282 if (c
<= MAX_5_BYTE_CHAR
)
2283 char_table_set_range (tables
[k
], c
, to
, alist
);
2285 XCHAR_TABLE (tables
[k
])->defalt
= alist
;
2295 DEFUN ("fontset-font", Ffontset_font
, Sfontset_font
, 2, 3, 0,
2296 doc
: /* Return a font name pattern for character CH in fontset NAME.
2297 If NAME is t, find a pattern in the default fontset.
2299 The value has the form (FAMILY . REGISTRY), where FAMILY is a font
2300 family name and REGISTRY is a font registry name. This is actually
2301 the first font name pattern for CH in the fontset or in the default
2304 If the 2nd optional arg ALL is non-nil, return a list of all font name
2307 Lisp_Object name
, ch
, all
;
2310 Lisp_Object fontset
, elt
, list
, repertory
, val
;
2313 fontset
= check_fontset_name (name
);
2315 CHECK_CHARACTER (ch
);
2320 for (i
= 0, elt
= FONTSET_REF (fontset
, c
); i
< 2;
2321 i
++, elt
= FONTSET_FALLBACK (fontset
))
2323 for (j
= 0; j
< ASIZE (elt
); j
++)
2325 val
= AREF (elt
, j
);
2326 repertory
= AREF (val
, 1);
2327 if (INTEGERP (repertory
))
2329 struct charset
*charset
= CHARSET_FROM_ID (XINT (repertory
));
2331 if (! CHAR_CHARSET_P (c
, charset
))
2334 else if (CHAR_TABLE_P (repertory
))
2336 if (NILP (CHAR_TABLE_REF (repertory
, c
)))
2339 val
= AREF (val
, 0);
2340 val
= Fcons (AREF (val
, 0), AREF (val
, 5));
2343 list
= Fcons (val
, list
);
2345 if (EQ (fontset
, Vdefault_fontset
))
2347 fontset
= Vdefault_fontset
;
2349 return (Fnreverse (list
));
2352 DEFUN ("fontset-list", Ffontset_list
, Sfontset_list
, 0, 0, 0,
2353 doc
: /* Return a list of all defined fontset names. */)
2356 Lisp_Object fontset
, list
;
2360 for (i
= 0; i
< ASIZE (Vfontset_table
); i
++)
2362 fontset
= FONTSET_FROM_ID (i
);
2364 && BASE_FONTSET_P (fontset
))
2365 list
= Fcons (FONTSET_NAME (fontset
), list
);
2372 #ifdef FONTSET_DEBUG
2375 dump_fontset (fontset
)
2376 Lisp_Object fontset
;
2380 vec
= Fmake_vector (make_number (3), Qnil
);
2381 ASET (vec
, 0, FONTSET_ID (fontset
));
2383 if (BASE_FONTSET_P (fontset
))
2385 ASET (vec
, 1, FONTSET_NAME (fontset
));
2391 frame
= FONTSET_FRAME (fontset
);
2394 FRAME_PTR f
= XFRAME (frame
);
2396 if (FRAME_LIVE_P (f
))
2398 Fcons (FONTSET_NAME (FONTSET_BASE (fontset
)), f
->name
));
2401 Fcons (FONTSET_NAME (FONTSET_BASE (fontset
)), Qnil
));
2403 if (!NILP (FONTSET_DEFAULT (fontset
)))
2404 ASET (vec
, 2, FONTSET_ID (FONTSET_DEFAULT (fontset
)));
2409 DEFUN ("fontset-list-all", Ffontset_list_all
, Sfontset_list_all
, 0, 0, 0,
2410 doc
: /* Return a brief summary of all fontsets for debug use. */)
2416 for (i
= 0, val
= Qnil
; i
< ASIZE (Vfontset_table
); i
++)
2417 if (! NILP (AREF (Vfontset_table
, i
)))
2418 val
= Fcons (dump_fontset (AREF (Vfontset_table
, i
)), val
);
2419 return (Fnreverse (val
));
2421 #endif /* FONTSET_DEBUG */
2426 if (!load_font_func
)
2427 /* Window system initializer should have set proper functions. */
2430 DEFSYM (Qfontset
, "fontset");
2431 Fput (Qfontset
, Qchar_table_extra_slots
, make_number (9));
2432 DEFSYM (Qfontset_info
, "fontset-info");
2433 Fput (Qfontset_info
, Qchar_table_extra_slots
, make_number (1));
2435 DEFSYM (Qprepend
, "prepend");
2436 DEFSYM (Qappend
, "append");
2437 DEFSYM (Qlatin
, "latin");
2439 Vcached_fontset_data
= Qnil
;
2440 staticpro (&Vcached_fontset_data
);
2442 Vfontset_table
= Fmake_vector (make_number (32), Qnil
);
2443 staticpro (&Vfontset_table
);
2445 Vdefault_fontset
= Fmake_char_table (Qfontset
, Qnil
);
2446 staticpro (&Vdefault_fontset
);
2447 FONTSET_ID (Vdefault_fontset
) = make_number (0);
2448 FONTSET_NAME (Vdefault_fontset
)
2449 = build_string ("-*-*-*-*-*-*-*-*-*-*-*-*-fontset-default");
2450 AREF (Vfontset_table
, 0) = Vdefault_fontset
;
2451 next_fontset_id
= 1;
2453 auto_fontset_alist
= Qnil
;
2454 staticpro (&auto_fontset_alist
);
2456 DEFVAR_LISP ("font-encoding-alist", &Vfont_encoding_alist
,
2458 Alist of fontname patterns vs the corresponding encoding and repertory info.
2459 Each element looks like (REGEXP . (ENCODING . REPERTORY)),
2460 where ENCODING is a charset or a char-table,
2461 and REPERTORY is a charset, a char-table, or nil.
2463 ENCODING is for converting a character to a glyph code of the font.
2464 If ENCODING is a charset, encoding a character by the charset gives
2465 the corresponding glyph code. If ENCODING is a char-table, looking up
2466 the table by a character gives the corresponding glyph code.
2468 REPERTORY specifies a repertory of characters supported by the font.
2469 If REPERTORY is a charset, all characters beloging to the charset are
2470 supported. If REPERTORY is a char-table, all characters who have a
2471 non-nil value in the table are supported. It REPERTORY is nil, Emacs
2472 gets the repertory information by an opened font and ENCODING. */);
2473 Vfont_encoding_alist
= Qnil
;
2475 DEFVAR_LISP ("use-default-ascent", &Vuse_default_ascent
,
2477 Char table of characters whose ascent values should be ignored.
2478 If an entry for a character is non-nil, the ascent value of the glyph
2479 is assumed to be what specified by _MULE_DEFAULT_ASCENT property of a font.
2481 This affects how a composite character which contains
2482 such a character is displayed on screen. */);
2483 Vuse_default_ascent
= Qnil
;
2485 DEFVAR_LISP ("ignore-relative-composition", &Vignore_relative_composition
,
2487 Char table of characters which is not composed relatively.
2488 If an entry for a character is non-nil, a composition sequence
2489 which contains that character is displayed so that
2490 the glyph of that character is put without considering
2491 an ascent and descent value of a previous character. */);
2492 Vignore_relative_composition
= Qnil
;
2494 DEFVAR_LISP ("alternate-fontname-alist", &Valternate_fontname_alist
,
2495 doc
: /* Alist of fontname vs list of the alternate fontnames.
2496 When a specified font name is not found, the corresponding
2497 alternate fontnames (if any) are tried instead. */);
2498 Valternate_fontname_alist
= Qnil
;
2500 DEFVAR_LISP ("fontset-alias-alist", &Vfontset_alias_alist
,
2501 doc
: /* Alist of fontset names vs the aliases. */);
2502 Vfontset_alias_alist
= Fcons (Fcons (FONTSET_NAME (Vdefault_fontset
),
2503 build_string ("fontset-default")),
2506 DEFVAR_LISP ("vertical-centering-font-regexp",
2507 &Vvertical_centering_font_regexp
,
2508 doc
: /* *Regexp matching font names that require vertical centering on display.
2509 When a character is displayed with such fonts, the character is displayed
2510 at the vertical center of lines. */);
2511 Vvertical_centering_font_regexp
= Qnil
;
2513 DEFVAR_LISP ("otf-script-alist", &Votf_script_alist
,
2514 doc
: /* Alist of OpenType script tags vs the corresponding script names. */);
2515 Votf_script_alist
= Qnil
;
2517 defsubr (&Squery_fontset
);
2518 defsubr (&Snew_fontset
);
2519 defsubr (&Sset_fontset_font
);
2520 defsubr (&Sfont_info
);
2521 defsubr (&Sinternal_char_font
);
2522 defsubr (&Sfontset_info
);
2523 defsubr (&Sfontset_font
);
2524 defsubr (&Sfontset_list
);
2525 #ifdef FONTSET_DEBUG
2526 defsubr (&Sfontset_list_all
);
2530 /* arch-tag: ea861585-2f5f-4e5b-9849-d04a9c3a3537
2531 (do not change this comment) */