aboutsummaryrefslogtreecommitdiff
path: root/generic/Field.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/Field.c')
-rw-r--r--generic/Field.c235
1 files changed, 234 insertions, 1 deletions
diff --git a/generic/Field.c b/generic/Field.c
index ace5407..9f36e88 100644
--- a/generic/Field.c
+++ b/generic/Field.c
@@ -2132,14 +2132,246 @@ RenderField(ZnWInfo *wi,
}
#endif
+#ifdef GL
static void
RenderFields(ZnFieldSet field_set)
{
-#ifdef GL
/* glDisable(GL_LINE_SMOOTH);*/
FieldsEngine(field_set, RenderField);
/* glEnable(GL_LINE_SMOOTH);*/
+}
+#else
+static void
+RenderFields(ZnFieldSet field_set)
+{
+}
#endif
+
+
+/*
+ **********************************************************************************
+ *
+ * PostScriptFields --
+ *
+ **********************************************************************************
+ */
+static int
+PsField(ZnWInfo *wi,
+ ZnBool prepass,
+ Field fptr,
+ ZnBBox *bbox,
+ ZnBBox *pm_bbox,
+ ZnPoint *text_pos,
+ ZnBBox *text_bbox)
+{
+ int j;
+ char path[250];
+
+ /*
+ * Must set the clip rect for the whole field, not only for stipple fill.
+ */
+ if (ISSET(fptr->flags, FILLED_BIT)) {
+ if (fptr->tile != ZnUnspecifiedImage) {
+ if (!ZnImageIsBitmap(fptr->tile)) { /* Fill tiled */
+ /* TODO No support yet */
+ }
+ else { /* Fill stippled */
+ Tcl_AppendResult(wi->interp, "gsave\n", NULL);
+ if (Tk_PostscriptColor(wi->interp, wi->ps_info,
+ ZnGetGradientColor(fptr->fill_color, 0.0, NULL)) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ if (Tk_PostscriptStipple(wi->interp, wi->win, wi->ps_info,
+ ZnImagePixmap(fptr->tile, wi->win)) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ Tcl_AppendResult(wi->interp, "grestore\n", NULL);
+ }
+ }
+ else { /* Fill solid */
+ if (Tk_PostscriptColor(wi->interp, wi->ps_info,
+ ZnGetGradientColor(fptr->fill_color, 0.0, NULL)) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ Tcl_AppendResult(wi->interp, "fill\n", NULL);
+ }
+ }
+
+ /*
+ * Draw the image and the text, which is in back depends on
+ * the value of text_on_top.
+ */
+ for (j = 0; j < 2; j++) {
+ if ((j == 0 && ISSET(fptr->flags, TEXT_ON_TOP_BIT)) ||
+ (j == 1 && ISCLEAR(fptr->flags, TEXT_ON_TOP_BIT))) {
+ /*
+ * Draw the image.
+ */
+ if (fptr->image != ZnUnspecifiedImage) {
+ int w, h;
+
+ Tcl_AppendResult(wi->interp, "gsave\n", NULL);
+ sprintf(path, "%.15g %.15g translate 1 -1 scale\n",
+ pm_bbox->orig.x, pm_bbox->corner.y);
+ Tcl_AppendResult(wi->interp, path, NULL);
+ w = ZnNearestInt(pm_bbox->corner.x - pm_bbox->orig.x);
+ h = ZnNearestInt(pm_bbox->corner.y - pm_bbox->orig.y);
+ if (Tk_PostscriptImage(ZnImageTkImage(fptr->image), wi->interp, wi->win,
+ wi->ps_info, 0, 0, w, h, prepass) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ Tcl_AppendResult(wi->interp, "grestore\n", NULL);
+ }
+ }
+ else if (fptr->text) {
+ Tcl_AppendResult(wi->interp, "gsave\n", NULL);
+ if (Tk_PostscriptFont(wi->interp, wi->ps_info, fptr->font) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ if (Tk_PostscriptColor(wi->interp, wi->ps_info,
+ ZnGetGradientColor(fptr->color, 0.0, NULL)) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ /*
+ * TODO pourquoi la text_bbox ne donne pas un texte centré verticalement ?
+ * Apparement la fonte PostScript n'est pas centrée comme la fonte X.
+ * Il faut donc opérer le calcul dans le code PostScript de DrawText.
+ */
+ sprintf(path, "%.15g %.15g translate 1 -1 scale 0 0 [\n",
+ text_bbox->orig.x, text_bbox->orig.y);
+ Tcl_AppendResult(wi->interp, path, NULL);
+ /*
+ * strlen should do the work of counting _bytes_ in the utf8 string.
+ */
+ ZnPostscriptString(wi->interp, fptr->text, strlen(fptr->text));
+ Tcl_AppendResult(wi->interp, "] 0 0.0 0.0 0.0 false DrawText\n", NULL);
+ Tcl_AppendResult(wi->interp, "grestore\n", NULL);
+ }
+ }
+
+ /*
+ * Draw the border relief.
+ */
+ if ((fptr->relief != ZN_RELIEF_FLAT) && (fptr->relief_thickness > 1)) {
+ }
+
+ /*
+ * Draw the border line.
+ */
+ if (fptr->border_edges != ZN_NO_BORDER) {
+ if (Tk_PostscriptColor(wi->interp, wi->ps_info,
+ ZnGetGradientColor(fptr->border_color, 0.0, NULL)) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ Tcl_AppendResult(wi->interp, "1 setlinewidth 0 setlinejoin 2 setlinecap\n", NULL);
+ if (fptr->border_edges & ZN_LEFT_BORDER) {
+ sprintf(path, "%.15g %.15g moveto %.15g %.15g lineto stroke\n",
+ bbox->orig.x, bbox->orig.y, bbox->orig.x, bbox->corner.y);
+ Tcl_AppendResult(wi->interp, path, NULL);
+ }
+ if (fptr->border_edges & ZN_RIGHT_BORDER) {
+ sprintf(path, "%.15g %.15g moveto %.15g %.15g lineto stroke\n",
+ bbox->corner.x, bbox->orig.y, bbox->corner.x, bbox->corner.y);
+ Tcl_AppendResult(wi->interp, path, NULL);
+ }
+ if (fptr->border_edges & ZN_TOP_BORDER) {
+ sprintf(path, "%.15g %.15g moveto %.15g %.15g lineto stroke\n",
+ bbox->orig.x, bbox->orig.y, bbox->corner.x, bbox->orig.y);
+ Tcl_AppendResult(wi->interp, path, NULL);
+ }
+ if (fptr->border_edges & ZN_BOTTOM_BORDER) {
+ sprintf(path, "%.15g %.15g moveto %.15g %.15g lineto stroke\n",
+ bbox->orig.x, bbox->corner.y, bbox->corner.x, bbox->corner.y);
+ Tcl_AppendResult(wi->interp, path, NULL);
+ }
+ if (fptr->border_edges & ZN_OBLIQUE) {
+ sprintf(path, "%.15g %.15g moveto %.15g %.15g lineto stroke\n",
+ bbox->orig.x, bbox->orig.y, bbox->corner.x, bbox->corner.y);
+ Tcl_AppendResult(wi->interp, path, NULL);
+ }
+ if (fptr->border_edges & ZN_COUNTER_OBLIQUE) {
+ sprintf(path, "%.15g %.15g moveto %.15g %.15g lineto stroke\n",
+ bbox->corner.x, bbox->orig.y, bbox->orig.x, bbox->corner.y);
+ Tcl_AppendResult(wi->interp, path, NULL);
+ }
+ }
+
+ return TCL_OK;
+}
+
+static int
+PostScriptFields(ZnFieldSet field_set,
+ ZnBool prepass,
+ ZnBBox *area)
+{
+ ZnWInfo *wi = field_set->item->wi;
+ ZnBBox lclip_bbox, fclip_bbox;
+ ZnBBox bbox, text_bbox, pm_bbox;
+ ZnPoint text_pos;
+ int i, num_fields;
+ ZnDim lwidth, lheight;
+ Field fptr;
+ char path[250];
+
+ if (!field_set->num_fields) {
+ return TCL_OK;
+ }
+
+
+ if (field_set->label_format && ZnLFNumFields(field_set->label_format)) {
+ /*
+ * Fields are drawn with respect to a point already converted
+ * to device space, so we need to reinstate the initial transform.
+ */
+ Tcl_AppendResult(wi->interp, "/InitialTransform load setmatrix\n", NULL);
+
+ lclip_bbox.orig.x = ZnNearestInt(field_set->label_pos.x);
+ lclip_bbox.orig.y = ZnNearestInt(field_set->label_pos.y);
+ GetLabelBBox(field_set, &lwidth, &lheight);
+ lclip_bbox.corner.x = lclip_bbox.orig.x + lwidth;
+ lclip_bbox.corner.y = lclip_bbox.orig.y + lheight;
+
+ num_fields = ZnLFNumFields(field_set->label_format);
+ for (i = 0; i < num_fields; i++) {
+ fptr = &field_set->fields[i];
+
+ if (ISCLEAR(fptr->flags, FIELD_VISIBLE_BIT)) {
+ continue;
+ }
+
+ GetFieldBBox(field_set, i, &bbox);
+ ZnIntersectBBox(&lclip_bbox, &bbox, &fclip_bbox);
+ if (ZnIsEmptyBBox(&fclip_bbox)) {
+ /* The field is outside the label bbox */
+ continue;
+ }
+
+ /*
+ * Setup a clip area around the field
+ */
+ Tcl_AppendResult(wi->interp, "gsave\n", NULL);
+ sprintf(path, "%.15g %.15g moveto %.15g %.15g lineto %.15g %.15g lineto %.15g %.15g",
+ fclip_bbox.orig.x, fclip_bbox.orig.y, fclip_bbox.corner.x+1, fclip_bbox.orig.y,
+ fclip_bbox.corner.x+1, fclip_bbox.corner.y+1, fclip_bbox.orig.x,
+ fclip_bbox.corner.y+1);
+ Tcl_AppendResult(wi->interp, path, " lineto closepath clip\n", NULL);
+
+ if (fptr->text) {
+ ComputeFieldTextLocation(fptr, &bbox, &text_pos, &text_bbox);
+ }
+ if (fptr->image != ZnUnspecifiedImage) {
+ ComputeFieldImageLocation(fptr, &bbox, &pm_bbox);
+ }
+
+ if (PsField(wi, prepass, fptr, &bbox, &pm_bbox, &text_pos, &text_bbox) != TCL_OK) {
+ return TCL_ERROR;
+ }
+
+ Tcl_AppendResult(wi->interp, "grestore\n", NULL);
+ }
+ }
+
+ return TCL_OK;
}
@@ -2325,6 +2557,7 @@ struct _ZnFIELD ZnFIELD = {
QueryField,
DrawFields,
RenderFields,
+ PostScriptFields,
FieldsToArea,
IsFieldSensitive,
FieldsPick,