From 9ec06c1450bc3f4984cbee812e30d3c9bfc202b8 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sat, 11 Feb 2012 00:19:20 +0000 Subject: let Tk_NameOfColor output a shorter color-name, when possible --- generic/tkColor.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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; } } -- cgit v0.12