+Sun Jun 12 23:44:38 2005 Ben Pfaff <blp@gnu.org>
+
+ Implement embedding for PostScript driver. Fixes bug 12970.
+
+ * ascii.c: Fix compiler warnings.
+
+ * html.c: Ditto.
+
+ * chart.h: Add `file' member.
+
+ * output.h: (struct outp_class) initialise_chart, finalise_chart
+ should take outp_driver *, not outp_class *. Update all
+ references.
+
+ * plot-chart.c: (chart_create) Fix segfault when there are no
+ output drivers at all.
+ (chart_submit) Call d->class->finalise_chart.
+
+ * postscript.c: (ps_open_page) Set cp_y to 0.
+ (ps_submit) New function.
+ (ps_chart_initialise) Implement.
+ (ps_chart_finalise) Implement.
+ (static var postscript_class) Add ps_submit.
+ (static var epsf_class) Add ps_submit.
+
+
Sun Jun 12 14:54:40 2005 Ben Pfaff <blp@gnu.org>
Did some more work on bug 12859 and then realized that a *good*
-void ascii_chart_initialise(struct outp_class *c UNUSED,
- struct chart *ch UNUSED);
-
-void ascii_chart_finalise(struct outp_class *c UNUSED,
- struct chart *ch UNUSED);
-
-
-void
-ascii_chart_initialise(struct outp_class *c UNUSED, struct chart *ch )
+static void
+ascii_chart_initialise(struct outp_driver *d UNUSED, struct chart *ch )
{
msg(MW, _("Charts are unsupported with ascii drivers."));
ch->lp = 0;
}
-void
-ascii_chart_finalise(struct outp_class *c UNUSED, struct chart *ch UNUSED)
+static void
+ascii_chart_finalise(struct outp_driver *d UNUSED, struct chart *ch UNUSED)
{
}
void *lp;
#endif
char *filename;
+ FILE *file;
/* The geometry of the chart
See diagram at the foot of this file.
fputs ("</TABLE>\n\n", x->file.file);
}
-
-void html_initialise_chart(struct outp_class *c, struct chart *ch);
-void html_finalise_chart(struct outp_class *c, struct chart *ch);
-
-
-void
-html_initialise_chart(struct outp_class *c UNUSED, struct chart *ch)
+static void
+html_initialise_chart(struct outp_driver *d UNUSED, struct chart *ch)
{
FILE *fp;
}
-void
-html_finalise_chart(struct outp_class *c UNUSED, struct chart *ch)
+static void
+html_finalise_chart(struct outp_driver *d UNUSED, struct chart *ch)
{
free(ch->filename);
}
void (*text_metrics) (struct outp_driver *, struct outp_text *);
void (*text_draw) (struct outp_driver *, struct outp_text *);
- void (*initialise_chart)(struct outp_class *, struct chart *);
- void (*finialise_chart)(struct outp_class *, struct chart *);
+ void (*initialise_chart)(struct outp_driver *, struct chart *);
+ void (*finalise_chart)(struct outp_driver *, struct chart *);
};
chart_create(void)
{
struct chart *chart;
-
struct outp_driver *d;
+ d = outp_drivers (NULL);
+ if (d == NULL)
+ return NULL;
+
chart = xmalloc(sizeof(struct chart) );
-
- for (d = outp_drivers (NULL); d; d = outp_drivers (d))
+ d->class->initialise_chart(d, chart);
+ if (!chart->lp)
{
- assert(d->class->initialise_chart);
- d->class->initialise_chart(d, chart);
- break; /* KLUDGE!! */
+ free (chart);
+ return NULL;
}
- if ( ! chart->lp )
- return 0;
-
if (pl_openpl_r (chart->lp) < 0) /* open Plotter */
- return 0;
-
+ return NULL;
+
pl_fspace_r (chart->lp, 0.0, 0.0, 1000.0, 1000.0); /* set coordinate system */
pl_flinewidth_r (chart->lp, 0.25); /* set line thickness */
pl_pencolorname_r (chart->lp, "black");
pl_erase_r (chart->lp); /* erase graphics display */
pl_filltype_r(chart->lp,0);
-
-
pl_savestate_r(chart->lp);
/* Set default chartetry */
chart->font_size = 0;
strcpy(chart->fill_colour,"red");
-
/* Get default font size */
if ( !chart->font_size)
chart->font_size = pl_fontsize_r(chart->lp, -1);
chart->data_right, chart->data_top);
return chart;
-
}
-
-
/* Draw a tick mark at position
If label is non zero, then print it at the tick mark
*/
chart_submit(struct chart *chart)
{
struct som_entity s;
+ struct outp_driver *d;
if ( ! chart )
return ;
pl_deleteplparams(chart->pl_params);
+ d = outp_drivers (NULL);
+ d->class->finalise_chart(d, chart);
free(chart);
-
}
#include "misc.h"
#include "misc.h"
#include "output.h"
+#include "som.h"
#include "version.h"
/* FIXMEs:
draw_headers (this);
}
+ this->cp_y = 0;
+
return !ferror (x->file.file);
}
this->page_open = 0;
return !ferror (x->file.file);
}
+
+static void
+ps_submit (struct outp_driver *this UNUSED, struct som_entity *s)
+{
+ switch (s->type)
+ {
+ case SOM_CHART:
+ break;
+ default:
+ assert(0);
+ break;
+ }
+}
\f
/* Lines. */
return fe;
}
-
-void ps_chart_initialise(struct outp_class *c UNUSED,
- struct chart *ch UNUSED);
-
-void ps_chart_finalise(struct outp_class *c UNUSED,
- struct chart *ch UNUSED);
-
-
-void
-ps_chart_initialise(struct outp_class *c UNUSED, struct chart *ch )
+static void
+ps_chart_initialise (struct outp_driver *this UNUSED, struct chart *ch)
{
- msg(MW, _("Charts are currently unsupported with postscript drivers."));
- ch->lp = 0;
-}
+#ifdef NO_CHARTS
+ ch->lp = NULL;
+#else
+ struct ps_driver_ext *x = this->ext;
+ char page_size[128];
+ int size;
+ int x_origin, y_origin;
-void
-ps_chart_finalise(struct outp_class *c UNUSED, struct chart *ch UNUSED)
-{
+ ch->file = tmpfile ();
+ if (ch->file == NULL)
+ {
+ ch->lp = NULL;
+ return;
+ }
+ size = this->width < this->length ? this->width : this->length;
+ x_origin = x->left_margin + (size - this->width) / 2;
+ y_origin = x->bottom_margin + (size - this->length) / 2;
+
+ snprintf (page_size, sizeof page_size,
+ "a,xsize=%.3f,ysize=%.3f,xorigin=%.3f,yorigin=%.3f",
+ (double) size / PSUS, (double) size / PSUS,
+ (double) x_origin / PSUS, (double) y_origin / PSUS);
+
+ ch->pl_params = pl_newplparams ();
+ pl_setplparam (ch->pl_params, "PAGESIZE", page_size);
+ ch->lp = pl_newpl_r ("ps", NULL, ch->file, stderr, ch->pl_params);
+#endif
}
+static void
+ps_chart_finalise (struct outp_driver *this UNUSED, struct chart *ch UNUSED)
+{
+#ifndef NO_CHARTS
+ struct ps_driver_ext *x = this->ext;
+ char buf[BUFSIZ];
+ static int doc_num = 0;
+
+ if (this->page_open)
+ {
+ this->class->close_page (this);
+ this->page_open = 0;
+ }
+ this->class->open_page (this);
+ fprintf (x->file.file,
+ "/sp save def%s"
+ "%d %d translate 1000 dup scale%s"
+ "userdict begin%s"
+ "/showpage { } def%s"
+ "0 setgray 0 setlinecap 1 setlinewidth%s"
+ "0 setlinejoin 10 setmiterlimit [ ] 0 setdash newpath clear%s"
+ "%%%%BeginDocument: %d%s",
+ x->eol,
+ -x->left_margin, -x->bottom_margin, x->eol,
+ x->eol,
+ x->eol,
+ x->eol,
+ x->eol,
+ doc_num++, x->eol);
+
+ rewind (ch->file);
+ while (fwrite (buf, 1, fread (buf, 1, sizeof buf, ch->file), x->file.file))
+ continue;
+ fclose (ch->file);
+
+ fprintf (x->file.file,
+ "%%%%EndDocument%s"
+ "end%s"
+ "sp restore%s",
+ x->eol,
+ x->eol,
+ x->eol);
+ this->class->close_page (this);
+ this->page_open = 0;
+#endif
+}
/* PostScript driver class. */
struct outp_class postscript_class =
ps_open_page,
ps_close_page,
- NULL,
+ ps_submit,
ps_line_horz,
ps_line_vert,
ps_open_page,
ps_close_page,
- NULL,
+ ps_submit,
ps_line_horz,
ps_line_vert,