summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2012-02-11 00:19:20 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2012-02-11 00:19:20 (GMT)
commit9ec06c1450bc3f4984cbee812e30d3c9bfc202b8 (patch)
tree9ddff604c603a4fd764b1010b14c17ed5c62f5b3 /generic
parentc910863e19f9c9cc3db56924634315a37ecfe2bb (diff)
downloadtk-9ec06c1450bc3f4984cbee812e30d3c9bfc202b8.zip
tk-9ec06c1450bc3f4984cbee812e30d3c9bfc202b8.tar.gz
tk-9ec06c1450bc3f4984cbee812e30d3c9bfc202b8.tar.bz2
let Tk_NameOfColor output a shorter color-name, when possible
Diffstat (limited to 'generic')
-rw-r--r--generic/tkColor.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/generic/tkColor.c b/generic/tkColor.c
index 87f3209..a9b1fc1 100644
--- a/generic/tkColor.c
+++ b/generic/tkColor.c
@@ -375,6 +375,21 @@ Tk_NameOfColor(colorPtr)
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
sprintf(tsdPtr->rgbString, "#%04x%04x%04x", colorPtr->red,
colorPtr->green, colorPtr->blue);
+ /* If the string has the form #RSRSTUTUVWVW (where equal
+ * letters denote equal hexdigits) then this is
+ * equivalent to #RSTUVW. Then output the shorter form */
+ if ((tsdPtr->rgbString[1] == tsdPtr->rgbString[3])
+ && (tsdPtr->rgbString[2] == tsdPtr->rgbString[4])
+ && (tsdPtr->rgbString[5] == tsdPtr->rgbString[7])
+ && (tsdPtr->rgbString[6] == tsdPtr->rgbString[8])
+ && (tsdPtr->rgbString[9] == tsdPtr->rgbString[11])
+ && (tsdPtr->rgbString[10] == tsdPtr->rgbString[12])) {
+ tsdPtr->rgbString[3] = tsdPtr->rgbString[5];
+ tsdPtr->rgbString[4] = tsdPtr->rgbString[6];
+ tsdPtr->rgbString[5] = tsdPtr->rgbString[9];
+ tsdPtr->rgbString[6] = tsdPtr->rgbString[10];
+ tsdPtr->rgbString[7] = '\0';
+ }
return tsdPtr->rgbString;
}
}