aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--generic/Attrs.c186
-rw-r--r--generic/Attrs.h54
2 files changed, 187 insertions, 53 deletions
diff --git a/generic/Attrs.c b/generic/Attrs.c
index a7238cd..2e58f67 100644
--- a/generic/Attrs.c
+++ b/generic/Attrs.c
@@ -154,16 +154,16 @@ CharToDim(char dim)
* The positional parameters can be omitted if there is only one field.
*
*/
-LabelFormat
+ZnLabelFormat
LabelFormatCreate(Tcl_Interp *interp,
char *format_str,
int num_fields)
{
ZnList fields;
Tcl_HashEntry *entry;
- FieldFormatStruct field_struct;
- FieldFormat field_array;
- LabelFormat format;
+ ZnFieldFormatStruct field_struct;
+ ZnFieldFormat field_array;
+ ZnLabelFormat format;
int width, height;
ZnDim c_width=0.0, c_height=0.0;
int index, num_tok, num_ffs, new;
@@ -177,7 +177,7 @@ LabelFormatCreate(Tcl_Interp *interp,
}
entry = Tcl_CreateHashEntry(&format_cache, format_str, &new);
if (!new) {
- format = (LabelFormat) Tcl_GetHashValue(entry);
+ format = (ZnLabelFormat) Tcl_GetHashValue(entry);
if (format->num_fields <= num_fields) {
format->ref_count++;
return format;
@@ -189,7 +189,7 @@ LabelFormatCreate(Tcl_Interp *interp,
}
}
- fields = ZnListNew(1, sizeof(FieldFormatStruct));
+ fields = ZnListNew(1, sizeof(ZnFieldFormatStruct));
/*
* Try to see if it starts with a number or a leader spec.
@@ -198,7 +198,7 @@ LabelFormatCreate(Tcl_Interp *interp,
ptr++;
}
if (!*ptr) {
- goto lf_end_parse;
+ goto lf_error_syn;
}
if ((*ptr != 'x') && (*ptr != 'f') && (*ptr != 'i') && (*ptr != 'a')) {
c_width = (ZnDim) strtod(ptr, &next_ptr);
@@ -293,15 +293,15 @@ LabelFormatCreate(Tcl_Interp *interp,
}
lf_end_parse:
- field_array = (FieldFormat) ZnListArray(fields);
+ field_array = (ZnFieldFormat) ZnListArray(fields);
num_ffs = ZnListSize(fields);
- format = (LabelFormat) ZnMalloc(sizeof(LabelFormatStruct) +
- (num_ffs-1) * sizeof(FieldFormatStruct));
+ format = (ZnLabelFormat) ZnMalloc(sizeof(ZnLabelFormatStruct) +
+ (num_ffs-1) * sizeof(ZnFieldFormatStruct));
format->clip_width = (short) c_width;
format->clip_height = (short) c_height;
format->num_fields = num_ffs;
- memcpy(&format->fields, field_array, num_ffs * sizeof(FieldFormatStruct));
+ memcpy(&format->fields, field_array, num_ffs * sizeof(ZnFieldFormatStruct));
ZnListFree(fields);
format->ref_count = 1;
@@ -312,8 +312,8 @@ LabelFormatCreate(Tcl_Interp *interp,
}
-LabelFormat
-LabelFormatDuplicate(LabelFormat lf)
+ZnLabelFormat
+LabelFormatDuplicate(ZnLabelFormat lf)
{
lf->ref_count++;
return lf;
@@ -321,7 +321,7 @@ LabelFormatDuplicate(LabelFormat lf)
void
-LabelFormatDelete(LabelFormat lf)
+LabelFormatDelete(ZnLabelFormat lf)
{
lf->ref_count--;
if (lf->ref_count == 0) {
@@ -332,12 +332,12 @@ LabelFormatDelete(LabelFormat lf)
char *
-LabelFormatGetString(LabelFormat lf)
+LabelFormatGetString(ZnLabelFormat lf)
{
return Tcl_GetHashKey(&format_cache, lf->entry);
#if 0
- FieldFormat ff;
+ ZnFieldFormat ff;
char *ptr;
char x_char, y_char, w_char, h_char;
int i, count;
@@ -382,7 +382,7 @@ LabelFormatGetString(LabelFormat lf)
* set to zero, it means that there is no clipbox.
*/
ZnBool
-LabelFormatGetClipBox(LabelFormat lf,
+LabelFormatGetClipBox(ZnLabelFormat lf,
ZnDim *w,
ZnDim *h)
{
@@ -398,18 +398,18 @@ LabelFormatGetClipBox(LabelFormat lf,
void
-LabelFormatGetField(LabelFormat lf,
- int field,
- char *x_attach,
- char *y_attach,
- char *x_dim,
- char *y_dim,
- int *x_spec,
- int *y_spec,
- short *width_spec,
- short *height_spec)
+LabelFormatGetField(ZnLabelFormat lf,
+ int field,
+ char *x_attach,
+ char *y_attach,
+ char *x_dim,
+ char *y_dim,
+ int *x_spec,
+ int *y_spec,
+ short *width_spec,
+ short *height_spec)
{
- FieldFormat fptr;
+ ZnFieldFormat fptr;
fptr = &lf->fields[field];
*x_attach = fptr->x_attach;
@@ -434,14 +434,14 @@ static Tcl_HashTable line_end_cache;
static ZnBool line_end_inited = False;
-LineEnd
+ZnLineEnd
LineEndCreate(Tcl_Interp *interp,
char *line_end_str)
{
Tcl_HashEntry *entry;
- LineEnd le;
+ ZnLineEnd le;
int new, argc;
- ZnReal a, b ,c;
+ ZnReal a, b, c;
if (!line_end_inited) {
Tcl_InitHashTable(&line_end_cache, TCL_STRING_KEYS);
@@ -450,14 +450,14 @@ LineEndCreate(Tcl_Interp *interp,
entry = Tcl_CreateHashEntry(&line_end_cache, line_end_str, &new);
if (!new) {
- le = (LineEnd) Tcl_GetHashValue(entry);
+ le = (ZnLineEnd) Tcl_GetHashValue(entry);
le->ref_count++;
return le;
}
argc = sscanf(line_end_str, "%lf %lf %lf", &a, &b, &c);
if (argc == 3) {
- le = (LineEnd) ZnMalloc(sizeof(LineEndStruct));
+ le = (ZnLineEnd) ZnMalloc(sizeof(ZnLineEndStruct));
le->shape_a = a;
le->shape_b = b;
le->shape_c = c;
@@ -475,14 +475,14 @@ LineEndCreate(Tcl_Interp *interp,
char *
-LineEndGetString(LineEnd le)
+LineEndGetString(ZnLineEnd le)
{
return Tcl_GetHashKey(&line_end_cache, le->entry);
}
void
-LineEndDelete(LineEnd le)
+LineEndDelete(ZnLineEnd le)
{
le->ref_count--;
if (le->ref_count == 0) {
@@ -492,9 +492,121 @@ LineEndDelete(LineEnd le)
}
-LineEnd
-LineEndDuplicate(LineEnd le)
+ZnLineEnd
+LineEndDuplicate(ZnLineEnd le)
{
le->ref_count++;
return le;
}
+
+
+/*
+ ****************************************************************
+ *
+ * Code for gradient geometry.
+ *
+ ****************************************************************
+ */
+static Tcl_HashTable gradient_geom_cache;
+static ZnBool gradient_inited = False;
+
+ZnGradientGeom
+GradientGeomCreate(Tcl_Interp *interp,
+ char *grad_geom_str)
+{
+ Tcl_HashEntry *entry;
+ ZnGradientGeom gg;
+ int new;
+ char *next_ptr, *ptr;
+ int d1, d2, angle;
+
+ if (!gradient_inited) {
+ Tcl_InitHashTable(&gradient_geom_cache, TCL_STRING_KEYS);
+ gradient_inited = True;
+ }
+
+ entry = Tcl_CreateHashEntry(&gradient_geom_cache, grad_geom_str, &new);
+ if (!new) {
+ gg = (ZnGradientGeom) Tcl_GetHashValue(entry);
+ gg->ref_count++;
+ return gg;
+ }
+
+ d1 = d2 = 50;
+ angle = 0;
+ ptr = grad_geom_str;
+ if (!*ptr) {
+ error_gg:
+ Tcl_AppendResult(interp, "incorrect gradient geometry spec: \"",
+ grad_geom_str,
+ "\", should be: [threshold1][-threshold2][/angle]", NULL);
+ return NULL;
+ }
+ if (*ptr != '/') {
+ d1 = strtol(ptr, &next_ptr, 10);
+ if (next_ptr == ptr) {
+ goto error_gg;
+ }
+ ptr = next_ptr;
+ if (*next_ptr == '-') {
+ ptr++;
+ d2 = strtol(ptr, &next_ptr, 10);
+ if (next_ptr == ptr) {
+ goto error_gg;
+ }
+ ptr = next_ptr;
+ }
+ }
+ if (*ptr == '/') {
+ ptr++;
+ angle = strtol(ptr, &next_ptr, 10);
+ if (*next_ptr != 0) {
+ goto error_gg;
+ }
+ ptr = next_ptr;
+ while (angle < 0) {
+ angle += 360;
+ }
+ while (angle >= 360) {
+ angle -= 360;
+ }
+ }
+ else if (*next_ptr != 0) {
+ goto error_gg;
+ }
+ gg = (ZnGradientGeom) ZnMalloc(sizeof(ZnGradientGeomStruct));
+ gg->d1 = d1;
+ gg->d2 = d2;
+ gg->angle = angle;
+ gg->entry = entry;
+ gg->ref_count = 1;
+ Tcl_SetHashValue(entry, (ClientData) gg);
+
+ return gg;
+}
+
+
+char *
+GradientGeomGetString(ZnGradientGeom gg)
+{
+ return Tcl_GetHashKey(&gradient_geom_cache, gg->entry);
+}
+
+
+void
+GradientGeomDelete(ZnGradientGeom gg)
+{
+ gg->ref_count--;
+ if (gg->ref_count == 0) {
+ Tcl_DeleteHashEntry(gg->entry);
+ ZnFree(gg);
+ }
+}
+
+
+ZnGradientGeom
+GradientGeomDuplicate(ZnGradientGeom gg)
+{
+ gg->ref_count++;
+ return gg;
+}
diff --git a/generic/Attrs.h b/generic/Attrs.h
index 2cdb7ec..582db9d 100644
--- a/generic/Attrs.h
+++ b/generic/Attrs.h
@@ -65,7 +65,7 @@ typedef struct {
char y_attach;
char x_dim;
char y_dim;
-} FieldFormatStruct, *FieldFormat;
+} ZnFieldFormatStruct, *ZnFieldFormat;
typedef struct {
short clip_width;
@@ -73,27 +73,27 @@ typedef struct {
int num_fields;
Tcl_HashEntry *entry;
int ref_count;
- FieldFormatStruct fields[1];
-} LabelFormatStruct, *LabelFormat;
+ ZnFieldFormatStruct fields[1];
+} ZnLabelFormatStruct, *ZnLabelFormat;
-LabelFormat
+ZnLabelFormat
LabelFormatCreate(Tcl_Interp * /* interp */,
char * /* format_str */,
int /* num_fields */);
-LabelFormat
-LabelFormatDuplicate(LabelFormat /* label_format */);
+ZnLabelFormat
+LabelFormatDuplicate(ZnLabelFormat /* label_format */);
void
-LabelFormatDelete(LabelFormat /* label_format */);
+LabelFormatDelete(ZnLabelFormat /* label_format */);
char *
-LabelFormatGetString(LabelFormat /* label_format */);
+LabelFormatGetString(ZnLabelFormat /* label_format */);
ZnBool
-LabelFormatGetClipBox(LabelFormat /* label_format */,
+LabelFormatGetClipBox(ZnLabelFormat /* label_format */,
ZnDim */* width */,
ZnDim */* height */);
#define LabelFormatNumFields(lf) ((lf)->num_fields)
void
-LabelFormatGetField(LabelFormat /* label_format */,
+LabelFormatGetField(ZnLabelFormat /* label_format */,
int /* field */,
char */* x_attach */,
char */* y_attach */,
@@ -113,18 +113,40 @@ typedef struct {
ZnReal shape_c;
Tcl_HashEntry *entry;
int ref_count;
-} LineEndStruct, *LineEnd;
+} ZnLineEndStruct, *ZnLineEnd;
-LineEnd
+ZnLineEnd
LineEndCreate(Tcl_Interp *interp,
char *line_end_str);
-LineEnd
-LineEndDuplicate(LineEnd le);
+ZnLineEnd
+LineEndDuplicate(ZnLineEnd le);
void
-LineEndDelete(LineEnd le);
+LineEndDelete(ZnLineEnd le);
char *
-LineEndGetString(LineEnd le);
+LineEndGetString(ZnLineEnd le);
+/*
+ * Gradient Geometry.
+ */
+typedef struct {
+ int d1;
+ int d2;
+ int angle;
+ Tcl_HashEntry *entry;
+ int ref_count;
+} ZnGradientGeomStruct, *ZnGradientGeom;
+
+ZnGradientGeom
+GradientGeomCreate(Tcl_Interp *interp,
+ char *grad_geom_str);
+ZnGradientGeom
+GradientGeomDuplicate(ZnGradientGeom gg);
+void
+GradientGeomDelete(ZnGradientGeom gg);
+char *
+GradientGeomGetString(ZnGradientGeom gg);
+
+
#ifdef __CPLUSPLUS__
}
#endif