2 Copyright (C) 1995, 1997, 2000 Electrotechnical Laboratory, JAPAN.
3 Licensed to the Free Software Foundation.
4 Copyright (C) 2001, 2002
5 National Institute of Advanced Industrial Science and Technology (AIST)
6 Registration Number H13PRO009
8 This file is part of GNU Emacs.
10 GNU Emacs is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 GNU Emacs is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GNU Emacs; see the file COPYING. If not, write to
22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* #define FONTSET_DEBUG */
34 #include "blockinput.h"
36 #include "character.h"
41 #include "dispextern.h"
47 #define xassert(X) do {if (!(X)) abort ();} while (0)
55 A fontset is a collection of font related information to give
56 similar appearance (style, etc) of characters. There are two kinds
57 of fontsets; base and realized. A base fontset is created by
58 `new-fontset' from Emacs Lisp explicitly. A realized fontset is
59 created implicitly when a face is realized for ASCII characters. A
60 face is also realized for non-ASCII characters based on an ASCII
61 face. All of non-ASCII faces based on the same ASCII face share
62 the same realized fontset.
64 A fontset object is implemented by a char-table whose default value
65 and parent are always nil.
67 An element of a base fontset is a font specification of the form:
68 [ FAMILY WEIGHT SLANT SWIDTH REGISTRY ] (vector of size 5)
72 FAMILY and REGISTRY are strings.
74 WEIGHT, SLANT, and SWIDTH must be symbols that set-face-attribute
75 accepts as attribute values for :weight, :slant, :swidth
79 A fontset has 7 extra slots.
81 The 1st slot is an ID number of the fontset.
83 The 2nd slot is a name of the fontset in a base fontset, and nil in
86 The 3rd slot is nil in a base fontset, and a base fontset in a
89 The 4th slot is a frame that the fontset belongs to. This is nil
92 The 5th slot is a cons of 0 and fontname for ASCII characters in a
93 base fontset, and nil in a realized face.
95 The 6th slot is an alist of a charset vs. the corresponding font
98 The 7th slot is an alist of a font specification vs. the
99 corresponding face ID. In a base fontset, the face IDs are all
102 All fontsets are recorded in Vfontset_table.
107 There's a special fontset named `default fontset' which defines the
108 default font specifications. When a base fontset doesn't specify a
109 font for a specific character, the corresponding value in the
110 default fontset is used. The format is the same as a base fontset.
112 The parent of a realized fontset created for such a face that has
113 no fontset is the default fontset.
116 These structures are hidden from the other codes than this file.
117 The other codes handle fontsets only by their ID numbers. They
118 usually use the variable name `fontset' for IDs. But, in this
119 file, we always use varialbe name `id' for IDs, and name `fontset'
120 for the actual fontset objects (i.e. char-table objects).
124 /********** VARIABLES and FUNCTION PROTOTYPES **********/
126 extern Lisp_Object Qfont
;
127 Lisp_Object Qfontset
;
129 /* Vector containing all fontsets. */
130 static Lisp_Object Vfontset_table
;
132 /* Next possibly free fontset ID. Usually this keeps the minimum
133 fontset ID not yet used. */
134 static int next_fontset_id
;
136 /* The default fontset. This gives default FAMILY and REGISTRY of
137 font for each character. */
138 static Lisp_Object Vdefault_fontset
;
140 Lisp_Object Vfont_encoding_alist
;
141 Lisp_Object Vuse_default_ascent
;
142 Lisp_Object Vignore_relative_composition
;
143 Lisp_Object Valternate_fontname_alist
;
144 Lisp_Object Vfontset_alias_alist
;
145 Lisp_Object Vvertical_centering_font_regexp
;
147 /* The following six are declarations of callback functions depending
148 on window system. See the comments in src/fontset.h for more
151 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
152 struct font_info
*(*get_font_info_func
) P_ ((FRAME_PTR f
, int font_idx
));
154 /* Return a list of font names which matches PATTERN. See the documentation
155 of `x-list-fonts' for more details. */
156 Lisp_Object (*list_fonts_func
) P_ ((struct frame
*f
,
161 /* Load a font named NAME for frame F and return a pointer to the
162 information of the loaded font. If loading is failed, return 0. */
163 struct font_info
*(*load_font_func
) P_ ((FRAME_PTR f
, char *name
, int));
165 /* Return a pointer to struct font_info of a font named NAME for frame F. */
166 struct font_info
*(*query_font_func
) P_ ((FRAME_PTR f
, char *name
));
168 /* Additional function for setting fontset or changing fontset
169 contents of frame F. */
170 void (*set_frame_fontset_func
) P_ ((FRAME_PTR f
, Lisp_Object arg
,
171 Lisp_Object oldval
));
173 /* To find a CCL program, fs_load_font calls this function.
174 The argument is a pointer to the struct font_info.
175 This function set the member `encoder' of the structure. */
176 void (*find_ccl_program_func
) P_ ((struct font_info
*));
178 /* Check if any window system is used now. */
179 void (*check_window_system_func
) P_ ((void));
182 /* Prototype declarations for static functions. */
183 static Lisp_Object make_fontset
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
));
184 static int fontset_id_valid_p
P_ ((int));
185 static Lisp_Object fontset_pattern_regexp
P_ ((Lisp_Object
));
188 /********** MACROS AND FUNCTIONS TO HANDLE FONTSET **********/
190 /* Return the fontset with ID. No check of ID's validness. */
191 #define FONTSET_FROM_ID(id) AREF (Vfontset_table, id)
193 /* Macros to access special values of FONTSET. */
194 #define FONTSET_ID(fontset) XCHAR_TABLE (fontset)->extras[0]
196 /* Macros to access special values of (base) FONTSET. */
197 #define FONTSET_NAME(fontset) XCHAR_TABLE (fontset)->extras[1]
198 #define FONTSET_ASCII(fontset) XCHAR_TABLE (fontset)->extras[4]
200 #define BASE_FONTSET_P(fontset) STRINGP (FONTSET_NAME (fontset))
202 /* Macros to access special values of (realized) FONTSET. */
203 #define FONTSET_BASE(fontset) XCHAR_TABLE (fontset)->extras[2]
204 #define FONTSET_FRAME(fontset) XCHAR_TABLE (fontset)->extras[3]
205 #define FONTSET_CHARSET_ALIST(fontset) XCHAR_TABLE (fontset)->extras[5]
206 #define FONTSET_FACE_ALIST(fontset) XCHAR_TABLE (fontset)->extras[6]
209 /* Return the element of FONTSET (char-table) at index C (character). */
211 #define FONTSET_REF(fontset, c, etl) ((elt) = fontset_ref ((fontset), (c)))
214 fontset_ref (fontset
, c
)
222 elt
= CHAR_TABLE_REF (fontset
, c
);
223 if (NILP (elt
) && ASCII_CHAR_P (c
))
224 elt
= FONTSET_ASCII (fontset
);
228 struct charset
*charset
;
230 for (tail
= FONTSET_CHARSET_ALIST (fontset
);
231 CONSP (tail
); tail
= XCDR (tail
))
233 charset
= CHARSET_FROM_ID (XCAR (XCAR (tail
)));
234 if (ENCODE_CHAR (charset
, c
) != CHARSET_INVALID_CODE (charset
))
236 elt
= XCDR (XCAR (tail
));
241 if (! NILP (elt
) || EQ (fontset
, Vdefault_fontset
))
243 fontset
= Vdefault_fontset
;
249 /* Set the element of FONTSET at index IDX to the value ELT. IDX may
250 be a character or a charset. */
252 #define FONTSET_SET(fontset, c, newelt) fontset_set(fontset, c, newelt)
255 fontset_set (fontset
, idx
, elt
)
256 Lisp_Object fontset
, idx
, elt
;
260 Lisp_Object id
, slot
, tail
;
262 id
= make_number (CHARSET_SYMBOL_ID (idx
));
263 if (id
== charset_ascii
)
264 Fset_char_table_range (fontset
,
265 Fcons (make_number (0), make_number (127)),
269 slot
= Fassq (id
, FONTSET_CHARSET_ALIST (fontset
));
272 else if (CONSP (FONTSET_CHARSET_ALIST (fontset
)))
274 for (tail
= FONTSET_CHARSET_ALIST (fontset
);
275 CONSP (XCDR (tail
)); tail
= XCDR (tail
));
276 XCDR (tail
) = Fcons (Fcons (id
, elt
), Qnil
);
279 FONTSET_CHARSET_ALIST (fontset
) = Fcons (Fcons (id
, elt
), Qnil
);
284 int from
= XINT (XCAR (idx
));
285 int to
= XINT (XCDR (idx
));
288 CHAR_TABLE_SET (fontset
, from
, elt
);
290 Fset_char_table_range (fontset
, idx
, elt
);
295 /* Return a face registerd in the realized fontset FONTSET for the
296 character C. Return -1 if a face ID is not yet set. */
299 fontset_face (fontset
, c
)
303 Lisp_Object base
, elt
;
307 base
= FONTSET_BASE (fontset
);
308 FONTSET_REF (base
, c
, elt
);
313 elt
= Fassoc (elt
, FONTSET_FACE_ALIST (fontset
));
316 id
= XINT (XCDR (elt
));
317 face
= FACE_FROM_ID (XFRAME (FONTSET_FRAME (fontset
)), id
);
322 /* Return a newly created fontset with NAME. If BASE is nil, make a
323 base fontset. Otherwise make a realized fontset whose base is
327 make_fontset (frame
, name
, base
)
328 Lisp_Object frame
, name
, base
;
331 int size
= ASIZE (Vfontset_table
);
332 int id
= next_fontset_id
;
334 /* Find a free slot in Vfontset_table. Usually, next_fontset_id is
335 the next available fontset ID. So it is expected that this loop
336 terminates quickly. In addition, as the last element of
337 Vfontset_table is always nil, we don't have to check the range of
339 while (!NILP (AREF (Vfontset_table
, id
))) id
++;
346 tem
= Fmake_vector (make_number (size
+ 32), Qnil
);
347 for (i
= 0; i
< size
; i
++)
348 AREF (tem
, i
) = AREF (Vfontset_table
, i
);
349 Vfontset_table
= tem
;
352 fontset
= Fmake_char_table (Qfontset
, Qnil
);
354 FONTSET_ID (fontset
) = make_number (id
);
357 FONTSET_NAME (fontset
) = name
;
361 FONTSET_NAME (fontset
) = Qnil
;
362 FONTSET_FRAME (fontset
) = frame
;
363 FONTSET_BASE (fontset
) = base
;
366 ASET (Vfontset_table
, id
, fontset
);
367 next_fontset_id
= id
+ 1;
373 /********** INTERFACES TO xfaces.c and dispextern.h **********/
375 /* Return name of the fontset with ID. */
383 fontset
= FONTSET_FROM_ID (id
);
384 return FONTSET_NAME (fontset
);
388 /* Return ASCII font name of the fontset with ID. */
396 fontset
= FONTSET_FROM_ID (id
);
397 return FONTSET_ASCII (fontset
);
401 /* Free fontset of FACE defined on frame F. Called from
402 free_realized_face. */
405 free_face_fontset (f
, face
)
409 AREF (Vfontset_table
, face
->fontset
) = Qnil
;
410 if (face
->fontset
< next_fontset_id
)
411 next_fontset_id
= face
->fontset
;
415 /* Return 1 iff FACE is suitable for displaying character C.
416 Otherwise return 0. Called from the macro FACE_SUITABLE_FOR_CHAR_P
417 when C is not an ASCII character. */
420 face_suitable_for_char_p (face
, c
)
426 fontset
= FONTSET_FROM_ID (face
->fontset
);
427 return (face
== fontset_face (fontset
, c
));
431 /* Return ID of face suitable for displaying character C on frame F.
432 The selection of face is done based on the fontset of FACE. FACE
433 must be reazlied for ASCII characters in advance. Called from the
434 macro FACE_FOR_CHAR when C is not an ASCII character. */
437 face_for_char (f
, face
, c
)
442 Lisp_Object fontset
, elt
;
443 struct face
*new_face
;
445 xassert (fontset_id_valid_p (face
->fontset
));
446 fontset
= FONTSET_FROM_ID (face
->fontset
);
447 xassert (!BASE_FONTSET_P (fontset
));
449 new_face
= fontset_face (fontset
, c
);
453 /* No face is recorded for C in the fontset of FACE. Make a new
454 realized face for C that has the same fontset. */
455 return lookup_face (f
, face
->lface
, c
, face
);
459 /* Make a realized fontset for ASCII face FACE on frame F from the
460 base fontset BASE_FONTSET_ID. If BASE_FONTSET_ID is -1, use the
461 default fontset as the base. Value is the id of the new fontset.
462 Called from realize_x_face. */
465 make_fontset_for_ascii_face (f
, base_fontset_id
)
469 Lisp_Object base_fontset
, fontset
, frame
;
471 XSETFRAME (frame
, f
);
472 if (base_fontset_id
>= 0)
474 base_fontset
= FONTSET_FROM_ID (base_fontset_id
);
475 if (!BASE_FONTSET_P (base_fontset
))
476 base_fontset
= FONTSET_BASE (base_fontset
);
477 xassert (BASE_FONTSET_P (base_fontset
));
480 base_fontset
= Vdefault_fontset
;
482 fontset
= make_fontset (frame
, Qnil
, base_fontset
);
483 return XINT (FONTSET_ID (fontset
));
487 /* Return FONT-SPEC recorded in the fontset of FACE for character C.
488 If FACE is null, or the fontset doesn't contain information about
489 C, get the font name pattern from the default fontset. Called from
493 fontset_font_pattern (f
, face
, c
)
498 Lisp_Object fontset
, base
, elt
;
499 int id
= face
? face
->fontset
: -1;
503 fontset
= FONTSET_FROM_ID (id
);
504 xassert (!BASE_FONTSET_P (fontset
));
505 base
= FONTSET_BASE (fontset
);
509 base
= Vdefault_fontset
;
512 FONTSET_REF (base
, c
, elt
);
513 if (face
&& ! NILP (elt
))
517 slot
= Fassoc (elt
, FONTSET_FACE_ALIST (fontset
));
519 XSETCDR (slot
, make_number (face
->id
));
520 FONTSET_FACE_ALIST (fontset
)
521 = Fcons (Fcons (elt
, make_number (face
->id
)),
522 FONTSET_FACE_ALIST (fontset
));
528 #if defined(WINDOWSNT) && defined (_MSC_VER)
529 #pragma optimize("", off)
532 /* Load a font named FONTNAME on frame F. Return a pointer to the
533 struct font_info of the loaded font. If loading fails, return
537 fs_load_font (f
, fontname
)
541 Lisp_Object tail
, elt
;
542 struct font_info
*fontp
;
545 /* No way to get fontname. */
548 fontp
= (*load_font_func
) (f
, fontname
, 0);
552 /* Fill in members (charset, vertical_centering, encoding, etc) of
553 font_info structure that are not set by (*load_font_func). */
554 for (tail
= Vfont_encoding_alist
; CONSP (tail
); tail
= XCDR (tail
))
557 if (STRINGP (XCAR (elt
)) && CHARSETP (XCDR (elt
))
558 && fast_c_string_match_ignore_case (XCAR (elt
), fontname
) >= 0)
560 fontp
->charset
= CHARSET_SYMBOL_ID (XCDR (elt
));
567 fontp
->vertical_centering
568 = (STRINGP (Vvertical_centering_font_regexp
)
569 && (fast_c_string_match_ignore_case
570 (Vvertical_centering_font_regexp
, fontp
->full_name
) >= 0));
572 fontp
->font_encoder
= NULL
;
574 if (find_ccl_program_func
)
575 (*find_ccl_program_func
) (fontp
);
580 #if defined(WINDOWSNT) && defined (_MSC_VER)
581 #pragma optimize("", on)
585 /* Cache data used by fontset_pattern_regexp. The car part is a
586 pattern string containing at least one wild card, the cdr part is
587 the corresponding regular expression. */
588 static Lisp_Object Vcached_fontset_data
;
590 #define CACHED_FONTSET_NAME (XSTRING (XCAR (Vcached_fontset_data))->data)
591 #define CACHED_FONTSET_REGEX (XCDR (Vcached_fontset_data))
593 /* If fontset name PATTERN contains any wild card, return regular
594 expression corresponding to PATTERN. */
597 fontset_pattern_regexp (pattern
)
600 if (!index (XSTRING (pattern
)->data
, '*')
601 && !index (XSTRING (pattern
)->data
, '?'))
602 /* PATTERN does not contain any wild cards. */
605 if (!CONSP (Vcached_fontset_data
)
606 || strcmp (XSTRING (pattern
)->data
, CACHED_FONTSET_NAME
))
608 /* We must at first update the cached data. */
609 char *regex
= (char *) alloca (XSTRING (pattern
)->size
* 2 + 3);
610 char *p0
, *p1
= regex
;
612 /* Convert "*" to ".*", "?" to ".". */
614 for (p0
= (char *) XSTRING (pattern
)->data
; *p0
; p0
++)
629 Vcached_fontset_data
= Fcons (build_string (XSTRING (pattern
)->data
),
630 build_string (regex
));
633 return CACHED_FONTSET_REGEX
;
636 /* Return ID of the base fontset named NAME. If there's no such
637 fontset, return -1. */
640 fs_query_fontset (name
, regexpp
)
647 name
= Fdowncase (name
);
650 tem
= Frassoc (name
, Vfontset_alias_alist
);
651 if (CONSP (tem
) && STRINGP (XCAR (tem
)))
655 tem
= fontset_pattern_regexp (name
);
664 for (i
= 0; i
< ASIZE (Vfontset_table
); i
++)
667 unsigned char *this_name
;
669 fontset
= FONTSET_FROM_ID (i
);
671 || !BASE_FONTSET_P (fontset
))
674 this_name
= XSTRING (FONTSET_NAME (fontset
))->data
;
676 ? fast_c_string_match_ignore_case (name
, this_name
) >= 0
677 : !strcmp (XSTRING (name
)->data
, this_name
))
684 DEFUN ("query-fontset", Fquery_fontset
, Squery_fontset
, 1, 2, 0,
685 doc
: /* Return the name of a fontset that matches PATTERN.
686 The value is nil if there is no matching fontset.
687 PATTERN can contain `*' or `?' as a wildcard
688 just as X font name matching algorithm allows.
689 If REGEXPP is non-nil, PATTERN is a regular expression. */)
691 Lisp_Object pattern
, regexpp
;
696 (*check_window_system_func
) ();
698 CHECK_STRING (pattern
);
700 if (XSTRING (pattern
)->size
== 0)
703 id
= fs_query_fontset (pattern
, !NILP (regexpp
));
707 fontset
= FONTSET_FROM_ID (id
);
708 return FONTSET_NAME (fontset
);
711 /* Return a list of base fontset names matching PATTERN on frame F. */
714 list_fontsets (f
, pattern
, size
)
719 Lisp_Object frame
, regexp
, val
;
722 XSETFRAME (frame
, f
);
724 regexp
= fontset_pattern_regexp (pattern
);
727 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
732 fontset
= FONTSET_FROM_ID (id
);
734 || !BASE_FONTSET_P (fontset
)
735 || !EQ (frame
, FONTSET_FRAME (fontset
)))
737 name
= XSTRING (FONTSET_NAME (fontset
))->data
;
740 ? (fast_c_string_match_ignore_case (regexp
, name
) < 0)
741 : strcmp (XSTRING (pattern
)->data
, name
))
744 val
= Fcons (Fcopy_sequence (FONTSET_NAME (fontset
)), val
);
751 /* Free all realized fontsets whose base fontset is BASE. */
754 free_realized_fontsets (base
)
760 /* For the moment, this doesn't work because free_realized_face
761 doesn't remove FACE from a cache. Until we find a solution, we
762 suppress this code, and simply use Fclear_face_cache even though
763 that is not efficient. */
765 for (id
= 0; id
< ASIZE (Vfontset_table
); id
++)
767 Lisp_Object
this = AREF (Vfontset_table
, id
);
769 if (EQ (FONTSET_BASE (this), base
))
773 for (tail
= FONTSET_FACE_ALIST (this); CONSP (tail
);
776 FRAME_PTR f
= XFRAME (FONTSET_FRAME (this));
777 int face_id
= XINT (XCDR (XCAR (tail
)));
778 struct face
*face
= FACE_FROM_ID (f
, face_id
);
780 /* Face THIS itself is also freed by the following call. */
781 free_realized_face (f
, face
);
787 Fclear_face_cache (Qt
);
792 /* Check validity of NAME as a fontset name and return the
793 corresponding fontset. If not valid, signal an error.
794 If NAME is t, return Vdefault_fontset. */
797 check_fontset_name (name
)
803 return Vdefault_fontset
;
806 id
= fs_query_fontset (name
, 0);
808 error ("Fontset `%s' does not exist", XSTRING (name
)->data
);
809 return FONTSET_FROM_ID (id
);
812 DEFUN ("set-fontset-font", Fset_fontset_font
, Sset_fontset_font
, 3, 4, 0,
813 doc
: /* Modify fontset NAME to use FONT-SPEC for characters of CHARSETS.
815 CHARSET may be a cons; (FROM . TO), where FROM and TO are characters.
816 In that case, use FONT-SPEC for all characters in the range FROM and
819 FONT-SPEC is be a vector; [ FAMILY WEIGHT SLANT WIDTH ADSTYLE REGISTRY ]
821 FONT-SPEC may be a cons; (FAMILY . REGISTRY), where FAMILY is a family
822 name of a font, REGSITRY is a registry name of a font.
824 FONT-SPEC may be a font name string. */)
825 (name
, charset
, font_spec
, frame
)
826 Lisp_Object name
, charset
, font_spec
, frame
;
829 Lisp_Object family
, registry
;
832 fontset
= check_fontset_name (name
);
834 if (VECTORP (font_spec
))
839 font_spec
= Fcopy_sequence (font_spec
);
840 for (i
= 0; i
< 5; i
++)
842 val
= Faref (font_spec
, make_number (i
));
846 ASET (font_spec
, i
, Fdowncase (val
));
849 val
= Faref (font_spec
, make_number (5));
851 ASET (font_spec
, 5, Fdowncase (val
));
853 else if (STRINGP (font_spec
))
854 font_spec
= Fdowncase (font_spec
);
855 else if (CONSP (font_spec
))
857 CHECK_CONS (font_spec
);
858 family
= XCAR (font_spec
);
859 registry
= XCDR (font_spec
);
860 font_spec
= Fmake_vector (make_number (6), Qnil
);
863 CHECK_STRING (family
);
864 ASET (font_spec
, 0, Fdowncase (family
));
866 CHECK_STRING (registry
);
867 ASET (font_spec
, 5, Fdowncase (registry
));
870 if (SYMBOLP (charset
))
872 CHECK_CHARSET (charset
);
876 Lisp_Object from
, to
;
878 /* CHARSET should be (FROM . TO). */
879 from
= Fcar (charset
);
881 CHECK_CHARACTER (from
);
882 CHECK_CHARACTER (to
);
885 /* The arg FRAME is kept for backward compatibility. We only check
888 CHECK_LIVE_FRAME (frame
);
890 FONTSET_SET (fontset
, charset
, font_spec
);
892 /* Free all realized fontsets whose base is FONTSET. This way, the
893 specified character(s) are surely redisplayed by a correct
895 free_realized_fontsets (fontset
);
901 DEFUN ("new-fontset", Fnew_fontset
, Snew_fontset
, 2, 2, 0,
902 doc
: /* Create a new fontset NAME from font information in FONTLIST.
904 FONTLIST is an alist of charsets vs corresponding font specifications.
905 Each element of FONTLIST has the form (CHARSET . FONT-SPEC), where
906 a character of CHARSET is displayed by a font that matches FONT-SPEC.
908 FONT-SPEC is a vector [ FAMILY WEIGHT SLANT WIDTH ADSTYLE REGISTRY ], where
909 FAMILY is a string specifying the font family,
910 WEIGHT is a string specifying the weight of the font,
911 SLANT is a string specifying the slant of the font,
912 WIDTH is a string specifying the width of the font,
913 ADSTYLE is a string specifying the adstyle of the font,
914 REGISTRY is a string specifying the charset-registry of the font.
916 See also the documentation of `set-face-attribute' for the detail of
917 these vector elements.
919 FONT-SPEC may be a font name (string). */)
921 Lisp_Object name
, fontlist
;
923 Lisp_Object fontset
, ascii_font
;
924 Lisp_Object tem
, tail
;
927 CHECK_LIST (fontlist
);
929 name
= Fdowncase (name
);
930 tem
= Fquery_fontset (name
, Qnil
);
932 free_realized_fontsets (tem
);
934 fontset
= make_fontset (Qnil
, name
, Qnil
);
936 /* Check the validity of FONTLIST. */
937 ascii_font
= Fcdr (Fassq (Qascii
, fontlist
));
938 if (NILP (ascii_font
))
939 error ("No ascii font specified");
940 if (! STRINGP (ascii_font
))
941 ascii_font
= generate_ascii_font (name
, ascii_font
);
943 fontlist
= Fcopy_sequence (fontlist
);
944 for (tail
= fontlist
; ! NILP (tail
); tail
= Fcdr (tail
))
945 Fset_fontset_font (name
, Fcar (Fcar (tail
)), Fcdr (Fcar (tail
)), Qnil
);
947 FONTSET_ASCII (fontset
) = ascii_font
;
953 DEFUN ("font-info", Ffont_info
, Sfont_info
, 1, 2, 0,
954 doc
: /* Return information about a font named NAME on frame FRAME.
955 If FRAME is omitted or nil, use the selected frame.
956 The returned value is a vector of OPENED-NAME, FULL-NAME, CHARSET, SIZE,
957 HEIGHT, BASELINE-OFFSET, RELATIVE-COMPOSE, and DEFAULT-ASCENT,
959 OPENED-NAME is the name used for opening the font,
960 FULL-NAME is the full name of the font,
961 SIZE is the maximum bound width of the font,
962 HEIGHT is the height of the font,
963 BASELINE-OFFSET is the upward offset pixels from ASCII baseline,
964 RELATIVE-COMPOSE and DEFAULT-ASCENT are the numbers controlling
965 how to compose characters.
966 If the named font is not yet loaded, return nil. */)
968 Lisp_Object name
, frame
;
971 struct font_info
*fontp
;
974 (*check_window_system_func
) ();
977 name
= Fdowncase (name
);
979 frame
= selected_frame
;
980 CHECK_LIVE_FRAME (frame
);
983 if (!query_font_func
)
984 error ("Font query function is not supported");
986 fontp
= (*query_font_func
) (f
, XSTRING (name
)->data
);
990 info
= Fmake_vector (make_number (7), Qnil
);
992 XVECTOR (info
)->contents
[0] = build_string (fontp
->name
);
993 XVECTOR (info
)->contents
[1] = build_string (fontp
->full_name
);
994 XVECTOR (info
)->contents
[2] = make_number (fontp
->size
);
995 XVECTOR (info
)->contents
[3] = make_number (fontp
->height
);
996 XVECTOR (info
)->contents
[4] = make_number (fontp
->baseline_offset
);
997 XVECTOR (info
)->contents
[5] = make_number (fontp
->relative_compose
);
998 XVECTOR (info
)->contents
[6] = make_number (fontp
->default_ascent
);
1004 /* Return the font name for the character at POSITION in the current
1005 buffer. This is computed from all the text properties and overlays
1006 that apply to POSITION. It returns nil in the following cases:
1008 (1) The window system doesn't have a font for the character (thus
1009 it is displayed by an empty box).
1011 (2) The character code is invalid.
1013 (3) The current buffer is not displayed in any window.
1015 In addition, the returned font name may not take into account of
1016 such redisplay engine hooks as what used in jit-lock-mode if
1017 POSITION is currently not visible. */
1020 DEFUN ("internal-char-font", Finternal_char_font
, Sinternal_char_font
, 1, 1, 0,
1021 doc
: /* For internal use only. */)
1023 Lisp_Object position
;
1025 int pos
, pos_byte
, dummy
;
1033 CHECK_NUMBER_COERCE_MARKER (position
);
1034 pos
= XINT (position
);
1035 if (pos
< BEGV
|| pos
>= ZV
)
1036 args_out_of_range_3 (position
, make_number (BEGV
), make_number (ZV
));
1037 pos_byte
= CHAR_TO_BYTE (pos
);
1038 c
= FETCH_CHAR (pos_byte
);
1039 window
= Fget_buffer_window (Fcurrent_buffer (), Qnil
);
1042 w
= XWINDOW (window
);
1043 f
= XFRAME (w
->frame
);
1044 face_id
= face_at_buffer_position (w
, pos
, -1, -1, &dummy
, pos
+ 100, 0);
1045 face_id
= FACE_FOR_CHAR (f
, FACE_FROM_ID (f
, face_id
), c
);
1046 face
= FACE_FROM_ID (f
, face_id
);
1047 return (face
->font
&& face
->font_name
1048 ? build_string (face
->font_name
)
1053 /* Called from Ffontset_info via map_char_table on each leaf of
1054 fontset. ARG is a list (LAST FONT-INFO ...), where LAST is `(last
1055 ARG)' and FONT-INFOs have this form:
1056 (CHAR FONT-SPEC) or ((FROM . TO) FONT-SPEC)
1057 The current leaf is indexed by CHARACTER and has value ELT. This
1058 function add the information of the current leaf to ARG by
1059 appending a new element or modifying the last element.. */
1062 accumulate_font_info (arg
, character
, elt
)
1063 Lisp_Object arg
, character
, elt
;
1065 Lisp_Object last
, last_char
, last_elt
;
1067 if (!CONSP (elt
) && !SINGLE_BYTE_CHAR_P (XINT (character
)))
1068 FONTSET_REF (Vdefault_fontset
, XINT (character
), elt
);
1072 last_char
= XCAR (XCAR (last
));
1073 last_elt
= XCAR (XCDR (XCAR (last
)));
1075 if (!NILP (Fequal (elt
, last_elt
)))
1077 struct charset
*this_charset
= CHAR_CHARSET (XINT (character
));
1079 if (CONSP (last_char
)) /* LAST_CHAR == (FROM . TO) */
1081 if (this_charset
== CHAR_CHARSET (XINT (XCAR (last_char
))))
1083 XSETCDR (last_char
, character
);
1087 else if (XINT (last_char
) == XINT (character
))
1089 else if (this_charset
== CHAR_CHARSET (XINT (last_char
)))
1091 XSETCAR (XCAR (last
), Fcons (last_char
, character
));
1095 XSETCDR (last
, Fcons (Fcons (character
, Fcons (elt
, Qnil
)), Qnil
));
1096 XSETCAR (arg
, XCDR (last
));
1100 DEFUN ("fontset-info", Ffontset_info
, Sfontset_info
, 1, 2, 0,
1101 doc
: /* Return information about a fontset named NAME on frame FRAME.
1102 The value is a vector:
1103 [ SIZE HEIGHT ((CHARSET-OR-RANGE FONT-SPEC OPENED ...) ...) ],
1105 SIZE is the maximum bound width of ASCII font in the fontset,
1106 HEIGHT is the maximum bound height of ASCII font in the fontset,
1107 CHARSET-OR-RANGE is a charset or a cons of two characters specifying
1108 the range of characters.
1109 FONT-SPEC is a fontname pattern string or a vector
1110 [ FAMILY WEIGHT SLANT ADSTYLE REGISTRY ].
1111 See the documentation of `new-fontset' for the meanings those elements.
1112 OPENEDs are names of fonts actually opened.
1113 If the ASCII font is not yet opened, SIZE and HEIGHT are 0.
1114 If FRAME is omitted, it defaults to the currently selected frame. */)
1116 Lisp_Object name
, frame
;
1118 Lisp_Object fontset
;
1120 Lisp_Object val
, tail
, elt
;
1121 Lisp_Object
*realized
;
1122 struct font_info
*fontp
= NULL
;
1126 (*check_window_system_func
) ();
1128 fontset
= check_fontset_name (name
);
1131 frame
= selected_frame
;
1132 CHECK_LIVE_FRAME (frame
);
1135 /* Recode realized fontsets whose base is FONTSET in the table
1137 realized
= (Lisp_Object
*) alloca (sizeof (Lisp_Object
)
1138 * ASIZE (Vfontset_table
));
1139 for (i
= 0; i
< ASIZE (Vfontset_table
); i
++)
1141 elt
= FONTSET_FROM_ID (i
);
1143 && EQ (FONTSET_BASE (elt
), fontset
))
1144 realized
[n_realized
++] = elt
;
1147 /* Accumulate information of the fontset in VAL. The format is
1148 (LAST FONT-INFO FONT-INFO ...), where FONT-INFO is (CHAR-OR-RANGE
1149 FONT-SPEC). See the comment for accumulate_font_info for the
1151 val
= Fcons (Fcons (Qascii
, Fcons (FONTSET_ASCII (fontset
), Qnil
)), Qnil
);
1152 val
= Fcons (val
, val
);
1153 for (i
= 128; i
<= MAX_CHAR
; )
1158 elt
= char_table_ref_and_range (fontset
, i
, &from
, &to
);
1161 elt
= Fcons (Fcons (make_number (from
), make_number (to
)),
1163 XSETCDR (XCAR (val
), Fcons (elt
, Qnil
));
1164 XSETCAR (val
, XCDR (XCAR (val
)));
1169 for (tail
= FONTSET_CHARSET_ALIST (fontset
);
1170 CONSP (tail
); tail
= XCDR (tail
))
1173 elt
= Fcons (XCAR (elt
), Fcons (XCDR (elt
), Qnil
));
1174 XSETCDR (XCAR (val
), Fcons (elt
, Qnil
));
1175 XSETCAR (val
, XCDR (XCAR (val
)));
1180 /* If fonts are opened for FONT-SPEC, append the names of the fonts to
1182 for (tail
= val
; CONSP (tail
); tail
= XCDR (tail
))
1187 for (i
= 0; i
< n_realized
; i
++)
1191 Lisp_Object face_list
, fontname
;
1193 for (face_list
= FONTSET_FACE_ALIST (realized
[i
]);
1194 CONSP (face_list
); face_list
= XCDR (face_list
))
1196 int face_id
= XINT (XCDR (XCAR (face_list
)));
1197 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1199 if (face
->font
&& face
->font_name
)
1201 fontname
= build_string (face
->font_name
);
1202 if (NILP (Fmember (fontname
, XCDR (XCDR (elt
)))))
1203 XSETCDR (XCDR (elt
), Fcons (fontname
, XCDR (XCDR (elt
))));
1209 elt
= XCDR (XCDR (XCAR (val
)));
1211 fontp
= (*query_font_func
) (f
, XSTRING (XCAR (elt
))->data
);
1212 val
= Fmake_vector (make_number (3), val
);
1213 AREF (val
, 0) = fontp
? make_number (fontp
->size
) : make_number (0);
1214 AREF (val
, 1) = fontp
? make_number (fontp
->height
) : make_number (0);
1218 DEFUN ("fontset-font", Ffontset_font
, Sfontset_font
, 2, 2, 0,
1219 doc
: /* Return a font name pattern for character CH in fontset NAME.
1220 If NAME is t, find a font name pattern in the default fontset. */)
1222 Lisp_Object name
, ch
;
1225 Lisp_Object fontset
, elt
;
1227 fontset
= check_fontset_name (name
);
1229 CHECK_CHARACTER (ch
);
1231 FONTSET_REF (fontset
, c
, elt
);
1235 DEFUN ("fontset-list", Ffontset_list
, Sfontset_list
, 0, 0, 0,
1236 doc
: /* Return a list of all defined fontset names. */)
1239 Lisp_Object fontset
, list
;
1243 for (i
= 0; i
< ASIZE (Vfontset_table
); i
++)
1245 fontset
= FONTSET_FROM_ID (i
);
1247 && BASE_FONTSET_P (fontset
))
1248 list
= Fcons (FONTSET_NAME (fontset
), list
);
1257 if (!load_font_func
)
1258 /* Window system initializer should have set proper functions. */
1261 Qfontset
= intern ("fontset");
1262 staticpro (&Qfontset
);
1263 Fput (Qfontset
, Qchar_table_extra_slots
, make_number (7));
1265 Vcached_fontset_data
= Qnil
;
1266 staticpro (&Vcached_fontset_data
);
1268 Vfontset_table
= Fmake_vector (make_number (32), Qnil
);
1269 staticpro (&Vfontset_table
);
1271 Vdefault_fontset
= Fmake_char_table (Qfontset
, Qnil
);
1272 staticpro (&Vdefault_fontset
);
1273 FONTSET_ID (Vdefault_fontset
) = make_number (0);
1274 FONTSET_NAME (Vdefault_fontset
)
1275 = build_string ("-*-*-*-*-*-*-*-*-*-*-*-*-fontset-default");
1277 Lisp_Object default_ascii_font
;
1279 #if defined (macintosh)
1281 = build_string ("-apple-monaco-medium-r-*--*-120-*-*-*-*-mac-roman");
1282 #elif defined (WINDOWSNT)
1284 = build_string ("-*-courier new-normal-r-*-*-*-100-*-*-*-*-iso8859-1");
1287 = build_string ("-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1");
1289 FONTSET_ASCII (Vdefault_fontset
) = default_ascii_font
;
1291 AREF (Vfontset_table
, 0) = Vdefault_fontset
;
1292 next_fontset_id
= 1;
1294 DEFVAR_LISP ("font-encoding-alist", &Vfont_encoding_alist
,
1295 doc
: /* Alist of fontname patterns vs corresponding encoding info.
1296 Each element looks like (REGEXP . ENCODING-INFO),
1297 where ENCODING-INFO is an alist of CHARSET vs ENCODING.
1298 ENCODING is one of the following integer values:
1299 0: code points 0x20..0x7F or 0x2020..0x7F7F are used,
1300 1: code points 0xA0..0xFF or 0xA0A0..0xFFFF are used,
1301 2: code points 0x20A0..0x7FFF are used,
1302 3: code points 0xA020..0xFF7F are used. */);
1303 Vfont_encoding_alist
= Qnil
;
1305 DEFVAR_LISP ("use-default-ascent", &Vuse_default_ascent
,
1306 doc
: /* Char table of characters whose ascent values should be ignored.
1307 If an entry for a character is non-nil, the ascent value of the glyph
1308 is assumed to be what specified by _MULE_DEFAULT_ASCENT property of a font.
1310 This affects how a composite character which contains
1311 such a character is displayed on screen. */);
1312 Vuse_default_ascent
= Qnil
;
1314 DEFVAR_LISP ("ignore-relative-composition", &Vignore_relative_composition
,
1315 doc
: /* Char table of characters which is not composed relatively.
1316 If an entry for a character is non-nil, a composition sequence
1317 which contains that character is displayed so that
1318 the glyph of that character is put without considering
1319 an ascent and descent value of a previous character. */);
1320 Vignore_relative_composition
= Qnil
;
1322 DEFVAR_LISP ("alternate-fontname-alist", &Valternate_fontname_alist
,
1323 doc
: /* Alist of fontname vs list of the alternate fontnames.
1324 When a specified font name is not found, the corresponding
1325 alternate fontnames (if any) are tried instead. */);
1326 Valternate_fontname_alist
= Qnil
;
1328 DEFVAR_LISP ("fontset-alias-alist", &Vfontset_alias_alist
,
1329 doc
: /* Alist of fontset names vs the aliases. */);
1330 Vfontset_alias_alist
= Fcons (Fcons (FONTSET_NAME (Vdefault_fontset
),
1331 build_string ("fontset-default")),
1334 DEFVAR_LISP ("vertical-centering-font-regexp",
1335 &Vvertical_centering_font_regexp
,
1336 doc
: /* *Regexp matching font names that require vertical centering on display.
1337 When a character is displayed with such fonts, the character is displayed
1338 at the vertical center of lines. */);
1339 Vvertical_centering_font_regexp
= Qnil
;
1341 defsubr (&Squery_fontset
);
1342 defsubr (&Snew_fontset
);
1343 defsubr (&Sset_fontset_font
);
1344 defsubr (&Sfont_info
);
1345 defsubr (&Sinternal_char_font
);
1346 defsubr (&Sfontset_info
);
1347 defsubr (&Sfontset_font
);
1348 defsubr (&Sfontset_list
);