diff options
Diffstat (limited to 'unix/tkUnixColor.c')
-rw-r--r-- | unix/tkUnixColor.c | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/unix/tkUnixColor.c b/unix/tkUnixColor.c index 38434e9..43500ad 100644 --- a/unix/tkUnixColor.c +++ b/unix/tkUnixColor.c @@ -8,8 +8,6 @@ * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. - * - * RCS: @(#) $Id: tkUnixColor.c,v 1.8 2010/02/13 13:47:49 nijtmans Exp $ */ #include "tkUnixInt.h" @@ -128,20 +126,6 @@ TkpGetColor( Colormap colormap = Tk_Colormap(tkwin); XColor color; TkColor *tkColPtr; - char buf[100]; - unsigned len = strlen(name); - - /* - * Make sure that we never exceed a reasonable length of color name. A - * good maximum length is 99, arbitrary, but larger than any known color - * name. [Bug 2809525] - */ - - if (len > 99) { - len = 99; - } - memcpy(buf, name, len); - buf[len] = '\0'; /* * Map from the name to a pixel value. Call XAllocNamedColor rather than @@ -152,7 +136,29 @@ TkpGetColor( if (*name != '#') { XColor screen; - if (XAllocNamedColor(display, colormap, buf, &screen, &color) != 0) { + if (((*name - 'A') & 0xdf) < sizeof(tkWebColors)/sizeof(tkWebColors[0])) { + if (!((name[0] - 'G') & 0xdf) && !((name[1] - 'R') & 0xdf) + && !((name[2] - 'A') & 0xdb) && !((name[3] - 'Y') & 0xdf) + && !name[4]) { + name = "#808080808080"; + goto gotWebColor; + } else { + const char *p = tkWebColors[((*name - 'A') & 0x1f)]; + if (p) { + const char *q = name; + while (!((*p - *(++q)) & 0xdf)) { + if (!*p++) { + name = p; + goto gotWebColor; + } + } + } + } + } + if (strlen(name) > 99) { + /* Don't bother to parse this. [Bug 2809525]*/ + return (TkColor *) NULL; + } else if (XAllocNamedColor(display, colormap, name, &screen, &color) != 0) { DeleteStressedCmap(display, colormap); } else { /* @@ -162,13 +168,14 @@ TkpGetColor( * approximation to the desired color. */ - if (XLookupColor(display, colormap, buf, &color, &screen) == 0) { + if (XLookupColor(display, colormap, name, &color, &screen) == 0) { return NULL; } FindClosestColor(tkwin, &screen, &color); } } else { - if (XParseColor(display, colormap, buf, &color) == 0) { + gotWebColor: + if (TkParseColor(display, colormap, name, &color) == 0) { return NULL; } if (XAllocColor(display, colormap, &color) != 0) { @@ -433,6 +440,7 @@ TkpCmapStressed( return 0; } + /* * Local Variables: * mode: c |