2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2013,2014, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
45 #include "gmx_fatal.h"
48 #include "gromacs/fileio/futil.h"
49 #include "gromacs/fileio/gmxfio.h"
51 const char *fontnm[efontNR] = {
52 "Times-Roman", "Times-Italic", "Times-Bold", "Times-BoldItalic",
53 "Helvetica", "Helvetica-Oblique", "Helvetica-Bold", "Helvetica-BoldOblique",
54 "Courier", "Courier-Oblique", "Courier-Bold", "Courier-BoldOblique"
58 /* Internal psdata structure (abstract datatype)
59 * to maintain the current state of the ps engine.
71 t_psdata ps_open(const char *fn, real x1, real y1, real x2, real y2)
77 ps->fp = gmx_fio_fopen(fn, "w");
78 fprintf(ps->fp, "%%!PS-Adobe-2.0 EPSF-1.2\n");
79 fprintf(ps->fp, "%%%%Creator: GROMACS\n");
80 fprintf(ps->fp, "%%%%Title: %s\n", fn);
81 fprintf(ps->fp, "%%%%BoundingBox: %g %g %g %g\n", x1, y1, x2, y2);
82 fprintf(ps->fp, "%%%%EndComments\n");
83 fprintf(ps->fp, "/m {moveto} bind def\n");
84 fprintf(ps->fp, "/l {lineto} bind def\n");
85 fprintf(ps->fp, "/rm {rmoveto} bind def\n");
86 fprintf(ps->fp, "/r {rlineto} bind def\n");
87 fprintf(ps->fp, "/f {fill} bind def\n");
88 fprintf(ps->fp, "/s {stroke} bind def\n");
99 void ps_linewidth(t_psdata ps, int lw)
101 fprintf(ps->fp, "%d setlinewidth\n", lw);
104 static void ps_defcolor(t_psdata ps, real r, real g, real b, char *cname)
106 fprintf(ps->fp, "/%s {%g %g %g setrgbcolor} bind def\n", cname, r, g, b);
109 static void ps_selcolor(t_psdata ps, char *cname)
111 fprintf(ps->fp, "%s\n", cname);
114 static int search_col(t_psdata ps, real r, real g, real b)
119 for (i = 0; (i < ps->nrgb); i++)
121 if ((ps->rgb[i].r == r) && (ps->rgb[i].g == g) && (ps->rgb[i].b == b))
127 if (ps->nrgb >= ps->maxrgb)
130 srenew(ps->rgb, ps->maxrgb);
133 sprintf(buf, "C%d", ps->nrgb);
134 ps_defcolor(ps, r, g, b, buf);
135 fprintf(ps->fp, "/B%d {%s b} bind def\n", ps->nrgb, buf);
144 void ps_color(t_psdata ps, real r, real g, real b)
149 i = search_col(ps, r, g, b);
151 sprintf(buf, "C%d", i);
152 ps_selcolor(ps, buf);
155 void ps_rgb(t_psdata ps, t_rgb *rgb)
157 ps_color(ps, rgb->r, rgb->g, rgb->b);
161 void ps_init_rgb_nbox(t_psdata ps, real xbox, real ybox)
164 fprintf(ps->fp, "/by {def currentpoint "
165 "%g y r %g %g r %g y neg r %g %g r f y add moveto} bind def\n",
166 0.0, xbox, 0.0, 0.0, -xbox, 0.0);
167 /* macro bn is used in ps_rgb_nbox to draw rectangular boxes */
170 void ps_rgb_nbox(t_psdata ps, t_rgb *rgb, real n)
177 fprintf(ps->fp, "/y %g by\n", n*ps->gen_ybox);
178 /* macro by is defined in ps_init_rgb_nbox */
182 for (i = 0; (i < n); i++)
190 void ps_init_rgb_box(t_psdata ps, real xbox, real ybox)
192 fprintf(ps->fp, "/b {currentpoint "
193 "%g %g r %g %g r %g %g r %g %g r f %g add moveto} bind def\n",
194 0.0, ybox, xbox, 0.0, 0.0, -ybox, -xbox, 0.0, ybox);
195 /* macro b is used in search_col to define macro B */
198 void ps_rgb_box(t_psdata ps, t_rgb *rgb)
200 fprintf(ps->fp, "B%d\n", search_col(ps, rgb->r, rgb->g, rgb->b));
201 /* macro B is defined in search_col from macro b */
204 void ps_lineto(t_psdata ps, real x, real y)
206 fprintf(ps->fp, "%g %g l\n", x, y);
209 void ps_linerel(t_psdata ps, real dx, real dy)
211 fprintf(ps->fp, "%g %g r\n", dx, dy);
214 void ps_moveto(t_psdata ps, real x, real y)
216 fprintf(ps->fp, "%g %g m\n", x, y);
219 void ps_moverel(t_psdata ps, real dx, real dy)
221 fprintf(ps->fp, "%g %g rm\n", dx, dy);
224 void ps_line(t_psdata ps, real x1, real y1, real x2, real y2)
226 ps_moveto(ps, x1, y1);
227 ps_lineto(ps, x2, y2);
228 fprintf(ps->fp, "s\n");
231 static void do_box(t_psdata ps, real x1, real y1, real x2, real y2)
233 ps_moveto(ps, x1, y1);
234 ps_linerel(ps, 0, (real)(y2-y1));
235 ps_linerel(ps, (real)(x2-x1), 0);
236 ps_linerel(ps, 0, (real)(y1-y2));
237 ps_linerel(ps, (real)(x1-x2), 0);
240 void ps_box(t_psdata ps, real x1, real y1, real x2, real y2)
242 do_box(ps, x1, y1, x2, y2);
243 fprintf(ps->fp, "s\n");
246 void ps_fillbox(t_psdata ps, real x1, real y1, real x2, real y2)
248 do_box(ps, x1, y1, x2, y2);
249 fprintf(ps->fp, "f\n");
252 void ps_arc(t_psdata ps, real x1, real y1, real rad, real a0, real a1)
254 fprintf(ps->fp, "%g %g %g %g %g arc s\n", x1, y1, rad, a0, a1);
257 void ps_fillarc(t_psdata ps, real x1, real y1, real rad, real a0, real a1)
259 fprintf(ps->fp, "%g %g %g %g %g arc f\n", x1, y1, rad, a0, a1);
262 void ps_arcslice(t_psdata ps, real xc, real yc,
263 real rad1, real rad2, real a0, real a1)
265 fprintf(ps->fp, "newpath %g %g %g %g %g arc %g %g %g %g %g arcn closepath s\n",
266 xc, yc, rad1, a0, a1, xc, yc, rad2, a1, a0);
269 void ps_fillarcslice(t_psdata ps, real xc, real yc,
270 real rad1, real rad2, real a0, real a1)
272 fprintf(ps->fp, "newpath %g %g %g %g %g arc %g %g %g %g %g arcn closepath f\n",
273 xc, yc, rad1, a0, a1, xc, yc, rad2, a1, a0);
276 void ps_circle(t_psdata ps, real x1, real y1, real rad)
278 ps_arc(ps, x1, y1, rad, 0, 360);
281 void ps_font(t_psdata ps, int font, real size)
284 if ((font < 0) || (font > efontNR))
286 fprintf(stderr, "Invalid Font: %d, using %s\n", font, fontnm[0]);
289 fprintf(ps->fp, "/%s findfont\n", fontnm[font]);
290 fprintf(ps->fp, "%g scalefont setfont\n", size);
293 void ps_strfont(t_psdata ps, char *font, real size)
295 fprintf(ps->fp, "/%s findfont\n", font);
296 fprintf(ps->fp, "%g scalefont setfont\n", size);
299 void ps_text(t_psdata ps, real x1, real y1, const char *str)
301 ps_moveto(ps, x1, y1);
302 fprintf(ps->fp, "(%s) show\n", str);
305 void ps_flip(t_psdata ps, gmx_bool bPlus)
309 fprintf(ps->fp, "612.5 0 translate 90 rotate\n");
313 fprintf(ps->fp, "-90 rotate -612.5 0 translate\n");
317 void ps_rotate(t_psdata ps, real angle)
319 fprintf(ps->fp, "%f rotate\n", angle);
322 void ps_ctext(t_psdata ps, real x1, real y1, const char *str, int expos)
326 ps_text(ps, x1, y1, str);
329 ps_moveto(ps, x1, y1);
330 fprintf(ps->fp, "(%s) stringwidth\n", str);
334 fprintf(ps->fp, "exch 0 exch pop exch\n");
337 fprintf(ps->fp, "exch 2 div neg exch\n");
340 fprintf(ps->fp, "exch neg exch\n");
343 gmx_fatal(FARGS, "invalid position index (expos=%d)", expos);
345 fprintf(ps->fp, "rmoveto (%s) show\n", str);
348 void ps_translate(t_psdata ps, real x, real y)
350 fprintf(ps->fp, "%g %g translate\n", x, y);
353 void ps_setorigin(t_psdata ps)
355 fprintf(ps->fp, "currentpoint dup 3 -1 roll dup 4 1 roll exch translate\n");
359 void ps_unsetorigin(t_psdata ps)
363 gmx_fatal(FARGS, "No origin on stack!\n");
365 fprintf(ps->fp, "neg exch neg exch translate\n");
369 void ps_close(t_psdata ps)
371 fprintf(ps->fp, "%%showpage\n");
372 fprintf(ps->fp, "%%%%EOF\n");
373 gmx_fio_fclose(ps->fp);
378 void ps_comment(t_psdata ps, const char *s)
380 fprintf(ps->fp, "%%%% %s\n", s);