2 Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
3 Copyright (C) 1995, 1997, 1998, 2000, 2003, 2004, 2005
4 National Institute of Advanced Industrial Science and Technology (AIST)
5 Registration Number H14PRO021
6 Copyright (C) 2003, 2006
7 National Institute of Advanced Industrial Science and Technology (AIST)
8 Registration Number H13PRO009
10 This file is part of GNU Emacs.
12 GNU Emacs is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2, or (at your option)
17 GNU Emacs is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with GNU Emacs; see the file COPYING. If not, write to
24 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 Boston, MA 02110-1301, USA. */
27 /* #define FONTSET_DEBUG */
36 #include "blockinput.h"
38 #include "character.h"
43 #include "dispextern.h"
44 #include "intervals.h"
57 #ifdef USE_FONT_BACKEND
59 #endif /* USE_FONT_BACKEND */
63 #define xassert(X) do {if (!(X)) abort ();} while (0)
66 #else /* not FONTSET_DEBUG */
67 #define xassert(X) (void) 0
68 #endif /* not FONTSET_DEBUG */
70 EXFUN (Fclear_face_cache
, 1);
74 A fontset is a collection of font related information to give
75 similar appearance (style, etc) of characters. A fontset has two
76 roles. One is to use for the frame parameter `font' as if it is an
77 ASCII font. In that case, Emacs uses the font specified for
78 `ascii' script for the frame's default font.
80 Another role, the more important one, is to provide information
81 about which font to use for each non-ASCII character.
83 There are two kinds of fontsets; base and realized. A base fontset
84 is created by `new-fontset' from Emacs Lisp explicitly. A realized
85 fontset is created implicitly when a face is realized for ASCII
86 characters. A face is also realized for non-ASCII characters based
87 on an ASCII face. All of non-ASCII faces based on the same ASCII
88 face share the same realized fontset.
90 A fontset object is implemented by a char-table whose default value
91 and parent are always nil.
93 An element of a base fontset is a vector of FONT-DEFs which itself
94 is a vector [ FONT-SPEC ENCODING REPERTORY ].
97 [ FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY ]
100 where FAMILY, WEIGHT, SLANT, SWIDTH, ADSTYLE, REGISTRY, and
101 FONT-NAME are strings.
103 Note: Currently WEIGHT through ADSTYLE are ignored.
105 ENCODING is a charset ID that can convert characters to glyph codes
106 of the corresponding font.
108 REPERTORY is a charset ID, a char-table, or nil. If REPERTORY is a
109 charset ID, the repertory of the charset exactly matches with that
110 of the font. If REPERTORY is a char-table, all characters who have
111 a non-nil value in the table are supported. If REPERTORY is nil,
112 we consult with the font itself to get the repertory.
114 ENCODING and REPERTORY are extracted from the variable
115 Vfont_encoding_alist by using a font name generated from FONT-SPEC
116 (if it is a vector) or FONT-NAME as a matching target.
119 An element of a realized fontset is nil or t, or has this form:
121 [CHARSET-ORDERED-LIST-TICK PREFERRED-CHARSET-ID
122 PREFERRED-RFONT-DEF RFONT-DEF0 RFONT-DEF1 ...].
124 RFONT-DEFn (i.e. Realized FONT-DEF) has this form:
126 [ FACE-ID FONT-INDEX FONT-DEF OPENED-FONT-NAME ]
128 RFONT-DEFn is automatically reordered by the current charset
131 The value nil means that we have not yet generated the above vector
132 from the base of the fontset.
134 The value t means that no font is available for the corresponding
138 A fontset has 9 extra slots.
140 The 1st slot: the ID number of the fontset
143 base: the name of the fontset
148 realized: the base fontset
152 realized: the frame that the fontset belongs to
155 base: the font name for ASCII characters
160 realized: the ID number of a face to use for characters that
161 has no font in a realized fontset.
165 realized: Alist of font index vs the corresponding repertory
170 realized: If the base is not the default fontset, a fontset
171 realized from the default fontset, else nil.
174 base: Same as element value (but for fallback fonts).
177 All fontsets are recorded in the vector Vfontset_table.
182 There's a special base fontset named `default fontset' which
183 defines the default font specifications. When a base fontset
184 doesn't specify a font for a specific character, the corresponding
185 value in the default fontset is used.
187 The parent of a realized fontset created for such a face that has
188 no fontset is the default fontset.
191 These structures are hidden from the other codes than this file.
192 The other codes handle fontsets only by their ID numbers. They
193 usually use the variable name `fontset' for IDs. But, in this
194 file, we always use varialbe name `id' for IDs, and name `fontset'
195 for an actual fontset object, i.e., char-table.
199 /********** VARIABLES and FUNCTION PROTOTYPES **********/
201 extern Lisp_Object Qfont
;
202 static Lisp_Object Qfontset
;
203 static Lisp_Object Qfontset_info
;
204 static Lisp_Object Qprepend
, Qappend
;
206 /* Vector containing all fontsets. */
207 static Lisp_Object Vfontset_table
;
209 /* Next possibly free fontset ID. Usually this keeps the minimum
210 fontset ID not yet used. */
211 static int next_fontset_id
;
213 /* The default fontset. This gives default FAMILY and REGISTRY of
214 font for each character. */
215 static Lisp_Object Vdefault_fontset
;
217 Lisp_Object Vfont_encoding_alist
;
218 Lisp_Object Vuse_default_ascent
;
219 Lisp_Object Vignore_relative_composition
;
220 Lisp_Object Valternate_fontname_alist
;
221 Lisp_Object Vfontset_alias_alist
;
222 Lisp_Object Vvertical_centering_font_regexp
;
223 Lisp_Object Votf_script_alist
;
225 /* The following six are declarations of callback functions depending
226 on window system. See the comments in src/fontset.h for more
229 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
230 struct font_info
*(*get_font_info_func
) P_ ((FRAME_PTR f
, int font_idx
));
232 /* Return a list of font names which matches PATTERN. See the documentation
233 of `x-list-fonts' for more details. */
234 Lisp_Object (*list_fonts_func
) P_ ((struct frame
*f
,
239 /* Load a font named NAME for frame F and return a pointer to the
240 information of the loaded font. If loading is failed, return 0. */
241 struct font_info
*(*load_font_func
) P_ ((FRAME_PTR f
, char *name
, int));
243 /* Return a pointer to struct font_info of a font named NAME for frame F. */
244 struct font_info
*(*query_font_func
) P_ ((FRAME_PTR f
, char *name
));
246 /* Additional function for setting fontset or changing fontset
247 contents of frame F. */
248 void (*set_frame_fontset_func
) P_ ((FRAME_PTR f
, Lisp_Object arg
,
249 Lisp_Object oldval
));
251 /* To find a CCL program, fs_load_font calls this function.
252 The argument is a pointer to the struct font_info.
253 This function set the member `encoder' of the structure. */
254 void (*find_ccl_program_func
) P_ ((struct font_info
*));
256 Lisp_Object (*get_font_repertory_func
) P_ ((struct frame
*,
257 struct font_info
*));
259 /* Check if any window system is used now. */
260 void (*check_window_system_func
) P_ ((void));
263 /* Prototype declarations for static functions. */
264 static Lisp_Object fontset_add
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
,
266 static Lisp_Object fontset_font
P_ ((Lisp_Object
, int, struct face
*, int));
267 static Lisp_Object make_fontset
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
));
268 static Lisp_Object fontset_pattern_regexp
P_ ((Lisp_Object
));
269 static void accumulate_script_ranges
P_ ((Lisp_Object
, Lisp_Object
,
271 Lisp_Object find_font_encoding
P_ ((Lisp_Object
));
273 static void set_fontset_font
P_ ((Lisp_Object
, Lisp_Object
));
277 /* Return 1 if ID is a valid fontset id, else return 0. */
280 fontset_id_valid_p (id
)
283 return (id
>= 0 && id
< ASIZE (Vfontset_table
) - 1);
290 /********** MACROS AND FUNCTIONS TO HANDLE FONTSET **********/
292 /* Return the fontset with ID. No check of ID's validness. */
293 #define FONTSET_FROM_ID(id) AREF (Vfontset_table, id)
295 /* Macros to access special values of FONTSET. */
296 #define FONTSET_ID(fontset) XCHAR_TABLE (fontset)->extras[0]
298 /* Macros to access special values of (base) FONTSET. */
299 #define FONTSET_NAME(fontset) XCHAR_TABLE (fontset)->extras[1]
300 #define FONTSET_ASCII(fontset) XCHAR_TABLE (fontset)->extras[4]
302 /* Macros to access special values of (realized) FONTSET. */
303 #define FONTSET_BASE(fontset) XCHAR_TABLE (fontset)->extras[2]
304 #define FONTSET_FRAME(fontset) XCHAR_TABLE (fontset)->extras[3]
305 #define FONTSET_NOFONT_FACE(fontset) XCHAR_TABLE (fontset)->extras[5]
306 #define FONTSET_REPERTORY(fontset) XCHAR_TABLE (fontset)->extras[6]
307 #define FONTSET_DEFAULT(fontset) XCHAR_TABLE (fontset)->extras[7]
309 /* For both base and realized fontset. */
310 #define FONTSET_FALLBACK(fontset) XCHAR_TABLE (fontset)->extras[8]
312 #define BASE_FONTSET_P(fontset) (NILP (FONTSET_BASE (fontset)))
315 /* Return the element of FONTSET for the character C. If FONTSET is a
316 base fontset other then the default fontset and FONTSET doesn't
317 contain information for C, return the information in the default
320 #define FONTSET_REF(fontset, c) \
321 (EQ (fontset, Vdefault_fontset) \
322 ? CHAR_TABLE_REF (fontset, c) \
323 : fontset_ref ((fontset), (c)))
326 fontset_ref (fontset
, c
)
332 elt
= CHAR_TABLE_REF (fontset
, c
);
333 if (NILP (elt
) && ! EQ (fontset
, Vdefault_fontset
)
334 /* Don't check Vdefault_fontset for a realized fontset. */
335 && NILP (FONTSET_BASE (fontset
)))
336 elt
= CHAR_TABLE_REF (Vdefault_fontset
, c
);
341 /* Return the element of FONTSET for the character C, set FROM and TO
342 to the range of characters around C that have the same value as C.
343 If FONTSET is a base fontset other then the default fontset and
344 FONTSET doesn't contain information for C, return the information
345 in the default fontset. */
347 #define FONTSET_REF_AND_RANGE(fontset, c, form, to) \
348 (EQ (fontset, Vdefault_fontset) \
349 ? char_table_ref_and_range (fontset, c, &from, &to) \
350 : fontset_ref_and_range (fontset, c, &from, &to))
353 fontset_ref_and_range (fontset
, c
, from
, to
)
360 elt
= char_table_ref_and_range (fontset
, c
, from
, to
);
361 if (NILP (elt
) && ! EQ (fontset
, Vdefault_fontset
)
362 /* Don't check Vdefault_fontset for a realized fontset. */
363 && NILP (FONTSET_BASE (fontset
)))
367 elt
= char_table_ref_and_range (Vdefault_fontset
, c
, &from1
, &to1
);
377 /* Set elements of FONTSET for characters in RANGE to the value ELT.
378 RANGE is a cons (FROM . TO), where FROM and TO are character codes
379 specifying a range. */
381 #define FONTSET_SET(fontset, range, elt) \
382 Fset_char_table_range ((fontset), (range), (elt))
385 /* Modify the elements of FONTSET for characters in RANGE by replacing
386 with ELT or adding ELT. RANGE is a cons (FROM . TO), where FROM
387 and TO are character codes specifying a range. If ADD is nil,
388 replace with ELT, if ADD is `prepend', prepend ELT, otherwise,
391 #define FONTSET_ADD(fontset, range, elt, add) \
394 ? (FONTSET_FALLBACK (fontset) = Fmake_vector (make_number (1), (elt))) \
395 : Fset_char_table_range ((fontset), (range), \
396 Fmake_vector (make_number (1), (elt)))) \
397 : fontset_add ((fontset), (range), (elt), (add)))
400 fontset_add (fontset
, range
, elt
, add
)
401 Lisp_Object fontset
, range
, elt
, add
;
404 int idx
= (EQ (add
, Qappend
) ? 0 : 1);
406 args
[1 - idx
] = Fmake_vector (make_number (1), elt
);
410 int from
= XINT (XCAR (range
));
411 int to
= XINT (XCDR (range
));
415 args
[idx
] = char_table_ref_and_range (fontset
, from
, &from1
, &to1
);
418 char_table_set_range (fontset
, from
, to1
,
419 NILP (args
[idx
]) ? args
[1 - idx
]
420 : Fvconcat (2, args
));
426 args
[idx
] = FONTSET_FALLBACK (fontset
);
427 FONTSET_FALLBACK (fontset
)
428 = NILP (args
[idx
]) ? args
[1 - idx
] : Fvconcat (2, args
);
434 /* Update FONTSET_ELEMENT which has this form:
435 [CHARSET-ORDERED-LIST-TICK PREFERRED-CHARSET-ID PREFERRED-RFONT-DEF
436 RFONT-DEF0 RFONT-DEF1 ...].
437 Reorder RFONT-DEFs according to the current order of charset
438 (Vcharset_ordered_list), and update CHARSET-ORDERED-LIST-TICK to
442 reorder_font_vector (fontset_element
)
443 Lisp_Object fontset_element
;
445 Lisp_Object list
, *new_vec
;
446 Lisp_Object font_def
;
448 int *charset_id_table
;
451 ASET (fontset_element
, 0, make_number (charset_ordered_list_tick
));
452 size
= ASIZE (fontset_element
) - 3;
454 /* No need to reorder VEC. */
456 charset_id_table
= (int *) alloca (sizeof (int) * size
);
457 new_vec
= (Lisp_Object
*) alloca (sizeof (Lisp_Object
) * size
);
459 /* At first, extract ENCODING (a chaset ID) from each FONT-DEF.
460 FONT-DEF has this form:
461 [FACE-ID FONT-INDEX [ FONT-SPEC ENCODING REPERTORY ]] */
462 for (i
= 0; i
< size
; i
++)
464 font_def
= AREF (fontset_element
, i
+ 3);
465 if (! NILP (AREF (font_def
, 2)))
466 charset_id_table
[i
] = XINT (AREF (AREF (font_def
, 2), 1));
468 charset_id_table
[i
] = -1;
471 /* Then, store FONT-DEFs in NEW_VEC in the correct order. */
472 for (idx
= 0, list
= Vcharset_ordered_list
;
473 idx
< size
&& CONSP (list
); list
= XCDR (list
))
475 for (i
= 0; i
< size
; i
++)
476 if (charset_id_table
[i
] == XINT (XCAR (list
)))
477 new_vec
[idx
++] = AREF (fontset_element
, i
+ 3);
479 for (i
= 0; i
< size
; i
++)
480 if (charset_id_table
[i
] < 0)
481 new_vec
[idx
++] = AREF (fontset_element
, i
+ 3);
483 /* At last, update FONT-DEFs. */
484 for (i
= 0; i
< size
; i
++)
485 ASET (fontset_element
, i
+ 3, new_vec
[i
]);
489 /* Load a font matching the font related attributes in FACE->lface and
490 font pattern in FONT_DEF of FONTSET, and return an index of the
491 font. FONT_DEF has this form:
492 [ FONT-SPEC ENCODING REPERTORY ]
493 If REPERTORY is nil, generate a char-table representing the font
494 repertory by looking into the font itself. */
497 load_font_get_repertory (f
, face
, font_def
, fontset
)
500 Lisp_Object font_def
;
504 struct font_info
*font_info
;
507 font_name
= choose_face_font (f
, face
->lface
, AREF (font_def
, 0), NULL
);
508 charset
= XINT (AREF (font_def
, 1));
509 if (! (font_info
= fs_load_font (f
, font_name
, charset
)))
512 if (NILP (AREF (font_def
, 2))
513 && NILP (Fassq (make_number (font_info
->font_idx
),
514 FONTSET_REPERTORY (fontset
))))
516 /* We must look into the font to get the correct repertory as a
518 Lisp_Object repertory
;
520 repertory
= (*get_font_repertory_func
) (f
, font_info
);
521 FONTSET_REPERTORY (fontset
)
522 = Fcons (Fcons (make_number (font_info
->font_idx
), repertory
),
523 FONTSET_REPERTORY (fontset
));
526 return font_info
->font_idx
;
530 /* Return RFONT-DEF (vector) in the realized fontset FONTSET for the
531 character C. If the corresponding font is not yet opened, open it
532 (if FACE is not NULL) or return Qnil (if FACE is NULL).
533 If no proper font is found for C, return Qnil. */
536 fontset_font (fontset
, c
, face
, id
)
542 Lisp_Object base_fontset
, elt
, vec
;
545 FRAME_PTR f
= XFRAME (FONTSET_FRAME (fontset
));
547 base_fontset
= FONTSET_BASE (fontset
);
548 vec
= CHAR_TABLE_REF (fontset
, c
);
554 /* We have not yet decided a face for C. */
559 elt
= FONTSET_REF_AND_RANGE (base_fontset
, c
, from
, to
);
560 range
= Fcons (make_number (from
), make_number (to
));
563 /* Record that we have no font for characters of this
566 FONTSET_SET (fontset
, range
, vec
);
569 /* Build a vector [ -1 -1 nil NEW-ELT0 NEW-ELT1 NEW-ELT2 ... ],
570 where the first -1 is to force reordering of NEW-ELTn,
571 NEW-ETLn is [nil nil AREF (elt, n) nil]. */
572 #ifdef USE_FONT_BACKEND
573 if (enable_font_backend
574 && EQ (base_fontset
, Vdefault_fontset
))
575 vec
= Fmake_vector (make_number (ASIZE (elt
) + 4), make_number (-1));
577 #endif /* not USE_FONT_BACKEND */
578 vec
= Fmake_vector (make_number (ASIZE (elt
) + 3), make_number (-1));
580 for (i
= 0; i
< ASIZE (elt
); i
++)
584 #ifdef USE_FONT_BACKEND
585 if (enable_font_backend
)
586 tmp
= Fmake_vector (make_number (5), Qnil
);
588 #endif /* USE_FONT_BACKEND */
589 tmp
= Fmake_vector (make_number (4), Qnil
);
590 ASET (tmp
, 2, AREF (elt
, i
));
591 ASET (vec
, 3 + i
, tmp
);
593 #ifdef USE_FONT_BACKEND
594 if (enable_font_backend
595 && EQ (base_fontset
, Vdefault_fontset
))
597 Lisp_Object script
, font_spec
, tmp
;
599 script
= CHAR_TABLE_REF (Vchar_script_table
, c
);
601 script
= intern ("latin");
602 font_spec
= Ffont_spec (0, NULL
);
603 ASET (font_spec
, FONT_REGISTRY_INDEX
, Qiso10646_1
);
604 ASET (font_spec
, FONT_EXTRA_INDEX
,
605 Fcons (Fcons (QCscript
, script
), Qnil
));
606 tmp
= Fmake_vector (make_number (5), Qnil
);
607 ASET (tmp
, 3, font_spec
);
608 ASET (vec
, 3 + i
, tmp
);
610 #endif /* USE_FONT_BACKEND */
612 /* Then store it in the fontset. */
613 FONTSET_SET (fontset
, range
, vec
);
617 if (XINT (AREF (vec
, 0)) != charset_ordered_list_tick
)
618 /* The priority of charsets is changed after we selected a face
620 reorder_font_vector (vec
);
624 else if (id
== XFASTINT (AREF (vec
, 1)))
628 ASET (vec
, 1, make_number (id
));
629 for (i
= 3; i
< ASIZE (vec
); i
++)
630 if (id
== XFASTINT (AREF (AREF (AREF (vec
, i
), 2), 1)))
634 ASET (vec
, 2, AREF (vec
, i
));
644 /* Find the first available font in the vector of RFONT-DEF. */
645 for (; i
< ASIZE (vec
); i
++)
647 Lisp_Object font_def
;
652 /* ELT == [ FACE-ID FONT-INDEX FONT-DEF OPENED-FONT-NAME ] */
653 if (INTEGERP (AREF (elt
, 1)) && XINT (AREF (elt
, 1)) < 0)
654 /* We couldn't open this font last time. */
657 if (!face
&& NILP (AREF (elt
, 1)))
658 /* We have not yet opened the font. */
661 font_def
= AREF (elt
, 2);
662 /* FONT_DEF == [ FONT-SPEC ENCODING REPERTORY ] */
664 #ifdef USE_FONT_BACKEND
665 if (enable_font_backend
)
667 /* ELT == [ FACE-ID FONT-INDEX FONT-DEF FONT-ENTITY FONT-OBJECT ] */
668 Lisp_Object font_entity
= AREF (elt
, 3);
669 Lisp_Object font_object
= AREF (elt
, 4);
672 if (NILP (font_entity
) && ! NILP (AREF (font_def
, 0)))
674 Lisp_Object tmp
= AREF (font_def
, 0);
675 Lisp_Object spec
= Ffont_spec (0, NULL
);
678 font_merge_old_spec (tmp
, Qnil
, Qnil
, spec
);
681 Lisp_Object family
= AREF (tmp
, 0);
682 Lisp_Object registry
= AREF (tmp
, 5);;
684 font_merge_old_spec (Qnil
, family
, registry
, spec
);
686 font_entity
= font_find_for_lface (f
, face
->lface
, spec
);
687 ASET (elt
, 3, font_entity
);
689 else if (FONT_SPEC_P (font_entity
))
691 font_entity
= font_find_for_lface (f
, face
->lface
, font_entity
);
692 ASET (elt
, 3, font_entity
);
694 if (NILP (font_entity
))
696 ASET (elt
, 1, make_number (-1));
699 has_char
= font_has_char (f
, font_entity
, c
);
702 if (NILP (font_object
))
703 font_object
= font_open_for_lface (f
, face
->lface
, font_entity
);
704 if (NILP (font_object
))
706 ASET (elt
, 1, make_number (-1));
709 ASET (elt
, 1, make_number (0));
710 ASET (elt
, 4, font_object
);
712 && font_encode_char (font_object
, c
) == FONT_INVALID_CODE
)
716 #endif /* USE_FONT_BACKEND */
718 if (INTEGERP (AREF (font_def
, 2)))
720 /* The repertory is specified by charset ID. */
721 struct charset
*charset
722 = CHARSET_FROM_ID (XINT (AREF (font_def
, 2)));
724 if (! CHAR_CHARSET_P (c
, charset
))
725 /* This font can't display C. */
728 else if (CHAR_TABLE_P (AREF (font_def
, 2)))
730 /* The repertory is specified by a char table. */
731 if (NILP (CHAR_TABLE_REF (AREF (font_def
, 2), c
)))
732 /* This font can't display C. */
739 if (! INTEGERP (AREF (elt
, 1)))
741 /* We have not yet opened a font matching this spec.
742 Open the best matching font now and register the
744 struct font_info
*font_info
;
746 font_idx
= load_font_get_repertory (f
, face
, font_def
, fontset
);
747 ASET (elt
, 1, make_number (font_idx
));
749 /* This means that we couldn't find a font matching
752 font_info
= (*get_font_info_func
) (f
, font_idx
);
753 ASET (elt
, 3, build_string (font_info
->full_name
));
756 slot
= Fassq (AREF (elt
, 1), FONTSET_REPERTORY (fontset
));
757 xassert (CONSP (slot
));
758 if (NILP (CHAR_TABLE_REF (XCDR (slot
), c
)))
759 /* This font can't display C. */
763 /* Now we have decided to use this font spec to display C. */
764 if (! INTEGERP (AREF (elt
, 1)))
766 /* But not yet opened the best matching font. */
767 struct font_info
*font_info
;
769 font_idx
= load_font_get_repertory (f
, face
, font_def
, fontset
);
770 ASET (elt
, 1, make_number (font_idx
));
772 /* Can't open it. Try the other one. */
774 font_info
= (*get_font_info_func
) (f
, font_idx
);
775 ASET (elt
, 3, build_string (font_info
->full_name
));
778 /* Now we have the opened font. */
783 if (! EQ (vec
, FONTSET_FALLBACK (fontset
)))
785 vec
= FONTSET_FALLBACK (fontset
);
790 elt
= FONTSET_FALLBACK (base_fontset
);
793 vec
= Fmake_vector (make_number (ASIZE (elt
) + 3), make_number (-1));
795 for (i
= 0; i
< ASIZE (elt
); i
++)
799 #ifdef USE_FONT_BACKEND
800 if (enable_font_backend
)
801 tmp
= Fmake_vector (make_number (5), Qnil
);
803 #endif /* USE_FONT_BACKEND */
804 tmp
= Fmake_vector (make_number (4), Qnil
);
805 ASET (tmp
, 2, AREF (elt
, i
));
806 ASET (vec
, 3 + i
, tmp
);
808 FONTSET_FALLBACK (fontset
) = vec
;
811 /* Record that this fontset has no fallback fonts. */
812 FONTSET_FALLBACK (fontset
) = Qt
;
815 /* Try the default fontset. */
817 if (! EQ (base_fontset
, Vdefault_fontset
))
819 if (NILP (FONTSET_DEFAULT (fontset
)))
820 FONTSET_DEFAULT (fontset
)
821 = make_fontset (FONTSET_FRAME (fontset
), Qnil
, Vdefault_fontset
);
822 return fontset_font (FONTSET_DEFAULT (fontset
), c
, face
, id
);
828 /* Return a newly created fontset with NAME. If BASE is nil, make a
829 base fontset. Otherwise make a realized fontset whose base is
833 make_fontset (frame
, name
, base
)
834 Lisp_Object frame
, name
, base
;
837 int size
= ASIZE (Vfontset_table
);
838 int id
= next_fontset_id
;
840 /* Find a free slot in Vfontset_table. Usually, next_fontset_id is
841 the next available fontset ID. So it is expected that this loop
842 terminates quickly. In addition, as the last element of
843 Vfontset_table is always nil, we don't have to check the range of
845 while (!NILP (AREF (Vfontset_table
, id
))) id
++;
849 /* We must grow Vfontset_table. */
853 tem
= Fmake_vector (make_number (size
+ 32), Qnil
);
854 for (i
= 0; i
< size
; i
++)
855 AREF (tem
, i
) = AREF (Vfontset_table
, i
);
856 Vfontset_table
= tem
;
859 fontset
= Fmake_char_table (Qfontset
, Qnil
);
861 FONTSET_ID (fontset
) = make_number (id
);
864 FONTSET_NAME (fontset
) = name
;
868 FONTSET_NAME (fontset
) = Qnil
;
869 FONTSET_FRAME (fontset
) = frame
;
870 FONTSET_BASE (fontset
) = base
;
873 ASET (Vfontset_table
, id
, fontset
);
874 next_fontset_id
= id
+ 1;
879 /* Set the ASCII font of the default fontset to FONTNAME if that is
882 set_default_ascii_font (fontname
)
883 Lisp_Object fontname
;
885 if (! STRINGP (FONTSET_ASCII (Vdefault_fontset
)))
887 int id
= fs_query_fontset (fontname
, 2);
890 fontname
= FONTSET_ASCII (FONTSET_FROM_ID (id
));
891 FONTSET_ASCII (Vdefault_fontset
)= fontname
;
896 /********** INTERFACES TO xfaces.c, xfns.c, and dispextern.h **********/
898 /* Return the name of the fontset who has ID. */
906 fontset
= FONTSET_FROM_ID (id
);
907 return FONTSET_NAME (fontset
);
911 /* Return the ASCII font name of the fontset who has ID. */
917 Lisp_Object fontset
, elt
;
919 fontset
= FONTSET_FROM_ID (id
);
920 elt
= FONTSET_ASCII (fontset
);
921 #ifdef USE_FONT_BACKEND
924 #endif /* USE_FONT_BACKEND */
925 /* It is assured that ELT is always a string (i.e. fontname
931 /* Free fontset of FACE defined on frame F. Called from
932 free_realized_face. */
935 free_face_fontset (f
, face
)
941 fontset
= AREF (Vfontset_table
, face
->fontset
);
942 xassert (!NILP (fontset
) && ! BASE_FONTSET_P (fontset
));
943 xassert (f
== XFRAME (FONTSET_FRAME (fontset
)));
944 ASET (Vfontset_table
, face
->fontset
, Qnil
);
945 if (face
->fontset
< next_fontset_id
)
946 next_fontset_id
= face
->fontset
;
947 if (! NILP (FONTSET_DEFAULT (fontset
)))
949 int id
= XINT (FONTSET_ID (FONTSET_DEFAULT (fontset
)));
951 fontset
= AREF (Vfontset_table
, id
);
952 xassert (!NILP (fontset
) && ! BASE_FONTSET_P (fontset
));
953 xassert (f
== XFRAME (FONTSET_FRAME (fontset
)));
954 ASET (Vfontset_table
, id
, Qnil
);
955 if (id
< next_fontset_id
)
956 next_fontset_id
= face
->fontset
;
961 /* Return 1 iff FACE is suitable for displaying character C.
962 Otherwise return 0. Called from the macro FACE_SUITABLE_FOR_CHAR_P
963 when C is not an ASCII character. */
966 face_suitable_for_char_p (face
, c
)
970 Lisp_Object fontset
, rfont_def
;
972 fontset
= FONTSET_FROM_ID (face
->fontset
);
973 rfont_def
= fontset_font (fontset
, c
, NULL
, -1);
974 return (VECTORP (rfont_def
)
975 && INTEGERP (AREF (rfont_def
, 0))
976 && face
->id
== XINT (AREF (rfont_def
, 0)));
980 /* Return ID of face suitable for displaying character C on frame F.
981 FACE must be reazlied for ASCII characters in advance. Called from
982 the macro FACE_FOR_CHAR. */
985 face_for_char (f
, face
, c
, pos
, object
)
991 Lisp_Object fontset
, charset
, rfont_def
;
995 if (ASCII_CHAR_P (c
))
996 return face
->ascii_face
->id
;
998 xassert (fontset_id_valid_p (face
->fontset
));
999 fontset
= FONTSET_FROM_ID (face
->fontset
);
1000 xassert (!BASE_FONTSET_P (fontset
));
1005 charset
= Fget_char_property (make_number (pos
), Qcharset
, object
);
1008 else if (CHARSETP (charset
))
1009 id
= XINT (CHARSET_SYMBOL_ID (charset
));
1011 rfont_def
= fontset_font (fontset
, c
, face
, id
);
1012 if (VECTORP (rfont_def
))
1014 #ifdef USE_FONT_BACKEND
1015 if (enable_font_backend
1016 && NILP (AREF (rfont_def
, 0)))
1018 struct font
*font
= XSAVE_VALUE (AREF (rfont_def
, 4))->pointer
;
1020 face_id
= face_for_font (f
, font
, face
);
1021 ASET (rfont_def
, 0, make_number (face_id
));
1024 #endif /* USE_FONT_BACKEND */
1025 if (NILP (AREF (rfont_def
, 0)))
1027 /* We have not yet made a realized face that uses this font. */
1028 int font_idx
= XINT (AREF (rfont_def
, 1));
1030 face_id
= lookup_non_ascii_face (f
, font_idx
, face
);
1031 ASET (rfont_def
, 0, make_number (face_id
));
1033 return XINT (AREF (rfont_def
, 0));
1036 if (NILP (FONTSET_NOFONT_FACE (fontset
)))
1038 face_id
= lookup_non_ascii_face (f
, -1, face
);
1039 FONTSET_NOFONT_FACE (fontset
) = make_number (face_id
);
1041 return XINT (FONTSET_NOFONT_FACE (fontset
));
1045 /* Make a realized fontset for ASCII face FACE on frame F from the
1046 base fontset BASE_FONTSET_ID. If BASE_FONTSET_ID is -1, use the
1047 default fontset as the base. Value is the id of the new fontset.
1048 Called from realize_x_face. */
1051 make_fontset_for_ascii_face (f
, base_fontset_id
, face
)
1053 int base_fontset_id
;
1056 Lisp_Object base_fontset
, fontset
, frame
;
1058 XSETFRAME (frame
, f
);
1059 if (base_fontset_id
>= 0)
1061 base_fontset
= FONTSET_FROM_ID (base_fontset_id
);
1062 if (!BASE_FONTSET_P (base_fontset
))
1063 base_fontset
= FONTSET_BASE (base_fontset
);
1064 xassert (BASE_FONTSET_P (base_fontset
));
1065 if (! BASE_FONTSET_P (base_fontset
))
1069 base_fontset
= Vdefault_fontset
;
1071 fontset
= make_fontset (frame
, Qnil
, base_fontset
);
1073 Lisp_Object elt
, rfont_def
;
1075 elt
= FONTSET_REF (base_fontset
, 0);
1076 xassert (VECTORP (elt
) && ASIZE (elt
) > 0);
1077 #ifdef USE_FONT_BACKEND
1078 rfont_def
= Fmake_vector (make_number (5), Qnil
);
1079 if (enable_font_backend
&& face
->font_info
)
1081 struct font
*font
= (struct font
*) face
->font_info
;
1083 ASET (rfont_def
, 3, font
->entity
);
1084 ASET (rfont_def
, 4, font_find_object (font
));
1087 #endif /* USE_FONT_BACKEND */
1089 rfont_def
= Fmake_vector (make_number (4), Qnil
);
1090 ASET (rfont_def
, 3, build_string (face
->font_name
));
1092 ASET (rfont_def
, 0, make_number (face
->id
));
1093 ASET (rfont_def
, 1, make_number (face
->font_info_id
));
1094 ASET (rfont_def
, 2, AREF (elt
, 0));
1095 elt
= Fmake_vector (make_number (4), Qnil
);
1096 ASET (elt
, 0, make_number (charset_ordered_list_tick
));
1097 ASET (elt
, 1, make_number (charset_ascii
));
1098 ASET (elt
, 2, rfont_def
);
1099 ASET (elt
, 3, rfont_def
);
1100 char_table_set_range (fontset
, 0, 127, elt
);
1102 return XINT (FONTSET_ID (fontset
));
1106 #if defined(WINDOWSNT) && defined (_MSC_VER)
1107 #pragma optimize("", off)
1110 /* Load a font named FONTNAME on frame F. Return a pointer to the
1111 struct font_info of the loaded font. If loading fails, return
1112 NULL. CHARSET is an ID of charset to encode characters for this
1113 font. If it is -1, find one from Vfont_encoding_alist. */
1116 fs_load_font (f
, fontname
, charset
)
1121 struct font_info
*fontp
;
1122 Lisp_Object fullname
;
1125 /* No way to get fontname. */
1128 fontp
= (*load_font_func
) (f
, fontname
, 0);
1129 if (! fontp
|| fontp
->charset
>= 0)
1132 fontname
= fontp
->full_name
;
1133 fullname
= build_string (fontp
->full_name
);
1137 Lisp_Object charset_symbol
;
1139 charset_symbol
= find_font_encoding (fullname
);
1140 if (CONSP (charset_symbol
))
1141 charset_symbol
= XCAR (charset_symbol
);
1142 if (NILP (charset_symbol
))
1143 charset_symbol
= Qascii
;
1144 charset
= XINT (CHARSET_SYMBOL_ID (charset_symbol
));
1146 fontp
->charset
= charset
;
1147 fontp
->vertical_centering
= 0;
1148 fontp
->font_encoder
= NULL
;
1150 if (charset
!= charset_ascii
)
1152 fontp
->vertical_centering
1153 = (STRINGP (Vvertical_centering_font_regexp
)
1154 && (fast_string_match_ignore_case
1155 (Vvertical_centering_font_regexp
, fullname
) >= 0));
1157 if (find_ccl_program_func
)
1158 (*find_ccl_program_func
) (fontp
);
1164 #if defined(WINDOWSNT) && defined (_MSC_VER)
1165 #pragma optimize("", on)
1169 /* Return ENCODING or a cons of ENCODING and REPERTORY of the font
1170 FONTNAME. ENCODING is a charset symbol that specifies the encoding
1171 of the font. REPERTORY is a charset symbol or nil. */
1175 find_font_encoding (fontname
)
1176 Lisp_Object fontname
;
1178 Lisp_Object tail
, elt
;
1180 for (tail
= Vfont_encoding_alist
; CONSP (tail
); tail
= XCDR (tail
))
1184 && STRINGP (XCAR (elt
))
1185 && fast_string_match_ignore_case (XCAR (elt
), fontname
) >= 0
1186 && (SYMBOLP (XCDR (elt
))
1187 ? CHARSETP (XCDR (elt
))
1188 : CONSP (XCDR (elt
)) && CHARSETP (XCAR (XCDR (elt
)))))
1189 return (XCDR (elt
));
1191 /* We don't know the encoding of this font. Let's assume `ascii'. */
1196 /* Cache data used by fontset_pattern_regexp. The car part is a
1197 pattern string containing at least one wild card, the cdr part is
1198 the corresponding regular expression. */
1199 static Lisp_Object Vcached_fontset_data
;
1201 #define CACHED_FONTSET_NAME (SDATA (XCAR (Vcached_fontset_data)))
1202 #define CACHED_FONTSET_REGEX (XCDR (Vcached_fontset_data))
1204 /* If fontset name PATTERN contains any wild card, return regular
1205 expression corresponding to PATTERN. */
1208 fontset_pattern_regexp (pattern
)
1209 Lisp_Object pattern
;
1211 if (!index (SDATA (pattern
), '*')
1212 && !index (SDATA (pattern
), '?'))
1213 /* PATTERN does not contain any wild cards. */
1216 if (!CONSP (Vcached_fontset_data
)
1217 || strcmp (SDATA (pattern
), CACHED_FONTSET_NAME
))
1219 /* We must at first update the cached data. */
1220 unsigned char *regex
, *p0
, *p1
;
1221 int ndashes
= 0, nstars
= 0;
1223 for (p0
= SDATA (pattern
); *p0
; p0
++)
1227 else if (*p0
== '*')
1231 /* If PATTERN is not full XLFD we conert "*" to ".*". Otherwise
1232 we convert "*" to "[^-]*" which is much faster in regular
1233 expression matching. */
1235 p1
= regex
= (unsigned char *) alloca (SBYTES (pattern
) + 2 * nstars
+ 1);
1237 p1
= regex
= (unsigned char *) alloca (SBYTES (pattern
) + 5 * nstars
+ 1);
1240 for (p0
= SDATA (pattern
); *p0
; p0
++)
1247 *p1
++ = '[', *p1
++ = '^', *p1
++ = '-', *p1
++ = ']';
1250 else if (*p0
== '?')
1258 Vcached_fontset_data
= Fcons (build_string (SDATA (pattern
)),
1259 build_string (regex
));
1262 return CACHED_FONTSET_REGEX
;
1265 /* Return ID of the base fontset named NAME. If there's no such
1266 fontset, return -1. NAME_PATTERN specifies how to treat NAME as this:
1267 0: pattern containing '*' and '?' as wildcards
1268 1: regular expression
1269 2: literal fontset name
1273 fs_query_fontset (name
, name_pattern
)
1280 name
= Fdowncase (name
);
1281 if (name_pattern
!= 1)
1283 tem
= Frassoc (name
, Vfontset_alias_alist
);
1285 tem
= Fassoc (name
, Vfontset_alias_alist
);
1286 if (CONSP (tem
) && STRINGP (XCAR (tem
)))
1288 else if (name_pattern
== 0)
1290 tem
= fontset_pattern_regexp (name
);
1299 for (i
= 0; i
< ASIZE (Vfontset_table
); i
++)
1301 Lisp_Object fontset
, this_name
;
1303 fontset
= FONTSET_FROM_ID (i
);
1305 || !BASE_FONTSET_P (fontset
))
1308 this_name
= FONTSET_NAME (fontset
);
1309 if (name_pattern
== 1
1310 ? fast_string_match (name
, this_name
) >= 0
1311 : !strcmp (SDATA (name
), SDATA (this_name
)))
1318 DEFUN ("query-fontset", Fquery_fontset
, Squery_fontset
, 1, 2, 0,
1319 doc
: /* Return the name of a fontset that matches PATTERN.
1320 The value is nil if there is no matching fontset.
1321 PATTERN can contain `*' or `?' as a wildcard
1322 just as X font name matching algorithm allows.
1323 If REGEXPP is non-nil, PATTERN is a regular expression. */)
1325 Lisp_Object pattern
, regexpp
;
1327 Lisp_Object fontset
;
1330 (*check_window_system_func
) ();
1332 CHECK_STRING (pattern
);
1334 if (SCHARS (pattern
) == 0)
1337 id
= fs_query_fontset (pattern
, !NILP (regexpp
));
1341 fontset
= FONTSET_FROM_ID (id
);
1342 return FONTSET_NAME (fontset
);
1345 /* Return a list of base fontset names matching PATTERN on frame F. */
1348 list_fontsets (f
, pattern
, size
)
1350 Lisp_Object pattern
;
1353 Lisp_Object frame
, regexp
, val
;
1356 XSETFRAME (frame
, f
);
1358 regexp
= fontset_pattern_regexp (pattern
);
1361 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
1363 Lisp_Object fontset
, name
;
1365 fontset
= FONTSET_FROM_ID (id
);
1367 || !BASE_FONTSET_P (fontset
)
1368 || !EQ (frame
, FONTSET_FRAME (fontset
)))
1370 name
= FONTSET_NAME (fontset
);
1372 if (STRINGP (regexp
)
1373 ? (fast_string_match (regexp
, name
) < 0)
1374 : strcmp (SDATA (pattern
), SDATA (name
)))
1377 val
= Fcons (Fcopy_sequence (FONTSET_NAME (fontset
)), val
);
1384 /* Free all realized fontsets whose base fontset is BASE. */
1387 free_realized_fontsets (base
)
1393 /* For the moment, this doesn't work because free_realized_face
1394 doesn't remove FACE from a cache. Until we find a solution, we
1395 suppress this code, and simply use Fclear_face_cache even though
1396 that is not efficient. */
1398 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
1400 Lisp_Object
this = AREF (Vfontset_table
, id
);
1402 if (EQ (FONTSET_BASE (this), base
))
1406 for (tail
= FONTSET_FACE_ALIST (this); CONSP (tail
);
1409 FRAME_PTR f
= XFRAME (FONTSET_FRAME (this));
1410 int face_id
= XINT (XCDR (XCAR (tail
)));
1411 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1413 /* Face THIS itself is also freed by the following call. */
1414 free_realized_face (f
, face
);
1420 Fclear_face_cache (Qt
);
1425 /* Check validity of NAME as a fontset name and return the
1426 corresponding fontset. If not valid, signal an error.
1427 If NAME is t, return Vdefault_fontset. */
1430 check_fontset_name (name
)
1436 return Vdefault_fontset
;
1438 CHECK_STRING (name
);
1439 /* First try NAME as literal. */
1440 id
= fs_query_fontset (name
, 2);
1442 /* For backward compatibility, try again NAME as pattern. */
1443 id
= fs_query_fontset (name
, 0);
1445 error ("Fontset `%s' does not exist", SDATA (name
));
1446 return FONTSET_FROM_ID (id
);
1450 accumulate_script_ranges (arg
, range
, val
)
1451 Lisp_Object arg
, range
, val
;
1453 if (EQ (XCAR (arg
), val
))
1456 XSETCDR (arg
, Fcons (Fcons (XCAR (range
), XCDR (range
)), XCDR (arg
)));
1458 XSETCDR (arg
, Fcons (Fcons (range
, range
), XCDR (arg
)));
1463 /* Return an ASCII font name generated from fontset name NAME and
1464 ASCII font specification ASCII_SPEC. NAME is a string conforming
1465 to XLFD. ASCII_SPEC is a vector:
1466 [FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY]. */
1468 static INLINE Lisp_Object
1469 generate_ascii_font_name (name
, ascii_spec
)
1470 Lisp_Object name
, ascii_spec
;
1475 vec
= split_font_name_into_vector (name
);
1476 for (i
= FONT_SPEC_FAMILY_INDEX
; i
<= FONT_SPEC_ADSTYLE_INDEX
; i
++)
1477 if (! NILP (AREF (ascii_spec
, i
)))
1478 ASET (vec
, 1 + i
, AREF (ascii_spec
, i
));
1479 if (! NILP (AREF (ascii_spec
, FONT_SPEC_REGISTRY_INDEX
)))
1480 ASET (vec
, 12, AREF (ascii_spec
, FONT_SPEC_REGISTRY_INDEX
));
1481 return build_font_name_from_vector (vec
);
1484 /* Variables referred in set_fontset_font. They are set before
1485 map_charset_chars is called in Fset_fontset_font. */
1486 static Lisp_Object font_def_arg
, add_arg
;
1487 static int from_arg
, to_arg
;
1489 /* Callback function for map_charset_chars in Fset_fontset_font. In
1490 FONTSET, set font_def_arg in a fashion specified by add_arg for
1491 characters in RANGE while ignoring the range between from_arg and
1495 set_fontset_font (fontset
, range
)
1496 Lisp_Object fontset
, range
;
1498 if (from_arg
< to_arg
)
1500 int from
= XINT (XCAR (range
)), to
= XINT (XCDR (range
));
1502 if (from
< from_arg
)
1508 range2
= Fcons (make_number (to_arg
), XCDR (range
));
1509 FONTSET_ADD (fontset
, range
, font_def_arg
, add_arg
);
1513 range
= Fcons (XCAR (range
), make_number (from_arg
));
1515 else if (to
<= to_arg
)
1520 range
= Fcons (make_number (to_arg
), XCDR (range
));
1523 FONTSET_ADD (fontset
, range
, font_def_arg
, add_arg
);
1527 DEFUN ("set-fontset-font", Fset_fontset_font
, Sset_fontset_font
, 3, 5, 0,
1529 Modify fontset NAME to use FONT-SPEC for TARGET characters.
1531 TARGET may be a cons; (FROM . TO), where FROM and TO are characters.
1532 In that case, use FONT-SPEC for all characters in the range FROM and
1535 TARGET may be a script name symbol. In that case, use FONT-SPEC for
1536 all characters that belong to the script.
1538 TARGET may be a charset. In that case, use FONT-SPEC for all
1539 characters in the charset.
1541 TARGET may be nil. In that case, use FONT-SPEC for any characters for
1542 that no FONT-SPEC is specified.
1544 FONT-SPEC may one of these:
1545 * A cons (FAMILY . REGISTRY), where FAMILY is a font family name and
1546 REGISTRY is a font registry name. FAMILY may contains foundry
1547 name, and REGISTRY may contains encoding name.
1548 * A font name string.
1550 Optional 4th argument FRAME, if non-nil, is a frame. This argument is
1551 kept for backward compatibility and has no meaning.
1553 Optional 5th argument ADD, if non-nil, specifies how to add FONT-SPEC
1554 to the font specifications for TARGET previously set. If it is
1555 `prepend', FONT-SPEC is prepended. If it is `append', FONT-SPEC is
1556 appended. By default, FONT-SPEC overrides the previous settings. */)
1557 (name
, target
, font_spec
, frame
, add
)
1558 Lisp_Object name
, target
, font_spec
, frame
, add
;
1560 Lisp_Object fontset
;
1561 Lisp_Object font_def
, registry
, family
;
1562 Lisp_Object encoding
, repertory
;
1563 Lisp_Object range_list
;
1564 struct charset
*charset
= NULL
;
1566 fontset
= check_fontset_name (name
);
1568 /* The arg FRAME is kept for backward compatibility. We only check
1571 CHECK_LIVE_FRAME (frame
);
1573 if (VECTORP (font_spec
))
1575 /* FONT_SPEC should have this form:
1576 [ FAMILY WEIGHT SLANT WIDTH ADSTYLE REGISTRY ]
1577 This is a feature not yet documented because WEIGHT thru
1578 ADSTYLE are ignored for the moment. */
1581 if (ASIZE (font_spec
) != FONT_SPEC_MAX_INDEX
)
1582 args_out_of_range (make_number (FONT_SPEC_MAX_INDEX
),
1583 make_number (ASIZE (font_spec
)));
1585 font_spec
= Fcopy_sequence (font_spec
);
1586 for (j
= 0; j
< FONT_SPEC_MAX_INDEX
- 1; j
++)
1587 if (! NILP (AREF (font_spec
, j
)))
1589 CHECK_STRING (AREF (font_spec
, j
));
1590 ASET (font_spec
, j
, Fdowncase (AREF (font_spec
, j
)));
1592 family
= AREF (font_spec
, FONT_SPEC_FAMILY_INDEX
);
1593 /* REGISTRY should not be omitted. */
1594 CHECK_STRING (AREF (font_spec
, FONT_SPEC_REGISTRY_INDEX
));
1595 registry
= AREF (font_spec
, FONT_SPEC_REGISTRY_INDEX
);
1597 else if (CONSP (font_spec
))
1599 family
= XCAR (font_spec
);
1600 registry
= XCDR (font_spec
);
1602 if (! NILP (family
))
1604 CHECK_STRING (family
);
1605 family
= Fdowncase (family
);
1607 CHECK_STRING (registry
);
1608 registry
= Fdowncase (registry
);
1609 font_spec
= Fmake_vector (make_number (FONT_SPEC_MAX_INDEX
), Qnil
);
1610 ASET (font_spec
, FONT_SPEC_FAMILY_INDEX
, family
);
1611 ASET (font_spec
, FONT_SPEC_REGISTRY_INDEX
, registry
);
1615 CHECK_STRING (font_spec
);
1616 font_spec
= Fdowncase (font_spec
);
1619 if (STRINGP (font_spec
))
1620 encoding
= find_font_encoding (font_spec
);
1622 encoding
= find_font_encoding (concat2 (family
, registry
));
1623 if (NILP (encoding
))
1626 if (SYMBOLP (encoding
))
1628 CHECK_CHARSET (encoding
);
1629 encoding
= repertory
= CHARSET_SYMBOL_ID (encoding
);
1633 repertory
= XCDR (encoding
);
1634 encoding
= XCAR (encoding
);
1635 CHECK_CHARSET (encoding
);
1636 encoding
= CHARSET_SYMBOL_ID (encoding
);
1637 if (! NILP (repertory
) && SYMBOLP (repertory
))
1639 CHECK_CHARSET (repertory
);
1640 repertory
= CHARSET_SYMBOL_ID (repertory
);
1643 font_def
= Fmake_vector (make_number (3), font_spec
);
1644 ASET (font_def
, 1, encoding
);
1645 ASET (font_def
, 2, repertory
);
1647 if (CHARACTERP (target
))
1648 range_list
= Fcons (Fcons (target
, target
), Qnil
);
1649 else if (CONSP (target
))
1651 Lisp_Object from
, to
;
1653 from
= Fcar (target
);
1655 CHECK_CHARACTER (from
);
1656 CHECK_CHARACTER (to
);
1657 range_list
= Fcons (target
, Qnil
);
1659 else if (SYMBOLP (target
) && !NILP (target
))
1661 Lisp_Object script_list
;
1665 script_list
= XCHAR_TABLE (Vchar_script_table
)->extras
[0];
1666 if (! NILP (Fmemq (target
, script_list
)))
1668 val
= Fcons (target
, Qnil
);
1669 map_char_table (accumulate_script_ranges
, Qnil
, Vchar_script_table
,
1671 range_list
= XCDR (val
);
1673 if (CHARSETP (target
))
1675 if (EQ (target
, Qascii
))
1677 if (VECTORP (font_spec
))
1678 font_spec
= generate_ascii_font_name (FONTSET_NAME (fontset
),
1680 FONTSET_ASCII (fontset
) = font_spec
;
1681 range_list
= Fcons (Fcons (make_number (0), make_number (127)),
1686 CHECK_CHARSET_GET_CHARSET (target
, charset
);
1689 else if (NILP (range_list
))
1690 error ("Invalid script or charset name: %s",
1691 SDATA (SYMBOL_NAME (target
)));
1693 else if (NILP (target
))
1694 range_list
= Fcons (Qnil
, Qnil
);
1696 error ("Invalid target for setting a font");
1701 font_def_arg
= font_def
;
1703 if (NILP (range_list
))
1704 from_arg
= to_arg
= 0;
1706 from_arg
= XINT (XCAR (XCAR (range_list
))),
1707 to_arg
= XINT (XCDR (XCAR (range_list
)));
1709 map_charset_chars (set_fontset_font
, Qnil
, fontset
, charset
,
1710 CHARSET_MIN_CODE (charset
),
1711 CHARSET_MAX_CODE (charset
));
1713 for (; CONSP (range_list
); range_list
= XCDR (range_list
))
1714 FONTSET_ADD (fontset
, XCAR (range_list
), font_def
, add
);
1716 /* Free all realized fontsets whose base is FONTSET. This way, the
1717 specified character(s) are surely redisplayed by a correct
1719 free_realized_fontsets (fontset
);
1725 DEFUN ("new-fontset", Fnew_fontset
, Snew_fontset
, 2, 2, 0,
1726 doc
: /* Create a new fontset NAME from font information in FONTLIST.
1728 FONTLIST is an alist of scripts vs the corresponding font specification list.
1729 Each element of FONTLIST has the form (SCRIPT FONT-SPEC ...), where a
1730 character of SCRIPT is displayed by a font that matches one of
1733 SCRIPT is a symbol that appears in the first extra slot of the
1734 char-table `char-script-table'.
1736 FONT-SPEC is a vector, a cons, or a string. See the documentation of
1737 `set-fontset-font' for the meaning. */)
1739 Lisp_Object name
, fontlist
;
1741 Lisp_Object fontset
;
1745 CHECK_STRING (name
);
1746 CHECK_LIST (fontlist
);
1748 id
= fs_query_fontset (name
, 0);
1751 name
= Fdowncase (name
);
1752 val
= split_font_name_into_vector (name
);
1753 if (NILP (val
) || NILP (AREF (val
, 12)) || NILP (AREF (val
, 13)))
1754 error ("Fontset name must be in XLFD format");
1755 if (strcmp (SDATA (AREF (val
, 12)), "fontset"))
1756 error ("Registry field of fontset name must be \"fontset\"");
1757 Vfontset_alias_alist
1758 = Fcons (Fcons (name
,
1759 concat2 (concat2 (AREF (val
, 12), build_string ("-")),
1761 Vfontset_alias_alist
);
1762 ASET (val
, 12, build_string ("iso8859-1"));
1763 fontset
= make_fontset (Qnil
, name
, Qnil
);
1764 FONTSET_ASCII (fontset
) = build_font_name_from_vector (val
);
1768 fontset
= FONTSET_FROM_ID (id
);;
1769 free_realized_fontsets (fontset
);
1770 Fset_char_table_range (fontset
, Qt
, Qnil
);
1773 for (; ! NILP (fontlist
); fontlist
= Fcdr (fontlist
))
1775 Lisp_Object elt
, script
;
1777 elt
= Fcar (fontlist
);
1778 script
= Fcar (elt
);
1780 if (CONSP (elt
) && (NILP (XCDR (elt
)) || CONSP (XCDR (elt
))))
1781 for (; CONSP (elt
); elt
= XCDR (elt
))
1782 Fset_fontset_font (name
, script
, XCAR (elt
), Qnil
, Qappend
);
1784 Fset_fontset_font (name
, script
, elt
, Qnil
, Qappend
);
1790 /* Alist of automatically created fontsets. Each element is a cons
1791 (FONTNAME . FONTSET-ID). */
1792 static Lisp_Object auto_fontset_alist
;
1795 new_fontset_from_font_name (Lisp_Object fontname
)
1802 fontname
= Fdowncase (fontname
);
1803 val
= Fassoc (fontname
, auto_fontset_alist
);
1805 return XINT (XCDR (val
));
1807 vec
= split_font_name_into_vector (fontname
);
1809 vec
= Fmake_vector (make_number (14), build_string (""));
1810 ASET (vec
, 12, build_string ("fontset"));
1811 if (NILP (auto_fontset_alist
))
1813 ASET (vec
, 13, build_string ("startup"));
1814 name
= build_font_name_from_vector (vec
);
1819 int len
= XINT (Flength (auto_fontset_alist
));
1821 sprintf (temp
, "auto%d", len
);
1822 ASET (vec
, 13, build_string (temp
));
1823 name
= build_font_name_from_vector (vec
);
1825 name
= Fnew_fontset (name
, list2 (list2 (Qascii
, fontname
),
1826 list2 (Fcons (make_number (0),
1827 make_number (MAX_CHAR
)),
1829 id
= fs_query_fontset (name
, 0);
1831 = Fcons (Fcons (fontname
, make_number (id
)), auto_fontset_alist
);
1835 #ifdef USE_FONT_BACKEND
1837 new_fontset_from_font (font_object
)
1838 Lisp_Object font_object
;
1840 Lisp_Object font_name
= font_get_name (font_object
);
1841 Lisp_Object font_spec
= font_get_spec (font_object
);
1842 Lisp_Object short_name
, name
, fontset
;
1844 if (NILP (auto_fontset_alist
))
1845 short_name
= build_string ("fontset-startup");
1849 int len
= XINT (Flength (auto_fontset_alist
));
1851 sprintf (temp
, "fontset-auto%d", len
);
1852 short_name
= build_string (temp
);
1854 ASET (font_spec
, FONT_REGISTRY_INDEX
, short_name
);
1855 name
= Ffont_xlfd_name (font_spec
);
1860 for (i
= 0; i
< FONT_SIZE_INDEX
; i
++)
1861 if ((i
!= FONT_FAMILY_INDEX
) && (i
!= FONT_REGISTRY_INDEX
))
1862 ASET (font_spec
, i
, Qnil
);
1863 name
= Ffont_xlfd_name (font_spec
);
1867 fontset
= make_fontset (Qnil
, name
, Qnil
);
1868 FONTSET_ASCII (fontset
) = font_name
;
1869 return XINT (FONTSET_ID (fontset
));
1873 fontset_ascii_font (f
, id
)
1877 Lisp_Object fontset
= FONTSET_FROM_ID (id
);
1878 Lisp_Object ascii_slot
= FONTSET_ASCII (fontset
);
1879 Lisp_Object val
, font_object
;
1881 if (CONSP (ascii_slot
))
1883 Lisp_Object ascii_font_name
= XCAR (ascii_slot
);
1886 for (val
= XCDR (ascii_slot
); ! NILP (val
); val
= XCDR (val
))
1888 Lisp_Object frame
= font_get_frame (XCAR (val
));
1890 if (NILP (frame
) || XFRAME (frame
) == f
)
1892 font_object
= XCAR (val
);
1893 if (XSAVE_VALUE (font_object
)->integer
== 0)
1895 font_object
= font_open_by_name (f
, SDATA (ascii_font_name
));
1896 XSETCAR (val
, font_object
);
1901 if (NILP (font_object
))
1903 font_object
= font_open_by_name (f
, SDATA (ascii_font_name
));
1904 XSETCDR (ascii_slot
, Fcons (font_object
, XCDR (ascii_slot
)));
1909 font_object
= font_open_by_name (f
, SDATA (ascii_slot
));
1910 FONTSET_ASCII (fontset
) = Fcons (ascii_slot
, Fcons (font_object
, Qnil
));
1912 if (NILP (font_object
))
1914 return XSAVE_VALUE (font_object
)->pointer
;
1917 #endif /* USE_FONT_BACKEND */
1919 DEFUN ("font-info", Ffont_info
, Sfont_info
, 1, 2, 0,
1920 doc
: /* Return information about a font named NAME on frame FRAME.
1921 If FRAME is omitted or nil, use the selected frame.
1922 The returned value is a vector of OPENED-NAME, FULL-NAME, CHARSET, SIZE,
1923 HEIGHT, BASELINE-OFFSET, RELATIVE-COMPOSE, and DEFAULT-ASCENT,
1925 OPENED-NAME is the name used for opening the font,
1926 FULL-NAME is the full name of the font,
1927 SIZE is the maximum bound width of the font,
1928 HEIGHT is the height of the font,
1929 BASELINE-OFFSET is the upward offset pixels from ASCII baseline,
1930 RELATIVE-COMPOSE and DEFAULT-ASCENT are the numbers controlling
1931 how to compose characters.
1932 If the named font is not yet loaded, return nil. */)
1934 Lisp_Object name
, frame
;
1937 struct font_info
*fontp
;
1939 Lisp_Object font_object
;
1941 (*check_window_system_func
) ();
1943 CHECK_STRING (name
);
1944 name
= Fdowncase (name
);
1946 frame
= selected_frame
;
1947 CHECK_LIVE_FRAME (frame
);
1950 if (!query_font_func
)
1951 error ("Font query function is not supported");
1953 #ifdef USE_FONT_BACKEND
1954 if (enable_font_backend
)
1956 font_object
= font_open_by_name (f
, SDATA (name
));
1957 if (NILP (font_object
))
1960 fontp
= (struct font_info
*) XSAVE_VALUE (font_object
)->pointer
;
1963 #endif /* USE_FONT_BACKEND */
1964 fontp
= (*query_font_func
) (f
, SDATA (name
));
1968 info
= Fmake_vector (make_number (7), Qnil
);
1970 XVECTOR (info
)->contents
[0] = build_string (fontp
->name
);
1971 XVECTOR (info
)->contents
[1] = build_string (fontp
->full_name
);
1972 XVECTOR (info
)->contents
[2] = make_number (fontp
->size
);
1973 XVECTOR (info
)->contents
[3] = make_number (fontp
->height
);
1974 XVECTOR (info
)->contents
[4] = make_number (fontp
->baseline_offset
);
1975 XVECTOR (info
)->contents
[5] = make_number (fontp
->relative_compose
);
1976 XVECTOR (info
)->contents
[6] = make_number (fontp
->default_ascent
);
1978 #ifdef USE_FONT_BACKEND
1979 if (! NILP (font_object
))
1980 font_close_object (f
, font_object
);
1981 #endif /* USE_FONT_BACKEND */
1986 /* Return a cons (FONT-NAME . GLYPH-CODE).
1987 FONT-NAME is the font name for the character at POSITION in the current
1988 buffer. This is computed from all the text properties and overlays
1989 that apply to POSITION. POSTION may be nil, in which case,
1990 FONT-NAME is the font name for display the character CH with the
1993 GLYPH-CODE is the glyph code in the font to use for the character.
1995 If the 2nd optional arg CH is non-nil, it is a character to check
1996 the font instead of the character at POSITION.
1998 It returns nil in the following cases:
2000 (1) The window system doesn't have a font for the character (thus
2001 it is displayed by an empty box).
2003 (2) The character code is invalid.
2005 (3) If POSITION is not nil, and the current buffer is not displayed
2008 In addition, the returned font name may not take into account of
2009 such redisplay engine hooks as what used in jit-lock-mode if
2010 POSITION is currently not visible. */
2013 DEFUN ("internal-char-font", Finternal_char_font
, Sinternal_char_font
, 1, 2, 0,
2014 doc
: /* For internal use only. */)
2016 Lisp_Object position
, ch
;
2018 int pos
, pos_byte
, dummy
;
2023 Lisp_Object charset
, rfont_def
;
2026 if (NILP (position
))
2028 CHECK_CHARACTER (ch
);
2030 f
= XFRAME (selected_frame
);
2031 face_id
= DEFAULT_FACE_ID
;
2039 CHECK_NUMBER_COERCE_MARKER (position
);
2040 pos
= XINT (position
);
2041 if (pos
< BEGV
|| pos
>= ZV
)
2042 args_out_of_range_3 (position
, make_number (BEGV
), make_number (ZV
));
2043 pos_byte
= CHAR_TO_BYTE (pos
);
2045 c
= FETCH_CHAR (pos_byte
);
2051 window
= Fget_buffer_window (Fcurrent_buffer (), Qnil
);
2054 w
= XWINDOW (window
);
2055 f
= XFRAME (w
->frame
);
2056 face_id
= face_at_buffer_position (w
, pos
, -1, -1, &dummy
, pos
+ 100, 0);
2058 if (! CHAR_VALID_P (c
, 0))
2060 face_id
= FACE_FOR_CHAR (f
, FACE_FROM_ID (f
, face_id
), c
, pos
, Qnil
);
2061 face
= FACE_FROM_ID (f
, face_id
);
2062 charset
= Fget_char_property (position
, Qcharset
, Qnil
);
2063 if (CHARSETP (charset
))
2064 id
= XINT (CHARSET_SYMBOL_ID (charset
));
2067 #ifdef USE_FONT_BACKEND
2068 if (enable_font_backend
)
2070 rfont_def
= fontset_font (FONTSET_FROM_ID (face
->fontset
), c
, face
, id
);
2071 if (VECTORP (rfont_def
) && ! NILP (AREF (rfont_def
, 4)))
2073 Lisp_Object font_object
= AREF (rfont_def
, 4);
2074 struct font
*font
= XSAVE_VALUE (font_object
)->pointer
;
2075 unsigned code
= font
->driver
->encode_char (font
, c
);
2076 Lisp_Object fontname
= font_get_name (font_object
);
2078 if (code
== FONT_INVALID_CODE
)
2079 return Fcons (fontname
, Qnil
);
2080 if (code
<= MOST_POSITIVE_FIXNUM
)
2081 return Fcons (fontname
, make_number (code
));
2082 return Fcons (fontname
, Fcons (make_number (code
>> 16),
2083 make_number (code
& 0xFFFF)));
2087 #endif /* USE_FONT_BACKEND */
2088 rfont_def
= fontset_font (FONTSET_FROM_ID (face
->fontset
), c
, face
, id
);
2089 if (VECTORP (rfont_def
) && STRINGP (AREF (rfont_def
, 3)))
2091 Lisp_Object font_def
;
2092 struct font_info
*fontp
;
2093 struct charset
*charset
;
2097 font_def
= AREF (rfont_def
, 2);
2098 charset
= CHARSET_FROM_ID (XINT (AREF (font_def
, 1)));
2099 code
= ENCODE_CHAR (charset
, c
);
2100 if (code
== CHARSET_INVALID_CODE (charset
))
2101 return (Fcons (AREF (rfont_def
, 3), Qnil
));
2102 STORE_XCHAR2B (&char2b
, ((code
>> 8) & 0xFF), (code
& 0xFF));
2103 fontp
= (*get_font_info_func
) (f
, XINT (AREF (rfont_def
, 1)));
2104 rif
->encode_char (c
, &char2b
, fontp
, charset
, NULL
);
2105 code
= (XCHAR2B_BYTE1 (&char2b
) << 8) | XCHAR2B_BYTE2 (&char2b
);
2106 return (Fcons (AREF (rfont_def
, 3), make_number (code
)));
2112 DEFUN ("fontset-info", Ffontset_info
, Sfontset_info
, 1, 2, 0,
2113 doc
: /* Return information about a fontset FONTSET on frame FRAME.
2114 The value is a char-table of which elements has this form.
2116 ((FONT-PATTERN OPENED-FONT ...) ...)
2118 FONT-PATTERN is a vector:
2120 [ FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY ]
2122 or a string of font name pattern.
2124 OPENED-FONT is a name of a font actually opened.
2126 The char-table has one extra slot. The value is a char-table
2127 containing the information about the derived fonts from the default
2128 fontset. The format is the same as abobe. */)
2130 Lisp_Object fontset
, frame
;
2133 Lisp_Object
*realized
[2], fontsets
[2], tables
[2];
2134 Lisp_Object val
, elt
;
2137 (*check_window_system_func
) ();
2139 fontset
= check_fontset_name (fontset
);
2142 frame
= selected_frame
;
2143 CHECK_LIVE_FRAME (frame
);
2146 /* Recode fontsets realized on FRAME from the base fontset FONTSET
2147 in the table `realized'. */
2148 realized
[0] = (Lisp_Object
*) alloca (sizeof (Lisp_Object
)
2149 * ASIZE (Vfontset_table
));
2150 for (i
= j
= 0; i
< ASIZE (Vfontset_table
); i
++)
2152 elt
= FONTSET_FROM_ID (i
);
2154 && EQ (FONTSET_BASE (elt
), fontset
)
2155 && EQ (FONTSET_FRAME (elt
), frame
))
2156 realized
[0][j
++] = elt
;
2158 realized
[0][j
] = Qnil
;
2160 realized
[1] = (Lisp_Object
*) alloca (sizeof (Lisp_Object
)
2161 * ASIZE (Vfontset_table
));
2162 for (i
= j
= 0; ! NILP (realized
[0][i
]); i
++)
2164 elt
= FONTSET_DEFAULT (realized
[0][i
]);
2166 realized
[1][j
++] = elt
;
2168 realized
[1][j
] = Qnil
;
2170 tables
[0] = Fmake_char_table (Qfontset_info
, Qnil
);
2171 tables
[1] = Fmake_char_table (Qnil
, Qnil
);
2172 XCHAR_TABLE (tables
[0])->extras
[0] = tables
[1];
2173 fontsets
[0] = fontset
;
2174 fontsets
[1] = Vdefault_fontset
;
2176 /* Accumulate information of the fontset in TABLE. The format of
2177 each element is ((FONT-SPEC OPENED-FONT ...) ...). */
2178 for (k
= 0; k
<= 1; k
++)
2180 for (c
= 0; c
<= MAX_CHAR
; )
2184 if (c
<= MAX_5_BYTE_CHAR
)
2186 val
= char_table_ref_and_range (fontsets
[k
], c
, &from
, &to
);
2187 if (to
> MAX_5_BYTE_CHAR
)
2188 to
= MAX_5_BYTE_CHAR
;
2192 val
= FONTSET_FALLBACK (fontsets
[k
]);
2199 /* At first, set ALIST to ((FONT-SPEC) ...). */
2200 for (alist
= Qnil
, i
= 0; i
< ASIZE (val
); i
++)
2201 alist
= Fcons (Fcons (AREF (AREF (val
, i
), 0), Qnil
), alist
);
2202 alist
= Fnreverse (alist
);
2204 /* Then store opend font names to cdr of each elements. */
2205 for (i
= 0; ! NILP (realized
[k
][i
]); i
++)
2207 if (c
<= MAX_5_BYTE_CHAR
)
2208 val
= FONTSET_REF (realized
[k
][i
], c
);
2210 val
= FONTSET_FALLBACK (realized
[k
][i
]);
2211 if (! VECTORP (val
))
2213 /* VAL is [int int ?
2214 [FACE-ID FONT-INDEX FONT-DEF FONT-NAME] ...].
2215 If a font of an element is already opened,
2216 FONT-NAME is the name of a opened font. */
2217 for (j
= 3; j
< ASIZE (val
); j
++)
2218 if (STRINGP (AREF (AREF (val
, j
), 3)))
2220 Lisp_Object font_idx
;
2222 font_idx
= AREF (AREF (val
, j
), 1);
2223 elt
= Fassq (AREF (AREF (AREF (val
, j
), 2), 0), alist
);
2225 && NILP (Fmemq (font_idx
, XCDR(elt
))))
2226 nconc2 (elt
, Fcons (font_idx
, Qnil
));
2229 for (val
= alist
; CONSP (val
); val
= XCDR (val
))
2230 for (elt
= XCDR (XCAR (val
)); CONSP (elt
); elt
= XCDR (elt
))
2232 struct font_info
*font_info
2233 = (*get_font_info_func
) (f
, XINT (XCAR (elt
)));
2234 XSETCAR (elt
, build_string (font_info
->full_name
));
2237 /* Store ALIST in TBL for characters C..TO. */
2238 if (c
<= MAX_5_BYTE_CHAR
)
2239 char_table_set_range (tables
[k
], c
, to
, alist
);
2241 XCHAR_TABLE (tables
[k
])->defalt
= alist
;
2251 DEFUN ("fontset-font", Ffontset_font
, Sfontset_font
, 2, 3, 0,
2252 doc
: /* Return a font name pattern for character CH in fontset NAME.
2253 If NAME is t, find a pattern in the default fontset.
2255 The value has the form (FAMILY . REGISTRY), where FAMILY is a font
2256 family name and REGISTRY is a font registry name. This is actually
2257 the first font name pattern for CH in the fontset or in the default
2260 If the 2nd optional arg ALL is non-nil, return a list of all font name
2263 Lisp_Object name
, ch
, all
;
2266 Lisp_Object fontset
, elt
, list
, repertory
, val
;
2269 fontset
= check_fontset_name (name
);
2271 CHECK_CHARACTER (ch
);
2276 for (i
= 0, elt
= FONTSET_REF (fontset
, c
); i
< 2;
2277 i
++, elt
= FONTSET_FALLBACK (fontset
))
2279 for (j
= 0; j
< ASIZE (elt
); j
++)
2281 val
= AREF (elt
, j
);
2282 repertory
= AREF (val
, 1);
2283 if (INTEGERP (repertory
))
2285 struct charset
*charset
= CHARSET_FROM_ID (XINT (repertory
));
2287 if (! CHAR_CHARSET_P (c
, charset
))
2290 else if (CHAR_TABLE_P (repertory
))
2292 if (NILP (CHAR_TABLE_REF (repertory
, c
)))
2295 val
= AREF (val
, 0);
2296 val
= Fcons (AREF (val
, 0), AREF (val
, 5));
2299 list
= Fcons (val
, list
);
2301 if (EQ (fontset
, Vdefault_fontset
))
2303 fontset
= Vdefault_fontset
;
2305 return (Fnreverse (list
));
2308 DEFUN ("fontset-list", Ffontset_list
, Sfontset_list
, 0, 0, 0,
2309 doc
: /* Return a list of all defined fontset names. */)
2312 Lisp_Object fontset
, list
;
2316 for (i
= 0; i
< ASIZE (Vfontset_table
); i
++)
2318 fontset
= FONTSET_FROM_ID (i
);
2320 && BASE_FONTSET_P (fontset
))
2321 list
= Fcons (FONTSET_NAME (fontset
), list
);
2328 #ifdef FONTSET_DEBUG
2331 dump_fontset (fontset
)
2332 Lisp_Object fontset
;
2336 vec
= Fmake_vector (make_number (3), Qnil
);
2337 ASET (vec
, 0, FONTSET_ID (fontset
));
2339 if (BASE_FONTSET_P (fontset
))
2341 ASET (vec
, 1, FONTSET_NAME (fontset
));
2347 frame
= FONTSET_FRAME (fontset
);
2350 FRAME_PTR f
= XFRAME (frame
);
2352 if (FRAME_LIVE_P (f
))
2353 ASET (vec
, 1, f
->name
);
2357 if (!NILP (FONTSET_DEFAULT (fontset
)))
2358 ASET (vec
, 2, FONTSET_ID (FONTSET_DEFAULT (fontset
)));
2363 DEFUN ("fontset-list-all", Ffontset_list_all
, Sfontset_list_all
, 0, 0, 0,
2364 doc
: /* Return a brief summary of all fontsets for debug use. */)
2370 for (i
= 0, val
= Qnil
; i
< ASIZE (Vfontset_table
); i
++)
2371 if (! NILP (AREF (Vfontset_table
, i
)))
2372 val
= Fcons (dump_fontset (AREF (Vfontset_table
, i
)), val
);
2373 return (Fnreverse (val
));
2375 #endif /* FONTSET_DEBUG */
2380 if (!load_font_func
)
2381 /* Window system initializer should have set proper functions. */
2384 DEFSYM (Qfontset
, "fontset");
2385 Fput (Qfontset
, Qchar_table_extra_slots
, make_number (9));
2386 DEFSYM (Qfontset_info
, "fontset-info");
2387 Fput (Qfontset_info
, Qchar_table_extra_slots
, make_number (1));
2389 DEFSYM (Qprepend
, "prepend");
2390 DEFSYM (Qappend
, "append");
2392 Vcached_fontset_data
= Qnil
;
2393 staticpro (&Vcached_fontset_data
);
2395 Vfontset_table
= Fmake_vector (make_number (32), Qnil
);
2396 staticpro (&Vfontset_table
);
2398 Vdefault_fontset
= Fmake_char_table (Qfontset
, Qnil
);
2399 staticpro (&Vdefault_fontset
);
2400 FONTSET_ID (Vdefault_fontset
) = make_number (0);
2401 FONTSET_NAME (Vdefault_fontset
)
2402 = build_string ("-*-*-*-*-*-*-*-*-*-*-*-*-fontset-default");
2403 AREF (Vfontset_table
, 0) = Vdefault_fontset
;
2404 next_fontset_id
= 1;
2406 auto_fontset_alist
= Qnil
;
2407 staticpro (&auto_fontset_alist
);
2409 DEFVAR_LISP ("font-encoding-alist", &Vfont_encoding_alist
,
2411 Alist of fontname patterns vs the corresponding encoding and repertory info.
2412 Each element looks like (REGEXP . (ENCODING . REPERTORY)),
2413 where ENCODING is a charset or a char-table,
2414 and REPERTORY is a charset, a char-table, or nil.
2416 ENCODING is for converting a character to a glyph code of the font.
2417 If ENCODING is a charset, encoding a character by the charset gives
2418 the corresponding glyph code. If ENCODING is a char-table, looking up
2419 the table by a character gives the corresponding glyph code.
2421 REPERTORY specifies a repertory of characters supported by the font.
2422 If REPERTORY is a charset, all characters beloging to the charset are
2423 supported. If REPERTORY is a char-table, all characters who have a
2424 non-nil value in the table are supported. It REPERTORY is nil, Emacs
2425 gets the repertory information by an opened font and ENCODING. */);
2426 Vfont_encoding_alist
= Qnil
;
2428 DEFVAR_LISP ("use-default-ascent", &Vuse_default_ascent
,
2430 Char table of characters whose ascent values should be ignored.
2431 If an entry for a character is non-nil, the ascent value of the glyph
2432 is assumed to be what specified by _MULE_DEFAULT_ASCENT property of a font.
2434 This affects how a composite character which contains
2435 such a character is displayed on screen. */);
2436 Vuse_default_ascent
= Qnil
;
2438 DEFVAR_LISP ("ignore-relative-composition", &Vignore_relative_composition
,
2440 Char table of characters which is not composed relatively.
2441 If an entry for a character is non-nil, a composition sequence
2442 which contains that character is displayed so that
2443 the glyph of that character is put without considering
2444 an ascent and descent value of a previous character. */);
2445 Vignore_relative_composition
= Qnil
;
2447 DEFVAR_LISP ("alternate-fontname-alist", &Valternate_fontname_alist
,
2448 doc
: /* Alist of fontname vs list of the alternate fontnames.
2449 When a specified font name is not found, the corresponding
2450 alternate fontnames (if any) are tried instead. */);
2451 Valternate_fontname_alist
= Qnil
;
2453 DEFVAR_LISP ("fontset-alias-alist", &Vfontset_alias_alist
,
2454 doc
: /* Alist of fontset names vs the aliases. */);
2455 Vfontset_alias_alist
= Fcons (Fcons (FONTSET_NAME (Vdefault_fontset
),
2456 build_string ("fontset-default")),
2459 DEFVAR_LISP ("vertical-centering-font-regexp",
2460 &Vvertical_centering_font_regexp
,
2461 doc
: /* *Regexp matching font names that require vertical centering on display.
2462 When a character is displayed with such fonts, the character is displayed
2463 at the vertical center of lines. */);
2464 Vvertical_centering_font_regexp
= Qnil
;
2466 DEFVAR_LISP ("otf-script-alist", &Votf_script_alist
,
2467 doc
: /* Alist of OpenType script tags vs the corresponding script names. */);
2468 Votf_script_alist
= Qnil
;
2470 defsubr (&Squery_fontset
);
2471 defsubr (&Snew_fontset
);
2472 defsubr (&Sset_fontset_font
);
2473 defsubr (&Sfont_info
);
2474 defsubr (&Sinternal_char_font
);
2475 defsubr (&Sfontset_info
);
2476 defsubr (&Sfontset_font
);
2477 defsubr (&Sfontset_list
);
2478 #ifdef FONTSET_DEBUG
2479 defsubr (&Sfontset_list_all
);
2483 /* arch-tag: ea861585-2f5f-4e5b-9849-d04a9c3a3537
2484 (do not change this comment) */