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"
59 #ifdef USE_FONT_BACKEND
61 #endif /* USE_FONT_BACKEND */
65 #define xassert(X) do {if (!(X)) abort ();} while (0)
68 #else /* not FONTSET_DEBUG */
69 #define xassert(X) (void) 0
70 #endif /* not FONTSET_DEBUG */
72 EXFUN (Fclear_face_cache
, 1);
76 A fontset is a collection of font related information to give
77 similar appearance (style, etc) of characters. A fontset has two
78 roles. One is to use for the frame parameter `font' as if it is an
79 ASCII font. In that case, Emacs uses the font specified for
80 `ascii' script for the frame's default font.
82 Another role, the more important one, is to provide information
83 about which font to use for each non-ASCII character.
85 There are two kinds of fontsets; base and realized. A base fontset
86 is created by `new-fontset' from Emacs Lisp explicitly. A realized
87 fontset is created implicitly when a face is realized for ASCII
88 characters. A face is also realized for non-ASCII characters based
89 on an ASCII face. All of non-ASCII faces based on the same ASCII
90 face share the same realized fontset.
92 A fontset object is implemented by a char-table whose default value
93 and parent are always nil.
95 An element of a base fontset is a vector of FONT-DEFs which itself
96 is a vector [ FONT-SPEC ENCODING REPERTORY ].
99 [ FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY ]
102 where FAMILY, WEIGHT, SLANT, SWIDTH, ADSTYLE, REGISTRY, and
103 FONT-NAME are strings.
105 Note: Currently WEIGHT through ADSTYLE are ignored.
107 ENCODING is a charset ID that can convert characters to glyph codes
108 of the corresponding font.
110 REPERTORY is a charset ID, a char-table, or nil. If REPERTORY is a
111 charset ID, the repertory of the charset exactly matches with that
112 of the font. If REPERTORY is a char-table, all characters who have
113 a non-nil value in the table are supported. If REPERTORY is nil,
114 we consult with the font itself to get the repertory.
116 ENCODING and REPERTORY are extracted from the variable
117 Vfont_encoding_alist by using a font name generated from FONT-SPEC
118 (if it is a vector) or FONT-NAME as a matching target.
121 An element of a realized fontset is nil or t, or has this form:
123 [CHARSET-ORDERED-LIST-TICK PREFERRED-CHARSET-ID
124 PREFERRED-RFONT-DEF RFONT-DEF0 RFONT-DEF1 ...].
126 RFONT-DEFn (i.e. Realized FONT-DEF) has this form:
128 [ FACE-ID FONT-INDEX FONT-DEF OPENED-FONT-NAME ]
130 RFONT-DEFn is automatically reordered by the current charset
133 The value nil means that we have not yet generated the above vector
134 from the base of the fontset.
136 The value t means that no font is available for the corresponding
140 A fontset has 9 extra slots.
142 The 1st slot: the ID number of the fontset
145 base: the name of the fontset
150 realized: the base fontset
154 realized: the frame that the fontset belongs to
157 base: the font name for ASCII characters
162 realized: the ID number of a face to use for characters that
163 has no font in a realized fontset.
167 realized: Alist of font index vs the corresponding repertory
172 realized: If the base is not the default fontset, a fontset
173 realized from the default fontset, else nil.
176 base: Same as element value (but for fallback fonts).
179 All fontsets are recorded in the vector Vfontset_table.
184 There's a special base fontset named `default fontset' which
185 defines the default font specifications. When a base fontset
186 doesn't specify a font for a specific character, the corresponding
187 value in the default fontset is used.
189 The parent of a realized fontset created for such a face that has
190 no fontset is the default fontset.
193 These structures are hidden from the other codes than this file.
194 The other codes handle fontsets only by their ID numbers. They
195 usually use the variable name `fontset' for IDs. But, in this
196 file, we always use varialbe name `id' for IDs, and name `fontset'
197 for an actual fontset object, i.e., char-table.
201 /********** VARIABLES and FUNCTION PROTOTYPES **********/
203 extern Lisp_Object Qfont
;
204 static Lisp_Object Qfontset
;
205 static Lisp_Object Qfontset_info
;
206 static Lisp_Object Qprepend
, Qappend
;
207 static Lisp_Object Qlatin
;
209 /* Vector containing all fontsets. */
210 static Lisp_Object Vfontset_table
;
212 /* Next possibly free fontset ID. Usually this keeps the minimum
213 fontset ID not yet used. */
214 static int next_fontset_id
;
216 /* The default fontset. This gives default FAMILY and REGISTRY of
217 font for each character. */
218 static Lisp_Object Vdefault_fontset
;
220 Lisp_Object Vfont_encoding_alist
;
221 Lisp_Object Vuse_default_ascent
;
222 Lisp_Object Vignore_relative_composition
;
223 Lisp_Object Valternate_fontname_alist
;
224 Lisp_Object Vfontset_alias_alist
;
225 Lisp_Object Vvertical_centering_font_regexp
;
226 Lisp_Object Votf_script_alist
;
228 /* The following six are declarations of callback functions depending
229 on window system. See the comments in src/fontset.h for more
232 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
233 struct font_info
*(*get_font_info_func
) P_ ((FRAME_PTR f
, int font_idx
));
235 /* Return a list of font names which matches PATTERN. See the documentation
236 of `x-list-fonts' for more details. */
237 Lisp_Object (*list_fonts_func
) P_ ((struct frame
*f
,
242 /* Load a font named NAME for frame F and return a pointer to the
243 information of the loaded font. If loading is failed, return 0. */
244 struct font_info
*(*load_font_func
) P_ ((FRAME_PTR f
, char *name
, int));
246 /* Return a pointer to struct font_info of a font named NAME for frame F. */
247 struct font_info
*(*query_font_func
) P_ ((FRAME_PTR f
, char *name
));
249 /* Additional function for setting fontset or changing fontset
250 contents of frame F. */
251 void (*set_frame_fontset_func
) P_ ((FRAME_PTR f
, Lisp_Object arg
,
252 Lisp_Object oldval
));
254 /* To find a CCL program, fs_load_font calls this function.
255 The argument is a pointer to the struct font_info.
256 This function set the member `encoder' of the structure. */
257 void (*find_ccl_program_func
) P_ ((struct font_info
*));
259 Lisp_Object (*get_font_repertory_func
) P_ ((struct frame
*,
260 struct font_info
*));
262 /* Check if any window system is used now. */
263 void (*check_window_system_func
) P_ ((void));
266 /* Prototype declarations for static functions. */
267 static Lisp_Object fontset_add
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
,
269 static Lisp_Object fontset_font
P_ ((Lisp_Object
, int, struct face
*, int));
270 static Lisp_Object make_fontset
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
));
271 static Lisp_Object fontset_pattern_regexp
P_ ((Lisp_Object
));
272 static void accumulate_script_ranges
P_ ((Lisp_Object
, Lisp_Object
,
274 Lisp_Object find_font_encoding
P_ ((Lisp_Object
));
276 static void set_fontset_font
P_ ((Lisp_Object
, Lisp_Object
));
280 /* Return 1 if ID is a valid fontset id, else return 0. */
283 fontset_id_valid_p (id
)
286 return (id
>= 0 && id
< ASIZE (Vfontset_table
) - 1);
293 /********** MACROS AND FUNCTIONS TO HANDLE FONTSET **********/
295 /* Return the fontset with ID. No check of ID's validness. */
296 #define FONTSET_FROM_ID(id) AREF (Vfontset_table, id)
298 /* Macros to access special values of FONTSET. */
299 #define FONTSET_ID(fontset) XCHAR_TABLE (fontset)->extras[0]
301 /* Macros to access special values of (base) FONTSET. */
302 #define FONTSET_NAME(fontset) XCHAR_TABLE (fontset)->extras[1]
303 #define FONTSET_ASCII(fontset) XCHAR_TABLE (fontset)->extras[4]
305 /* Macros to access special values of (realized) FONTSET. */
306 #define FONTSET_BASE(fontset) XCHAR_TABLE (fontset)->extras[2]
307 #define FONTSET_FRAME(fontset) XCHAR_TABLE (fontset)->extras[3]
308 #define FONTSET_NOFONT_FACE(fontset) XCHAR_TABLE (fontset)->extras[5]
309 #define FONTSET_REPERTORY(fontset) XCHAR_TABLE (fontset)->extras[6]
310 #define FONTSET_DEFAULT(fontset) XCHAR_TABLE (fontset)->extras[7]
312 /* For both base and realized fontset. */
313 #define FONTSET_FALLBACK(fontset) XCHAR_TABLE (fontset)->extras[8]
315 #define BASE_FONTSET_P(fontset) (NILP (FONTSET_BASE (fontset)))
318 /* Return the element of FONTSET for the character C. If FONTSET is a
319 base fontset other then the default fontset and FONTSET doesn't
320 contain information for C, return the information in the default
323 #define FONTSET_REF(fontset, c) \
324 (EQ (fontset, Vdefault_fontset) \
325 ? CHAR_TABLE_REF (fontset, c) \
326 : fontset_ref ((fontset), (c)))
329 fontset_ref (fontset
, c
)
335 elt
= CHAR_TABLE_REF (fontset
, c
);
336 if (NILP (elt
) && ! EQ (fontset
, Vdefault_fontset
)
337 /* Don't check Vdefault_fontset for a realized fontset. */
338 && NILP (FONTSET_BASE (fontset
)))
339 elt
= CHAR_TABLE_REF (Vdefault_fontset
, c
);
344 /* Return the element of FONTSET for the character C, set FROM and TO
345 to the range of characters around C that have the same value as C.
346 If FONTSET is a base fontset other then the default fontset and
347 FONTSET doesn't contain information for C, return the information
348 in the default fontset. */
350 #define FONTSET_REF_AND_RANGE(fontset, c, form, to) \
351 (EQ (fontset, Vdefault_fontset) \
352 ? char_table_ref_and_range (fontset, c, &from, &to) \
353 : fontset_ref_and_range (fontset, c, &from, &to))
356 fontset_ref_and_range (fontset
, c
, from
, to
)
363 elt
= char_table_ref_and_range (fontset
, c
, from
, to
);
364 if (NILP (elt
) && ! EQ (fontset
, Vdefault_fontset
)
365 /* Don't check Vdefault_fontset for a realized fontset. */
366 && NILP (FONTSET_BASE (fontset
)))
370 elt
= char_table_ref_and_range (Vdefault_fontset
, c
, &from1
, &to1
);
380 /* Set elements of FONTSET for characters in RANGE to the value ELT.
381 RANGE is a cons (FROM . TO), where FROM and TO are character codes
382 specifying a range. */
384 #define FONTSET_SET(fontset, range, elt) \
385 Fset_char_table_range ((fontset), (range), (elt))
388 /* Modify the elements of FONTSET for characters in RANGE by replacing
389 with ELT or adding ELT. RANGE is a cons (FROM . TO), where FROM
390 and TO are character codes specifying a range. If ADD is nil,
391 replace with ELT, if ADD is `prepend', prepend ELT, otherwise,
394 #define FONTSET_ADD(fontset, range, elt, add) \
397 ? (FONTSET_FALLBACK (fontset) = Fmake_vector (make_number (1), (elt))) \
398 : Fset_char_table_range ((fontset), (range), \
399 Fmake_vector (make_number (1), (elt)))) \
400 : fontset_add ((fontset), (range), (elt), (add)))
403 fontset_add (fontset
, range
, elt
, add
)
404 Lisp_Object fontset
, range
, elt
, add
;
407 int idx
= (EQ (add
, Qappend
) ? 0 : 1);
409 args
[1 - idx
] = Fmake_vector (make_number (1), elt
);
413 int from
= XINT (XCAR (range
));
414 int to
= XINT (XCDR (range
));
418 args
[idx
] = char_table_ref_and_range (fontset
, from
, &from1
, &to1
);
421 char_table_set_range (fontset
, from
, to1
,
422 NILP (args
[idx
]) ? args
[1 - idx
]
423 : Fvconcat (2, args
));
429 args
[idx
] = FONTSET_FALLBACK (fontset
);
430 FONTSET_FALLBACK (fontset
)
431 = NILP (args
[idx
]) ? args
[1 - idx
] : Fvconcat (2, args
);
437 /* Update FONTSET_ELEMENT which has this form:
438 [CHARSET-ORDERED-LIST-TICK PREFERRED-CHARSET-ID PREFERRED-RFONT-DEF
439 RFONT-DEF0 RFONT-DEF1 ...].
440 Reorder RFONT-DEFs according to the current order of charset
441 (Vcharset_ordered_list), and update CHARSET-ORDERED-LIST-TICK to
445 reorder_font_vector (fontset_element
)
446 Lisp_Object fontset_element
;
448 Lisp_Object list
, *new_vec
;
449 Lisp_Object font_def
;
451 int *charset_id_table
;
454 ASET (fontset_element
, 0, make_number (charset_ordered_list_tick
));
455 size
= ASIZE (fontset_element
) - 3;
457 /* No need to reorder VEC. */
459 charset_id_table
= (int *) alloca (sizeof (int) * size
);
460 new_vec
= (Lisp_Object
*) alloca (sizeof (Lisp_Object
) * size
);
462 /* At first, extract ENCODING (a chaset ID) from each FONT-DEF.
463 FONT-DEF has this form:
464 [FACE-ID FONT-INDEX [ FONT-SPEC ENCODING REPERTORY ]] */
465 for (i
= 0; i
< size
; i
++)
467 font_def
= AREF (fontset_element
, i
+ 3);
468 if (VECTORP (AREF (font_def
, 2))
469 && INTEGERP (AREF (AREF (font_def
, 2), 1)))
470 charset_id_table
[i
] = XINT (AREF (AREF (font_def
, 2), 1));
472 charset_id_table
[i
] = -1;
475 /* Then, store FONT-DEFs in NEW_VEC in the correct order. */
476 for (idx
= 0, list
= Vcharset_ordered_list
;
477 idx
< size
&& CONSP (list
); list
= XCDR (list
))
479 for (i
= 0; i
< size
; i
++)
480 if (charset_id_table
[i
] == XINT (XCAR (list
)))
481 new_vec
[idx
++] = AREF (fontset_element
, i
+ 3);
483 for (i
= 0; i
< size
; i
++)
484 if (charset_id_table
[i
] < 0)
485 new_vec
[idx
++] = AREF (fontset_element
, i
+ 3);
487 /* At last, update FONT-DEFs. */
488 for (i
= 0; i
< size
; i
++)
489 ASET (fontset_element
, i
+ 3, new_vec
[i
]);
493 /* Load a font matching the font related attributes in FACE->lface and
494 font pattern in FONT_DEF of FONTSET, and return an index of the
495 font. FONT_DEF has this form:
496 [ FONT-SPEC ENCODING REPERTORY ]
497 If REPERTORY is nil, generate a char-table representing the font
498 repertory by looking into the font itself. */
501 load_font_get_repertory (f
, face
, font_def
, fontset
)
504 Lisp_Object font_def
;
508 struct font_info
*font_info
;
511 font_name
= choose_face_font (f
, face
->lface
, AREF (font_def
, 0), NULL
);
512 charset
= XINT (AREF (font_def
, 1));
513 if (! (font_info
= fs_load_font (f
, font_name
, charset
)))
516 if (NILP (AREF (font_def
, 2))
517 && NILP (Fassq (make_number (font_info
->font_idx
),
518 FONTSET_REPERTORY (fontset
))))
520 /* We must look into the font to get the correct repertory as a
522 Lisp_Object repertory
;
524 repertory
= (*get_font_repertory_func
) (f
, font_info
);
525 FONTSET_REPERTORY (fontset
)
526 = Fcons (Fcons (make_number (font_info
->font_idx
), repertory
),
527 FONTSET_REPERTORY (fontset
));
530 return font_info
->font_idx
;
533 static Lisp_Object fontset_find_font
P_ ((Lisp_Object
, int, struct face
*,
536 /* Return RFONT-DEF (vector) in the realized fontset FONTSET for the
537 character C. If the corresponding font is not yet opened, open it
538 (if FACE is not NULL) or return Qnil (if FACE is NULL).
539 If no proper font is found for C, return Qnil.
540 ID is a charset-id that must be preferred, or -1 meaning no
542 If FALLBACK if nonzero, search only fallback fonts. */
545 fontset_find_font (fontset
, c
, face
, id
, fallback
)
551 Lisp_Object base_fontset
, elt
, vec
, font_def
;
554 FRAME_PTR f
= XFRAME (FONTSET_FRAME (fontset
));
556 base_fontset
= FONTSET_BASE (fontset
);
558 vec
= CHAR_TABLE_REF (fontset
, c
);
560 vec
= FONTSET_FALLBACK (fontset
);
563 /* We have not yet decided a font for C. */
569 elt
= FONTSET_REF_AND_RANGE (base_fontset
, c
, from
, to
);
571 elt
= FONTSET_FALLBACK (base_fontset
);
572 range
= Fcons (make_number (from
), make_number (to
));
575 /* Qt means we have no font for characters of this range. */
580 /* Build a vector [ -1 -1 nil NEW-ELT0 NEW-ELT1 NEW-ELT2 ... ],
581 where the first -1 is to force reordering of NEW-ELTn,
582 NEW-ELTn is [nil nil AREF (elt, n) nil]. */
583 #ifdef USE_FONT_BACKEND
585 && enable_font_backend
586 && EQ (base_fontset
, Vdefault_fontset
))
587 /* Extra one element is for an automatically added
588 font-def specifying only a script. */
589 vec
= Fmake_vector (make_number (ASIZE (elt
) + 4), Qnil
);
591 #endif /* not USE_FONT_BACKEND */
592 vec
= Fmake_vector (make_number (ASIZE (elt
) + 3), Qnil
);
593 ASET (vec
, 0, make_number (-1));
594 ASET (vec
, 1, make_number (-1));
595 for (i
= 0; i
< ASIZE (elt
); i
++)
599 tmp
= Fmake_vector (make_number (5), Qnil
);
600 ASET (tmp
, 2, AREF (elt
, i
));
601 ASET (vec
, 3 + i
, tmp
);
603 #ifdef USE_FONT_BACKEND
605 && enable_font_backend
606 && EQ (base_fontset
, Vdefault_fontset
))
608 Lisp_Object script
, font_spec
;
610 script
= CHAR_TABLE_REF (Vchar_script_table
, c
);
612 script
= intern ("latin");
613 font_spec
= Ffont_spec (0, NULL
);
614 ASET (font_spec
, FONT_REGISTRY_INDEX
, Qiso10646_1
);
615 ASET (font_spec
, FONT_EXTRA_INDEX
,
616 Fcons (Fcons (QCscript
, script
), Qnil
));
617 font_def
= Fmake_vector (make_number (3), Qnil
);
618 ASET (font_def
, 0, font_spec
);
619 elt
= Fmake_vector (make_number (5), Qnil
);
620 ASET (elt
, 2, font_def
);
621 ASET (vec
, 3 + i
, elt
);
623 #endif /* USE_FONT_BACKEND */
625 /* Then store it in the fontset. */
627 FONTSET_SET (fontset
, range
, vec
);
629 FONTSET_FALLBACK (fontset
) = vec
;
635 if (XINT (AREF (vec
, 0)) != charset_ordered_list_tick
)
636 /* The priority of charsets is changed after we selected a face
638 reorder_font_vector (vec
);
642 else if (id
== XFASTINT (AREF (vec
, 1)))
646 ASET (vec
, 1, make_number (id
));
647 for (i
= 3; i
< ASIZE (vec
); i
++)
648 if (id
== XFASTINT (AREF (AREF (AREF (vec
, i
), 2), 1)))
652 ASET (vec
, 2, AREF (vec
, i
));
662 /* Find the first available font in the vector of RFONT-DEF. */
663 for (; i
< ASIZE (vec
); i
++)
668 /* ELT == [ FACE-ID FONT-INDEX FONT-DEF OPENED-FONT-NAME ] */
669 if (INTEGERP (AREF (elt
, 1)) && XINT (AREF (elt
, 1)) < 0)
670 /* We couldn't open this font last time. */
673 if (!face
&& NILP (AREF (elt
, 1)))
674 /* We have not yet opened the font. */
677 font_def
= AREF (elt
, 2);
678 /* FONT_DEF == [ FONT-SPEC ENCODING REPERTORY ] */
680 #ifdef USE_FONT_BACKEND
681 if (enable_font_backend
)
683 /* ELT == [ FACE-ID FONT-INDEX FONT-DEF FONT-ENTITY FONT-OBJECT ] */
684 Lisp_Object font_entity
= AREF (elt
, 3);
685 Lisp_Object font_object
= AREF (elt
, 4);
686 Lisp_Object font_spec
= AREF (font_def
, 0);
689 if (NILP (font_entity
))
691 if (! FONT_SPEC_P (font_spec
))
693 /* FONT_SPEC is FONT-NAME or (FAMILY . REGISTRY). */
694 font_spec
= Ffont_spec (0, NULL
);
695 if (STRINGP (AREF (font_def
, 0)))
696 font_merge_old_spec (AREF (font_def
, 0), Qnil
, Qnil
,
700 Lisp_Object family
= AREF (AREF (font_def
, 0), 0);
701 Lisp_Object registry
= AREF (AREF (font_def
, 0), 5);;
703 font_merge_old_spec (Qnil
, family
, registry
, font_spec
);
705 ASET (font_def
, 0, font_spec
);
707 font_entity
= font_find_for_lface (f
, face
->lface
, font_spec
);
708 ASET (elt
, 3, font_entity
);
709 if (NILP (font_entity
))
711 ASET (elt
, 1, make_number (-1));
716 has_char
= font_has_char (f
, font_entity
, c
);
719 if (NILP (font_object
))
721 font_object
= font_open_for_lface (f
, font_entity
,
722 face
->lface
, font_spec
);
723 ASET (elt
, 4, font_object
);
724 if (NILP (font_object
))
726 ASET (elt
, 1, make_number (-1));
730 ASET (elt
, 1, make_number (0));
731 ASET (elt
, 4, font_object
);
733 && font_encode_char (font_object
, c
) == FONT_INVALID_CODE
)
737 #endif /* USE_FONT_BACKEND */
739 if (INTEGERP (AREF (font_def
, 2)))
741 /* The repertory is specified by charset ID. */
742 struct charset
*charset
743 = CHARSET_FROM_ID (XINT (AREF (font_def
, 2)));
745 if (! CHAR_CHARSET_P (c
, charset
))
746 /* This font can't display C. */
749 else if (CHAR_TABLE_P (AREF (font_def
, 2)))
751 /* The repertory is specified by a char table. */
752 if (NILP (CHAR_TABLE_REF (AREF (font_def
, 2), c
)))
753 /* This font can't display C. */
760 if (! INTEGERP (AREF (elt
, 1)))
762 /* We have not yet opened a font matching this spec.
763 Open the best matching font now and register the
765 struct font_info
*font_info
;
767 font_idx
= load_font_get_repertory (f
, face
, font_def
, fontset
);
768 ASET (elt
, 1, make_number (font_idx
));
770 /* This means that we couldn't find a font matching
773 font_info
= (*get_font_info_func
) (f
, font_idx
);
774 ASET (elt
, 3, build_string (font_info
->full_name
));
777 slot
= Fassq (AREF (elt
, 1), FONTSET_REPERTORY (fontset
));
778 xassert (CONSP (slot
));
779 if (NILP (CHAR_TABLE_REF (XCDR (slot
), c
)))
780 /* This font can't display C. */
784 /* Now we have decided to use this font spec to display C. */
785 if (! INTEGERP (AREF (elt
, 1)))
787 /* But not yet opened the best matching font. */
788 struct font_info
*font_info
;
790 font_idx
= load_font_get_repertory (f
, face
, font_def
, fontset
);
791 ASET (elt
, 1, make_number (font_idx
));
793 /* Can't open it. Try the other one. */
795 font_info
= (*get_font_info_func
) (f
, font_idx
);
796 ASET (elt
, 3, build_string (font_info
->full_name
));
799 /* Now we have the opened font. */
807 fontset_font (fontset
, c
, face
, id
)
813 Lisp_Object rfont_def
;
814 Lisp_Object base_fontset
;
816 /* Try a font-group for C. */
817 rfont_def
= fontset_find_font (fontset
, c
, face
, id
, 0);
818 if (! NILP (rfont_def
))
820 base_fontset
= FONTSET_BASE (fontset
);
821 /* Try a font-group for C of the default fontset. */
822 if (! EQ (base_fontset
, Vdefault_fontset
))
824 if (NILP (FONTSET_DEFAULT (fontset
)))
825 FONTSET_DEFAULT (fontset
)
826 = make_fontset (FONTSET_FRAME (fontset
), Qnil
, Vdefault_fontset
);
827 rfont_def
= fontset_find_font (FONTSET_DEFAULT (fontset
), c
, face
, id
, 0);
829 if (! NILP (rfont_def
))
831 /* Try a fallback font-group. */
832 rfont_def
= fontset_find_font (fontset
, c
, face
, id
, 1);
833 if (! NILP (rfont_def
))
835 /* Try a fallback font-group of the default fontset . */
836 if (! EQ (base_fontset
, Vdefault_fontset
))
837 rfont_def
= fontset_find_font (FONTSET_DEFAULT (fontset
), c
, face
, id
, 1);
841 /* Return a newly created fontset with NAME. If BASE is nil, make a
842 base fontset. Otherwise make a realized fontset whose base is
846 make_fontset (frame
, name
, base
)
847 Lisp_Object frame
, name
, base
;
850 int size
= ASIZE (Vfontset_table
);
851 int id
= next_fontset_id
;
853 /* Find a free slot in Vfontset_table. Usually, next_fontset_id is
854 the next available fontset ID. So it is expected that this loop
855 terminates quickly. In addition, as the last element of
856 Vfontset_table is always nil, we don't have to check the range of
858 while (!NILP (AREF (Vfontset_table
, id
))) id
++;
862 /* We must grow Vfontset_table. */
866 tem
= Fmake_vector (make_number (size
+ 32), Qnil
);
867 for (i
= 0; i
< size
; i
++)
868 AREF (tem
, i
) = AREF (Vfontset_table
, i
);
869 Vfontset_table
= tem
;
872 fontset
= Fmake_char_table (Qfontset
, Qnil
);
874 FONTSET_ID (fontset
) = make_number (id
);
877 FONTSET_NAME (fontset
) = name
;
881 FONTSET_NAME (fontset
) = Qnil
;
882 FONTSET_FRAME (fontset
) = frame
;
883 FONTSET_BASE (fontset
) = base
;
886 ASET (Vfontset_table
, id
, fontset
);
887 next_fontset_id
= id
+ 1;
892 /* Set the ASCII font of the default fontset to FONTNAME if that is
895 set_default_ascii_font (fontname
)
896 Lisp_Object fontname
;
898 if (! STRINGP (FONTSET_ASCII (Vdefault_fontset
)))
900 int id
= fs_query_fontset (fontname
, 2);
903 fontname
= FONTSET_ASCII (FONTSET_FROM_ID (id
));
904 FONTSET_ASCII (Vdefault_fontset
)= fontname
;
909 /********** INTERFACES TO xfaces.c, xfns.c, and dispextern.h **********/
911 /* Return the name of the fontset who has ID. */
919 fontset
= FONTSET_FROM_ID (id
);
920 return FONTSET_NAME (fontset
);
924 /* Return the ASCII font name of the fontset who has ID. */
930 Lisp_Object fontset
, elt
;
932 fontset
= FONTSET_FROM_ID (id
);
933 elt
= FONTSET_ASCII (fontset
);
934 #ifdef USE_FONT_BACKEND
937 #endif /* USE_FONT_BACKEND */
938 /* It is assured that ELT is always a string (i.e. fontname
944 /* Free fontset of FACE defined on frame F. Called from
945 free_realized_face. */
948 free_face_fontset (f
, face
)
954 fontset
= AREF (Vfontset_table
, face
->fontset
);
955 xassert (!NILP (fontset
) && ! BASE_FONTSET_P (fontset
));
956 xassert (f
== XFRAME (FONTSET_FRAME (fontset
)));
957 ASET (Vfontset_table
, face
->fontset
, Qnil
);
958 if (face
->fontset
< next_fontset_id
)
959 next_fontset_id
= face
->fontset
;
960 if (! NILP (FONTSET_DEFAULT (fontset
)))
962 int id
= XINT (FONTSET_ID (FONTSET_DEFAULT (fontset
)));
964 fontset
= AREF (Vfontset_table
, id
);
965 xassert (!NILP (fontset
) && ! BASE_FONTSET_P (fontset
));
966 xassert (f
== XFRAME (FONTSET_FRAME (fontset
)));
967 ASET (Vfontset_table
, id
, Qnil
);
968 if (id
< next_fontset_id
)
969 next_fontset_id
= face
->fontset
;
974 /* Return 1 if FACE is suitable for displaying character C.
975 Otherwise return 0. Called from the macro FACE_SUITABLE_FOR_CHAR_P
976 when C is not an ASCII character. */
979 face_suitable_for_char_p (face
, c
)
983 Lisp_Object fontset
, rfont_def
;
985 fontset
= FONTSET_FROM_ID (face
->fontset
);
986 rfont_def
= fontset_font (fontset
, c
, NULL
, -1);
987 return (VECTORP (rfont_def
)
988 && INTEGERP (AREF (rfont_def
, 0))
989 && face
->id
== XINT (AREF (rfont_def
, 0)));
993 /* Return ID of face suitable for displaying character C on frame F.
994 FACE must be reazlied for ASCII characters in advance. Called from
995 the macro FACE_FOR_CHAR. */
998 face_for_char (f
, face
, c
, pos
, object
)
1004 Lisp_Object fontset
, charset
, rfont_def
;
1008 if (ASCII_CHAR_P (c
))
1009 return face
->ascii_face
->id
;
1011 xassert (fontset_id_valid_p (face
->fontset
));
1012 fontset
= FONTSET_FROM_ID (face
->fontset
);
1013 xassert (!BASE_FONTSET_P (fontset
));
1018 charset
= Fget_char_property (make_number (pos
), Qcharset
, object
);
1021 else if (CHARSETP (charset
))
1022 id
= XINT (CHARSET_SYMBOL_ID (charset
));
1024 rfont_def
= fontset_font (fontset
, c
, face
, id
);
1025 if (VECTORP (rfont_def
))
1027 #ifdef USE_FONT_BACKEND
1028 if (enable_font_backend
1029 && NILP (AREF (rfont_def
, 0)))
1031 struct font
*font
= XSAVE_VALUE (AREF (rfont_def
, 4))->pointer
;
1033 face_id
= face_for_font (f
, font
, face
);
1034 ASET (rfont_def
, 0, make_number (face_id
));
1037 #endif /* USE_FONT_BACKEND */
1038 if (NILP (AREF (rfont_def
, 0)))
1040 /* We have not yet made a realized face that uses this font. */
1041 int font_idx
= XINT (AREF (rfont_def
, 1));
1043 face_id
= lookup_non_ascii_face (f
, font_idx
, face
);
1044 ASET (rfont_def
, 0, make_number (face_id
));
1046 return XINT (AREF (rfont_def
, 0));
1049 if (NILP (FONTSET_NOFONT_FACE (fontset
)))
1051 face_id
= lookup_non_ascii_face (f
, -1, face
);
1052 FONTSET_NOFONT_FACE (fontset
) = make_number (face_id
);
1054 return XINT (FONTSET_NOFONT_FACE (fontset
));
1058 /* Make a realized fontset for ASCII face FACE on frame F from the
1059 base fontset BASE_FONTSET_ID. If BASE_FONTSET_ID is -1, use the
1060 default fontset as the base. Value is the id of the new fontset.
1061 Called from realize_x_face. */
1064 make_fontset_for_ascii_face (f
, base_fontset_id
, face
)
1066 int base_fontset_id
;
1069 Lisp_Object base_fontset
, fontset
, frame
;
1071 XSETFRAME (frame
, f
);
1072 if (base_fontset_id
>= 0)
1074 base_fontset
= FONTSET_FROM_ID (base_fontset_id
);
1075 if (!BASE_FONTSET_P (base_fontset
))
1076 base_fontset
= FONTSET_BASE (base_fontset
);
1077 xassert (BASE_FONTSET_P (base_fontset
));
1078 if (! BASE_FONTSET_P (base_fontset
))
1082 base_fontset
= Vdefault_fontset
;
1084 fontset
= make_fontset (frame
, Qnil
, base_fontset
);
1086 Lisp_Object elt
, rfont_def
, val
;
1088 elt
= FONTSET_REF (base_fontset
, 0);
1089 xassert (VECTORP (elt
) && ASIZE (elt
) > 0);
1090 #ifdef USE_FONT_BACKEND
1091 rfont_def
= Fmake_vector (make_number (5), Qnil
);
1092 if (enable_font_backend
&& face
->font_info
)
1094 struct font
*font
= (struct font
*) face
->font_info
;
1096 ASET (rfont_def
, 3, font
->entity
);
1097 ASET (rfont_def
, 4, font_find_object (font
));
1100 #endif /* USE_FONT_BACKEND */
1102 rfont_def
= Fmake_vector (make_number (4), Qnil
);
1103 ASET (rfont_def
, 3, build_string (face
->font_name
));
1105 ASET (rfont_def
, 1, make_number (face
->font_info_id
));
1106 ASET (rfont_def
, 2, AREF (elt
, 0));
1107 elt
= Fmake_vector (make_number (4), Qnil
);
1108 ASET (elt
, 0, make_number (charset_ordered_list_tick
));
1109 ASET (elt
, 1, make_number (charset_ascii
));
1110 ASET (elt
, 2, rfont_def
);
1111 ASET (elt
, 3, rfont_def
);
1113 val
= Fcons (Qlatin
, Qnil
);
1114 map_char_table (accumulate_script_ranges
, Qnil
, Vchar_script_table
, val
);
1115 for (val
= XCDR (val
); CONSP (val
); val
= XCDR (val
))
1116 char_table_set_range (fontset
, XINT (XCAR (XCAR (val
))),
1117 XINT (XCDR (XCAR (val
))), elt
);
1118 FONTSET_FALLBACK (fontset
) = elt
;
1120 return XINT (FONTSET_ID (fontset
));
1124 #if defined(WINDOWSNT) && defined (_MSC_VER)
1125 #pragma optimize("", off)
1128 /* Load a font named FONTNAME on frame F. Return a pointer to the
1129 struct font_info of the loaded font. If loading fails, return
1130 NULL. CHARSET is an ID of charset to encode characters for this
1131 font. If it is -1, find one from Vfont_encoding_alist. */
1134 fs_load_font (f
, fontname
, charset
)
1139 struct font_info
*fontp
;
1140 Lisp_Object fullname
;
1143 /* No way to get fontname. */
1146 fontp
= (*load_font_func
) (f
, fontname
, 0);
1147 if (! fontp
|| fontp
->charset
>= 0)
1150 fontname
= fontp
->full_name
;
1151 fullname
= build_string (fontp
->full_name
);
1155 Lisp_Object charset_symbol
;
1157 charset_symbol
= find_font_encoding (fullname
);
1158 if (CONSP (charset_symbol
))
1159 charset_symbol
= XCAR (charset_symbol
);
1160 if (NILP (charset_symbol
))
1161 charset_symbol
= Qascii
;
1162 charset
= XINT (CHARSET_SYMBOL_ID (charset_symbol
));
1164 fontp
->charset
= charset
;
1165 fontp
->vertical_centering
= 0;
1166 fontp
->font_encoder
= NULL
;
1168 if (charset
!= charset_ascii
)
1170 fontp
->vertical_centering
1171 = (STRINGP (Vvertical_centering_font_regexp
)
1172 && (fast_string_match_ignore_case
1173 (Vvertical_centering_font_regexp
, fullname
) >= 0));
1175 if (find_ccl_program_func
)
1176 (*find_ccl_program_func
) (fontp
);
1182 #if defined(WINDOWSNT) && defined (_MSC_VER)
1183 #pragma optimize("", on)
1187 /* Return ENCODING or a cons of ENCODING and REPERTORY of the font
1188 FONTNAME. ENCODING is a charset symbol that specifies the encoding
1189 of the font. REPERTORY is a charset symbol or nil. */
1193 find_font_encoding (fontname
)
1194 Lisp_Object fontname
;
1196 Lisp_Object tail
, elt
;
1198 for (tail
= Vfont_encoding_alist
; CONSP (tail
); tail
= XCDR (tail
))
1202 && STRINGP (XCAR (elt
))
1203 && fast_string_match_ignore_case (XCAR (elt
), fontname
) >= 0
1204 && (SYMBOLP (XCDR (elt
))
1205 ? CHARSETP (XCDR (elt
))
1206 : CONSP (XCDR (elt
)) && CHARSETP (XCAR (XCDR (elt
)))))
1207 return (XCDR (elt
));
1209 /* We don't know the encoding of this font. Let's assume `ascii'. */
1214 /* Cache data used by fontset_pattern_regexp. The car part is a
1215 pattern string containing at least one wild card, the cdr part is
1216 the corresponding regular expression. */
1217 static Lisp_Object Vcached_fontset_data
;
1219 #define CACHED_FONTSET_NAME (SDATA (XCAR (Vcached_fontset_data)))
1220 #define CACHED_FONTSET_REGEX (XCDR (Vcached_fontset_data))
1222 /* If fontset name PATTERN contains any wild card, return regular
1223 expression corresponding to PATTERN. */
1226 fontset_pattern_regexp (pattern
)
1227 Lisp_Object pattern
;
1229 if (!index (SDATA (pattern
), '*')
1230 && !index (SDATA (pattern
), '?'))
1231 /* PATTERN does not contain any wild cards. */
1234 if (!CONSP (Vcached_fontset_data
)
1235 || strcmp (SDATA (pattern
), CACHED_FONTSET_NAME
))
1237 /* We must at first update the cached data. */
1238 unsigned char *regex
, *p0
, *p1
;
1239 int ndashes
= 0, nstars
= 0;
1241 for (p0
= SDATA (pattern
); *p0
; p0
++)
1245 else if (*p0
== '*')
1249 /* If PATTERN is not full XLFD we conert "*" to ".*". Otherwise
1250 we convert "*" to "[^-]*" which is much faster in regular
1251 expression matching. */
1253 p1
= regex
= (unsigned char *) alloca (SBYTES (pattern
) + 2 * nstars
+ 1);
1255 p1
= regex
= (unsigned char *) alloca (SBYTES (pattern
) + 5 * nstars
+ 1);
1258 for (p0
= SDATA (pattern
); *p0
; p0
++)
1265 *p1
++ = '[', *p1
++ = '^', *p1
++ = '-', *p1
++ = ']';
1268 else if (*p0
== '?')
1276 Vcached_fontset_data
= Fcons (build_string (SDATA (pattern
)),
1277 build_string (regex
));
1280 return CACHED_FONTSET_REGEX
;
1283 /* Return ID of the base fontset named NAME. If there's no such
1284 fontset, return -1. NAME_PATTERN specifies how to treat NAME as this:
1285 0: pattern containing '*' and '?' as wildcards
1286 1: regular expression
1287 2: literal fontset name
1291 fs_query_fontset (name
, name_pattern
)
1298 name
= Fdowncase (name
);
1299 if (name_pattern
!= 1)
1301 tem
= Frassoc (name
, Vfontset_alias_alist
);
1303 tem
= Fassoc (name
, Vfontset_alias_alist
);
1304 if (CONSP (tem
) && STRINGP (XCAR (tem
)))
1306 else if (name_pattern
== 0)
1308 tem
= fontset_pattern_regexp (name
);
1317 for (i
= 0; i
< ASIZE (Vfontset_table
); i
++)
1319 Lisp_Object fontset
, this_name
;
1321 fontset
= FONTSET_FROM_ID (i
);
1323 || !BASE_FONTSET_P (fontset
))
1326 this_name
= FONTSET_NAME (fontset
);
1327 if (name_pattern
== 1
1328 ? fast_string_match (name
, this_name
) >= 0
1329 : !strcmp (SDATA (name
), SDATA (this_name
)))
1336 DEFUN ("query-fontset", Fquery_fontset
, Squery_fontset
, 1, 2, 0,
1337 doc
: /* Return the name of a fontset that matches PATTERN.
1338 The value is nil if there is no matching fontset.
1339 PATTERN can contain `*' or `?' as a wildcard
1340 just as X font name matching algorithm allows.
1341 If REGEXPP is non-nil, PATTERN is a regular expression. */)
1343 Lisp_Object pattern
, regexpp
;
1345 Lisp_Object fontset
;
1348 (*check_window_system_func
) ();
1350 CHECK_STRING (pattern
);
1352 if (SCHARS (pattern
) == 0)
1355 id
= fs_query_fontset (pattern
, !NILP (regexpp
));
1359 fontset
= FONTSET_FROM_ID (id
);
1360 return FONTSET_NAME (fontset
);
1363 /* Return a list of base fontset names matching PATTERN on frame F. */
1366 list_fontsets (f
, pattern
, size
)
1368 Lisp_Object pattern
;
1371 Lisp_Object frame
, regexp
, val
;
1374 XSETFRAME (frame
, f
);
1376 regexp
= fontset_pattern_regexp (pattern
);
1379 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
1381 Lisp_Object fontset
, name
;
1383 fontset
= FONTSET_FROM_ID (id
);
1385 || !BASE_FONTSET_P (fontset
)
1386 || !EQ (frame
, FONTSET_FRAME (fontset
)))
1388 name
= FONTSET_NAME (fontset
);
1390 if (STRINGP (regexp
)
1391 ? (fast_string_match (regexp
, name
) < 0)
1392 : strcmp (SDATA (pattern
), SDATA (name
)))
1395 val
= Fcons (Fcopy_sequence (FONTSET_NAME (fontset
)), val
);
1402 /* Free all realized fontsets whose base fontset is BASE. */
1405 free_realized_fontsets (base
)
1411 /* For the moment, this doesn't work because free_realized_face
1412 doesn't remove FACE from a cache. Until we find a solution, we
1413 suppress this code, and simply use Fclear_face_cache even though
1414 that is not efficient. */
1416 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
1418 Lisp_Object
this = AREF (Vfontset_table
, id
);
1420 if (EQ (FONTSET_BASE (this), base
))
1424 for (tail
= FONTSET_FACE_ALIST (this); CONSP (tail
);
1427 FRAME_PTR f
= XFRAME (FONTSET_FRAME (this));
1428 int face_id
= XINT (XCDR (XCAR (tail
)));
1429 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1431 /* Face THIS itself is also freed by the following call. */
1432 free_realized_face (f
, face
);
1438 /* But, we don't have to call Fclear_face_cache if no fontset has
1439 been realized from BASE. */
1440 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
1442 Lisp_Object
this = AREF (Vfontset_table
, id
);
1444 if (EQ (FONTSET_BASE (this), base
))
1446 Fclear_face_cache (Qt
);
1454 /* Check validity of NAME as a fontset name and return the
1455 corresponding fontset. If not valid, signal an error.
1456 If NAME is t, return Vdefault_fontset. */
1459 check_fontset_name (name
)
1465 return Vdefault_fontset
;
1467 CHECK_STRING (name
);
1468 /* First try NAME as literal. */
1469 id
= fs_query_fontset (name
, 2);
1471 /* For backward compatibility, try again NAME as pattern. */
1472 id
= fs_query_fontset (name
, 0);
1474 error ("Fontset `%s' does not exist", SDATA (name
));
1475 return FONTSET_FROM_ID (id
);
1479 accumulate_script_ranges (arg
, range
, val
)
1480 Lisp_Object arg
, range
, val
;
1482 if (EQ (XCAR (arg
), val
))
1485 XSETCDR (arg
, Fcons (Fcons (XCAR (range
), XCDR (range
)), XCDR (arg
)));
1487 XSETCDR (arg
, Fcons (Fcons (range
, range
), XCDR (arg
)));
1492 /* Return an ASCII font name generated from fontset name NAME and
1493 ASCII font specification ASCII_SPEC. NAME is a string conforming
1494 to XLFD. ASCII_SPEC is a vector:
1495 [FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY]. */
1497 static INLINE Lisp_Object
1498 generate_ascii_font_name (name
, ascii_spec
)
1499 Lisp_Object name
, ascii_spec
;
1504 vec
= split_font_name_into_vector (name
);
1505 for (i
= FONT_SPEC_FAMILY_INDEX
; i
<= FONT_SPEC_ADSTYLE_INDEX
; i
++)
1506 if (! NILP (AREF (ascii_spec
, i
)))
1507 ASET (vec
, 1 + i
, AREF (ascii_spec
, i
));
1508 if (! NILP (AREF (ascii_spec
, FONT_SPEC_REGISTRY_INDEX
)))
1509 ASET (vec
, 12, AREF (ascii_spec
, FONT_SPEC_REGISTRY_INDEX
));
1510 return build_font_name_from_vector (vec
);
1513 /* Variables referred in set_fontset_font. They are set before
1514 map_charset_chars is called in Fset_fontset_font. */
1515 static Lisp_Object font_def_arg
, add_arg
;
1516 static int from_arg
, to_arg
;
1518 /* Callback function for map_charset_chars in Fset_fontset_font. In
1519 FONTSET, set font_def_arg in a fashion specified by add_arg for
1520 characters in RANGE while ignoring the range between from_arg and
1524 set_fontset_font (fontset
, range
)
1525 Lisp_Object fontset
, range
;
1527 if (from_arg
< to_arg
)
1529 int from
= XINT (XCAR (range
)), to
= XINT (XCDR (range
));
1531 if (from
< from_arg
)
1537 range2
= Fcons (make_number (to_arg
), XCDR (range
));
1538 FONTSET_ADD (fontset
, range
, font_def_arg
, add_arg
);
1542 range
= Fcons (XCAR (range
), make_number (from_arg
));
1544 else if (to
<= to_arg
)
1549 range
= Fcons (make_number (to_arg
), XCDR (range
));
1552 FONTSET_ADD (fontset
, range
, font_def_arg
, add_arg
);
1556 DEFUN ("set-fontset-font", Fset_fontset_font
, Sset_fontset_font
, 3, 5, 0,
1558 Modify fontset NAME to use FONT-SPEC for TARGET characters.
1560 TARGET may be a cons; (FROM . TO), where FROM and TO are characters.
1561 In that case, use FONT-SPEC for all characters in the range FROM and
1564 TARGET may be a script name symbol. In that case, use FONT-SPEC for
1565 all characters that belong to the script.
1567 TARGET may be a charset. In that case, use FONT-SPEC for all
1568 characters in the charset.
1570 TARGET may be nil. In that case, use FONT-SPEC for any characters for
1571 that no FONT-SPEC is specified.
1573 FONT-SPEC may one of these:
1574 * A cons (FAMILY . REGISTRY), where FAMILY is a font family name and
1575 REGISTRY is a font registry name. FAMILY may contains foundry
1576 name, and REGISTRY may contains encoding name.
1577 * A font name string.
1579 Optional 4th argument FRAME, if non-nil, is a frame. This argument is
1580 kept for backward compatibility and has no meaning.
1582 Optional 5th argument ADD, if non-nil, specifies how to add FONT-SPEC
1583 to the font specifications for TARGET previously set. If it is
1584 `prepend', FONT-SPEC is prepended. If it is `append', FONT-SPEC is
1585 appended. By default, FONT-SPEC overrides the previous settings. */)
1586 (name
, target
, font_spec
, frame
, add
)
1587 Lisp_Object name
, target
, font_spec
, frame
, add
;
1589 Lisp_Object fontset
;
1590 Lisp_Object font_def
, registry
, family
;
1591 Lisp_Object encoding
, repertory
;
1592 Lisp_Object range_list
;
1593 struct charset
*charset
= NULL
;
1595 fontset
= check_fontset_name (name
);
1597 /* The arg FRAME is kept for backward compatibility. We only check
1600 CHECK_LIVE_FRAME (frame
);
1602 if (VECTORP (font_spec
))
1604 /* FONT_SPEC should have this form:
1605 [ FAMILY WEIGHT SLANT WIDTH ADSTYLE REGISTRY ]
1606 This is a feature not yet documented because WEIGHT thru
1607 ADSTYLE are ignored for the moment. */
1610 if (ASIZE (font_spec
) != FONT_SPEC_MAX_INDEX
)
1611 args_out_of_range (make_number (FONT_SPEC_MAX_INDEX
),
1612 make_number (ASIZE (font_spec
)));
1614 font_spec
= Fcopy_sequence (font_spec
);
1615 for (j
= 0; j
< FONT_SPEC_MAX_INDEX
- 1; j
++)
1616 if (! NILP (AREF (font_spec
, j
)))
1618 CHECK_STRING (AREF (font_spec
, j
));
1619 ASET (font_spec
, j
, Fdowncase (AREF (font_spec
, j
)));
1621 family
= AREF (font_spec
, FONT_SPEC_FAMILY_INDEX
);
1622 /* REGISTRY should not be omitted. */
1623 CHECK_STRING (AREF (font_spec
, FONT_SPEC_REGISTRY_INDEX
));
1624 registry
= AREF (font_spec
, FONT_SPEC_REGISTRY_INDEX
);
1626 else if (CONSP (font_spec
))
1628 family
= XCAR (font_spec
);
1629 registry
= XCDR (font_spec
);
1631 if (! NILP (family
))
1633 CHECK_STRING (family
);
1634 family
= Fdowncase (family
);
1636 CHECK_STRING (registry
);
1637 registry
= Fdowncase (registry
);
1638 font_spec
= Fmake_vector (make_number (FONT_SPEC_MAX_INDEX
), Qnil
);
1639 ASET (font_spec
, FONT_SPEC_FAMILY_INDEX
, family
);
1640 ASET (font_spec
, FONT_SPEC_REGISTRY_INDEX
, registry
);
1644 CHECK_STRING (font_spec
);
1645 font_spec
= Fdowncase (font_spec
);
1648 if (STRINGP (font_spec
))
1649 encoding
= find_font_encoding (font_spec
);
1651 encoding
= find_font_encoding (concat2 (family
, registry
));
1652 if (NILP (encoding
))
1655 if (SYMBOLP (encoding
))
1657 CHECK_CHARSET (encoding
);
1658 encoding
= repertory
= CHARSET_SYMBOL_ID (encoding
);
1662 repertory
= XCDR (encoding
);
1663 encoding
= XCAR (encoding
);
1664 CHECK_CHARSET (encoding
);
1665 encoding
= CHARSET_SYMBOL_ID (encoding
);
1666 if (! NILP (repertory
) && SYMBOLP (repertory
))
1668 CHECK_CHARSET (repertory
);
1669 repertory
= CHARSET_SYMBOL_ID (repertory
);
1672 font_def
= Fmake_vector (make_number (3), font_spec
);
1673 ASET (font_def
, 1, encoding
);
1674 ASET (font_def
, 2, repertory
);
1676 if (CHARACTERP (target
))
1677 range_list
= Fcons (Fcons (target
, target
), Qnil
);
1678 else if (CONSP (target
))
1680 Lisp_Object from
, to
;
1682 from
= Fcar (target
);
1684 CHECK_CHARACTER (from
);
1685 CHECK_CHARACTER (to
);
1686 range_list
= Fcons (target
, Qnil
);
1688 else if (SYMBOLP (target
) && !NILP (target
))
1690 Lisp_Object script_list
;
1694 script_list
= XCHAR_TABLE (Vchar_script_table
)->extras
[0];
1695 if (! NILP (Fmemq (target
, script_list
)))
1697 val
= Fcons (target
, Qnil
);
1698 map_char_table (accumulate_script_ranges
, Qnil
, Vchar_script_table
,
1700 range_list
= XCDR (val
);
1701 if (EQ (target
, Qlatin
))
1703 if (VECTORP (font_spec
))
1704 val
= generate_ascii_font_name (FONTSET_NAME (fontset
),
1708 FONTSET_ASCII (fontset
) = val
;
1711 if (CHARSETP (target
))
1713 if (EQ (target
, Qascii
))
1715 if (VECTORP (font_spec
))
1716 font_spec
= generate_ascii_font_name (FONTSET_NAME (fontset
),
1718 FONTSET_ASCII (fontset
) = font_spec
;
1719 range_list
= Fcons (Fcons (make_number (0), make_number (127)),
1724 CHECK_CHARSET_GET_CHARSET (target
, charset
);
1727 else if (NILP (range_list
))
1728 error ("Invalid script or charset name: %s",
1729 SDATA (SYMBOL_NAME (target
)));
1731 else if (NILP (target
))
1732 range_list
= Fcons (Qnil
, Qnil
);
1734 error ("Invalid target for setting a font");
1739 font_def_arg
= font_def
;
1741 if (NILP (range_list
))
1742 from_arg
= to_arg
= 0;
1744 from_arg
= XINT (XCAR (XCAR (range_list
))),
1745 to_arg
= XINT (XCDR (XCAR (range_list
)));
1747 map_charset_chars (set_fontset_font
, Qnil
, fontset
, charset
,
1748 CHARSET_MIN_CODE (charset
),
1749 CHARSET_MAX_CODE (charset
));
1751 for (; CONSP (range_list
); range_list
= XCDR (range_list
))
1752 FONTSET_ADD (fontset
, XCAR (range_list
), font_def
, add
);
1754 /* Free all realized fontsets whose base is FONTSET. This way, the
1755 specified character(s) are surely redisplayed by a correct
1757 free_realized_fontsets (fontset
);
1763 DEFUN ("new-fontset", Fnew_fontset
, Snew_fontset
, 2, 2, 0,
1764 doc
: /* Create a new fontset NAME from font information in FONTLIST.
1766 FONTLIST is an alist of scripts vs the corresponding font specification list.
1767 Each element of FONTLIST has the form (SCRIPT FONT-SPEC ...), where a
1768 character of SCRIPT is displayed by a font that matches one of
1771 SCRIPT is a symbol that appears in the first extra slot of the
1772 char-table `char-script-table'.
1774 FONT-SPEC is a vector, a cons, or a string. See the documentation of
1775 `set-fontset-font' for the meaning. */)
1777 Lisp_Object name
, fontlist
;
1779 Lisp_Object fontset
;
1783 CHECK_STRING (name
);
1784 CHECK_LIST (fontlist
);
1786 id
= fs_query_fontset (name
, 0);
1789 name
= Fdowncase (name
);
1790 val
= split_font_name_into_vector (name
);
1791 if (NILP (val
) || NILP (AREF (val
, 12)) || NILP (AREF (val
, 13)))
1792 error ("Fontset name must be in XLFD format");
1793 if (strcmp (SDATA (AREF (val
, 12)), "fontset"))
1794 error ("Registry field of fontset name must be \"fontset\"");
1795 Vfontset_alias_alist
1796 = Fcons (Fcons (name
,
1797 concat2 (concat2 (AREF (val
, 12), build_string ("-")),
1799 Vfontset_alias_alist
);
1800 ASET (val
, 12, build_string ("iso8859-1"));
1801 fontset
= make_fontset (Qnil
, name
, Qnil
);
1802 FONTSET_ASCII (fontset
) = build_font_name_from_vector (val
);
1806 fontset
= FONTSET_FROM_ID (id
);;
1807 free_realized_fontsets (fontset
);
1808 Fset_char_table_range (fontset
, Qt
, Qnil
);
1811 for (; ! NILP (fontlist
); fontlist
= Fcdr (fontlist
))
1813 Lisp_Object elt
, script
;
1815 elt
= Fcar (fontlist
);
1816 script
= Fcar (elt
);
1818 if (CONSP (elt
) && (NILP (XCDR (elt
)) || CONSP (XCDR (elt
))))
1819 for (; CONSP (elt
); elt
= XCDR (elt
))
1820 Fset_fontset_font (name
, script
, XCAR (elt
), Qnil
, Qappend
);
1822 Fset_fontset_font (name
, script
, elt
, Qnil
, Qappend
);
1828 /* Alist of automatically created fontsets. Each element is a cons
1829 (FONTNAME . FONTSET-ID). */
1830 static Lisp_Object auto_fontset_alist
;
1833 new_fontset_from_font_name (Lisp_Object fontname
)
1840 fontname
= Fdowncase (fontname
);
1841 val
= Fassoc (fontname
, auto_fontset_alist
);
1843 return XINT (XCDR (val
));
1845 vec
= split_font_name_into_vector (fontname
);
1847 vec
= Fmake_vector (make_number (14), build_string (""));
1848 ASET (vec
, 12, build_string ("fontset"));
1849 if (NILP (auto_fontset_alist
))
1851 ASET (vec
, 13, build_string ("startup"));
1852 name
= build_font_name_from_vector (vec
);
1857 int len
= XINT (Flength (auto_fontset_alist
));
1859 sprintf (temp
, "auto%d", len
);
1860 ASET (vec
, 13, build_string (temp
));
1861 name
= build_font_name_from_vector (vec
);
1863 name
= Fnew_fontset (name
, list2 (list2 (Qascii
, fontname
),
1864 list2 (Fcons (make_number (0),
1865 make_number (MAX_CHAR
)),
1867 id
= fs_query_fontset (name
, 0);
1869 = Fcons (Fcons (fontname
, make_number (id
)), auto_fontset_alist
);
1873 #ifdef USE_FONT_BACKEND
1875 new_fontset_from_font (font_object
)
1876 Lisp_Object font_object
;
1878 Lisp_Object font_name
= font_get_name (font_object
);
1879 Lisp_Object font_spec
= font_get_spec (font_object
);
1880 Lisp_Object fontset_spec
, short_name
, name
, fontset
;
1882 if (NILP (auto_fontset_alist
))
1883 short_name
= build_string ("fontset-startup");
1887 int len
= XINT (Flength (auto_fontset_alist
));
1889 sprintf (temp
, "fontset-auto%d", len
);
1890 short_name
= build_string (temp
);
1892 fontset_spec
= Fcopy_sequence (font_spec
);
1893 ASET (fontset_spec
, FONT_REGISTRY_INDEX
, short_name
);
1894 name
= Ffont_xlfd_name (fontset_spec
);
1899 for (i
= 0; i
< FONT_SIZE_INDEX
; i
++)
1900 if ((i
!= FONT_FAMILY_INDEX
) && (i
!= FONT_REGISTRY_INDEX
))
1901 ASET (fontset_spec
, i
, Qnil
);
1902 name
= Ffont_xlfd_name (fontset_spec
);
1906 fontset
= make_fontset (Qnil
, name
, Qnil
);
1907 FONTSET_ASCII (fontset
) = font_name
;
1908 font_spec
= Fcons (SYMBOL_NAME (AREF (font_spec
, FONT_FAMILY_INDEX
)),
1909 SYMBOL_NAME (AREF (font_spec
, FONT_REGISTRY_INDEX
)));
1910 Fset_fontset_font (name
, Qlatin
, font_spec
, Qnil
, Qnil
);
1911 Fset_fontset_font (name
, Qnil
, font_spec
, Qnil
, Qnil
);
1912 return XINT (FONTSET_ID (fontset
));
1916 fontset_ascii_font (f
, id
)
1920 Lisp_Object fontset
= FONTSET_FROM_ID (id
);
1921 Lisp_Object ascii_slot
= FONTSET_ASCII (fontset
);
1922 Lisp_Object val
, font_object
;
1924 if (CONSP (ascii_slot
))
1926 Lisp_Object ascii_font_name
= XCAR (ascii_slot
);
1929 for (val
= XCDR (ascii_slot
); ! NILP (val
); val
= XCDR (val
))
1931 Lisp_Object frame
= font_get_frame (XCAR (val
));
1933 if (NILP (frame
) || XFRAME (frame
) == f
)
1935 font_object
= XCAR (val
);
1936 if (XSAVE_VALUE (font_object
)->integer
== 0)
1938 font_object
= font_open_by_name (f
, SDATA (ascii_font_name
));
1939 XSETCAR (val
, font_object
);
1944 if (NILP (font_object
))
1946 font_object
= font_open_by_name (f
, SDATA (ascii_font_name
));
1947 XSETCDR (ascii_slot
, Fcons (font_object
, XCDR (ascii_slot
)));
1952 font_object
= font_open_by_name (f
, SDATA (ascii_slot
));
1953 FONTSET_ASCII (fontset
) = Fcons (ascii_slot
, Fcons (font_object
, Qnil
));
1955 if (NILP (font_object
))
1957 return XSAVE_VALUE (font_object
)->pointer
;
1960 #endif /* USE_FONT_BACKEND */
1962 DEFUN ("font-info", Ffont_info
, Sfont_info
, 1, 2, 0,
1963 doc
: /* Return information about a font named NAME on frame FRAME.
1964 If FRAME is omitted or nil, use the selected frame.
1965 The returned value is a vector of OPENED-NAME, FULL-NAME, CHARSET, SIZE,
1966 HEIGHT, BASELINE-OFFSET, RELATIVE-COMPOSE, and DEFAULT-ASCENT,
1968 OPENED-NAME is the name used for opening the font,
1969 FULL-NAME is the full name of the font,
1970 SIZE is the maximum bound width of the font,
1971 HEIGHT is the height of the font,
1972 BASELINE-OFFSET is the upward offset pixels from ASCII baseline,
1973 RELATIVE-COMPOSE and DEFAULT-ASCENT are the numbers controlling
1974 how to compose characters.
1975 If the named font is not yet loaded, return nil. */)
1977 Lisp_Object name
, frame
;
1980 struct font_info
*fontp
;
1982 Lisp_Object font_object
;
1984 (*check_window_system_func
) ();
1986 CHECK_STRING (name
);
1987 name
= Fdowncase (name
);
1989 frame
= selected_frame
;
1990 CHECK_LIVE_FRAME (frame
);
1993 if (!query_font_func
)
1994 error ("Font query function is not supported");
1996 #ifdef USE_FONT_BACKEND
1997 if (enable_font_backend
)
1999 font_object
= font_open_by_name (f
, SDATA (name
));
2000 if (NILP (font_object
))
2003 fontp
= (struct font_info
*) XSAVE_VALUE (font_object
)->pointer
;
2006 #endif /* USE_FONT_BACKEND */
2007 fontp
= (*query_font_func
) (f
, SDATA (name
));
2011 info
= Fmake_vector (make_number (7), Qnil
);
2013 XVECTOR (info
)->contents
[0] = build_string (fontp
->name
);
2014 XVECTOR (info
)->contents
[1] = build_string (fontp
->full_name
);
2015 XVECTOR (info
)->contents
[2] = make_number (fontp
->size
);
2016 XVECTOR (info
)->contents
[3] = make_number (fontp
->height
);
2017 XVECTOR (info
)->contents
[4] = make_number (fontp
->baseline_offset
);
2018 XVECTOR (info
)->contents
[5] = make_number (fontp
->relative_compose
);
2019 XVECTOR (info
)->contents
[6] = make_number (fontp
->default_ascent
);
2021 #ifdef USE_FONT_BACKEND
2022 if (! NILP (font_object
))
2023 font_close_object (f
, font_object
);
2024 #endif /* USE_FONT_BACKEND */
2029 /* Return a cons (FONT-NAME . GLYPH-CODE).
2030 FONT-NAME is the font name for the character at POSITION in the current
2031 buffer. This is computed from all the text properties and overlays
2032 that apply to POSITION. POSTION may be nil, in which case,
2033 FONT-NAME is the font name for display the character CH with the
2036 GLYPH-CODE is the glyph code in the font to use for the character.
2038 If the 2nd optional arg CH is non-nil, it is a character to check
2039 the font instead of the character at POSITION.
2041 It returns nil in the following cases:
2043 (1) The window system doesn't have a font for the character (thus
2044 it is displayed by an empty box).
2046 (2) The character code is invalid.
2048 (3) If POSITION is not nil, and the current buffer is not displayed
2051 In addition, the returned font name may not take into account of
2052 such redisplay engine hooks as what used in jit-lock-mode if
2053 POSITION is currently not visible. */
2056 DEFUN ("internal-char-font", Finternal_char_font
, Sinternal_char_font
, 1, 2, 0,
2057 doc
: /* For internal use only. */)
2059 Lisp_Object position
, ch
;
2061 int pos
, pos_byte
, dummy
;
2066 Lisp_Object charset
, rfont_def
;
2069 if (NILP (position
))
2071 CHECK_CHARACTER (ch
);
2073 f
= XFRAME (selected_frame
);
2074 face_id
= DEFAULT_FACE_ID
;
2080 Lisp_Object window
, charset
;
2083 CHECK_NUMBER_COERCE_MARKER (position
);
2084 pos
= XINT (position
);
2085 if (pos
< BEGV
|| pos
>= ZV
)
2086 args_out_of_range_3 (position
, make_number (BEGV
), make_number (ZV
));
2087 pos_byte
= CHAR_TO_BYTE (pos
);
2089 c
= FETCH_CHAR (pos_byte
);
2095 window
= Fget_buffer_window (Fcurrent_buffer (), Qnil
);
2098 w
= XWINDOW (window
);
2099 f
= XFRAME (w
->frame
);
2100 face_id
= face_at_buffer_position (w
, pos
, -1, -1, &dummy
, pos
+ 100, 0);
2101 charset
= Fget_char_property (position
, Qcharset
, Qnil
);
2102 if (CHARSETP (charset
))
2103 cs_id
= XINT (CHARSET_SYMBOL_ID (charset
));
2107 if (! CHAR_VALID_P (c
, 0))
2109 face_id
= FACE_FOR_CHAR (f
, FACE_FROM_ID (f
, face_id
), c
, pos
, Qnil
);
2110 face
= FACE_FROM_ID (f
, face_id
);
2111 rfont_def
= fontset_font (FONTSET_FROM_ID (face
->fontset
), c
, face
, cs_id
);
2112 #ifdef USE_FONT_BACKEND
2113 if (enable_font_backend
)
2115 if (VECTORP (rfont_def
) && ! NILP (AREF (rfont_def
, 4)))
2117 Lisp_Object font_object
= AREF (rfont_def
, 4);
2118 struct font
*font
= XSAVE_VALUE (font_object
)->pointer
;
2119 unsigned code
= font
->driver
->encode_char (font
, c
);
2120 Lisp_Object fontname
= font_get_name (font_object
);
2122 if (code
== FONT_INVALID_CODE
)
2123 return Fcons (fontname
, Qnil
);
2124 if (code
<= MOST_POSITIVE_FIXNUM
)
2125 return Fcons (fontname
, make_number (code
));
2126 return Fcons (fontname
, Fcons (make_number (code
>> 16),
2127 make_number (code
& 0xFFFF)));
2131 #endif /* USE_FONT_BACKEND */
2132 if (VECTORP (rfont_def
) && STRINGP (AREF (rfont_def
, 3)))
2134 Lisp_Object font_def
;
2135 struct font_info
*fontp
;
2136 struct charset
*charset
;
2140 font_def
= AREF (rfont_def
, 2);
2141 charset
= CHARSET_FROM_ID (XINT (AREF (font_def
, 1)));
2142 code
= ENCODE_CHAR (charset
, c
);
2143 if (code
== CHARSET_INVALID_CODE (charset
))
2144 return (Fcons (AREF (rfont_def
, 3), Qnil
));
2145 STORE_XCHAR2B (&char2b
, ((code
>> 8) & 0xFF), (code
& 0xFF));
2146 fontp
= (*get_font_info_func
) (f
, XINT (AREF (rfont_def
, 1)));
2147 rif
->encode_char (c
, &char2b
, fontp
, charset
, NULL
);
2148 code
= (XCHAR2B_BYTE1 (&char2b
) << 8) | XCHAR2B_BYTE2 (&char2b
);
2149 return (Fcons (AREF (rfont_def
, 3), make_number (code
)));
2155 DEFUN ("fontset-info", Ffontset_info
, Sfontset_info
, 1, 2, 0,
2156 doc
: /* Return information about a fontset FONTSET on frame FRAME.
2157 The value is a char-table of which elements has this form.
2159 ((FONT-PATTERN OPENED-FONT ...) ...)
2161 FONT-PATTERN is a vector:
2163 [ FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY ]
2165 or a string of font name pattern.
2167 OPENED-FONT is a name of a font actually opened.
2169 The char-table has one extra slot. The value is a char-table
2170 containing the information about the derived fonts from the default
2171 fontset. The format is the same as abobe. */)
2173 Lisp_Object fontset
, frame
;
2176 Lisp_Object
*realized
[2], fontsets
[2], tables
[2];
2177 Lisp_Object val
, elt
;
2180 (*check_window_system_func
) ();
2182 fontset
= check_fontset_name (fontset
);
2185 frame
= selected_frame
;
2186 CHECK_LIVE_FRAME (frame
);
2189 /* Recode fontsets realized on FRAME from the base fontset FONTSET
2190 in the table `realized'. */
2191 realized
[0] = (Lisp_Object
*) alloca (sizeof (Lisp_Object
)
2192 * ASIZE (Vfontset_table
));
2193 for (i
= j
= 0; i
< ASIZE (Vfontset_table
); i
++)
2195 elt
= FONTSET_FROM_ID (i
);
2197 && EQ (FONTSET_BASE (elt
), fontset
)
2198 && EQ (FONTSET_FRAME (elt
), frame
))
2199 realized
[0][j
++] = elt
;
2201 realized
[0][j
] = Qnil
;
2203 realized
[1] = (Lisp_Object
*) alloca (sizeof (Lisp_Object
)
2204 * ASIZE (Vfontset_table
));
2205 for (i
= j
= 0; ! NILP (realized
[0][i
]); i
++)
2207 elt
= FONTSET_DEFAULT (realized
[0][i
]);
2209 realized
[1][j
++] = elt
;
2211 realized
[1][j
] = Qnil
;
2213 tables
[0] = Fmake_char_table (Qfontset_info
, Qnil
);
2214 tables
[1] = Fmake_char_table (Qnil
, Qnil
);
2215 XCHAR_TABLE (tables
[0])->extras
[0] = tables
[1];
2216 fontsets
[0] = fontset
;
2217 fontsets
[1] = Vdefault_fontset
;
2219 /* Accumulate information of the fontset in TABLE. The format of
2220 each element is ((FONT-SPEC OPENED-FONT ...) ...). */
2221 for (k
= 0; k
<= 1; k
++)
2223 for (c
= 0; c
<= MAX_CHAR
; )
2227 if (c
<= MAX_5_BYTE_CHAR
)
2229 val
= char_table_ref_and_range (fontsets
[k
], c
, &from
, &to
);
2230 if (to
> MAX_5_BYTE_CHAR
)
2231 to
= MAX_5_BYTE_CHAR
;
2235 val
= FONTSET_FALLBACK (fontsets
[k
]);
2242 /* At first, set ALIST to ((FONT-SPEC) ...). */
2243 for (alist
= Qnil
, i
= 0; i
< ASIZE (val
); i
++)
2244 alist
= Fcons (Fcons (AREF (AREF (val
, i
), 0), Qnil
), alist
);
2245 alist
= Fnreverse (alist
);
2247 /* Then store opend font names to cdr of each elements. */
2248 for (i
= 0; ! NILP (realized
[k
][i
]); i
++)
2250 if (c
<= MAX_5_BYTE_CHAR
)
2251 val
= FONTSET_REF (realized
[k
][i
], c
);
2253 val
= FONTSET_FALLBACK (realized
[k
][i
]);
2254 if (! VECTORP (val
))
2256 /* VAL is [int int ?
2257 [FACE-ID FONT-INDEX FONT-DEF FONT-NAME] ...].
2258 If a font of an element is already opened,
2259 FONT-NAME is the name of a opened font. */
2260 for (j
= 3; j
< ASIZE (val
); j
++)
2261 if (STRINGP (AREF (AREF (val
, j
), 3)))
2263 Lisp_Object font_idx
;
2265 font_idx
= AREF (AREF (val
, j
), 1);
2266 elt
= Fassq (AREF (AREF (AREF (val
, j
), 2), 0), alist
);
2268 && NILP (Fmemq (font_idx
, XCDR(elt
))))
2269 nconc2 (elt
, Fcons (font_idx
, Qnil
));
2272 for (val
= alist
; CONSP (val
); val
= XCDR (val
))
2273 for (elt
= XCDR (XCAR (val
)); CONSP (elt
); elt
= XCDR (elt
))
2275 struct font_info
*font_info
2276 = (*get_font_info_func
) (f
, XINT (XCAR (elt
)));
2277 XSETCAR (elt
, build_string (font_info
->full_name
));
2280 /* Store ALIST in TBL for characters C..TO. */
2281 if (c
<= MAX_5_BYTE_CHAR
)
2282 char_table_set_range (tables
[k
], c
, to
, alist
);
2284 XCHAR_TABLE (tables
[k
])->defalt
= alist
;
2294 DEFUN ("fontset-font", Ffontset_font
, Sfontset_font
, 2, 3, 0,
2295 doc
: /* Return a font name pattern for character CH in fontset NAME.
2296 If NAME is t, find a pattern in the default fontset.
2298 The value has the form (FAMILY . REGISTRY), where FAMILY is a font
2299 family name and REGISTRY is a font registry name. This is actually
2300 the first font name pattern for CH in the fontset or in the default
2303 If the 2nd optional arg ALL is non-nil, return a list of all font name
2306 Lisp_Object name
, ch
, all
;
2309 Lisp_Object fontset
, elt
, list
, repertory
, val
;
2312 fontset
= check_fontset_name (name
);
2314 CHECK_CHARACTER (ch
);
2319 for (i
= 0, elt
= FONTSET_REF (fontset
, c
); i
< 2;
2320 i
++, elt
= FONTSET_FALLBACK (fontset
))
2322 for (j
= 0; j
< ASIZE (elt
); j
++)
2324 val
= AREF (elt
, j
);
2325 repertory
= AREF (val
, 1);
2326 if (INTEGERP (repertory
))
2328 struct charset
*charset
= CHARSET_FROM_ID (XINT (repertory
));
2330 if (! CHAR_CHARSET_P (c
, charset
))
2333 else if (CHAR_TABLE_P (repertory
))
2335 if (NILP (CHAR_TABLE_REF (repertory
, c
)))
2338 val
= AREF (val
, 0);
2339 val
= Fcons (AREF (val
, 0), AREF (val
, 5));
2342 list
= Fcons (val
, list
);
2344 if (EQ (fontset
, Vdefault_fontset
))
2346 fontset
= Vdefault_fontset
;
2348 return (Fnreverse (list
));
2351 DEFUN ("fontset-list", Ffontset_list
, Sfontset_list
, 0, 0, 0,
2352 doc
: /* Return a list of all defined fontset names. */)
2355 Lisp_Object fontset
, list
;
2359 for (i
= 0; i
< ASIZE (Vfontset_table
); i
++)
2361 fontset
= FONTSET_FROM_ID (i
);
2363 && BASE_FONTSET_P (fontset
))
2364 list
= Fcons (FONTSET_NAME (fontset
), list
);
2371 #ifdef FONTSET_DEBUG
2374 dump_fontset (fontset
)
2375 Lisp_Object fontset
;
2379 vec
= Fmake_vector (make_number (3), Qnil
);
2380 ASET (vec
, 0, FONTSET_ID (fontset
));
2382 if (BASE_FONTSET_P (fontset
))
2384 ASET (vec
, 1, FONTSET_NAME (fontset
));
2390 frame
= FONTSET_FRAME (fontset
);
2393 FRAME_PTR f
= XFRAME (frame
);
2395 if (FRAME_LIVE_P (f
))
2397 Fcons (FONTSET_NAME (FONTSET_BASE (fontset
)), f
->name
));
2400 Fcons (FONTSET_NAME (FONTSET_BASE (fontset
)), Qnil
));
2402 if (!NILP (FONTSET_DEFAULT (fontset
)))
2403 ASET (vec
, 2, FONTSET_ID (FONTSET_DEFAULT (fontset
)));
2408 DEFUN ("fontset-list-all", Ffontset_list_all
, Sfontset_list_all
, 0, 0, 0,
2409 doc
: /* Return a brief summary of all fontsets for debug use. */)
2415 for (i
= 0, val
= Qnil
; i
< ASIZE (Vfontset_table
); i
++)
2416 if (! NILP (AREF (Vfontset_table
, i
)))
2417 val
= Fcons (dump_fontset (AREF (Vfontset_table
, i
)), val
);
2418 return (Fnreverse (val
));
2420 #endif /* FONTSET_DEBUG */
2425 if (!load_font_func
)
2426 /* Window system initializer should have set proper functions. */
2429 DEFSYM (Qfontset
, "fontset");
2430 Fput (Qfontset
, Qchar_table_extra_slots
, make_number (9));
2431 DEFSYM (Qfontset_info
, "fontset-info");
2432 Fput (Qfontset_info
, Qchar_table_extra_slots
, make_number (1));
2434 DEFSYM (Qprepend
, "prepend");
2435 DEFSYM (Qappend
, "append");
2436 DEFSYM (Qlatin
, "latin");
2438 Vcached_fontset_data
= Qnil
;
2439 staticpro (&Vcached_fontset_data
);
2441 Vfontset_table
= Fmake_vector (make_number (32), Qnil
);
2442 staticpro (&Vfontset_table
);
2444 Vdefault_fontset
= Fmake_char_table (Qfontset
, Qnil
);
2445 staticpro (&Vdefault_fontset
);
2446 FONTSET_ID (Vdefault_fontset
) = make_number (0);
2447 FONTSET_NAME (Vdefault_fontset
)
2448 = build_string ("-*-*-*-*-*-*-*-*-*-*-*-*-fontset-default");
2449 AREF (Vfontset_table
, 0) = Vdefault_fontset
;
2450 next_fontset_id
= 1;
2452 auto_fontset_alist
= Qnil
;
2453 staticpro (&auto_fontset_alist
);
2455 DEFVAR_LISP ("font-encoding-alist", &Vfont_encoding_alist
,
2457 Alist of fontname patterns vs the corresponding encoding and repertory info.
2458 Each element looks like (REGEXP . (ENCODING . REPERTORY)),
2459 where ENCODING is a charset or a char-table,
2460 and REPERTORY is a charset, a char-table, or nil.
2462 ENCODING is for converting a character to a glyph code of the font.
2463 If ENCODING is a charset, encoding a character by the charset gives
2464 the corresponding glyph code. If ENCODING is a char-table, looking up
2465 the table by a character gives the corresponding glyph code.
2467 REPERTORY specifies a repertory of characters supported by the font.
2468 If REPERTORY is a charset, all characters beloging to the charset are
2469 supported. If REPERTORY is a char-table, all characters who have a
2470 non-nil value in the table are supported. It REPERTORY is nil, Emacs
2471 gets the repertory information by an opened font and ENCODING. */);
2472 Vfont_encoding_alist
= Qnil
;
2474 DEFVAR_LISP ("use-default-ascent", &Vuse_default_ascent
,
2476 Char table of characters whose ascent values should be ignored.
2477 If an entry for a character is non-nil, the ascent value of the glyph
2478 is assumed to be what specified by _MULE_DEFAULT_ASCENT property of a font.
2480 This affects how a composite character which contains
2481 such a character is displayed on screen. */);
2482 Vuse_default_ascent
= Qnil
;
2484 DEFVAR_LISP ("ignore-relative-composition", &Vignore_relative_composition
,
2486 Char table of characters which is not composed relatively.
2487 If an entry for a character is non-nil, a composition sequence
2488 which contains that character is displayed so that
2489 the glyph of that character is put without considering
2490 an ascent and descent value of a previous character. */);
2491 Vignore_relative_composition
= Qnil
;
2493 DEFVAR_LISP ("alternate-fontname-alist", &Valternate_fontname_alist
,
2494 doc
: /* Alist of fontname vs list of the alternate fontnames.
2495 When a specified font name is not found, the corresponding
2496 alternate fontnames (if any) are tried instead. */);
2497 Valternate_fontname_alist
= Qnil
;
2499 DEFVAR_LISP ("fontset-alias-alist", &Vfontset_alias_alist
,
2500 doc
: /* Alist of fontset names vs the aliases. */);
2501 Vfontset_alias_alist
= Fcons (Fcons (FONTSET_NAME (Vdefault_fontset
),
2502 build_string ("fontset-default")),
2505 DEFVAR_LISP ("vertical-centering-font-regexp",
2506 &Vvertical_centering_font_regexp
,
2507 doc
: /* *Regexp matching font names that require vertical centering on display.
2508 When a character is displayed with such fonts, the character is displayed
2509 at the vertical center of lines. */);
2510 Vvertical_centering_font_regexp
= Qnil
;
2512 DEFVAR_LISP ("otf-script-alist", &Votf_script_alist
,
2513 doc
: /* Alist of OpenType script tags vs the corresponding script names. */);
2514 Votf_script_alist
= Qnil
;
2516 defsubr (&Squery_fontset
);
2517 defsubr (&Snew_fontset
);
2518 defsubr (&Sset_fontset_font
);
2519 defsubr (&Sfont_info
);
2520 defsubr (&Sinternal_char_font
);
2521 defsubr (&Sfontset_info
);
2522 defsubr (&Sfontset_font
);
2523 defsubr (&Sfontset_list
);
2524 #ifdef FONTSET_DEBUG
2525 defsubr (&Sfontset_list_all
);
2529 /* arch-tag: ea861585-2f5f-4e5b-9849-d04a9c3a3537
2530 (do not change this comment) */