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 */
33 #include "blockinput.h"
35 #include "character.h"
40 #include "dispextern.h"
41 #include "intervals.h"
53 #include "termhooks.h"
59 #define xassert(X) do {if (!(X)) abort ();} while (0)
62 #else /* not FONTSET_DEBUG */
63 #define xassert(X) (void) 0
64 #endif /* not FONTSET_DEBUG */
66 EXFUN (Fclear_face_cache
, 1);
70 A fontset is a collection of font related information to give
71 similar appearance (style, etc) of characters. A fontset has two
72 roles. One is to use for the frame parameter `font' as if it is an
73 ASCII font. In that case, Emacs uses the font specified for
74 `ascii' script for the frame's default font.
76 Another role, the more important one, is to provide information
77 about which font to use for each non-ASCII character.
79 There are two kinds of fontsets; base and realized. A base fontset
80 is created by `new-fontset' from Emacs Lisp explicitly. A realized
81 fontset is created implicitly when a face is realized for ASCII
82 characters. A face is also realized for non-ASCII characters based
83 on an ASCII face. All of non-ASCII faces based on the same ASCII
84 face share the same realized fontset.
86 A fontset object is implemented by a char-table whose default value
87 and parent are always nil.
89 An element of a base fontset is a vector of FONT-DEFs which itself
90 is a vector [ FONT-SPEC ENCODING REPERTORY ].
92 An element of a realized fontset is nil, t, or a vector of this form:
94 [ CHARSET-ORDERED-LIST-TICK PREFERRED-RFONT-DEF
95 RFONT-DEF0 RFONT-DEF1 ... ]
97 RFONT-DEFn (i.e. Realized FONT-DEF) has this form:
99 [ FACE-ID FONT-DEF FONT-OBJECT SORTING-SCORE ]
101 RFONT-DEFn are automatically reordered by the current charset
104 The value nil means that we have not yet generated the above vector
105 from the base of the fontset.
107 The value t means that no font is available for the corresponding
111 A fontset has 9 extra slots.
113 The 1st slot: the ID number of the fontset
116 base: the name of the fontset
121 realized: the base fontset
125 realized: the frame that the fontset belongs to
128 base: the font name for ASCII characters
133 realized: the ID number of a face to use for characters that
134 has no font in a realized fontset.
138 realized: Alist of font index vs the corresponding repertory
143 realized: If the base is not the default fontset, a fontset
144 realized from the default fontset, else nil.
147 base: Same as element value (but for fallback fonts).
150 All fontsets are recorded in the vector Vfontset_table.
155 There's a special base fontset named `default fontset' which
156 defines the default font specifications. When a base fontset
157 doesn't specify a font for a specific character, the corresponding
158 value in the default fontset is used.
160 The parent of a realized fontset created for such a face that has
161 no fontset is the default fontset.
164 These structures are hidden from the other codes than this file.
165 The other codes handle fontsets only by their ID numbers. They
166 usually use the variable name `fontset' for IDs. But, in this
167 file, we always use varialbe name `id' for IDs, and name `fontset'
168 for an actual fontset object, i.e., char-table.
172 /********** VARIABLES and FUNCTION PROTOTYPES **********/
174 extern Lisp_Object Qfont
;
175 static Lisp_Object Qfontset
;
176 static Lisp_Object Qfontset_info
;
177 static Lisp_Object Qprepend
, Qappend
;
178 static Lisp_Object Qlatin
;
180 /* Vector containing all fontsets. */
181 static Lisp_Object Vfontset_table
;
183 /* Next possibly free fontset ID. Usually this keeps the minimum
184 fontset ID not yet used. */
185 static int next_fontset_id
;
187 /* The default fontset. This gives default FAMILY and REGISTRY of
188 font for each character. */
189 static Lisp_Object Vdefault_fontset
;
191 Lisp_Object Vfont_encoding_charset_alist
;
192 Lisp_Object Vuse_default_ascent
;
193 Lisp_Object Vignore_relative_composition
;
194 Lisp_Object Valternate_fontname_alist
;
195 Lisp_Object Vfontset_alias_alist
;
196 Lisp_Object Vvertical_centering_font_regexp
;
197 Lisp_Object Votf_script_alist
;
199 /* Check if any window system is used now. */
200 void (*check_window_system_func
) P_ ((void));
203 /* Prototype declarations for static functions. */
204 static Lisp_Object fontset_add
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
,
206 static Lisp_Object fontset_find_font
P_ ((Lisp_Object
, int, struct face
*,
208 static void reorder_font_vector
P_ ((Lisp_Object
, struct font
*));
209 static Lisp_Object fontset_font
P_ ((Lisp_Object
, int, struct face
*, int));
210 static Lisp_Object make_fontset
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
));
211 static Lisp_Object fontset_pattern_regexp
P_ ((Lisp_Object
));
212 static void accumulate_script_ranges
P_ ((Lisp_Object
, Lisp_Object
,
214 Lisp_Object find_font_encoding
P_ ((Lisp_Object
));
216 static void set_fontset_font
P_ ((Lisp_Object
, Lisp_Object
));
220 /* Return 1 if ID is a valid fontset id, else return 0. */
223 fontset_id_valid_p (id
)
226 return (id
>= 0 && id
< ASIZE (Vfontset_table
) - 1);
233 /********** MACROS AND FUNCTIONS TO HANDLE FONTSET **********/
235 /* Return the fontset with ID. No check of ID's validness. */
236 #define FONTSET_FROM_ID(id) AREF (Vfontset_table, id)
238 /* Macros to access special values of FONTSET. */
239 #define FONTSET_ID(fontset) XCHAR_TABLE (fontset)->extras[0]
241 /* Macros to access special values of (base) FONTSET. */
242 #define FONTSET_NAME(fontset) XCHAR_TABLE (fontset)->extras[1]
243 #define FONTSET_ASCII(fontset) XCHAR_TABLE (fontset)->extras[4]
244 #define FONTSET_SPEC(fontset) XCHAR_TABLE (fontset)->extras[5]
246 /* Macros to access special values of (realized) FONTSET. */
247 #define FONTSET_BASE(fontset) XCHAR_TABLE (fontset)->extras[2]
248 #define FONTSET_FRAME(fontset) XCHAR_TABLE (fontset)->extras[3]
249 #define FONTSET_OBJLIST(fontset) XCHAR_TABLE (fontset)->extras[4]
250 #define FONTSET_NOFONT_FACE(fontset) XCHAR_TABLE (fontset)->extras[5]
251 #define FONTSET_REPERTORY(fontset) XCHAR_TABLE (fontset)->extras[6]
252 #define FONTSET_DEFAULT(fontset) XCHAR_TABLE (fontset)->extras[7]
254 /* For both base and realized fontset. */
255 #define FONTSET_FALLBACK(fontset) XCHAR_TABLE (fontset)->extras[8]
257 #define BASE_FONTSET_P(fontset) (NILP (FONTSET_BASE (fontset)))
260 /* Macros for FONT-DEF and RFONT-DEF of fontset. */
261 #define FONT_DEF_NEW(font_def, font_spec, encoding, repertory) \
263 (font_def) = Fmake_vector (make_number (3), (font_spec)); \
264 ASET ((font_def), 1, encoding); \
265 ASET ((font_def), 2, repertory); \
268 #define FONT_DEF_SPEC(font_def) AREF (font_def, 0)
269 #define FONT_DEF_ENCODING(font_def) AREF (font_def, 1)
270 #define FONT_DEF_REPERTORY(font_def) AREF (font_def, 2)
272 #define RFONT_DEF_FACE(rfont_def) AREF (rfont_def, 0)
273 #define RFONT_DEF_SET_FACE(rfont_def, face_id) \
274 ASET ((rfont_def), 0, make_number (face_id))
275 #define RFONT_DEF_FONT_DEF(rfont_def) AREF (rfont_def, 1)
276 #define RFONT_DEF_SPEC(rfont_def) FONT_DEF_SPEC (AREF (rfont_def, 1))
277 #define RFONT_DEF_REPERTORY(rfont_def) FONT_DEF_REPERTORY (AREF (rfont_def, 1))
278 #define RFONT_DEF_OBJECT(rfont_def) AREF (rfont_def, 2)
279 #define RFONT_DEF_SET_OBJECT(rfont_def, object) \
280 ASET ((rfont_def), 2, (object))
281 #define RFONT_DEF_SCORE(rfont_def) XINT (AREF (rfont_def, 3))
282 #define RFONT_DEF_SET_SCORE(rfont_def, score) \
283 ASET ((rfont_def), 3, make_number (score))
284 #define RFONT_DEF_NEW(rfont_def, font_def) \
286 (rfont_def) = Fmake_vector (make_number (4), Qnil); \
287 ASET ((rfont_def), 1, (font_def)); \
288 RFONT_DEF_SET_SCORE ((rfont_def), 0); \
292 /* Return the element of FONTSET for the character C. If FONTSET is a
293 base fontset other then the default fontset and FONTSET doesn't
294 contain information for C, return the information in the default
297 #define FONTSET_REF(fontset, c) \
298 (EQ (fontset, Vdefault_fontset) \
299 ? CHAR_TABLE_REF (fontset, c) \
300 : fontset_ref ((fontset), (c)))
303 fontset_ref (fontset
, c
)
309 elt
= CHAR_TABLE_REF (fontset
, c
);
310 if (NILP (elt
) && ! EQ (fontset
, Vdefault_fontset
)
311 /* Don't check Vdefault_fontset for a realized fontset. */
312 && NILP (FONTSET_BASE (fontset
)))
313 elt
= CHAR_TABLE_REF (Vdefault_fontset
, c
);
317 /* Set elements of FONTSET for characters in RANGE to the value ELT.
318 RANGE is a cons (FROM . TO), where FROM and TO are character codes
319 specifying a range. */
321 #define FONTSET_SET(fontset, range, elt) \
322 Fset_char_table_range ((fontset), (range), (elt))
325 /* Modify the elements of FONTSET for characters in RANGE by replacing
326 with ELT or adding ELT. RANGE is a cons (FROM . TO), where FROM
327 and TO are character codes specifying a range. If ADD is nil,
328 replace with ELT, if ADD is `prepend', prepend ELT, otherwise,
331 #define FONTSET_ADD(fontset, range, elt, add) \
334 ? (FONTSET_FALLBACK (fontset) = Fmake_vector (make_number (1), (elt))) \
335 : Fset_char_table_range ((fontset), (range), \
336 Fmake_vector (make_number (1), (elt)))) \
337 : fontset_add ((fontset), (range), (elt), (add)))
340 fontset_add (fontset
, range
, elt
, add
)
341 Lisp_Object fontset
, range
, elt
, add
;
344 int idx
= (EQ (add
, Qappend
) ? 0 : 1);
346 args
[1 - idx
] = Fmake_vector (make_number (1), elt
);
350 int from
= XINT (XCAR (range
));
351 int to
= XINT (XCDR (range
));
355 args
[idx
] = char_table_ref_and_range (fontset
, from
, &from1
, &to1
);
358 char_table_set_range (fontset
, from
, to1
,
359 NILP (args
[idx
]) ? args
[1 - idx
]
360 : Fvconcat (2, args
));
366 args
[idx
] = FONTSET_FALLBACK (fontset
);
367 FONTSET_FALLBACK (fontset
)
368 = NILP (args
[idx
]) ? args
[1 - idx
] : Fvconcat (2, args
);
374 fontset_compare_rfontdef (val1
, val2
)
375 const void *val1
, *val2
;
377 return (RFONT_DEF_SCORE (*(Lisp_Object
*) val1
)
378 - RFONT_DEF_SCORE (*(Lisp_Object
*) val2
));
381 /* Update FONT-GROUP which has this form:
382 [ CHARSET-ORDERED-LIST-TICK PREFERRED-RFONT-DEF
383 RFONT-DEF0 RFONT-DEF1 ... ]
384 Reorder RFONT-DEFs according to the current language, and update
385 CHARSET-ORDERED-LIST-TICK.
387 If PREFERRED_FAMILY is not nil, that family has the higher priority
388 if the encoding charsets or languages in font-specs are the same. */
390 extern Lisp_Object
Fassoc_string ();
393 reorder_font_vector (font_group
, font
)
394 Lisp_Object font_group
;
397 Lisp_Object vec
, font_object
;
400 int score_changed
= 0;
403 XSETFONT (font_object
, font
);
407 vec
= XCDR (font_group
);
409 /* Exclude the tailing nil element from the reordering. */
410 if (NILP (AREF (vec
, size
- 1)))
413 for (i
= 0; i
< size
; i
++)
415 Lisp_Object rfont_def
= AREF (vec
, i
);
416 Lisp_Object font_def
= RFONT_DEF_FONT_DEF (rfont_def
);
417 Lisp_Object font_spec
= FONT_DEF_SPEC (font_def
);
418 int score
= RFONT_DEF_SCORE (rfont_def
) & 0xFF;
420 if (! font_match_p (font_spec
, font_object
))
422 Lisp_Object encoding
= FONT_DEF_ENCODING (font_def
);
424 if (! NILP (encoding
))
428 for (tail
= Vcharset_ordered_list
;
429 ! EQ (tail
, Vcharset_non_preferred_head
) && CONSP (tail
);
430 score
+= 0x100, tail
= XCDR (tail
))
431 if (EQ (encoding
, XCAR (tail
)))
436 Lisp_Object lang
= Ffont_get (font_spec
, QClang
);
439 && ! EQ (lang
, Vcurrent_iso639_language
)
440 && (! CONSP (Vcurrent_iso639_language
)
441 || NILP (Fmemq (lang
, Vcurrent_iso639_language
))))
445 if (RFONT_DEF_SCORE (rfont_def
) != score
)
447 RFONT_DEF_SET_SCORE (rfont_def
, score
);
453 qsort (XVECTOR (vec
)->contents
, size
, sizeof (Lisp_Object
),
454 fontset_compare_rfontdef
);
455 XSETCAR (font_group
, make_number (charset_ordered_list_tick
));
459 fontset_get_font_group (Lisp_Object fontset
, int c
)
461 Lisp_Object font_group
;
462 Lisp_Object base_fontset
;
465 xassert (! BASE_FONTSET_P (fontset
));
467 font_group
= CHAR_TABLE_REF (fontset
, c
);
469 font_group
= FONTSET_FALLBACK (fontset
);
470 if (! NILP (font_group
))
472 base_fontset
= FONTSET_BASE (fontset
);
474 font_group
= char_table_ref_and_range (base_fontset
, c
, &from
, &to
);
476 font_group
= FONTSET_FALLBACK (base_fontset
);
477 if (NILP (font_group
))
479 font_group
= Fcopy_sequence (font_group
);
480 for (i
= 0; i
< ASIZE (font_group
); i
++)
481 if (! NILP (AREF (font_group
, i
)))
483 Lisp_Object rfont_def
;
485 RFONT_DEF_NEW (rfont_def
, AREF (font_group
, i
));
486 /* Remember the original order. */
487 RFONT_DEF_SET_SCORE (rfont_def
, i
);
488 ASET (font_group
, i
, rfont_def
);
490 font_group
= Fcons (make_number (-1), font_group
);
492 char_table_set_range (fontset
, from
, to
, font_group
);
494 FONTSET_FALLBACK (fontset
) = font_group
;
498 /* Return RFONT-DEF (vector) in the realized fontset FONTSET for the
499 character C. If no font is found, return Qnil if there's a
500 possibility that the default fontset or the fallback font groups
501 have a proper font, and return Qt if not.
503 If a font is found but is not yet opened, open it (if FACE is not
504 NULL) or return Qnil (if FACE is NULL).
506 ID is a charset-id that must be preferred, or -1 meaning no
509 If FALLBACK is nonzero, search only fallback fonts. */
512 fontset_find_font (fontset
, c
, face
, id
, fallback
)
518 Lisp_Object elt
, vec
, font_group
;
519 int i
, charset_matched
= -1;
520 FRAME_PTR f
= (FRAMEP (FONTSET_FRAME (fontset
)))
521 ? XFRAME (selected_frame
) : XFRAME (FONTSET_FRAME (fontset
));
523 font_group
= fontset_get_font_group (fontset
, fallback
? -1 : c
);
524 if (! CONSP (font_group
))
526 vec
= XCDR (font_group
);
527 if (ASIZE (vec
) == 0)
532 if (XINT (XCAR (font_group
)) != charset_ordered_list_tick
)
533 /* We have just created the font-group,
534 or the charset priorities were changed. */
535 reorder_font_vector (font_group
, face
->ascii_face
->font
);
537 /* Find a spec matching with the charset ID to try at
539 for (i
= 0; i
< ASIZE (vec
); i
++)
541 Lisp_Object rfont_def
= AREF (vec
, i
);
542 Lisp_Object repertory
543 = FONT_DEF_REPERTORY (RFONT_DEF_FONT_DEF (rfont_def
));
545 if (XINT (repertory
) == id
)
553 /* Find the first available font in the vector of RFONT-DEF. */
554 for (i
= 0; i
< ASIZE (vec
); i
++)
556 Lisp_Object font_entity
, font_object
;
558 if (i
== 0 && charset_matched
>= 0)
560 /* Try the element matching with the charset ID at first. */
561 elt
= AREF (vec
, charset_matched
);
562 charset_matched
= -1;
565 else if (i
!= charset_matched
)
571 /* This is a sign of not to try the other fonts. */
573 if (INTEGERP (RFONT_DEF_FACE (elt
))
574 && XINT (AREF (elt
, 1)) < 0)
575 /* We couldn't open this font last time. */
578 font_object
= RFONT_DEF_OBJECT (elt
);
579 if (NILP (font_object
))
581 Lisp_Object font_def
= RFONT_DEF_FONT_DEF (elt
);
584 /* We have not yet opened the font. */
586 font_entity
= font_find_for_lface (f
, face
->lface
,
587 FONT_DEF_SPEC (font_def
), -1);
588 if (NILP (font_entity
))
590 /* Record that no font matches the spec. */
591 RFONT_DEF_SET_FACE (elt
, -1);
594 font_object
= font_open_for_lface (f
, font_entity
, face
->lface
,
595 FONT_DEF_SPEC (font_def
));
596 if (NILP (font_object
))
598 /* Record that the font is unsable. */
599 RFONT_DEF_SET_FACE (elt
, -1);
602 RFONT_DEF_SET_OBJECT (elt
, font_object
);
605 if (font_has_char (f
, font_object
, c
))
609 /* The following code makes Emacs to find a font for C by fairly
610 exhausitive search. But, that takes long time especially for
613 /* Try to find the different font maching with the current spec
615 font_def
= RFONT_DEF_FONT_DEF (elt
);
616 for (i
++; i
< ASIZE (vec
); i
++)
618 if (! EQ (RFONT_DEF_FONT_DEF (AREF (vec
, i
)), font_def
))
620 if (font_has_char (f
, RFONT_DEF_OBJECT (AREF (vec
, i
)), c
))
621 return AREF (vec
, i
);
623 /* Find an font-entity that support C. */
624 font_entity
= font_find_for_lface (f
, face
->lface
,
625 FONT_DEF_SPEC (font_def
), c
);
626 if (! NILP (font_entity
))
628 Lisp_Object rfont_def
, new_vec
;
631 font_object
= font_open_for_lface (f
, font_entity
, face
->lface
,
633 RFONT_DEF_NEW (rfont_def
, font_def
);
634 RFONT_DEF_SET_OBJECT (rfont_def
, font_object
);
635 RFONT_DEF_SET_SCORE (rfont_def
, RFONT_DEF_SCORE (elt
));
636 new_vec
= Fmake_vector (make_number (ASIZE (vec
) + 1), Qnil
);
637 for (j
= 0; j
< i
; j
++)
638 ASET (new_vec
, j
, AREF (vec
, j
));
639 ASET (new_vec
, j
, rfont_def
);
640 for (j
++; j
< ASIZE (new_vec
); j
++)
641 ASET (new_vec
, j
, AREF (vec
, j
- 1));
649 FONTSET_SET (fontset
, make_number (c
), make_number (0));
655 fontset_font (fontset
, c
, face
, id
)
661 Lisp_Object rfont_def
;
662 Lisp_Object base_fontset
;
664 /* Try a font-group of FONTSET. */
665 rfont_def
= fontset_find_font (fontset
, c
, face
, id
, 0);
666 if (VECTORP (rfont_def
))
668 if (EQ (rfont_def
, Qt
))
671 /* Try a font-group of the default fontset. */
672 base_fontset
= FONTSET_BASE (fontset
);
673 if (! EQ (base_fontset
, Vdefault_fontset
))
675 if (NILP (FONTSET_DEFAULT (fontset
)))
676 FONTSET_DEFAULT (fontset
)
677 = make_fontset (FONTSET_FRAME (fontset
), Qnil
, Vdefault_fontset
);
678 rfont_def
= fontset_find_font (FONTSET_DEFAULT (fontset
), c
, face
, id
, 0);
679 if (VECTORP (rfont_def
))
681 if (EQ (rfont_def
, Qt
))
685 /* Try a fallback font-group of FONTSET. */
686 rfont_def
= fontset_find_font (fontset
, c
, face
, id
, 1);
687 if (VECTORP (rfont_def
))
689 if (EQ (rfont_def
, Qt
))
692 /* Try a fallback font-group of the default fontset . */
693 if (! EQ (base_fontset
, Vdefault_fontset
))
695 rfont_def
= fontset_find_font (FONTSET_DEFAULT (fontset
), c
, face
, id
, 1);
696 if (VECTORP (rfont_def
))
700 /* Remeber that we have no font for C. */
701 FONTSET_SET (fontset
, make_number (c
), Qt
);
706 /* Return a newly created fontset with NAME. If BASE is nil, make a
707 base fontset. Otherwise make a realized fontset whose base is
711 make_fontset (frame
, name
, base
)
712 Lisp_Object frame
, name
, base
;
715 int size
= ASIZE (Vfontset_table
);
716 int id
= next_fontset_id
;
718 /* Find a free slot in Vfontset_table. Usually, next_fontset_id is
719 the next available fontset ID. So it is expected that this loop
720 terminates quickly. In addition, as the last element of
721 Vfontset_table is always nil, we don't have to check the range of
723 while (!NILP (AREF (Vfontset_table
, id
))) id
++;
726 Vfontset_table
= larger_vector (Vfontset_table
, size
+ 32, Qnil
);
728 fontset
= Fmake_char_table (Qfontset
, Qnil
);
730 FONTSET_ID (fontset
) = make_number (id
);
733 FONTSET_NAME (fontset
) = name
;
737 FONTSET_NAME (fontset
) = Qnil
;
738 FONTSET_FRAME (fontset
) = frame
;
739 FONTSET_BASE (fontset
) = base
;
742 ASET (Vfontset_table
, id
, fontset
);
743 next_fontset_id
= id
+ 1;
748 /* Set the ASCII font of the default fontset to FONTNAME if that is
751 set_default_ascii_font (fontname
)
752 Lisp_Object fontname
;
754 if (! STRINGP (FONTSET_ASCII (Vdefault_fontset
)))
756 int id
= fs_query_fontset (fontname
, 2);
759 fontname
= FONTSET_ASCII (FONTSET_FROM_ID (id
));
760 FONTSET_ASCII (Vdefault_fontset
)= fontname
;
765 /********** INTERFACES TO xfaces.c, xfns.c, and dispextern.h **********/
767 /* Return the name of the fontset who has ID. */
775 fontset
= FONTSET_FROM_ID (id
);
776 return FONTSET_NAME (fontset
);
780 /* Return the ASCII font name of the fontset who has ID. */
786 Lisp_Object fontset
, elt
;
788 fontset
= FONTSET_FROM_ID (id
);
789 elt
= FONTSET_ASCII (fontset
);
796 free_realized_fontset (f
, fontset
)
803 for (tail
= FONTSET_OBJLIST (fontset
); CONSP (tail
); tail
= XCDR (tail
))
805 xassert (FONT_OBJECT_P (XCAR (tail
)));
806 font_close_object (f
, XCAR (tail
));
810 /* Free fontset of FACE defined on frame F. Called from
811 free_realized_face. */
814 free_face_fontset (f
, face
)
820 fontset
= FONTSET_FROM_ID (face
->fontset
);
823 xassert (! BASE_FONTSET_P (fontset
));
824 xassert (f
== XFRAME (FONTSET_FRAME (fontset
)));
825 free_realized_fontset (f
, fontset
);
826 ASET (Vfontset_table
, face
->fontset
, Qnil
);
827 if (face
->fontset
< next_fontset_id
)
828 next_fontset_id
= face
->fontset
;
829 if (! NILP (FONTSET_DEFAULT (fontset
)))
831 int id
= XINT (FONTSET_ID (FONTSET_DEFAULT (fontset
)));
833 fontset
= AREF (Vfontset_table
, id
);
834 xassert (!NILP (fontset
) && ! BASE_FONTSET_P (fontset
));
835 xassert (f
== XFRAME (FONTSET_FRAME (fontset
)));
836 free_realized_fontset (f
, fontset
);
837 ASET (Vfontset_table
, id
, Qnil
);
838 if (id
< next_fontset_id
)
839 next_fontset_id
= face
->fontset
;
845 /* Return 1 if FACE is suitable for displaying character C.
846 Otherwise return 0. Called from the macro FACE_SUITABLE_FOR_CHAR_P
847 when C is not an ASCII character. */
850 face_suitable_for_char_p (face
, c
)
854 Lisp_Object fontset
, rfont_def
;
856 fontset
= FONTSET_FROM_ID (face
->fontset
);
857 rfont_def
= fontset_font (fontset
, c
, NULL
, -1);
858 return (VECTORP (rfont_def
)
859 && INTEGERP (RFONT_DEF_FACE (rfont_def
))
860 && face
->id
== XINT (RFONT_DEF_FACE (rfont_def
)));
864 /* Return ID of face suitable for displaying character C on frame F.
865 FACE must be reazlied for ASCII characters in advance. Called from
866 the macro FACE_FOR_CHAR. */
869 face_for_char (f
, face
, c
, pos
, object
)
875 Lisp_Object fontset
, rfont_def
, charset
;
879 /* If face->fontset is negative (that happens when no font is found
880 for face), just return face->ascii_face because we can't do
881 anything. Perhaps, we should fix the callers to assure
882 that face->fontset is always valid. */
883 if (ASCII_CHAR_P (c
) || face
->fontset
< 0)
884 return face
->ascii_face
->id
;
886 xassert (fontset_id_valid_p (face
->fontset
));
887 fontset
= FONTSET_FROM_ID (face
->fontset
);
888 xassert (!BASE_FONTSET_P (fontset
));
897 charset
= Fget_char_property (make_number (pos
), Qcharset
, object
);
900 else if (CHARSETP (charset
))
904 val
= assoc_no_quit (charset
, Vfont_encoding_charset_alist
);
905 if (CONSP (val
) && CHARSETP (XCDR (val
)))
906 charset
= XCDR (val
);
907 id
= XINT (CHARSET_SYMBOL_ID (charset
));
911 font_deferred_log ("font for", Fcons (make_number (c
), charset
), Qnil
);
912 rfont_def
= fontset_font (fontset
, c
, face
, id
);
913 if (VECTORP (rfont_def
))
915 if (INTEGERP (RFONT_DEF_FACE (rfont_def
)))
916 face_id
= XINT (RFONT_DEF_FACE (rfont_def
));
919 Lisp_Object font_object
;
921 font_object
= RFONT_DEF_OBJECT (rfont_def
);
922 face_id
= face_for_font (f
, font_object
, face
);
923 RFONT_DEF_SET_FACE (rfont_def
, face_id
);
928 if (INTEGERP (FONTSET_NOFONT_FACE (fontset
)))
929 face_id
= XINT (FONTSET_NOFONT_FACE (fontset
));
932 face_id
= face_for_font (f
, Qnil
, face
);
933 FONTSET_NOFONT_FACE (fontset
) = make_number (face_id
);
936 xassert (face_id
>= 0);
942 font_for_char (face
, c
, pos
, object
)
947 Lisp_Object fontset
, rfont_def
, charset
;
951 if (ASCII_CHAR_P (c
))
953 Lisp_Object font_object
;
955 XSETFONT (font_object
, face
->ascii_face
->font
);
959 xassert (fontset_id_valid_p (face
->fontset
));
960 fontset
= FONTSET_FROM_ID (face
->fontset
);
961 xassert (!BASE_FONTSET_P (fontset
));
969 charset
= Fget_char_property (make_number (pos
), Qcharset
, object
);
972 else if (CHARSETP (charset
))
976 val
= assoc_no_quit (charset
, Vfont_encoding_charset_alist
);
977 if (CONSP (val
) && CHARSETP (XCDR (val
)))
978 charset
= XCDR (val
);
979 id
= XINT (CHARSET_SYMBOL_ID (charset
));
983 font_deferred_log ("font for", Fcons (make_number (c
), charset
), Qnil
);
984 rfont_def
= fontset_font (fontset
, c
, face
, id
);
985 return (VECTORP (rfont_def
)
986 ? RFONT_DEF_OBJECT (rfont_def
)
991 /* Make a realized fontset for ASCII face FACE on frame F from the
992 base fontset BASE_FONTSET_ID. If BASE_FONTSET_ID is -1, use the
993 default fontset as the base. Value is the id of the new fontset.
994 Called from realize_x_face. */
997 make_fontset_for_ascii_face (f
, base_fontset_id
, face
)
1002 Lisp_Object base_fontset
, fontset
, frame
;
1004 XSETFRAME (frame
, f
);
1005 if (base_fontset_id
>= 0)
1007 base_fontset
= FONTSET_FROM_ID (base_fontset_id
);
1008 if (!BASE_FONTSET_P (base_fontset
))
1009 base_fontset
= FONTSET_BASE (base_fontset
);
1010 if (! BASE_FONTSET_P (base_fontset
))
1014 base_fontset
= Vdefault_fontset
;
1016 fontset
= make_fontset (frame
, Qnil
, base_fontset
);
1017 return XINT (FONTSET_ID (fontset
));
1022 /* Cache data used by fontset_pattern_regexp. The car part is a
1023 pattern string containing at least one wild card, the cdr part is
1024 the corresponding regular expression. */
1025 static Lisp_Object Vcached_fontset_data
;
1027 #define CACHED_FONTSET_NAME ((char *) SDATA (XCAR (Vcached_fontset_data)))
1028 #define CACHED_FONTSET_REGEX (XCDR (Vcached_fontset_data))
1030 /* If fontset name PATTERN contains any wild card, return regular
1031 expression corresponding to PATTERN. */
1034 fontset_pattern_regexp (pattern
)
1035 Lisp_Object pattern
;
1037 if (!index ((char *) SDATA (pattern
), '*')
1038 && !index ((char *) SDATA (pattern
), '?'))
1039 /* PATTERN does not contain any wild cards. */
1042 if (!CONSP (Vcached_fontset_data
)
1043 || strcmp ((char *) SDATA (pattern
), CACHED_FONTSET_NAME
))
1045 /* We must at first update the cached data. */
1046 unsigned char *regex
, *p0
, *p1
;
1047 int ndashes
= 0, nstars
= 0, nescs
= 0;
1049 for (p0
= SDATA (pattern
); *p0
; p0
++)
1053 else if (*p0
== '*')
1056 || *p0
== '.' || *p0
== '\\'
1057 || *p0
== '+' || *p0
== '^'
1062 /* If PATTERN is not full XLFD we conert "*" to ".*". Otherwise
1063 we convert "*" to "[^-]*" which is much faster in regular
1064 expression matching. */
1066 p1
= regex
= (unsigned char *) alloca (SBYTES (pattern
) + 2 * nstars
+ 2 * nescs
+ 1);
1068 p1
= regex
= (unsigned char *) alloca (SBYTES (pattern
) + 5 * nstars
+ 2 * nescs
+ 1);
1071 for (p0
= SDATA (pattern
); *p0
; p0
++)
1078 *p1
++ = '[', *p1
++ = '^', *p1
++ = '-', *p1
++ = ']';
1081 else if (*p0
== '?')
1084 || *p0
== '.' || *p0
== '\\'
1085 || *p0
== '+' || *p0
== '^'
1087 *p1
++ = '\\', *p1
++ = *p0
;
1094 Vcached_fontset_data
= Fcons (build_string ((char *) SDATA (pattern
)),
1095 build_string ((char *) regex
));
1098 return CACHED_FONTSET_REGEX
;
1101 /* Return ID of the base fontset named NAME. If there's no such
1102 fontset, return -1. NAME_PATTERN specifies how to treat NAME as this:
1103 0: pattern containing '*' and '?' as wildcards
1104 1: regular expression
1105 2: literal fontset name
1109 fs_query_fontset (name
, name_pattern
)
1116 name
= Fdowncase (name
);
1117 if (name_pattern
!= 1)
1119 tem
= Frassoc (name
, Vfontset_alias_alist
);
1121 tem
= Fassoc (name
, Vfontset_alias_alist
);
1122 if (CONSP (tem
) && STRINGP (XCAR (tem
)))
1124 else if (name_pattern
== 0)
1126 tem
= fontset_pattern_regexp (name
);
1135 for (i
= 0; i
< ASIZE (Vfontset_table
); i
++)
1137 Lisp_Object fontset
, this_name
;
1139 fontset
= FONTSET_FROM_ID (i
);
1141 || !BASE_FONTSET_P (fontset
))
1144 this_name
= FONTSET_NAME (fontset
);
1145 if (name_pattern
== 1
1146 ? fast_string_match_ignore_case (name
, this_name
) >= 0
1147 : !xstrcasecmp (SDATA (name
), SDATA (this_name
)))
1154 DEFUN ("query-fontset", Fquery_fontset
, Squery_fontset
, 1, 2, 0,
1155 doc
: /* Return the name of a fontset that matches PATTERN.
1156 The value is nil if there is no matching fontset.
1157 PATTERN can contain `*' or `?' as a wildcard
1158 just as X font name matching algorithm allows.
1159 If REGEXPP is non-nil, PATTERN is a regular expression. */)
1161 Lisp_Object pattern
, regexpp
;
1163 Lisp_Object fontset
;
1166 (*check_window_system_func
) ();
1168 CHECK_STRING (pattern
);
1170 if (SCHARS (pattern
) == 0)
1173 id
= fs_query_fontset (pattern
, !NILP (regexpp
));
1177 fontset
= FONTSET_FROM_ID (id
);
1178 return FONTSET_NAME (fontset
);
1181 /* Return a list of base fontset names matching PATTERN on frame F. */
1184 list_fontsets (f
, pattern
, size
)
1186 Lisp_Object pattern
;
1189 Lisp_Object frame
, regexp
, val
;
1192 XSETFRAME (frame
, f
);
1194 regexp
= fontset_pattern_regexp (pattern
);
1197 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
1199 Lisp_Object fontset
, name
;
1201 fontset
= FONTSET_FROM_ID (id
);
1203 || !BASE_FONTSET_P (fontset
)
1204 || !EQ (frame
, FONTSET_FRAME (fontset
)))
1206 name
= FONTSET_NAME (fontset
);
1208 if (STRINGP (regexp
)
1209 ? (fast_string_match (regexp
, name
) < 0)
1210 : strcmp ((char *) SDATA (pattern
), (char *) SDATA (name
)))
1213 val
= Fcons (Fcopy_sequence (FONTSET_NAME (fontset
)), val
);
1220 /* Free all realized fontsets whose base fontset is BASE. */
1223 free_realized_fontsets (base
)
1229 /* For the moment, this doesn't work because free_realized_face
1230 doesn't remove FACE from a cache. Until we find a solution, we
1231 suppress this code, and simply use Fclear_face_cache even though
1232 that is not efficient. */
1234 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
1236 Lisp_Object
this = AREF (Vfontset_table
, id
);
1238 if (EQ (FONTSET_BASE (this), base
))
1242 for (tail
= FONTSET_FACE_ALIST (this); CONSP (tail
);
1245 FRAME_PTR f
= XFRAME (FONTSET_FRAME (this));
1246 int face_id
= XINT (XCDR (XCAR (tail
)));
1247 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1249 /* Face THIS itself is also freed by the following call. */
1250 free_realized_face (f
, face
);
1256 /* But, we don't have to call Fclear_face_cache if no fontset has
1257 been realized from BASE. */
1258 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
1260 Lisp_Object
this = AREF (Vfontset_table
, id
);
1262 if (CHAR_TABLE_P (this) && EQ (FONTSET_BASE (this), base
))
1264 Fclear_face_cache (Qt
);
1272 /* Check validity of NAME as a fontset name and return the
1273 corresponding fontset. If not valid, signal an error.
1274 If NAME is t, return Vdefault_fontset. */
1277 check_fontset_name (name
)
1283 return Vdefault_fontset
;
1285 CHECK_STRING (name
);
1286 /* First try NAME as literal. */
1287 id
= fs_query_fontset (name
, 2);
1289 /* For backward compatibility, try again NAME as pattern. */
1290 id
= fs_query_fontset (name
, 0);
1292 error ("Fontset `%s' does not exist", SDATA (name
));
1293 return FONTSET_FROM_ID (id
);
1297 accumulate_script_ranges (arg
, range
, val
)
1298 Lisp_Object arg
, range
, val
;
1300 if (EQ (XCAR (arg
), val
))
1303 XSETCDR (arg
, Fcons (Fcons (XCAR (range
), XCDR (range
)), XCDR (arg
)));
1305 XSETCDR (arg
, Fcons (Fcons (range
, range
), XCDR (arg
)));
1310 /* Return an ASCII font name generated from fontset name NAME and
1311 font-spec ASCII_SPEC. NAME is a string conforming to XLFD. */
1313 static INLINE Lisp_Object
1314 generate_ascii_font_name (name
, ascii_spec
)
1315 Lisp_Object name
, ascii_spec
;
1317 Lisp_Object font_spec
= Ffont_spec (0, NULL
);
1321 if (font_parse_xlfd ((char *) SDATA (name
), font_spec
) < 0)
1322 error ("Not an XLFD font name: %s", SDATA (name
));
1323 for (i
= FONT_FOUNDRY_INDEX
; i
< FONT_EXTRA_INDEX
; i
++)
1324 if (! NILP (AREF (ascii_spec
, i
)))
1325 ASET (font_spec
, i
, AREF (ascii_spec
, i
));
1326 i
= font_unparse_xlfd (font_spec
, 0, xlfd
, 256);
1328 error ("Not an XLFD font name: %s", SDATA (name
));
1329 return make_unibyte_string (xlfd
, i
);
1332 /* Variables referred in set_fontset_font. They are set before
1333 map_charset_chars is called in Fset_fontset_font. */
1334 static Lisp_Object font_def_arg
, add_arg
;
1335 static int from_arg
, to_arg
;
1337 /* Callback function for map_charset_chars in Fset_fontset_font. In
1338 FONTSET, set font_def_arg in a fashion specified by add_arg for
1339 characters in RANGE while ignoring the range between from_arg and
1343 set_fontset_font (fontset
, range
)
1344 Lisp_Object fontset
, range
;
1346 if (from_arg
< to_arg
)
1348 int from
= XINT (XCAR (range
)), to
= XINT (XCDR (range
));
1350 if (from
< from_arg
)
1356 range2
= Fcons (make_number (to_arg
), XCDR (range
));
1357 FONTSET_ADD (fontset
, range
, font_def_arg
, add_arg
);
1361 range
= Fcons (XCAR (range
), make_number (from_arg
));
1363 else if (to
<= to_arg
)
1368 range
= Fcons (make_number (to_arg
), XCDR (range
));
1371 FONTSET_ADD (fontset
, range
, font_def_arg
, add_arg
);
1374 extern Lisp_Object QCfamily
, QCregistry
;
1376 DEFUN ("set-fontset-font", Fset_fontset_font
, Sset_fontset_font
, 3, 5, 0,
1378 Modify fontset NAME to use FONT-SPEC for TARGET characters.
1380 TARGET may be a cons; (FROM . TO), where FROM and TO are characters.
1381 In that case, use FONT-SPEC for all characters in the range FROM and
1384 TARGET may be a script name symbol. In that case, use FONT-SPEC for
1385 all characters that belong to the script.
1387 TARGET may be a charset. In that case, use FONT-SPEC for all
1388 characters in the charset.
1390 TARGET may be nil. In that case, use FONT-SPEC for any characters for
1391 that no FONT-SPEC is specified.
1393 FONT-SPEC may one of these:
1394 * A font-spec object made by the function `font-spec' (which see).
1395 * A cons (FAMILY . REGISTRY), where FAMILY is a font family name and
1396 REGISTRY is a font registry name. FAMILY may contain foundry
1397 name, and REGISTRY may contain encoding name.
1398 * A font name string.
1399 * nil, which explicitly specifies that there's no font for TARGET.
1401 Optional 4th argument FRAME, if non-nil, is a frame. This argument is
1402 kept for backward compatibility and has no meaning.
1404 Optional 5th argument ADD, if non-nil, specifies how to add FONT-SPEC
1405 to the font specifications for TARGET previously set. If it is
1406 `prepend', FONT-SPEC is prepended. If it is `append', FONT-SPEC is
1407 appended. By default, FONT-SPEC overrides the previous settings. */)
1408 (name
, target
, font_spec
, frame
, add
)
1409 Lisp_Object name
, target
, font_spec
, frame
, add
;
1411 Lisp_Object fontset
;
1412 Lisp_Object font_def
, registry
, family
;
1413 Lisp_Object range_list
;
1414 struct charset
*charset
= NULL
;
1416 fontset
= check_fontset_name (name
);
1418 /* The arg FRAME is kept for backward compatibility. We only check
1421 CHECK_LIVE_FRAME (frame
);
1423 if (CONSP (font_spec
))
1425 Lisp_Object spec
= Ffont_spec (0, NULL
);
1427 font_parse_family_registry (XCAR (font_spec
), XCDR (font_spec
), spec
);
1430 else if (STRINGP (font_spec
))
1432 Lisp_Object args
[2];
1433 extern Lisp_Object QCname
;
1436 args
[1] = font_spec
;
1437 font_spec
= Ffont_spec (2, args
);
1439 else if (! NILP (font_spec
) && ! FONT_SPEC_P (font_spec
))
1440 Fsignal (Qfont
, list2 (build_string ("Invalid font-spec"), font_spec
));
1442 if (! NILP (font_spec
))
1444 Lisp_Object encoding
, repertory
;
1446 family
= AREF (font_spec
, FONT_FAMILY_INDEX
);
1447 if (! NILP (family
) )
1448 family
= SYMBOL_NAME (family
);
1449 registry
= AREF (font_spec
, FONT_REGISTRY_INDEX
);
1450 if (! NILP (registry
))
1451 registry
= Fdowncase (SYMBOL_NAME (registry
));
1452 encoding
= find_font_encoding (concat3 (family
, build_string ("-"),
1454 if (NILP (encoding
))
1457 if (SYMBOLP (encoding
))
1459 CHECK_CHARSET (encoding
);
1460 encoding
= repertory
= CHARSET_SYMBOL_ID (encoding
);
1464 repertory
= XCDR (encoding
);
1465 encoding
= XCAR (encoding
);
1466 CHECK_CHARSET (encoding
);
1467 encoding
= CHARSET_SYMBOL_ID (encoding
);
1468 if (! NILP (repertory
) && SYMBOLP (repertory
))
1470 CHECK_CHARSET (repertory
);
1471 repertory
= CHARSET_SYMBOL_ID (repertory
);
1474 FONT_DEF_NEW (font_def
, font_spec
, encoding
, repertory
);
1479 if (CHARACTERP (target
))
1480 range_list
= Fcons (Fcons (target
, target
), Qnil
);
1481 else if (CONSP (target
))
1483 Lisp_Object from
, to
;
1485 from
= Fcar (target
);
1487 CHECK_CHARACTER (from
);
1488 CHECK_CHARACTER (to
);
1489 range_list
= Fcons (target
, Qnil
);
1491 else if (SYMBOLP (target
) && !NILP (target
))
1493 Lisp_Object script_list
;
1497 script_list
= XCHAR_TABLE (Vchar_script_table
)->extras
[0];
1498 if (! NILP (Fmemq (target
, script_list
)))
1500 val
= Fcons (target
, Qnil
);
1501 map_char_table (accumulate_script_ranges
, Qnil
, Vchar_script_table
,
1503 range_list
= XCDR (val
);
1504 if (EQ (target
, Qlatin
) && NILP (FONTSET_ASCII (fontset
)))
1506 if (VECTORP (font_spec
))
1507 val
= generate_ascii_font_name (FONTSET_NAME (fontset
),
1511 FONTSET_ASCII (fontset
) = val
;
1514 if (CHARSETP (target
))
1516 if (EQ (target
, Qascii
) && NILP (FONTSET_ASCII (fontset
)))
1518 if (VECTORP (font_spec
))
1519 font_spec
= generate_ascii_font_name (FONTSET_NAME (fontset
),
1521 FONTSET_ASCII (fontset
) = font_spec
;
1522 range_list
= Fcons (Fcons (make_number (0), make_number (127)),
1527 CHECK_CHARSET_GET_CHARSET (target
, charset
);
1530 else if (NILP (range_list
))
1531 error ("Invalid script or charset name: %s",
1532 SDATA (SYMBOL_NAME (target
)));
1534 else if (NILP (target
))
1535 range_list
= Fcons (Qnil
, Qnil
);
1537 error ("Invalid target for setting a font");
1542 font_def_arg
= font_def
;
1544 if (NILP (range_list
))
1545 from_arg
= to_arg
= 0;
1547 from_arg
= XINT (XCAR (XCAR (range_list
))),
1548 to_arg
= XINT (XCDR (XCAR (range_list
)));
1550 map_charset_chars (set_fontset_font
, Qnil
, fontset
, charset
,
1551 CHARSET_MIN_CODE (charset
),
1552 CHARSET_MAX_CODE (charset
));
1554 for (; CONSP (range_list
); range_list
= XCDR (range_list
))
1555 FONTSET_ADD (fontset
, XCAR (range_list
), font_def
, add
);
1557 /* Free all realized fontsets whose base is FONTSET. This way, the
1558 specified character(s) are surely redisplayed by a correct
1560 free_realized_fontsets (fontset
);
1566 DEFUN ("new-fontset", Fnew_fontset
, Snew_fontset
, 2, 2, 0,
1567 doc
: /* Create a new fontset NAME from font information in FONTLIST.
1569 FONTLIST is an alist of scripts vs the corresponding font specification list.
1570 Each element of FONTLIST has the form (SCRIPT FONT-SPEC ...), where a
1571 character of SCRIPT is displayed by a font that matches one of
1574 SCRIPT is a symbol that appears in the first extra slot of the
1575 char-table `char-script-table'.
1577 FONT-SPEC is a vector, a cons, or a string. See the documentation of
1578 `set-fontset-font' for the meaning. */)
1580 Lisp_Object name
, fontlist
;
1582 Lisp_Object fontset
;
1585 CHECK_STRING (name
);
1586 CHECK_LIST (fontlist
);
1588 name
= Fdowncase (name
);
1589 id
= fs_query_fontset (name
, 0);
1592 Lisp_Object font_spec
= Ffont_spec (0, NULL
);
1593 Lisp_Object short_name
;
1597 if (font_parse_xlfd ((char *) SDATA (name
), font_spec
) < 0)
1598 error ("Fontset name must be in XLFD format");
1599 short_name
= AREF (font_spec
, FONT_REGISTRY_INDEX
);
1600 if (strncmp ((char *) SDATA (SYMBOL_NAME (short_name
)), "fontset-", 8)
1601 || SBYTES (SYMBOL_NAME (short_name
)) < 9)
1602 error ("Registry field of fontset name must be \"fontset-*\"");
1603 Vfontset_alias_alist
= Fcons (Fcons (name
, SYMBOL_NAME (short_name
)),
1604 Vfontset_alias_alist
);
1605 ASET (font_spec
, FONT_REGISTRY_INDEX
, Qiso8859_1
);
1606 fontset
= make_fontset (Qnil
, name
, Qnil
);
1607 len
= font_unparse_xlfd (font_spec
, 0, xlfd
, 256);
1609 error ("Invalid fontset name (perhaps too long): %s", SDATA (name
));
1610 FONTSET_ASCII (fontset
) = make_unibyte_string (xlfd
, len
);
1614 fontset
= FONTSET_FROM_ID (id
);;
1615 free_realized_fontsets (fontset
);
1616 Fset_char_table_range (fontset
, Qt
, Qnil
);
1619 for (; ! NILP (fontlist
); fontlist
= Fcdr (fontlist
))
1621 Lisp_Object elt
, script
;
1623 elt
= Fcar (fontlist
);
1624 script
= Fcar (elt
);
1626 if (CONSP (elt
) && (NILP (XCDR (elt
)) || CONSP (XCDR (elt
))))
1627 for (; CONSP (elt
); elt
= XCDR (elt
))
1628 Fset_fontset_font (name
, script
, XCAR (elt
), Qnil
, Qappend
);
1630 Fset_fontset_font (name
, script
, elt
, Qnil
, Qappend
);
1636 /* Alist of automatically created fontsets. Each element is a cons
1637 (FONT-SPEC . FONTSET-ID). */
1638 static Lisp_Object auto_fontset_alist
;
1641 fontset_from_font (font_object
)
1642 Lisp_Object font_object
;
1644 Lisp_Object font_name
= font_get_name (font_object
);
1645 Lisp_Object font_spec
= Fcopy_font_spec (font_object
);
1646 Lisp_Object fontset_spec
, alias
, name
, fontset
;
1650 val
= assoc_no_quit (font_spec
, auto_fontset_alist
);
1652 return XINT (FONTSET_ID (XCDR (val
)));
1653 if (NILP (auto_fontset_alist
))
1654 alias
= intern ("fontset-startup");
1658 int len
= XINT (Flength (auto_fontset_alist
));
1660 sprintf (temp
, "fontset-auto%d", len
);
1661 alias
= intern (temp
);
1663 fontset_spec
= Fcopy_font_spec (font_spec
);
1664 ASET (fontset_spec
, FONT_REGISTRY_INDEX
, alias
);
1665 name
= Ffont_xlfd_name (fontset_spec
, Qnil
);
1668 fontset
= make_fontset (Qnil
, name
, Qnil
);
1669 Vfontset_alias_alist
= Fcons (Fcons (name
, SYMBOL_NAME (alias
)),
1670 Vfontset_alias_alist
);
1671 alias
= Fdowncase (AREF (font_object
, FONT_NAME_INDEX
));
1672 Vfontset_alias_alist
= Fcons (Fcons (name
, alias
), Vfontset_alias_alist
);
1673 auto_fontset_alist
= Fcons (Fcons (font_spec
, fontset
), auto_fontset_alist
);
1674 FONTSET_ASCII (fontset
) = font_name
;
1675 font_spec
= Fcopy_font_spec (font_spec
);
1676 ASET (font_spec
, FONT_REGISTRY_INDEX
, Qiso10646_1
);
1677 for (i
= FONT_WEIGHT_INDEX
; i
< FONT_EXTRA_INDEX
; i
++)
1678 ASET (font_spec
, i
, Qnil
);
1679 Fset_fontset_font (name
, Qlatin
, font_spec
, Qnil
, Qnil
);
1680 Fset_fontset_font (name
, Qnil
, font_spec
, Qnil
, Qnil
);
1683 nsfont_make_fontset_for_font(name
, font_object
);
1686 return XINT (FONTSET_ID (fontset
));
1689 /* Return a cons (FONT-OBJECT . GLYPH-CODE).
1690 FONT-OBJECT is the font for the character at POSITION in the current
1691 buffer. This is computed from all the text properties and overlays
1692 that apply to POSITION. POSTION may be nil, in which case,
1693 FONT-SPEC is the font for displaying the character CH with the
1696 GLYPH-CODE is the glyph code in the font to use for the character.
1698 If the 2nd optional arg CH is non-nil, it is a character to check
1699 the font instead of the character at POSITION.
1701 It returns nil in the following cases:
1703 (1) The window system doesn't have a font for the character (thus
1704 it is displayed by an empty box).
1706 (2) The character code is invalid.
1708 (3) If POSITION is not nil, and the current buffer is not displayed
1711 In addition, the returned font name may not take into account of
1712 such redisplay engine hooks as what used in jit-lock-mode if
1713 POSITION is currently not visible. */
1716 DEFUN ("internal-char-font", Finternal_char_font
, Sinternal_char_font
, 1, 2, 0,
1717 doc
: /* For internal use only. */)
1719 Lisp_Object position
, ch
;
1721 EMACS_INT pos
, pos_byte
, dummy
;
1728 if (NILP (position
))
1730 CHECK_CHARACTER (ch
);
1732 f
= XFRAME (selected_frame
);
1733 face_id
= lookup_basic_face (f
, DEFAULT_FACE_ID
);
1739 Lisp_Object window
, charset
;
1742 CHECK_NUMBER_COERCE_MARKER (position
);
1743 pos
= XINT (position
);
1744 if (pos
< BEGV
|| pos
>= ZV
)
1745 args_out_of_range_3 (position
, make_number (BEGV
), make_number (ZV
));
1746 pos_byte
= CHAR_TO_BYTE (pos
);
1748 c
= FETCH_CHAR (pos_byte
);
1754 window
= Fget_buffer_window (Fcurrent_buffer (), Qnil
);
1757 w
= XWINDOW (window
);
1758 f
= XFRAME (w
->frame
);
1759 face_id
= face_at_buffer_position (w
, pos
, -1, -1, &dummy
, pos
+ 100, 0);
1760 charset
= Fget_char_property (position
, Qcharset
, Qnil
);
1761 if (CHARSETP (charset
))
1762 cs_id
= XINT (CHARSET_SYMBOL_ID (charset
));
1766 if (! CHAR_VALID_P (c
, 0))
1768 face_id
= FACE_FOR_CHAR (f
, FACE_FROM_ID (f
, face_id
), c
, pos
, Qnil
);
1769 face
= FACE_FROM_ID (f
, face_id
);
1772 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
1773 Lisp_Object font_object
;
1774 /* Assignment to EMACS_INT stops GCC whining about limited range
1776 EMACS_INT cod
= code
;
1778 if (code
== FONT_INVALID_CODE
)
1780 XSETFONT (font_object
, face
->font
);
1781 if (cod
<= MOST_POSITIVE_FIXNUM
)
1782 return Fcons (font_object
, make_number (code
));
1783 return Fcons (font_object
, Fcons (make_number (code
>> 16),
1784 make_number (code
& 0xFFFF)));
1790 DEFUN ("fontset-info", Ffontset_info
, Sfontset_info
, 1, 2, 0,
1791 doc
: /* Return information about a fontset FONTSET on frame FRAME.
1792 The value is a char-table whose elements have this form:
1794 ((FONT-PATTERN OPENED-FONT ...) ...)
1796 FONT-PATTERN is a vector:
1798 [ FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY ]
1800 or a string of font name pattern.
1802 OPENED-FONT is a name of a font actually opened.
1804 The char-table has one extra slot. The value is a char-table
1805 containing the information about the derived fonts from the default
1806 fontset. The format is the same as above. */)
1808 Lisp_Object fontset
, frame
;
1811 Lisp_Object
*realized
[2], fontsets
[2], tables
[2];
1812 Lisp_Object val
, elt
;
1815 (*check_window_system_func
) ();
1817 fontset
= check_fontset_name (fontset
);
1820 frame
= selected_frame
;
1821 CHECK_LIVE_FRAME (frame
);
1824 /* Recode fontsets realized on FRAME from the base fontset FONTSET
1825 in the table `realized'. */
1826 realized
[0] = (Lisp_Object
*) alloca (sizeof (Lisp_Object
)
1827 * ASIZE (Vfontset_table
));
1828 for (i
= j
= 0; i
< ASIZE (Vfontset_table
); i
++)
1830 elt
= FONTSET_FROM_ID (i
);
1832 && EQ (FONTSET_BASE (elt
), fontset
)
1833 && EQ (FONTSET_FRAME (elt
), frame
))
1834 realized
[0][j
++] = elt
;
1836 realized
[0][j
] = Qnil
;
1838 realized
[1] = (Lisp_Object
*) alloca (sizeof (Lisp_Object
)
1839 * ASIZE (Vfontset_table
));
1840 for (i
= j
= 0; ! NILP (realized
[0][i
]); i
++)
1842 elt
= FONTSET_DEFAULT (realized
[0][i
]);
1844 realized
[1][j
++] = elt
;
1846 realized
[1][j
] = Qnil
;
1848 tables
[0] = Fmake_char_table (Qfontset_info
, Qnil
);
1849 tables
[1] = Fmake_char_table (Qnil
, Qnil
);
1850 XCHAR_TABLE (tables
[0])->extras
[0] = tables
[1];
1851 fontsets
[0] = fontset
;
1852 fontsets
[1] = Vdefault_fontset
;
1854 /* Accumulate information of the fontset in TABLE. The format of
1855 each element is ((FONT-SPEC OPENED-FONT ...) ...). */
1856 for (k
= 0; k
<= 1; k
++)
1858 for (c
= 0; c
<= MAX_CHAR
; )
1862 if (c
<= MAX_5_BYTE_CHAR
)
1864 val
= char_table_ref_and_range (fontsets
[k
], c
, &from
, &to
);
1865 if (to
> MAX_5_BYTE_CHAR
)
1866 to
= MAX_5_BYTE_CHAR
;
1870 val
= FONTSET_FALLBACK (fontsets
[k
]);
1877 /* At first, set ALIST to ((FONT-SPEC) ...). */
1878 for (alist
= Qnil
, i
= 0; i
< ASIZE (val
); i
++)
1879 if (! NILP (AREF (val
, i
)))
1880 alist
= Fcons (Fcons (FONT_DEF_SPEC (AREF (val
, i
)), Qnil
),
1882 alist
= Fnreverse (alist
);
1884 /* Then store opened font names to cdr of each elements. */
1885 for (i
= 0; ! NILP (realized
[k
][i
]); i
++)
1887 if (c
<= MAX_5_BYTE_CHAR
)
1888 val
= FONTSET_REF (realized
[k
][i
], c
);
1890 val
= FONTSET_FALLBACK (realized
[k
][i
]);
1891 if (! VECTORP (val
))
1893 /* VAL: [int ? [FACE-ID FONT-DEF FONT-OBJECT int] ... ] */
1894 for (j
= 2; j
< ASIZE (val
); j
++)
1896 elt
= AREF (val
, j
);
1897 if (FONT_OBJECT_P (RFONT_DEF_OBJECT (elt
)))
1899 Lisp_Object font_object
= RFONT_DEF_OBJECT (elt
);
1900 Lisp_Object slot
, name
;
1902 slot
= Fassq (RFONT_DEF_SPEC (elt
), alist
);
1903 name
= AREF (font_object
, FONT_NAME_INDEX
);
1904 if (NILP (Fmember (name
, XCDR (slot
))))
1905 nconc2 (slot
, Fcons (name
, Qnil
));
1910 /* Store ALIST in TBL for characters C..TO. */
1911 if (c
<= MAX_5_BYTE_CHAR
)
1912 char_table_set_range (tables
[k
], c
, to
, alist
);
1914 XCHAR_TABLE (tables
[k
])->defalt
= alist
;
1916 /* At last, change each elements to font names. */
1917 for (; CONSP (alist
); alist
= XCDR (alist
))
1920 XSETCAR (elt
, Ffont_xlfd_name (XCAR (elt
), Qnil
));
1931 DEFUN ("fontset-font", Ffontset_font
, Sfontset_font
, 2, 3, 0,
1932 doc
: /* Return a font name pattern for character CH in fontset NAME.
1933 If NAME is t, find a pattern in the default fontset.
1935 The value has the form (FAMILY . REGISTRY), where FAMILY is a font
1936 family name and REGISTRY is a font registry name. This is actually
1937 the first font name pattern for CH in the fontset or in the default
1940 If the 2nd optional arg ALL is non-nil, return a list of all font name
1943 Lisp_Object name
, ch
, all
;
1946 Lisp_Object fontset
, elt
, list
, repertory
, val
;
1949 fontset
= check_fontset_name (name
);
1951 CHECK_CHARACTER (ch
);
1956 for (i
= 0, elt
= FONTSET_REF (fontset
, c
); i
< 2;
1957 i
++, elt
= FONTSET_FALLBACK (fontset
))
1959 for (j
= 0; j
< ASIZE (elt
); j
++)
1961 val
= AREF (elt
, j
);
1962 repertory
= AREF (val
, 1);
1963 if (INTEGERP (repertory
))
1965 struct charset
*charset
= CHARSET_FROM_ID (XINT (repertory
));
1967 if (! CHAR_CHARSET_P (c
, charset
))
1970 else if (CHAR_TABLE_P (repertory
))
1972 if (NILP (CHAR_TABLE_REF (repertory
, c
)))
1975 val
= AREF (val
, 0);
1976 val
= Fcons (AREF (val
, 0), AREF (val
, 5));
1979 list
= Fcons (val
, list
);
1981 if (EQ (fontset
, Vdefault_fontset
))
1983 fontset
= Vdefault_fontset
;
1985 return (Fnreverse (list
));
1988 DEFUN ("fontset-list", Ffontset_list
, Sfontset_list
, 0, 0, 0,
1989 doc
: /* Return a list of all defined fontset names. */)
1992 Lisp_Object fontset
, list
;
1996 for (i
= 0; i
< ASIZE (Vfontset_table
); i
++)
1998 fontset
= FONTSET_FROM_ID (i
);
2000 && BASE_FONTSET_P (fontset
))
2001 list
= Fcons (FONTSET_NAME (fontset
), list
);
2008 #ifdef FONTSET_DEBUG
2011 dump_fontset (fontset
)
2012 Lisp_Object fontset
;
2016 vec
= Fmake_vector (make_number (3), Qnil
);
2017 ASET (vec
, 0, FONTSET_ID (fontset
));
2019 if (BASE_FONTSET_P (fontset
))
2021 ASET (vec
, 1, FONTSET_NAME (fontset
));
2027 frame
= FONTSET_FRAME (fontset
);
2030 FRAME_PTR f
= XFRAME (frame
);
2032 if (FRAME_LIVE_P (f
))
2034 Fcons (FONTSET_NAME (FONTSET_BASE (fontset
)), f
->name
));
2037 Fcons (FONTSET_NAME (FONTSET_BASE (fontset
)), Qnil
));
2039 if (!NILP (FONTSET_DEFAULT (fontset
)))
2040 ASET (vec
, 2, FONTSET_ID (FONTSET_DEFAULT (fontset
)));
2045 DEFUN ("fontset-list-all", Ffontset_list_all
, Sfontset_list_all
, 0, 0, 0,
2046 doc
: /* Return a brief summary of all fontsets for debug use. */)
2052 for (i
= 0, val
= Qnil
; i
< ASIZE (Vfontset_table
); i
++)
2053 if (! NILP (AREF (Vfontset_table
, i
)))
2054 val
= Fcons (dump_fontset (AREF (Vfontset_table
, i
)), val
);
2055 return (Fnreverse (val
));
2057 #endif /* FONTSET_DEBUG */
2062 DEFSYM (Qfontset
, "fontset");
2063 Fput (Qfontset
, Qchar_table_extra_slots
, make_number (9));
2064 DEFSYM (Qfontset_info
, "fontset-info");
2065 Fput (Qfontset_info
, Qchar_table_extra_slots
, make_number (1));
2067 DEFSYM (Qprepend
, "prepend");
2068 DEFSYM (Qappend
, "append");
2069 DEFSYM (Qlatin
, "latin");
2071 Vcached_fontset_data
= Qnil
;
2072 staticpro (&Vcached_fontset_data
);
2074 Vfontset_table
= Fmake_vector (make_number (32), Qnil
);
2075 staticpro (&Vfontset_table
);
2077 Vdefault_fontset
= Fmake_char_table (Qfontset
, Qnil
);
2078 staticpro (&Vdefault_fontset
);
2079 FONTSET_ID (Vdefault_fontset
) = make_number (0);
2080 FONTSET_NAME (Vdefault_fontset
)
2081 = build_string ("-*-*-*-*-*-*-*-*-*-*-*-*-fontset-default");
2082 ASET (Vfontset_table
, 0, Vdefault_fontset
);
2083 next_fontset_id
= 1;
2085 auto_fontset_alist
= Qnil
;
2086 staticpro (&auto_fontset_alist
);
2088 DEFVAR_LISP ("font-encoding-charset-alist", &Vfont_encoding_charset_alist
,
2090 Alist of charsets vs the charsets to determine the preferred font encoding.
2091 Each element looks like (CHARSET . ENCODING-CHARSET),
2092 where ENCODING-CHARSET is a charset registered in the variable
2093 `font-encoding-alist' as ENCODING.
2095 When a text has a property `charset' and the value is CHARSET, a font
2096 whose encoding corresponds to ENCODING-CHARSET is preferred. */);
2097 Vfont_encoding_charset_alist
= Qnil
;
2099 DEFVAR_LISP ("use-default-ascent", &Vuse_default_ascent
,
2101 Char table of characters whose ascent values should be ignored.
2102 If an entry for a character is non-nil, the ascent value of the glyph
2103 is assumed to be specified by _MULE_DEFAULT_ASCENT property of a font.
2105 This affects how a composite character which contains
2106 such a character is displayed on screen. */);
2107 Vuse_default_ascent
= Qnil
;
2109 DEFVAR_LISP ("ignore-relative-composition", &Vignore_relative_composition
,
2111 Char table of characters which are not composed relatively.
2112 If an entry for a character is non-nil, a composition sequence
2113 which contains that character is displayed so that
2114 the glyph of that character is put without considering
2115 an ascent and descent value of a previous character. */);
2116 Vignore_relative_composition
= Qnil
;
2118 DEFVAR_LISP ("alternate-fontname-alist", &Valternate_fontname_alist
,
2119 doc
: /* Alist of fontname vs list of the alternate fontnames.
2120 When a specified font name is not found, the corresponding
2121 alternate fontnames (if any) are tried instead. */);
2122 Valternate_fontname_alist
= Qnil
;
2124 DEFVAR_LISP ("fontset-alias-alist", &Vfontset_alias_alist
,
2125 doc
: /* Alist of fontset names vs the aliases. */);
2126 Vfontset_alias_alist
= Fcons (Fcons (FONTSET_NAME (Vdefault_fontset
),
2127 build_string ("fontset-default")),
2130 DEFVAR_LISP ("vertical-centering-font-regexp",
2131 &Vvertical_centering_font_regexp
,
2132 doc
: /* *Regexp matching font names that require vertical centering on display.
2133 When a character is displayed with such fonts, the character is displayed
2134 at the vertical center of lines. */);
2135 Vvertical_centering_font_regexp
= Qnil
;
2137 DEFVAR_LISP ("otf-script-alist", &Votf_script_alist
,
2138 doc
: /* Alist of OpenType script tags vs the corresponding script names. */);
2139 Votf_script_alist
= Qnil
;
2141 defsubr (&Squery_fontset
);
2142 defsubr (&Snew_fontset
);
2143 defsubr (&Sset_fontset_font
);
2144 defsubr (&Sinternal_char_font
);
2145 defsubr (&Sfontset_info
);
2146 defsubr (&Sfontset_font
);
2147 defsubr (&Sfontset_list
);
2148 #ifdef FONTSET_DEBUG
2149 defsubr (&Sfontset_list_all
);
2153 /* arch-tag: ea861585-2f5f-4e5b-9849-d04a9c3a3537
2154 (do not change this comment) */