summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornijtmans@users.sourceforge.net <jan.nijtmans>2012-02-11 00:19:20 (GMT)
committernijtmans@users.sourceforge.net <jan.nijtmans>2012-02-11 00:19:20 (GMT)
commit51649167dc2737386468d6e796aef2184d9e5dac (patch)
tree9ddff604c603a4fd764b1010b14c17ed5c62f5b3
parentad4cd4540bd884f7d1b6e44dde685971b89c394b (diff)
downloadtk-51649167dc2737386468d6e796aef2184d9e5dac.zip
tk-51649167dc2737386468d6e796aef2184d9e5dac.tar.gz
tk-51649167dc2737386468d6e796aef2184d9e5dac.tar.bz2
let Tk_NameOfColor output a shorter color-name, when possible
-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;
}
}