3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
33 * GROningen Mixture of Alchemy and Childrens' Stories
40 #include "gromacs/fileio/futil.h"
41 #include "gmx_fatal.h"
44 #include "gromacs/fileio/gmxfio.h"
46 const char *fontnm[efontNR] = {
47 "Times-Roman", "Times-Italic", "Times-Bold", "Times-BoldItalic",
48 "Helvetica", "Helvetica-Oblique", "Helvetica-Bold", "Helvetica-BoldOblique",
49 "Courier", "Courier-Oblique", "Courier-Bold", "Courier-BoldOblique"
53 /* Internal psdata structure (abstract datatype)
54 * to maintain the current state of the ps engine.
66 t_psdata ps_open(const char *fn, real x1, real y1, real x2, real y2)
72 ps->fp = gmx_fio_fopen(fn, "w");
73 fprintf(ps->fp, "%%!PS-Adobe-2.0 EPSF-1.2\n");
74 fprintf(ps->fp, "%%%%Creator: GROMACS\n");
75 fprintf(ps->fp, "%%%%Title: %s\n", fn);
76 fprintf(ps->fp, "%%%%BoundingBox: %g %g %g %g\n", x1, y1, x2, y2);
77 fprintf(ps->fp, "%%%%EndComments\n");
78 fprintf(ps->fp, "/m {moveto} bind def\n");
79 fprintf(ps->fp, "/l {lineto} bind def\n");
80 fprintf(ps->fp, "/rm {rmoveto} bind def\n");
81 fprintf(ps->fp, "/r {rlineto} bind def\n");
82 fprintf(ps->fp, "/f {fill} bind def\n");
83 fprintf(ps->fp, "/s {stroke} bind def\n");
94 void ps_linewidth(t_psdata ps, int lw)
96 fprintf(ps->fp, "%d setlinewidth\n", lw);
99 static void ps_defcolor(t_psdata ps, real r, real g, real b, char *cname)
101 fprintf(ps->fp, "/%s {%g %g %g setrgbcolor} bind def\n", cname, r, g, b);
104 static void ps_selcolor(t_psdata ps, char *cname)
106 fprintf(ps->fp, "%s\n", cname);
109 static int search_col(t_psdata ps, real r, real g, real b)
114 for (i = 0; (i < ps->nrgb); i++)
116 if ((ps->rgb[i].r == r) && (ps->rgb[i].g == g) && (ps->rgb[i].b == b))
122 if (ps->nrgb >= ps->maxrgb)
125 srenew(ps->rgb, ps->maxrgb);
128 sprintf(buf, "C%d", ps->nrgb);
129 ps_defcolor(ps, r, g, b, buf);
130 fprintf(ps->fp, "/B%d {%s b} bind def\n", ps->nrgb, buf);
139 void ps_color(t_psdata ps, real r, real g, real b)
144 i = search_col(ps, r, g, b);
146 sprintf(buf, "C%d", i);
147 ps_selcolor(ps, buf);
150 void ps_rgb(t_psdata ps, t_rgb *rgb)
152 ps_color(ps, rgb->r, rgb->g, rgb->b);
156 void ps_init_rgb_nbox(t_psdata ps, real xbox, real ybox)
159 fprintf(ps->fp, "/by {def currentpoint "
160 "%g y r %g %g r %g y neg r %g %g r f y add moveto} bind def\n",
161 0.0, xbox, 0.0, 0.0, -xbox, 0.0);
162 /* macro bn is used in ps_rgb_nbox to draw rectangular boxes */
165 void ps_rgb_nbox(t_psdata ps, t_rgb *rgb, real n)
172 fprintf(ps->fp, "/y %g by\n", n*ps->gen_ybox);
173 /* macro by is defined in ps_init_rgb_nbox */
177 for (i = 0; (i < n); i++)
185 void ps_init_rgb_box(t_psdata ps, real xbox, real ybox)
187 fprintf(ps->fp, "/b {currentpoint "
188 "%g %g r %g %g r %g %g r %g %g r f %g add moveto} bind def\n",
189 0.0, ybox, xbox, 0.0, 0.0, -ybox, -xbox, 0.0, ybox);
190 /* macro b is used in search_col to define macro B */
193 void ps_rgb_box(t_psdata ps, t_rgb *rgb)
195 fprintf(ps->fp, "B%d\n", search_col(ps, rgb->r, rgb->g, rgb->b));
196 /* macro B is defined in search_col from macro b */
199 void ps_lineto(t_psdata ps, real x, real y)
201 fprintf(ps->fp, "%g %g l\n", x, y);
204 void ps_linerel(t_psdata ps, real dx, real dy)
206 fprintf(ps->fp, "%g %g r\n", dx, dy);
209 void ps_moveto(t_psdata ps, real x, real y)
211 fprintf(ps->fp, "%g %g m\n", x, y);
214 void ps_moverel(t_psdata ps, real dx, real dy)
216 fprintf(ps->fp, "%g %g rm\n", dx, dy);
219 void ps_line(t_psdata ps, real x1, real y1, real x2, real y2)
221 ps_moveto(ps, x1, y1);
222 ps_lineto(ps, x2, y2);
223 fprintf(ps->fp, "s\n");
226 static void do_box(t_psdata ps, real x1, real y1, real x2, real y2)
228 ps_moveto(ps, x1, y1);
229 ps_linerel(ps, 0, (real)(y2-y1));
230 ps_linerel(ps, (real)(x2-x1), 0);
231 ps_linerel(ps, 0, (real)(y1-y2));
232 ps_linerel(ps, (real)(x1-x2), 0);
235 void ps_box(t_psdata ps, real x1, real y1, real x2, real y2)
237 do_box(ps, x1, y1, x2, y2);
238 fprintf(ps->fp, "s\n");
241 void ps_fillbox(t_psdata ps, real x1, real y1, real x2, real y2)
243 do_box(ps, x1, y1, x2, y2);
244 fprintf(ps->fp, "f\n");
247 void ps_arc(t_psdata ps, real x1, real y1, real rad, real a0, real a1)
249 fprintf(ps->fp, "%g %g %g %g %g arc s\n", x1, y1, rad, a0, a1);
252 void ps_fillarc(t_psdata ps, real x1, real y1, real rad, real a0, real a1)
254 fprintf(ps->fp, "%g %g %g %g %g arc f\n", x1, y1, rad, a0, a1);
257 void ps_arcslice(t_psdata ps, real xc, real yc,
258 real rad1, real rad2, real a0, real a1)
260 fprintf(ps->fp, "newpath %g %g %g %g %g arc %g %g %g %g %g arcn closepath s\n",
261 xc, yc, rad1, a0, a1, xc, yc, rad2, a1, a0);
264 void ps_fillarcslice(t_psdata ps, real xc, real yc,
265 real rad1, real rad2, real a0, real a1)
267 fprintf(ps->fp, "newpath %g %g %g %g %g arc %g %g %g %g %g arcn closepath f\n",
268 xc, yc, rad1, a0, a1, xc, yc, rad2, a1, a0);
271 void ps_circle(t_psdata ps, real x1, real y1, real rad)
273 ps_arc(ps, x1, y1, rad, 0, 360);
276 void ps_font(t_psdata ps, int font, real size)
279 if ((font < 0) || (font > efontNR))
281 fprintf(stderr, "Invalid Font: %d, using %s\n", font, fontnm[0]);
284 fprintf(ps->fp, "/%s findfont\n", fontnm[font]);
285 fprintf(ps->fp, "%g scalefont setfont\n", size);
288 void ps_strfont(t_psdata ps, char *font, real size)
290 fprintf(ps->fp, "/%s findfont\n", font);
291 fprintf(ps->fp, "%g scalefont setfont\n", size);
294 void ps_text(t_psdata ps, real x1, real y1, const char *str)
296 ps_moveto(ps, x1, y1);
297 fprintf(ps->fp, "(%s) show\n", str);
300 void ps_flip(t_psdata ps, gmx_bool bPlus)
304 fprintf(ps->fp, "612.5 0 translate 90 rotate\n");
308 fprintf(ps->fp, "-90 rotate -612.5 0 translate\n");
312 void ps_rotate(t_psdata ps, real angle)
314 fprintf(ps->fp, "%f rotate\n", angle);
317 void ps_ctext(t_psdata ps, real x1, real y1, const char *str, int expos)
321 ps_text(ps, x1, y1, str);
324 ps_moveto(ps, x1, y1);
325 fprintf(ps->fp, "(%s) stringwidth\n", str);
329 fprintf(ps->fp, "exch 0 exch pop exch\n");
332 fprintf(ps->fp, "exch 2 div neg exch\n");
335 fprintf(ps->fp, "exch neg exch\n");
338 gmx_fatal(FARGS, "invalid position index (expos=%d)", expos);
340 fprintf(ps->fp, "rmoveto (%s) show\n", str);
343 void ps_translate(t_psdata ps, real x, real y)
345 fprintf(ps->fp, "%g %g translate\n", x, y);
348 void ps_setorigin(t_psdata ps)
350 fprintf(ps->fp, "currentpoint dup 3 -1 roll dup 4 1 roll exch translate\n");
354 void ps_unsetorigin(t_psdata ps)
358 gmx_fatal(FARGS, "No origin on stack!\n");
360 fprintf(ps->fp, "neg exch neg exch translate\n");
364 void ps_close(t_psdata ps)
366 fprintf(ps->fp, "%%showpage\n");
367 fprintf(ps->fp, "%%%%EOF\n");
368 gmx_fio_fclose(ps->fp);
373 void ps_comment(t_psdata ps, const char *s)
375 fprintf(ps->fp, "%%%% %s\n", s);