aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenichi Handa2003-12-29 06:53:50 +0000
committerKenichi Handa2003-12-29 06:53:50 +0000
commit2f65c7b5ef9afed29c365ed08c7b149e0b8ac69c (patch)
treed5cd2fd19a569ecd5613e0d813b34dca726abd68 /src
parent475a1234b72851704d6d217aa9041060ffdf3e2e (diff)
downloademacs-2f65c7b5ef9afed29c365ed08c7b149e0b8ac69c.tar.gz
emacs-2f65c7b5ef9afed29c365ed08c7b149e0b8ac69c.zip
(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.
Diffstat (limited to 'src')
-rw-r--r--src/fontset.c170
1 files changed, 145 insertions, 25 deletions
diff --git a/src/fontset.c b/src/fontset.c
index e462387beae..b199f53df17 100644
--- a/src/fontset.c
+++ b/src/fontset.c
@@ -140,6 +140,10 @@ static int next_fontset_id;
140 font for each characters. */ 140 font for each characters. */
141static Lisp_Object Vdefault_fontset; 141static Lisp_Object Vdefault_fontset;
142 142
143/* Alist of font specifications. It override the font specification
144 in the default fontset. */
145static Lisp_Object Voverriding_fontspec_alist;
146
143Lisp_Object Vfont_encoding_alist; 147Lisp_Object Vfont_encoding_alist;
144Lisp_Object Vuse_default_ascent; 148Lisp_Object Vuse_default_ascent;
145Lisp_Object Vignore_relative_composition; 149Lisp_Object Vignore_relative_composition;
@@ -184,11 +188,13 @@ void (*check_window_system_func) P_ ((void));
184 188
185/* Prototype declarations for static functions. */ 189/* Prototype declarations for static functions. */
186static Lisp_Object fontset_ref P_ ((Lisp_Object, int)); 190static Lisp_Object fontset_ref P_ ((Lisp_Object, int));
191static Lisp_Object lookup_overriding_fontspec P_ ((Lisp_Object, int));
187static void fontset_set P_ ((Lisp_Object, int, Lisp_Object)); 192static void fontset_set P_ ((Lisp_Object, int, Lisp_Object));
188static Lisp_Object make_fontset P_ ((Lisp_Object, Lisp_Object, Lisp_Object)); 193static Lisp_Object make_fontset P_ ((Lisp_Object, Lisp_Object, Lisp_Object));
189static int fontset_id_valid_p P_ ((int)); 194static int fontset_id_valid_p P_ ((int));
190static Lisp_Object fontset_pattern_regexp P_ ((Lisp_Object)); 195static Lisp_Object fontset_pattern_regexp P_ ((Lisp_Object));
191static Lisp_Object font_family_registry P_ ((Lisp_Object, int)); 196static Lisp_Object font_family_registry P_ ((Lisp_Object, int));
197static 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 **********/
@@ -241,6 +247,46 @@ fontset_ref (fontset, c)
241} 247}
242 248
243 249
250static Lisp_Object
251lookup_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
246static Lisp_Object 292static Lisp_Object
@@ -254,8 +300,12 @@ fontset_ref_via_base (fontset, c)
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;
@@ -551,6 +601,13 @@ fontset_font_pattern (f, id, c)
551 elt = FONTSET_REF (fontset, c); 601 elt = FONTSET_REF (fontset, c);
552 } 602 }
553 if (NILP (elt)) 603 if (NILP (elt))
604 {
605 Lisp_Object frame;
606
607 XSETFRAME (frame, f);
608 elt = lookup_overriding_fontspec (frame, c);
609 }
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))
@@ -980,6 +1037,33 @@ check_fontset_name (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
1043static Lisp_Object
1044regulalize_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
983DEFUN ("set-fontset-font", Fset_fontset_font, Sset_fontset_font, 3, 4, 0, 1067DEFUN ("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
@@ -1043,34 +1127,12 @@ name of a font, REGISTRY is a registry name of a font. */)
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);
@@ -1445,6 +1507,60 @@ DEFUN ("fontset-list", Ffontset_list, Sfontset_list, 0, 0, 0,
1445 return list; 1507 return list;
1446} 1508}
1447 1509
1510DEFUN ("set-overriding-fontspec-internal", Fset_overriding_fontspec_internal,
1511 Sset_overriding_fontspec_internal, 1, 1, 0,
1512 doc: /* Internal use only.
1513
1514FONTLIST is an alist of TARGET vs FONTNAME, where TARGET is a charset
1515or a char-table, FONTNAME have the same meanings as in
1516`set-fontset-font'.
1517
1518It overrides the font specifications for each TARGET in the default
1519fontset by the corresponding FONTNAME.
1520
1521If TARGET is a charset, targets are all characters in the charset. If
1522TARGET is a char-table, targets are characters whose value is non-nil
1523in the table.
1524
1525It 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
1448void 1564void
1449syms_of_fontset () 1565syms_of_fontset ()
1450{ 1566{
@@ -1483,6 +1599,9 @@ syms_of_fontset ()
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.
1488Each element looks like (REGEXP . ENCODING-INFO), 1607Each element looks like (REGEXP . ENCODING-INFO),
@@ -1548,6 +1667,7 @@ at the vertical center of lines. */);
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