changeset 34160:bb9ec0151423

(struct font_name): New member registry_priority. (split_font_name): Initialize the above member to zero. (concat_font_list): New function. (font_list): Include fonts of all alternative registries. (FONT_POINT_SIZE_QUANTUM): New macro. (better_font_p): Ignore point size difference less than FONT_POINT_SIZE_QUANTUM. Use registry_prioprity as a last resort.
author Kenichi Handa <handa@m17n.org>
date Mon, 04 Dec 2000 06:26:38 +0000
parents a734985ec0bc
children d8535b05965f
files src/xfaces.c
diffstat 1 files changed, 58 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/xfaces.c	Mon Dec 04 01:20:30 2000 +0000
+++ b/src/xfaces.c	Mon Dec 04 06:26:38 2000 +0000
@@ -1827,6 +1827,9 @@
   /* Numeric values for those fields that interest us.  See
      split_font_name for which these are.  */
   int numeric[XLFD_LAST];
+
+  /* Lower value mean higher priority.  */
+  int registry_priority;
 };
 
 /* The frame in effect when sorting font names.  Set temporarily in
@@ -2176,6 +2179,10 @@
       font->numeric[XLFD_SWIDTH] = xlfd_numeric_swidth (font);
     }
 
+  /* Initialize it to zero.  It will be overridden by font_list while
+     trying alternate registries.  */
+  font->registry_priority = 0;
+
   return success_p;
 }
 
@@ -2547,13 +2554,34 @@
 }
 
 
+/* Concatenate font list FONTS1 and FONTS2.  FONTS1 and FONTS2
+   contains NFONTS1 fonts and NFONTS2 fonts respectively.  Return a
+   pointer to a newly allocated font list.  FONTS1 and FONTS2 are
+   freed.  */
+
+static struct font_name *
+concat_font_list (fonts1, nfonts1, fonts2, nfonts2)
+     struct font_name *fonts1, *fonts2;
+     int nfonts1, nfonts2;
+{
+  int new_nfonts = nfonts1 + nfonts2;
+  struct font_name *new_fonts;
+
+  new_fonts = (struct font_name *) xmalloc (sizeof *new_fonts * new_nfonts);
+  bcopy (fonts1, new_fonts, sizeof *new_fonts * nfonts1);
+  bcopy (fonts2, new_fonts + nfonts1, sizeof *new_fonts * nfonts2);
+  xfree (fonts1);
+  xfree (fonts2);
+  return new_fonts;
+}
+
+
 /* Get a sorted list of fonts of family FAMILY on frame F.
 
    If PATTERN is non-nil list fonts matching that pattern.
 
-   If REGISTRY is non-nil, retur fonts with that registry.  If none
-   are found, try alternative registries from
-   Vface_alternative_font_registry_alist.
+   If REGISTRY is non-nil, return fonts with that registry and the
+   alternative registries from Vface_alternative_font_registry_alist.
    
    If REGISTRY is nil return fonts of any registry.
 
@@ -2569,8 +2597,7 @@
 {
   int nfonts = font_list_1 (f, pattern, family, registry, fonts);
   
-  if (nfonts == 0
-      && !NILP (registry)
+  if (!NILP (registry)
       && CONSP (Vface_alternative_font_registry_alist))
     {
       Lisp_Object alter;
@@ -2578,11 +2605,25 @@
       alter = Fassoc (registry, Vface_alternative_font_registry_alist);
       if (CONSP (alter))
 	{
-	  for (alter = XCDR (alter);
-	       CONSP (alter) && nfonts == 0;
-	       alter = XCDR (alter))
+	  int reg_prio, i;
+
+	  for (alter = XCDR (alter), reg_prio = 1;
+	       CONSP (alter);
+	       alter = XCDR (alter), reg_prio++)
 	    if (STRINGP (XCAR (alter)))
-	      nfonts = font_list_1 (f, pattern, family, XCAR (alter), fonts);
+	      {
+		int nfonts2;
+		struct font_name *fonts2;
+
+		nfonts2 = font_list_1 (f, pattern, family, XCAR (alter),
+				       &fonts2);
+		for (i = 0; i < nfonts2; i++)
+		  fonts2[i].registry_priority = reg_prio;
+		*fonts = (nfonts > 0
+			  ? concat_font_list (*fonts, nfonts, fonts2, nfonts2)
+			  : fonts2);
+		nfonts += nfonts2;
+	      }
 	}
     }
 
@@ -5614,6 +5655,10 @@
 }
 
 
+/* Ignore the difference of font point size less than this value.  */
+
+#define FONT_POINT_SIZE_QUANTUM 5
+
 /* Value is non-zero if FONT1 is a better match for font attributes
    VALUES than FONT2.  VALUES is an array of face attribute values in
    font sort order.  COMPARE_PT_P zero means don't compare point
@@ -5636,6 +5681,9 @@
 	  int delta1 = abs (values[i] - font1->numeric[xlfd_idx]);
 	  int delta2 = abs (values[i] - font2->numeric[xlfd_idx]);
 
+	  if (xlfd_idx == XLFD_POINT_SIZE
+	      && abs (delta1 - delta2) < FONT_POINT_SIZE_QUANTUM)
+	    continue;
 	  if (delta1 > delta2)
 	    return 0;
 	  else if (delta1 < delta2)
@@ -5653,7 +5701,7 @@
 	}
     }
 
-  return 0;
+  return (font1->registry_priority < font2->registry_priority);
 }