From: Ben Pfaff Date: Mon, 13 Jun 2005 06:51:13 +0000 (+0000) Subject: Implement embedding for PostScript driver. Fixes bug 12970. X-Git-Tag: v0.4.0~57 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=33a381c1da6c8a92ad8e1809e64a4953e9586b26;p=pspp-builds.git Implement embedding for PostScript driver. Fixes bug 12970. --- diff --git a/src/ChangeLog b/src/ChangeLog index 45b4ce33..2e2267fb 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,29 @@ +Sun Jun 12 23:44:38 2005 Ben Pfaff + + 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 Did some more work on bug 12859 and then realized that a *good* diff --git a/src/ascii.c b/src/ascii.c index dc783bfa..b91b6a6b 100644 --- a/src/ascii.c +++ b/src/ascii.c @@ -1633,22 +1633,15 @@ ascii_close_page (struct outp_driver *this) -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) { } diff --git a/src/chart.h b/src/chart.h index 795462a7..c0ab0a20 100644 --- a/src/chart.h +++ b/src/chart.h @@ -44,6 +44,7 @@ struct chart { void *lp; #endif char *filename; + FILE *file; /* The geometry of the chart See diagram at the foot of this file. diff --git a/src/html.c b/src/html.c index 73a1123e..fbb6b968 100644 --- a/src/html.c +++ b/src/html.c @@ -582,13 +582,8 @@ output_tab_table (struct outp_driver *this, struct tab_table *t) fputs ("\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; @@ -604,8 +599,8 @@ html_initialise_chart(struct outp_class *c UNUSED, struct chart *ch) } -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); } diff --git a/src/output.h b/src/output.h index baa9d473..3b5eeeba 100644 --- a/src/output.h +++ b/src/output.h @@ -170,8 +170,8 @@ struct outp_class 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 *); }; diff --git a/src/plot-chart.c b/src/plot-chart.c index c38a5622..a866f4f3 100644 --- a/src/plot-chart.c +++ b/src/plot-chart.c @@ -52,24 +52,23 @@ 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"); @@ -77,8 +76,6 @@ chart_create(void) pl_erase_r (chart->lp); /* erase graphics display */ pl_filltype_r(chart->lp,0); - - pl_savestate_r(chart->lp); /* Set default chartetry */ @@ -94,7 +91,6 @@ chart_create(void) 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); @@ -105,11 +101,8 @@ chart_create(void) 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 */ @@ -188,6 +181,7 @@ void chart_submit(struct chart *chart) { struct som_entity s; + struct outp_driver *d; if ( ! chart ) return ; @@ -208,8 +202,9 @@ chart_submit(struct chart *chart) pl_deleteplparams(chart->pl_params); + d = outp_drivers (NULL); + d->class->finalise_chart(d, chart); free(chart); - } diff --git a/src/postscript.c b/src/postscript.c index 2caf2a65..c828a0df 100644 --- a/src/postscript.c +++ b/src/postscript.c @@ -54,6 +54,7 @@ #include "misc.h" #include "misc.h" #include "output.h" +#include "som.h" #include "version.h" /* FIXMEs: @@ -1693,6 +1694,8 @@ ps_open_page (struct outp_driver *this) draw_headers (this); } + this->cp_y = 0; + return !ferror (x->file.file); } @@ -1714,6 +1717,19 @@ ps_close_page (struct outp_driver *this) 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; + } +} /* Lines. */ @@ -2871,27 +2887,85 @@ load_font (struct outp_driver *this, const char *dit) 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 = @@ -2912,7 +2986,7 @@ struct outp_class postscript_class = ps_open_page, ps_close_page, - NULL, + ps_submit, ps_line_horz, ps_line_vert, @@ -2956,7 +3030,7 @@ struct outp_class epsf_class = ps_open_page, ps_close_page, - NULL, + ps_submit, ps_line_horz, ps_line_vert,