aboutsummaryrefslogtreecommitdiff
path: root/generic/Attrs.c
diff options
context:
space:
mode:
authorlecoanet2003-04-16 09:49:22 +0000
committerlecoanet2003-04-16 09:49:22 +0000
commit3261805fee19e346b4d1f84b23816daa1628764a (patch)
tree63ca1d7e4b0a3d9ae49cc0888e58033c3ef3fe22 /generic/Attrs.c
parenteed2656db0adae2c234c3d74af0913746ed5c444 (diff)
downloadtkzinc-3261805fee19e346b4d1f84b23816daa1628764a.zip
tkzinc-3261805fee19e346b4d1f84b23816daa1628764a.tar.gz
tkzinc-3261805fee19e346b4d1f84b23816daa1628764a.tar.bz2
tkzinc-3261805fee19e346b4d1f84b23816daa1628764a.tar.xz
Update from the Windows port and general cleanup/restructure
Diffstat (limited to 'generic/Attrs.c')
-rw-r--r--generic/Attrs.c805
1 files changed, 651 insertions, 154 deletions
diff --git a/generic/Attrs.c b/generic/Attrs.c
index 175a0ee..77ce2a5 100644
--- a/generic/Attrs.c
+++ b/generic/Attrs.c
@@ -34,7 +34,6 @@
#include "WidgetInfo.h"
#include <memory.h>
-#include <malloc.h>
#include <stdlib.h>
@@ -43,88 +42,6 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ "
/*
- ******************************************************************
- *
- * Code for label formats.
- *
- ******************************************************************
- */
-static Tcl_HashTable format_cache;
-static ZnBool format_inited = False;
-
-#if 0
-static char
-AttachToChar(char attach)
-{
- switch (attach) {
- case LF_ATTACH_FWD:
- return '>';
- case LF_ATTACH_BWD:
- return '<';
- case LF_ATTACH_LEFT:
- return '^';
- case LF_ATTACH_RIGHT:
- return '$';
- case LF_ATTACH_PIXEL:
- default:
- return '+';
- }
-}
-
-static char
-DimToChar(char dim)
-{
- switch (dim) {
- case LF_DIM_FONT:
- return 'f';
- case LF_DIM_ICON:
- return 'i';
- case LF_DIM_AUTO:
- return 'a';
- case LF_DIM_PIXEL:
- default:
- return 'x';
- }
-}
-#endif
-
-static char
-CharToAttach(char attach)
-{
- switch (attach) {
- case '>':
- return LF_ATTACH_FWD;
- case '<':
- return LF_ATTACH_BWD;
- case '^':
- return LF_ATTACH_LEFT;
- case '$':
- return LF_ATTACH_RIGHT;
- case '+':
- default:
- return LF_ATTACH_PIXEL;
- }
-}
-
-static char
-CharToDim(char dim)
-{
- switch (dim) {
- case 'f':
- return LF_DIM_FONT;
- case 'i':
- return LF_DIM_ICON;
- case 'a':
- return LF_DIM_AUTO;
- case 'l':
- return LF_DIM_LABEL;
- case 'x':
- default:
- return LF_DIM_PIXEL;
- }
-}
-
-/*
****************************************************************
*
* Code for reliefs.
@@ -144,48 +61,48 @@ CharToDim(char dim)
#define RELIEF_RAISED_RULE_SPEC "raisedrule"
int
-ZnGetRelief(WidgetInfo *wi,
- char *name,
- ReliefStyle *relief)
+ZnGetRelief(ZnWInfo *wi,
+ char *name,
+ ZnReliefStyle *relief)
{
size_t length;
length = strlen(name);
- if (strncasecmp(name, RELIEF_FLAT_SPEC, length) == 0) {
- *relief = RELIEF_FLAT;
+ if (strncmp(name, RELIEF_FLAT_SPEC, length) == 0) {
+ *relief = ZN_RELIEF_FLAT;
}
- else if (strncasecmp(name, RELIEF_SUNKEN_SPEC, length) == 0) {
- *relief = RELIEF_SUNKEN;
+ else if (strncmp(name, RELIEF_SUNKEN_SPEC, length) == 0) {
+ *relief = ZN_RELIEF_SUNKEN;
}
- else if ((strncasecmp(name, RELIEF_RAISED_SPEC, length) == 0) && (length >= 2)) {
- *relief = RELIEF_RAISED;
+ else if ((strncmp(name, RELIEF_RAISED_SPEC, length) == 0) && (length >= 2)) {
+ *relief = ZN_RELIEF_RAISED;
}
- else if ((strncasecmp(name, RELIEF_RIDGE_SPEC, length) == 0) && (length >= 2)) {
- *relief = RELIEF_RIDGE;
+ else if ((strncmp(name, RELIEF_RIDGE_SPEC, length) == 0) && (length >= 2)) {
+ *relief = ZN_RELIEF_RIDGE;
}
- else if (strncasecmp(name, RELIEF_GROOVE_SPEC, length) == 0) {
- *relief = RELIEF_GROOVE;
+ else if (strncmp(name, RELIEF_GROOVE_SPEC, length) == 0) {
+ *relief = ZN_RELIEF_GROOVE;
}
- else if ((strncasecmp(name, RELIEF_ROUND_SUNKEN_SPEC, length) == 0) && (length >= 6)) {
- *relief = RELIEF_ROUND_SUNKEN;
+ else if ((strncmp(name, RELIEF_ROUND_SUNKEN_SPEC, length) == 0) && (length >= 6)) {
+ *relief = ZN_RELIEF_ROUND_SUNKEN;
}
- else if ((strncasecmp(name, RELIEF_ROUND_RAISED_SPEC, length) == 0) && (length >= 7)) {
- *relief = RELIEF_ROUND_RAISED;
+ else if ((strncmp(name, RELIEF_ROUND_RAISED_SPEC, length) == 0) && (length >= 7)) {
+ *relief = ZN_RELIEF_ROUND_RAISED;
}
- else if ((strncasecmp(name, RELIEF_ROUND_RIDGE_SPEC, length) == 0) && (length >= 7)) {
- *relief = RELIEF_ROUND_RIDGE;
+ else if ((strncmp(name, RELIEF_ROUND_RIDGE_SPEC, length) == 0) && (length >= 7)) {
+ *relief = ZN_RELIEF_ROUND_RIDGE;
}
- else if ((strncasecmp(name, RELIEF_ROUND_GROOVE_SPEC, length) == 0) && (length >= 6)) {
- *relief = RELIEF_ROUND_GROOVE;
+ else if ((strncmp(name, RELIEF_ROUND_GROOVE_SPEC, length) == 0) && (length >= 6)) {
+ *relief = ZN_RELIEF_ROUND_GROOVE;
}
- else if ((strncasecmp(name, RELIEF_SUNKEN_RULE_SPEC, length) == 0) && (length >= 7)) {
- *relief = RELIEF_SUNKEN_RULE;
+ else if ((strncmp(name, RELIEF_SUNKEN_RULE_SPEC, length) == 0) && (length >= 7)) {
+ *relief = ZN_RELIEF_SUNKEN_RULE;
}
- else if ((strncasecmp(name, RELIEF_RAISED_RULE_SPEC, length) == 0) && (length >= 7)) {
- *relief = RELIEF_RAISED_RULE;
+ else if ((strncmp(name, RELIEF_RAISED_RULE_SPEC, length) == 0) && (length >= 7)) {
+ *relief = ZN_RELIEF_RAISED_RULE;
}
else {
- Tcl_AppendResult(wi->interp, "bad relief type \"", name, "\": must be ",
+ Tcl_AppendResult(wi->interp, "bad relief \"", name, "\": must be ",
RELIEF_FLAT_SPEC, ", ",
RELIEF_RAISED_SPEC, ", ",
RELIEF_SUNKEN_SPEC, ", ",
@@ -198,40 +115,40 @@ ZnGetRelief(WidgetInfo *wi,
RELIEF_SUNKEN_RULE_SPEC, ", ",
RELIEF_RAISED_RULE_SPEC,
NULL);
- return ZN_ERROR;
+ return TCL_ERROR;
}
if (!wi->render) {
- *relief = *relief & ~(RELIEF_ROUND|RELIEF_RULE);
+ *relief = *relief & ~(ZN_RELIEF_ROUND|ZN_RELIEF_RULE);
}
- return ZN_OK;
+ return TCL_OK;
}
char *
-ZnNameOfRelief(ReliefStyle relief)
+ZnNameOfRelief(ZnReliefStyle relief)
{
switch (relief) {
- case RELIEF_FLAT:
+ case ZN_RELIEF_FLAT:
return RELIEF_FLAT_SPEC;
- case RELIEF_SUNKEN:
+ case ZN_RELIEF_SUNKEN:
return RELIEF_SUNKEN_SPEC;
- case RELIEF_RAISED:
+ case ZN_RELIEF_RAISED:
return RELIEF_RAISED_SPEC;
- case RELIEF_GROOVE:
+ case ZN_RELIEF_GROOVE:
return RELIEF_GROOVE_SPEC;
- case RELIEF_RIDGE:
+ case ZN_RELIEF_RIDGE:
return RELIEF_RIDGE_SPEC;
- case RELIEF_ROUND_SUNKEN:
+ case ZN_RELIEF_ROUND_SUNKEN:
return RELIEF_ROUND_SUNKEN_SPEC;
- case RELIEF_ROUND_RAISED:
+ case ZN_RELIEF_ROUND_RAISED:
return RELIEF_ROUND_RAISED_SPEC;
- case RELIEF_ROUND_GROOVE:
+ case ZN_RELIEF_ROUND_GROOVE:
return RELIEF_ROUND_GROOVE_SPEC;
- case RELIEF_ROUND_RIDGE:
+ case ZN_RELIEF_ROUND_RIDGE:
return RELIEF_ROUND_RIDGE_SPEC;
- case RELIEF_SUNKEN_RULE:
+ case ZN_RELIEF_SUNKEN_RULE:
return RELIEF_SUNKEN_RULE_SPEC;
- case RELIEF_RAISED_RULE:
+ case ZN_RELIEF_RAISED_RULE:
return RELIEF_RAISED_RULE_SPEC;
default:
return "unknown relief";
@@ -239,6 +156,437 @@ ZnNameOfRelief(ReliefStyle relief)
}
/*
+ ****************************************************************
+ *
+ * Code for borders.
+ *
+ ****************************************************************
+ */
+#define BORDER_LEFT_SPEC "left"
+#define BORDER_RIGHT_SPEC "right"
+#define BORDER_TOP_SPEC "top"
+#define BORDER_BOTTOM_SPEC "bottom"
+#define BORDER_CONTOUR_SPEC "contour"
+#define BORDER_COUNTER_OBLIQUE_SPEC "counteroblique"
+#define BORDER_OBLIQUE_SPEC "oblique"
+#define NO_BORDER_SPEC "noborder"
+
+int
+ZnGetBorder(ZnWInfo *wi,
+ Tcl_Obj *name,
+ ZnBorder *border)
+{
+ unsigned int j, len, largc;
+ Tcl_Obj **largv;
+ char *str;
+
+ *border = ZN_NO_BORDER;
+ if (Tcl_ListObjGetElements(wi->interp, name,
+ &largc, &largv) == TCL_ERROR) {
+ border_error:
+ Tcl_AppendResult(wi->interp, "bad line shape \"", Tcl_GetString(name),
+ "\": must be a list of ",
+ BORDER_LEFT_SPEC, ", ",
+ BORDER_RIGHT_SPEC, ", ",
+ BORDER_TOP_SPEC, ", ",
+ BORDER_BOTTOM_SPEC, ", ",
+ BORDER_COUNTER_OBLIQUE_SPEC, ", ",
+ BORDER_OBLIQUE_SPEC, " or ",
+ BORDER_CONTOUR_SPEC, ", ",
+ NO_BORDER_SPEC, " alone",
+ NULL);
+ return TCL_ERROR;
+ }
+ for (j = 0; j < largc; j++) {
+ str = Tcl_GetString(largv[j]);
+ len = strlen(str);
+ if (strncmp(str, BORDER_LEFT_SPEC, len) == 0) {
+ *border |= ZN_LEFT_BORDER;
+ }
+ else if (strncmp(str, BORDER_RIGHT_SPEC, len) == 0) {
+ *border |= ZN_RIGHT_BORDER;
+ }
+ else if (strncmp(str, BORDER_TOP_SPEC, len) == 0) {
+ *border |= ZN_TOP_BORDER;
+ }
+ else if (strncmp(str, BORDER_BOTTOM_SPEC, len) == 0) {
+ *border |= ZN_BOTTOM_BORDER;
+ }
+ else if (strncmp(str, BORDER_CONTOUR_SPEC, len) == 0) {
+ *border |= ZN_CONTOUR_BORDER;
+ }
+ else if (strncmp(str, BORDER_OBLIQUE_SPEC, len) == 0) {
+ *border |= ZN_OBLIQUE;
+ }
+ else if (strncmp(str, BORDER_COUNTER_OBLIQUE_SPEC, len) == 0) {
+ *border |= ZN_COUNTER_OBLIQUE;
+ }
+ else if (strncmp(str, NO_BORDER_SPEC, len) == 0) {
+ *border = ZN_NO_BORDER;
+ }
+ else {
+ goto border_error;
+ }
+ }
+ return TCL_OK;
+}
+
+/*
+ * name must be large enough to hold the returned string.
+ * 64 chars should be enough with the current values.
+ */
+void
+ZnNameOfBorder(ZnBorder border,
+ char *name)
+{
+ if (border == ZN_NO_BORDER) {
+ strcpy(name, NO_BORDER_SPEC);
+ return;
+ }
+ name[0] = 0;
+ if ((border & ZN_CONTOUR_BORDER) == ZN_CONTOUR_BORDER) {
+ strcat(name, BORDER_CONTOUR_SPEC);
+ }
+ else {
+ if (border & ZN_LEFT_BORDER) {
+ strcat(name, BORDER_LEFT_SPEC);
+ }
+ if (border & ZN_RIGHT_BORDER) {
+ if (name[0] != 0) {
+ strcat(name, " ");
+ }
+ strcat(name, BORDER_RIGHT_SPEC);
+ }
+ if (border & ZN_TOP_BORDER) {
+ if (name[0] != 0) {
+ strcat(name, " ");
+ }
+ strcat(name, BORDER_TOP_SPEC);
+ }
+ if (border & ZN_BOTTOM_BORDER) {
+ if (name[0] != 0) {
+ strcat(name, " ");
+ }
+ strcat(name, BORDER_BOTTOM_SPEC);
+ }
+ }
+ if (border & ZN_OBLIQUE) {
+ if (name[0] != 0) {
+ strcat(name, " ");
+ }
+ strcat(name, BORDER_OBLIQUE_SPEC);
+ }
+ if (border & ZN_COUNTER_OBLIQUE) {
+ if (name[0] != 0) {
+ strcat(name, " ");
+ }
+ strcat(name, BORDER_COUNTER_OBLIQUE_SPEC);
+ }
+}
+
+/*
+ ****************************************************************
+ *
+ * Code for line shapes.
+ *
+ ****************************************************************
+ */
+#define STRAIGHT_SPEC "straight"
+#define RIGHT_LIGHTNING_SPEC "rightlightning"
+#define LEFT_LIGHTNING_SPEC "leftlightning"
+#define RIGHT_CORNER_SPEC "rightcorner"
+#define LEFT_CORNER_SPEC "leftcorner"
+#define DOUBLE_RIGHT_CORNER_SPEC "doublerightcorner"
+#define DOUBLE_LEFT_CORNER_SPEC "doubleleftcorner"
+
+int
+ZnGetLineShape(ZnWInfo *wi,
+ char *name,
+ ZnLineShape *line_shape)
+{
+ unsigned int len;
+
+ len = strlen(name);
+ if (strncmp(name, STRAIGHT_SPEC, len) == 0) {
+ *line_shape = ZN_LINE_STRAIGHT;
+ }
+ else if (strncmp(name, RIGHT_LIGHTNING_SPEC, len) == 0) {
+ *line_shape = ZN_LINE_RIGHT_LIGHTNING;
+ }
+ else if (strncmp(name, LEFT_LIGHTNING_SPEC, len) == 0) {
+ *line_shape = ZN_LINE_LEFT_LIGHTNING;
+ }
+ else if (strncmp(name, RIGHT_CORNER_SPEC, len) == 0) {
+ *line_shape = ZN_LINE_RIGHT_CORNER;
+ }
+ else if (strncmp(name, LEFT_CORNER_SPEC, len) == 0) {
+ *line_shape = ZN_LINE_LEFT_CORNER;
+ }
+ else if (strncmp(name, DOUBLE_RIGHT_CORNER_SPEC, len) == 0) {
+ *line_shape = ZN_LINE_DOUBLE_RIGHT_CORNER;
+ }
+ else if (strncmp(name, DOUBLE_LEFT_CORNER_SPEC, len) == 0) {
+ *line_shape = ZN_LINE_DOUBLE_LEFT_CORNER;
+ }
+ else {
+ Tcl_AppendResult(wi->interp, "bad line shape \"", name, "\": must be ",
+ STRAIGHT_SPEC, ", ",
+ RIGHT_LIGHTNING_SPEC, ", ",
+ LEFT_LIGHTNING_SPEC, ", ",
+ RIGHT_CORNER_SPEC, ", ",
+ LEFT_CORNER_SPEC, ", ",
+ DOUBLE_RIGHT_CORNER_SPEC, ", ",
+ DOUBLE_LEFT_CORNER_SPEC,
+ NULL);
+ return TCL_ERROR;
+ }
+ return TCL_OK;
+}
+
+char *
+ZnNameOfLineShape(ZnLineShape line_shape)
+{
+ switch (line_shape) {
+ case ZN_LINE_STRAIGHT:
+ return STRAIGHT_SPEC;
+ case ZN_LINE_RIGHT_LIGHTNING:
+ return RIGHT_LIGHTNING_SPEC;
+ case ZN_LINE_LEFT_LIGHTNING:
+ return LEFT_LIGHTNING_SPEC;
+ case ZN_LINE_RIGHT_CORNER:
+ return RIGHT_CORNER_SPEC;
+ case ZN_LINE_LEFT_CORNER:
+ return LEFT_CORNER_SPEC;
+ case ZN_LINE_DOUBLE_RIGHT_CORNER:
+ return DOUBLE_RIGHT_CORNER_SPEC;
+ case ZN_LINE_DOUBLE_LEFT_CORNER:
+ return DOUBLE_LEFT_CORNER_SPEC;
+ default:
+ return "unknown line shape";
+ }
+}
+
+/*
+ ****************************************************************
+ *
+ * Code for line styles.
+ *
+ ****************************************************************
+ */
+#define SIMPLE_SPEC "simple"
+#define DASHED_SPEC "dashed"
+#define DOTTED_SPEC "dotted"
+#define MIXED_SPEC "mixed"
+
+int
+ZnGetLineStyle(ZnWInfo *wi,
+ char *name,
+ ZnLineStyle *line_style)
+{
+ unsigned int len;
+
+ len = strlen(name);
+ if (strncmp(name, SIMPLE_SPEC, len) == 0)
+ *line_style = ZN_LINE_SIMPLE;
+ else if (strncmp(name, DASHED_SPEC, len) == 0)
+ *line_style = ZN_LINE_DASHED;
+ else if (strncmp(name, MIXED_SPEC, len) == 0)
+ *line_style = ZN_LINE_MIXED;
+ else if (strncmp(name, DOTTED_SPEC, len) == 0)
+ *line_style = ZN_LINE_DOTTED;
+ else {
+ Tcl_AppendResult(wi->interp, "bad line style \"", name, "\": must be ",
+ SIMPLE_SPEC, ", ",
+ DASHED_SPEC, ", ",
+ DOTTED_SPEC, ", ",
+ MIXED_SPEC,
+ NULL);
+ return TCL_ERROR;
+ }
+ return TCL_OK;
+}
+
+char *
+ZnNameOfLineStyle(ZnLineStyle line_style)
+{
+ switch (line_style) {
+ case ZN_LINE_SIMPLE:
+ return SIMPLE_SPEC;
+ case ZN_LINE_DASHED:
+ return DASHED_SPEC;
+ case ZN_LINE_MIXED:
+ return MIXED_SPEC;
+ case ZN_LINE_DOTTED:
+ return DOTTED_SPEC;
+ default:
+ return "unknown line style";
+ }
+}
+
+/*
+ ****************************************************************
+ *
+ * Code for leader anchors.
+ *
+ * Format is: lChar leftLeaderAnchor [ lChar rightLeaderAnchor]
+ *
+ * If lChar is a '|', leftLeaderAnchor and rightLeaderAnchor are the indices
+ * of the fields that serve to anchor the label's leader. More specifically
+ * the bottom left corner of the left field and the bottom right corner of
+ * the right field are used as the anchors.
+ * If lChar is '%', leftLeaderAnchor and rightLeaderAnchor should be
+ * specified as 'valxval', 'val' being a percentage (max 100) of the
+ * width/height of the label bounding box.
+ * If rightLeaderAnchor is not specified it defaults to leftLeaderAnchor.
+ * If neither of them are specified, the center of the label is used as an
+ * anchor.
+ *
+ ****************************************************************
+ */
+int
+ZnGetLeaderAnchors(ZnWInfo *wi,
+ char *name,
+ ZnLeaderAnchors *leader_anchors)
+{
+ int anchors[4];
+ int index, num_tok, anchor_index=0;
+
+ *leader_anchors = NULL;
+ while (*name && (*name == ' ')) {
+ name++;
+ }
+ while (*name && (anchor_index < 4)) {
+ switch (*name) {
+ case '|':
+ num_tok = sscanf(name, "|%d%n", &anchors[anchor_index], &index);
+ if (num_tok != 1) {
+ la_error:
+ Tcl_AppendResult(wi->interp, " incorrect leader anchors \"",
+ name, "\"", NULL);
+ return TCL_ERROR;
+ }
+ anchors[anchor_index+1] = -1;
+ break;
+ case '%':
+ num_tok = sscanf(name, "%%%dx%d%n", &anchors[anchor_index],
+ &anchors[anchor_index+1], &index);
+ if (num_tok != 2) {
+ goto la_error;
+ }
+ if (anchors[anchor_index] < 0) {
+ anchors[anchor_index] = 0;
+ }
+ if (anchors[anchor_index] > 100) {
+ anchors[anchor_index] = 100;
+ }
+ if (anchors[anchor_index+1] < 0) {
+ anchors[anchor_index+1] = 0;
+ }
+ if (anchors[anchor_index+1] > 100) {
+ anchors[anchor_index+1] = 100;
+ }
+ break;
+ }
+ anchor_index += 2;
+ name += index;
+ }
+ /*
+ * If empty, pick the default (center of the bounding box).
+ */
+ if (anchor_index != 0) {
+ *leader_anchors = ZnMalloc(sizeof(ZnLeaderAnchorsStruct));
+ (*leader_anchors)->left_x = anchors[0];
+ (*leader_anchors)->left_y = anchors[1];
+ if (anchor_index == 2) {
+ (*leader_anchors)->right_x = (*leader_anchors)->left_x;
+ (*leader_anchors)->right_y = (*leader_anchors)->left_y;
+ }
+ else {
+ (*leader_anchors)->right_x = anchors[2];
+ (*leader_anchors)->right_y = anchors[3];
+ }
+ }
+ return TCL_OK;
+}
+
+/*
+ * name must be large enough to hold the returned string.
+ */
+void
+ZnNameOfLeaderAnchors(ZnLeaderAnchors leader_anchors,
+ char *name)
+{
+ unsigned int count;
+
+ if (!leader_anchors) {
+ strcpy(name, "%50x50");
+ }
+ else {
+ if (leader_anchors->left_y < 0) {
+ count = sprintf(name, "|%d", leader_anchors->left_x);
+ }
+ else {
+ count = sprintf(name, "%%%dx%d", leader_anchors->left_x,
+ leader_anchors->left_y);
+ }
+ name += count;
+ if (leader_anchors->right_y < 0) {
+ sprintf(name, "|%d", leader_anchors->right_x);
+ }
+ else {
+ sprintf(name, "%%%dx%d", leader_anchors->right_x, leader_anchors->right_y);
+ }
+ }
+}
+
+/*
+ ******************************************************************
+ *
+ * Code for label formats.
+ *
+ ******************************************************************
+ */
+static Tcl_HashTable format_cache;
+static ZnBool format_inited = False;
+
+
+static char
+CharToAttach(int attach)
+{
+ switch (attach) {
+ case '>':
+ return ZN_LF_ATTACH_FWD;
+ case '<':
+ return ZN_LF_ATTACH_BWD;
+ case '^':
+ return ZN_LF_ATTACH_LEFT;
+ case '$':
+ return ZN_LF_ATTACH_RIGHT;
+ case '+':
+ default:
+ return ZN_LF_ATTACH_PIXEL;
+ }
+}
+
+static char
+CharToDim(int dim)
+{
+ switch (dim) {
+ case 'f':
+ return ZN_LF_DIM_FONT;
+ case 'i':
+ return ZN_LF_DIM_ICON;
+ case 'a':
+ return ZN_LF_DIM_AUTO;
+ case 'l':
+ return ZN_LF_DIM_LABEL;
+ case 'x':
+ default:
+ return ZN_LF_DIM_PIXEL;
+ }
+}
+
+/*
* The new format is as follow. Parameters between [] are
* optional and take default values when omitted. The spaces can appear
* between blocks but not inside.
@@ -272,9 +620,9 @@ ZnNameOfRelief(ReliefStyle relief)
*
*/
ZnLabelFormat
-LabelFormatCreate(Tcl_Interp *interp,
- char *format_str,
- int num_fields)
+ZnLFCreate(Tcl_Interp *interp,
+ char *format_str,
+ unsigned int num_fields)
{
ZnList fields;
Tcl_HashEntry *entry;
@@ -284,7 +632,7 @@ LabelFormatCreate(Tcl_Interp *interp,
int width, height;
ZnDim c_width=0.0, c_height=0.0;
int index, num_tok, num_ffs, new;
- int field_index=0;
+ unsigned int field_index=0;
char *ptr = format_str, *next_ptr;
char x_char, y_char;
@@ -338,8 +686,8 @@ LabelFormatCreate(Tcl_Interp *interp,
}
if (!*ptr) {
/* It is a simple spec, one field. */
- field_struct.x_attach = field_struct.y_attach = LF_ATTACH_PIXEL;
- field_struct.x_dim = field_struct.y_dim = LF_DIM_PIXEL;
+ field_struct.x_attach = field_struct.y_attach = ZN_LF_ATTACH_PIXEL;
+ field_struct.x_dim = field_struct.y_dim = ZN_LF_DIM_PIXEL;
field_struct.x_spec = field_struct.y_spec = 0;
field_struct.width_spec = (short) c_width;
field_struct.height_spec = (short) c_height;
@@ -360,8 +708,8 @@ LabelFormatCreate(Tcl_Interp *interp,
}
/* Preset the default field values. */
field_struct.x_spec = field_struct.y_spec = 0;
- field_struct.x_attach = field_struct.y_attach = LF_ATTACH_PIXEL;
- field_struct.x_dim = field_struct.y_dim = LF_DIM_PIXEL;
+ field_struct.x_attach = field_struct.y_attach = ZN_LF_ATTACH_PIXEL;
+ field_struct.x_dim = field_struct.y_dim = ZN_LF_DIM_PIXEL;
if ((*ptr == 'x') || (*ptr == 'f') || (*ptr == 'i') ||
(*ptr == 'a') || (*ptr == 'l')) {
num_tok = sscanf(ptr, "%c%d%c%d%n", &x_char, &width,
@@ -433,7 +781,7 @@ LabelFormatCreate(Tcl_Interp *interp,
ZnLabelFormat
-LabelFormatDuplicate(ZnLabelFormat lf)
+ZnLFDuplicate(ZnLabelFormat lf)
{
lf->ref_count++;
return lf;
@@ -441,7 +789,7 @@ LabelFormatDuplicate(ZnLabelFormat lf)
void
-LabelFormatDelete(ZnLabelFormat lf)
+ZnLFDelete(ZnLabelFormat lf)
{
lf->ref_count--;
if (lf->ref_count == 0) {
@@ -452,7 +800,7 @@ LabelFormatDelete(ZnLabelFormat lf)
char *
-LabelFormatGetString(ZnLabelFormat lf)
+ZnLFGetString(ZnLabelFormat lf)
{
return Tcl_GetHashKey(&format_cache, lf->entry);
@@ -460,7 +808,7 @@ LabelFormatGetString(ZnLabelFormat lf)
ZnFieldFormat ff;
char *ptr;
char x_char, y_char, w_char, h_char;
- int i, count;
+ unsigned int i, count;
ptr = str;
if ((lf->clip_width != 0) || (lf->clip_height != 0)) {
@@ -502,9 +850,9 @@ LabelFormatGetString(ZnLabelFormat lf)
* set to zero, it means that there is no clipbox.
*/
ZnBool
-LabelFormatGetClipBox(ZnLabelFormat lf,
- ZnDim *w,
- ZnDim *h)
+ZnLFGetClipBox(ZnLabelFormat lf,
+ ZnDim *w,
+ ZnDim *h)
{
if ((lf->clip_width == 0) && (lf->clip_height == 0)) {
return False;
@@ -518,16 +866,16 @@ LabelFormatGetClipBox(ZnLabelFormat lf,
void
-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)
+ZnLFGetField(ZnLabelFormat lf,
+ unsigned 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)
{
ZnFieldFormat fptr;
@@ -555,8 +903,8 @@ static ZnBool line_end_inited = False;
ZnLineEnd
-LineEndCreate(Tcl_Interp *interp,
- char *line_end_str)
+ZnLineEndCreate(Tcl_Interp *interp,
+ char *line_end_str)
{
Tcl_HashEntry *entry;
ZnLineEnd le;
@@ -595,14 +943,14 @@ LineEndCreate(Tcl_Interp *interp,
char *
-LineEndGetString(ZnLineEnd le)
+ZnLineEndGetString(ZnLineEnd le)
{
return Tcl_GetHashKey(&line_end_cache, le->entry);
}
void
-LineEndDelete(ZnLineEnd le)
+ZnLineEndDelete(ZnLineEnd le)
{
le->ref_count--;
if (le->ref_count == 0) {
@@ -613,8 +961,157 @@ LineEndDelete(ZnLineEnd le)
ZnLineEnd
-LineEndDuplicate(ZnLineEnd le)
+ZnLineEndDuplicate(ZnLineEnd le)
{
le->ref_count++;
return le;
}
+
+
+/*
+ ******************************************************************
+ *
+ * Code for fill rules. They are directly inhereted from the
+ * GLU tesselator constants.
+ *
+ ******************************************************************
+ */
+#define FILL_RULE_ODD_SPEC "odd"
+#define FILL_RULE_NON_ZERO_SPEC "nonzero"
+#define FILL_RULE_POSITIVE_SPEC "positive"
+#define FILL_RULE_NEGATIVE_SPEC "negative"
+#define FILL_RULE_ABS_GEQ_2_SPEC "abs_geq_2"
+
+int
+ZnGetFillRule(ZnWInfo *wi,
+ char *name,
+ ZnFillRule *fill_rule)
+{
+ unsigned int len;
+
+ len = strlen(name);
+ if (strncmp(name, FILL_RULE_ODD_SPEC, len) == 0) {
+ *fill_rule = GLU_TESS_WINDING_ODD;
+ }
+ else if (strncmp(name, FILL_RULE_NON_ZERO_SPEC, len) == 0) {
+ *fill_rule = GLU_TESS_WINDING_NONZERO;
+ }
+ else if (strncmp(name, FILL_RULE_POSITIVE_SPEC, len) == 0) {
+ *fill_rule = GLU_TESS_WINDING_POSITIVE;
+ }
+ else if (strncmp(name, FILL_RULE_NEGATIVE_SPEC, len) == 0) {
+ *fill_rule = GLU_TESS_WINDING_NEGATIVE;
+ }
+ else if (strncmp(name, FILL_RULE_ABS_GEQ_2_SPEC, len) == 0) {
+ *fill_rule = GLU_TESS_WINDING_ABS_GEQ_TWO;
+ }
+ else {
+ Tcl_AppendResult(wi->interp, "bad fill rule \"", name, "\": must be ",
+ FILL_RULE_ODD_SPEC, ", ",
+ FILL_RULE_NON_ZERO_SPEC, ", ",
+ FILL_RULE_POSITIVE_SPEC, ", ",
+ FILL_RULE_NEGATIVE_SPEC, ", ",
+ FILL_RULE_ABS_GEQ_2_SPEC,
+ NULL);
+ return TCL_ERROR;
+ }
+ return TCL_OK;
+}
+
+char *
+ZnNameOfFillRule(ZnFillRule fill_rule)
+{
+ switch (fill_rule) {
+ case GLU_TESS_WINDING_ODD:
+ return FILL_RULE_ODD_SPEC;
+ case GLU_TESS_WINDING_NONZERO:
+ return FILL_RULE_NON_ZERO_SPEC;
+ case GLU_TESS_WINDING_POSITIVE:
+ return FILL_RULE_POSITIVE_SPEC;
+ case GLU_TESS_WINDING_NEGATIVE:
+ return FILL_RULE_NEGATIVE_SPEC;
+ case GLU_TESS_WINDING_ABS_GEQ_TWO:
+ return FILL_RULE_ABS_GEQ_2_SPEC;
+ default:
+ return "unknown fill rule";
+ }
+}
+
+
+/*
+ ******************************************************************
+ *
+ * Code for auto alignments in fields.
+ *
+ ******************************************************************
+ */
+int
+ZnGetAutoAlign(ZnWInfo *wi,
+ char *name,
+ ZnAutoAlign *aa)
+{
+ int j;
+
+ if (strcmp(name, "-") == 0) {
+ aa->automatic = False;
+ }
+ else if (strlen(name) == 3) {
+ aa->automatic = True;
+ for (j = 0; j < 3; j++) {
+ switch(name[j]) {
+ case 'l':
+ case 'L':
+ aa->align[j] = TK_JUSTIFY_LEFT;
+ break;
+ case 'c':
+ case 'C':
+ aa->align[j] = TK_JUSTIFY_CENTER;
+ break;
+ case 'r':
+ case 'R':
+ aa->align[j] = TK_JUSTIFY_RIGHT;
+ break;
+ default:
+ goto aa_error;
+ }
+ }
+ }
+ else {
+ aa_error:
+ Tcl_AppendResult(wi->interp, "invalid auto alignment specification \"", name,
+ "\" should be - or a triple of lcr", NULL);
+ return TCL_ERROR;
+ }
+ return TCL_OK;
+}
+
+/*
+ * name must be large enough to hold the returned string.
+ * 64 chars should be enough with the current values.
+ */
+void
+ZnNameOfAutoAlign(ZnAutoAlign *aa,
+ char *name)
+{
+ unsigned int i;
+
+ if (aa->automatic == False) {
+ strcpy(name, "-");
+ }
+ else {
+ name[0] = 0;
+ for (i = 0; i < 3; i++) {
+ switch (aa->align[i]) {
+ case TK_JUSTIFY_LEFT:
+ strcat(name, "l");
+ break;
+ case TK_JUSTIFY_CENTER:
+ strcat(name, "c");
+ break;
+ case TK_JUSTIFY_RIGHT:
+ strcat(name, "r");
+ break;
+ }
+ }
+ }
+}