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 of the License, or
17 (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>. */
27 /* #define FONTSET_DEBUG */
36 #include "blockinput.h"
38 #include "character.h"
43 #include "dispextern.h"
44 #include "intervals.h"
56 #include "termhooks.h"
62 #define xassert(X) do {if (!(X)) abort ();} while (0)
65 #else /* not FONTSET_DEBUG */
66 #define xassert(X) (void) 0
67 #endif /* not FONTSET_DEBUG */
69 EXFUN (Fclear_face_cache
, 1);
73 A fontset is a collection of font related information to give
74 similar appearance (style, etc) of characters. A fontset has two
75 roles. One is to use for the frame parameter `font' as if it is an
76 ASCII font. In that case, Emacs uses the font specified for
77 `ascii' script for the frame's default font.
79 Another role, the more important one, is to provide information
80 about which font to use for each non-ASCII character.
82 There are two kinds of fontsets; base and realized. A base fontset
83 is created by `new-fontset' from Emacs Lisp explicitly. A realized
84 fontset is created implicitly when a face is realized for ASCII
85 characters. A face is also realized for non-ASCII characters based
86 on an ASCII face. All of non-ASCII faces based on the same ASCII
87 face share the same realized fontset.
89 A fontset object is implemented by a char-table whose default value
90 and parent are always nil.
92 An element of a base fontset is a vector of FONT-DEFs which itself
93 is a vector [ FONT-SPEC ENCODING REPERTORY ].
95 An element of a realized fontset is nil, t, or a vector of this form:
97 [ CHARSET-ORDERED-LIST-TICK PREFERRED-RFONT-DEF
98 RFONT-DEF0 RFONT-DEF1 ... ]
100 RFONT-DEFn (i.e. Realized FONT-DEF) has this form:
102 [ FACE-ID FONT-DEF FONT-OBJECT SORTING-SCORE ]
104 RFONT-DEFn are automatically reordered by the current charset
107 The value nil means that we have not yet generated the above vector
108 from the base of the fontset.
110 The value t means that no font is available for the corresponding
114 A fontset has 9 extra slots.
116 The 1st slot: the ID number of the fontset
119 base: the name of the fontset
124 realized: the base fontset
128 realized: the frame that the fontset belongs to
131 base: the font name for ASCII characters
136 realized: the ID number of a face to use for characters that
137 has no font in a realized fontset.
141 realized: Alist of font index vs the corresponding repertory
146 realized: If the base is not the default fontset, a fontset
147 realized from the default fontset, else nil.
150 base: Same as element value (but for fallback fonts).
153 All fontsets are recorded in the vector Vfontset_table.
158 There's a special base fontset named `default fontset' which
159 defines the default font specifications. When a base fontset
160 doesn't specify a font for a specific character, the corresponding
161 value in the default fontset is used.
163 The parent of a realized fontset created for such a face that has
164 no fontset is the default fontset.
167 These structures are hidden from the other codes than this file.
168 The other codes handle fontsets only by their ID numbers. They
169 usually use the variable name `fontset' for IDs. But, in this
170 file, we always use varialbe name `id' for IDs, and name `fontset'
171 for an actual fontset object, i.e., char-table.
175 /********** VARIABLES and FUNCTION PROTOTYPES **********/
177 extern Lisp_Object Qfont
;
178 static Lisp_Object Qfontset
;
179 static Lisp_Object Qfontset_info
;
180 static Lisp_Object Qprepend
, Qappend
;
181 static Lisp_Object Qlatin
;
183 /* Vector containing all fontsets. */
184 static Lisp_Object Vfontset_table
;
186 /* Next possibly free fontset ID. Usually this keeps the minimum
187 fontset ID not yet used. */
188 static int next_fontset_id
;
190 /* The default fontset. This gives default FAMILY and REGISTRY of
191 font for each character. */
192 static Lisp_Object Vdefault_fontset
;
194 Lisp_Object Vfont_encoding_charset_alist
;
195 Lisp_Object Vuse_default_ascent
;
196 Lisp_Object Vignore_relative_composition
;
197 Lisp_Object Valternate_fontname_alist
;
198 Lisp_Object Vfontset_alias_alist
;
199 Lisp_Object Vvertical_centering_font_regexp
;
200 Lisp_Object Votf_script_alist
;
202 /* Check if any window system is used now. */
203 void (*check_window_system_func
) P_ ((void));
206 /* Prototype declarations for static functions. */
207 static Lisp_Object fontset_add
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
,
209 static Lisp_Object fontset_find_font
P_ ((Lisp_Object
, int, struct face
*,
211 static void reorder_font_vector
P_ ((Lisp_Object
, Lisp_Object
));
212 static Lisp_Object fontset_font
P_ ((Lisp_Object
, int, struct face
*, int));
213 static Lisp_Object make_fontset
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
));
214 static Lisp_Object fontset_pattern_regexp
P_ ((Lisp_Object
));
215 static void accumulate_script_ranges
P_ ((Lisp_Object
, Lisp_Object
,
217 Lisp_Object find_font_encoding
P_ ((Lisp_Object
));
219 static void set_fontset_font
P_ ((Lisp_Object
, Lisp_Object
));
223 /* Return 1 if ID is a valid fontset id, else return 0. */
226 fontset_id_valid_p (id
)
229 return (id
>= 0 && id
< ASIZE (Vfontset_table
) - 1);
236 /********** MACROS AND FUNCTIONS TO HANDLE FONTSET **********/
238 /* Return the fontset with ID. No check of ID's validness. */
239 #define FONTSET_FROM_ID(id) AREF (Vfontset_table, id)
241 /* Macros to access special values of FONTSET. */
242 #define FONTSET_ID(fontset) XCHAR_TABLE (fontset)->extras[0]
244 /* Macros to access special values of (base) FONTSET. */
245 #define FONTSET_NAME(fontset) XCHAR_TABLE (fontset)->extras[1]
246 #define FONTSET_ASCII(fontset) XCHAR_TABLE (fontset)->extras[4]
247 #define FONTSET_SPEC(fontset) XCHAR_TABLE (fontset)->extras[5]
249 /* Macros to access special values of (realized) FONTSET. */
250 #define FONTSET_BASE(fontset) XCHAR_TABLE (fontset)->extras[2]
251 #define FONTSET_FRAME(fontset) XCHAR_TABLE (fontset)->extras[3]
252 #define FONTSET_OBJLIST(fontset) XCHAR_TABLE (fontset)->extras[4]
253 #define FONTSET_NOFONT_FACE(fontset) XCHAR_TABLE (fontset)->extras[5]
254 #define FONTSET_REPERTORY(fontset) XCHAR_TABLE (fontset)->extras[6]
255 #define FONTSET_DEFAULT(fontset) XCHAR_TABLE (fontset)->extras[7]
257 /* For both base and realized fontset. */
258 #define FONTSET_FALLBACK(fontset) XCHAR_TABLE (fontset)->extras[8]
260 #define BASE_FONTSET_P(fontset) (NILP (FONTSET_BASE (fontset)))
263 /* Macros for FONT-DEF and RFONT-DEF of fontset. */
264 #define FONT_DEF_NEW(font_def, font_spec, encoding, repertory) \
266 (font_def) = Fmake_vector (make_number (3), (font_spec)); \
267 ASET ((font_def), 1, encoding); \
268 ASET ((font_def), 2, repertory); \
271 #define FONT_DEF_SPEC(font_def) AREF (font_def, 0)
272 #define FONT_DEF_ENCODING(font_def) AREF (font_def, 1)
273 #define FONT_DEF_REPERTORY(font_def) AREF (font_def, 2)
275 #define RFONT_DEF_FACE(rfont_def) AREF (rfont_def, 0)
276 #define RFONT_DEF_SET_FACE(rfont_def, face_id) \
277 ASET ((rfont_def), 0, make_number (face_id))
278 #define RFONT_DEF_FONT_DEF(rfont_def) AREF (rfont_def, 1)
279 #define RFONT_DEF_SPEC(rfont_def) FONT_DEF_SPEC (AREF (rfont_def, 1))
280 #define RFONT_DEF_REPERTORY(rfont_def) FONT_DEF_REPERTORY (AREF (rfont_def, 1))
281 #define RFONT_DEF_OBJECT(rfont_def) AREF (rfont_def, 2)
282 #define RFONT_DEF_SET_OBJECT(rfont_def, object) \
283 ASET ((rfont_def), 2, (object))
284 #define RFONT_DEF_SCORE(rfont_def) XINT (AREF (rfont_def, 3))
285 #define RFONT_DEF_SET_SCORE(rfont_def, score) \
286 ASET ((rfont_def), 3, make_number (score))
287 #define RFONT_DEF_NEW(rfont_def, font_def) \
289 (rfont_def) = Fmake_vector (make_number (4), Qnil); \
290 ASET ((rfont_def), 1, (font_def)); \
291 RFONT_DEF_SET_SCORE ((rfont_def), 0); \
295 /* Return the element of FONTSET for the character C. If FONTSET is a
296 base fontset other then the default fontset and FONTSET doesn't
297 contain information for C, return the information in the default
300 #define FONTSET_REF(fontset, c) \
301 (EQ (fontset, Vdefault_fontset) \
302 ? CHAR_TABLE_REF (fontset, c) \
303 : fontset_ref ((fontset), (c)))
306 fontset_ref (fontset
, c
)
312 elt
= CHAR_TABLE_REF (fontset
, c
);
313 if (NILP (elt
) && ! EQ (fontset
, Vdefault_fontset
)
314 /* Don't check Vdefault_fontset for a realized fontset. */
315 && NILP (FONTSET_BASE (fontset
)))
316 elt
= CHAR_TABLE_REF (Vdefault_fontset
, c
);
320 /* Set elements of FONTSET for characters in RANGE to the value ELT.
321 RANGE is a cons (FROM . TO), where FROM and TO are character codes
322 specifying a range. */
324 #define FONTSET_SET(fontset, range, elt) \
325 Fset_char_table_range ((fontset), (range), (elt))
328 /* Modify the elements of FONTSET for characters in RANGE by replacing
329 with ELT or adding ELT. RANGE is a cons (FROM . TO), where FROM
330 and TO are character codes specifying a range. If ADD is nil,
331 replace with ELT, if ADD is `prepend', prepend ELT, otherwise,
334 #define FONTSET_ADD(fontset, range, elt, add) \
337 ? (FONTSET_FALLBACK (fontset) = Fmake_vector (make_number (1), (elt))) \
338 : Fset_char_table_range ((fontset), (range), \
339 Fmake_vector (make_number (1), (elt)))) \
340 : fontset_add ((fontset), (range), (elt), (add)))
343 fontset_add (fontset
, range
, elt
, add
)
344 Lisp_Object fontset
, range
, elt
, add
;
347 int idx
= (EQ (add
, Qappend
) ? 0 : 1);
349 args
[1 - idx
] = Fmake_vector (make_number (1), elt
);
353 int from
= XINT (XCAR (range
));
354 int to
= XINT (XCDR (range
));
358 args
[idx
] = char_table_ref_and_range (fontset
, from
, &from1
, &to1
);
361 char_table_set_range (fontset
, from
, to1
,
362 NILP (args
[idx
]) ? args
[1 - idx
]
363 : Fvconcat (2, args
));
369 args
[idx
] = FONTSET_FALLBACK (fontset
);
370 FONTSET_FALLBACK (fontset
)
371 = NILP (args
[idx
]) ? args
[1 - idx
] : Fvconcat (2, args
);
377 fontset_compare_rfontdef (val1
, val2
)
378 const void *val1
, *val2
;
380 return (RFONT_DEF_SCORE (*(Lisp_Object
*) val2
)
381 - RFONT_DEF_SCORE (*(Lisp_Object
*) val1
));
384 /* Update FONT-GROUP which has this form:
385 [ CHARSET-ORDERED-LIST-TICK PREFERRED-RFONT-DEF
386 RFONT-DEF0 RFONT-DEF1 ... ]
387 Reorder RFONT-DEFs according to the current language, and update
388 CHARSET-ORDERED-LIST-TICK.
390 If PREFERRED_FAMILY is not nil, that family has the higher priority
391 if the encoding charsets or languages in font-specs are the same. */
393 extern Lisp_Object
Fassoc_string ();
396 reorder_font_vector (font_group
, preferred_family
)
397 Lisp_Object font_group
;
398 Lisp_Object preferred_family
;
402 int score_changed
= 0;
404 size
= ASIZE (font_group
);
405 /* Exclude the tailing nil elements from the reordering. */
406 while (NILP (AREF (font_group
, size
- 1))) size
--;
409 for (i
= 0; i
< size
; i
++)
411 Lisp_Object rfont_def
= AREF (font_group
, i
+ 2);
412 Lisp_Object font_def
= RFONT_DEF_FONT_DEF (rfont_def
);
413 Lisp_Object font_spec
= FONT_DEF_SPEC (font_def
);
414 Lisp_Object lang
= Ffont_get (font_spec
, QClang
);
415 Lisp_Object family
= AREF (font_spec
, FONT_FAMILY_INDEX
);
416 Lisp_Object repertory
= FONT_DEF_REPERTORY (font_def
);
419 if (! NILP (repertory
))
423 for (score
= 0xFFFF, tail
= Vcharset_ordered_list
;
424 ! EQ (tail
, Vcharset_non_preferred_head
) && CONSP (tail
);
425 score
--, tail
= XCDR (tail
))
426 if (EQ (repertory
, XCAR (tail
)))
428 if (EQ (tail
, Vcharset_non_preferred_head
))
431 else if (! NILP (lang
))
433 if (EQ (lang
, Vcurrent_iso639_language
))
435 else if (CONSP (Vcurrent_iso639_language
))
436 score
= ! NILP (Fmemq (lang
, Vcurrent_iso639_language
));
439 if (! NILP (preferred_family
) && ! NILP (family
))
441 if (fast_string_match_ignore_case (preferred_family
,
442 SYMBOL_NAME (family
)) < 0)
445 if (RFONT_DEF_SCORE (rfont_def
) != score
)
447 RFONT_DEF_SET_SCORE (rfont_def
, score
);
453 qsort (XVECTOR (font_group
)->contents
+ 2, size
, sizeof (Lisp_Object
),
454 fontset_compare_rfontdef
);
456 ASET (font_group
, 0, make_number (charset_ordered_list_tick
));
459 /* Return RFONT-DEF (vector) in the realized fontset FONTSET for the
460 character C. If no font is found, return Qnil if there's a
461 possibility that the default fontset or the fallback font groups
462 have a proper font, and return Qt if not.
464 If a font is found but is not yet opened, open it (if FACE is not
465 NULL) or return Qnil (if FACE is NULL).
467 ID is a charset-id that must be preferred, or -1 meaning no
470 If FALLBACK is nonzero, search only fallback fonts. */
473 fontset_find_font (fontset
, c
, face
, id
, fallback
)
479 Lisp_Object base_fontset
, elt
, vec
;
481 FRAME_PTR f
= XFRAME (FONTSET_FRAME (fontset
));
483 base_fontset
= FONTSET_BASE (fontset
);
485 vec
= CHAR_TABLE_REF (fontset
, c
);
487 vec
= FONTSET_FALLBACK (fontset
);
493 /* We have not yet decided a font for C. */
498 elt
= char_table_ref_and_range (base_fontset
, c
, &from
, &to
);
499 range
= Fcons (make_number (from
), make_number (to
));
503 elt
= FONTSET_FALLBACK (base_fontset
);
507 /* This fontset doesn't specify any font for C. */
508 vec
= make_number (0);
510 else if (ASIZE (elt
) == 1 && NILP (AREF (elt
, 0)))
512 /* Explicitly specified no font. */
517 /* Build a font-group vector [ -1 nil RFONT-DEF0 RFONT-DEF1 ... ],
518 where the first -1 is to force reordering of RFONT-DEFs. */
519 int size
= ASIZE (elt
);
522 vec
= Fmake_vector (make_number (size
+ 2), Qnil
);
523 ASET (vec
, 0, make_number (-1));
524 for (i
= j
= 0; i
< size
; i
++)
525 if (! NILP (AREF (elt
, i
)))
527 Lisp_Object rfont_def
;
529 RFONT_DEF_NEW (rfont_def
, AREF (elt
, i
));
530 ASET (vec
, j
+ 2, rfont_def
);
534 /* Then store it in the fontset. */
536 FONTSET_SET (fontset
, range
, vec
);
538 FONTSET_FALLBACK (fontset
) = vec
;
542 return (EQ (vec
, Qt
) ? Qt
: Qnil
);
544 if (ASIZE (vec
) > 4 /* multiple RFONT-DEFs */
545 && XINT (AREF (vec
, 0)) != charset_ordered_list_tick
)
546 /* We have just created VEC,
547 or the charset priorities were changed. */
548 reorder_font_vector (vec
, face
->lface
[LFACE_FAMILY_INDEX
]);
554 && EQ (make_number (id
), RFONT_DEF_REPERTORY (elt
)))
558 for (; i
< ASIZE (vec
); i
++)
562 && EQ (make_number (id
), RFONT_DEF_REPERTORY (elt
)))
578 /* Find the first available font in the vector of RFONT-DEF. */
579 for (; i
< ASIZE (vec
); i
++)
581 Lisp_Object font_entity
, font_object
;
585 /* This is the sign of not to try fallback fonts. */
587 if (id
>= 0 && i
> 1 && EQ (AREF (vec
, 1), elt
))
588 /* This is already checked. */
590 if (INTEGERP (RFONT_DEF_FACE (elt
))
591 && XINT (AREF (elt
, 1)) < 0)
592 /* We couldn't open this font last time. */
595 font_object
= RFONT_DEF_OBJECT (elt
);
596 if (NILP (font_object
))
598 Lisp_Object font_def
= RFONT_DEF_FONT_DEF (elt
);
601 /* We have not yet opened the font. */
603 font_entity
= font_find_for_lface (f
, face
->lface
,
604 FONT_DEF_SPEC (font_def
), -1);
605 if (NILP (font_entity
))
607 /* Record that no font matches the spec. */
608 RFONT_DEF_SET_FACE (elt
, -1);
611 font_object
= font_open_for_lface (f
, font_entity
, face
->lface
,
612 FONT_DEF_SPEC (font_def
));
613 if (NILP (font_object
))
615 /* Record that the font is unsable. */
616 RFONT_DEF_SET_FACE (elt
, -1);
619 RFONT_DEF_SET_OBJECT (elt
, font_object
);
622 if (font_has_char (f
, font_object
, c
))
626 /* The following code makes Emacs to find a font for C by fairly
627 exhausitive search. But, that takes long time especially for
630 /* Try to find the different font maching with the current spec
632 font_def
= RFONT_DEF_FONT_DEF (elt
);
633 for (i
++; i
< ASIZE (vec
); i
++)
635 if (! EQ (RFONT_DEF_FONT_DEF (AREF (vec
, i
)), font_def
))
637 if (font_has_char (f
, RFONT_DEF_OBJECT (AREF (vec
, i
)), c
))
638 return AREF (vec
, i
);
640 /* Find an font-entity that support C. */
641 font_entity
= font_find_for_lface (f
, face
->lface
,
642 FONT_DEF_SPEC (font_def
), c
);
643 if (! NILP (font_entity
))
645 Lisp_Object rfont_def
, new_vec
;
648 font_object
= font_open_for_lface (f
, font_entity
, face
->lface
,
650 RFONT_DEF_NEW (rfont_def
, font_def
);
651 RFONT_DEF_SET_OBJECT (rfont_def
, font_object
);
652 RFONT_DEF_SET_SCORE (rfont_def
, RFONT_DEF_SCORE (elt
));
653 new_vec
= Fmake_vector (make_number (ASIZE (vec
) + 1), Qnil
);
654 for (j
= 0; j
< i
; j
++)
655 ASET (new_vec
, j
, AREF (vec
, j
));
656 ASET (new_vec
, j
, rfont_def
);
657 for (j
++; j
< ASIZE (new_vec
); j
++)
658 ASET (new_vec
, j
, AREF (vec
, j
- 1));
666 FONTSET_SET (fontset
, make_number (c
), make_number (0));
672 fontset_font (fontset
, c
, face
, id
)
678 Lisp_Object rfont_def
;
679 Lisp_Object base_fontset
;
681 /* Try a font-group for C. */
682 rfont_def
= fontset_find_font (fontset
, c
, face
, id
, 0);
683 if (VECTORP (rfont_def
))
685 if (EQ (rfont_def
, Qt
))
687 /* Try a fallback font-group. */
688 rfont_def
= fontset_find_font (fontset
, c
, face
, id
, 1);
689 if (VECTORP (rfont_def
))
691 if (EQ (rfont_def
, Qt
))
694 base_fontset
= FONTSET_BASE (fontset
);
695 if (EQ (base_fontset
, Vdefault_fontset
))
698 /* Try a font-group for C of the default fontset. */
699 if (NILP (FONTSET_DEFAULT (fontset
)))
700 FONTSET_DEFAULT (fontset
)
701 = make_fontset (FONTSET_FRAME (fontset
), Qnil
, Vdefault_fontset
);
702 rfont_def
= fontset_find_font (FONTSET_DEFAULT (fontset
), c
, face
, id
, 0);
703 if (VECTORP (rfont_def
))
705 /* Try a fallback font-group of the default fontset . */
706 rfont_def
= fontset_find_font (FONTSET_DEFAULT (fontset
), c
, face
, id
, 1);
707 if (! VECTORP (rfont_def
))
708 /* Remeber that we have no font for C. */
709 FONTSET_SET (fontset
, make_number (c
), Qt
);
714 /* Return a newly created fontset with NAME. If BASE is nil, make a
715 base fontset. Otherwise make a realized fontset whose base is
719 make_fontset (frame
, name
, base
)
720 Lisp_Object frame
, name
, base
;
723 int size
= ASIZE (Vfontset_table
);
724 int id
= next_fontset_id
;
726 /* Find a free slot in Vfontset_table. Usually, next_fontset_id is
727 the next available fontset ID. So it is expected that this loop
728 terminates quickly. In addition, as the last element of
729 Vfontset_table is always nil, we don't have to check the range of
731 while (!NILP (AREF (Vfontset_table
, id
))) id
++;
734 Vfontset_table
= larger_vector (Vfontset_table
, size
+ 32, Qnil
);
736 fontset
= Fmake_char_table (Qfontset
, Qnil
);
738 FONTSET_ID (fontset
) = make_number (id
);
741 FONTSET_NAME (fontset
) = name
;
745 FONTSET_NAME (fontset
) = Qnil
;
746 FONTSET_FRAME (fontset
) = frame
;
747 FONTSET_BASE (fontset
) = base
;
750 ASET (Vfontset_table
, id
, fontset
);
751 next_fontset_id
= id
+ 1;
756 /* Set the ASCII font of the default fontset to FONTNAME if that is
759 set_default_ascii_font (fontname
)
760 Lisp_Object fontname
;
762 if (! STRINGP (FONTSET_ASCII (Vdefault_fontset
)))
764 int id
= fs_query_fontset (fontname
, 2);
767 fontname
= FONTSET_ASCII (FONTSET_FROM_ID (id
));
768 FONTSET_ASCII (Vdefault_fontset
)= fontname
;
773 /********** INTERFACES TO xfaces.c, xfns.c, and dispextern.h **********/
775 /* Return the name of the fontset who has ID. */
783 fontset
= FONTSET_FROM_ID (id
);
784 return FONTSET_NAME (fontset
);
788 /* Return the ASCII font name of the fontset who has ID. */
794 Lisp_Object fontset
, elt
;
796 fontset
= FONTSET_FROM_ID (id
);
797 elt
= FONTSET_ASCII (fontset
);
804 free_realized_fontset (f
, fontset
)
811 for (tail
= FONTSET_OBJLIST (fontset
); CONSP (tail
); tail
= XCDR (tail
))
813 xassert (FONT_OBJECT_P (XCAR (tail
)));
814 font_close_object (f
, XCAR (tail
));
818 /* Free fontset of FACE defined on frame F. Called from
819 free_realized_face. */
822 free_face_fontset (f
, face
)
828 fontset
= FONTSET_FROM_ID (face
->fontset
);
831 xassert (! BASE_FONTSET_P (fontset
));
832 xassert (f
== XFRAME (FONTSET_FRAME (fontset
)));
833 free_realized_fontset (f
, fontset
);
834 ASET (Vfontset_table
, face
->fontset
, Qnil
);
835 if (face
->fontset
< next_fontset_id
)
836 next_fontset_id
= face
->fontset
;
837 if (! NILP (FONTSET_DEFAULT (fontset
)))
839 int id
= XINT (FONTSET_ID (FONTSET_DEFAULT (fontset
)));
841 fontset
= AREF (Vfontset_table
, id
);
842 xassert (!NILP (fontset
) && ! BASE_FONTSET_P (fontset
));
843 xassert (f
== XFRAME (FONTSET_FRAME (fontset
)));
844 free_realized_fontset (f
, fontset
);
845 ASET (Vfontset_table
, id
, Qnil
);
846 if (id
< next_fontset_id
)
847 next_fontset_id
= face
->fontset
;
853 /* Return 1 if FACE is suitable for displaying character C.
854 Otherwise return 0. Called from the macro FACE_SUITABLE_FOR_CHAR_P
855 when C is not an ASCII character. */
858 face_suitable_for_char_p (face
, c
)
862 Lisp_Object fontset
, rfont_def
;
864 fontset
= FONTSET_FROM_ID (face
->fontset
);
865 rfont_def
= fontset_font (fontset
, c
, NULL
, -1);
866 return (VECTORP (rfont_def
)
867 && INTEGERP (RFONT_DEF_FACE (rfont_def
))
868 && face
->id
== XINT (RFONT_DEF_FACE (rfont_def
)));
872 /* Return ID of face suitable for displaying character C on frame F.
873 FACE must be reazlied for ASCII characters in advance. Called from
874 the macro FACE_FOR_CHAR. */
877 face_for_char (f
, face
, c
, pos
, object
)
883 Lisp_Object fontset
, rfont_def
;
887 if (ASCII_CHAR_P (c
))
888 return face
->ascii_face
->id
;
890 xassert (fontset_id_valid_p (face
->fontset
));
891 fontset
= FONTSET_FROM_ID (face
->fontset
);
892 xassert (!BASE_FONTSET_P (fontset
));
899 charset
= Fget_char_property (make_number (pos
), Qcharset
, object
);
902 else if (CHARSETP (charset
))
906 val
= assoc_no_quit (charset
, Vfont_encoding_charset_alist
);
907 if (CONSP (val
) && CHARSETP (XCDR (val
)))
908 charset
= XCDR (val
);
909 id
= XINT (CHARSET_SYMBOL_ID (charset
));
914 struct font
*font
= face
->ascii_face
->font
;
916 if (font
&& font
->driver
->encode_char (font
, c
) != FONT_INVALID_CODE
)
917 return face
->ascii_face
->id
;
919 if (font
&& font
->driver
->encode_char (font
, c
) != FONT_INVALID_CODE
)
923 rfont_def
= fontset_font (fontset
, c
, face
, id
);
924 if (VECTORP (rfont_def
))
926 if (INTEGERP (RFONT_DEF_FACE (rfont_def
)))
927 face_id
= XINT (RFONT_DEF_FACE (rfont_def
));
930 Lisp_Object font_object
;
932 font_object
= RFONT_DEF_OBJECT (rfont_def
);
933 face_id
= face_for_font (f
, font_object
, face
);
934 RFONT_DEF_SET_FACE (rfont_def
, face_id
);
939 if (INTEGERP (FONTSET_NOFONT_FACE (fontset
)))
940 face_id
= XINT (FONTSET_NOFONT_FACE (fontset
));
943 face_id
= face_for_font (f
, Qnil
, face
);
944 FONTSET_NOFONT_FACE (fontset
) = make_number (face_id
);
947 xassert (face_id
>= 0);
952 /* Make a realized fontset for ASCII face FACE on frame F from the
953 base fontset BASE_FONTSET_ID. If BASE_FONTSET_ID is -1, use the
954 default fontset as the base. Value is the id of the new fontset.
955 Called from realize_x_face. */
958 make_fontset_for_ascii_face (f
, base_fontset_id
, face
)
963 Lisp_Object base_fontset
, fontset
, frame
;
965 XSETFRAME (frame
, f
);
966 if (base_fontset_id
>= 0)
968 base_fontset
= FONTSET_FROM_ID (base_fontset_id
);
969 if (!BASE_FONTSET_P (base_fontset
))
970 base_fontset
= FONTSET_BASE (base_fontset
);
971 if (! BASE_FONTSET_P (base_fontset
))
975 base_fontset
= Vdefault_fontset
;
977 fontset
= make_fontset (frame
, Qnil
, base_fontset
);
978 return XINT (FONTSET_ID (fontset
));
983 /* Cache data used by fontset_pattern_regexp. The car part is a
984 pattern string containing at least one wild card, the cdr part is
985 the corresponding regular expression. */
986 static Lisp_Object Vcached_fontset_data
;
988 #define CACHED_FONTSET_NAME ((char *) SDATA (XCAR (Vcached_fontset_data)))
989 #define CACHED_FONTSET_REGEX (XCDR (Vcached_fontset_data))
991 /* If fontset name PATTERN contains any wild card, return regular
992 expression corresponding to PATTERN. */
995 fontset_pattern_regexp (pattern
)
998 if (!index ((char *) SDATA (pattern
), '*')
999 && !index ((char *) SDATA (pattern
), '?'))
1000 /* PATTERN does not contain any wild cards. */
1003 if (!CONSP (Vcached_fontset_data
)
1004 || strcmp ((char *) SDATA (pattern
), CACHED_FONTSET_NAME
))
1006 /* We must at first update the cached data. */
1007 unsigned char *regex
, *p0
, *p1
;
1008 int ndashes
= 0, nstars
= 0, nescs
= 0;
1010 for (p0
= SDATA (pattern
); *p0
; p0
++)
1014 else if (*p0
== '*')
1017 || *p0
== '.' || *p0
== '\\'
1018 || *p0
== '+' || *p0
== '^'
1023 /* If PATTERN is not full XLFD we conert "*" to ".*". Otherwise
1024 we convert "*" to "[^-]*" which is much faster in regular
1025 expression matching. */
1027 p1
= regex
= (unsigned char *) alloca (SBYTES (pattern
) + 2 * nstars
+ 2 * nescs
+ 1);
1029 p1
= regex
= (unsigned char *) alloca (SBYTES (pattern
) + 5 * nstars
+ 2 * nescs
+ 1);
1032 for (p0
= SDATA (pattern
); *p0
; p0
++)
1039 *p1
++ = '[', *p1
++ = '^', *p1
++ = '-', *p1
++ = ']';
1042 else if (*p0
== '?')
1045 || *p0
== '.' || *p0
== '\\'
1046 || *p0
== '+' || *p0
== '^'
1048 *p1
++ = '\\', *p1
++ = *p0
;
1055 Vcached_fontset_data
= Fcons (build_string ((char *) SDATA (pattern
)),
1056 build_string ((char *) regex
));
1059 return CACHED_FONTSET_REGEX
;
1062 /* Return ID of the base fontset named NAME. If there's no such
1063 fontset, return -1. NAME_PATTERN specifies how to treat NAME as this:
1064 0: pattern containing '*' and '?' as wildcards
1065 1: regular expression
1066 2: literal fontset name
1070 fs_query_fontset (name
, name_pattern
)
1077 name
= Fdowncase (name
);
1078 if (name_pattern
!= 1)
1080 tem
= Frassoc (name
, Vfontset_alias_alist
);
1082 tem
= Fassoc (name
, Vfontset_alias_alist
);
1083 if (CONSP (tem
) && STRINGP (XCAR (tem
)))
1085 else if (name_pattern
== 0)
1087 tem
= fontset_pattern_regexp (name
);
1096 for (i
= 0; i
< ASIZE (Vfontset_table
); i
++)
1098 Lisp_Object fontset
, this_name
;
1100 fontset
= FONTSET_FROM_ID (i
);
1102 || !BASE_FONTSET_P (fontset
))
1105 this_name
= FONTSET_NAME (fontset
);
1106 if (name_pattern
== 1
1107 ? fast_string_match_ignore_case (name
, this_name
) >= 0
1108 : !xstrcasecmp (SDATA (name
), SDATA (this_name
)))
1115 DEFUN ("query-fontset", Fquery_fontset
, Squery_fontset
, 1, 2, 0,
1116 doc
: /* Return the name of a fontset that matches PATTERN.
1117 The value is nil if there is no matching fontset.
1118 PATTERN can contain `*' or `?' as a wildcard
1119 just as X font name matching algorithm allows.
1120 If REGEXPP is non-nil, PATTERN is a regular expression. */)
1122 Lisp_Object pattern
, regexpp
;
1124 Lisp_Object fontset
;
1127 (*check_window_system_func
) ();
1129 CHECK_STRING (pattern
);
1131 if (SCHARS (pattern
) == 0)
1134 id
= fs_query_fontset (pattern
, !NILP (regexpp
));
1138 fontset
= FONTSET_FROM_ID (id
);
1139 return FONTSET_NAME (fontset
);
1142 /* Return a list of base fontset names matching PATTERN on frame F. */
1145 list_fontsets (f
, pattern
, size
)
1147 Lisp_Object pattern
;
1150 Lisp_Object frame
, regexp
, val
;
1153 XSETFRAME (frame
, f
);
1155 regexp
= fontset_pattern_regexp (pattern
);
1158 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
1160 Lisp_Object fontset
, name
;
1162 fontset
= FONTSET_FROM_ID (id
);
1164 || !BASE_FONTSET_P (fontset
)
1165 || !EQ (frame
, FONTSET_FRAME (fontset
)))
1167 name
= FONTSET_NAME (fontset
);
1169 if (STRINGP (regexp
)
1170 ? (fast_string_match (regexp
, name
) < 0)
1171 : strcmp ((char *) SDATA (pattern
), (char *) SDATA (name
)))
1174 val
= Fcons (Fcopy_sequence (FONTSET_NAME (fontset
)), val
);
1181 /* Free all realized fontsets whose base fontset is BASE. */
1184 free_realized_fontsets (base
)
1190 /* For the moment, this doesn't work because free_realized_face
1191 doesn't remove FACE from a cache. Until we find a solution, we
1192 suppress this code, and simply use Fclear_face_cache even though
1193 that is not efficient. */
1195 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
1197 Lisp_Object
this = AREF (Vfontset_table
, id
);
1199 if (EQ (FONTSET_BASE (this), base
))
1203 for (tail
= FONTSET_FACE_ALIST (this); CONSP (tail
);
1206 FRAME_PTR f
= XFRAME (FONTSET_FRAME (this));
1207 int face_id
= XINT (XCDR (XCAR (tail
)));
1208 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1210 /* Face THIS itself is also freed by the following call. */
1211 free_realized_face (f
, face
);
1217 /* But, we don't have to call Fclear_face_cache if no fontset has
1218 been realized from BASE. */
1219 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
1221 Lisp_Object
this = AREF (Vfontset_table
, id
);
1223 if (CHAR_TABLE_P (this) && EQ (FONTSET_BASE (this), base
))
1225 Fclear_face_cache (Qt
);
1233 /* Check validity of NAME as a fontset name and return the
1234 corresponding fontset. If not valid, signal an error.
1235 If NAME is t, return Vdefault_fontset. */
1238 check_fontset_name (name
)
1244 return Vdefault_fontset
;
1246 CHECK_STRING (name
);
1247 /* First try NAME as literal. */
1248 id
= fs_query_fontset (name
, 2);
1250 /* For backward compatibility, try again NAME as pattern. */
1251 id
= fs_query_fontset (name
, 0);
1253 error ("Fontset `%s' does not exist", SDATA (name
));
1254 return FONTSET_FROM_ID (id
);
1258 accumulate_script_ranges (arg
, range
, val
)
1259 Lisp_Object arg
, range
, val
;
1261 if (EQ (XCAR (arg
), val
))
1264 XSETCDR (arg
, Fcons (Fcons (XCAR (range
), XCDR (range
)), XCDR (arg
)));
1266 XSETCDR (arg
, Fcons (Fcons (range
, range
), XCDR (arg
)));
1271 /* Return an ASCII font name generated from fontset name NAME and
1272 font-spec ASCII_SPEC. NAME is a string conforming to XLFD. */
1274 static INLINE Lisp_Object
1275 generate_ascii_font_name (name
, ascii_spec
)
1276 Lisp_Object name
, ascii_spec
;
1278 Lisp_Object font_spec
= Ffont_spec (0, NULL
);
1282 if (font_parse_xlfd ((char *) SDATA (name
), font_spec
) < 0)
1283 error ("Not an XLFD font name: %s", SDATA (name
));
1284 for (i
= FONT_FOUNDRY_INDEX
; i
< FONT_EXTRA_INDEX
; i
++)
1285 if (! NILP (AREF (ascii_spec
, i
)))
1286 ASET (font_spec
, i
, AREF (ascii_spec
, i
));
1287 i
= font_unparse_xlfd (font_spec
, 0, xlfd
, 256);
1289 error ("Not an XLFD font name: %s", SDATA (name
));
1290 return make_unibyte_string (xlfd
, i
);
1293 /* Variables referred in set_fontset_font. They are set before
1294 map_charset_chars is called in Fset_fontset_font. */
1295 static Lisp_Object font_def_arg
, add_arg
;
1296 static int from_arg
, to_arg
;
1298 /* Callback function for map_charset_chars in Fset_fontset_font. In
1299 FONTSET, set font_def_arg in a fashion specified by add_arg for
1300 characters in RANGE while ignoring the range between from_arg and
1304 set_fontset_font (fontset
, range
)
1305 Lisp_Object fontset
, range
;
1307 if (from_arg
< to_arg
)
1309 int from
= XINT (XCAR (range
)), to
= XINT (XCDR (range
));
1311 if (from
< from_arg
)
1317 range2
= Fcons (make_number (to_arg
), XCDR (range
));
1318 FONTSET_ADD (fontset
, range
, font_def_arg
, add_arg
);
1322 range
= Fcons (XCAR (range
), make_number (from_arg
));
1324 else if (to
<= to_arg
)
1329 range
= Fcons (make_number (to_arg
), XCDR (range
));
1332 FONTSET_ADD (fontset
, range
, font_def_arg
, add_arg
);
1335 extern Lisp_Object QCfamily
, QCregistry
;
1337 DEFUN ("set-fontset-font", Fset_fontset_font
, Sset_fontset_font
, 3, 5, 0,
1339 Modify fontset NAME to use FONT-SPEC for TARGET characters.
1341 TARGET may be a cons; (FROM . TO), where FROM and TO are characters.
1342 In that case, use FONT-SPEC for all characters in the range FROM and
1345 TARGET may be a script name symbol. In that case, use FONT-SPEC for
1346 all characters that belong to the script.
1348 TARGET may be a charset. In that case, use FONT-SPEC for all
1349 characters in the charset.
1351 TARGET may be nil. In that case, use FONT-SPEC for any characters for
1352 that no FONT-SPEC is specified.
1354 FONT-SPEC may one of these:
1355 * A font-spec object made by the function `font-spec' (which see).
1356 * A cons (FAMILY . REGISTRY), where FAMILY is a font family name and
1357 REGISTRY is a font registry name. FAMILY may contain foundry
1358 name, and REGISTRY may contain encoding name.
1359 * A font name string.
1360 * nil, which explicitly specifies that there's no font for TARGET.
1362 Optional 4th argument FRAME, if non-nil, is a frame. This argument is
1363 kept for backward compatibility and has no meaning.
1365 Optional 5th argument ADD, if non-nil, specifies how to add FONT-SPEC
1366 to the font specifications for TARGET previously set. If it is
1367 `prepend', FONT-SPEC is prepended. If it is `append', FONT-SPEC is
1368 appended. By default, FONT-SPEC overrides the previous settings. */)
1369 (name
, target
, font_spec
, frame
, add
)
1370 Lisp_Object name
, target
, font_spec
, frame
, add
;
1372 Lisp_Object fontset
;
1373 Lisp_Object font_def
, registry
, family
;
1374 Lisp_Object range_list
;
1375 struct charset
*charset
= NULL
;
1377 fontset
= check_fontset_name (name
);
1379 /* The arg FRAME is kept for backward compatibility. We only check
1382 CHECK_LIVE_FRAME (frame
);
1384 if (CONSP (font_spec
))
1386 Lisp_Object spec
= Ffont_spec (0, NULL
);
1388 font_parse_family_registry (XCAR (font_spec
), XCDR (font_spec
), spec
);
1391 else if (STRINGP (font_spec
))
1393 Lisp_Object args
[2];
1394 extern Lisp_Object QCname
;
1397 args
[1] = font_spec
;
1398 font_spec
= Ffont_spec (2, args
);
1400 else if (! NILP (font_spec
) && ! FONT_SPEC_P (font_spec
))
1401 Fsignal (Qfont
, list2 (build_string ("Invalid font-spec"), font_spec
));
1403 if (! NILP (font_spec
))
1405 Lisp_Object encoding
, repertory
;
1407 family
= AREF (font_spec
, FONT_FAMILY_INDEX
);
1408 if (! NILP (family
) )
1409 family
= SYMBOL_NAME (family
);
1410 registry
= AREF (font_spec
, FONT_REGISTRY_INDEX
);
1411 if (! NILP (registry
))
1412 registry
= Fdowncase (SYMBOL_NAME (registry
));
1413 encoding
= find_font_encoding (concat3 (family
, build_string ("-"),
1415 if (NILP (encoding
))
1418 if (SYMBOLP (encoding
))
1420 CHECK_CHARSET (encoding
);
1421 encoding
= repertory
= CHARSET_SYMBOL_ID (encoding
);
1425 repertory
= XCDR (encoding
);
1426 encoding
= XCAR (encoding
);
1427 CHECK_CHARSET (encoding
);
1428 encoding
= CHARSET_SYMBOL_ID (encoding
);
1429 if (! NILP (repertory
) && SYMBOLP (repertory
))
1431 CHECK_CHARSET (repertory
);
1432 repertory
= CHARSET_SYMBOL_ID (repertory
);
1435 FONT_DEF_NEW (font_def
, font_spec
, encoding
, repertory
);
1440 if (CHARACTERP (target
))
1441 range_list
= Fcons (Fcons (target
, target
), Qnil
);
1442 else if (CONSP (target
))
1444 Lisp_Object from
, to
;
1446 from
= Fcar (target
);
1448 CHECK_CHARACTER (from
);
1449 CHECK_CHARACTER (to
);
1450 range_list
= Fcons (target
, Qnil
);
1452 else if (SYMBOLP (target
) && !NILP (target
))
1454 Lisp_Object script_list
;
1458 script_list
= XCHAR_TABLE (Vchar_script_table
)->extras
[0];
1459 if (! NILP (Fmemq (target
, script_list
)))
1461 val
= Fcons (target
, Qnil
);
1462 map_char_table (accumulate_script_ranges
, Qnil
, Vchar_script_table
,
1464 range_list
= XCDR (val
);
1465 if (EQ (target
, Qlatin
) && NILP (FONTSET_ASCII (fontset
)))
1467 if (VECTORP (font_spec
))
1468 val
= generate_ascii_font_name (FONTSET_NAME (fontset
),
1472 FONTSET_ASCII (fontset
) = val
;
1475 if (CHARSETP (target
))
1477 if (EQ (target
, Qascii
) && NILP (FONTSET_ASCII (fontset
)))
1479 if (VECTORP (font_spec
))
1480 font_spec
= generate_ascii_font_name (FONTSET_NAME (fontset
),
1482 FONTSET_ASCII (fontset
) = font_spec
;
1483 range_list
= Fcons (Fcons (make_number (0), make_number (127)),
1488 CHECK_CHARSET_GET_CHARSET (target
, charset
);
1491 else if (NILP (range_list
))
1492 error ("Invalid script or charset name: %s",
1493 SDATA (SYMBOL_NAME (target
)));
1495 else if (NILP (target
))
1496 range_list
= Fcons (Qnil
, Qnil
);
1498 error ("Invalid target for setting a font");
1503 font_def_arg
= font_def
;
1505 if (NILP (range_list
))
1506 from_arg
= to_arg
= 0;
1508 from_arg
= XINT (XCAR (XCAR (range_list
))),
1509 to_arg
= XINT (XCDR (XCAR (range_list
)));
1511 map_charset_chars (set_fontset_font
, Qnil
, fontset
, charset
,
1512 CHARSET_MIN_CODE (charset
),
1513 CHARSET_MAX_CODE (charset
));
1515 for (; CONSP (range_list
); range_list
= XCDR (range_list
))
1516 FONTSET_ADD (fontset
, XCAR (range_list
), font_def
, add
);
1518 /* Free all realized fontsets whose base is FONTSET. This way, the
1519 specified character(s) are surely redisplayed by a correct
1521 free_realized_fontsets (fontset
);
1527 DEFUN ("new-fontset", Fnew_fontset
, Snew_fontset
, 2, 2, 0,
1528 doc
: /* Create a new fontset NAME from font information in FONTLIST.
1530 FONTLIST is an alist of scripts vs the corresponding font specification list.
1531 Each element of FONTLIST has the form (SCRIPT FONT-SPEC ...), where a
1532 character of SCRIPT is displayed by a font that matches one of
1535 SCRIPT is a symbol that appears in the first extra slot of the
1536 char-table `char-script-table'.
1538 FONT-SPEC is a vector, a cons, or a string. See the documentation of
1539 `set-fontset-font' for the meaning. */)
1541 Lisp_Object name
, fontlist
;
1543 Lisp_Object fontset
;
1546 CHECK_STRING (name
);
1547 CHECK_LIST (fontlist
);
1549 name
= Fdowncase (name
);
1550 id
= fs_query_fontset (name
, 0);
1553 Lisp_Object font_spec
= Ffont_spec (0, NULL
);
1554 Lisp_Object short_name
;
1558 if (font_parse_xlfd ((char *) SDATA (name
), font_spec
) < 0)
1559 error ("Fontset name must be in XLFD format");
1560 short_name
= AREF (font_spec
, FONT_REGISTRY_INDEX
);
1561 if (strncmp ((char *) SDATA (SYMBOL_NAME (short_name
)), "fontset-", 8)
1562 || SBYTES (SYMBOL_NAME (short_name
)) < 9)
1563 error ("Registry field of fontset name must be \"fontset-*\"");
1564 Vfontset_alias_alist
= Fcons (Fcons (name
, SYMBOL_NAME (short_name
)),
1565 Vfontset_alias_alist
);
1566 ASET (font_spec
, FONT_REGISTRY_INDEX
, Qiso8859_1
);
1567 fontset
= make_fontset (Qnil
, name
, Qnil
);
1568 len
= font_unparse_xlfd (font_spec
, 0, xlfd
, 256);
1570 error ("Invalid fontset name (perhaps too long): %s", SDATA (name
));
1571 FONTSET_ASCII (fontset
) = make_unibyte_string (xlfd
, len
);
1575 fontset
= FONTSET_FROM_ID (id
);;
1576 free_realized_fontsets (fontset
);
1577 Fset_char_table_range (fontset
, Qt
, Qnil
);
1580 for (; ! NILP (fontlist
); fontlist
= Fcdr (fontlist
))
1582 Lisp_Object elt
, script
;
1584 elt
= Fcar (fontlist
);
1585 script
= Fcar (elt
);
1587 if (CONSP (elt
) && (NILP (XCDR (elt
)) || CONSP (XCDR (elt
))))
1588 for (; CONSP (elt
); elt
= XCDR (elt
))
1589 Fset_fontset_font (name
, script
, XCAR (elt
), Qnil
, Qappend
);
1591 Fset_fontset_font (name
, script
, elt
, Qnil
, Qappend
);
1597 /* Alist of automatically created fontsets. Each element is a cons
1598 (FONT-SPEC . FONTSET-ID). */
1599 static Lisp_Object auto_fontset_alist
;
1602 fontset_from_font (font_object
)
1603 Lisp_Object font_object
;
1605 Lisp_Object font_name
= font_get_name (font_object
);
1606 Lisp_Object font_spec
= Fcopy_font_spec (font_object
);
1607 Lisp_Object fontset_spec
, alias
, name
, fontset
;
1611 val
= assoc_no_quit (font_spec
, auto_fontset_alist
);
1613 return XINT (FONTSET_ID (XCDR (val
)));
1614 if (NILP (auto_fontset_alist
))
1615 alias
= intern ("fontset-startup");
1619 int len
= XINT (Flength (auto_fontset_alist
));
1621 sprintf (temp
, "fontset-auto%d", len
);
1622 alias
= intern (temp
);
1624 fontset_spec
= Fcopy_font_spec (font_spec
);
1625 ASET (fontset_spec
, FONT_REGISTRY_INDEX
, alias
);
1626 name
= Ffont_xlfd_name (fontset_spec
, Qnil
);
1629 fontset
= make_fontset (Qnil
, name
, Qnil
);
1630 Vfontset_alias_alist
= Fcons (Fcons (name
, SYMBOL_NAME (alias
)),
1631 Vfontset_alias_alist
);
1632 alias
= Fdowncase (AREF (font_object
, FONT_NAME_INDEX
));
1633 Vfontset_alias_alist
= Fcons (Fcons (name
, alias
), Vfontset_alias_alist
);
1634 auto_fontset_alist
= Fcons (Fcons (font_spec
, fontset
), auto_fontset_alist
);
1635 FONTSET_ASCII (fontset
) = font_name
;
1636 font_spec
= Fcopy_font_spec (font_spec
);
1637 ASET (font_spec
, FONT_FOUNDRY_INDEX
, Qnil
);
1638 ASET (font_spec
, FONT_ADSTYLE_INDEX
, Qnil
);
1639 for (i
= FONT_WEIGHT_INDEX
; i
< FONT_EXTRA_INDEX
; i
++)
1640 ASET (font_spec
, i
, Qnil
);
1641 Fset_fontset_font (name
, Qlatin
, font_spec
, Qnil
, Qnil
);
1642 font_spec
= Fcopy_font_spec (font_spec
);
1643 ASET (font_spec
, FONT_REGISTRY_INDEX
, Qiso10646_1
);
1644 Fset_fontset_font (name
, Qnil
, font_spec
, Qnil
, Qnil
);
1645 return XINT (FONTSET_ID (fontset
));
1648 /* Return a cons (FONT-NAME . GLYPH-CODE).
1649 FONT-NAME is the font name for the character at POSITION in the current
1650 buffer. This is computed from all the text properties and overlays
1651 that apply to POSITION. POSTION may be nil, in which case,
1652 FONT-NAME is the font name for display the character CH with the
1655 GLYPH-CODE is the glyph code in the font to use for the character.
1657 If the 2nd optional arg CH is non-nil, it is a character to check
1658 the font instead of the character at POSITION.
1660 It returns nil in the following cases:
1662 (1) The window system doesn't have a font for the character (thus
1663 it is displayed by an empty box).
1665 (2) The character code is invalid.
1667 (3) If POSITION is not nil, and the current buffer is not displayed
1670 In addition, the returned font name may not take into account of
1671 such redisplay engine hooks as what used in jit-lock-mode if
1672 POSITION is currently not visible. */
1675 DEFUN ("internal-char-font", Finternal_char_font
, Sinternal_char_font
, 1, 2, 0,
1676 doc
: /* For internal use only. */)
1678 Lisp_Object position
, ch
;
1680 EMACS_INT pos
, pos_byte
, dummy
;
1687 if (NILP (position
))
1689 CHECK_CHARACTER (ch
);
1691 f
= XFRAME (selected_frame
);
1692 face_id
= lookup_basic_face (f
, DEFAULT_FACE_ID
);
1698 Lisp_Object window
, charset
;
1701 CHECK_NUMBER_COERCE_MARKER (position
);
1702 pos
= XINT (position
);
1703 if (pos
< BEGV
|| pos
>= ZV
)
1704 args_out_of_range_3 (position
, make_number (BEGV
), make_number (ZV
));
1705 pos_byte
= CHAR_TO_BYTE (pos
);
1707 c
= FETCH_CHAR (pos_byte
);
1713 window
= Fget_buffer_window (Fcurrent_buffer (), Qnil
);
1716 w
= XWINDOW (window
);
1717 f
= XFRAME (w
->frame
);
1718 face_id
= face_at_buffer_position (w
, pos
, -1, -1, &dummy
, pos
+ 100, 0);
1719 charset
= Fget_char_property (position
, Qcharset
, Qnil
);
1720 if (CHARSETP (charset
))
1721 cs_id
= XINT (CHARSET_SYMBOL_ID (charset
));
1725 if (! CHAR_VALID_P (c
, 0))
1727 face_id
= FACE_FOR_CHAR (f
, FACE_FROM_ID (f
, face_id
), c
, pos
, Qnil
);
1728 face
= FACE_FROM_ID (f
, face_id
);
1731 struct font
*font
= face
->font
;
1732 unsigned code
= font
->driver
->encode_char (font
, c
);
1733 Lisp_Object fontname
= font
->props
[FONT_NAME_INDEX
];
1734 /* Assignment to EMACS_INT stops GCC whining about limited range
1736 EMACS_INT cod
= code
;
1738 if (code
== FONT_INVALID_CODE
)
1740 if (cod
<= MOST_POSITIVE_FIXNUM
)
1741 return Fcons (fontname
, make_number (code
));
1742 return Fcons (fontname
, Fcons (make_number (code
>> 16),
1743 make_number (code
& 0xFFFF)));
1749 DEFUN ("fontset-info", Ffontset_info
, Sfontset_info
, 1, 2, 0,
1750 doc
: /* Return information about a fontset FONTSET on frame FRAME.
1751 The value is a char-table whose elements have this form:
1753 ((FONT-PATTERN OPENED-FONT ...) ...)
1755 FONT-PATTERN is a vector:
1757 [ FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY ]
1759 or a string of font name pattern.
1761 OPENED-FONT is a name of a font actually opened.
1763 The char-table has one extra slot. The value is a char-table
1764 containing the information about the derived fonts from the default
1765 fontset. The format is the same as above. */)
1767 Lisp_Object fontset
, frame
;
1770 Lisp_Object
*realized
[2], fontsets
[2], tables
[2];
1771 Lisp_Object val
, elt
;
1774 (*check_window_system_func
) ();
1776 fontset
= check_fontset_name (fontset
);
1779 frame
= selected_frame
;
1780 CHECK_LIVE_FRAME (frame
);
1783 /* Recode fontsets realized on FRAME from the base fontset FONTSET
1784 in the table `realized'. */
1785 realized
[0] = (Lisp_Object
*) alloca (sizeof (Lisp_Object
)
1786 * ASIZE (Vfontset_table
));
1787 for (i
= j
= 0; i
< ASIZE (Vfontset_table
); i
++)
1789 elt
= FONTSET_FROM_ID (i
);
1791 && EQ (FONTSET_BASE (elt
), fontset
)
1792 && EQ (FONTSET_FRAME (elt
), frame
))
1793 realized
[0][j
++] = elt
;
1795 realized
[0][j
] = Qnil
;
1797 realized
[1] = (Lisp_Object
*) alloca (sizeof (Lisp_Object
)
1798 * ASIZE (Vfontset_table
));
1799 for (i
= j
= 0; ! NILP (realized
[0][i
]); i
++)
1801 elt
= FONTSET_DEFAULT (realized
[0][i
]);
1803 realized
[1][j
++] = elt
;
1805 realized
[1][j
] = Qnil
;
1807 tables
[0] = Fmake_char_table (Qfontset_info
, Qnil
);
1808 tables
[1] = Fmake_char_table (Qnil
, Qnil
);
1809 XCHAR_TABLE (tables
[0])->extras
[0] = tables
[1];
1810 fontsets
[0] = fontset
;
1811 fontsets
[1] = Vdefault_fontset
;
1813 /* Accumulate information of the fontset in TABLE. The format of
1814 each element is ((FONT-SPEC OPENED-FONT ...) ...). */
1815 for (k
= 0; k
<= 1; k
++)
1817 for (c
= 0; c
<= MAX_CHAR
; )
1821 if (c
<= MAX_5_BYTE_CHAR
)
1823 val
= char_table_ref_and_range (fontsets
[k
], c
, &from
, &to
);
1824 if (to
> MAX_5_BYTE_CHAR
)
1825 to
= MAX_5_BYTE_CHAR
;
1829 val
= FONTSET_FALLBACK (fontsets
[k
]);
1836 /* At first, set ALIST to ((FONT-SPEC) ...). */
1837 for (alist
= Qnil
, i
= 0; i
< ASIZE (val
); i
++)
1838 if (! NILP (AREF (val
, i
)))
1839 alist
= Fcons (Fcons (FONT_DEF_SPEC (AREF (val
, i
)), Qnil
),
1841 alist
= Fnreverse (alist
);
1843 /* Then store opened font names to cdr of each elements. */
1844 for (i
= 0; ! NILP (realized
[k
][i
]); i
++)
1846 if (c
<= MAX_5_BYTE_CHAR
)
1847 val
= FONTSET_REF (realized
[k
][i
], c
);
1849 val
= FONTSET_FALLBACK (realized
[k
][i
]);
1850 if (! VECTORP (val
))
1852 /* VAL: [int ? [FACE-ID FONT-DEF FONT-OBJECT int] ... ] */
1853 for (j
= 2; j
< ASIZE (val
); j
++)
1855 elt
= AREF (val
, j
);
1856 if (FONT_OBJECT_P (RFONT_DEF_OBJECT (elt
)))
1858 Lisp_Object font_object
= RFONT_DEF_OBJECT (elt
);
1859 Lisp_Object slot
, name
;
1861 slot
= Fassq (RFONT_DEF_SPEC (elt
), alist
);
1862 name
= AREF (font_object
, FONT_NAME_INDEX
);
1863 if (NILP (Fmember (name
, XCDR (slot
))))
1864 nconc2 (slot
, Fcons (name
, Qnil
));
1869 /* Store ALIST in TBL for characters C..TO. */
1870 if (c
<= MAX_5_BYTE_CHAR
)
1871 char_table_set_range (tables
[k
], c
, to
, alist
);
1873 XCHAR_TABLE (tables
[k
])->defalt
= alist
;
1875 /* At last, change each elements to font names. */
1876 for (; CONSP (alist
); alist
= XCDR (alist
))
1879 XSETCAR (elt
, Ffont_xlfd_name (XCAR (elt
), Qnil
));
1890 DEFUN ("fontset-font", Ffontset_font
, Sfontset_font
, 2, 3, 0,
1891 doc
: /* Return a font name pattern for character CH in fontset NAME.
1892 If NAME is t, find a pattern in the default fontset.
1894 The value has the form (FAMILY . REGISTRY), where FAMILY is a font
1895 family name and REGISTRY is a font registry name. This is actually
1896 the first font name pattern for CH in the fontset or in the default
1899 If the 2nd optional arg ALL is non-nil, return a list of all font name
1902 Lisp_Object name
, ch
, all
;
1905 Lisp_Object fontset
, elt
, list
, repertory
, val
;
1908 fontset
= check_fontset_name (name
);
1910 CHECK_CHARACTER (ch
);
1915 for (i
= 0, elt
= FONTSET_REF (fontset
, c
); i
< 2;
1916 i
++, elt
= FONTSET_FALLBACK (fontset
))
1918 for (j
= 0; j
< ASIZE (elt
); j
++)
1920 val
= AREF (elt
, j
);
1921 repertory
= AREF (val
, 1);
1922 if (INTEGERP (repertory
))
1924 struct charset
*charset
= CHARSET_FROM_ID (XINT (repertory
));
1926 if (! CHAR_CHARSET_P (c
, charset
))
1929 else if (CHAR_TABLE_P (repertory
))
1931 if (NILP (CHAR_TABLE_REF (repertory
, c
)))
1934 val
= AREF (val
, 0);
1935 val
= Fcons (AREF (val
, 0), AREF (val
, 5));
1938 list
= Fcons (val
, list
);
1940 if (EQ (fontset
, Vdefault_fontset
))
1942 fontset
= Vdefault_fontset
;
1944 return (Fnreverse (list
));
1947 DEFUN ("fontset-list", Ffontset_list
, Sfontset_list
, 0, 0, 0,
1948 doc
: /* Return a list of all defined fontset names. */)
1951 Lisp_Object fontset
, list
;
1955 for (i
= 0; i
< ASIZE (Vfontset_table
); i
++)
1957 fontset
= FONTSET_FROM_ID (i
);
1959 && BASE_FONTSET_P (fontset
))
1960 list
= Fcons (FONTSET_NAME (fontset
), list
);
1967 #ifdef FONTSET_DEBUG
1970 dump_fontset (fontset
)
1971 Lisp_Object fontset
;
1975 vec
= Fmake_vector (make_number (3), Qnil
);
1976 ASET (vec
, 0, FONTSET_ID (fontset
));
1978 if (BASE_FONTSET_P (fontset
))
1980 ASET (vec
, 1, FONTSET_NAME (fontset
));
1986 frame
= FONTSET_FRAME (fontset
);
1989 FRAME_PTR f
= XFRAME (frame
);
1991 if (FRAME_LIVE_P (f
))
1993 Fcons (FONTSET_NAME (FONTSET_BASE (fontset
)), f
->name
));
1996 Fcons (FONTSET_NAME (FONTSET_BASE (fontset
)), Qnil
));
1998 if (!NILP (FONTSET_DEFAULT (fontset
)))
1999 ASET (vec
, 2, FONTSET_ID (FONTSET_DEFAULT (fontset
)));
2004 DEFUN ("fontset-list-all", Ffontset_list_all
, Sfontset_list_all
, 0, 0, 0,
2005 doc
: /* Return a brief summary of all fontsets for debug use. */)
2011 for (i
= 0, val
= Qnil
; i
< ASIZE (Vfontset_table
); i
++)
2012 if (! NILP (AREF (Vfontset_table
, i
)))
2013 val
= Fcons (dump_fontset (AREF (Vfontset_table
, i
)), val
);
2014 return (Fnreverse (val
));
2016 #endif /* FONTSET_DEBUG */
2021 DEFSYM (Qfontset
, "fontset");
2022 Fput (Qfontset
, Qchar_table_extra_slots
, make_number (9));
2023 DEFSYM (Qfontset_info
, "fontset-info");
2024 Fput (Qfontset_info
, Qchar_table_extra_slots
, make_number (1));
2026 DEFSYM (Qprepend
, "prepend");
2027 DEFSYM (Qappend
, "append");
2028 DEFSYM (Qlatin
, "latin");
2030 Vcached_fontset_data
= Qnil
;
2031 staticpro (&Vcached_fontset_data
);
2033 Vfontset_table
= Fmake_vector (make_number (32), Qnil
);
2034 staticpro (&Vfontset_table
);
2036 Vdefault_fontset
= Fmake_char_table (Qfontset
, Qnil
);
2037 staticpro (&Vdefault_fontset
);
2038 FONTSET_ID (Vdefault_fontset
) = make_number (0);
2039 FONTSET_NAME (Vdefault_fontset
)
2040 = build_string ("-*-*-*-*-*-*-*-*-*-*-*-*-fontset-default");
2041 ASET (Vfontset_table
, 0, Vdefault_fontset
);
2042 next_fontset_id
= 1;
2044 auto_fontset_alist
= Qnil
;
2045 staticpro (&auto_fontset_alist
);
2047 DEFVAR_LISP ("font-encoding-charset-alist", &Vfont_encoding_charset_alist
,
2049 Alist of charsets vs the charsets to determine the preferred font encoding.
2050 Each element looks like (CHARSET . ENCODING-CHARSET),
2051 where ENCODING-CHARSET is a charset registered in the variable
2052 `font-encoding-alist' as ENCODING.
2054 When a text has a property `charset' and the value is CHARSET, a font
2055 whose encoding corresponds to ENCODING-CHARSET is preferred. */);
2056 Vfont_encoding_charset_alist
= Qnil
;
2058 DEFVAR_LISP ("use-default-ascent", &Vuse_default_ascent
,
2060 Char table of characters whose ascent values should be ignored.
2061 If an entry for a character is non-nil, the ascent value of the glyph
2062 is assumed to be specified by _MULE_DEFAULT_ASCENT property of a font.
2064 This affects how a composite character which contains
2065 such a character is displayed on screen. */);
2066 Vuse_default_ascent
= Qnil
;
2068 DEFVAR_LISP ("ignore-relative-composition", &Vignore_relative_composition
,
2070 Char table of characters which are not composed relatively.
2071 If an entry for a character is non-nil, a composition sequence
2072 which contains that character is displayed so that
2073 the glyph of that character is put without considering
2074 an ascent and descent value of a previous character. */);
2075 Vignore_relative_composition
= Qnil
;
2077 DEFVAR_LISP ("alternate-fontname-alist", &Valternate_fontname_alist
,
2078 doc
: /* Alist of fontname vs list of the alternate fontnames.
2079 When a specified font name is not found, the corresponding
2080 alternate fontnames (if any) are tried instead. */);
2081 Valternate_fontname_alist
= Qnil
;
2083 DEFVAR_LISP ("fontset-alias-alist", &Vfontset_alias_alist
,
2084 doc
: /* Alist of fontset names vs the aliases. */);
2085 Vfontset_alias_alist
= Fcons (Fcons (FONTSET_NAME (Vdefault_fontset
),
2086 build_string ("fontset-default")),
2089 DEFVAR_LISP ("vertical-centering-font-regexp",
2090 &Vvertical_centering_font_regexp
,
2091 doc
: /* *Regexp matching font names that require vertical centering on display.
2092 When a character is displayed with such fonts, the character is displayed
2093 at the vertical center of lines. */);
2094 Vvertical_centering_font_regexp
= Qnil
;
2096 DEFVAR_LISP ("otf-script-alist", &Votf_script_alist
,
2097 doc
: /* Alist of OpenType script tags vs the corresponding script names. */);
2098 Votf_script_alist
= Qnil
;
2100 defsubr (&Squery_fontset
);
2101 defsubr (&Snew_fontset
);
2102 defsubr (&Sset_fontset_font
);
2103 defsubr (&Sinternal_char_font
);
2104 defsubr (&Sfontset_info
);
2105 defsubr (&Sfontset_font
);
2106 defsubr (&Sfontset_list
);
2107 #ifdef FONTSET_DEBUG
2108 defsubr (&Sfontset_list_all
);
2112 /* arch-tag: ea861585-2f5f-4e5b-9849-d04a9c3a3537
2113 (do not change this comment) */