diff src/fontset.c @ 91266:3cd59392b3ec

(Vfont_encoding_charset_alist): New variable. (syms_of_fontset): DEFVAR it. (reorder_font_vector): Optimize for the case of no need of reordring. (fontset_find_font): Likewise. (face_for_char): Map the charset property by Vfont_encoding_charset_alist.
author Kenichi Handa <handa@m17n.org>
date Fri, 21 Dec 2007 01:37:31 +0000
parents 2de541db2c82
children 606f2d163a64
line wrap: on
line diff
--- a/src/fontset.c	Thu Dec 20 14:29:09 2007 +0000
+++ b/src/fontset.c	Fri Dec 21 01:37:31 2007 +0000
@@ -214,6 +214,7 @@
 static Lisp_Object Vdefault_fontset;
 
 Lisp_Object Vfont_encoding_alist;
+Lisp_Object Vfont_encoding_charset_alist;
 Lisp_Object Vuse_default_ascent;
 Lisp_Object Vignore_relative_composition;
 Lisp_Object Valternate_fontname_alist;
@@ -450,13 +451,7 @@
   int i, idx;
   Lisp_Object preferred_by_charset, preferred_by_family;
 
-  ASET (font_group, 0, make_number (charset_ordered_list_tick));
-  ASET (font_group, 1, make_number (charset_id));
-  ASET (font_group, 2, family);
   size = ASIZE (font_group) - 3;
-  if (size <= 1)
-    /* No need to reorder VEC.  */
-    return;
   charset_id_table = (int *) alloca (sizeof (int) * size);
   new_vec = (Lisp_Object *) alloca (sizeof (Lisp_Object) * size);
 
@@ -493,6 +488,15 @@
 	charset_id_table[i] = id;
     }
 
+  if (idx == 0
+      && (XINT (AREF (font_group, 0)) == charset_ordered_list_tick))
+    /* No need of reordering.  */
+    return;
+
+  ASET (font_group, 0, make_number (charset_ordered_list_tick));
+  ASET (font_group, 1, make_number (charset_id));
+  ASET (font_group, 2, family);
+
   /* Then, store the remaining RFONT-DEFs in NEW_VEC in the correct
      order.  */
   for (list = Vcharset_ordered_list; idx < size; list = XCDR (list))
@@ -664,7 +668,7 @@
 
   if (ASIZE (vec) > 4
       && (XINT (AREF (vec, 0)) != charset_ordered_list_tick
-	  || XINT (AREF (vec, 1)) != id
+	  || (id >= 0 && XINT (AREF (vec, 1)) != id)
 	  || NILP (Fequal (AREF (vec, 2), face->lface[LFACE_FAMILY_INDEX]))))
     /* We have just created VEC,
        or the charset priorities were changed,
@@ -1032,7 +1036,14 @@
       if (NILP (charset))
 	id = -1;
       else if (CHARSETP (charset))
-	id = XINT (CHARSET_SYMBOL_ID (charset));
+	{
+	  Lisp_Object val;
+
+	  val = assoc_no_quit (charset, Vfont_encoding_charset_alist);
+	  if (CONSP (val) && CHARSETP (XCDR (val)))
+	    charset = XCDR (val);
+	  id = XINT (CHARSET_SYMBOL_ID (charset));
+	}
     }
   rfont_def = fontset_font (fontset, c, face, id);
   if (VECTORP (rfont_def))
@@ -2465,6 +2476,9 @@
 where ENCODING is a charset or a char-table,
 and REPERTORY is a charset, a char-table, or nil.
 
+If ENCDING and REPERTORY are the same, the element can have the form
+\(REGEXP . ENCODING).
+
 ENCODING is for converting a character to a glyph code of the font.
 If ENCODING is a charset, encoding a character by the charset gives
 the corresponding glyph code.  If ENCODING is a char-table, looking up
@@ -2477,6 +2491,17 @@
 gets the repertory information by an opened font and ENCODING.  */);
   Vfont_encoding_alist = Qnil;
 
+  DEFVAR_LISP ("font-encoding-charset-alist", &Vfont_encoding_charset_alist,
+	       doc: /*
+Alist of charsets vs the charsets to determine the preferred font encoding.
+Each element looks like (CHARSET . ENCDOING-CHARSET),
+where ENCODING-CHARSET is a charset registered in the variable
+`font-encoding-alist' as ENCODING.
+
+When a text has a property `charset' and the value is CHARSET, a font
+whose encoding corresponds to ENCODING-CHARSET is preferred.  */);
+  Vfont_encoding_charset_alist = Qnil;
+
   DEFVAR_LISP ("use-default-ascent", &Vuse_default_ascent,
 	       doc: /*
 Char table of characters whose ascent values should be ignored.