summaryrefslogtreecommitdiffstats
path: root/unix/tkUnixColor.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2012-07-16 15:17:27 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2012-07-16 15:17:27 (GMT)
commit95c723cdcfe9a574608d9d85288588b9ea982bc9 (patch)
tree8c509cc28415813d532c9048aab943572fefbdba /unix/tkUnixColor.c
parent9f6d41c61faba304dce324aa4d5629db643f4191 (diff)
downloadtk-95c723cdcfe9a574608d9d85288588b9ea982bc9.zip
tk-95c723cdcfe9a574608d9d85288588b9ea982bc9.tar.gz
tk-95c723cdcfe9a574608d9d85288588b9ea982bc9.tar.bz2
better wrapper, with one less roundtrip through X11 server
Diffstat (limited to 'unix/tkUnixColor.c')
-rw-r--r--unix/tkUnixColor.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/unix/tkUnixColor.c b/unix/tkUnixColor.c
index aa01f24..43500ad 100644
--- a/unix/tkUnixColor.c
+++ b/unix/tkUnixColor.c
@@ -133,10 +133,28 @@ TkpGetColor(
* names.
*/
- /* TODO: better wrapper for XAllocNamedColor, for now always use TkParseColor */
- if (0 && *name != '#') {
+ if (*name != '#') {
XColor screen;
+ 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;
@@ -156,6 +174,7 @@ TkpGetColor(
FindClosestColor(tkwin, &screen, &color);
}
} else {
+ gotWebColor:
if (TkParseColor(display, colormap, name, &color) == 0) {
return NULL;
}