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
);
341 /* Set elements of FONTSET for characters in RANGE to the value ELT.
342 RANGE is a cons (FROM . TO), where FROM and TO are character codes
343 specifying a range. */
345 #define FONTSET_SET(fontset, range, elt) \
346 Fset_char_table_range ((fontset), (range), (elt))
349 /* Modify the elements of FONTSET for characters in RANGE by replacing
350 with ELT or adding ELT. RANGE is a cons (FROM . TO), where FROM
351 and TO are character codes specifying a range. If ADD is nil,
352 replace with ELT, if ADD is `prepend', prepend ELT, otherwise,
355 #define FONTSET_ADD(fontset, range, elt, add) \
358 ? (FONTSET_FALLBACK (fontset) = Fmake_vector (make_number (1), (elt))) \
359 : Fset_char_table_range ((fontset), (range), \
360 Fmake_vector (make_number (1), (elt)))) \
361 : fontset_add ((fontset), (range), (elt), (add)))
364 fontset_add (fontset
, range
, elt
, add
)
365 Lisp_Object fontset
, range
, elt
, add
;
368 int idx
= (EQ (add
, Qappend
) ? 0 : 1);
370 args
[1 - idx
] = Fmake_vector (make_number (1), elt
);
374 int from
= XINT (XCAR (range
));
375 int to
= XINT (XCDR (range
));
379 args
[idx
] = char_table_ref_and_range (fontset
, from
, &from1
, &to1
);
382 char_table_set_range (fontset
, from
, to1
,
383 NILP (args
[idx
]) ? args
[1 - idx
]
384 : Fvconcat (2, args
));
390 args
[idx
] = FONTSET_FALLBACK (fontset
);
391 FONTSET_FALLBACK (fontset
)
392 = NILP (args
[idx
]) ? args
[1 - idx
] : Fvconcat (2, args
);
398 /* Update FONT-GROUP which has this form:
399 [CHARSET-ORDERED-LIST-TICK PREFERRED-CHARSET-ID PREFERRED-FAMILY
400 RFONT-DEF0 RFONT-DEF1 ...].
401 Reorder RFONT-DEFs according to the current order of charset
402 (Vcharset_ordered_list), and update CHARSET-ORDERED-LIST-TICK to
406 reorder_font_vector (font_group
, charset_id
, family
)
407 Lisp_Object font_group
;
411 Lisp_Object list
, *new_vec
;
413 int *charset_id_table
;
415 Lisp_Object preferred_by_charset
, preferred_by_family
;
417 size
= ASIZE (font_group
) - 3;
418 /* Exclude the tailing nil elements from the reordering. */
419 while (NILP (AREF (font_group
, size
- 1))) size
--;
420 charset_id_table
= (int *) alloca (sizeof (int) * size
);
421 new_vec
= (Lisp_Object
*) alloca (sizeof (Lisp_Object
) * size
);
423 /* At first, extract ENCODING (a chaset ID) from RFONT_DEF which
425 [FACE-ID FONT-INDEX [ FONT-SPEC ENCODING REPERTORY ]]
426 In addtion, if RFONT_DEF is preferred by family or charset, store
427 it from the start of new_vec. */
428 for (i
= 0, idx
= 0; i
< size
; i
++)
430 Lisp_Object rfont_def
= AREF (font_group
, i
+ 3);
431 Lisp_Object font_spec
= AREF (AREF (rfont_def
, 2), 0);
432 Lisp_Object this_family
= AREF (font_spec
, FONT_FAMILY_INDEX
);
433 int id
= XINT (AREF (AREF (rfont_def
, 2), 1));
434 struct charset
*charset
= CHARSET_FROM_ID (id
);
436 charset_id_table
[i
] = -1;
437 if (! NILP (this_family
)
438 && (fast_string_match_ignore_case (family
, SYMBOL_NAME (this_family
))
442 memmove (new_vec
+ 1, new_vec
, sizeof (Lisp_Object
) * idx
);
443 new_vec
[0] = rfont_def
;
445 ASET (font_group
, i
+ 3, Qnil
);
447 else if (id
== charset_id
)
449 new_vec
[idx
++] = rfont_def
;
450 ASET (font_group
, i
+ 3, Qnil
);
452 else if (! charset
->supplementary_p
)
453 charset_id_table
[i
] = id
;
457 && (XINT (AREF (font_group
, 0)) == charset_ordered_list_tick
))
458 /* No need of reordering. */
461 ASET (font_group
, 0, make_number (charset_ordered_list_tick
));
462 ASET (font_group
, 1, make_number (charset_id
));
463 ASET (font_group
, 2, family
);
465 /* Then, store the remaining RFONT-DEFs in NEW_VEC in the correct
467 for (list
= Vcharset_ordered_list
; idx
< size
; list
= XCDR (list
))
469 int id
= XINT (XCAR (list
));
470 struct charset
*charset
= CHARSET_FROM_ID (id
);
472 if (charset
->supplementary_p
)
474 for (i
= 0; i
< size
; i
++)
475 if (charset_id_table
[i
] == XINT (XCAR (list
))
476 && ! NILP (AREF (font_group
, i
+ 3)))
478 new_vec
[idx
++] = AREF (font_group
, i
+ 3);
479 ASET (font_group
, i
+ 3, Qnil
);
482 for (i
= 0; i
< size
; i
++)
483 if (! NILP (AREF (font_group
, i
+ 3)))
484 new_vec
[idx
++] = AREF (font_group
, i
+ 3);
486 /* At last, update elements of FONT-GROUP. */
487 for (i
= 0; i
< size
; i
++)
488 ASET (font_group
, i
+ 3, new_vec
[i
]);
492 /* Load a font matching the font related attributes in FACE->lface and
493 font pattern in FONT_DEF of FONTSET, and return an index of the
494 font. FONT_DEF has this form:
495 [ FONT-SPEC ENCODING REPERTORY ]
496 If REPERTORY is nil, generate a char-table representing the font
497 repertory by looking into the font itself. */
499 extern Lisp_Object QCname
;
502 load_font_get_repertory (f
, face
, font_def
, fontset
)
505 Lisp_Object font_def
;
509 struct font_info
*font_info
;
511 Lisp_Object font_spec
, name
;
513 font_spec
= AREF (font_def
, 0);
514 name
= Ffont_get (font_spec
, QCname
);
516 font_name
= choose_face_font (f
, face
->lface
, name
, NULL
);
518 font_name
= choose_face_font (f
, face
->lface
, font_spec
, NULL
);
519 charset
= XINT (AREF (font_def
, 1));
520 if (! (font_info
= fs_load_font (f
, font_name
, charset
)))
523 if (NILP (AREF (font_def
, 2))
524 && NILP (Fassq (make_number (font_info
->font_idx
),
525 FONTSET_REPERTORY (fontset
))))
527 /* We must look into the font to get the correct repertory as a
529 Lisp_Object repertory
;
531 repertory
= (*get_font_repertory_func
) (f
, font_info
);
532 FONTSET_REPERTORY (fontset
)
533 = Fcons (Fcons (make_number (font_info
->font_idx
), repertory
),
534 FONTSET_REPERTORY (fontset
));
537 return font_info
->font_idx
;
540 static Lisp_Object fontset_find_font
P_ ((Lisp_Object
, int, struct face
*,
543 /* Return RFONT-DEF (vector) in the realized fontset FONTSET for the
544 character C. If no font is found, return Qnil if there's a
545 possibility that the default fontset or the fallback font groups
546 have a proper font, and return Qt if not.
548 If a font is found but is not yet opened, open it (if FACE is not
549 NULL) or return Qnil (if FACE is NULL).
551 ID is a charset-id that must be preferred, or -1 meaning no
554 If FALLBACK is nonzero, search only fallback fonts. */
557 fontset_find_font (fontset
, c
, face
, id
, fallback
)
563 Lisp_Object base_fontset
, elt
, vec
, font_def
;
566 FRAME_PTR f
= XFRAME (FONTSET_FRAME (fontset
));
568 base_fontset
= FONTSET_BASE (fontset
);
570 vec
= CHAR_TABLE_REF (fontset
, c
);
572 vec
= FONTSET_FALLBACK (fontset
);
578 /* We have not yet decided a font for C. */
583 elt
= char_table_ref_and_range (base_fontset
, c
, &from
, &to
);
584 range
= Fcons (make_number (from
), make_number (to
));
588 elt
= FONTSET_FALLBACK (base_fontset
);
592 /* This fontset doesn't specify any font for C. */
593 vec
= make_number (0);
595 else if (ASIZE (elt
) == 1 && NILP (AREF (elt
, 0)))
597 /* Explicitly specified no font. */
602 /* Build a vector [ -1 -1 nil NEW-ELT0 NEW-ELT1 NEW-ELT2 ... ],
603 where the first -1 is to force reordering of NEW-ELTn,
604 NEW-ELTn is [nil nil AREF (elt, n) nil]. */
605 int size
= ASIZE (elt
);
608 vec
= Fmake_vector (make_number (size
+ 3), Qnil
);
609 ASET (vec
, 0, make_number (-1));
610 ASET (vec
, 1, make_number (-1));
611 for (i
= j
= 0; i
< size
; i
++)
612 if (! NILP (AREF (elt
, i
)))
615 tmp
= Fmake_vector (make_number (5), Qnil
);
616 ASET (tmp
, 2, AREF (elt
, i
));
617 ASET (vec
, j
+ 3, tmp
);
621 /* Then store it in the fontset. */
623 FONTSET_SET (fontset
, range
, vec
);
625 FONTSET_FALLBACK (fontset
) = vec
;
629 return (EQ (vec
, Qt
) ? Qt
: Qnil
);
632 && (XINT (AREF (vec
, 0)) != charset_ordered_list_tick
633 || (id
>= 0 && XINT (AREF (vec
, 1)) != id
)
634 || NILP (Fequal (AREF (vec
, 2), face
->lface
[LFACE_FAMILY_INDEX
]))))
635 /* We have just created VEC,
636 or the charset priorities were changed,
637 or the preferred charset was changed,
638 or the preferred family was changed. */
639 reorder_font_vector (vec
, id
, face
->lface
[LFACE_FAMILY_INDEX
]);
641 /* Find the first available font in the vector of RFONT-DEF. */
642 for (i
= 3; i
< ASIZE (vec
); i
++)
646 /* This is the sign of not to try fallback fonts. */
648 /* ELT == [ FACE-ID FONT-INDEX FONT-DEF ... ] */
649 if (INTEGERP (AREF (elt
, 1)) && XINT (AREF (elt
, 1)) < 0)
650 /* We couldn't open this font last time. */
653 if (!face
&& NILP (AREF (elt
, 1)))
654 /* We have not yet opened the font. */
657 font_def
= AREF (elt
, 2);
658 /* FONT_DEF == [ FONT-SPEC ENCODING REPERTORY ] */
660 #ifdef USE_FONT_BACKEND
661 if (enable_font_backend
)
663 /* ELT == [ FACE-ID FONT-INDEX FONT-DEF FONT-ENTITY ]
664 where FONT-ENTITY turns to a font-object once opened. */
665 Lisp_Object font_entity
= AREF (elt
, 3);
668 if (NILP (font_entity
))
670 font_entity
= font_find_for_lface (f
, face
->lface
,
671 AREF (font_def
, 0), -1);
672 if (NILP (font_entity
))
674 ASET (elt
, 1, make_number (-1));
677 ASET (elt
, 3, font_entity
);
679 else if (FONT_ENTITY_P (font_entity
))
681 if (FONT_ENTITY_NOT_LOADABLE (font_entity
))
684 has_char
= font_has_char (f
, font_entity
, c
);
687 if (! FONT_OBJECT_P (font_entity
))
689 Lisp_Object font_object
690 = font_open_for_lface (f
, font_entity
, face
->lface
, Qnil
);
692 if (NILP (font_object
))
694 FONT_ENTITY_SET_NOT_LOADABLE (font_entity
);
697 ASET (elt
, 3, font_object
);
700 has_char
= font_has_char (f
, font_object
, c
);
705 /* Decide to use this font. */
706 ASET (elt
, 1, make_number (0));
709 #endif /* USE_FONT_BACKEND */
711 if (INTEGERP (AREF (font_def
, 2)))
713 /* The repertory is specified by charset ID. */
714 struct charset
*charset
715 = CHARSET_FROM_ID (XINT (AREF (font_def
, 2)));
717 if (! CHAR_CHARSET_P (c
, charset
))
718 /* This font can't display C. */
721 else if (CHAR_TABLE_P (AREF (font_def
, 2)))
723 /* The repertory is specified by a char table. */
724 if (NILP (CHAR_TABLE_REF (AREF (font_def
, 2), c
)))
725 /* This font can't display C. */
732 if (! INTEGERP (AREF (elt
, 1)))
734 /* We have not yet opened a font matching this spec.
735 Open the best matching font now and register the
737 struct font_info
*font_info
;
739 font_idx
= load_font_get_repertory (f
, face
, font_def
, fontset
);
740 ASET (elt
, 1, make_number (font_idx
));
742 /* This means that we couldn't find a font matching
745 font_info
= (*get_font_info_func
) (f
, font_idx
);
746 ASET (elt
, 3, build_string (font_info
->full_name
));
749 slot
= Fassq (AREF (elt
, 1), FONTSET_REPERTORY (fontset
));
750 xassert (CONSP (slot
));
751 if (NILP (CHAR_TABLE_REF (XCDR (slot
), c
)))
752 /* This font can't display C. */
756 /* Now we have decided to use this font spec to display C. */
757 if (! INTEGERP (AREF (elt
, 1)))
759 /* But not yet opened the best matching font. */
760 struct font_info
*font_info
;
762 font_idx
= load_font_get_repertory (f
, face
, font_def
, fontset
);
763 ASET (elt
, 1, make_number (font_idx
));
765 /* Can't open it. Try the other one. */
767 font_info
= (*get_font_info_func
) (f
, font_idx
);
768 ASET (elt
, 3, build_string (font_info
->full_name
));
778 fontset_font (fontset
, c
, face
, id
)
784 Lisp_Object rfont_def
;
785 Lisp_Object base_fontset
;
787 /* Try a font-group for C. */
788 rfont_def
= fontset_find_font (fontset
, c
, face
, id
, 0);
789 if (VECTORP (rfont_def
))
791 if (EQ (rfont_def
, Qt
))
793 base_fontset
= FONTSET_BASE (fontset
);
794 /* Try a font-group for C of the default fontset. */
795 if (! EQ (base_fontset
, Vdefault_fontset
))
797 if (NILP (FONTSET_DEFAULT (fontset
)))
798 FONTSET_DEFAULT (fontset
)
799 = make_fontset (FONTSET_FRAME (fontset
), Qnil
, Vdefault_fontset
);
800 rfont_def
= fontset_find_font (FONTSET_DEFAULT (fontset
), c
, face
, id
, 0);
801 if (VECTORP (rfont_def
))
803 if (! NILP (rfont_def
))
804 /* Remeber that we have no font for C. */
805 FONTSET_SET (fontset
, make_number (c
), Qt
);
808 /* Try a fallback font-group. */
809 rfont_def
= fontset_find_font (fontset
, c
, face
, id
, 1);
810 if (! VECTORP (rfont_def
)
811 && ! EQ (base_fontset
, Vdefault_fontset
))
812 /* Try a fallback font-group of the default fontset . */
813 rfont_def
= fontset_find_font (FONTSET_DEFAULT (fontset
), c
, face
, id
, 1);
815 if (! VECTORP (rfont_def
))
816 /* Remeber that we have no font for C. */
817 FONTSET_SET (fontset
, make_number (c
), Qt
);
822 /* Return a newly created fontset with NAME. If BASE is nil, make a
823 base fontset. Otherwise make a realized fontset whose base is
827 make_fontset (frame
, name
, base
)
828 Lisp_Object frame
, name
, base
;
831 int size
= ASIZE (Vfontset_table
);
832 int id
= next_fontset_id
;
834 /* Find a free slot in Vfontset_table. Usually, next_fontset_id is
835 the next available fontset ID. So it is expected that this loop
836 terminates quickly. In addition, as the last element of
837 Vfontset_table is always nil, we don't have to check the range of
839 while (!NILP (AREF (Vfontset_table
, id
))) id
++;
842 Vfontset_table
= larger_vector (Vfontset_table
, size
+ 32, Qnil
);
844 fontset
= Fmake_char_table (Qfontset
, Qnil
);
846 FONTSET_ID (fontset
) = make_number (id
);
849 FONTSET_NAME (fontset
) = name
;
853 FONTSET_NAME (fontset
) = Qnil
;
854 FONTSET_FRAME (fontset
) = frame
;
855 FONTSET_BASE (fontset
) = base
;
858 ASET (Vfontset_table
, id
, fontset
);
859 next_fontset_id
= id
+ 1;
864 /* Set the ASCII font of the default fontset to FONTNAME if that is
867 set_default_ascii_font (fontname
)
868 Lisp_Object fontname
;
870 if (! STRINGP (FONTSET_ASCII (Vdefault_fontset
)))
872 int id
= fs_query_fontset (fontname
, 2);
875 fontname
= FONTSET_ASCII (FONTSET_FROM_ID (id
));
876 FONTSET_ASCII (Vdefault_fontset
)= fontname
;
881 /********** INTERFACES TO xfaces.c, xfns.c, and dispextern.h **********/
883 /* Return the name of the fontset who has ID. */
891 fontset
= FONTSET_FROM_ID (id
);
892 return FONTSET_NAME (fontset
);
896 /* Return the ASCII font name of the fontset who has ID. */
902 Lisp_Object fontset
, elt
;
904 fontset
= FONTSET_FROM_ID (id
);
905 elt
= FONTSET_ASCII (fontset
);
906 #ifdef USE_FONT_BACKEND
909 #endif /* USE_FONT_BACKEND */
910 /* It is assured that ELT is always a string (i.e. fontname
916 /* Free fontset of FACE defined on frame F. Called from
917 free_realized_face. */
920 free_face_fontset (f
, face
)
926 fontset
= AREF (Vfontset_table
, face
->fontset
);
927 xassert (!NILP (fontset
) && ! BASE_FONTSET_P (fontset
));
928 xassert (f
== XFRAME (FONTSET_FRAME (fontset
)));
929 ASET (Vfontset_table
, face
->fontset
, Qnil
);
930 if (face
->fontset
< next_fontset_id
)
931 next_fontset_id
= face
->fontset
;
932 if (! NILP (FONTSET_DEFAULT (fontset
)))
934 int id
= XINT (FONTSET_ID (FONTSET_DEFAULT (fontset
)));
936 fontset
= AREF (Vfontset_table
, id
);
937 xassert (!NILP (fontset
) && ! BASE_FONTSET_P (fontset
));
938 xassert (f
== XFRAME (FONTSET_FRAME (fontset
)));
939 ASET (Vfontset_table
, id
, Qnil
);
940 if (id
< next_fontset_id
)
941 next_fontset_id
= face
->fontset
;
946 /* Return 1 if FACE is suitable for displaying character C.
947 Otherwise return 0. Called from the macro FACE_SUITABLE_FOR_CHAR_P
948 when C is not an ASCII character. */
951 face_suitable_for_char_p (face
, c
)
955 Lisp_Object fontset
, rfont_def
;
957 fontset
= FONTSET_FROM_ID (face
->fontset
);
958 rfont_def
= fontset_font (fontset
, c
, NULL
, -1);
959 return (VECTORP (rfont_def
)
960 && INTEGERP (AREF (rfont_def
, 0))
961 && face
->id
== XINT (AREF (rfont_def
, 0)));
965 /* Return ID of face suitable for displaying character C on frame F.
966 FACE must be reazlied for ASCII characters in advance. Called from
967 the macro FACE_FOR_CHAR. */
970 face_for_char (f
, face
, c
, pos
, object
)
976 Lisp_Object fontset
, charset
, rfont_def
;
980 if (ASCII_CHAR_P (c
))
981 return face
->ascii_face
->id
;
983 xassert (fontset_id_valid_p (face
->fontset
));
984 fontset
= FONTSET_FROM_ID (face
->fontset
);
985 xassert (!BASE_FONTSET_P (fontset
));
990 charset
= Fget_char_property (make_number (pos
), Qcharset
, object
);
993 else if (CHARSETP (charset
))
997 val
= assoc_no_quit (charset
, Vfont_encoding_charset_alist
);
998 if (CONSP (val
) && CHARSETP (XCDR (val
)))
999 charset
= XCDR (val
);
1000 id
= XINT (CHARSET_SYMBOL_ID (charset
));
1003 rfont_def
= fontset_font (fontset
, c
, face
, id
);
1004 if (VECTORP (rfont_def
))
1006 #ifdef USE_FONT_BACKEND
1007 if (enable_font_backend
1008 && NILP (AREF (rfont_def
, 0)))
1010 struct font
*font
= XSAVE_VALUE (AREF (rfont_def
, 3))->pointer
;
1012 face_id
= face_for_font (f
, font
, face
);
1013 ASET (rfont_def
, 0, make_number (face_id
));
1016 #endif /* USE_FONT_BACKEND */
1017 if (NILP (AREF (rfont_def
, 0)))
1019 /* We have not yet made a realized face that uses this font. */
1020 int font_idx
= XINT (AREF (rfont_def
, 1));
1022 face_id
= lookup_non_ascii_face (f
, font_idx
, face
);
1023 ASET (rfont_def
, 0, make_number (face_id
));
1025 return XINT (AREF (rfont_def
, 0));
1028 if (NILP (FONTSET_NOFONT_FACE (fontset
)))
1030 face_id
= lookup_non_ascii_face (f
, -1, face
);
1031 FONTSET_NOFONT_FACE (fontset
) = make_number (face_id
);
1033 return XINT (FONTSET_NOFONT_FACE (fontset
));
1037 /* Make a realized fontset for ASCII face FACE on frame F from the
1038 base fontset BASE_FONTSET_ID. If BASE_FONTSET_ID is -1, use the
1039 default fontset as the base. Value is the id of the new fontset.
1040 Called from realize_x_face. */
1043 make_fontset_for_ascii_face (f
, base_fontset_id
, face
)
1045 int base_fontset_id
;
1048 Lisp_Object base_fontset
, fontset
, frame
;
1050 XSETFRAME (frame
, f
);
1051 if (base_fontset_id
>= 0)
1053 base_fontset
= FONTSET_FROM_ID (base_fontset_id
);
1054 if (!BASE_FONTSET_P (base_fontset
))
1055 base_fontset
= FONTSET_BASE (base_fontset
);
1056 if (! BASE_FONTSET_P (base_fontset
))
1060 base_fontset
= Vdefault_fontset
;
1062 fontset
= make_fontset (frame
, Qnil
, base_fontset
);
1063 return XINT (FONTSET_ID (fontset
));
1067 #if defined(WINDOWSNT) && defined (_MSC_VER)
1068 #pragma optimize("", off)
1071 /* Load a font named FONTNAME on frame F. Return a pointer to the
1072 struct font_info of the loaded font. If loading fails, return
1073 NULL. CHARSET is an ID of charset to encode characters for this
1074 font. If it is -1, find one from Vfont_encoding_alist. */
1077 fs_load_font (f
, fontname
, charset
)
1082 struct font_info
*fontp
;
1083 Lisp_Object fullname
;
1086 /* No way to get fontname. */
1089 fontp
= (*load_font_func
) (f
, fontname
, 0);
1090 if (! fontp
|| fontp
->charset
>= 0)
1093 fontname
= fontp
->full_name
;
1094 fullname
= build_string (fontp
->full_name
);
1098 Lisp_Object charset_symbol
;
1100 charset_symbol
= find_font_encoding (fullname
);
1101 if (CONSP (charset_symbol
))
1102 charset_symbol
= XCAR (charset_symbol
);
1103 if (NILP (charset_symbol
))
1104 charset_symbol
= Qascii
;
1105 charset
= XINT (CHARSET_SYMBOL_ID (charset_symbol
));
1107 fontp
->charset
= charset
;
1108 fontp
->vertical_centering
= 0;
1109 fontp
->font_encoder
= NULL
;
1111 if (charset
!= charset_ascii
)
1113 fontp
->vertical_centering
1114 = (STRINGP (Vvertical_centering_font_regexp
)
1115 && (fast_string_match_ignore_case
1116 (Vvertical_centering_font_regexp
, fullname
) >= 0));
1118 if (find_ccl_program_func
)
1119 (*find_ccl_program_func
) (fontp
);
1125 #if defined(WINDOWSNT) && defined (_MSC_VER)
1126 #pragma optimize("", on)
1130 /* Return ENCODING or a cons of ENCODING and REPERTORY of the font
1131 FONTNAME. ENCODING is a charset symbol that specifies the encoding
1132 of the font. REPERTORY is a charset symbol or nil. */
1136 find_font_encoding (fontname
)
1137 Lisp_Object fontname
;
1139 Lisp_Object tail
, elt
;
1141 for (tail
= Vfont_encoding_alist
; CONSP (tail
); tail
= XCDR (tail
))
1145 && STRINGP (XCAR (elt
))
1146 && fast_string_match_ignore_case (XCAR (elt
), fontname
) >= 0
1147 && (SYMBOLP (XCDR (elt
))
1148 ? CHARSETP (XCDR (elt
))
1149 : CONSP (XCDR (elt
)) && CHARSETP (XCAR (XCDR (elt
)))))
1150 return (XCDR (elt
));
1152 /* We don't know the encoding of this font. Let's assume `ascii'. */
1157 /* Cache data used by fontset_pattern_regexp. The car part is a
1158 pattern string containing at least one wild card, the cdr part is
1159 the corresponding regular expression. */
1160 static Lisp_Object Vcached_fontset_data
;
1162 #define CACHED_FONTSET_NAME (SDATA (XCAR (Vcached_fontset_data)))
1163 #define CACHED_FONTSET_REGEX (XCDR (Vcached_fontset_data))
1165 /* If fontset name PATTERN contains any wild card, return regular
1166 expression corresponding to PATTERN. */
1169 fontset_pattern_regexp (pattern
)
1170 Lisp_Object pattern
;
1172 if (!index (SDATA (pattern
), '*')
1173 && !index (SDATA (pattern
), '?'))
1174 /* PATTERN does not contain any wild cards. */
1177 if (!CONSP (Vcached_fontset_data
)
1178 || strcmp (SDATA (pattern
), CACHED_FONTSET_NAME
))
1180 /* We must at first update the cached data. */
1181 unsigned char *regex
, *p0
, *p1
;
1182 int ndashes
= 0, nstars
= 0;
1184 for (p0
= SDATA (pattern
); *p0
; p0
++)
1188 else if (*p0
== '*')
1192 /* If PATTERN is not full XLFD we conert "*" to ".*". Otherwise
1193 we convert "*" to "[^-]*" which is much faster in regular
1194 expression matching. */
1196 p1
= regex
= (unsigned char *) alloca (SBYTES (pattern
) + 2 * nstars
+ 1);
1198 p1
= regex
= (unsigned char *) alloca (SBYTES (pattern
) + 5 * nstars
+ 1);
1201 for (p0
= SDATA (pattern
); *p0
; p0
++)
1208 *p1
++ = '[', *p1
++ = '^', *p1
++ = '-', *p1
++ = ']';
1211 else if (*p0
== '?')
1219 Vcached_fontset_data
= Fcons (build_string (SDATA (pattern
)),
1220 build_string (regex
));
1223 return CACHED_FONTSET_REGEX
;
1226 /* Return ID of the base fontset named NAME. If there's no such
1227 fontset, return -1. NAME_PATTERN specifies how to treat NAME as this:
1228 0: pattern containing '*' and '?' as wildcards
1229 1: regular expression
1230 2: literal fontset name
1234 fs_query_fontset (name
, name_pattern
)
1241 name
= Fdowncase (name
);
1242 if (name_pattern
!= 1)
1244 tem
= Frassoc (name
, Vfontset_alias_alist
);
1246 tem
= Fassoc (name
, Vfontset_alias_alist
);
1247 if (CONSP (tem
) && STRINGP (XCAR (tem
)))
1249 else if (name_pattern
== 0)
1251 tem
= fontset_pattern_regexp (name
);
1260 for (i
= 0; i
< ASIZE (Vfontset_table
); i
++)
1262 Lisp_Object fontset
, this_name
;
1264 fontset
= FONTSET_FROM_ID (i
);
1266 || !BASE_FONTSET_P (fontset
))
1269 this_name
= FONTSET_NAME (fontset
);
1270 if (name_pattern
== 1
1271 ? fast_string_match (name
, this_name
) >= 0
1272 : !strcmp (SDATA (name
), SDATA (this_name
)))
1279 DEFUN ("query-fontset", Fquery_fontset
, Squery_fontset
, 1, 2, 0,
1280 doc
: /* Return the name of a fontset that matches PATTERN.
1281 The value is nil if there is no matching fontset.
1282 PATTERN can contain `*' or `?' as a wildcard
1283 just as X font name matching algorithm allows.
1284 If REGEXPP is non-nil, PATTERN is a regular expression. */)
1286 Lisp_Object pattern
, regexpp
;
1288 Lisp_Object fontset
;
1291 (*check_window_system_func
) ();
1293 CHECK_STRING (pattern
);
1295 if (SCHARS (pattern
) == 0)
1298 id
= fs_query_fontset (pattern
, !NILP (regexpp
));
1302 fontset
= FONTSET_FROM_ID (id
);
1303 return FONTSET_NAME (fontset
);
1306 /* Return a list of base fontset names matching PATTERN on frame F. */
1309 list_fontsets (f
, pattern
, size
)
1311 Lisp_Object pattern
;
1314 Lisp_Object frame
, regexp
, val
;
1317 XSETFRAME (frame
, f
);
1319 regexp
= fontset_pattern_regexp (pattern
);
1322 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
1324 Lisp_Object fontset
, name
;
1326 fontset
= FONTSET_FROM_ID (id
);
1328 || !BASE_FONTSET_P (fontset
)
1329 || !EQ (frame
, FONTSET_FRAME (fontset
)))
1331 name
= FONTSET_NAME (fontset
);
1333 if (STRINGP (regexp
)
1334 ? (fast_string_match (regexp
, name
) < 0)
1335 : strcmp (SDATA (pattern
), SDATA (name
)))
1338 val
= Fcons (Fcopy_sequence (FONTSET_NAME (fontset
)), val
);
1345 /* Free all realized fontsets whose base fontset is BASE. */
1348 free_realized_fontsets (base
)
1354 /* For the moment, this doesn't work because free_realized_face
1355 doesn't remove FACE from a cache. Until we find a solution, we
1356 suppress this code, and simply use Fclear_face_cache even though
1357 that is not efficient. */
1359 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
1361 Lisp_Object
this = AREF (Vfontset_table
, id
);
1363 if (EQ (FONTSET_BASE (this), base
))
1367 for (tail
= FONTSET_FACE_ALIST (this); CONSP (tail
);
1370 FRAME_PTR f
= XFRAME (FONTSET_FRAME (this));
1371 int face_id
= XINT (XCDR (XCAR (tail
)));
1372 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1374 /* Face THIS itself is also freed by the following call. */
1375 free_realized_face (f
, face
);
1381 /* But, we don't have to call Fclear_face_cache if no fontset has
1382 been realized from BASE. */
1383 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
1385 Lisp_Object
this = AREF (Vfontset_table
, id
);
1387 if (CHAR_TABLE_P (this) && EQ (FONTSET_BASE (this), base
))
1389 Fclear_face_cache (Qt
);
1397 /* Check validity of NAME as a fontset name and return the
1398 corresponding fontset. If not valid, signal an error.
1399 If NAME is t, return Vdefault_fontset. */
1402 check_fontset_name (name
)
1408 return Vdefault_fontset
;
1410 CHECK_STRING (name
);
1411 /* First try NAME as literal. */
1412 id
= fs_query_fontset (name
, 2);
1414 /* For backward compatibility, try again NAME as pattern. */
1415 id
= fs_query_fontset (name
, 0);
1417 error ("Fontset `%s' does not exist", SDATA (name
));
1418 return FONTSET_FROM_ID (id
);
1422 accumulate_script_ranges (arg
, range
, val
)
1423 Lisp_Object arg
, range
, val
;
1425 if (EQ (XCAR (arg
), val
))
1428 XSETCDR (arg
, Fcons (Fcons (XCAR (range
), XCDR (range
)), XCDR (arg
)));
1430 XSETCDR (arg
, Fcons (Fcons (range
, range
), XCDR (arg
)));
1435 /* Return an ASCII font name generated from fontset name NAME and
1436 font-spec ASCII_SPEC. NAME is a string conforming to XLFD. */
1438 static INLINE Lisp_Object
1439 generate_ascii_font_name (name
, ascii_spec
)
1440 Lisp_Object name
, ascii_spec
;
1442 Lisp_Object font_spec
= Ffont_spec (0, NULL
);
1447 if (font_parse_xlfd (SDATA (name
), font_spec
) < 0)
1448 error ("Not an XLFD font name: %s", SDATA (name
));
1449 for (i
= FONT_FOUNDRY_INDEX
; i
<= FONT_WIDTH_INDEX
; i
++)
1450 if (! NILP (AREF (ascii_spec
, i
)))
1451 ASET (font_spec
, i
, AREF (ascii_spec
, i
));
1452 i
= font_unparse_xlfd (font_spec
, 0, xlfd
, 256);
1454 error ("Not an XLFD font name: %s", SDATA (name
));
1455 return make_unibyte_string (xlfd
, i
);
1458 /* Variables referred in set_fontset_font. They are set before
1459 map_charset_chars is called in Fset_fontset_font. */
1460 static Lisp_Object font_def_arg
, add_arg
;
1461 static int from_arg
, to_arg
;
1463 /* Callback function for map_charset_chars in Fset_fontset_font. In
1464 FONTSET, set font_def_arg in a fashion specified by add_arg for
1465 characters in RANGE while ignoring the range between from_arg and
1469 set_fontset_font (fontset
, range
)
1470 Lisp_Object fontset
, range
;
1472 if (from_arg
< to_arg
)
1474 int from
= XINT (XCAR (range
)), to
= XINT (XCDR (range
));
1476 if (from
< from_arg
)
1482 range2
= Fcons (make_number (to_arg
), XCDR (range
));
1483 FONTSET_ADD (fontset
, range
, font_def_arg
, add_arg
);
1487 range
= Fcons (XCAR (range
), make_number (from_arg
));
1489 else if (to
<= to_arg
)
1494 range
= Fcons (make_number (to_arg
), XCDR (range
));
1497 FONTSET_ADD (fontset
, range
, font_def_arg
, add_arg
);
1500 extern Lisp_Object QCfamily
, QCregistry
;
1502 DEFUN ("set-fontset-font", Fset_fontset_font
, Sset_fontset_font
, 3, 5, 0,
1504 Modify fontset NAME to use FONT-SPEC for TARGET characters.
1506 TARGET may be a cons; (FROM . TO), where FROM and TO are characters.
1507 In that case, use FONT-SPEC for all characters in the range FROM and
1510 TARGET may be a script name symbol. In that case, use FONT-SPEC for
1511 all characters that belong to the script.
1513 TARGET may be a charset. In that case, use FONT-SPEC for all
1514 characters in the charset.
1516 TARGET may be nil. In that case, use FONT-SPEC for any characters for
1517 that no FONT-SPEC is specified.
1519 FONT-SPEC may one of these:
1520 * A cons (FAMILY . REGISTRY), where FAMILY is a font family name and
1521 REGISTRY is a font registry name. FAMILY may contains foundry
1522 name, and REGISTRY may contains encoding name.
1523 * A font name string.
1524 * nil, which explicitly specifies that there's no font for TARGET.
1526 Optional 4th argument FRAME, if non-nil, is a frame. This argument is
1527 kept for backward compatibility and has no meaning.
1529 Optional 5th argument ADD, if non-nil, specifies how to add FONT-SPEC
1530 to the font specifications for TARGET previously set. If it is
1531 `prepend', FONT-SPEC is prepended. If it is `append', FONT-SPEC is
1532 appended. By default, FONT-SPEC overrides the previous settings. */)
1533 (name
, target
, font_spec
, frame
, add
)
1534 Lisp_Object name
, target
, font_spec
, frame
, add
;
1536 Lisp_Object fontset
;
1537 Lisp_Object font_def
, registry
, family
;
1538 Lisp_Object encoding
, repertory
;
1539 Lisp_Object range_list
;
1540 struct charset
*charset
= NULL
;
1542 fontset
= check_fontset_name (name
);
1544 /* The arg FRAME is kept for backward compatibility. We only check
1547 CHECK_LIVE_FRAME (frame
);
1549 if (VECTORP (font_spec
))
1551 if (! FONT_SPEC_P (font_spec
))
1552 Fsignal (Qfont
, list2 (build_string ("invalid font-spec"), font_spec
));
1554 else if (CONSP (font_spec
))
1556 Lisp_Object args
[4];
1559 family
= XCAR (font_spec
);
1560 registry
= XCDR (font_spec
);
1562 if (! NILP (family
))
1564 CHECK_STRING (family
);
1565 args
[i
++] = QCfamily
;
1568 CHECK_STRING (registry
);
1569 args
[i
++] = QCregistry
;
1570 args
[i
++] = registry
;
1571 font_spec
= Ffont_spec (i
, args
);
1573 else if (STRINGP (font_spec
))
1575 Lisp_Object args
[2];
1578 args
[1] = font_spec
;
1579 font_spec
= Ffont_spec (2, args
);
1581 else if (! NILP (font_spec
))
1582 wrong_type_argument (intern ("font-spec"), font_spec
);
1584 if (! NILP (font_spec
))
1586 family
= AREF (font_spec
, FONT_FAMILY_INDEX
);
1587 if (! NILP (family
) && SYMBOLP (family
))
1588 family
= SYMBOL_NAME (family
);
1589 registry
= AREF (font_spec
, FONT_REGISTRY_INDEX
);
1590 if (! NILP (registry
) && SYMBOLP (registry
))
1591 registry
= SYMBOL_NAME (registry
);
1593 encoding
= find_font_encoding (concat2 (family
, registry
));
1594 if (NILP (encoding
))
1597 if (SYMBOLP (encoding
))
1599 CHECK_CHARSET (encoding
);
1600 encoding
= repertory
= CHARSET_SYMBOL_ID (encoding
);
1604 repertory
= XCDR (encoding
);
1605 encoding
= XCAR (encoding
);
1606 CHECK_CHARSET (encoding
);
1607 encoding
= CHARSET_SYMBOL_ID (encoding
);
1608 if (! NILP (repertory
) && SYMBOLP (repertory
))
1610 CHECK_CHARSET (repertory
);
1611 repertory
= CHARSET_SYMBOL_ID (repertory
);
1614 font_def
= Fmake_vector (make_number (3), font_spec
);
1615 ASET (font_def
, 1, encoding
);
1616 ASET (font_def
, 2, repertory
);
1621 if (CHARACTERP (target
))
1622 range_list
= Fcons (Fcons (target
, target
), Qnil
);
1623 else if (CONSP (target
))
1625 Lisp_Object from
, to
;
1627 from
= Fcar (target
);
1629 CHECK_CHARACTER (from
);
1630 CHECK_CHARACTER (to
);
1631 range_list
= Fcons (target
, Qnil
);
1633 else if (SYMBOLP (target
) && !NILP (target
))
1635 Lisp_Object script_list
;
1639 script_list
= XCHAR_TABLE (Vchar_script_table
)->extras
[0];
1640 if (! NILP (Fmemq (target
, script_list
)))
1642 val
= Fcons (target
, Qnil
);
1643 map_char_table (accumulate_script_ranges
, Qnil
, Vchar_script_table
,
1645 range_list
= XCDR (val
);
1646 if (EQ (target
, Qlatin
) && NILP (FONTSET_ASCII (fontset
)))
1648 if (VECTORP (font_spec
))
1649 val
= generate_ascii_font_name (FONTSET_NAME (fontset
),
1653 FONTSET_ASCII (fontset
) = val
;
1656 if (CHARSETP (target
))
1658 if (EQ (target
, Qascii
) && NILP (FONTSET_ASCII (fontset
)))
1660 if (VECTORP (font_spec
))
1661 font_spec
= generate_ascii_font_name (FONTSET_NAME (fontset
),
1663 FONTSET_ASCII (fontset
) = font_spec
;
1664 range_list
= Fcons (Fcons (make_number (0), make_number (127)),
1669 CHECK_CHARSET_GET_CHARSET (target
, charset
);
1672 else if (NILP (range_list
))
1673 error ("Invalid script or charset name: %s",
1674 SDATA (SYMBOL_NAME (target
)));
1676 else if (NILP (target
))
1677 range_list
= Fcons (Qnil
, Qnil
);
1679 error ("Invalid target for setting a font");
1684 font_def_arg
= font_def
;
1686 if (NILP (range_list
))
1687 from_arg
= to_arg
= 0;
1689 from_arg
= XINT (XCAR (XCAR (range_list
))),
1690 to_arg
= XINT (XCDR (XCAR (range_list
)));
1692 map_charset_chars (set_fontset_font
, Qnil
, fontset
, charset
,
1693 CHARSET_MIN_CODE (charset
),
1694 CHARSET_MAX_CODE (charset
));
1696 for (; CONSP (range_list
); range_list
= XCDR (range_list
))
1697 FONTSET_ADD (fontset
, XCAR (range_list
), font_def
, add
);
1699 /* Free all realized fontsets whose base is FONTSET. This way, the
1700 specified character(s) are surely redisplayed by a correct
1702 free_realized_fontsets (fontset
);
1708 DEFUN ("new-fontset", Fnew_fontset
, Snew_fontset
, 2, 2, 0,
1709 doc
: /* Create a new fontset NAME from font information in FONTLIST.
1711 FONTLIST is an alist of scripts vs the corresponding font specification list.
1712 Each element of FONTLIST has the form (SCRIPT FONT-SPEC ...), where a
1713 character of SCRIPT is displayed by a font that matches one of
1716 SCRIPT is a symbol that appears in the first extra slot of the
1717 char-table `char-script-table'.
1719 FONT-SPEC is a vector, a cons, or a string. See the documentation of
1720 `set-fontset-font' for the meaning. */)
1722 Lisp_Object name
, fontlist
;
1724 Lisp_Object fontset
;
1728 CHECK_STRING (name
);
1729 CHECK_LIST (fontlist
);
1731 id
= fs_query_fontset (name
, 0);
1734 name
= Fdowncase (name
);
1735 val
= split_font_name_into_vector (name
);
1736 if (NILP (val
) || NILP (AREF (val
, 12)) || NILP (AREF (val
, 13)))
1737 error ("Fontset name must be in XLFD format");
1738 if (strcmp (SDATA (AREF (val
, 12)), "fontset"))
1739 error ("Registry field of fontset name must be \"fontset\"");
1740 Vfontset_alias_alist
1741 = Fcons (Fcons (name
,
1742 concat2 (concat2 (AREF (val
, 12), build_string ("-")),
1744 Vfontset_alias_alist
);
1745 ASET (val
, 12, build_string ("iso8859-1"));
1746 fontset
= make_fontset (Qnil
, name
, Qnil
);
1747 FONTSET_ASCII (fontset
) = build_font_name_from_vector (val
);
1751 fontset
= FONTSET_FROM_ID (id
);;
1752 free_realized_fontsets (fontset
);
1753 Fset_char_table_range (fontset
, Qt
, Qnil
);
1756 for (; ! NILP (fontlist
); fontlist
= Fcdr (fontlist
))
1758 Lisp_Object elt
, script
;
1760 elt
= Fcar (fontlist
);
1761 script
= Fcar (elt
);
1763 if (CONSP (elt
) && (NILP (XCDR (elt
)) || CONSP (XCDR (elt
))))
1764 for (; CONSP (elt
); elt
= XCDR (elt
))
1765 Fset_fontset_font (name
, script
, XCAR (elt
), Qnil
, Qappend
);
1767 Fset_fontset_font (name
, script
, elt
, Qnil
, Qappend
);
1773 /* Alist of automatically created fontsets. Each element is a cons
1774 (FONTNAME . FONTSET-ID). */
1775 static Lisp_Object auto_fontset_alist
;
1778 new_fontset_from_font_name (Lisp_Object fontname
)
1785 fontname
= Fdowncase (fontname
);
1786 val
= Fassoc (fontname
, auto_fontset_alist
);
1788 return XINT (XCDR (val
));
1790 vec
= split_font_name_into_vector (fontname
);
1792 vec
= Fmake_vector (make_number (14), build_string (""));
1793 ASET (vec
, 12, build_string ("fontset"));
1794 if (NILP (auto_fontset_alist
))
1796 ASET (vec
, 13, build_string ("startup"));
1797 name
= build_font_name_from_vector (vec
);
1802 int len
= XINT (Flength (auto_fontset_alist
));
1804 sprintf (temp
, "auto%d", len
);
1805 ASET (vec
, 13, build_string (temp
));
1806 name
= build_font_name_from_vector (vec
);
1808 name
= Fnew_fontset (name
, list2 (list2 (Qascii
, fontname
),
1809 list2 (Fcons (make_number (0),
1810 make_number (MAX_CHAR
)),
1812 id
= fs_query_fontset (name
, 0);
1814 = Fcons (Fcons (fontname
, make_number (id
)), auto_fontset_alist
);
1818 #ifdef USE_FONT_BACKEND
1820 new_fontset_from_font (font_object
)
1821 Lisp_Object font_object
;
1823 Lisp_Object font_name
= font_get_name (font_object
);
1824 Lisp_Object font_spec
= font_get_spec (font_object
);
1825 Lisp_Object fontset_spec
, short_name
, name
, fontset
;
1827 if (NILP (auto_fontset_alist
))
1828 short_name
= build_string ("fontset-startup");
1832 int len
= XINT (Flength (auto_fontset_alist
));
1834 sprintf (temp
, "fontset-auto%d", len
);
1835 short_name
= build_string (temp
);
1837 fontset_spec
= Fcopy_sequence (font_spec
);
1838 ASET (fontset_spec
, FONT_REGISTRY_INDEX
, short_name
);
1839 name
= Ffont_xlfd_name (fontset_spec
);
1844 for (i
= 0; i
< FONT_SIZE_INDEX
; i
++)
1845 if ((i
!= FONT_FAMILY_INDEX
) && (i
!= FONT_REGISTRY_INDEX
))
1846 ASET (fontset_spec
, i
, Qnil
);
1847 name
= Ffont_xlfd_name (fontset_spec
);
1851 fontset
= make_fontset (Qnil
, name
, Qnil
);
1852 FONTSET_ASCII (fontset
) = font_name
;
1853 font_spec
= Fcons (SYMBOL_NAME (AREF (font_spec
, FONT_FAMILY_INDEX
)),
1854 SYMBOL_NAME (AREF (font_spec
, FONT_REGISTRY_INDEX
)));
1855 Fset_fontset_font (name
, Qlatin
, font_spec
, Qnil
, Qnil
);
1856 XSETCDR (font_spec
, build_string ("iso10646-1"));
1857 Fset_fontset_font (name
, Qlatin
, font_spec
, Qnil
, Qappend
);
1858 Fset_fontset_font (name
, Qnil
, font_spec
, Qnil
, Qnil
);
1859 return XINT (FONTSET_ID (fontset
));
1863 fontset_ascii_font (f
, id
)
1867 Lisp_Object fontset
= FONTSET_FROM_ID (id
);
1868 Lisp_Object ascii_slot
= FONTSET_ASCII (fontset
);
1869 Lisp_Object val
, font_object
;
1871 if (CONSP (ascii_slot
))
1873 Lisp_Object ascii_font_name
= XCAR (ascii_slot
);
1876 for (val
= XCDR (ascii_slot
); ! NILP (val
); val
= XCDR (val
))
1878 Lisp_Object frame
= font_get_frame (XCAR (val
));
1880 if (NILP (frame
) || XFRAME (frame
) == f
)
1882 font_object
= XCAR (val
);
1883 if (XSAVE_VALUE (font_object
)->integer
== 0)
1885 font_object
= font_open_by_name (f
, SDATA (ascii_font_name
));
1886 XSETCAR (val
, font_object
);
1891 if (NILP (font_object
))
1893 font_object
= font_open_by_name (f
, SDATA (ascii_font_name
));
1894 XSETCDR (ascii_slot
, Fcons (font_object
, XCDR (ascii_slot
)));
1899 font_object
= font_open_by_name (f
, SDATA (ascii_slot
));
1900 FONTSET_ASCII (fontset
) = Fcons (ascii_slot
, Fcons (font_object
, Qnil
));
1902 if (NILP (font_object
))
1904 return XSAVE_VALUE (font_object
)->pointer
;
1907 #endif /* USE_FONT_BACKEND */
1909 DEFUN ("font-info", Ffont_info
, Sfont_info
, 1, 2, 0,
1910 doc
: /* Return information about a font named NAME on frame FRAME.
1911 If FRAME is omitted or nil, use the selected frame.
1912 The returned value is a vector of OPENED-NAME, FULL-NAME, CHARSET, SIZE,
1913 HEIGHT, BASELINE-OFFSET, RELATIVE-COMPOSE, and DEFAULT-ASCENT,
1915 OPENED-NAME is the name used for opening the font,
1916 FULL-NAME is the full name of the font,
1917 SIZE is the maximum bound width of the font,
1918 HEIGHT is the height of the font,
1919 BASELINE-OFFSET is the upward offset pixels from ASCII baseline,
1920 RELATIVE-COMPOSE and DEFAULT-ASCENT are the numbers controlling
1921 how to compose characters.
1922 If the named font is not yet loaded, return nil. */)
1924 Lisp_Object name
, frame
;
1927 struct font_info
*fontp
;
1929 Lisp_Object font_object
;
1931 (*check_window_system_func
) ();
1933 CHECK_STRING (name
);
1934 name
= Fdowncase (name
);
1936 frame
= selected_frame
;
1937 CHECK_LIVE_FRAME (frame
);
1940 if (!query_font_func
)
1941 error ("Font query function is not supported");
1943 #ifdef USE_FONT_BACKEND
1944 if (enable_font_backend
)
1946 font_object
= font_open_by_name (f
, SDATA (name
));
1947 if (NILP (font_object
))
1950 fontp
= (struct font_info
*) XSAVE_VALUE (font_object
)->pointer
;
1953 #endif /* USE_FONT_BACKEND */
1954 fontp
= (*query_font_func
) (f
, SDATA (name
));
1958 info
= Fmake_vector (make_number (7), Qnil
);
1960 XVECTOR (info
)->contents
[0] = build_string (fontp
->name
);
1961 XVECTOR (info
)->contents
[1] = build_string (fontp
->full_name
);
1962 XVECTOR (info
)->contents
[2] = make_number (fontp
->size
);
1963 XVECTOR (info
)->contents
[3] = make_number (fontp
->height
);
1964 XVECTOR (info
)->contents
[4] = make_number (fontp
->baseline_offset
);
1965 XVECTOR (info
)->contents
[5] = make_number (fontp
->relative_compose
);
1966 XVECTOR (info
)->contents
[6] = make_number (fontp
->default_ascent
);
1968 #ifdef USE_FONT_BACKEND
1969 if (! NILP (font_object
))
1970 font_close_object (f
, font_object
);
1971 #endif /* USE_FONT_BACKEND */
1976 /* Return a cons (FONT-NAME . GLYPH-CODE).
1977 FONT-NAME is the font name for the character at POSITION in the current
1978 buffer. This is computed from all the text properties and overlays
1979 that apply to POSITION. POSTION may be nil, in which case,
1980 FONT-NAME is the font name for display the character CH with the
1983 GLYPH-CODE is the glyph code in the font to use for the character.
1985 If the 2nd optional arg CH is non-nil, it is a character to check
1986 the font instead of the character at POSITION.
1988 It returns nil in the following cases:
1990 (1) The window system doesn't have a font for the character (thus
1991 it is displayed by an empty box).
1993 (2) The character code is invalid.
1995 (3) If POSITION is not nil, and the current buffer is not displayed
1998 In addition, the returned font name may not take into account of
1999 such redisplay engine hooks as what used in jit-lock-mode if
2000 POSITION is currently not visible. */
2003 DEFUN ("internal-char-font", Finternal_char_font
, Sinternal_char_font
, 1, 2, 0,
2004 doc
: /* For internal use only. */)
2006 Lisp_Object position
, ch
;
2008 int pos
, pos_byte
, dummy
;
2013 Lisp_Object charset
, rfont_def
;
2016 if (NILP (position
))
2018 CHECK_CHARACTER (ch
);
2020 f
= XFRAME (selected_frame
);
2021 face_id
= DEFAULT_FACE_ID
;
2027 Lisp_Object window
, charset
;
2030 CHECK_NUMBER_COERCE_MARKER (position
);
2031 pos
= XINT (position
);
2032 if (pos
< BEGV
|| pos
>= ZV
)
2033 args_out_of_range_3 (position
, make_number (BEGV
), make_number (ZV
));
2034 pos_byte
= CHAR_TO_BYTE (pos
);
2036 c
= FETCH_CHAR (pos_byte
);
2042 window
= Fget_buffer_window (Fcurrent_buffer (), Qnil
);
2045 w
= XWINDOW (window
);
2046 f
= XFRAME (w
->frame
);
2047 face_id
= face_at_buffer_position (w
, pos
, -1, -1, &dummy
, pos
+ 100, 0);
2048 charset
= Fget_char_property (position
, Qcharset
, Qnil
);
2049 if (CHARSETP (charset
))
2050 cs_id
= XINT (CHARSET_SYMBOL_ID (charset
));
2054 if (! CHAR_VALID_P (c
, 0))
2056 face_id
= FACE_FOR_CHAR (f
, FACE_FROM_ID (f
, face_id
), c
, pos
, Qnil
);
2057 face
= FACE_FROM_ID (f
, face_id
);
2058 rfont_def
= fontset_font (FONTSET_FROM_ID (face
->fontset
), c
, face
, cs_id
);
2059 #ifdef USE_FONT_BACKEND
2060 if (enable_font_backend
)
2062 if (VECTORP (rfont_def
) && ! NILP (AREF (rfont_def
, 3)))
2064 Lisp_Object font_object
= AREF (rfont_def
, 3);
2065 struct font
*font
= XSAVE_VALUE (font_object
)->pointer
;
2066 unsigned code
= font
->driver
->encode_char (font
, c
);
2067 Lisp_Object fontname
= font_get_name (font_object
);
2069 if (code
== FONT_INVALID_CODE
)
2071 if (code
<= MOST_POSITIVE_FIXNUM
)
2072 return Fcons (fontname
, make_number (code
));
2073 return Fcons (fontname
, Fcons (make_number (code
>> 16),
2074 make_number (code
& 0xFFFF)));
2078 #endif /* USE_FONT_BACKEND */
2079 if (VECTORP (rfont_def
) && STRINGP (AREF (rfont_def
, 3)))
2081 Lisp_Object font_def
;
2082 struct font_info
*fontp
;
2083 struct charset
*charset
;
2087 font_def
= AREF (rfont_def
, 2);
2088 charset
= CHARSET_FROM_ID (XINT (AREF (font_def
, 1)));
2089 code
= ENCODE_CHAR (charset
, c
);
2090 if (code
== CHARSET_INVALID_CODE (charset
))
2091 return (Fcons (AREF (rfont_def
, 3), Qnil
));
2092 STORE_XCHAR2B (&char2b
, ((code
>> 8) & 0xFF), (code
& 0xFF));
2093 fontp
= (*get_font_info_func
) (f
, XINT (AREF (rfont_def
, 1)));
2094 FRAME_RIF (f
)->encode_char (c
, &char2b
, fontp
, charset
, NULL
);
2095 code
= (XCHAR2B_BYTE1 (&char2b
) << 8) | XCHAR2B_BYTE2 (&char2b
);
2096 return (Fcons (AREF (rfont_def
, 3), make_number (code
)));
2102 DEFUN ("fontset-info", Ffontset_info
, Sfontset_info
, 1, 2, 0,
2103 doc
: /* Return information about a fontset FONTSET on frame FRAME.
2104 The value is a char-table of which elements has this form.
2106 ((FONT-PATTERN OPENED-FONT ...) ...)
2108 FONT-PATTERN is a vector:
2110 [ FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY ]
2112 or a string of font name pattern.
2114 OPENED-FONT is a name of a font actually opened.
2116 The char-table has one extra slot. The value is a char-table
2117 containing the information about the derived fonts from the default
2118 fontset. The format is the same as abobe. */)
2120 Lisp_Object fontset
, frame
;
2123 Lisp_Object
*realized
[2], fontsets
[2], tables
[2];
2124 Lisp_Object val
, elt
;
2127 (*check_window_system_func
) ();
2129 fontset
= check_fontset_name (fontset
);
2132 frame
= selected_frame
;
2133 CHECK_LIVE_FRAME (frame
);
2136 /* Recode fontsets realized on FRAME from the base fontset FONTSET
2137 in the table `realized'. */
2138 realized
[0] = (Lisp_Object
*) alloca (sizeof (Lisp_Object
)
2139 * ASIZE (Vfontset_table
));
2140 for (i
= j
= 0; i
< ASIZE (Vfontset_table
); i
++)
2142 elt
= FONTSET_FROM_ID (i
);
2144 && EQ (FONTSET_BASE (elt
), fontset
)
2145 && EQ (FONTSET_FRAME (elt
), frame
))
2146 realized
[0][j
++] = elt
;
2148 realized
[0][j
] = Qnil
;
2150 realized
[1] = (Lisp_Object
*) alloca (sizeof (Lisp_Object
)
2151 * ASIZE (Vfontset_table
));
2152 for (i
= j
= 0; ! NILP (realized
[0][i
]); i
++)
2154 elt
= FONTSET_DEFAULT (realized
[0][i
]);
2156 realized
[1][j
++] = elt
;
2158 realized
[1][j
] = Qnil
;
2160 tables
[0] = Fmake_char_table (Qfontset_info
, Qnil
);
2161 tables
[1] = Fmake_char_table (Qnil
, Qnil
);
2162 XCHAR_TABLE (tables
[0])->extras
[0] = tables
[1];
2163 fontsets
[0] = fontset
;
2164 fontsets
[1] = Vdefault_fontset
;
2166 /* Accumulate information of the fontset in TABLE. The format of
2167 each element is ((FONT-SPEC OPENED-FONT ...) ...). */
2168 for (k
= 0; k
<= 1; k
++)
2170 for (c
= 0; c
<= MAX_CHAR
; )
2174 if (c
<= MAX_5_BYTE_CHAR
)
2176 val
= char_table_ref_and_range (fontsets
[k
], c
, &from
, &to
);
2177 if (to
> MAX_5_BYTE_CHAR
)
2178 to
= MAX_5_BYTE_CHAR
;
2182 val
= FONTSET_FALLBACK (fontsets
[k
]);
2189 /* At first, set ALIST to ((FONT-SPEC) ...). */
2190 for (alist
= Qnil
, i
= 0; i
< ASIZE (val
); i
++)
2191 alist
= Fcons (Fcons (AREF (AREF (val
, i
), 0), Qnil
), alist
);
2192 alist
= Fnreverse (alist
);
2194 /* Then store opend font names to cdr of each elements. */
2195 for (i
= 0; ! NILP (realized
[k
][i
]); i
++)
2197 if (c
<= MAX_5_BYTE_CHAR
)
2198 val
= FONTSET_REF (realized
[k
][i
], c
);
2200 val
= FONTSET_FALLBACK (realized
[k
][i
]);
2201 if (! VECTORP (val
))
2203 /* VAL is [int int ?
2204 [FACE-ID FONT-INDEX FONT-DEF FONT-NAME] ...].
2205 If a font of an element is already opened,
2206 FONT-NAME is the name of a opened font. */
2207 for (j
= 3; j
< ASIZE (val
); j
++)
2208 if (STRINGP (AREF (AREF (val
, j
), 3)))
2210 Lisp_Object font_idx
;
2212 font_idx
= AREF (AREF (val
, j
), 1);
2213 elt
= Fassq (AREF (AREF (AREF (val
, j
), 2), 0), alist
);
2215 && NILP (Fmemq (font_idx
, XCDR(elt
))))
2216 nconc2 (elt
, Fcons (font_idx
, Qnil
));
2219 for (val
= alist
; CONSP (val
); val
= XCDR (val
))
2220 for (elt
= XCDR (XCAR (val
)); CONSP (elt
); elt
= XCDR (elt
))
2222 struct font_info
*font_info
2223 = (*get_font_info_func
) (f
, XINT (XCAR (elt
)));
2224 XSETCAR (elt
, build_string (font_info
->full_name
));
2227 /* Store ALIST in TBL for characters C..TO. */
2228 if (c
<= MAX_5_BYTE_CHAR
)
2229 char_table_set_range (tables
[k
], c
, to
, alist
);
2231 XCHAR_TABLE (tables
[k
])->defalt
= alist
;
2241 DEFUN ("fontset-font", Ffontset_font
, Sfontset_font
, 2, 3, 0,
2242 doc
: /* Return a font name pattern for character CH in fontset NAME.
2243 If NAME is t, find a pattern in the default fontset.
2245 The value has the form (FAMILY . REGISTRY), where FAMILY is a font
2246 family name and REGISTRY is a font registry name. This is actually
2247 the first font name pattern for CH in the fontset or in the default
2250 If the 2nd optional arg ALL is non-nil, return a list of all font name
2253 Lisp_Object name
, ch
, all
;
2256 Lisp_Object fontset
, elt
, list
, repertory
, val
;
2259 fontset
= check_fontset_name (name
);
2261 CHECK_CHARACTER (ch
);
2266 for (i
= 0, elt
= FONTSET_REF (fontset
, c
); i
< 2;
2267 i
++, elt
= FONTSET_FALLBACK (fontset
))
2269 for (j
= 0; j
< ASIZE (elt
); j
++)
2271 val
= AREF (elt
, j
);
2272 repertory
= AREF (val
, 1);
2273 if (INTEGERP (repertory
))
2275 struct charset
*charset
= CHARSET_FROM_ID (XINT (repertory
));
2277 if (! CHAR_CHARSET_P (c
, charset
))
2280 else if (CHAR_TABLE_P (repertory
))
2282 if (NILP (CHAR_TABLE_REF (repertory
, c
)))
2285 val
= AREF (val
, 0);
2286 val
= Fcons (AREF (val
, 0), AREF (val
, 5));
2289 list
= Fcons (val
, list
);
2291 if (EQ (fontset
, Vdefault_fontset
))
2293 fontset
= Vdefault_fontset
;
2295 return (Fnreverse (list
));
2298 DEFUN ("fontset-list", Ffontset_list
, Sfontset_list
, 0, 0, 0,
2299 doc
: /* Return a list of all defined fontset names. */)
2302 Lisp_Object fontset
, list
;
2306 for (i
= 0; i
< ASIZE (Vfontset_table
); i
++)
2308 fontset
= FONTSET_FROM_ID (i
);
2310 && BASE_FONTSET_P (fontset
))
2311 list
= Fcons (FONTSET_NAME (fontset
), list
);
2318 #ifdef FONTSET_DEBUG
2321 dump_fontset (fontset
)
2322 Lisp_Object fontset
;
2326 vec
= Fmake_vector (make_number (3), Qnil
);
2327 ASET (vec
, 0, FONTSET_ID (fontset
));
2329 if (BASE_FONTSET_P (fontset
))
2331 ASET (vec
, 1, FONTSET_NAME (fontset
));
2337 frame
= FONTSET_FRAME (fontset
);
2340 FRAME_PTR f
= XFRAME (frame
);
2342 if (FRAME_LIVE_P (f
))
2344 Fcons (FONTSET_NAME (FONTSET_BASE (fontset
)), f
->name
));
2347 Fcons (FONTSET_NAME (FONTSET_BASE (fontset
)), Qnil
));
2349 if (!NILP (FONTSET_DEFAULT (fontset
)))
2350 ASET (vec
, 2, FONTSET_ID (FONTSET_DEFAULT (fontset
)));
2355 DEFUN ("fontset-list-all", Ffontset_list_all
, Sfontset_list_all
, 0, 0, 0,
2356 doc
: /* Return a brief summary of all fontsets for debug use. */)
2362 for (i
= 0, val
= Qnil
; i
< ASIZE (Vfontset_table
); i
++)
2363 if (! NILP (AREF (Vfontset_table
, i
)))
2364 val
= Fcons (dump_fontset (AREF (Vfontset_table
, i
)), val
);
2365 return (Fnreverse (val
));
2367 #endif /* FONTSET_DEBUG */
2372 if (!load_font_func
)
2373 /* Window system initializer should have set proper functions. */
2376 DEFSYM (Qfontset
, "fontset");
2377 Fput (Qfontset
, Qchar_table_extra_slots
, make_number (9));
2378 DEFSYM (Qfontset_info
, "fontset-info");
2379 Fput (Qfontset_info
, Qchar_table_extra_slots
, make_number (1));
2381 DEFSYM (Qprepend
, "prepend");
2382 DEFSYM (Qappend
, "append");
2383 DEFSYM (Qlatin
, "latin");
2385 Vcached_fontset_data
= Qnil
;
2386 staticpro (&Vcached_fontset_data
);
2388 Vfontset_table
= Fmake_vector (make_number (32), Qnil
);
2389 staticpro (&Vfontset_table
);
2391 Vdefault_fontset
= Fmake_char_table (Qfontset
, Qnil
);
2392 staticpro (&Vdefault_fontset
);
2393 FONTSET_ID (Vdefault_fontset
) = make_number (0);
2394 FONTSET_NAME (Vdefault_fontset
)
2395 = build_string ("-*-*-*-*-*-*-*-*-*-*-*-*-fontset-default");
2396 AREF (Vfontset_table
, 0) = Vdefault_fontset
;
2397 next_fontset_id
= 1;
2399 auto_fontset_alist
= Qnil
;
2400 staticpro (&auto_fontset_alist
);
2402 DEFVAR_LISP ("font-encoding-alist", &Vfont_encoding_alist
,
2404 Alist of fontname patterns vs the corresponding encoding and repertory info.
2405 Each element looks like (REGEXP . (ENCODING . REPERTORY)),
2406 where ENCODING is a charset or a char-table,
2407 and REPERTORY is a charset, a char-table, or nil.
2409 If ENCDING and REPERTORY are the same, the element can have the form
2410 \(REGEXP . ENCODING).
2412 ENCODING is for converting a character to a glyph code of the font.
2413 If ENCODING is a charset, encoding a character by the charset gives
2414 the corresponding glyph code. If ENCODING is a char-table, looking up
2415 the table by a character gives the corresponding glyph code.
2417 REPERTORY specifies a repertory of characters supported by the font.
2418 If REPERTORY is a charset, all characters beloging to the charset are
2419 supported. If REPERTORY is a char-table, all characters who have a
2420 non-nil value in the table are supported. It REPERTORY is nil, Emacs
2421 gets the repertory information by an opened font and ENCODING. */);
2422 Vfont_encoding_alist
= Qnil
;
2424 DEFVAR_LISP ("font-encoding-charset-alist", &Vfont_encoding_charset_alist
,
2426 Alist of charsets vs the charsets to determine the preferred font encoding.
2427 Each element looks like (CHARSET . ENCDOING-CHARSET),
2428 where ENCODING-CHARSET is a charset registered in the variable
2429 `font-encoding-alist' as ENCODING.
2431 When a text has a property `charset' and the value is CHARSET, a font
2432 whose encoding corresponds to ENCODING-CHARSET is preferred. */);
2433 Vfont_encoding_charset_alist
= Qnil
;
2435 DEFVAR_LISP ("use-default-ascent", &Vuse_default_ascent
,
2437 Char table of characters whose ascent values should be ignored.
2438 If an entry for a character is non-nil, the ascent value of the glyph
2439 is assumed to be what specified by _MULE_DEFAULT_ASCENT property of a font.
2441 This affects how a composite character which contains
2442 such a character is displayed on screen. */);
2443 Vuse_default_ascent
= Qnil
;
2445 DEFVAR_LISP ("ignore-relative-composition", &Vignore_relative_composition
,
2447 Char table of characters which is not composed relatively.
2448 If an entry for a character is non-nil, a composition sequence
2449 which contains that character is displayed so that
2450 the glyph of that character is put without considering
2451 an ascent and descent value of a previous character. */);
2452 Vignore_relative_composition
= Qnil
;
2454 DEFVAR_LISP ("alternate-fontname-alist", &Valternate_fontname_alist
,
2455 doc
: /* Alist of fontname vs list of the alternate fontnames.
2456 When a specified font name is not found, the corresponding
2457 alternate fontnames (if any) are tried instead. */);
2458 Valternate_fontname_alist
= Qnil
;
2460 DEFVAR_LISP ("fontset-alias-alist", &Vfontset_alias_alist
,
2461 doc
: /* Alist of fontset names vs the aliases. */);
2462 Vfontset_alias_alist
= Fcons (Fcons (FONTSET_NAME (Vdefault_fontset
),
2463 build_string ("fontset-default")),
2466 DEFVAR_LISP ("vertical-centering-font-regexp",
2467 &Vvertical_centering_font_regexp
,
2468 doc
: /* *Regexp matching font names that require vertical centering on display.
2469 When a character is displayed with such fonts, the character is displayed
2470 at the vertical center of lines. */);
2471 Vvertical_centering_font_regexp
= Qnil
;
2473 DEFVAR_LISP ("otf-script-alist", &Votf_script_alist
,
2474 doc
: /* Alist of OpenType script tags vs the corresponding script names. */);
2475 Votf_script_alist
= Qnil
;
2477 defsubr (&Squery_fontset
);
2478 defsubr (&Snew_fontset
);
2479 defsubr (&Sset_fontset_font
);
2480 defsubr (&Sfont_info
);
2481 defsubr (&Sinternal_char_font
);
2482 defsubr (&Sfontset_info
);
2483 defsubr (&Sfontset_font
);
2484 defsubr (&Sfontset_list
);
2485 #ifdef FONTSET_DEBUG
2486 defsubr (&Sfontset_list_all
);
2490 /* arch-tag: ea861585-2f5f-4e5b-9849-d04a9c3a3537
2491 (do not change this comment) */