aboutsummaryrefslogtreecommitdiff
path: root/generic
diff options
context:
space:
mode:
Diffstat (limited to 'generic')
-rw-r--r--generic/Color.c49
1 files changed, 32 insertions, 17 deletions
diff --git a/generic/Color.c b/generic/Color.c
index 47ff7ab..ba06dc1 100644
--- a/generic/Color.c
+++ b/generic/Color.c
@@ -145,10 +145,6 @@ typedef struct {
* Maximum size of a color name including the \0.
*/
#define COLOR_NAME_SIZE 32
-/*
- * Maximum size of a gradient name including the \0.
- */
-#define GRADIENT_NAME_SIZE 1024
/*
* Maximum intensity for a color.
@@ -949,7 +945,7 @@ ZnGetReliefGradient(Tcl_Interp *interp,
{
XColor *base, light_color, dark_color, color;
char color_name[COLOR_NAME_SIZE];
- char buffer[GRADIENT_NAME_SIZE];
+ char buffer[COLOR_NAME_SIZE*(3+2*RELIEF_STEPS)];
int j, tmp1, tmp2;
int red_range, green_range, blue_range;
@@ -1062,14 +1058,29 @@ ZnNameGradient(Tcl_Interp *interp,
Tcl_HashEntry *hash;
int new;
ZnGradient *grad;
-
+ XColor color;
+
grad = ZnGetGradient(interp, tkwin, grad_descr);
if (!grad) {
+ Tcl_AppendResult(interp, "gradient specification \"", grad_descr,
+ "\", is invalid", NULL);
+ return False;
+ }
+ /*
+ * First try to find if the name interfere with a color name,
+ * this must be avoided. Gradients may be described by a single
+ * color name and gradient descriptions / names share the same
+ * name space.
+ */
+ if (XParseColor(Tk_Display(tkwin), Tk_Colormap(tkwin), name, &color)) {
+ Tcl_AppendResult(interp, "gradient name \"", name,
+ "\", is a color name", NULL);
return False;
}
-
hash = Tcl_CreateHashEntry(&gradient_table, Tk_GetUid(name), &new);
if (!new) {
+ Tcl_AppendResult(interp, "gradient name \"", name,
+ "\", is already in use", NULL);
return False;
}
else {
@@ -1138,7 +1149,7 @@ ZnGetGradientByValue(ZnGradient *grad)
ZnGradient *
ZnGetGradient(Tcl_Interp *interp,
Tk_Window tkwin,
- Tk_Uid name)
+ Tk_Uid desc)
{
Tcl_HashEntry *hash;
ZnGradient *grad;
@@ -1147,12 +1158,12 @@ ZnGetGradient(Tcl_Interp *interp,
int num_tok, angle, position, control;
double x, y;
char *color_ptr, color_name[COLOR_NAME_SIZE];
- char buffer[GRADIENT_NAME_SIZE];
+ char *buffer = NULL;
ZnGradientColor *first, *last;
XColor color;
int red_range, green_range, blue_range;
- if (!name || !*name) {
+ if (!desc || !*desc) {
return NULL;
}
if (!initialized) {
@@ -1163,9 +1174,9 @@ ZnGetGradient(Tcl_Interp *interp,
* First, check to see if there's already a gradient that will work
* for this request.
*/
- name = Tk_GetUid(name);
+ desc = Tk_GetUid(desc);
- hash = Tcl_CreateHashEntry(&gradient_table, name, &new);
+ hash = Tcl_CreateHashEntry(&gradient_table, desc, &new);
if (!new) {
grad = (ZnGradient *) Tcl_GetHashValue(hash);
grad->ref_count++;
@@ -1174,11 +1185,12 @@ ZnGetGradient(Tcl_Interp *interp,
/*
* No satisfactory gradient exists yet. Initialize a new one.
*/
- if ((name[0] == '/') || (name[0] == '(') || (name[0] == '[')) {
+ if ((desc[0] == '/') || (desc[0] == '(') || (desc[0] == '[')) {
goto grad_err2;
}
- strcpy(buffer, name);
+ buffer = ZnMalloc(strlen(desc) + 1);
+ strcpy(buffer, desc);
/*
* Then look at the gradient type.
*/
@@ -1188,9 +1200,10 @@ ZnGetGradient(Tcl_Interp *interp,
num_tok = sscanf(scan_ptr, "/%d", &angle);
if (num_tok != 1) {
grad_err2:
+ ZnFree(buffer);
Tcl_DeleteHashEntry(hash);
Tcl_AppendResult(interp, "incorrect gradient format \"",
- name, "\",", NULL);
+ desc, "\",", NULL);
return NULL;
}
*scan_ptr = '\0';
@@ -1256,8 +1269,9 @@ ZnGetGradient(Tcl_Interp *interp,
}
if (num_tok == 0) {
Tcl_AppendResult(interp, "incorrect gradient format \"",
- name, "\",", NULL);
+ desc, "\",", NULL);
grad_err:
+ ZnFree(buffer);
Tcl_DeleteHashEntry(hash);
for (j = 0; j < i; j++) {
ZnFreeColor(grad->colors[j].rgb);
@@ -1290,7 +1304,7 @@ ZnGetGradient(Tcl_Interp *interp,
if ((grad->colors[i].position > 100) ||
(grad->colors[i].position < grad->colors[i-1].position)) {
Tcl_AppendResult(interp, "incorrect color position in gradient \"",
- name, "\",", NULL);
+ desc, "\",", NULL);
goto grad_err;
}
}
@@ -1302,6 +1316,7 @@ ZnGetGradient(Tcl_Interp *interp,
}
scan_ptr = strtok(NULL, "|");
}
+ ZnFree(buffer);
}
/*