2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
3 Free Software Foundation, Inc.
4 Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
6 National Institute of Advanced Industrial Science and Technology (AIST)
7 Registration Number H14PRO021
8 Copyright (C) 2003, 2006
9 National Institute of Advanced Industrial Science and Technology (AIST)
10 Registration Number H13PRO009
12 This file is part of GNU Emacs.
14 GNU Emacs is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3, or (at your option)
19 GNU Emacs is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with GNU Emacs; see the file COPYING. If not, write to
26 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 Boston, MA 02110-1301, USA. */
29 /* #define FONTSET_DEBUG */
38 #include "blockinput.h"
40 #include "character.h"
45 #include "dispextern.h"
46 #include "intervals.h"
58 #include "termhooks.h"
64 #define xassert(X) do {if (!(X)) abort ();} while (0)
67 #else /* not FONTSET_DEBUG */
68 #define xassert(X) (void) 0
69 #endif /* not FONTSET_DEBUG */
71 EXFUN (Fclear_face_cache
, 1);
75 A fontset is a collection of font related information to give
76 similar appearance (style, etc) of characters. A fontset has two
77 roles. One is to use for the frame parameter `font' as if it is an
78 ASCII font. In that case, Emacs uses the font specified for
79 `ascii' script for the frame's default font.
81 Another role, the more important one, is to provide information
82 about which font to use for each non-ASCII character.
84 There are two kinds of fontsets; base and realized. A base fontset
85 is created by `new-fontset' from Emacs Lisp explicitly. A realized
86 fontset is created implicitly when a face is realized for ASCII
87 characters. A face is also realized for non-ASCII characters based
88 on an ASCII face. All of non-ASCII faces based on the same ASCII
89 face share the same realized fontset.
91 A fontset object is implemented by a char-table whose default value
92 and parent are always nil.
94 An element of a base fontset is a vector of FONT-DEFs which itself
95 is a vector [ FONT-SPEC ENCODING REPERTORY ].
97 An element of a realized fontset is nil, t, or a vector of this form:
99 [ CHARSET-ORDERED-LIST-TICK PREFERRED-RFONT-DEF
100 RFONT-DEF0 RFONT-DEF1 ... ]
102 RFONT-DEFn (i.e. Realized FONT-DEF) has this form:
104 [ FACE-ID FONT-DEF FONT-OBJECT SORTING-SCORE ]
106 RFONT-DEFn are automatically reordered by the current charset
109 The value nil means that we have not yet generated the above vector
110 from the base of the fontset.
112 The value t means that no font is available for the corresponding
116 A fontset has 9 extra slots.
118 The 1st slot: the ID number of the fontset
121 base: the name of the fontset
126 realized: the base fontset
130 realized: the frame that the fontset belongs to
133 base: the font name for ASCII characters
138 realized: the ID number of a face to use for characters that
139 has no font in a realized fontset.
143 realized: Alist of font index vs the corresponding repertory
148 realized: If the base is not the default fontset, a fontset
149 realized from the default fontset, else nil.
152 base: Same as element value (but for fallback fonts).
155 All fontsets are recorded in the vector Vfontset_table.
160 There's a special base fontset named `default fontset' which
161 defines the default font specifications. When a base fontset
162 doesn't specify a font for a specific character, the corresponding
163 value in the default fontset is used.
165 The parent of a realized fontset created for such a face that has
166 no fontset is the default fontset.
169 These structures are hidden from the other codes than this file.
170 The other codes handle fontsets only by their ID numbers. They
171 usually use the variable name `fontset' for IDs. But, in this
172 file, we always use varialbe name `id' for IDs, and name `fontset'
173 for an actual fontset object, i.e., char-table.
177 /********** VARIABLES and FUNCTION PROTOTYPES **********/
179 extern Lisp_Object Qfont
;
180 static Lisp_Object Qfontset
;
181 static Lisp_Object Qfontset_info
;
182 static Lisp_Object Qprepend
, Qappend
;
183 static Lisp_Object Qlatin
;
185 /* Vector containing all fontsets. */
186 static Lisp_Object Vfontset_table
;
188 /* Next possibly free fontset ID. Usually this keeps the minimum
189 fontset ID not yet used. */
190 static int next_fontset_id
;
192 /* The default fontset. This gives default FAMILY and REGISTRY of
193 font for each character. */
194 static Lisp_Object Vdefault_fontset
;
196 Lisp_Object Vfont_encoding_alist
;
197 Lisp_Object Vfont_encoding_charset_alist
;
198 Lisp_Object Vuse_default_ascent
;
199 Lisp_Object Vignore_relative_composition
;
200 Lisp_Object Valternate_fontname_alist
;
201 Lisp_Object Vfontset_alias_alist
;
202 Lisp_Object Vvertical_centering_font_regexp
;
203 Lisp_Object Votf_script_alist
;
205 /* Check if any window system is used now. */
206 void (*check_window_system_func
) P_ ((void));
209 /* Prototype declarations for static functions. */
210 static Lisp_Object fontset_add
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
,
212 static Lisp_Object fontset_find_font
P_ ((Lisp_Object
, int, struct face
*,
214 static void reorder_font_vector
P_ ((Lisp_Object
, Lisp_Object
));
215 static Lisp_Object fontset_font
P_ ((Lisp_Object
, int, struct face
*, int));
216 static Lisp_Object make_fontset
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
));
217 static Lisp_Object fontset_pattern_regexp
P_ ((Lisp_Object
));
218 static void accumulate_script_ranges
P_ ((Lisp_Object
, Lisp_Object
,
220 Lisp_Object find_font_encoding
P_ ((Lisp_Object
));
222 static void set_fontset_font
P_ ((Lisp_Object
, Lisp_Object
));
226 /* Return 1 if ID is a valid fontset id, else return 0. */
229 fontset_id_valid_p (id
)
232 return (id
>= 0 && id
< ASIZE (Vfontset_table
) - 1);
239 /********** MACROS AND FUNCTIONS TO HANDLE FONTSET **********/
241 /* Return the fontset with ID. No check of ID's validness. */
242 #define FONTSET_FROM_ID(id) AREF (Vfontset_table, id)
244 /* Macros to access special values of FONTSET. */
245 #define FONTSET_ID(fontset) XCHAR_TABLE (fontset)->extras[0]
247 /* Macros to access special values of (base) FONTSET. */
248 #define FONTSET_NAME(fontset) XCHAR_TABLE (fontset)->extras[1]
249 #define FONTSET_ASCII(fontset) XCHAR_TABLE (fontset)->extras[4]
250 #define FONTSET_SPEC(fontset) XCHAR_TABLE (fontset)->extras[5]
252 /* Macros to access special values of (realized) FONTSET. */
253 #define FONTSET_BASE(fontset) XCHAR_TABLE (fontset)->extras[2]
254 #define FONTSET_FRAME(fontset) XCHAR_TABLE (fontset)->extras[3]
255 #define FONTSET_OBJLIST(fontset) XCHAR_TABLE (fontset)->extras[4]
256 #define FONTSET_NOFONT_FACE(fontset) XCHAR_TABLE (fontset)->extras[5]
257 #define FONTSET_REPERTORY(fontset) XCHAR_TABLE (fontset)->extras[6]
258 #define FONTSET_DEFAULT(fontset) XCHAR_TABLE (fontset)->extras[7]
260 /* For both base and realized fontset. */
261 #define FONTSET_FALLBACK(fontset) XCHAR_TABLE (fontset)->extras[8]
263 #define BASE_FONTSET_P(fontset) (NILP (FONTSET_BASE (fontset)))
266 /* Macros for FONT-DEF and RFONT-DEF of fontset. */
267 #define FONT_DEF_NEW(font_def, font_spec, encoding, repertory) \
269 (font_def) = Fmake_vector (make_number (3), (font_spec)); \
270 ASET ((font_def), 1, encoding); \
271 ASET ((font_def), 2, repertory); \
274 #define FONT_DEF_SPEC(font_def) AREF (font_def, 0)
275 #define FONT_DEF_ENCODING(font_def) AREF (font_def, 1)
276 #define FONT_DEF_REPERTORY(font_def) AREF (font_def, 2)
278 #define RFONT_DEF_FACE(rfont_def) AREF (rfont_def, 0)
279 #define RFONT_DEF_SET_FACE(rfont_def, face_id) \
280 ASET ((rfont_def), 0, make_number (face_id))
281 #define RFONT_DEF_FONT_DEF(rfont_def) AREF (rfont_def, 1)
282 #define RFONT_DEF_SPEC(rfont_def) FONT_DEF_SPEC (AREF (rfont_def, 1))
283 #define RFONT_DEF_REPERTORY(rfont_def) FONT_DEF_REPERTORY (AREF (rfont_def, 1))
284 #define RFONT_DEF_OBJECT(rfont_def) AREF (rfont_def, 2)
285 #define RFONT_DEF_SET_OBJECT(rfont_def, object) \
286 ASET ((rfont_def), 2, (object))
287 #define RFONT_DEF_SCORE(rfont_def) XINT (AREF (rfont_def, 3))
288 #define RFONT_DEF_SET_SCORE(rfont_def, score) \
289 ASET ((rfont_def), 3, make_number (score))
290 #define RFONT_DEF_NEW(rfont_def, font_def) \
292 (rfont_def) = Fmake_vector (make_number (4), Qnil); \
293 ASET ((rfont_def), 1, (font_def)); \
294 RFONT_DEF_SET_SCORE ((rfont_def), 0); \
298 /* Return the element of FONTSET for the character C. If FONTSET is a
299 base fontset other then the default fontset and FONTSET doesn't
300 contain information for C, return the information in the default
303 #define FONTSET_REF(fontset, c) \
304 (EQ (fontset, Vdefault_fontset) \
305 ? CHAR_TABLE_REF (fontset, c) \
306 : fontset_ref ((fontset), (c)))
309 fontset_ref (fontset
, c
)
315 elt
= CHAR_TABLE_REF (fontset
, c
);
316 if (NILP (elt
) && ! EQ (fontset
, Vdefault_fontset
)
317 /* Don't check Vdefault_fontset for a realized fontset. */
318 && NILP (FONTSET_BASE (fontset
)))
319 elt
= CHAR_TABLE_REF (Vdefault_fontset
, c
);
323 /* Set elements of FONTSET for characters in RANGE to the value ELT.
324 RANGE is a cons (FROM . TO), where FROM and TO are character codes
325 specifying a range. */
327 #define FONTSET_SET(fontset, range, elt) \
328 Fset_char_table_range ((fontset), (range), (elt))
331 /* Modify the elements of FONTSET for characters in RANGE by replacing
332 with ELT or adding ELT. RANGE is a cons (FROM . TO), where FROM
333 and TO are character codes specifying a range. If ADD is nil,
334 replace with ELT, if ADD is `prepend', prepend ELT, otherwise,
337 #define FONTSET_ADD(fontset, range, elt, add) \
340 ? (FONTSET_FALLBACK (fontset) = Fmake_vector (make_number (1), (elt))) \
341 : Fset_char_table_range ((fontset), (range), \
342 Fmake_vector (make_number (1), (elt)))) \
343 : fontset_add ((fontset), (range), (elt), (add)))
346 fontset_add (fontset
, range
, elt
, add
)
347 Lisp_Object fontset
, range
, elt
, add
;
350 int idx
= (EQ (add
, Qappend
) ? 0 : 1);
352 args
[1 - idx
] = Fmake_vector (make_number (1), elt
);
356 int from
= XINT (XCAR (range
));
357 int to
= XINT (XCDR (range
));
361 args
[idx
] = char_table_ref_and_range (fontset
, from
, &from1
, &to1
);
364 char_table_set_range (fontset
, from
, to1
,
365 NILP (args
[idx
]) ? args
[1 - idx
]
366 : Fvconcat (2, args
));
372 args
[idx
] = FONTSET_FALLBACK (fontset
);
373 FONTSET_FALLBACK (fontset
)
374 = NILP (args
[idx
]) ? args
[1 - idx
] : Fvconcat (2, args
);
380 fontset_compare_rfontdef (val1
, val2
)
381 const void *val1
, *val2
;
383 return (RFONT_DEF_SCORE (*(Lisp_Object
*) val2
)
384 - RFONT_DEF_SCORE (*(Lisp_Object
*) val1
));
387 /* Update FONT-GROUP which has this form:
388 [ CHARSET-ORDERED-LIST-TICK PREFERRED-RFONT-DEF
389 RFONT-DEF0 RFONT-DEF1 ... ]
390 Reorder RFONT-DEFs according to the current langauge, and update
391 CHARSET-ORDERED-LIST-TICK.
393 If PREFERRED_FAMILY is not nil, that family has the higher priority
394 if the encoding charsets or languages in font-specs are the same. */
396 extern Lisp_Object
Fassoc_string ();
399 reorder_font_vector (font_group
, preferred_family
)
400 Lisp_Object font_group
;
401 Lisp_Object preferred_family
;
405 int score_changed
= 0;
407 size
= ASIZE (font_group
);
408 /* Exclude the tailing nil elements from the reordering. */
409 while (NILP (AREF (font_group
, size
- 1))) size
--;
412 for (i
= 0; i
< size
; i
++)
414 Lisp_Object rfont_def
= AREF (font_group
, i
+ 2);
415 Lisp_Object font_def
= RFONT_DEF_FONT_DEF (rfont_def
);
416 Lisp_Object font_spec
= FONT_DEF_SPEC (font_def
);
417 Lisp_Object lang
= Ffont_get (font_spec
, QClang
);
418 Lisp_Object family
= AREF (font_spec
, FONT_FAMILY_INDEX
);
419 Lisp_Object repertory
= FONT_DEF_REPERTORY (font_def
);
422 if (! NILP (repertory
))
426 for (score
= 0xFFFF, tail
= Vcharset_ordered_list
;
427 ! EQ (tail
, Vcharset_non_preferred_head
) && CONSP (tail
);
428 score
--, tail
= XCDR (tail
))
429 if (EQ (repertory
, XCAR (tail
)))
431 if (EQ (tail
, Vcharset_non_preferred_head
))
434 else if (! NILP (lang
))
436 if (EQ (lang
, Vcurrent_iso639_language
))
438 else if (CONSP (Vcurrent_iso639_language
))
439 score
= ! NILP (Fmemq (lang
, Vcurrent_iso639_language
));
442 if (! NILP (preferred_family
) && ! NILP (family
))
444 if (fast_string_match_ignore_case (preferred_family
,
445 SYMBOL_NAME (family
)) < 0)
448 if (RFONT_DEF_SCORE (rfont_def
) != score
)
450 RFONT_DEF_SET_SCORE (rfont_def
, score
);
456 qsort (XVECTOR (font_group
)->contents
+ 2, size
, sizeof (Lisp_Object
),
457 fontset_compare_rfontdef
);
459 ASET (font_group
, 0, make_number (charset_ordered_list_tick
));
462 /* Return RFONT-DEF (vector) in the realized fontset FONTSET for the
463 character C. If no font is found, return Qnil if there's a
464 possibility that the default fontset or the fallback font groups
465 have a proper font, and return Qt if not.
467 If a font is found but is not yet opened, open it (if FACE is not
468 NULL) or return Qnil (if FACE is NULL).
470 ID is a charset-id that must be preferred, or -1 meaning no
473 If FALLBACK is nonzero, search only fallback fonts. */
476 fontset_find_font (fontset
, c
, face
, id
, fallback
)
482 Lisp_Object base_fontset
, elt
, vec
;
484 FRAME_PTR f
= XFRAME (FONTSET_FRAME (fontset
));
486 base_fontset
= FONTSET_BASE (fontset
);
488 vec
= CHAR_TABLE_REF (fontset
, c
);
490 vec
= FONTSET_FALLBACK (fontset
);
496 /* We have not yet decided a font for C. */
501 elt
= char_table_ref_and_range (base_fontset
, c
, &from
, &to
);
502 range
= Fcons (make_number (from
), make_number (to
));
506 elt
= FONTSET_FALLBACK (base_fontset
);
510 /* This fontset doesn't specify any font for C. */
511 vec
= make_number (0);
513 else if (ASIZE (elt
) == 1 && NILP (AREF (elt
, 0)))
515 /* Explicitly specified no font. */
520 /* Build a font-group vector [ -1 nil RFONT-DEF0 RFONT-DEF1 ... ],
521 where the first -1 is to force reordering of RFONT-DEFs. */
522 int size
= ASIZE (elt
);
525 vec
= Fmake_vector (make_number (size
+ 2), Qnil
);
526 ASET (vec
, 0, make_number (-1));
527 for (i
= j
= 0; i
< size
; i
++)
528 if (! NILP (AREF (elt
, i
)))
530 Lisp_Object rfont_def
;
532 RFONT_DEF_NEW (rfont_def
, AREF (elt
, i
));
533 ASET (vec
, j
+ 2, rfont_def
);
537 /* Then store it in the fontset. */
539 FONTSET_SET (fontset
, range
, vec
);
541 FONTSET_FALLBACK (fontset
) = vec
;
545 return (EQ (vec
, Qt
) ? Qt
: Qnil
);
547 if (ASIZE (vec
) > 4 /* multiple RFONT-DEFs */
548 && XINT (AREF (vec
, 0)) != charset_ordered_list_tick
)
549 /* We have just created VEC,
550 or the charset priorities were changed. */
551 reorder_font_vector (vec
, face
->lface
[LFACE_FAMILY_INDEX
]);
557 && EQ (make_number (id
), RFONT_DEF_REPERTORY (elt
)))
561 for (; i
< ASIZE (vec
); i
++)
565 && EQ (make_number (id
), RFONT_DEF_REPERTORY (elt
)))
581 /* Find the first available font in the vector of RFONT-DEF. */
582 for (; i
< ASIZE (vec
); i
++)
584 Lisp_Object font_def
, font_entity
, font_object
;
588 /* This is the sign of not to try fallback fonts. */
590 if (id
>= 0 && i
> 1 && EQ (AREF (vec
, 1), elt
))
591 /* This is already checked. */
593 if (INTEGERP (RFONT_DEF_FACE (elt
))
594 && XINT (AREF (elt
, 1)) < 0)
595 /* We couldn't open this font last time. */
598 font_object
= RFONT_DEF_OBJECT (elt
);
599 if (NILP (font_object
))
601 Lisp_Object font_def
= RFONT_DEF_FONT_DEF (elt
);
604 /* We have not yet opened the font. */
606 font_entity
= font_find_for_lface (f
, face
->lface
,
607 FONT_DEF_SPEC (font_def
), -1);
608 if (NILP (font_entity
))
610 /* Record that no font matches the spec. */
611 RFONT_DEF_SET_FACE (elt
, -1);
614 font_object
= font_open_for_lface (f
, font_entity
, face
->lface
, Qnil
);
615 if (NILP (font_object
))
617 /* Record that the font is unsable. */
618 RFONT_DEF_SET_FACE (elt
, -1);
621 RFONT_DEF_SET_OBJECT (elt
, font_object
);
624 if (font_has_char (f
, font_object
, c
))
628 /* The following code makes Emacs to find a font for C by fairly
629 exhausitive search. But, that takes long time especially for
632 /* Try to find the different font maching with the current spec
634 font_def
= RFONT_DEF_FONT_DEF (elt
);
635 for (i
++; i
< ASIZE (vec
); i
++)
637 if (! EQ (RFONT_DEF_FONT_DEF (AREF (vec
, i
)), font_def
))
639 if (font_has_char (f
, RFONT_DEF_OBJECT (AREF (vec
, i
)), c
))
640 return AREF (vec
, i
);
642 /* Find an font-entity that support C. */
643 font_entity
= font_find_for_lface (f
, face
->lface
,
644 FONT_DEF_SPEC (font_def
), c
);
645 if (! NILP (font_entity
))
647 Lisp_Object rfont_def
, new_vec
;
650 font_object
= font_open_for_lface (f
, font_entity
, face
->lface
,
652 RFONT_DEF_NEW (rfont_def
, font_def
);
653 RFONT_DEF_SET_OBJECT (rfont_def
, font_object
);
654 RFONT_DEF_SET_SCORE (rfont_def
, RFONT_DEF_SCORE (elt
));
655 new_vec
= Fmake_vector (make_number (ASIZE (vec
) + 1), Qnil
);
656 for (j
= 0; j
< i
; j
++)
657 ASET (new_vec
, j
, AREF (vec
, j
));
658 ASET (new_vec
, j
, rfont_def
);
659 for (j
++; j
< ASIZE (new_vec
); j
++)
660 ASET (new_vec
, j
, AREF (vec
, j
- 1));
668 FONTSET_SET (fontset
, make_number (c
), make_number (0));
674 fontset_font (fontset
, c
, face
, id
)
680 Lisp_Object rfont_def
;
681 Lisp_Object base_fontset
;
683 /* Try a font-group for C. */
684 rfont_def
= fontset_find_font (fontset
, c
, face
, id
, 0);
685 if (VECTORP (rfont_def
))
687 if (EQ (rfont_def
, Qt
))
689 base_fontset
= FONTSET_BASE (fontset
);
690 /* Try a font-group for C of the default fontset. */
691 if (! EQ (base_fontset
, Vdefault_fontset
))
693 if (NILP (FONTSET_DEFAULT (fontset
)))
694 FONTSET_DEFAULT (fontset
)
695 = make_fontset (FONTSET_FRAME (fontset
), Qnil
, Vdefault_fontset
);
696 rfont_def
= fontset_find_font (FONTSET_DEFAULT (fontset
), c
, face
, id
, 0);
697 if (VECTORP (rfont_def
))
701 /* Try a fallback font-group. */
702 rfont_def
= fontset_find_font (fontset
, c
, face
, id
, 1);
703 if (! VECTORP (rfont_def
)
704 && ! EQ (base_fontset
, Vdefault_fontset
))
705 /* Try a fallback font-group of the default fontset . */
706 rfont_def
= fontset_find_font (FONTSET_DEFAULT (fontset
), c
, face
, id
, 1);
708 if (! VECTORP (rfont_def
))
709 /* Remeber that we have no font for C. */
710 FONTSET_SET (fontset
, make_number (c
), Qt
);
715 /* Return a newly created fontset with NAME. If BASE is nil, make a
716 base fontset. Otherwise make a realized fontset whose base is
720 make_fontset (frame
, name
, base
)
721 Lisp_Object frame
, name
, base
;
724 int size
= ASIZE (Vfontset_table
);
725 int id
= next_fontset_id
;
727 /* Find a free slot in Vfontset_table. Usually, next_fontset_id is
728 the next available fontset ID. So it is expected that this loop
729 terminates quickly. In addition, as the last element of
730 Vfontset_table is always nil, we don't have to check the range of
732 while (!NILP (AREF (Vfontset_table
, id
))) id
++;
735 Vfontset_table
= larger_vector (Vfontset_table
, size
+ 32, Qnil
);
737 fontset
= Fmake_char_table (Qfontset
, Qnil
);
739 FONTSET_ID (fontset
) = make_number (id
);
742 FONTSET_NAME (fontset
) = name
;
746 FONTSET_NAME (fontset
) = Qnil
;
747 FONTSET_FRAME (fontset
) = frame
;
748 FONTSET_BASE (fontset
) = base
;
751 ASET (Vfontset_table
, id
, fontset
);
752 next_fontset_id
= id
+ 1;
757 /* Set the ASCII font of the default fontset to FONTNAME if that is
760 set_default_ascii_font (fontname
)
761 Lisp_Object fontname
;
763 if (! STRINGP (FONTSET_ASCII (Vdefault_fontset
)))
765 int id
= fs_query_fontset (fontname
, 2);
768 fontname
= FONTSET_ASCII (FONTSET_FROM_ID (id
));
769 FONTSET_ASCII (Vdefault_fontset
)= fontname
;
774 /********** INTERFACES TO xfaces.c, xfns.c, and dispextern.h **********/
776 /* Return the name of the fontset who has ID. */
784 fontset
= FONTSET_FROM_ID (id
);
785 return FONTSET_NAME (fontset
);
789 /* Return the ASCII font name of the fontset who has ID. */
795 Lisp_Object fontset
, elt
;
797 fontset
= FONTSET_FROM_ID (id
);
798 elt
= FONTSET_ASCII (fontset
);
805 free_realized_fontset (f
, fontset
)
812 for (tail
= FONTSET_OBJLIST (fontset
); CONSP (tail
); tail
= XCDR (tail
))
814 xassert (FONT_OBJECT_P (XCAR (tail
)));
815 font_close_object (f
, XCAR (tail
));
819 /* Free fontset of FACE defined on frame F. Called from
820 free_realized_face. */
823 free_face_fontset (f
, face
)
829 fontset
= FONTSET_FROM_ID (face
->fontset
);
832 xassert (! BASE_FONTSET_P (fontset
));
833 xassert (f
== XFRAME (FONTSET_FRAME (fontset
)));
834 free_realized_fontset (f
, fontset
);
835 ASET (Vfontset_table
, face
->fontset
, Qnil
);
836 if (face
->fontset
< next_fontset_id
)
837 next_fontset_id
= face
->fontset
;
838 if (! NILP (FONTSET_DEFAULT (fontset
)))
840 int id
= XINT (FONTSET_ID (FONTSET_DEFAULT (fontset
)));
842 fontset
= AREF (Vfontset_table
, id
);
843 xassert (!NILP (fontset
) && ! BASE_FONTSET_P (fontset
));
844 xassert (f
== XFRAME (FONTSET_FRAME (fontset
)));
845 free_realized_fontset (f
, fontset
);
846 ASET (Vfontset_table
, id
, Qnil
);
847 if (id
< next_fontset_id
)
848 next_fontset_id
= face
->fontset
;
854 /* Return 1 if FACE is suitable for displaying character C.
855 Otherwise return 0. Called from the macro FACE_SUITABLE_FOR_CHAR_P
856 when C is not an ASCII character. */
859 face_suitable_for_char_p (face
, c
)
863 Lisp_Object fontset
, rfont_def
;
865 fontset
= FONTSET_FROM_ID (face
->fontset
);
866 rfont_def
= fontset_font (fontset
, c
, NULL
, -1);
867 return (VECTORP (rfont_def
)
868 && INTEGERP (RFONT_DEF_FACE (rfont_def
))
869 && face
->id
== XINT (RFONT_DEF_FACE (rfont_def
)));
873 /* Return ID of face suitable for displaying character C on frame F.
874 FACE must be reazlied for ASCII characters in advance. Called from
875 the macro FACE_FOR_CHAR. */
878 face_for_char (f
, face
, c
, pos
, object
)
884 Lisp_Object fontset
, rfont_def
;
888 if (ASCII_CHAR_P (c
))
889 return face
->ascii_face
->id
;
891 xassert (fontset_id_valid_p (face
->fontset
));
892 fontset
= FONTSET_FROM_ID (face
->fontset
);
893 xassert (!BASE_FONTSET_P (fontset
));
900 charset
= Fget_char_property (make_number (pos
), Qcharset
, object
);
903 else if (CHARSETP (charset
))
907 val
= assoc_no_quit (charset
, Vfont_encoding_charset_alist
);
908 if (CONSP (val
) && CHARSETP (XCDR (val
)))
909 charset
= XCDR (val
);
910 id
= XINT (CHARSET_SYMBOL_ID (charset
));
913 rfont_def
= fontset_font (fontset
, c
, face
, id
);
914 if (VECTORP (rfont_def
))
916 if (INTEGERP (RFONT_DEF_FACE (rfont_def
)))
917 face_id
= XINT (RFONT_DEF_FACE (rfont_def
));
920 Lisp_Object font_object
;
922 font_object
= RFONT_DEF_OBJECT (rfont_def
);
923 face_id
= face_for_font (f
, font_object
, face
);
924 RFONT_DEF_SET_FACE (rfont_def
, face_id
);
929 if (INTEGERP (FONTSET_NOFONT_FACE (fontset
)))
930 face_id
= XINT (FONTSET_NOFONT_FACE (fontset
));
933 face_id
= face_for_font (f
, Qnil
, face
);
934 FONTSET_NOFONT_FACE (fontset
) = make_number (face_id
);
937 xassert (face_id
>= 0);
942 /* Make a realized fontset for ASCII face FACE on frame F from the
943 base fontset BASE_FONTSET_ID. If BASE_FONTSET_ID is -1, use the
944 default fontset as the base. Value is the id of the new fontset.
945 Called from realize_x_face. */
948 make_fontset_for_ascii_face (f
, base_fontset_id
, face
)
953 Lisp_Object base_fontset
, fontset
, frame
;
955 XSETFRAME (frame
, f
);
956 if (base_fontset_id
>= 0)
958 base_fontset
= FONTSET_FROM_ID (base_fontset_id
);
959 if (!BASE_FONTSET_P (base_fontset
))
960 base_fontset
= FONTSET_BASE (base_fontset
);
961 if (! BASE_FONTSET_P (base_fontset
))
965 base_fontset
= Vdefault_fontset
;
967 fontset
= make_fontset (frame
, Qnil
, base_fontset
);
968 return XINT (FONTSET_ID (fontset
));
972 /* Return ENCODING or a cons of ENCODING and REPERTORY of the font
973 FONTNAME. ENCODING is a charset symbol that specifies the encoding
974 of the font. REPERTORY is a charset symbol or nil. */
977 find_font_encoding (fontname
)
978 Lisp_Object fontname
;
980 Lisp_Object tail
, elt
;
982 for (tail
= Vfont_encoding_alist
; CONSP (tail
); tail
= XCDR (tail
))
986 && STRINGP (XCAR (elt
))
987 && fast_string_match_ignore_case (XCAR (elt
), fontname
) >= 0
988 && (SYMBOLP (XCDR (elt
))
989 ? CHARSETP (XCDR (elt
))
990 : CONSP (XCDR (elt
)) && CHARSETP (XCAR (XCDR (elt
)))))
993 /* We don't know the encoding of this font. Let's assume `ascii'. */
998 /* Cache data used by fontset_pattern_regexp. The car part is a
999 pattern string containing at least one wild card, the cdr part is
1000 the corresponding regular expression. */
1001 static Lisp_Object Vcached_fontset_data
;
1003 #define CACHED_FONTSET_NAME (SDATA (XCAR (Vcached_fontset_data)))
1004 #define CACHED_FONTSET_REGEX (XCDR (Vcached_fontset_data))
1006 /* If fontset name PATTERN contains any wild card, return regular
1007 expression corresponding to PATTERN. */
1010 fontset_pattern_regexp (pattern
)
1011 Lisp_Object pattern
;
1013 if (!index (SDATA (pattern
), '*')
1014 && !index (SDATA (pattern
), '?'))
1015 /* PATTERN does not contain any wild cards. */
1018 if (!CONSP (Vcached_fontset_data
)
1019 || strcmp (SDATA (pattern
), CACHED_FONTSET_NAME
))
1021 /* We must at first update the cached data. */
1022 unsigned char *regex
, *p0
, *p1
;
1023 int ndashes
= 0, nstars
= 0;
1025 for (p0
= SDATA (pattern
); *p0
; p0
++)
1029 else if (*p0
== '*')
1033 /* If PATTERN is not full XLFD we conert "*" to ".*". Otherwise
1034 we convert "*" to "[^-]*" which is much faster in regular
1035 expression matching. */
1037 p1
= regex
= (unsigned char *) alloca (SBYTES (pattern
) + 2 * nstars
+ 1);
1039 p1
= regex
= (unsigned char *) alloca (SBYTES (pattern
) + 5 * nstars
+ 1);
1042 for (p0
= SDATA (pattern
); *p0
; p0
++)
1049 *p1
++ = '[', *p1
++ = '^', *p1
++ = '-', *p1
++ = ']';
1052 else if (*p0
== '?')
1060 Vcached_fontset_data
= Fcons (build_string (SDATA (pattern
)),
1061 build_string (regex
));
1064 return CACHED_FONTSET_REGEX
;
1067 /* Return ID of the base fontset named NAME. If there's no such
1068 fontset, return -1. NAME_PATTERN specifies how to treat NAME as this:
1069 0: pattern containing '*' and '?' as wildcards
1070 1: regular expression
1071 2: literal fontset name
1075 fs_query_fontset (name
, name_pattern
)
1082 name
= Fdowncase (name
);
1083 if (name_pattern
!= 1)
1085 tem
= Frassoc (name
, Vfontset_alias_alist
);
1087 tem
= Fassoc (name
, Vfontset_alias_alist
);
1088 if (CONSP (tem
) && STRINGP (XCAR (tem
)))
1090 else if (name_pattern
== 0)
1092 tem
= fontset_pattern_regexp (name
);
1101 for (i
= 0; i
< ASIZE (Vfontset_table
); i
++)
1103 Lisp_Object fontset
, this_name
;
1105 fontset
= FONTSET_FROM_ID (i
);
1107 || !BASE_FONTSET_P (fontset
))
1110 this_name
= FONTSET_NAME (fontset
);
1111 if (name_pattern
== 1
1112 ? fast_string_match_ignore_case (name
, this_name
) >= 0
1113 : !strcasecmp (SDATA (name
), SDATA (this_name
)))
1120 DEFUN ("query-fontset", Fquery_fontset
, Squery_fontset
, 1, 2, 0,
1121 doc
: /* Return the name of a fontset that matches PATTERN.
1122 The value is nil if there is no matching fontset.
1123 PATTERN can contain `*' or `?' as a wildcard
1124 just as X font name matching algorithm allows.
1125 If REGEXPP is non-nil, PATTERN is a regular expression. */)
1127 Lisp_Object pattern
, regexpp
;
1129 Lisp_Object fontset
;
1132 (*check_window_system_func
) ();
1134 CHECK_STRING (pattern
);
1136 if (SCHARS (pattern
) == 0)
1139 id
= fs_query_fontset (pattern
, !NILP (regexpp
));
1143 fontset
= FONTSET_FROM_ID (id
);
1144 return FONTSET_NAME (fontset
);
1147 /* Return a list of base fontset names matching PATTERN on frame F. */
1150 list_fontsets (f
, pattern
, size
)
1152 Lisp_Object pattern
;
1155 Lisp_Object frame
, regexp
, val
;
1158 XSETFRAME (frame
, f
);
1160 regexp
= fontset_pattern_regexp (pattern
);
1163 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
1165 Lisp_Object fontset
, name
;
1167 fontset
= FONTSET_FROM_ID (id
);
1169 || !BASE_FONTSET_P (fontset
)
1170 || !EQ (frame
, FONTSET_FRAME (fontset
)))
1172 name
= FONTSET_NAME (fontset
);
1174 if (STRINGP (regexp
)
1175 ? (fast_string_match (regexp
, name
) < 0)
1176 : strcmp (SDATA (pattern
), SDATA (name
)))
1179 val
= Fcons (Fcopy_sequence (FONTSET_NAME (fontset
)), val
);
1186 /* Free all realized fontsets whose base fontset is BASE. */
1189 free_realized_fontsets (base
)
1195 /* For the moment, this doesn't work because free_realized_face
1196 doesn't remove FACE from a cache. Until we find a solution, we
1197 suppress this code, and simply use Fclear_face_cache even though
1198 that is not efficient. */
1200 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
1202 Lisp_Object
this = AREF (Vfontset_table
, id
);
1204 if (EQ (FONTSET_BASE (this), base
))
1208 for (tail
= FONTSET_FACE_ALIST (this); CONSP (tail
);
1211 FRAME_PTR f
= XFRAME (FONTSET_FRAME (this));
1212 int face_id
= XINT (XCDR (XCAR (tail
)));
1213 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1215 /* Face THIS itself is also freed by the following call. */
1216 free_realized_face (f
, face
);
1222 /* But, we don't have to call Fclear_face_cache if no fontset has
1223 been realized from BASE. */
1224 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
1226 Lisp_Object
this = AREF (Vfontset_table
, id
);
1228 if (CHAR_TABLE_P (this) && EQ (FONTSET_BASE (this), base
))
1230 Fclear_face_cache (Qt
);
1238 /* Check validity of NAME as a fontset name and return the
1239 corresponding fontset. If not valid, signal an error.
1240 If NAME is t, return Vdefault_fontset. */
1243 check_fontset_name (name
)
1249 return Vdefault_fontset
;
1251 CHECK_STRING (name
);
1252 /* First try NAME as literal. */
1253 id
= fs_query_fontset (name
, 2);
1255 /* For backward compatibility, try again NAME as pattern. */
1256 id
= fs_query_fontset (name
, 0);
1258 error ("Fontset `%s' does not exist", SDATA (name
));
1259 return FONTSET_FROM_ID (id
);
1263 accumulate_script_ranges (arg
, range
, val
)
1264 Lisp_Object arg
, range
, val
;
1266 if (EQ (XCAR (arg
), val
))
1269 XSETCDR (arg
, Fcons (Fcons (XCAR (range
), XCDR (range
)), XCDR (arg
)));
1271 XSETCDR (arg
, Fcons (Fcons (range
, range
), XCDR (arg
)));
1276 /* Return an ASCII font name generated from fontset name NAME and
1277 font-spec ASCII_SPEC. NAME is a string conforming to XLFD. */
1279 static INLINE Lisp_Object
1280 generate_ascii_font_name (name
, ascii_spec
)
1281 Lisp_Object name
, ascii_spec
;
1283 Lisp_Object font_spec
= Ffont_spec (0, NULL
);
1288 if (font_parse_xlfd (SDATA (name
), font_spec
) < 0)
1289 error ("Not an XLFD font name: %s", SDATA (name
));
1290 for (i
= FONT_FOUNDRY_INDEX
; i
< FONT_EXTRA_INDEX
; i
++)
1291 if (! NILP (AREF (ascii_spec
, i
)))
1292 ASET (font_spec
, i
, AREF (ascii_spec
, i
));
1293 i
= font_unparse_xlfd (font_spec
, 0, xlfd
, 256);
1295 error ("Not an XLFD font name: %s", SDATA (name
));
1296 return make_unibyte_string (xlfd
, i
);
1299 /* Variables referred in set_fontset_font. They are set before
1300 map_charset_chars is called in Fset_fontset_font. */
1301 static Lisp_Object font_def_arg
, add_arg
;
1302 static int from_arg
, to_arg
;
1304 /* Callback function for map_charset_chars in Fset_fontset_font. In
1305 FONTSET, set font_def_arg in a fashion specified by add_arg for
1306 characters in RANGE while ignoring the range between from_arg and
1310 set_fontset_font (fontset
, range
)
1311 Lisp_Object fontset
, range
;
1313 if (from_arg
< to_arg
)
1315 int from
= XINT (XCAR (range
)), to
= XINT (XCDR (range
));
1317 if (from
< from_arg
)
1323 range2
= Fcons (make_number (to_arg
), XCDR (range
));
1324 FONTSET_ADD (fontset
, range
, font_def_arg
, add_arg
);
1328 range
= Fcons (XCAR (range
), make_number (from_arg
));
1330 else if (to
<= to_arg
)
1335 range
= Fcons (make_number (to_arg
), XCDR (range
));
1338 FONTSET_ADD (fontset
, range
, font_def_arg
, add_arg
);
1341 extern Lisp_Object QCfamily
, QCregistry
;
1343 DEFUN ("set-fontset-font", Fset_fontset_font
, Sset_fontset_font
, 3, 5, 0,
1345 Modify fontset NAME to use FONT-SPEC for TARGET characters.
1347 TARGET may be a cons; (FROM . TO), where FROM and TO are characters.
1348 In that case, use FONT-SPEC for all characters in the range FROM and
1351 TARGET may be a script name symbol. In that case, use FONT-SPEC for
1352 all characters that belong to the script.
1354 TARGET may be a charset. In that case, use FONT-SPEC for all
1355 characters in the charset.
1357 TARGET may be nil. In that case, use FONT-SPEC for any characters for
1358 that no FONT-SPEC is specified.
1360 FONT-SPEC may one of these:
1361 * A font-spec object made by the function `font-spec' (which see).
1362 * A cons (FAMILY . REGISTRY), where FAMILY is a font family name and
1363 REGISTRY is a font registry name. FAMILY may contain foundry
1364 name, and REGISTRY may contain encoding name.
1365 * A font name string.
1366 * nil, which explicitly specifies that there's no font for TARGET.
1368 Optional 4th argument FRAME, if non-nil, is a frame. This argument is
1369 kept for backward compatibility and has no meaning.
1371 Optional 5th argument ADD, if non-nil, specifies how to add FONT-SPEC
1372 to the font specifications for TARGET previously set. If it is
1373 `prepend', FONT-SPEC is prepended. If it is `append', FONT-SPEC is
1374 appended. By default, FONT-SPEC overrides the previous settings. */)
1375 (name
, target
, font_spec
, frame
, add
)
1376 Lisp_Object name
, target
, font_spec
, frame
, add
;
1378 Lisp_Object fontset
;
1379 Lisp_Object font_def
, registry
, family
;
1380 Lisp_Object range_list
;
1381 struct charset
*charset
= NULL
;
1383 fontset
= check_fontset_name (name
);
1385 /* The arg FRAME is kept for backward compatibility. We only check
1388 CHECK_LIVE_FRAME (frame
);
1390 if (CONSP (font_spec
))
1392 Lisp_Object spec
= Ffont_spec (0, NULL
);
1394 font_parse_family_registry (XCAR (font_spec
), XCDR (font_spec
), spec
);
1397 else if (STRINGP (font_spec
))
1399 Lisp_Object args
[2];
1400 extern Lisp_Object QCname
;
1403 args
[1] = font_spec
;
1404 font_spec
= Ffont_spec (2, args
);
1406 else if (! NILP (font_spec
) && ! FONT_SPEC_P (font_spec
))
1407 Fsignal (Qfont
, list2 (build_string ("Invalid font-spec"), font_spec
));
1409 if (! NILP (font_spec
))
1411 Lisp_Object encoding
, repertory
;
1413 family
= AREF (font_spec
, FONT_FAMILY_INDEX
);
1414 if (! NILP (family
) )
1415 family
= SYMBOL_NAME (family
);
1416 registry
= AREF (font_spec
, FONT_REGISTRY_INDEX
);
1417 if (! NILP (registry
))
1418 registry
= Fdowncase (SYMBOL_NAME (registry
));
1419 encoding
= find_font_encoding (concat3 (family
, build_string ("-"),
1421 if (NILP (encoding
))
1424 if (SYMBOLP (encoding
))
1426 CHECK_CHARSET (encoding
);
1427 encoding
= repertory
= CHARSET_SYMBOL_ID (encoding
);
1431 repertory
= XCDR (encoding
);
1432 encoding
= XCAR (encoding
);
1433 CHECK_CHARSET (encoding
);
1434 encoding
= CHARSET_SYMBOL_ID (encoding
);
1435 if (! NILP (repertory
) && SYMBOLP (repertory
))
1437 CHECK_CHARSET (repertory
);
1438 repertory
= CHARSET_SYMBOL_ID (repertory
);
1441 FONT_DEF_NEW (font_def
, font_spec
, encoding
, repertory
);
1446 if (CHARACTERP (target
))
1447 range_list
= Fcons (Fcons (target
, target
), Qnil
);
1448 else if (CONSP (target
))
1450 Lisp_Object from
, to
;
1452 from
= Fcar (target
);
1454 CHECK_CHARACTER (from
);
1455 CHECK_CHARACTER (to
);
1456 range_list
= Fcons (target
, Qnil
);
1458 else if (SYMBOLP (target
) && !NILP (target
))
1460 Lisp_Object script_list
;
1464 script_list
= XCHAR_TABLE (Vchar_script_table
)->extras
[0];
1465 if (! NILP (Fmemq (target
, script_list
)))
1467 val
= Fcons (target
, Qnil
);
1468 map_char_table (accumulate_script_ranges
, Qnil
, Vchar_script_table
,
1470 range_list
= XCDR (val
);
1471 if (EQ (target
, Qlatin
) && NILP (FONTSET_ASCII (fontset
)))
1473 if (VECTORP (font_spec
))
1474 val
= generate_ascii_font_name (FONTSET_NAME (fontset
),
1478 FONTSET_ASCII (fontset
) = val
;
1481 if (CHARSETP (target
))
1483 if (EQ (target
, Qascii
) && NILP (FONTSET_ASCII (fontset
)))
1485 if (VECTORP (font_spec
))
1486 font_spec
= generate_ascii_font_name (FONTSET_NAME (fontset
),
1488 FONTSET_ASCII (fontset
) = font_spec
;
1489 range_list
= Fcons (Fcons (make_number (0), make_number (127)),
1494 CHECK_CHARSET_GET_CHARSET (target
, charset
);
1497 else if (NILP (range_list
))
1498 error ("Invalid script or charset name: %s",
1499 SDATA (SYMBOL_NAME (target
)));
1501 else if (NILP (target
))
1502 range_list
= Fcons (Qnil
, Qnil
);
1504 error ("Invalid target for setting a font");
1509 font_def_arg
= font_def
;
1511 if (NILP (range_list
))
1512 from_arg
= to_arg
= 0;
1514 from_arg
= XINT (XCAR (XCAR (range_list
))),
1515 to_arg
= XINT (XCDR (XCAR (range_list
)));
1517 map_charset_chars (set_fontset_font
, Qnil
, fontset
, charset
,
1518 CHARSET_MIN_CODE (charset
),
1519 CHARSET_MAX_CODE (charset
));
1521 for (; CONSP (range_list
); range_list
= XCDR (range_list
))
1522 FONTSET_ADD (fontset
, XCAR (range_list
), font_def
, add
);
1524 /* Free all realized fontsets whose base is FONTSET. This way, the
1525 specified character(s) are surely redisplayed by a correct
1527 free_realized_fontsets (fontset
);
1533 DEFUN ("new-fontset", Fnew_fontset
, Snew_fontset
, 2, 2, 0,
1534 doc
: /* Create a new fontset NAME from font information in FONTLIST.
1536 FONTLIST is an alist of scripts vs the corresponding font specification list.
1537 Each element of FONTLIST has the form (SCRIPT FONT-SPEC ...), where a
1538 character of SCRIPT is displayed by a font that matches one of
1541 SCRIPT is a symbol that appears in the first extra slot of the
1542 char-table `char-script-table'.
1544 FONT-SPEC is a vector, a cons, or a string. See the documentation of
1545 `set-fontset-font' for the meaning. */)
1547 Lisp_Object name
, fontlist
;
1549 Lisp_Object fontset
;
1553 CHECK_STRING (name
);
1554 CHECK_LIST (fontlist
);
1556 name
= Fdowncase (name
);
1557 id
= fs_query_fontset (name
, 0);
1560 Lisp_Object font_spec
= Ffont_spec (0, NULL
);
1561 Lisp_Object short_name
;
1565 if (font_parse_xlfd (SDATA (name
), font_spec
) < 0)
1566 error ("Fontset name must be in XLFD format");
1567 short_name
= AREF (font_spec
, FONT_REGISTRY_INDEX
);
1568 if (strncmp (SDATA (SYMBOL_NAME (short_name
)), "fontset-", 8)
1569 || SBYTES (SYMBOL_NAME (short_name
)) < 9)
1570 error ("Registry field of fontset name must be \"fontset-*\"");
1571 Vfontset_alias_alist
= Fcons (Fcons (name
, SYMBOL_NAME (short_name
)),
1572 Vfontset_alias_alist
);
1573 ASET (font_spec
, FONT_REGISTRY_INDEX
, Qiso8859_1
);
1574 fontset
= make_fontset (Qnil
, name
, Qnil
);
1575 xlfd
= alloca (SBYTES (name
) + 1);
1576 len
= font_unparse_xlfd (font_spec
, 0, xlfd
, SBYTES (name
) + 1);
1577 FONTSET_ASCII (fontset
) = make_unibyte_string (xlfd
, len
);
1581 fontset
= FONTSET_FROM_ID (id
);;
1582 free_realized_fontsets (fontset
);
1583 Fset_char_table_range (fontset
, Qt
, Qnil
);
1586 for (; ! NILP (fontlist
); fontlist
= Fcdr (fontlist
))
1588 Lisp_Object elt
, script
;
1590 elt
= Fcar (fontlist
);
1591 script
= Fcar (elt
);
1593 if (CONSP (elt
) && (NILP (XCDR (elt
)) || CONSP (XCDR (elt
))))
1594 for (; CONSP (elt
); elt
= XCDR (elt
))
1595 Fset_fontset_font (name
, script
, XCAR (elt
), Qnil
, Qappend
);
1597 Fset_fontset_font (name
, script
, elt
, Qnil
, Qappend
);
1603 /* Alist of automatically created fontsets. Each element is a cons
1604 (FONT-SPEC . FONTSET-ID). */
1605 static Lisp_Object auto_fontset_alist
;
1608 fontset_from_font (font_object
)
1609 Lisp_Object font_object
;
1611 Lisp_Object font_name
= font_get_name (font_object
);
1612 Lisp_Object font_spec
= Fcopy_font_spec (font_object
);
1613 Lisp_Object fontset_spec
, alias
, name
, fontset
;
1617 val
= assoc_no_quit (font_spec
, auto_fontset_alist
);
1619 return XINT (FONTSET_ID (XCDR (val
)));
1620 if (NILP (auto_fontset_alist
))
1621 alias
= intern ("fontset-startup");
1625 int len
= XINT (Flength (auto_fontset_alist
));
1627 sprintf (temp
, "fontset-auto%d", len
);
1628 alias
= intern (temp
);
1630 fontset_spec
= Fcopy_font_spec (font_spec
);
1631 ASET (fontset_spec
, FONT_REGISTRY_INDEX
, alias
);
1632 name
= Ffont_xlfd_name (fontset_spec
);
1635 fontset
= make_fontset (Qnil
, name
, Qnil
);
1636 Vfontset_alias_alist
= Fcons (Fcons (name
, SYMBOL_NAME (alias
)),
1637 Vfontset_alias_alist
);
1638 alias
= Fdowncase (AREF (font_object
, FONT_NAME_INDEX
));
1639 Vfontset_alias_alist
= Fcons (Fcons (name
, alias
), Vfontset_alias_alist
);
1640 auto_fontset_alist
= Fcons (Fcons (font_spec
, fontset
), auto_fontset_alist
);
1641 FONTSET_ASCII (fontset
) = font_name
;
1642 ASET (font_spec
, FONT_FOUNDRY_INDEX
, Qnil
);
1643 ASET (font_spec
, FONT_ADSTYLE_INDEX
, Qnil
);
1644 for (i
= FONT_WEIGHT_INDEX
; i
< FONT_EXTRA_INDEX
; i
++)
1645 ASET (font_spec
, i
, Qnil
);
1646 Fset_fontset_font (name
, Qlatin
, font_spec
, Qnil
, Qnil
);
1647 font_spec
= Fcopy_font_spec (font_spec
);
1648 ASET (font_spec
, FONT_REGISTRY_INDEX
, Qiso10646_1
);
1649 Fset_fontset_font (name
, Qnil
, font_spec
, Qnil
, Qnil
);
1650 return XINT (FONTSET_ID (fontset
));
1653 DEFUN ("font-info", Ffont_info
, Sfont_info
, 1, 2, 0,
1654 doc
: /* Return information about a font named NAME on frame FRAME.
1655 If FRAME is omitted or nil, use the selected frame.
1656 The returned value is a vector of OPENED-NAME, FULL-NAME, CHARSET, SIZE,
1657 HEIGHT, BASELINE-OFFSET, RELATIVE-COMPOSE, and DEFAULT-ASCENT,
1659 OPENED-NAME is the name used for opening the font,
1660 FULL-NAME is the full name of the font,
1661 SIZE is the maximum bound width of the font,
1662 HEIGHT is the height of the font,
1663 BASELINE-OFFSET is the upward offset pixels from ASCII baseline,
1664 RELATIVE-COMPOSE and DEFAULT-ASCENT are the numbers controlling
1665 how to compose characters.
1666 If the named font is not yet loaded, return nil. */)
1668 Lisp_Object name
, frame
;
1673 Lisp_Object font_object
;
1675 (*check_window_system_func
) ();
1677 CHECK_STRING (name
);
1678 name
= Fdowncase (name
);
1680 frame
= selected_frame
;
1681 CHECK_LIVE_FRAME (frame
);
1684 font_object
= font_open_by_name (f
, SDATA (name
));
1685 if (NILP (font_object
))
1687 font
= XFONT_OBJECT (font_object
);
1689 info
= Fmake_vector (make_number (7), Qnil
);
1690 XVECTOR (info
)->contents
[0] = AREF (font_object
, FONT_NAME_INDEX
);
1691 XVECTOR (info
)->contents
[1] = AREF (font_object
, FONT_NAME_INDEX
);
1692 XVECTOR (info
)->contents
[2] = make_number (font
->pixel_size
);
1693 XVECTOR (info
)->contents
[3] = make_number (font
->height
);
1694 XVECTOR (info
)->contents
[4] = make_number (font
->baseline_offset
);
1695 XVECTOR (info
)->contents
[5] = make_number (font
->relative_compose
);
1696 XVECTOR (info
)->contents
[6] = make_number (font
->default_ascent
);
1698 font_close_object (f
, font_object
);
1703 /* Return a cons (FONT-NAME . GLYPH-CODE).
1704 FONT-NAME is the font name for the character at POSITION in the current
1705 buffer. This is computed from all the text properties and overlays
1706 that apply to POSITION. POSTION may be nil, in which case,
1707 FONT-NAME is the font name for display the character CH with the
1710 GLYPH-CODE is the glyph code in the font to use for the character.
1712 If the 2nd optional arg CH is non-nil, it is a character to check
1713 the font instead of the character at POSITION.
1715 It returns nil in the following cases:
1717 (1) The window system doesn't have a font for the character (thus
1718 it is displayed by an empty box).
1720 (2) The character code is invalid.
1722 (3) If POSITION is not nil, and the current buffer is not displayed
1725 In addition, the returned font name may not take into account of
1726 such redisplay engine hooks as what used in jit-lock-mode if
1727 POSITION is currently not visible. */
1730 DEFUN ("internal-char-font", Finternal_char_font
, Sinternal_char_font
, 1, 2, 0,
1731 doc
: /* For internal use only. */)
1733 Lisp_Object position
, ch
;
1735 EMACS_INT pos
, pos_byte
, dummy
;
1740 Lisp_Object rfont_def
;
1743 if (NILP (position
))
1745 CHECK_CHARACTER (ch
);
1747 f
= XFRAME (selected_frame
);
1748 face_id
= DEFAULT_FACE_ID
;
1754 Lisp_Object window
, charset
;
1757 CHECK_NUMBER_COERCE_MARKER (position
);
1758 pos
= XINT (position
);
1759 if (pos
< BEGV
|| pos
>= ZV
)
1760 args_out_of_range_3 (position
, make_number (BEGV
), make_number (ZV
));
1761 pos_byte
= CHAR_TO_BYTE (pos
);
1763 c
= FETCH_CHAR (pos_byte
);
1769 window
= Fget_buffer_window (Fcurrent_buffer (), Qnil
);
1772 w
= XWINDOW (window
);
1773 f
= XFRAME (w
->frame
);
1774 face_id
= face_at_buffer_position (w
, pos
, -1, -1, &dummy
, pos
+ 100, 0);
1775 charset
= Fget_char_property (position
, Qcharset
, Qnil
);
1776 if (CHARSETP (charset
))
1777 cs_id
= XINT (CHARSET_SYMBOL_ID (charset
));
1781 if (! CHAR_VALID_P (c
, 0))
1783 face_id
= FACE_FOR_CHAR (f
, FACE_FROM_ID (f
, face_id
), c
, pos
, Qnil
);
1784 face
= FACE_FROM_ID (f
, face_id
);
1787 struct font
*font
= face
->font
;
1788 unsigned code
= font
->driver
->encode_char (font
, c
);
1789 Lisp_Object fontname
= font
->props
[FONT_NAME_INDEX
];
1790 /* Assignment to EMACS_INT stops GCC whining about limited range
1792 EMACS_INT cod
= code
;
1794 if (code
== FONT_INVALID_CODE
)
1796 if (cod
<= MOST_POSITIVE_FIXNUM
)
1797 return Fcons (fontname
, make_number (code
));
1798 return Fcons (fontname
, Fcons (make_number (code
>> 16),
1799 make_number (code
& 0xFFFF)));
1805 DEFUN ("fontset-info", Ffontset_info
, Sfontset_info
, 1, 2, 0,
1806 doc
: /* Return information about a fontset FONTSET on frame FRAME.
1807 The value is a char-table of which elements has this form.
1809 ((FONT-PATTERN OPENED-FONT ...) ...)
1811 FONT-PATTERN is a vector:
1813 [ FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY ]
1815 or a string of font name pattern.
1817 OPENED-FONT is a name of a font actually opened.
1819 The char-table has one extra slot. The value is a char-table
1820 containing the information about the derived fonts from the default
1821 fontset. The format is the same as abobe. */)
1823 Lisp_Object fontset
, frame
;
1826 Lisp_Object
*realized
[2], fontsets
[2], tables
[2];
1827 Lisp_Object val
, elt
;
1830 (*check_window_system_func
) ();
1832 fontset
= check_fontset_name (fontset
);
1835 frame
= selected_frame
;
1836 CHECK_LIVE_FRAME (frame
);
1839 /* Recode fontsets realized on FRAME from the base fontset FONTSET
1840 in the table `realized'. */
1841 realized
[0] = (Lisp_Object
*) alloca (sizeof (Lisp_Object
)
1842 * ASIZE (Vfontset_table
));
1843 for (i
= j
= 0; i
< ASIZE (Vfontset_table
); i
++)
1845 elt
= FONTSET_FROM_ID (i
);
1847 && EQ (FONTSET_BASE (elt
), fontset
)
1848 && EQ (FONTSET_FRAME (elt
), frame
))
1849 realized
[0][j
++] = elt
;
1851 realized
[0][j
] = Qnil
;
1853 realized
[1] = (Lisp_Object
*) alloca (sizeof (Lisp_Object
)
1854 * ASIZE (Vfontset_table
));
1855 for (i
= j
= 0; ! NILP (realized
[0][i
]); i
++)
1857 elt
= FONTSET_DEFAULT (realized
[0][i
]);
1859 realized
[1][j
++] = elt
;
1861 realized
[1][j
] = Qnil
;
1863 tables
[0] = Fmake_char_table (Qfontset_info
, Qnil
);
1864 tables
[1] = Fmake_char_table (Qnil
, Qnil
);
1865 XCHAR_TABLE (tables
[0])->extras
[0] = tables
[1];
1866 fontsets
[0] = fontset
;
1867 fontsets
[1] = Vdefault_fontset
;
1869 /* Accumulate information of the fontset in TABLE. The format of
1870 each element is ((FONT-SPEC OPENED-FONT ...) ...). */
1871 for (k
= 0; k
<= 1; k
++)
1873 for (c
= 0; c
<= MAX_CHAR
; )
1877 if (c
<= MAX_5_BYTE_CHAR
)
1879 val
= char_table_ref_and_range (fontsets
[k
], c
, &from
, &to
);
1880 if (to
> MAX_5_BYTE_CHAR
)
1881 to
= MAX_5_BYTE_CHAR
;
1885 val
= FONTSET_FALLBACK (fontsets
[k
]);
1892 /* At first, set ALIST to ((FONT-SPEC) ...). */
1893 for (alist
= Qnil
, i
= 0; i
< ASIZE (val
); i
++)
1894 if (! NILP (AREF (val
, i
)))
1895 alist
= Fcons (Fcons (FONT_DEF_SPEC (AREF (val
, i
)), Qnil
),
1897 alist
= Fnreverse (alist
);
1899 /* Then store opend font names to cdr of each elements. */
1900 for (i
= 0; ! NILP (realized
[k
][i
]); i
++)
1902 if (c
<= MAX_5_BYTE_CHAR
)
1903 val
= FONTSET_REF (realized
[k
][i
], c
);
1905 val
= FONTSET_FALLBACK (realized
[k
][i
]);
1906 if (! VECTORP (val
))
1908 /* VAL: [int ? [FACE-ID FONT-DEF FONT-OBJECT int] ... ] */
1909 for (j
= 2; j
< ASIZE (val
); j
++)
1911 elt
= AREF (val
, j
);
1912 if (FONT_OBJECT_P (RFONT_DEF_OBJECT (elt
)))
1914 Lisp_Object font_object
= RFONT_DEF_OBJECT (elt
);
1915 Lisp_Object slot
, name
;
1917 slot
= Fassq (RFONT_DEF_SPEC (elt
), alist
);
1918 name
= AREF (font_object
, FONT_NAME_INDEX
);
1919 if (NILP (Fmember (name
, XCDR (slot
))))
1920 nconc2 (slot
, Fcons (name
, Qnil
));
1925 /* Store ALIST in TBL for characters C..TO. */
1926 if (c
<= MAX_5_BYTE_CHAR
)
1927 char_table_set_range (tables
[k
], c
, to
, alist
);
1929 XCHAR_TABLE (tables
[k
])->defalt
= alist
;
1931 /* At last, change each elements to font names. */
1932 for (; CONSP (alist
); alist
= XCDR (alist
))
1935 XSETCAR (elt
, Ffont_xlfd_name (XCAR (elt
)));
1946 DEFUN ("fontset-font", Ffontset_font
, Sfontset_font
, 2, 3, 0,
1947 doc
: /* Return a font name pattern for character CH in fontset NAME.
1948 If NAME is t, find a pattern in the default fontset.
1950 The value has the form (FAMILY . REGISTRY), where FAMILY is a font
1951 family name and REGISTRY is a font registry name. This is actually
1952 the first font name pattern for CH in the fontset or in the default
1955 If the 2nd optional arg ALL is non-nil, return a list of all font name
1958 Lisp_Object name
, ch
, all
;
1961 Lisp_Object fontset
, elt
, list
, repertory
, val
;
1964 fontset
= check_fontset_name (name
);
1966 CHECK_CHARACTER (ch
);
1971 for (i
= 0, elt
= FONTSET_REF (fontset
, c
); i
< 2;
1972 i
++, elt
= FONTSET_FALLBACK (fontset
))
1974 for (j
= 0; j
< ASIZE (elt
); j
++)
1976 val
= AREF (elt
, j
);
1977 repertory
= AREF (val
, 1);
1978 if (INTEGERP (repertory
))
1980 struct charset
*charset
= CHARSET_FROM_ID (XINT (repertory
));
1982 if (! CHAR_CHARSET_P (c
, charset
))
1985 else if (CHAR_TABLE_P (repertory
))
1987 if (NILP (CHAR_TABLE_REF (repertory
, c
)))
1990 val
= AREF (val
, 0);
1991 val
= Fcons (AREF (val
, 0), AREF (val
, 5));
1994 list
= Fcons (val
, list
);
1996 if (EQ (fontset
, Vdefault_fontset
))
1998 fontset
= Vdefault_fontset
;
2000 return (Fnreverse (list
));
2003 DEFUN ("fontset-list", Ffontset_list
, Sfontset_list
, 0, 0, 0,
2004 doc
: /* Return a list of all defined fontset names. */)
2007 Lisp_Object fontset
, list
;
2011 for (i
= 0; i
< ASIZE (Vfontset_table
); i
++)
2013 fontset
= FONTSET_FROM_ID (i
);
2015 && BASE_FONTSET_P (fontset
))
2016 list
= Fcons (FONTSET_NAME (fontset
), list
);
2023 #ifdef FONTSET_DEBUG
2026 dump_fontset (fontset
)
2027 Lisp_Object fontset
;
2031 vec
= Fmake_vector (make_number (3), Qnil
);
2032 ASET (vec
, 0, FONTSET_ID (fontset
));
2034 if (BASE_FONTSET_P (fontset
))
2036 ASET (vec
, 1, FONTSET_NAME (fontset
));
2042 frame
= FONTSET_FRAME (fontset
);
2045 FRAME_PTR f
= XFRAME (frame
);
2047 if (FRAME_LIVE_P (f
))
2049 Fcons (FONTSET_NAME (FONTSET_BASE (fontset
)), f
->name
));
2052 Fcons (FONTSET_NAME (FONTSET_BASE (fontset
)), Qnil
));
2054 if (!NILP (FONTSET_DEFAULT (fontset
)))
2055 ASET (vec
, 2, FONTSET_ID (FONTSET_DEFAULT (fontset
)));
2060 DEFUN ("fontset-list-all", Ffontset_list_all
, Sfontset_list_all
, 0, 0, 0,
2061 doc
: /* Return a brief summary of all fontsets for debug use. */)
2067 for (i
= 0, val
= Qnil
; i
< ASIZE (Vfontset_table
); i
++)
2068 if (! NILP (AREF (Vfontset_table
, i
)))
2069 val
= Fcons (dump_fontset (AREF (Vfontset_table
, i
)), val
);
2070 return (Fnreverse (val
));
2072 #endif /* FONTSET_DEBUG */
2077 DEFSYM (Qfontset
, "fontset");
2078 Fput (Qfontset
, Qchar_table_extra_slots
, make_number (9));
2079 DEFSYM (Qfontset_info
, "fontset-info");
2080 Fput (Qfontset_info
, Qchar_table_extra_slots
, make_number (1));
2082 DEFSYM (Qprepend
, "prepend");
2083 DEFSYM (Qappend
, "append");
2084 DEFSYM (Qlatin
, "latin");
2086 Vcached_fontset_data
= Qnil
;
2087 staticpro (&Vcached_fontset_data
);
2089 Vfontset_table
= Fmake_vector (make_number (32), Qnil
);
2090 staticpro (&Vfontset_table
);
2092 Vdefault_fontset
= Fmake_char_table (Qfontset
, Qnil
);
2093 staticpro (&Vdefault_fontset
);
2094 FONTSET_ID (Vdefault_fontset
) = make_number (0);
2095 FONTSET_NAME (Vdefault_fontset
)
2096 = build_string ("-*-*-*-*-*-*-*-*-*-*-*-*-fontset-default");
2097 ASET (Vfontset_table
, 0, Vdefault_fontset
);
2098 next_fontset_id
= 1;
2100 auto_fontset_alist
= Qnil
;
2101 staticpro (&auto_fontset_alist
);
2103 DEFVAR_LISP ("font-encoding-alist", &Vfont_encoding_alist
,
2105 Alist of fontname patterns vs the corresponding encoding and repertory info.
2106 Each element looks like (REGEXP . (ENCODING . REPERTORY)),
2107 where ENCODING is a charset or a char-table,
2108 and REPERTORY is a charset, a char-table, or nil.
2110 If ENCDING and REPERTORY are the same, the element can have the form
2111 \(REGEXP . ENCODING).
2113 ENCODING is for converting a character to a glyph code of the font.
2114 If ENCODING is a charset, encoding a character by the charset gives
2115 the corresponding glyph code. If ENCODING is a char-table, looking up
2116 the table by a character gives the corresponding glyph code.
2118 REPERTORY specifies a repertory of characters supported by the font.
2119 If REPERTORY is a charset, all characters beloging to the charset are
2120 supported. If REPERTORY is a char-table, all characters who have a
2121 non-nil value in the table are supported. It REPERTORY is nil, Emacs
2122 gets the repertory information by an opened font and ENCODING. */);
2123 Vfont_encoding_alist
= Qnil
;
2125 DEFVAR_LISP ("font-encoding-charset-alist", &Vfont_encoding_charset_alist
,
2127 Alist of charsets vs the charsets to determine the preferred font encoding.
2128 Each element looks like (CHARSET . ENCDOING-CHARSET),
2129 where ENCODING-CHARSET is a charset registered in the variable
2130 `font-encoding-alist' as ENCODING.
2132 When a text has a property `charset' and the value is CHARSET, a font
2133 whose encoding corresponds to ENCODING-CHARSET is preferred. */);
2134 Vfont_encoding_charset_alist
= Qnil
;
2136 DEFVAR_LISP ("use-default-ascent", &Vuse_default_ascent
,
2138 Char table of characters whose ascent values should be ignored.
2139 If an entry for a character is non-nil, the ascent value of the glyph
2140 is assumed to be what specified by _MULE_DEFAULT_ASCENT property of a font.
2142 This affects how a composite character which contains
2143 such a character is displayed on screen. */);
2144 Vuse_default_ascent
= Qnil
;
2146 DEFVAR_LISP ("ignore-relative-composition", &Vignore_relative_composition
,
2148 Char table of characters which is not composed relatively.
2149 If an entry for a character is non-nil, a composition sequence
2150 which contains that character is displayed so that
2151 the glyph of that character is put without considering
2152 an ascent and descent value of a previous character. */);
2153 Vignore_relative_composition
= Qnil
;
2155 DEFVAR_LISP ("alternate-fontname-alist", &Valternate_fontname_alist
,
2156 doc
: /* Alist of fontname vs list of the alternate fontnames.
2157 When a specified font name is not found, the corresponding
2158 alternate fontnames (if any) are tried instead. */);
2159 Valternate_fontname_alist
= Qnil
;
2161 DEFVAR_LISP ("fontset-alias-alist", &Vfontset_alias_alist
,
2162 doc
: /* Alist of fontset names vs the aliases. */);
2163 Vfontset_alias_alist
= Fcons (Fcons (FONTSET_NAME (Vdefault_fontset
),
2164 build_string ("fontset-default")),
2167 DEFVAR_LISP ("vertical-centering-font-regexp",
2168 &Vvertical_centering_font_regexp
,
2169 doc
: /* *Regexp matching font names that require vertical centering on display.
2170 When a character is displayed with such fonts, the character is displayed
2171 at the vertical center of lines. */);
2172 Vvertical_centering_font_regexp
= Qnil
;
2174 DEFVAR_LISP ("otf-script-alist", &Votf_script_alist
,
2175 doc
: /* Alist of OpenType script tags vs the corresponding script names. */);
2176 Votf_script_alist
= Qnil
;
2178 defsubr (&Squery_fontset
);
2179 defsubr (&Snew_fontset
);
2180 defsubr (&Sset_fontset_font
);
2181 defsubr (&Sfont_info
);
2182 defsubr (&Sinternal_char_font
);
2183 defsubr (&Sfontset_info
);
2184 defsubr (&Sfontset_font
);
2185 defsubr (&Sfontset_list
);
2186 #ifdef FONTSET_DEBUG
2187 defsubr (&Sfontset_list_all
);
2191 /* arch-tag: ea861585-2f5f-4e5b-9849-d04a9c3a3537
2192 (do not change this comment) */