Mercurial > emacs
comparison src/fontset.c @ 53353:b085f18ebcf0
(Voverriding_fontspec_alist): New variable.
(lookup_overriding_fontspec): New function.
(fontset_ref_via_base): Call lookup_overriding_fontspec if
necessary.
(fontset_font_pattern): Likewise.
(regulalize_fontname): New function.
(Fset_fontset_font): Call regulalize_fontname.
(Fset_overriding_fontspec_internal): New function.
(syms_of_fontset): Initialize and staticprop
Voverriding_fontspec_alist.
(syms_of_fontset): Defsubr Sset_overriding_fontspec_internal.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Mon, 29 Dec 2003 06:53:50 +0000 |
parents | 8787289602d1 |
children | ccddf8ef9113 5de4189e659d |
comparison
equal
deleted
inserted
replaced
53352:958aea5e5a05 | 53353:b085f18ebcf0 |
---|---|
138 | 138 |
139 /* The default fontset. This gives default FAMILY and REGISTRY of | 139 /* The default fontset. This gives default FAMILY and REGISTRY of |
140 font for each characters. */ | 140 font for each characters. */ |
141 static Lisp_Object Vdefault_fontset; | 141 static Lisp_Object Vdefault_fontset; |
142 | 142 |
143 /* Alist of font specifications. It override the font specification | |
144 in the default fontset. */ | |
145 static Lisp_Object Voverriding_fontspec_alist; | |
146 | |
143 Lisp_Object Vfont_encoding_alist; | 147 Lisp_Object Vfont_encoding_alist; |
144 Lisp_Object Vuse_default_ascent; | 148 Lisp_Object Vuse_default_ascent; |
145 Lisp_Object Vignore_relative_composition; | 149 Lisp_Object Vignore_relative_composition; |
146 Lisp_Object Valternate_fontname_alist; | 150 Lisp_Object Valternate_fontname_alist; |
147 Lisp_Object Vfontset_alias_alist; | 151 Lisp_Object Vfontset_alias_alist; |
182 void (*check_window_system_func) P_ ((void)); | 186 void (*check_window_system_func) P_ ((void)); |
183 | 187 |
184 | 188 |
185 /* Prototype declarations for static functions. */ | 189 /* Prototype declarations for static functions. */ |
186 static Lisp_Object fontset_ref P_ ((Lisp_Object, int)); | 190 static Lisp_Object fontset_ref P_ ((Lisp_Object, int)); |
191 static Lisp_Object lookup_overriding_fontspec P_ ((Lisp_Object, int)); | |
187 static void fontset_set P_ ((Lisp_Object, int, Lisp_Object)); | 192 static void fontset_set P_ ((Lisp_Object, int, Lisp_Object)); |
188 static Lisp_Object make_fontset P_ ((Lisp_Object, Lisp_Object, Lisp_Object)); | 193 static Lisp_Object make_fontset P_ ((Lisp_Object, Lisp_Object, Lisp_Object)); |
189 static int fontset_id_valid_p P_ ((int)); | 194 static int fontset_id_valid_p P_ ((int)); |
190 static Lisp_Object fontset_pattern_regexp P_ ((Lisp_Object)); | 195 static Lisp_Object fontset_pattern_regexp P_ ((Lisp_Object)); |
191 static Lisp_Object font_family_registry P_ ((Lisp_Object, int)); | 196 static Lisp_Object font_family_registry P_ ((Lisp_Object, int)); |
197 static Lisp_Object regulalize_fontname P_ ((Lisp_Object)); | |
192 | 198 |
193 | 199 |
194 /********** MACROS AND FUNCTIONS TO HANDLE FONTSET **********/ | 200 /********** MACROS AND FUNCTIONS TO HANDLE FONTSET **********/ |
195 | 201 |
196 /* Return the fontset with ID. No check of ID's validness. */ | 202 /* Return the fontset with ID. No check of ID's validness. */ |
239 return defalt; | 245 return defalt; |
240 return elt; | 246 return elt; |
241 } | 247 } |
242 | 248 |
243 | 249 |
250 static Lisp_Object | |
251 lookup_overriding_fontspec (frame, c) | |
252 Lisp_Object frame; | |
253 int c; | |
254 { | |
255 Lisp_Object tail; | |
256 | |
257 for (tail = Voverriding_fontspec_alist; CONSP (tail); tail = XCDR (tail)) | |
258 { | |
259 Lisp_Object val, target, elt; | |
260 | |
261 val = XCAR (tail); | |
262 target = XCAR (val); | |
263 val = XCDR (val); | |
264 /* Now VAL is (NO-FRAME-LIST OK-FRAME-LIST CHAR FONTNAME). */ | |
265 if (NILP (Fmemq (frame, XCAR (val))) | |
266 && (CHAR_TABLE_P (target) | |
267 ? ! NILP (CHAR_TABLE_REF (target, c)) | |
268 : XINT (target) == CHAR_CHARSET (c))) | |
269 { | |
270 val = XCDR (val); | |
271 elt = XCDR (val); | |
272 if (NILP (Fmemq (frame, XCAR (val)))) | |
273 { | |
274 if (! face_font_available_p (XFRAME (frame), XCDR (elt))) | |
275 { | |
276 val = XCDR (XCAR (tail)); | |
277 XSETCAR (val, Fcons (frame, XCAR (val))); | |
278 continue; | |
279 } | |
280 XSETCAR (val, Fcons (frame, XCAR (val))); | |
281 } | |
282 if (NILP (XCAR (elt))) | |
283 XSETCAR (elt, make_number (c)); | |
284 return elt; | |
285 } | |
286 } | |
287 return Qnil; | |
288 } | |
289 | |
244 #define FONTSET_REF_VIA_BASE(fontset, c) fontset_ref_via_base (fontset, &c) | 290 #define FONTSET_REF_VIA_BASE(fontset, c) fontset_ref_via_base (fontset, &c) |
245 | 291 |
246 static Lisp_Object | 292 static Lisp_Object |
247 fontset_ref_via_base (fontset, c) | 293 fontset_ref_via_base (fontset, c) |
248 Lisp_Object fontset; | 294 Lisp_Object fontset; |
252 Lisp_Object elt; | 298 Lisp_Object elt; |
253 | 299 |
254 if (SINGLE_BYTE_CHAR_P (*c)) | 300 if (SINGLE_BYTE_CHAR_P (*c)) |
255 return FONTSET_ASCII (fontset); | 301 return FONTSET_ASCII (fontset); |
256 | 302 |
257 elt = FONTSET_REF (FONTSET_BASE (fontset), *c); | 303 elt = Qnil; |
258 if (NILP (elt) && ! EQ (fontset, Vdefault_fontset)) | 304 if (! EQ (FONTSET_BASE (fontset), Vdefault_fontset)) |
305 elt = FONTSET_REF (FONTSET_BASE (fontset), *c); | |
306 if (NILP (elt)) | |
307 elt = lookup_overriding_fontspec (FONTSET_FRAME (fontset), *c); | |
308 if (NILP (elt) && ! EQ (FONTSET_BASE (fontset), Vdefault_fontset)) | |
259 elt = FONTSET_REF (Vdefault_fontset, *c); | 309 elt = FONTSET_REF (Vdefault_fontset, *c); |
260 if (NILP (elt)) | 310 if (NILP (elt)) |
261 return Qnil; | 311 return Qnil; |
262 | 312 |
263 *c = XINT (XCAR (elt)); | 313 *c = XINT (XCAR (elt)); |
547 { | 597 { |
548 fontset = FONTSET_FROM_ID (id); | 598 fontset = FONTSET_FROM_ID (id); |
549 xassert (!BASE_FONTSET_P (fontset)); | 599 xassert (!BASE_FONTSET_P (fontset)); |
550 fontset = FONTSET_BASE (fontset); | 600 fontset = FONTSET_BASE (fontset); |
551 elt = FONTSET_REF (fontset, c); | 601 elt = FONTSET_REF (fontset, c); |
602 } | |
603 if (NILP (elt)) | |
604 { | |
605 Lisp_Object frame; | |
606 | |
607 XSETFRAME (frame, f); | |
608 elt = lookup_overriding_fontspec (frame, c); | |
552 } | 609 } |
553 if (NILP (elt)) | 610 if (NILP (elt)) |
554 elt = FONTSET_REF (Vdefault_fontset, c); | 611 elt = FONTSET_REF (Vdefault_fontset, c); |
555 | 612 |
556 if (!CONSP (elt)) | 613 if (!CONSP (elt)) |
978 if (id < 0) | 1035 if (id < 0) |
979 error ("Fontset `%s' does not exist", SDATA (name)); | 1036 error ("Fontset `%s' does not exist", SDATA (name)); |
980 return FONTSET_FROM_ID (id); | 1037 return FONTSET_FROM_ID (id); |
981 } | 1038 } |
982 | 1039 |
1040 /* Downcase FONTNAME or car and cdr of FONTNAME. If FONTNAME is a | |
1041 string, maybe change FONTNAME to (FAMILY . REGISTRY). */ | |
1042 | |
1043 static Lisp_Object | |
1044 regulalize_fontname (Lisp_Object fontname) | |
1045 { | |
1046 Lisp_Object family, registry; | |
1047 | |
1048 if (STRINGP (fontname)) | |
1049 return font_family_registry (Fdowncase (fontname), 0); | |
1050 | |
1051 CHECK_CONS (fontname); | |
1052 family = XCAR (fontname); | |
1053 registry = XCDR (fontname); | |
1054 if (!NILP (family)) | |
1055 { | |
1056 CHECK_STRING (family); | |
1057 family = Fdowncase (family); | |
1058 } | |
1059 if (!NILP (registry)) | |
1060 { | |
1061 CHECK_STRING (registry); | |
1062 registry = Fdowncase (registry); | |
1063 } | |
1064 return Fcons (family, registry); | |
1065 } | |
1066 | |
983 DEFUN ("set-fontset-font", Fset_fontset_font, Sset_fontset_font, 3, 4, 0, | 1067 DEFUN ("set-fontset-font", Fset_fontset_font, Sset_fontset_font, 3, 4, 0, |
984 doc: /* Modify fontset NAME to use FONTNAME for CHARACTER. | 1068 doc: /* Modify fontset NAME to use FONTNAME for CHARACTER. |
985 | 1069 |
986 If NAME is nil, modify the default fontset. | 1070 If NAME is nil, modify the default fontset. |
987 CHARACTER may be a cons; (FROM . TO), where FROM and TO are | 1071 CHARACTER may be a cons; (FROM . TO), where FROM and TO are |
1041 invalid_character (to); | 1125 invalid_character (to); |
1042 if (SINGLE_BYTE_CHAR_P (to)) | 1126 if (SINGLE_BYTE_CHAR_P (to)) |
1043 error ("Can't change font for a single byte character"); | 1127 error ("Can't change font for a single byte character"); |
1044 } | 1128 } |
1045 | 1129 |
1046 if (STRINGP (fontname)) | |
1047 { | |
1048 fontname = Fdowncase (fontname); | |
1049 elt = Fcons (make_number (from), font_family_registry (fontname, 0)); | |
1050 } | |
1051 else | |
1052 { | |
1053 CHECK_CONS (fontname); | |
1054 family = XCAR (fontname); | |
1055 registry = XCDR (fontname); | |
1056 if (!NILP (family)) | |
1057 { | |
1058 CHECK_STRING (family); | |
1059 family = Fdowncase (family); | |
1060 } | |
1061 if (!NILP (registry)) | |
1062 { | |
1063 CHECK_STRING (registry); | |
1064 registry = Fdowncase (registry); | |
1065 } | |
1066 elt = Fcons (make_number (from), Fcons (family, registry)); | |
1067 } | |
1068 | |
1069 /* The arg FRAME is kept for backward compatibility. We only check | 1130 /* The arg FRAME is kept for backward compatibility. We only check |
1070 the validity. */ | 1131 the validity. */ |
1071 if (!NILP (frame)) | 1132 if (!NILP (frame)) |
1072 CHECK_LIVE_FRAME (frame); | 1133 CHECK_LIVE_FRAME (frame); |
1073 | 1134 |
1135 elt = Fcons (make_number (from), regulalize_fontname (fontname)); | |
1074 for (; from <= to; from++) | 1136 for (; from <= to; from++) |
1075 FONTSET_SET (fontset, from, elt); | 1137 FONTSET_SET (fontset, from, elt); |
1076 Foptimize_char_table (fontset); | 1138 Foptimize_char_table (fontset); |
1077 | 1139 |
1078 /* If there's a realized fontset REALIZED whose parent is FONTSET, | 1140 /* If there's a realized fontset REALIZED whose parent is FONTSET, |
1443 } | 1505 } |
1444 | 1506 |
1445 return list; | 1507 return list; |
1446 } | 1508 } |
1447 | 1509 |
1510 DEFUN ("set-overriding-fontspec-internal", Fset_overriding_fontspec_internal, | |
1511 Sset_overriding_fontspec_internal, 1, 1, 0, | |
1512 doc: /* Internal use only. | |
1513 | |
1514 FONTLIST is an alist of TARGET vs FONTNAME, where TARGET is a charset | |
1515 or a char-table, FONTNAME have the same meanings as in | |
1516 `set-fontset-font'. | |
1517 | |
1518 It overrides the font specifications for each TARGET in the default | |
1519 fontset by the corresponding FONTNAME. | |
1520 | |
1521 If TARGET is a charset, targets are all characters in the charset. If | |
1522 TARGET is a char-table, targets are characters whose value is non-nil | |
1523 in the table. | |
1524 | |
1525 It is intended that this function is called only from | |
1526 `set-language-environment'. */) | |
1527 (fontlist) | |
1528 Lisp_Object fontlist; | |
1529 { | |
1530 Lisp_Object tail; | |
1531 | |
1532 fontlist = Fcopy_sequence (fontlist); | |
1533 /* Now FONTLIST is ((TARGET . FONTNAME) ...). Reform it to ((TARGET | |
1534 nil nil nil FONTSPEC) ...), where TARGET is a charset-id or a | |
1535 char-table. */ | |
1536 for (tail = fontlist; CONSP (tail); tail = XCDR (tail)) | |
1537 { | |
1538 Lisp_Object elt, target; | |
1539 | |
1540 elt = XCAR (tail); | |
1541 target = Fcar (elt); | |
1542 elt = Fcons (Qnil, regulalize_fontname (Fcdr (elt))); | |
1543 if (! CHAR_TABLE_P (target)) | |
1544 { | |
1545 int charset, c; | |
1546 | |
1547 CHECK_SYMBOL (target); | |
1548 charset = get_charset_id (target); | |
1549 if (charset < 0) | |
1550 error ("Invalid charset %s", SDATA (SYMBOL_NAME (target))); | |
1551 target = make_number (charset); | |
1552 c = MAKE_CHAR (charset, 0, 0); | |
1553 XSETCAR (elt, make_number (c)); | |
1554 } | |
1555 elt = Fcons (target, Fcons (Qnil, Fcons (Qnil, elt))); | |
1556 XSETCAR (tail, elt); | |
1557 } | |
1558 Voverriding_fontspec_alist = fontlist; | |
1559 clear_face_cache (0); | |
1560 ++windows_or_buffers_changed; | |
1561 return Qnil; | |
1562 } | |
1563 | |
1448 void | 1564 void |
1449 syms_of_fontset () | 1565 syms_of_fontset () |
1450 { | 1566 { |
1451 if (!load_font_func) | 1567 if (!load_font_func) |
1452 /* Window system initializer should have set proper functions. */ | 1568 /* Window system initializer should have set proper functions. */ |
1481 build_string ("-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1")); | 1597 build_string ("-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1")); |
1482 #endif | 1598 #endif |
1483 AREF (Vfontset_table, 0) = Vdefault_fontset; | 1599 AREF (Vfontset_table, 0) = Vdefault_fontset; |
1484 next_fontset_id = 1; | 1600 next_fontset_id = 1; |
1485 | 1601 |
1602 Voverriding_fontspec_alist = Qnil; | |
1603 staticpro (&Voverriding_fontspec_alist); | |
1604 | |
1486 DEFVAR_LISP ("font-encoding-alist", &Vfont_encoding_alist, | 1605 DEFVAR_LISP ("font-encoding-alist", &Vfont_encoding_alist, |
1487 doc: /* Alist of fontname patterns vs corresponding encoding info. | 1606 doc: /* Alist of fontname patterns vs corresponding encoding info. |
1488 Each element looks like (REGEXP . ENCODING-INFO), | 1607 Each element looks like (REGEXP . ENCODING-INFO), |
1489 where ENCODING-INFO is an alist of CHARSET vs ENCODING. | 1608 where ENCODING-INFO is an alist of CHARSET vs ENCODING. |
1490 ENCODING is one of the following integer values: | 1609 ENCODING is one of the following integer values: |
1546 defsubr (&Sfont_info); | 1665 defsubr (&Sfont_info); |
1547 defsubr (&Sinternal_char_font); | 1666 defsubr (&Sinternal_char_font); |
1548 defsubr (&Sfontset_info); | 1667 defsubr (&Sfontset_info); |
1549 defsubr (&Sfontset_font); | 1668 defsubr (&Sfontset_font); |
1550 defsubr (&Sfontset_list); | 1669 defsubr (&Sfontset_list); |
1670 defsubr (&Sset_overriding_fontspec_internal); | |
1551 } | 1671 } |
1552 | 1672 |
1553 /* arch-tag: ea861585-2f5f-4e5b-9849-d04a9c3a3537 | 1673 /* arch-tag: ea861585-2f5f-4e5b-9849-d04a9c3a3537 |
1554 (do not change this comment) */ | 1674 (do not change this comment) */ |