changeset 70149:6188dfce9d77

(x_per_char_metric): Return NULL if glyph width is 0. (add_mac_font_name): New function. (init_font_name_table): Use it. Adopt the first found font from those having the same family name.
author YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
date Fri, 21 Apr 2006 07:56:57 +0000
parents a2348b30cc21
children 50b254bd63de
files src/macterm.c
diffstat 1 files changed, 58 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/src/macterm.c	Fri Apr 21 07:56:47 2006 +0000
+++ b/src/macterm.c	Fri Apr 21 07:56:57 2006 +0000
@@ -2230,7 +2230,11 @@
 #endif
 
   return ((pcm == NULL
-	   || (pcm->width == 0 && (pcm->rbearing - pcm->lbearing) == 0))
+	   || (pcm->width == 0
+#if 0 /* Show hollow boxes for zero-width glyphs such as combining diacritics.  */
+	       && (pcm->rbearing - pcm->lbearing) == 0
+#endif
+	       ))
 	  ? NULL : pcm);
 }
 
@@ -7042,6 +7046,25 @@
   font_name_table[font_name_count++] = font_name;
 }
 
+static void
+add_mac_font_name (name, size, style, charset)
+     char *name;
+     int size;
+     Style style;
+     char *charset;
+{
+  if (size > 0)
+    add_font_name_table_entry (mac_to_x_fontname (name, size, style, charset));
+  else
+    {
+      add_font_name_table_entry (mac_to_x_fontname (name, 0, style, charset));
+      add_font_name_table_entry (mac_to_x_fontname (name, 0, italic, charset));
+      add_font_name_table_entry (mac_to_x_fontname (name, 0, bold, charset));
+      add_font_name_table_entry (mac_to_x_fontname (name, 0, italic | bold,
+						    charset));
+    }
+}
+
 /* Sets up the table font_name_table to contain the list of all fonts
    in the system the first time the table is used so that the Resource
    Manager need not be accessed every time this information is
@@ -7067,16 +7090,21 @@
 			   text_encoding_info_alist)))
     {
       OSErr err;
+      struct Lisp_Hash_Table *h;
+      unsigned hash_code;
       ItemCount nfonts, i;
       ATSUFontID *font_ids = NULL;
-      Ptr name, prev_name = NULL;
+      Ptr name;
       ByteCount name_len;
+      Lisp_Object family;
 
       atsu_font_id_hash =
 	make_hash_table (Qequal, make_number (DEFAULT_HASH_SIZE),
 			 make_float (DEFAULT_REHASH_SIZE),
 			 make_float (DEFAULT_REHASH_THRESHOLD),
 			 Qnil, Qnil, Qnil);;
+      h = XHASH_TABLE (atsu_font_id_hash);
+
       err = ATSUFontCount (&nfonts);
       if (err == noErr)
 	{
@@ -7098,32 +7126,19 @@
 				    kFontNoLanguage, name_len, name,
 				    NULL, NULL);
 	    if (err == noErr)
-	      decode_mac_font_name (name, name_len + 1, Qnil);
-	    if (err == noErr
-		&& *name != '.'
-		&& (prev_name == NULL
-		    || strcmp (name, prev_name) != 0))
 	      {
-		static char *cs = "iso10646-1";
-
-		add_font_name_table_entry (mac_to_x_fontname (name, 0,
-							      normal, cs));
-		add_font_name_table_entry (mac_to_x_fontname (name, 0,
-							      italic, cs));
-		add_font_name_table_entry (mac_to_x_fontname (name, 0,
-							      bold, cs));
-		add_font_name_table_entry (mac_to_x_fontname (name, 0,
-							      italic | bold, cs));
-		Fputhash (make_unibyte_string (name, name_len),
-			  long_to_cons (font_ids[i]), atsu_font_id_hash);
-		xfree (prev_name);
-		prev_name = name;
+		decode_mac_font_name (name, name_len + 1, Qnil);
+		family = make_unibyte_string (name, name_len);
+		if (*name != '.'
+		    && hash_lookup (h, family, &hash_code) < 0)
+		  {
+		    add_mac_font_name (name, 0, normal, "iso10646-1");
+		    hash_put (h, family, long_to_cons (font_ids[i]),
+			      hash_code);
+		  }
 	      }
-	    else
-	      xfree (name);
+	    xfree (name);
 	  }
-      if (prev_name)
-	xfree (prev_name);
       if (font_ids)
 	xfree (font_ids);
     }
@@ -7151,16 +7166,16 @@
       FMFontSize size;
       TextEncoding encoding;
       TextEncodingBase sc;
-      Lisp_Object text_encoding_info;
+      Lisp_Object text_encoding_info, family;
 
       if (FMGetFontFamilyName (ff, name) != noErr)
-	break;
+	continue;
       p2cstr (name);
       if (*name == '.')
 	continue;
 
       if (FMGetFontFamilyTextEncoding (ff, &encoding) != noErr)
-	break;
+	continue;
       sc = GetTextEncodingBase (encoding);
       text_encoding_info = assq_no_quit (make_number (sc),
 					 text_encoding_info_alist);
@@ -7169,13 +7184,15 @@
 					   text_encoding_info_alist);
       decode_mac_font_name (name, sizeof (name),
 			    XCAR (XCDR (text_encoding_info)));
-      fm_font_family_alist = Fcons (Fcons (build_string (name),
-					   make_number (ff)),
+      family = build_string (name);
+      if (!NILP (Fassoc (family, fm_font_family_alist)))
+	continue;
+      fm_font_family_alist = Fcons (Fcons (family, make_number (ff)),
 				    fm_font_family_alist);
 
       /* Point the instance iterator at the current font family.  */
       if (FMResetFontFamilyInstanceIterator (ff, &ffii) != noErr)
-	break;
+	continue;
 
       while (FMGetNextFontFamilyInstance (&ffii, &font, &style, &size)
 	     == noErr)
@@ -7184,27 +7201,7 @@
 
 	  if (size > 0 || style == normal)
 	    for (; !NILP (rest); rest = XCDR (rest))
-	      {
-		char *cs = SDATA (XCAR (rest));
-
-		if (size == 0)
-		  {
-		    add_font_name_table_entry (mac_to_x_fontname (name, size,
-								  style, cs));
-		    add_font_name_table_entry (mac_to_x_fontname (name, size,
-								  italic, cs));
-		    add_font_name_table_entry (mac_to_x_fontname (name, size,
-								  bold, cs));
-		    add_font_name_table_entry (mac_to_x_fontname (name, size,
-								  italic | bold,
-								  cs));
-		  }
-		else
-		  {
-		    add_font_name_table_entry (mac_to_x_fontname (name, size,
-								  style, cs));
-		  }
-	      }
+	      add_mac_font_name (name, size, style, SDATA (XCAR (rest)));
 	}
     }
 
@@ -7224,7 +7221,7 @@
   Str255 name;
   struct FontAssoc *fat;
   struct AsscEntry *assc_entry;
-  Lisp_Object text_encoding_info_alist, text_encoding_info;
+  Lisp_Object text_encoding_info_alist, text_encoding_info, family;
   struct gcpro gcpro1;
 
   GetPort (&port);  /* save the current font number used */
@@ -7243,7 +7240,7 @@
       GetResInfo (font_handle, &id, &type, name);
       GetFNum (name, &fontnum);
       p2cstr (name);
-      if (fontnum == 0)
+      if (fontnum == 0 || *name == '.')
 	continue;
 
       TextFont (fontnum);
@@ -7255,8 +7252,10 @@
 					   text_encoding_info_alist);
       decode_mac_font_name (name, sizeof (name),
 			    XCAR (XCDR (text_encoding_info)));
-      fm_font_family_alist = Fcons (Fcons (build_string (name),
-					   make_number (fontnum)),
+      family = build_string (name);
+      if (!NILP (Fassoc (family, fm_font_family_alist)))
+	continue;
+      fm_font_family_alist = Fcons (Fcons (family, make_number (fontnum)),
 				    fm_font_family_alist);
       do
 	{
@@ -7277,14 +7276,9 @@
 		  Lisp_Object rest = XCDR (XCDR (text_encoding_info));
 
 		  for (; !NILP (rest); rest = XCDR (rest))
-		    {
-		      char *cs = SDATA (XCAR (rest));
-
-		      add_font_name_table_entry (mac_to_x_fontname (name,
-								    assc_entry->fontSize,
-								    assc_entry->fontStyle,
-								    cs));
-		    }
+		    add_mac_font_name (name, assc_entry->fontSize,
+				       assc_entry->fontStyle,
+				       SDATA (XCAR (rest)));
 		}
 	    }