2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
3 Free Software Foundation, Inc.
4 Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
6 National Institute of Advanced Industrial Science and Technology (AIST)
7 Registration Number H14PRO021
8 Copyright (C) 2003, 2006
9 National Institute of Advanced Industrial Science and Technology (AIST)
10 Registration Number H13PRO009
12 This file is part of GNU Emacs.
14 GNU Emacs is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2, or (at your option)
19 GNU Emacs is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with GNU Emacs; see the file COPYING. If not, write to
26 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 Boston, MA 02110-1301, USA. */
29 /* #define FONTSET_DEBUG */
38 #include "blockinput.h"
40 #include "character.h"
45 #include "dispextern.h"
46 #include "intervals.h"
59 #ifdef USE_FONT_BACKEND
61 #endif /* USE_FONT_BACKEND */
65 #define xassert(X) do {if (!(X)) abort ();} while (0)
68 #else /* not FONTSET_DEBUG */
69 #define xassert(X) (void) 0
70 #endif /* not FONTSET_DEBUG */
72 EXFUN (Fclear_face_cache
, 1);
76 A fontset is a collection of font related information to give
77 similar appearance (style, etc) of characters. A fontset has two
78 roles. One is to use for the frame parameter `font' as if it is an
79 ASCII font. In that case, Emacs uses the font specified for
80 `ascii' script for the frame's default font.
82 Another role, the more important one, is to provide information
83 about which font to use for each non-ASCII character.
85 There are two kinds of fontsets; base and realized. A base fontset
86 is created by `new-fontset' from Emacs Lisp explicitly. A realized
87 fontset is created implicitly when a face is realized for ASCII
88 characters. A face is also realized for non-ASCII characters based
89 on an ASCII face. All of non-ASCII faces based on the same ASCII
90 face share the same realized fontset.
92 A fontset object is implemented by a char-table whose default value
93 and parent are always nil.
95 An element of a base fontset is a vector of FONT-DEFs which itself
96 is a vector [ FONT-SPEC ENCODING REPERTORY ].
99 [ FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY ]
102 where FAMILY, WEIGHT, SLANT, SWIDTH, ADSTYLE, REGISTRY, and
103 FONT-NAME are strings.
105 Note: Currently WEIGHT through ADSTYLE are ignored.
107 ENCODING is a charset ID that can convert characters to glyph codes
108 of the corresponding font.
110 REPERTORY is a charset ID, a char-table, or nil. If REPERTORY is a
111 charset ID, the repertory of the charset exactly matches with that
112 of the font. If REPERTORY is a char-table, all characters who have
113 a non-nil value in the table are supported. If REPERTORY is nil,
114 we consult with the font itself to get the repertory.
116 ENCODING and REPERTORY are extracted from the variable
117 Vfont_encoding_alist by using a font name generated from FONT-SPEC
118 (if it is a vector) or FONT-NAME as a matching target.
121 An element of a realized fontset is nil or t, or has this form:
123 [CHARSET-ORDERED-LIST-TICK PREFERRED-CHARSET-ID
124 PREFERRED-RFONT-DEF RFONT-DEF0 RFONT-DEF1 ...].
126 RFONT-DEFn (i.e. Realized FONT-DEF) has this form:
128 [ FACE-ID FONT-INDEX FONT-DEF OPENED-FONT-NAME ]
130 RFONT-DEFn is automatically reordered by the current charset
133 The value nil means that we have not yet generated the above vector
134 from the base of the fontset.
136 The value t means that no font is available for the corresponding
140 A fontset has 9 extra slots.
142 The 1st slot: the ID number of the fontset
145 base: the name of the fontset
150 realized: the base fontset
154 realized: the frame that the fontset belongs to
157 base: the font name for ASCII characters
162 realized: the ID number of a face to use for characters that
163 has no font in a realized fontset.
167 realized: Alist of font index vs the corresponding repertory
172 realized: If the base is not the default fontset, a fontset
173 realized from the default fontset, else nil.
176 base: Same as element value (but for fallback fonts).
179 All fontsets are recorded in the vector Vfontset_table.
184 There's a special base fontset named `default fontset' which
185 defines the default font specifications. When a base fontset
186 doesn't specify a font for a specific character, the corresponding
187 value in the default fontset is used.
189 The parent of a realized fontset created for such a face that has
190 no fontset is the default fontset.
193 These structures are hidden from the other codes than this file.
194 The other codes handle fontsets only by their ID numbers. They
195 usually use the variable name `fontset' for IDs. But, in this
196 file, we always use varialbe name `id' for IDs, and name `fontset'
197 for an actual fontset object, i.e., char-table.
201 /********** VARIABLES and FUNCTION PROTOTYPES **********/
203 extern Lisp_Object Qfont
;
204 static Lisp_Object Qfontset
;
205 static Lisp_Object Qfontset_info
;
206 static Lisp_Object Qprepend
, Qappend
;
207 static Lisp_Object Qlatin
;
209 /* Vector containing all fontsets. */
210 static Lisp_Object Vfontset_table
;
212 /* Next possibly free fontset ID. Usually this keeps the minimum
213 fontset ID not yet used. */
214 static int next_fontset_id
;
216 /* The default fontset. This gives default FAMILY and REGISTRY of
217 font for each character. */
218 static Lisp_Object Vdefault_fontset
;
220 Lisp_Object Vfont_encoding_alist
;
221 Lisp_Object Vuse_default_ascent
;
222 Lisp_Object Vignore_relative_composition
;
223 Lisp_Object Valternate_fontname_alist
;
224 Lisp_Object Vfontset_alias_alist
;
225 Lisp_Object Vvertical_centering_font_regexp
;
226 Lisp_Object Votf_script_alist
;
228 /* The following six are declarations of callback functions depending
229 on window system. See the comments in src/fontset.h for more
232 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
233 struct font_info
*(*get_font_info_func
) P_ ((FRAME_PTR f
, int font_idx
));
235 /* Return a list of font names which matches PATTERN. See the documentation
236 of `x-list-fonts' for more details. */
237 Lisp_Object (*list_fonts_func
) P_ ((struct frame
*f
,
242 /* Load a font named NAME for frame F and return a pointer to the
243 information of the loaded font. If loading is failed, return 0. */
244 struct font_info
*(*load_font_func
) P_ ((FRAME_PTR f
, char *name
, int));
246 /* Return a pointer to struct font_info of a font named NAME for frame F. */
247 struct font_info
*(*query_font_func
) P_ ((FRAME_PTR f
, char *name
));
249 /* Additional function for setting fontset or changing fontset
250 contents of frame F. */
251 void (*set_frame_fontset_func
) P_ ((FRAME_PTR f
, Lisp_Object arg
,
252 Lisp_Object oldval
));
254 /* To find a CCL program, fs_load_font calls this function.
255 The argument is a pointer to the struct font_info.
256 This function set the member `encoder' of the structure. */
257 void (*find_ccl_program_func
) P_ ((struct font_info
*));
259 Lisp_Object (*get_font_repertory_func
) P_ ((struct frame
*,
260 struct font_info
*));
262 /* Check if any window system is used now. */
263 void (*check_window_system_func
) P_ ((void));
266 /* Prototype declarations for static functions. */
267 static Lisp_Object fontset_add
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
,
269 static Lisp_Object fontset_font
P_ ((Lisp_Object
, int, struct face
*, int));
270 static Lisp_Object make_fontset
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
));
271 static Lisp_Object fontset_pattern_regexp
P_ ((Lisp_Object
));
272 static void accumulate_script_ranges
P_ ((Lisp_Object
, Lisp_Object
,
274 Lisp_Object find_font_encoding
P_ ((Lisp_Object
));
276 static void set_fontset_font
P_ ((Lisp_Object
, Lisp_Object
));
280 /* Return 1 if ID is a valid fontset id, else return 0. */
283 fontset_id_valid_p (id
)
286 return (id
>= 0 && id
< ASIZE (Vfontset_table
) - 1);
293 /********** MACROS AND FUNCTIONS TO HANDLE FONTSET **********/
295 /* Return the fontset with ID. No check of ID's validness. */
296 #define FONTSET_FROM_ID(id) AREF (Vfontset_table, id)
298 /* Macros to access special values of FONTSET. */
299 #define FONTSET_ID(fontset) XCHAR_TABLE (fontset)->extras[0]
301 /* Macros to access special values of (base) FONTSET. */
302 #define FONTSET_NAME(fontset) XCHAR_TABLE (fontset)->extras[1]
303 #define FONTSET_ASCII(fontset) XCHAR_TABLE (fontset)->extras[4]
305 /* Macros to access special values of (realized) FONTSET. */
306 #define FONTSET_BASE(fontset) XCHAR_TABLE (fontset)->extras[2]
307 #define FONTSET_FRAME(fontset) XCHAR_TABLE (fontset)->extras[3]
308 #define FONTSET_NOFONT_FACE(fontset) XCHAR_TABLE (fontset)->extras[5]
309 #define FONTSET_REPERTORY(fontset) XCHAR_TABLE (fontset)->extras[6]
310 #define FONTSET_DEFAULT(fontset) XCHAR_TABLE (fontset)->extras[7]
312 /* For both base and realized fontset. */
313 #define FONTSET_FALLBACK(fontset) XCHAR_TABLE (fontset)->extras[8]
315 #define BASE_FONTSET_P(fontset) (NILP (FONTSET_BASE (fontset)))
318 /* Return the element of FONTSET for the character C. If FONTSET is a
319 base fontset other then the default fontset and FONTSET doesn't
320 contain information for C, return the information in the default
323 #define FONTSET_REF(fontset, c) \
324 (EQ (fontset, Vdefault_fontset) \
325 ? CHAR_TABLE_REF (fontset, c) \
326 : fontset_ref ((fontset), (c)))
329 fontset_ref (fontset
, c
)
335 elt
= CHAR_TABLE_REF (fontset
, c
);
336 if (NILP (elt
) && ! EQ (fontset
, Vdefault_fontset
)
337 /* Don't check Vdefault_fontset for a realized fontset. */
338 && NILP (FONTSET_BASE (fontset
)))
339 elt
= CHAR_TABLE_REF (Vdefault_fontset
, c
);
344 /* Return the element of FONTSET for the character C, set FROM and TO
345 to the range of characters around C that have the same value as C.
346 If FONTSET is a base fontset other then the default fontset and
347 FONTSET doesn't contain information for C, return the information
348 in the default fontset. */
350 #define FONTSET_REF_AND_RANGE(fontset, c, form, to) \
351 (EQ (fontset, Vdefault_fontset) \
352 ? char_table_ref_and_range (fontset, c, &from, &to) \
353 : fontset_ref_and_range (fontset, c, &from, &to))
356 fontset_ref_and_range (fontset
, c
, from
, to
)
363 elt
= char_table_ref_and_range (fontset
, c
, from
, to
);
364 if (NILP (elt
) && ! EQ (fontset
, Vdefault_fontset
)
365 /* Don't check Vdefault_fontset for a realized fontset. */
366 && NILP (FONTSET_BASE (fontset
)))
370 elt
= char_table_ref_and_range (Vdefault_fontset
, c
, &from1
, &to1
);
380 /* Set elements of FONTSET for characters in RANGE to the value ELT.
381 RANGE is a cons (FROM . TO), where FROM and TO are character codes
382 specifying a range. */
384 #define FONTSET_SET(fontset, range, elt) \
385 Fset_char_table_range ((fontset), (range), (elt))
388 /* Modify the elements of FONTSET for characters in RANGE by replacing
389 with ELT or adding ELT. RANGE is a cons (FROM . TO), where FROM
390 and TO are character codes specifying a range. If ADD is nil,
391 replace with ELT, if ADD is `prepend', prepend ELT, otherwise,
394 #define FONTSET_ADD(fontset, range, elt, add) \
397 ? (FONTSET_FALLBACK (fontset) = Fmake_vector (make_number (1), (elt))) \
398 : Fset_char_table_range ((fontset), (range), \
399 Fmake_vector (make_number (1), (elt)))) \
400 : fontset_add ((fontset), (range), (elt), (add)))
403 fontset_add (fontset
, range
, elt
, add
)
404 Lisp_Object fontset
, range
, elt
, add
;
407 int idx
= (EQ (add
, Qappend
) ? 0 : 1);
409 args
[1 - idx
] = Fmake_vector (make_number (1), elt
);
413 int from
= XINT (XCAR (range
));
414 int to
= XINT (XCDR (range
));
418 args
[idx
] = char_table_ref_and_range (fontset
, from
, &from1
, &to1
);
421 char_table_set_range (fontset
, from
, to1
,
422 NILP (args
[idx
]) ? args
[1 - idx
]
423 : Fvconcat (2, args
));
429 args
[idx
] = FONTSET_FALLBACK (fontset
);
430 FONTSET_FALLBACK (fontset
)
431 = NILP (args
[idx
]) ? args
[1 - idx
] : Fvconcat (2, args
);
437 /* Update FONTSET_ELEMENT which has this form:
438 [CHARSET-ORDERED-LIST-TICK PREFERRED-CHARSET-ID PREFERRED-RFONT-DEF
439 RFONT-DEF0 RFONT-DEF1 ...].
440 Reorder RFONT-DEFs according to the current order of charset
441 (Vcharset_ordered_list), and update CHARSET-ORDERED-LIST-TICK to
445 reorder_font_vector (fontset_element
)
446 Lisp_Object fontset_element
;
448 Lisp_Object list
, *new_vec
;
449 Lisp_Object font_def
;
451 int *charset_id_table
;
454 ASET (fontset_element
, 0, make_number (charset_ordered_list_tick
));
455 size
= ASIZE (fontset_element
) - 3;
457 /* No need to reorder VEC. */
459 charset_id_table
= (int *) alloca (sizeof (int) * size
);
460 new_vec
= (Lisp_Object
*) alloca (sizeof (Lisp_Object
) * size
);
462 /* At first, extract ENCODING (a chaset ID) from each FONT-DEF.
463 FONT-DEF has this form:
464 [FACE-ID FONT-INDEX [ FONT-SPEC ENCODING REPERTORY ]] */
465 for (i
= 0; i
< size
; i
++)
467 font_def
= AREF (fontset_element
, i
+ 3);
468 if (! NILP (AREF (font_def
, 2)))
469 charset_id_table
[i
] = XINT (AREF (AREF (font_def
, 2), 1));
471 charset_id_table
[i
] = -1;
474 /* Then, store FONT-DEFs in NEW_VEC in the correct order. */
475 for (idx
= 0, list
= Vcharset_ordered_list
;
476 idx
< size
&& CONSP (list
); list
= XCDR (list
))
478 for (i
= 0; i
< size
; i
++)
479 if (charset_id_table
[i
] == XINT (XCAR (list
)))
480 new_vec
[idx
++] = AREF (fontset_element
, i
+ 3);
482 for (i
= 0; i
< size
; i
++)
483 if (charset_id_table
[i
] < 0)
484 new_vec
[idx
++] = AREF (fontset_element
, i
+ 3);
486 /* At last, update FONT-DEFs. */
487 for (i
= 0; i
< size
; i
++)
488 ASET (fontset_element
, i
+ 3, new_vec
[i
]);
492 /* Load a font matching the font related attributes in FACE->lface and
493 font pattern in FONT_DEF of FONTSET, and return an index of the
494 font. FONT_DEF has this form:
495 [ FONT-SPEC ENCODING REPERTORY ]
496 If REPERTORY is nil, generate a char-table representing the font
497 repertory by looking into the font itself. */
500 load_font_get_repertory (f
, face
, font_def
, fontset
)
503 Lisp_Object font_def
;
507 struct font_info
*font_info
;
510 font_name
= choose_face_font (f
, face
->lface
, AREF (font_def
, 0), NULL
);
511 charset
= XINT (AREF (font_def
, 1));
512 if (! (font_info
= fs_load_font (f
, font_name
, charset
)))
515 if (NILP (AREF (font_def
, 2))
516 && NILP (Fassq (make_number (font_info
->font_idx
),
517 FONTSET_REPERTORY (fontset
))))
519 /* We must look into the font to get the correct repertory as a
521 Lisp_Object repertory
;
523 repertory
= (*get_font_repertory_func
) (f
, font_info
);
524 FONTSET_REPERTORY (fontset
)
525 = Fcons (Fcons (make_number (font_info
->font_idx
), repertory
),
526 FONTSET_REPERTORY (fontset
));
529 return font_info
->font_idx
;
533 /* Return RFONT-DEF (vector) in the realized fontset FONTSET for the
534 character C. If the corresponding font is not yet opened, open it
535 (if FACE is not NULL) or return Qnil (if FACE is NULL).
536 If no proper font is found for C, return Qnil. */
539 fontset_font (fontset
, c
, face
, id
)
545 Lisp_Object base_fontset
, elt
, vec
;
548 FRAME_PTR f
= XFRAME (FONTSET_FRAME (fontset
));
550 base_fontset
= FONTSET_BASE (fontset
);
551 vec
= CHAR_TABLE_REF (fontset
, c
);
557 /* We have not yet decided a face for C. */
562 elt
= FONTSET_REF_AND_RANGE (base_fontset
, c
, from
, to
);
563 range
= Fcons (make_number (from
), make_number (to
));
566 /* Record that we have no font for characters of this
569 FONTSET_SET (fontset
, range
, vec
);
572 /* Build a vector [ -1 -1 nil NEW-ELT0 NEW-ELT1 NEW-ELT2 ... ],
573 where the first -1 is to force reordering of NEW-ELTn,
574 NEW-ETLn is [nil nil AREF (elt, n) nil]. */
575 #ifdef USE_FONT_BACKEND
576 if (enable_font_backend
577 && EQ (base_fontset
, Vdefault_fontset
))
578 vec
= Fmake_vector (make_number (ASIZE (elt
) + 4), make_number (-1));
580 #endif /* not USE_FONT_BACKEND */
581 vec
= Fmake_vector (make_number (ASIZE (elt
) + 3), make_number (-1));
583 for (i
= 0; i
< ASIZE (elt
); i
++)
587 #ifdef USE_FONT_BACKEND
588 if (enable_font_backend
)
589 tmp
= Fmake_vector (make_number (5), Qnil
);
591 #endif /* USE_FONT_BACKEND */
592 tmp
= Fmake_vector (make_number (4), Qnil
);
593 ASET (tmp
, 2, AREF (elt
, i
));
594 ASET (vec
, 3 + i
, tmp
);
596 #ifdef USE_FONT_BACKEND
597 if (enable_font_backend
598 && EQ (base_fontset
, Vdefault_fontset
))
600 Lisp_Object script
, font_spec
, tmp
;
602 script
= CHAR_TABLE_REF (Vchar_script_table
, c
);
604 script
= intern ("latin");
605 font_spec
= Ffont_spec (0, NULL
);
606 ASET (font_spec
, FONT_REGISTRY_INDEX
, Qiso10646_1
);
607 ASET (font_spec
, FONT_EXTRA_INDEX
,
608 Fcons (Fcons (QCscript
, script
), Qnil
));
609 tmp
= Fmake_vector (make_number (5), Qnil
);
610 ASET (tmp
, 3, font_spec
);
611 ASET (vec
, 3 + i
, tmp
);
613 #endif /* USE_FONT_BACKEND */
615 /* Then store it in the fontset. */
616 FONTSET_SET (fontset
, range
, vec
);
620 if (XINT (AREF (vec
, 0)) != charset_ordered_list_tick
)
621 /* The priority of charsets is changed after we selected a face
623 reorder_font_vector (vec
);
627 else if (id
== XFASTINT (AREF (vec
, 1)))
631 ASET (vec
, 1, make_number (id
));
632 for (i
= 3; i
< ASIZE (vec
); i
++)
633 if (id
== XFASTINT (AREF (AREF (AREF (vec
, i
), 2), 1)))
637 ASET (vec
, 2, AREF (vec
, i
));
647 /* Find the first available font in the vector of RFONT-DEF. */
648 for (; i
< ASIZE (vec
); i
++)
650 Lisp_Object font_def
;
655 /* ELT == [ FACE-ID FONT-INDEX FONT-DEF OPENED-FONT-NAME ] */
656 if (INTEGERP (AREF (elt
, 1)) && XINT (AREF (elt
, 1)) < 0)
657 /* We couldn't open this font last time. */
660 if (!face
&& NILP (AREF (elt
, 1)))
661 /* We have not yet opened the font. */
664 font_def
= AREF (elt
, 2);
665 /* FONT_DEF == [ FONT-SPEC ENCODING REPERTORY ] */
667 #ifdef USE_FONT_BACKEND
668 if (enable_font_backend
)
670 /* ELT == [ FACE-ID FONT-INDEX FONT-DEF FONT-ENTITY FONT-OBJECT ] */
671 Lisp_Object font_entity
= AREF (elt
, 3);
672 Lisp_Object font_object
= AREF (elt
, 4);
675 if (NILP (font_entity
) && ! NILP (AREF (font_def
, 0)))
677 Lisp_Object tmp
= AREF (font_def
, 0);
678 Lisp_Object spec
= Ffont_spec (0, NULL
);
681 font_merge_old_spec (tmp
, Qnil
, Qnil
, spec
);
684 Lisp_Object family
= AREF (tmp
, 0);
685 Lisp_Object registry
= AREF (tmp
, 5);;
687 font_merge_old_spec (Qnil
, family
, registry
, spec
);
689 font_entity
= font_find_for_lface (f
, face
->lface
, spec
);
690 ASET (elt
, 3, font_entity
);
692 else if (FONT_SPEC_P (font_entity
))
694 font_entity
= font_find_for_lface (f
, face
->lface
, font_entity
);
695 ASET (elt
, 3, font_entity
);
697 if (NILP (font_entity
))
699 ASET (elt
, 1, make_number (-1));
702 has_char
= font_has_char (f
, font_entity
, c
);
705 if (NILP (font_object
))
706 font_object
= font_open_for_lface (f
, face
->lface
, font_entity
);
707 if (NILP (font_object
))
709 ASET (elt
, 1, make_number (-1));
712 ASET (elt
, 1, make_number (0));
713 ASET (elt
, 4, font_object
);
715 && font_encode_char (font_object
, c
) == FONT_INVALID_CODE
)
719 #endif /* USE_FONT_BACKEND */
721 if (INTEGERP (AREF (font_def
, 2)))
723 /* The repertory is specified by charset ID. */
724 struct charset
*charset
725 = CHARSET_FROM_ID (XINT (AREF (font_def
, 2)));
727 if (! CHAR_CHARSET_P (c
, charset
))
728 /* This font can't display C. */
731 else if (CHAR_TABLE_P (AREF (font_def
, 2)))
733 /* The repertory is specified by a char table. */
734 if (NILP (CHAR_TABLE_REF (AREF (font_def
, 2), c
)))
735 /* This font can't display C. */
742 if (! INTEGERP (AREF (elt
, 1)))
744 /* We have not yet opened a font matching this spec.
745 Open the best matching font now and register the
747 struct font_info
*font_info
;
749 font_idx
= load_font_get_repertory (f
, face
, font_def
, fontset
);
750 ASET (elt
, 1, make_number (font_idx
));
752 /* This means that we couldn't find a font matching
755 font_info
= (*get_font_info_func
) (f
, font_idx
);
756 ASET (elt
, 3, build_string (font_info
->full_name
));
759 slot
= Fassq (AREF (elt
, 1), FONTSET_REPERTORY (fontset
));
760 xassert (CONSP (slot
));
761 if (NILP (CHAR_TABLE_REF (XCDR (slot
), c
)))
762 /* This font can't display C. */
766 /* Now we have decided to use this font spec to display C. */
767 if (! INTEGERP (AREF (elt
, 1)))
769 /* But not yet opened the best matching font. */
770 struct font_info
*font_info
;
772 font_idx
= load_font_get_repertory (f
, face
, font_def
, fontset
);
773 ASET (elt
, 1, make_number (font_idx
));
775 /* Can't open it. Try the other one. */
777 font_info
= (*get_font_info_func
) (f
, font_idx
);
778 ASET (elt
, 3, build_string (font_info
->full_name
));
781 /* Now we have the opened font. */
786 if (! EQ (vec
, FONTSET_FALLBACK (fontset
)))
788 vec
= FONTSET_FALLBACK (fontset
);
793 elt
= FONTSET_FALLBACK (base_fontset
);
796 vec
= Fmake_vector (make_number (ASIZE (elt
) + 3), make_number (-1));
798 for (i
= 0; i
< ASIZE (elt
); i
++)
802 #ifdef USE_FONT_BACKEND
803 if (enable_font_backend
)
804 tmp
= Fmake_vector (make_number (5), Qnil
);
806 #endif /* USE_FONT_BACKEND */
807 tmp
= Fmake_vector (make_number (4), Qnil
);
808 ASET (tmp
, 2, AREF (elt
, i
));
809 ASET (vec
, 3 + i
, tmp
);
811 FONTSET_FALLBACK (fontset
) = vec
;
814 /* Record that this fontset has no fallback fonts. */
815 FONTSET_FALLBACK (fontset
) = Qt
;
818 /* Try the default fontset. */
820 if (! EQ (base_fontset
, Vdefault_fontset
))
822 if (NILP (FONTSET_DEFAULT (fontset
)))
823 FONTSET_DEFAULT (fontset
)
824 = make_fontset (FONTSET_FRAME (fontset
), Qnil
, Vdefault_fontset
);
825 return fontset_font (FONTSET_DEFAULT (fontset
), c
, face
, id
);
831 /* Return a newly created fontset with NAME. If BASE is nil, make a
832 base fontset. Otherwise make a realized fontset whose base is
836 make_fontset (frame
, name
, base
)
837 Lisp_Object frame
, name
, base
;
840 int size
= ASIZE (Vfontset_table
);
841 int id
= next_fontset_id
;
843 /* Find a free slot in Vfontset_table. Usually, next_fontset_id is
844 the next available fontset ID. So it is expected that this loop
845 terminates quickly. In addition, as the last element of
846 Vfontset_table is always nil, we don't have to check the range of
848 while (!NILP (AREF (Vfontset_table
, id
))) id
++;
852 /* We must grow Vfontset_table. */
856 tem
= Fmake_vector (make_number (size
+ 32), Qnil
);
857 for (i
= 0; i
< size
; i
++)
858 AREF (tem
, i
) = AREF (Vfontset_table
, i
);
859 Vfontset_table
= tem
;
862 fontset
= Fmake_char_table (Qfontset
, Qnil
);
864 FONTSET_ID (fontset
) = make_number (id
);
867 FONTSET_NAME (fontset
) = name
;
871 FONTSET_NAME (fontset
) = Qnil
;
872 FONTSET_FRAME (fontset
) = frame
;
873 FONTSET_BASE (fontset
) = base
;
876 ASET (Vfontset_table
, id
, fontset
);
877 next_fontset_id
= id
+ 1;
882 /* Set the ASCII font of the default fontset to FONTNAME if that is
885 set_default_ascii_font (fontname
)
886 Lisp_Object fontname
;
888 if (! STRINGP (FONTSET_ASCII (Vdefault_fontset
)))
890 int id
= fs_query_fontset (fontname
, 2);
893 fontname
= FONTSET_ASCII (FONTSET_FROM_ID (id
));
894 FONTSET_ASCII (Vdefault_fontset
)= fontname
;
899 /********** INTERFACES TO xfaces.c, xfns.c, and dispextern.h **********/
901 /* Return the name of the fontset who has ID. */
909 fontset
= FONTSET_FROM_ID (id
);
910 return FONTSET_NAME (fontset
);
914 /* Return the ASCII font name of the fontset who has ID. */
920 Lisp_Object fontset
, elt
;
922 fontset
= FONTSET_FROM_ID (id
);
923 elt
= FONTSET_ASCII (fontset
);
924 #ifdef USE_FONT_BACKEND
927 #endif /* USE_FONT_BACKEND */
928 /* It is assured that ELT is always a string (i.e. fontname
934 /* Free fontset of FACE defined on frame F. Called from
935 free_realized_face. */
938 free_face_fontset (f
, face
)
944 fontset
= AREF (Vfontset_table
, face
->fontset
);
945 xassert (!NILP (fontset
) && ! BASE_FONTSET_P (fontset
));
946 xassert (f
== XFRAME (FONTSET_FRAME (fontset
)));
947 ASET (Vfontset_table
, face
->fontset
, Qnil
);
948 if (face
->fontset
< next_fontset_id
)
949 next_fontset_id
= face
->fontset
;
950 if (! NILP (FONTSET_DEFAULT (fontset
)))
952 int id
= XINT (FONTSET_ID (FONTSET_DEFAULT (fontset
)));
954 fontset
= AREF (Vfontset_table
, id
);
955 xassert (!NILP (fontset
) && ! BASE_FONTSET_P (fontset
));
956 xassert (f
== XFRAME (FONTSET_FRAME (fontset
)));
957 ASET (Vfontset_table
, id
, Qnil
);
958 if (id
< next_fontset_id
)
959 next_fontset_id
= face
->fontset
;
964 /* Return 1 iff FACE is suitable for displaying character C.
965 Otherwise return 0. Called from the macro FACE_SUITABLE_FOR_CHAR_P
966 when C is not an ASCII character. */
969 face_suitable_for_char_p (face
, c
)
973 Lisp_Object fontset
, rfont_def
;
975 fontset
= FONTSET_FROM_ID (face
->fontset
);
976 rfont_def
= fontset_font (fontset
, c
, NULL
, -1);
977 return (VECTORP (rfont_def
)
978 && INTEGERP (AREF (rfont_def
, 0))
979 && face
->id
== XINT (AREF (rfont_def
, 0)));
983 /* Return ID of face suitable for displaying character C on frame F.
984 FACE must be reazlied for ASCII characters in advance. Called from
985 the macro FACE_FOR_CHAR. */
988 face_for_char (f
, face
, c
, pos
, object
)
994 Lisp_Object fontset
, charset
, rfont_def
;
998 if (ASCII_CHAR_P (c
))
999 return face
->ascii_face
->id
;
1001 xassert (fontset_id_valid_p (face
->fontset
));
1002 fontset
= FONTSET_FROM_ID (face
->fontset
);
1003 xassert (!BASE_FONTSET_P (fontset
));
1008 charset
= Fget_char_property (make_number (pos
), Qcharset
, object
);
1011 else if (CHARSETP (charset
))
1012 id
= XINT (CHARSET_SYMBOL_ID (charset
));
1014 rfont_def
= fontset_font (fontset
, c
, face
, id
);
1015 if (VECTORP (rfont_def
))
1017 #ifdef USE_FONT_BACKEND
1018 if (enable_font_backend
1019 && NILP (AREF (rfont_def
, 0)))
1021 struct font
*font
= XSAVE_VALUE (AREF (rfont_def
, 4))->pointer
;
1023 face_id
= face_for_font (f
, font
, face
);
1024 ASET (rfont_def
, 0, make_number (face_id
));
1027 #endif /* USE_FONT_BACKEND */
1028 if (NILP (AREF (rfont_def
, 0)))
1030 /* We have not yet made a realized face that uses this font. */
1031 int font_idx
= XINT (AREF (rfont_def
, 1));
1033 face_id
= lookup_non_ascii_face (f
, font_idx
, face
);
1034 ASET (rfont_def
, 0, make_number (face_id
));
1036 return XINT (AREF (rfont_def
, 0));
1039 if (NILP (FONTSET_NOFONT_FACE (fontset
)))
1041 face_id
= lookup_non_ascii_face (f
, -1, face
);
1042 FONTSET_NOFONT_FACE (fontset
) = make_number (face_id
);
1044 return XINT (FONTSET_NOFONT_FACE (fontset
));
1048 /* Make a realized fontset for ASCII face FACE on frame F from the
1049 base fontset BASE_FONTSET_ID. If BASE_FONTSET_ID is -1, use the
1050 default fontset as the base. Value is the id of the new fontset.
1051 Called from realize_x_face. */
1054 make_fontset_for_ascii_face (f
, base_fontset_id
, face
)
1056 int base_fontset_id
;
1059 Lisp_Object base_fontset
, fontset
, frame
;
1061 XSETFRAME (frame
, f
);
1062 if (base_fontset_id
>= 0)
1064 base_fontset
= FONTSET_FROM_ID (base_fontset_id
);
1065 if (!BASE_FONTSET_P (base_fontset
))
1066 base_fontset
= FONTSET_BASE (base_fontset
);
1067 xassert (BASE_FONTSET_P (base_fontset
));
1068 if (! BASE_FONTSET_P (base_fontset
))
1072 base_fontset
= Vdefault_fontset
;
1074 fontset
= make_fontset (frame
, Qnil
, base_fontset
);
1076 Lisp_Object elt
, rfont_def
;
1078 elt
= FONTSET_REF (base_fontset
, 0);
1079 xassert (VECTORP (elt
) && ASIZE (elt
) > 0);
1080 #ifdef USE_FONT_BACKEND
1081 rfont_def
= Fmake_vector (make_number (5), Qnil
);
1082 if (enable_font_backend
&& face
->font_info
)
1084 struct font
*font
= (struct font
*) face
->font_info
;
1086 ASET (rfont_def
, 3, font
->entity
);
1087 ASET (rfont_def
, 4, font_find_object (font
));
1090 #endif /* USE_FONT_BACKEND */
1092 rfont_def
= Fmake_vector (make_number (4), Qnil
);
1093 ASET (rfont_def
, 3, build_string (face
->font_name
));
1095 ASET (rfont_def
, 0, make_number (face
->id
));
1096 ASET (rfont_def
, 1, make_number (face
->font_info_id
));
1097 ASET (rfont_def
, 2, AREF (elt
, 0));
1098 elt
= Fmake_vector (make_number (4), Qnil
);
1099 ASET (elt
, 0, make_number (charset_ordered_list_tick
));
1100 ASET (elt
, 1, make_number (charset_ascii
));
1101 ASET (elt
, 2, rfont_def
);
1102 ASET (elt
, 3, rfont_def
);
1103 char_table_set_range (fontset
, 0, 127, elt
);
1105 return XINT (FONTSET_ID (fontset
));
1109 #if defined(WINDOWSNT) && defined (_MSC_VER)
1110 #pragma optimize("", off)
1113 /* Load a font named FONTNAME on frame F. Return a pointer to the
1114 struct font_info of the loaded font. If loading fails, return
1115 NULL. CHARSET is an ID of charset to encode characters for this
1116 font. If it is -1, find one from Vfont_encoding_alist. */
1119 fs_load_font (f
, fontname
, charset
)
1124 struct font_info
*fontp
;
1125 Lisp_Object fullname
;
1128 /* No way to get fontname. */
1131 fontp
= (*load_font_func
) (f
, fontname
, 0);
1132 if (! fontp
|| fontp
->charset
>= 0)
1135 fontname
= fontp
->full_name
;
1136 fullname
= build_string (fontp
->full_name
);
1140 Lisp_Object charset_symbol
;
1142 charset_symbol
= find_font_encoding (fullname
);
1143 if (CONSP (charset_symbol
))
1144 charset_symbol
= XCAR (charset_symbol
);
1145 if (NILP (charset_symbol
))
1146 charset_symbol
= Qascii
;
1147 charset
= XINT (CHARSET_SYMBOL_ID (charset_symbol
));
1149 fontp
->charset
= charset
;
1150 fontp
->vertical_centering
= 0;
1151 fontp
->font_encoder
= NULL
;
1153 if (charset
!= charset_ascii
)
1155 fontp
->vertical_centering
1156 = (STRINGP (Vvertical_centering_font_regexp
)
1157 && (fast_string_match_ignore_case
1158 (Vvertical_centering_font_regexp
, fullname
) >= 0));
1160 if (find_ccl_program_func
)
1161 (*find_ccl_program_func
) (fontp
);
1167 #if defined(WINDOWSNT) && defined (_MSC_VER)
1168 #pragma optimize("", on)
1172 /* Return ENCODING or a cons of ENCODING and REPERTORY of the font
1173 FONTNAME. ENCODING is a charset symbol that specifies the encoding
1174 of the font. REPERTORY is a charset symbol or nil. */
1178 find_font_encoding (fontname
)
1179 Lisp_Object fontname
;
1181 Lisp_Object tail
, elt
;
1183 for (tail
= Vfont_encoding_alist
; CONSP (tail
); tail
= XCDR (tail
))
1187 && STRINGP (XCAR (elt
))
1188 && fast_string_match_ignore_case (XCAR (elt
), fontname
) >= 0
1189 && (SYMBOLP (XCDR (elt
))
1190 ? CHARSETP (XCDR (elt
))
1191 : CONSP (XCDR (elt
)) && CHARSETP (XCAR (XCDR (elt
)))))
1192 return (XCDR (elt
));
1194 /* We don't know the encoding of this font. Let's assume `ascii'. */
1199 /* Cache data used by fontset_pattern_regexp. The car part is a
1200 pattern string containing at least one wild card, the cdr part is
1201 the corresponding regular expression. */
1202 static Lisp_Object Vcached_fontset_data
;
1204 #define CACHED_FONTSET_NAME (SDATA (XCAR (Vcached_fontset_data)))
1205 #define CACHED_FONTSET_REGEX (XCDR (Vcached_fontset_data))
1207 /* If fontset name PATTERN contains any wild card, return regular
1208 expression corresponding to PATTERN. */
1211 fontset_pattern_regexp (pattern
)
1212 Lisp_Object pattern
;
1214 if (!index (SDATA (pattern
), '*')
1215 && !index (SDATA (pattern
), '?'))
1216 /* PATTERN does not contain any wild cards. */
1219 if (!CONSP (Vcached_fontset_data
)
1220 || strcmp (SDATA (pattern
), CACHED_FONTSET_NAME
))
1222 /* We must at first update the cached data. */
1223 unsigned char *regex
, *p0
, *p1
;
1224 int ndashes
= 0, nstars
= 0;
1226 for (p0
= SDATA (pattern
); *p0
; p0
++)
1230 else if (*p0
== '*')
1234 /* If PATTERN is not full XLFD we conert "*" to ".*". Otherwise
1235 we convert "*" to "[^-]*" which is much faster in regular
1236 expression matching. */
1238 p1
= regex
= (unsigned char *) alloca (SBYTES (pattern
) + 2 * nstars
+ 1);
1240 p1
= regex
= (unsigned char *) alloca (SBYTES (pattern
) + 5 * nstars
+ 1);
1243 for (p0
= SDATA (pattern
); *p0
; p0
++)
1250 *p1
++ = '[', *p1
++ = '^', *p1
++ = '-', *p1
++ = ']';
1253 else if (*p0
== '?')
1261 Vcached_fontset_data
= Fcons (build_string (SDATA (pattern
)),
1262 build_string (regex
));
1265 return CACHED_FONTSET_REGEX
;
1268 /* Return ID of the base fontset named NAME. If there's no such
1269 fontset, return -1. NAME_PATTERN specifies how to treat NAME as this:
1270 0: pattern containing '*' and '?' as wildcards
1271 1: regular expression
1272 2: literal fontset name
1276 fs_query_fontset (name
, name_pattern
)
1283 name
= Fdowncase (name
);
1284 if (name_pattern
!= 1)
1286 tem
= Frassoc (name
, Vfontset_alias_alist
);
1288 tem
= Fassoc (name
, Vfontset_alias_alist
);
1289 if (CONSP (tem
) && STRINGP (XCAR (tem
)))
1291 else if (name_pattern
== 0)
1293 tem
= fontset_pattern_regexp (name
);
1302 for (i
= 0; i
< ASIZE (Vfontset_table
); i
++)
1304 Lisp_Object fontset
, this_name
;
1306 fontset
= FONTSET_FROM_ID (i
);
1308 || !BASE_FONTSET_P (fontset
))
1311 this_name
= FONTSET_NAME (fontset
);
1312 if (name_pattern
== 1
1313 ? fast_string_match (name
, this_name
) >= 0
1314 : !strcmp (SDATA (name
), SDATA (this_name
)))
1321 DEFUN ("query-fontset", Fquery_fontset
, Squery_fontset
, 1, 2, 0,
1322 doc
: /* Return the name of a fontset that matches PATTERN.
1323 The value is nil if there is no matching fontset.
1324 PATTERN can contain `*' or `?' as a wildcard
1325 just as X font name matching algorithm allows.
1326 If REGEXPP is non-nil, PATTERN is a regular expression. */)
1328 Lisp_Object pattern
, regexpp
;
1330 Lisp_Object fontset
;
1333 (*check_window_system_func
) ();
1335 CHECK_STRING (pattern
);
1337 if (SCHARS (pattern
) == 0)
1340 id
= fs_query_fontset (pattern
, !NILP (regexpp
));
1344 fontset
= FONTSET_FROM_ID (id
);
1345 return FONTSET_NAME (fontset
);
1348 /* Return a list of base fontset names matching PATTERN on frame F. */
1351 list_fontsets (f
, pattern
, size
)
1353 Lisp_Object pattern
;
1356 Lisp_Object frame
, regexp
, val
;
1359 XSETFRAME (frame
, f
);
1361 regexp
= fontset_pattern_regexp (pattern
);
1364 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
1366 Lisp_Object fontset
, name
;
1368 fontset
= FONTSET_FROM_ID (id
);
1370 || !BASE_FONTSET_P (fontset
)
1371 || !EQ (frame
, FONTSET_FRAME (fontset
)))
1373 name
= FONTSET_NAME (fontset
);
1375 if (STRINGP (regexp
)
1376 ? (fast_string_match (regexp
, name
) < 0)
1377 : strcmp (SDATA (pattern
), SDATA (name
)))
1380 val
= Fcons (Fcopy_sequence (FONTSET_NAME (fontset
)), val
);
1387 /* Free all realized fontsets whose base fontset is BASE. */
1390 free_realized_fontsets (base
)
1396 /* For the moment, this doesn't work because free_realized_face
1397 doesn't remove FACE from a cache. Until we find a solution, we
1398 suppress this code, and simply use Fclear_face_cache even though
1399 that is not efficient. */
1401 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
1403 Lisp_Object
this = AREF (Vfontset_table
, id
);
1405 if (EQ (FONTSET_BASE (this), base
))
1409 for (tail
= FONTSET_FACE_ALIST (this); CONSP (tail
);
1412 FRAME_PTR f
= XFRAME (FONTSET_FRAME (this));
1413 int face_id
= XINT (XCDR (XCAR (tail
)));
1414 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1416 /* Face THIS itself is also freed by the following call. */
1417 free_realized_face (f
, face
);
1423 Fclear_face_cache (Qt
);
1428 /* Check validity of NAME as a fontset name and return the
1429 corresponding fontset. If not valid, signal an error.
1430 If NAME is t, return Vdefault_fontset. */
1433 check_fontset_name (name
)
1439 return Vdefault_fontset
;
1441 CHECK_STRING (name
);
1442 /* First try NAME as literal. */
1443 id
= fs_query_fontset (name
, 2);
1445 /* For backward compatibility, try again NAME as pattern. */
1446 id
= fs_query_fontset (name
, 0);
1448 error ("Fontset `%s' does not exist", SDATA (name
));
1449 return FONTSET_FROM_ID (id
);
1453 accumulate_script_ranges (arg
, range
, val
)
1454 Lisp_Object arg
, range
, val
;
1456 if (EQ (XCAR (arg
), val
))
1459 XSETCDR (arg
, Fcons (Fcons (XCAR (range
), XCDR (range
)), XCDR (arg
)));
1461 XSETCDR (arg
, Fcons (Fcons (range
, range
), XCDR (arg
)));
1466 /* Return an ASCII font name generated from fontset name NAME and
1467 ASCII font specification ASCII_SPEC. NAME is a string conforming
1468 to XLFD. ASCII_SPEC is a vector:
1469 [FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY]. */
1471 static INLINE Lisp_Object
1472 generate_ascii_font_name (name
, ascii_spec
)
1473 Lisp_Object name
, ascii_spec
;
1478 vec
= split_font_name_into_vector (name
);
1479 for (i
= FONT_SPEC_FAMILY_INDEX
; i
<= FONT_SPEC_ADSTYLE_INDEX
; i
++)
1480 if (! NILP (AREF (ascii_spec
, i
)))
1481 ASET (vec
, 1 + i
, AREF (ascii_spec
, i
));
1482 if (! NILP (AREF (ascii_spec
, FONT_SPEC_REGISTRY_INDEX
)))
1483 ASET (vec
, 12, AREF (ascii_spec
, FONT_SPEC_REGISTRY_INDEX
));
1484 return build_font_name_from_vector (vec
);
1487 /* Variables referred in set_fontset_font. They are set before
1488 map_charset_chars is called in Fset_fontset_font. */
1489 static Lisp_Object font_def_arg
, add_arg
;
1490 static int from_arg
, to_arg
;
1492 /* Callback function for map_charset_chars in Fset_fontset_font. In
1493 FONTSET, set font_def_arg in a fashion specified by add_arg for
1494 characters in RANGE while ignoring the range between from_arg and
1498 set_fontset_font (fontset
, range
)
1499 Lisp_Object fontset
, range
;
1501 if (from_arg
< to_arg
)
1503 int from
= XINT (XCAR (range
)), to
= XINT (XCDR (range
));
1505 if (from
< from_arg
)
1511 range2
= Fcons (make_number (to_arg
), XCDR (range
));
1512 FONTSET_ADD (fontset
, range
, font_def_arg
, add_arg
);
1516 range
= Fcons (XCAR (range
), make_number (from_arg
));
1518 else if (to
<= to_arg
)
1523 range
= Fcons (make_number (to_arg
), XCDR (range
));
1526 FONTSET_ADD (fontset
, range
, font_def_arg
, add_arg
);
1530 DEFUN ("set-fontset-font", Fset_fontset_font
, Sset_fontset_font
, 3, 5, 0,
1532 Modify fontset NAME to use FONT-SPEC for TARGET characters.
1534 TARGET may be a cons; (FROM . TO), where FROM and TO are characters.
1535 In that case, use FONT-SPEC for all characters in the range FROM and
1538 TARGET may be a script name symbol. In that case, use FONT-SPEC for
1539 all characters that belong to the script.
1541 TARGET may be a charset. In that case, use FONT-SPEC for all
1542 characters in the charset.
1544 TARGET may be nil. In that case, use FONT-SPEC for any characters for
1545 that no FONT-SPEC is specified.
1547 FONT-SPEC may one of these:
1548 * A cons (FAMILY . REGISTRY), where FAMILY is a font family name and
1549 REGISTRY is a font registry name. FAMILY may contains foundry
1550 name, and REGISTRY may contains encoding name.
1551 * A font name string.
1553 Optional 4th argument FRAME, if non-nil, is a frame. This argument is
1554 kept for backward compatibility and has no meaning.
1556 Optional 5th argument ADD, if non-nil, specifies how to add FONT-SPEC
1557 to the font specifications for TARGET previously set. If it is
1558 `prepend', FONT-SPEC is prepended. If it is `append', FONT-SPEC is
1559 appended. By default, FONT-SPEC overrides the previous settings. */)
1560 (name
, target
, font_spec
, frame
, add
)
1561 Lisp_Object name
, target
, font_spec
, frame
, add
;
1563 Lisp_Object fontset
;
1564 Lisp_Object font_def
, registry
, family
;
1565 Lisp_Object encoding
, repertory
;
1566 Lisp_Object range_list
;
1567 struct charset
*charset
= NULL
;
1569 fontset
= check_fontset_name (name
);
1571 /* The arg FRAME is kept for backward compatibility. We only check
1574 CHECK_LIVE_FRAME (frame
);
1576 if (VECTORP (font_spec
))
1578 /* FONT_SPEC should have this form:
1579 [ FAMILY WEIGHT SLANT WIDTH ADSTYLE REGISTRY ]
1580 This is a feature not yet documented because WEIGHT thru
1581 ADSTYLE are ignored for the moment. */
1584 if (ASIZE (font_spec
) != FONT_SPEC_MAX_INDEX
)
1585 args_out_of_range (make_number (FONT_SPEC_MAX_INDEX
),
1586 make_number (ASIZE (font_spec
)));
1588 font_spec
= Fcopy_sequence (font_spec
);
1589 for (j
= 0; j
< FONT_SPEC_MAX_INDEX
- 1; j
++)
1590 if (! NILP (AREF (font_spec
, j
)))
1592 CHECK_STRING (AREF (font_spec
, j
));
1593 ASET (font_spec
, j
, Fdowncase (AREF (font_spec
, j
)));
1595 family
= AREF (font_spec
, FONT_SPEC_FAMILY_INDEX
);
1596 /* REGISTRY should not be omitted. */
1597 CHECK_STRING (AREF (font_spec
, FONT_SPEC_REGISTRY_INDEX
));
1598 registry
= AREF (font_spec
, FONT_SPEC_REGISTRY_INDEX
);
1600 else if (CONSP (font_spec
))
1602 family
= XCAR (font_spec
);
1603 registry
= XCDR (font_spec
);
1605 if (! NILP (family
))
1607 CHECK_STRING (family
);
1608 family
= Fdowncase (family
);
1610 CHECK_STRING (registry
);
1611 registry
= Fdowncase (registry
);
1612 font_spec
= Fmake_vector (make_number (FONT_SPEC_MAX_INDEX
), Qnil
);
1613 ASET (font_spec
, FONT_SPEC_FAMILY_INDEX
, family
);
1614 ASET (font_spec
, FONT_SPEC_REGISTRY_INDEX
, registry
);
1618 CHECK_STRING (font_spec
);
1619 font_spec
= Fdowncase (font_spec
);
1622 if (STRINGP (font_spec
))
1623 encoding
= find_font_encoding (font_spec
);
1625 encoding
= find_font_encoding (concat2 (family
, registry
));
1626 if (NILP (encoding
))
1629 if (SYMBOLP (encoding
))
1631 CHECK_CHARSET (encoding
);
1632 encoding
= repertory
= CHARSET_SYMBOL_ID (encoding
);
1636 repertory
= XCDR (encoding
);
1637 encoding
= XCAR (encoding
);
1638 CHECK_CHARSET (encoding
);
1639 encoding
= CHARSET_SYMBOL_ID (encoding
);
1640 if (! NILP (repertory
) && SYMBOLP (repertory
))
1642 CHECK_CHARSET (repertory
);
1643 repertory
= CHARSET_SYMBOL_ID (repertory
);
1646 font_def
= Fmake_vector (make_number (3), font_spec
);
1647 ASET (font_def
, 1, encoding
);
1648 ASET (font_def
, 2, repertory
);
1650 if (CHARACTERP (target
))
1651 range_list
= Fcons (Fcons (target
, target
), Qnil
);
1652 else if (CONSP (target
))
1654 Lisp_Object from
, to
;
1656 from
= Fcar (target
);
1658 CHECK_CHARACTER (from
);
1659 CHECK_CHARACTER (to
);
1660 range_list
= Fcons (target
, Qnil
);
1662 else if (SYMBOLP (target
) && !NILP (target
))
1664 Lisp_Object script_list
;
1668 script_list
= XCHAR_TABLE (Vchar_script_table
)->extras
[0];
1669 if (! NILP (Fmemq (target
, script_list
)))
1671 val
= Fcons (target
, Qnil
);
1672 map_char_table (accumulate_script_ranges
, Qnil
, Vchar_script_table
,
1674 range_list
= XCDR (val
);
1675 if (EQ (target
, Qlatin
))
1677 if (VECTORP (font_spec
))
1678 val
= generate_ascii_font_name (FONTSET_NAME (fontset
),
1682 FONTSET_ASCII (fontset
) = val
;
1685 if (CHARSETP (target
))
1687 if (EQ (target
, Qascii
))
1689 if (VECTORP (font_spec
))
1690 font_spec
= generate_ascii_font_name (FONTSET_NAME (fontset
),
1692 FONTSET_ASCII (fontset
) = font_spec
;
1693 range_list
= Fcons (Fcons (make_number (0), make_number (127)),
1698 CHECK_CHARSET_GET_CHARSET (target
, charset
);
1701 else if (NILP (range_list
))
1702 error ("Invalid script or charset name: %s",
1703 SDATA (SYMBOL_NAME (target
)));
1705 else if (NILP (target
))
1706 range_list
= Fcons (Qnil
, Qnil
);
1708 error ("Invalid target for setting a font");
1713 font_def_arg
= font_def
;
1715 if (NILP (range_list
))
1716 from_arg
= to_arg
= 0;
1718 from_arg
= XINT (XCAR (XCAR (range_list
))),
1719 to_arg
= XINT (XCDR (XCAR (range_list
)));
1721 map_charset_chars (set_fontset_font
, Qnil
, fontset
, charset
,
1722 CHARSET_MIN_CODE (charset
),
1723 CHARSET_MAX_CODE (charset
));
1725 for (; CONSP (range_list
); range_list
= XCDR (range_list
))
1726 FONTSET_ADD (fontset
, XCAR (range_list
), font_def
, add
);
1728 /* Free all realized fontsets whose base is FONTSET. This way, the
1729 specified character(s) are surely redisplayed by a correct
1731 free_realized_fontsets (fontset
);
1737 DEFUN ("new-fontset", Fnew_fontset
, Snew_fontset
, 2, 2, 0,
1738 doc
: /* Create a new fontset NAME from font information in FONTLIST.
1740 FONTLIST is an alist of scripts vs the corresponding font specification list.
1741 Each element of FONTLIST has the form (SCRIPT FONT-SPEC ...), where a
1742 character of SCRIPT is displayed by a font that matches one of
1745 SCRIPT is a symbol that appears in the first extra slot of the
1746 char-table `char-script-table'.
1748 FONT-SPEC is a vector, a cons, or a string. See the documentation of
1749 `set-fontset-font' for the meaning. */)
1751 Lisp_Object name
, fontlist
;
1753 Lisp_Object fontset
;
1757 CHECK_STRING (name
);
1758 CHECK_LIST (fontlist
);
1760 id
= fs_query_fontset (name
, 0);
1763 name
= Fdowncase (name
);
1764 val
= split_font_name_into_vector (name
);
1765 if (NILP (val
) || NILP (AREF (val
, 12)) || NILP (AREF (val
, 13)))
1766 error ("Fontset name must be in XLFD format");
1767 if (strcmp (SDATA (AREF (val
, 12)), "fontset"))
1768 error ("Registry field of fontset name must be \"fontset\"");
1769 Vfontset_alias_alist
1770 = Fcons (Fcons (name
,
1771 concat2 (concat2 (AREF (val
, 12), build_string ("-")),
1773 Vfontset_alias_alist
);
1774 ASET (val
, 12, build_string ("iso8859-1"));
1775 fontset
= make_fontset (Qnil
, name
, Qnil
);
1776 FONTSET_ASCII (fontset
) = build_font_name_from_vector (val
);
1780 fontset
= FONTSET_FROM_ID (id
);;
1781 free_realized_fontsets (fontset
);
1782 Fset_char_table_range (fontset
, Qt
, Qnil
);
1785 for (; ! NILP (fontlist
); fontlist
= Fcdr (fontlist
))
1787 Lisp_Object elt
, script
;
1789 elt
= Fcar (fontlist
);
1790 script
= Fcar (elt
);
1792 if (CONSP (elt
) && (NILP (XCDR (elt
)) || CONSP (XCDR (elt
))))
1793 for (; CONSP (elt
); elt
= XCDR (elt
))
1794 Fset_fontset_font (name
, script
, XCAR (elt
), Qnil
, Qappend
);
1796 Fset_fontset_font (name
, script
, elt
, Qnil
, Qappend
);
1802 /* Alist of automatically created fontsets. Each element is a cons
1803 (FONTNAME . FONTSET-ID). */
1804 static Lisp_Object auto_fontset_alist
;
1807 new_fontset_from_font_name (Lisp_Object fontname
)
1814 fontname
= Fdowncase (fontname
);
1815 val
= Fassoc (fontname
, auto_fontset_alist
);
1817 return XINT (XCDR (val
));
1819 vec
= split_font_name_into_vector (fontname
);
1821 vec
= Fmake_vector (make_number (14), build_string (""));
1822 ASET (vec
, 12, build_string ("fontset"));
1823 if (NILP (auto_fontset_alist
))
1825 ASET (vec
, 13, build_string ("startup"));
1826 name
= build_font_name_from_vector (vec
);
1831 int len
= XINT (Flength (auto_fontset_alist
));
1833 sprintf (temp
, "auto%d", len
);
1834 ASET (vec
, 13, build_string (temp
));
1835 name
= build_font_name_from_vector (vec
);
1837 name
= Fnew_fontset (name
, list2 (list2 (Qascii
, fontname
),
1838 list2 (Fcons (make_number (0),
1839 make_number (MAX_CHAR
)),
1841 id
= fs_query_fontset (name
, 0);
1843 = Fcons (Fcons (fontname
, make_number (id
)), auto_fontset_alist
);
1847 #ifdef USE_FONT_BACKEND
1849 new_fontset_from_font (font_object
)
1850 Lisp_Object font_object
;
1852 Lisp_Object font_name
= font_get_name (font_object
);
1853 Lisp_Object font_spec
= font_get_spec (font_object
);
1854 Lisp_Object short_name
, name
, fontset
;
1856 if (NILP (auto_fontset_alist
))
1857 short_name
= build_string ("fontset-startup");
1861 int len
= XINT (Flength (auto_fontset_alist
));
1863 sprintf (temp
, "fontset-auto%d", len
);
1864 short_name
= build_string (temp
);
1866 ASET (font_spec
, FONT_REGISTRY_INDEX
, short_name
);
1867 name
= Ffont_xlfd_name (font_spec
);
1872 for (i
= 0; i
< FONT_SIZE_INDEX
; i
++)
1873 if ((i
!= FONT_FAMILY_INDEX
) && (i
!= FONT_REGISTRY_INDEX
))
1874 ASET (font_spec
, i
, Qnil
);
1875 name
= Ffont_xlfd_name (font_spec
);
1879 fontset
= make_fontset (Qnil
, name
, Qnil
);
1880 FONTSET_ASCII (fontset
) = font_name
;
1881 return XINT (FONTSET_ID (fontset
));
1885 fontset_ascii_font (f
, id
)
1889 Lisp_Object fontset
= FONTSET_FROM_ID (id
);
1890 Lisp_Object ascii_slot
= FONTSET_ASCII (fontset
);
1891 Lisp_Object val
, font_object
;
1893 if (CONSP (ascii_slot
))
1895 Lisp_Object ascii_font_name
= XCAR (ascii_slot
);
1898 for (val
= XCDR (ascii_slot
); ! NILP (val
); val
= XCDR (val
))
1900 Lisp_Object frame
= font_get_frame (XCAR (val
));
1902 if (NILP (frame
) || XFRAME (frame
) == f
)
1904 font_object
= XCAR (val
);
1905 if (XSAVE_VALUE (font_object
)->integer
== 0)
1907 font_object
= font_open_by_name (f
, SDATA (ascii_font_name
));
1908 XSETCAR (val
, font_object
);
1913 if (NILP (font_object
))
1915 font_object
= font_open_by_name (f
, SDATA (ascii_font_name
));
1916 XSETCDR (ascii_slot
, Fcons (font_object
, XCDR (ascii_slot
)));
1921 font_object
= font_open_by_name (f
, SDATA (ascii_slot
));
1922 FONTSET_ASCII (fontset
) = Fcons (ascii_slot
, Fcons (font_object
, Qnil
));
1924 if (NILP (font_object
))
1926 return XSAVE_VALUE (font_object
)->pointer
;
1929 #endif /* USE_FONT_BACKEND */
1931 DEFUN ("font-info", Ffont_info
, Sfont_info
, 1, 2, 0,
1932 doc
: /* Return information about a font named NAME on frame FRAME.
1933 If FRAME is omitted or nil, use the selected frame.
1934 The returned value is a vector of OPENED-NAME, FULL-NAME, CHARSET, SIZE,
1935 HEIGHT, BASELINE-OFFSET, RELATIVE-COMPOSE, and DEFAULT-ASCENT,
1937 OPENED-NAME is the name used for opening the font,
1938 FULL-NAME is the full name of the font,
1939 SIZE is the maximum bound width of the font,
1940 HEIGHT is the height of the font,
1941 BASELINE-OFFSET is the upward offset pixels from ASCII baseline,
1942 RELATIVE-COMPOSE and DEFAULT-ASCENT are the numbers controlling
1943 how to compose characters.
1944 If the named font is not yet loaded, return nil. */)
1946 Lisp_Object name
, frame
;
1949 struct font_info
*fontp
;
1951 Lisp_Object font_object
;
1953 (*check_window_system_func
) ();
1955 CHECK_STRING (name
);
1956 name
= Fdowncase (name
);
1958 frame
= selected_frame
;
1959 CHECK_LIVE_FRAME (frame
);
1962 if (!query_font_func
)
1963 error ("Font query function is not supported");
1965 #ifdef USE_FONT_BACKEND
1966 if (enable_font_backend
)
1968 font_object
= font_open_by_name (f
, SDATA (name
));
1969 if (NILP (font_object
))
1972 fontp
= (struct font_info
*) XSAVE_VALUE (font_object
)->pointer
;
1975 #endif /* USE_FONT_BACKEND */
1976 fontp
= (*query_font_func
) (f
, SDATA (name
));
1980 info
= Fmake_vector (make_number (7), Qnil
);
1982 XVECTOR (info
)->contents
[0] = build_string (fontp
->name
);
1983 XVECTOR (info
)->contents
[1] = build_string (fontp
->full_name
);
1984 XVECTOR (info
)->contents
[2] = make_number (fontp
->size
);
1985 XVECTOR (info
)->contents
[3] = make_number (fontp
->height
);
1986 XVECTOR (info
)->contents
[4] = make_number (fontp
->baseline_offset
);
1987 XVECTOR (info
)->contents
[5] = make_number (fontp
->relative_compose
);
1988 XVECTOR (info
)->contents
[6] = make_number (fontp
->default_ascent
);
1990 #ifdef USE_FONT_BACKEND
1991 if (! NILP (font_object
))
1992 font_close_object (f
, font_object
);
1993 #endif /* USE_FONT_BACKEND */
1998 /* Return a cons (FONT-NAME . GLYPH-CODE).
1999 FONT-NAME is the font name for the character at POSITION in the current
2000 buffer. This is computed from all the text properties and overlays
2001 that apply to POSITION. POSTION may be nil, in which case,
2002 FONT-NAME is the font name for display the character CH with the
2005 GLYPH-CODE is the glyph code in the font to use for the character.
2007 If the 2nd optional arg CH is non-nil, it is a character to check
2008 the font instead of the character at POSITION.
2010 It returns nil in the following cases:
2012 (1) The window system doesn't have a font for the character (thus
2013 it is displayed by an empty box).
2015 (2) The character code is invalid.
2017 (3) If POSITION is not nil, and the current buffer is not displayed
2020 In addition, the returned font name may not take into account of
2021 such redisplay engine hooks as what used in jit-lock-mode if
2022 POSITION is currently not visible. */
2025 DEFUN ("internal-char-font", Finternal_char_font
, Sinternal_char_font
, 1, 2, 0,
2026 doc
: /* For internal use only. */)
2028 Lisp_Object position
, ch
;
2030 int pos
, pos_byte
, dummy
;
2035 Lisp_Object charset
, rfont_def
;
2038 if (NILP (position
))
2040 CHECK_CHARACTER (ch
);
2042 f
= XFRAME (selected_frame
);
2043 face_id
= DEFAULT_FACE_ID
;
2049 Lisp_Object window
, charset
;
2052 CHECK_NUMBER_COERCE_MARKER (position
);
2053 pos
= XINT (position
);
2054 if (pos
< BEGV
|| pos
>= ZV
)
2055 args_out_of_range_3 (position
, make_number (BEGV
), make_number (ZV
));
2056 pos_byte
= CHAR_TO_BYTE (pos
);
2058 c
= FETCH_CHAR (pos_byte
);
2064 window
= Fget_buffer_window (Fcurrent_buffer (), Qnil
);
2067 w
= XWINDOW (window
);
2068 f
= XFRAME (w
->frame
);
2069 face_id
= face_at_buffer_position (w
, pos
, -1, -1, &dummy
, pos
+ 100, 0);
2070 charset
= Fget_char_property (position
, Qcharset
, Qnil
);
2071 if (CHARSETP (charset
))
2072 cs_id
= XINT (CHARSET_SYMBOL_ID (charset
));
2076 if (! CHAR_VALID_P (c
, 0))
2078 face_id
= FACE_FOR_CHAR (f
, FACE_FROM_ID (f
, face_id
), c
, pos
, Qnil
);
2079 face
= FACE_FROM_ID (f
, face_id
);
2080 rfont_def
= fontset_font (FONTSET_FROM_ID (face
->fontset
), c
, face
, cs_id
);
2081 #ifdef USE_FONT_BACKEND
2082 if (enable_font_backend
)
2084 if (VECTORP (rfont_def
) && ! NILP (AREF (rfont_def
, 4)))
2086 Lisp_Object font_object
= AREF (rfont_def
, 4);
2087 struct font
*font
= XSAVE_VALUE (font_object
)->pointer
;
2088 unsigned code
= font
->driver
->encode_char (font
, c
);
2089 Lisp_Object fontname
= font_get_name (font_object
);
2091 if (code
== FONT_INVALID_CODE
)
2092 return Fcons (fontname
, Qnil
);
2093 if (code
<= MOST_POSITIVE_FIXNUM
)
2094 return Fcons (fontname
, make_number (code
));
2095 return Fcons (fontname
, Fcons (make_number (code
>> 16),
2096 make_number (code
& 0xFFFF)));
2100 #endif /* USE_FONT_BACKEND */
2101 if (VECTORP (rfont_def
) && STRINGP (AREF (rfont_def
, 3)))
2103 Lisp_Object font_def
;
2104 struct font_info
*fontp
;
2105 struct charset
*charset
;
2109 font_def
= AREF (rfont_def
, 2);
2110 charset
= CHARSET_FROM_ID (XINT (AREF (font_def
, 1)));
2111 code
= ENCODE_CHAR (charset
, c
);
2112 if (code
== CHARSET_INVALID_CODE (charset
))
2113 return (Fcons (AREF (rfont_def
, 3), Qnil
));
2114 STORE_XCHAR2B (&char2b
, ((code
>> 8) & 0xFF), (code
& 0xFF));
2115 fontp
= (*get_font_info_func
) (f
, XINT (AREF (rfont_def
, 1)));
2116 rif
->encode_char (c
, &char2b
, fontp
, charset
, NULL
);
2117 code
= (XCHAR2B_BYTE1 (&char2b
) << 8) | XCHAR2B_BYTE2 (&char2b
);
2118 return (Fcons (AREF (rfont_def
, 3), make_number (code
)));
2124 DEFUN ("fontset-info", Ffontset_info
, Sfontset_info
, 1, 2, 0,
2125 doc
: /* Return information about a fontset FONTSET on frame FRAME.
2126 The value is a char-table of which elements has this form.
2128 ((FONT-PATTERN OPENED-FONT ...) ...)
2130 FONT-PATTERN is a vector:
2132 [ FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY ]
2134 or a string of font name pattern.
2136 OPENED-FONT is a name of a font actually opened.
2138 The char-table has one extra slot. The value is a char-table
2139 containing the information about the derived fonts from the default
2140 fontset. The format is the same as abobe. */)
2142 Lisp_Object fontset
, frame
;
2145 Lisp_Object
*realized
[2], fontsets
[2], tables
[2];
2146 Lisp_Object val
, elt
;
2149 (*check_window_system_func
) ();
2151 fontset
= check_fontset_name (fontset
);
2154 frame
= selected_frame
;
2155 CHECK_LIVE_FRAME (frame
);
2158 /* Recode fontsets realized on FRAME from the base fontset FONTSET
2159 in the table `realized'. */
2160 realized
[0] = (Lisp_Object
*) alloca (sizeof (Lisp_Object
)
2161 * ASIZE (Vfontset_table
));
2162 for (i
= j
= 0; i
< ASIZE (Vfontset_table
); i
++)
2164 elt
= FONTSET_FROM_ID (i
);
2166 && EQ (FONTSET_BASE (elt
), fontset
)
2167 && EQ (FONTSET_FRAME (elt
), frame
))
2168 realized
[0][j
++] = elt
;
2170 realized
[0][j
] = Qnil
;
2172 realized
[1] = (Lisp_Object
*) alloca (sizeof (Lisp_Object
)
2173 * ASIZE (Vfontset_table
));
2174 for (i
= j
= 0; ! NILP (realized
[0][i
]); i
++)
2176 elt
= FONTSET_DEFAULT (realized
[0][i
]);
2178 realized
[1][j
++] = elt
;
2180 realized
[1][j
] = Qnil
;
2182 tables
[0] = Fmake_char_table (Qfontset_info
, Qnil
);
2183 tables
[1] = Fmake_char_table (Qnil
, Qnil
);
2184 XCHAR_TABLE (tables
[0])->extras
[0] = tables
[1];
2185 fontsets
[0] = fontset
;
2186 fontsets
[1] = Vdefault_fontset
;
2188 /* Accumulate information of the fontset in TABLE. The format of
2189 each element is ((FONT-SPEC OPENED-FONT ...) ...). */
2190 for (k
= 0; k
<= 1; k
++)
2192 for (c
= 0; c
<= MAX_CHAR
; )
2196 if (c
<= MAX_5_BYTE_CHAR
)
2198 val
= char_table_ref_and_range (fontsets
[k
], c
, &from
, &to
);
2199 if (to
> MAX_5_BYTE_CHAR
)
2200 to
= MAX_5_BYTE_CHAR
;
2204 val
= FONTSET_FALLBACK (fontsets
[k
]);
2211 /* At first, set ALIST to ((FONT-SPEC) ...). */
2212 for (alist
= Qnil
, i
= 0; i
< ASIZE (val
); i
++)
2213 alist
= Fcons (Fcons (AREF (AREF (val
, i
), 0), Qnil
), alist
);
2214 alist
= Fnreverse (alist
);
2216 /* Then store opend font names to cdr of each elements. */
2217 for (i
= 0; ! NILP (realized
[k
][i
]); i
++)
2219 if (c
<= MAX_5_BYTE_CHAR
)
2220 val
= FONTSET_REF (realized
[k
][i
], c
);
2222 val
= FONTSET_FALLBACK (realized
[k
][i
]);
2223 if (! VECTORP (val
))
2225 /* VAL is [int int ?
2226 [FACE-ID FONT-INDEX FONT-DEF FONT-NAME] ...].
2227 If a font of an element is already opened,
2228 FONT-NAME is the name of a opened font. */
2229 for (j
= 3; j
< ASIZE (val
); j
++)
2230 if (STRINGP (AREF (AREF (val
, j
), 3)))
2232 Lisp_Object font_idx
;
2234 font_idx
= AREF (AREF (val
, j
), 1);
2235 elt
= Fassq (AREF (AREF (AREF (val
, j
), 2), 0), alist
);
2237 && NILP (Fmemq (font_idx
, XCDR(elt
))))
2238 nconc2 (elt
, Fcons (font_idx
, Qnil
));
2241 for (val
= alist
; CONSP (val
); val
= XCDR (val
))
2242 for (elt
= XCDR (XCAR (val
)); CONSP (elt
); elt
= XCDR (elt
))
2244 struct font_info
*font_info
2245 = (*get_font_info_func
) (f
, XINT (XCAR (elt
)));
2246 XSETCAR (elt
, build_string (font_info
->full_name
));
2249 /* Store ALIST in TBL for characters C..TO. */
2250 if (c
<= MAX_5_BYTE_CHAR
)
2251 char_table_set_range (tables
[k
], c
, to
, alist
);
2253 XCHAR_TABLE (tables
[k
])->defalt
= alist
;
2263 DEFUN ("fontset-font", Ffontset_font
, Sfontset_font
, 2, 3, 0,
2264 doc
: /* Return a font name pattern for character CH in fontset NAME.
2265 If NAME is t, find a pattern in the default fontset.
2267 The value has the form (FAMILY . REGISTRY), where FAMILY is a font
2268 family name and REGISTRY is a font registry name. This is actually
2269 the first font name pattern for CH in the fontset or in the default
2272 If the 2nd optional arg ALL is non-nil, return a list of all font name
2275 Lisp_Object name
, ch
, all
;
2278 Lisp_Object fontset
, elt
, list
, repertory
, val
;
2281 fontset
= check_fontset_name (name
);
2283 CHECK_CHARACTER (ch
);
2288 for (i
= 0, elt
= FONTSET_REF (fontset
, c
); i
< 2;
2289 i
++, elt
= FONTSET_FALLBACK (fontset
))
2291 for (j
= 0; j
< ASIZE (elt
); j
++)
2293 val
= AREF (elt
, j
);
2294 repertory
= AREF (val
, 1);
2295 if (INTEGERP (repertory
))
2297 struct charset
*charset
= CHARSET_FROM_ID (XINT (repertory
));
2299 if (! CHAR_CHARSET_P (c
, charset
))
2302 else if (CHAR_TABLE_P (repertory
))
2304 if (NILP (CHAR_TABLE_REF (repertory
, c
)))
2307 val
= AREF (val
, 0);
2308 val
= Fcons (AREF (val
, 0), AREF (val
, 5));
2311 list
= Fcons (val
, list
);
2313 if (EQ (fontset
, Vdefault_fontset
))
2315 fontset
= Vdefault_fontset
;
2317 return (Fnreverse (list
));
2320 DEFUN ("fontset-list", Ffontset_list
, Sfontset_list
, 0, 0, 0,
2321 doc
: /* Return a list of all defined fontset names. */)
2324 Lisp_Object fontset
, list
;
2328 for (i
= 0; i
< ASIZE (Vfontset_table
); i
++)
2330 fontset
= FONTSET_FROM_ID (i
);
2332 && BASE_FONTSET_P (fontset
))
2333 list
= Fcons (FONTSET_NAME (fontset
), list
);
2340 #ifdef FONTSET_DEBUG
2343 dump_fontset (fontset
)
2344 Lisp_Object fontset
;
2348 vec
= Fmake_vector (make_number (3), Qnil
);
2349 ASET (vec
, 0, FONTSET_ID (fontset
));
2351 if (BASE_FONTSET_P (fontset
))
2353 ASET (vec
, 1, FONTSET_NAME (fontset
));
2359 frame
= FONTSET_FRAME (fontset
);
2362 FRAME_PTR f
= XFRAME (frame
);
2364 if (FRAME_LIVE_P (f
))
2365 ASET (vec
, 1, f
->name
);
2369 if (!NILP (FONTSET_DEFAULT (fontset
)))
2370 ASET (vec
, 2, FONTSET_ID (FONTSET_DEFAULT (fontset
)));
2375 DEFUN ("fontset-list-all", Ffontset_list_all
, Sfontset_list_all
, 0, 0, 0,
2376 doc
: /* Return a brief summary of all fontsets for debug use. */)
2382 for (i
= 0, val
= Qnil
; i
< ASIZE (Vfontset_table
); i
++)
2383 if (! NILP (AREF (Vfontset_table
, i
)))
2384 val
= Fcons (dump_fontset (AREF (Vfontset_table
, i
)), val
);
2385 return (Fnreverse (val
));
2387 #endif /* FONTSET_DEBUG */
2392 if (!load_font_func
)
2393 /* Window system initializer should have set proper functions. */
2396 DEFSYM (Qfontset
, "fontset");
2397 Fput (Qfontset
, Qchar_table_extra_slots
, make_number (9));
2398 DEFSYM (Qfontset_info
, "fontset-info");
2399 Fput (Qfontset_info
, Qchar_table_extra_slots
, make_number (1));
2401 DEFSYM (Qprepend
, "prepend");
2402 DEFSYM (Qappend
, "append");
2403 DEFSYM (Qlatin
, "latin");
2405 Vcached_fontset_data
= Qnil
;
2406 staticpro (&Vcached_fontset_data
);
2408 Vfontset_table
= Fmake_vector (make_number (32), Qnil
);
2409 staticpro (&Vfontset_table
);
2411 Vdefault_fontset
= Fmake_char_table (Qfontset
, Qnil
);
2412 staticpro (&Vdefault_fontset
);
2413 FONTSET_ID (Vdefault_fontset
) = make_number (0);
2414 FONTSET_NAME (Vdefault_fontset
)
2415 = build_string ("-*-*-*-*-*-*-*-*-*-*-*-*-fontset-default");
2416 AREF (Vfontset_table
, 0) = Vdefault_fontset
;
2417 next_fontset_id
= 1;
2419 auto_fontset_alist
= Qnil
;
2420 staticpro (&auto_fontset_alist
);
2422 DEFVAR_LISP ("font-encoding-alist", &Vfont_encoding_alist
,
2424 Alist of fontname patterns vs the corresponding encoding and repertory info.
2425 Each element looks like (REGEXP . (ENCODING . REPERTORY)),
2426 where ENCODING is a charset or a char-table,
2427 and REPERTORY is a charset, a char-table, or nil.
2429 ENCODING is for converting a character to a glyph code of the font.
2430 If ENCODING is a charset, encoding a character by the charset gives
2431 the corresponding glyph code. If ENCODING is a char-table, looking up
2432 the table by a character gives the corresponding glyph code.
2434 REPERTORY specifies a repertory of characters supported by the font.
2435 If REPERTORY is a charset, all characters beloging to the charset are
2436 supported. If REPERTORY is a char-table, all characters who have a
2437 non-nil value in the table are supported. It REPERTORY is nil, Emacs
2438 gets the repertory information by an opened font and ENCODING. */);
2439 Vfont_encoding_alist
= Qnil
;
2441 DEFVAR_LISP ("use-default-ascent", &Vuse_default_ascent
,
2443 Char table of characters whose ascent values should be ignored.
2444 If an entry for a character is non-nil, the ascent value of the glyph
2445 is assumed to be what specified by _MULE_DEFAULT_ASCENT property of a font.
2447 This affects how a composite character which contains
2448 such a character is displayed on screen. */);
2449 Vuse_default_ascent
= Qnil
;
2451 DEFVAR_LISP ("ignore-relative-composition", &Vignore_relative_composition
,
2453 Char table of characters which is not composed relatively.
2454 If an entry for a character is non-nil, a composition sequence
2455 which contains that character is displayed so that
2456 the glyph of that character is put without considering
2457 an ascent and descent value of a previous character. */);
2458 Vignore_relative_composition
= Qnil
;
2460 DEFVAR_LISP ("alternate-fontname-alist", &Valternate_fontname_alist
,
2461 doc
: /* Alist of fontname vs list of the alternate fontnames.
2462 When a specified font name is not found, the corresponding
2463 alternate fontnames (if any) are tried instead. */);
2464 Valternate_fontname_alist
= Qnil
;
2466 DEFVAR_LISP ("fontset-alias-alist", &Vfontset_alias_alist
,
2467 doc
: /* Alist of fontset names vs the aliases. */);
2468 Vfontset_alias_alist
= Fcons (Fcons (FONTSET_NAME (Vdefault_fontset
),
2469 build_string ("fontset-default")),
2472 DEFVAR_LISP ("vertical-centering-font-regexp",
2473 &Vvertical_centering_font_regexp
,
2474 doc
: /* *Regexp matching font names that require vertical centering on display.
2475 When a character is displayed with such fonts, the character is displayed
2476 at the vertical center of lines. */);
2477 Vvertical_centering_font_regexp
= Qnil
;
2479 DEFVAR_LISP ("otf-script-alist", &Votf_script_alist
,
2480 doc
: /* Alist of OpenType script tags vs the corresponding script names. */);
2481 Votf_script_alist
= Qnil
;
2483 defsubr (&Squery_fontset
);
2484 defsubr (&Snew_fontset
);
2485 defsubr (&Sset_fontset_font
);
2486 defsubr (&Sfont_info
);
2487 defsubr (&Sinternal_char_font
);
2488 defsubr (&Sfontset_info
);
2489 defsubr (&Sfontset_font
);
2490 defsubr (&Sfontset_list
);
2491 #ifdef FONTSET_DEBUG
2492 defsubr (&Sfontset_list_all
);
2496 /* arch-tag: ea861585-2f5f-4e5b-9849-d04a9c3a3537
2497 (do not change this comment) */