changeset 59034:2dd8aacd82ce

* term/mac-win.el (encoding-vector, mac-font-encoder-list) (ccl-encode-mac-centraleurroman-font): Use centraleurroman instead of centraleuropean as the name * macterm.c (endif, x_font_name_to_mac_font_name): Use maccentraleurroman instead of maccentraleuropean (mac_c_string_match, mac_do_list_fonts): Speed up font search by quickly finding a specific font without needing regexps.
author Steven Tamm <steventamm@mac.com>
date Sat, 18 Dec 2004 16:36:31 +0000
parents baa093a1f30a
children 34481a806584
files lisp/ChangeLog lisp/term/mac-win.el src/ChangeLog src/macterm.c
diffstat 4 files changed, 104 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Fri Dec 17 23:53:23 2004 +0000
+++ b/lisp/ChangeLog	Sat Dec 18 16:36:31 2004 +0000
@@ -1,3 +1,9 @@
+2004-12-18  YAMAMOTO Mitsuharu  <mituharu@math.s.chiba-u.ac.jp>
+
+	* term/mac-win.el (encoding-vector, mac-font-encoder-list)
+	(ccl-encode-mac-centraleurroman-font): Use centraleurroman
+	instead of centraleuropean as the name
+
 2004-12-17  Michael Albinus  <michael.albinus@gmx.de>
 
 	Sync with Tramp 2.0.46.
--- a/lisp/term/mac-win.el	Fri Dec 17 23:53:23 2004 +0000
+++ b/lisp/term/mac-win.el	Sat Dec 18 16:36:31 2004 +0000
@@ -199,7 +199,7 @@
 (let
     ((encoding-vector (make-vector 256 nil))
      (i 0)
-     (vec	;; mac-centraleuropean (128..255) -> UCS mapping
+     (vec	;; mac-centraleurroman (128..255) -> UCS mapping
       [	#x00C4	;; 128:LATIN CAPITAL LETTER A WITH DIAERESIS
 	#x0100	;; 129:LATIN CAPITAL LETTER A WITH MACRON
 	#x0101	;; 130:LATIN SMALL LETTER A WITH MACRON
@@ -339,8 +339,8 @@
     (setq i (1+ i)))
   (setq translation-table
 	(make-translation-table-from-vector encoding-vector))
-;;  (define-translation-table 'mac-centraleuropean-decoder translation-table)
-  (define-translation-table 'mac-centraleuropean-encoder
+;;  (define-translation-table 'mac-centraleurroman-decoder translation-table)
+  (define-translation-table 'mac-centraleurroman-encoder
     (char-table-extra-slot translation-table 0)))
 
 (let
@@ -493,8 +493,8 @@
 (defvar mac-font-encoder-list
   '(("mac-roman" mac-roman-encoder
      ccl-encode-mac-roman-font "%s")
-    ("mac-centraleuropean" mac-centraleuropean-encoder
-     ccl-encode-mac-centraleuropean-font "%s ce")
+    ("mac-centraleurroman" mac-centraleurroman-encoder
+     ccl-encode-mac-centraleurroman-font "%s ce")
     ("mac-cyrillic" mac-cyrillic-encoder
      ccl-encode-mac-cyrillic-font "%s cy")))
 
@@ -515,15 +515,15 @@
 	    (if mac-encoded
 		(aset table c mac-encoded))))))))
 
-(define-ccl-program ccl-encode-mac-centraleuropean-font
+(define-ccl-program ccl-encode-mac-centraleurroman-font
   `(0
     (if (r0 != ,(charset-id 'ascii))
 	(if (r0 <= ?\x8f)
-	    (translate-character mac-centraleuropean-encoder r0 r1)
+	    (translate-character mac-centraleurroman-encoder r0 r1)
 	  ((r1 <<= 7)
 	   (r1 |= r2)
-	   (translate-character mac-centraleuropean-encoder r0 r1)))))
-  "CCL program for Mac Central European font")
+	   (translate-character mac-centraleurroman-encoder r0 r1)))))
+  "CCL program for Mac Central European Roman font")
 
 (define-ccl-program ccl-encode-mac-cyrillic-font
   `(0
--- a/src/ChangeLog	Fri Dec 17 23:53:23 2004 +0000
+++ b/src/ChangeLog	Sat Dec 18 16:36:31 2004 +0000
@@ -1,3 +1,10 @@
+2004-12-18  YAMAMOTO Mitsuharu  <mituharu@math.s.chiba-u.ac.jp>
+
+	* macterm.c (endif, x_font_name_to_mac_font_name): Use
+	maccentraleurroman instead of maccentraleuropean
+	(mac_c_string_match, mac_do_list_fonts): Speed up font search by
+	quickly finding a specific font without needing regexps.
+
 2004-12-15  Jan Dj,Ad(Brv  <jan.h.d@swipnet.se>
 
 	* syssignal.h: Declare main_thread.
--- a/src/macterm.c	Fri Dec 17 23:53:23 2004 +0000
+++ b/src/macterm.c	Sat Dec 18 16:36:31 2004 +0000
@@ -5976,7 +5976,7 @@
 	strcpy(cs, "mac-cyrillic");
 	break;
       case kTextEncodingMacCentralEurRoman:
-	strcpy(cs, "mac-centraleuropean");
+	strcpy(cs, "mac-centraleurroman");
 	break;
       case kTextEncodingMacSymbol:
       case kTextEncodingMacDingbats:
@@ -6034,7 +6034,7 @@
     coding_system = Qeuc_kr;
   else if (strcmp (cs, "mac-roman") == 0
 	   || strcmp (cs, "mac-cyrillic") == 0
-	   || strcmp (cs, "mac-centraleuropean") == 0
+	   || strcmp (cs, "mac-centraleurroman") == 0
 	   || strcmp (cs, "adobe-fontspecific") == 0)
     strcpy (mf, family);
   else
@@ -6276,6 +6276,28 @@
   };
 
 static Lisp_Object
+mac_c_string_match (regexp, string, nonspecial, exact)
+     Lisp_Object regexp;
+     const char *string, *nonspecial;
+     int exact;
+{
+  if (exact)
+    {
+      if (strcmp (string, nonspecial) == 0)
+	return build_string (string);
+    }
+  else if (strstr (string, nonspecial))
+    {
+      Lisp_Object str = build_string (string);
+
+      if (fast_string_match (regexp, str) >= 0)
+	return str;
+    }
+
+  return Qnil;
+}
+
+static Lisp_Object
 mac_do_list_fonts (pattern, maxnames)
      char *pattern;
      int maxnames;
@@ -6286,6 +6308,8 @@
   char scaled[256];
   char *ptr;
   int scl_val[XLFD_SCL_LAST], *field, *val;
+  char *longest_start, *cur_start, *nonspecial;
+  int longest_len, cur_len, exact;
 
   for (i = 0; i < XLFD_SCL_LAST; i++)
     scl_val[i] = -1;
@@ -6343,34 +6367,66 @@
   ptr = regex;
   *ptr++ = '^';
 
-  /* Turn pattern into a regexp and do a regexp match.  */
+  longest_start = cur_start = ptr;
+  longest_len = cur_len = 0;
+  exact = 1;
+
+  /* Turn pattern into a regexp and do a regexp match.  Also find the
+     longest substring containing no special characters.  */
   for (; *pattern; pattern++)
     {
-      if (*pattern == '?')
-        *ptr++ = '.';
-      else if (*pattern == '*')
-        {
-          *ptr++ = '.';
-          *ptr++ = '*';
-        }
+      if (*pattern == '?' || *pattern == '*')
+	{
+	  if (cur_len > longest_len)
+	    {
+	      longest_start = cur_start;
+	      longest_len = cur_len;
+	    }
+	  cur_len = 0;
+	  exact = 0;
+
+	  if (*pattern == '?')
+	    *ptr++ = '.';
+	  else /* if (*pattern == '*') */
+	    {
+	      *ptr++ = '.';
+	      *ptr++ = '*';
+	    }
+	}
       else
-        *ptr++ = tolower (*pattern);
-    }
+	{
+	  if (cur_len == 0)
+	    cur_start = ptr;
+	  cur_len++;
+
+	  *ptr++ = tolower (*pattern);
+	}
+    }
+
+  if (cur_len > longest_len)
+    {
+      longest_start = cur_start;
+      longest_len = cur_len;
+    }
+
   *ptr = '$';
   *(ptr + 1) = '\0';
 
+  nonspecial = xmalloc (longest_len + 1);
+  strncpy (nonspecial, longest_start, longest_len);
+  nonspecial[longest_len] = '\0';
+
   pattern_regex = build_string (regex);
 
   for (i = 0; i < font_name_count; i++)
     {
-      fontname = build_string (font_name_table[i]);
-      if (fast_string_match (pattern_regex, fontname) >= 0)
+      fontname = mac_c_string_match (pattern_regex, font_name_table[i],
+				     nonspecial, exact);
+      if (!NILP (fontname))
 	{
 	  font_list = Fcons (fontname, font_list);
-
-          n_fonts++;
-          if (maxnames > 0 && n_fonts >= maxnames)
-            break;
+	  if (exact || maxnames > 0 && ++n_fonts >= maxnames)
+	    return font_list;
 	}
       else if (scl_val[XLFD_SCL_PIXEL_SIZE] > 0
 	       && (ptr = strstr (font_name_table[i], "-0-0-75-75-m-0-")))
@@ -6384,17 +6440,19 @@
 		   scl_val[XLFD_SCL_POINT_SIZE],
 		   scl_val[XLFD_SCL_AVGWIDTH],
 		   ptr + sizeof ("-0-0-75-75-m-0-") - 1);
-	  fontname = build_string (scaled);
-	  if (fast_string_match (pattern_regex, fontname) >= 0)
+	  fontname = mac_c_string_match (pattern_regex, scaled,
+					 nonspecial, exact);
+	  if (!NILP (fontname))
 	    {
 	      font_list = Fcons (fontname, font_list);
-
-	      n_fonts++;
-	      if (maxnames > 0 && n_fonts >= maxnames)
-		break;
+	      if (exact || maxnames > 0 && ++n_fonts >= maxnames)
+		return font_list;
 	    }
 	}
     }
+
+  xfree (nonspecial);
+
   return font_list;
 }