changeset 97908:464a00cca3cf

(ftfont_spec_pattern): Don't create a charset of the representative chars of the script is a vector. (ftfont_list): Handle the case the representative chars of the script is a vector.
author Kenichi Handa <handa@m17n.org>
date Mon, 01 Sep 2008 02:46:23 +0000
parents 3a2d65dc9abc
children ec291be9f039
files src/ftfont.c
diffstat 1 files changed, 37 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/ftfont.c	Mon Sep 01 02:44:56 2008 +0000
+++ b/src/ftfont.c	Mon Sep 01 02:46:23 2008 +0000
@@ -673,7 +673,7 @@
     {
       Lisp_Object chars = assq_no_quit (script, Vscript_representative_chars);
 
-      if (CONSP (chars))
+      if (CONSP (chars) && CONSP (CDR (chars)))
 	{
 	  charset = FcCharSetCreate ();
 	  if (! charset)
@@ -744,6 +744,9 @@
   FcPattern *pattern;
   FcFontSet *fontset = NULL;
   FcObjectSet *objset = NULL;
+  FcCharSet *charset;
+  Lisp_Object chars = Qnil;
+  FcResult result;
   char otlayout[15];		/* For "otlayout:XXXX" */
   struct OpenTypeSpec *otspec = NULL;
   int spacing = -1;
@@ -757,6 +760,17 @@
   pattern = ftfont_spec_pattern (spec, otlayout, &otspec);
   if (! pattern)
     return Qnil;
+  if (FcPatternGetCharSet (pattern, FC_CHARSET, 0, &charset) != FcResultMatch)
+    {
+      val = assq_no_quit (QCscript, AREF (spec, FONT_EXTRA_INDEX));
+      if (! NILP (val))
+	{
+	  val = assq_no_quit (XCDR (val), Vscript_representative_chars);
+	  if (CONSP (val) && VECTORP (XCDR (val)))
+	    chars = XCDR (val);
+	}
+      val = Qnil;
+    }
   if (INTEGERP (AREF (spec, FONT_SPACING_INDEX)))
     spacing = XINT (AREF (spec, FONT_SPACING_INDEX));
   family = AREF (spec, FONT_FAMILY_INDEX);
@@ -786,10 +800,12 @@
 			     NULL);
   if (! objset)
     goto err;
+  if (! NILP (chars))
+    FcObjectSetAdd (objset, FC_CHARSET);
 
   fontset = FcFontList (NULL, pattern, objset);
-  if (! fontset)
-    goto err;
+  if (! fontset || fontset->nfont == 0)
+    goto finish;
 #if 0
   /* Need fix because this finds any fonts.  */
   if (fontset->nfont == 0 && ! NILP (family))
@@ -836,8 +852,8 @@
 	{
 	  FcChar8 *this;
 
-	  if (FcPatternGetString (fontset->fonts[i], FC_CAPABILITY, 0,
-				  &this) != FcResultMatch
+	  if (FcPatternGetString (fontset->fonts[i], FC_CAPABILITY, 0, &this)
+	      != FcResultMatch
 	      || ! strstr ((char *) this, otlayout))
 	    continue;
 	}
@@ -865,12 +881,26 @@
 	    continue;
 	}
 #endif	/* HAVE_LIBOTF */
+      if (VECTORP (chars))
+	{
+	  int j;
+
+	  if (FcPatternGetCharSet (fontset->fonts[i], FC_CHARSET, 0, &charset)
+	      != FcResultMatch)
+	    continue;
+	  for (j = 0; j < ASIZE (chars); j++)
+	    if (NATNUMP (AREF (chars, j))
+		&& FcCharSetHasChar (charset, XFASTINT (AREF (chars, j))))
+	      break;
+	  if (j == ASIZE (chars))
+	    continue;
+	}
       entity = ftfont_pattern_entity (fontset->fonts[i],
 				      AREF (spec, FONT_EXTRA_INDEX));
       if (! NILP (entity))
 	val = Fcons (entity, val);
     }
-  font_add_log ("ftfont-list", spec, val);
+  val = Fnreverse (val);
   goto finish;
 
  err:
@@ -879,6 +909,7 @@
   val = Qnil;
 
  finish:
+  font_add_log ("ftfont-list", spec, val);
   if (objset) FcObjectSetDestroy (objset);
   if (fontset) FcFontSetDestroy (fontset);
   if (pattern) FcPatternDestroy (pattern);