changeset 23314:87acd2b6ce97

(w32_color_map_lookup): New function. (x_to_w32_color): Approximate colors ending in numbers if necessary.
author Geoff Voelker <voelker@cs.washington.edu>
date Thu, 24 Sep 1998 02:14:55 +0000
parents fdd00554260b
children 86a8b8566369
files src/w32fns.c
diffstat 1 files changed, 50 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/w32fns.c	Wed Sep 23 23:42:22 1998 +0000
+++ b/src/w32fns.c	Thu Sep 24 02:14:55 1998 +0000
@@ -1266,6 +1266,38 @@
     return Qnil;
 }
 
+COLORREF
+w32_color_map_lookup (colorname)
+     char *colorname;
+{
+  Lisp_Object tail, ret = Qnil;
+
+  BLOCK_INPUT;
+
+  for (tail = Vw32_color_map; !NILP (tail); tail = Fcdr (tail))
+    {
+      register Lisp_Object elt, tem;
+
+      elt = Fcar (tail);
+      if (!CONSP (elt)) continue;
+
+      tem = Fcar (elt);
+
+      if (lstrcmpi (XSTRING (tem)->data, colorname) == 0)
+	{
+	  ret = XUINT (Fcdr (elt));
+	  break;
+	}
+
+      QUIT;
+    }
+
+
+  UNBLOCK_INPUT;
+
+  return ret;
+}
+
 COLORREF 
 x_to_w32_color (colorname)
      char * colorname;
@@ -1430,27 +1462,30 @@
   /* I am not going to attempt to handle any of the CIE color schemes
      or TekHVC, since I don't know the algorithms for conversion to
      RGB.  */
-  
-  for (tail = Vw32_color_map; !NILP (tail); tail = Fcdr (tail))
+
+  /* If we fail to lookup the color name in w32_color_map, then check the
+     colorname to see if it can be crudely approximated: If the X color 
+     ends in a number (e.g., "darkseagreen2"), strip the number and
+     return the result of looking up the base color name.  */
+  ret = w32_color_map_lookup (colorname);
+  if (NILP (ret)) 
     {
-      register Lisp_Object elt, tem;
-
-      elt = Fcar (tail);
-      if (!CONSP (elt)) continue;
-
-      tem = Fcar (elt);
-
-      if (lstrcmpi (XSTRING (tem)->data, colorname) == 0)
+      int len = strlen (colorname);
+
+      if (isdigit (colorname[len - 1])) 
 	{
-	  ret = XUINT(Fcdr (elt));
-	  break;
+	  char *ptr, *approx = alloca (len);
+
+	  strcpy (approx, colorname);
+	  ptr = &approx[len - 1];
+	  while (ptr > approx && isdigit (*ptr)) 
+	      *ptr-- = '\0';
+
+	  ret = w32_color_map_lookup (approx);
 	}
-
-      QUIT;
     }
   
   UNBLOCK_INPUT;
-  
   return ret;
 }