1 /*
2 * Fig2dev: Translate Fig code to various Devices
3 * Copyright (c) 1991 by Micah Beck
4 * Parts Copyright (c) 1985-1988 by Supoj Sutanthavibul
5 * Parts Copyright (c) 1989-2015 by Brian V. Smith
6 * Parts Copyright (c) 2015-2019 by Thomas Loimer
7 *
8 * Any party obtaining a copy of these files is granted, free of charge, a
9 * full and unrestricted irrevocable, world-wide, paid up, royalty-free,
10 * nonexclusive right and license to deal in this software and documentation
11 * files (the "Software"), including without limitation the rights to use,
12 * copy, modify, merge, publish, distribute, sublicense and/or sell copies
13 * of the Software, and to permit persons who receive copies from any such
14 * party to do so, with the only requirement being that the above copyright
15 * and this permission notice remain intact.
16 *
17 */
18
19 /*
20 * genpstex.c: convert fig to psTeX and psTeX_t
21 *
22 * Author: Jose Alberto Fernandez R /Maryland CP 9/90
23 *
24 *
25 * It uses the LaTeX and PostScript drivers to generate
26 * LaTeX processed text for a Postscript figure.
27 *
28 * The pstex_t driver is like a latex driver that only translates
29 * text defined in the default font.
30 *
31 * The pstex driver is like a PostScript driver that translates
32 * everything except for text in the default font.
33 *
34 * The pdftex_t and pdftex are drivers for combined PDF/LaTeX.
35 *
36 * The option '-p file' added to the pstex_t translator specifies
37 * the name of the PostScript file to be called in the psfig macro.
38 * If not set or its value is null then no PS file will be inserted.
39 *
40 * Jose Alberto.
41 */
42
43 #ifdef HAVE_CONFIG_H
44 #include "config.h"
45 #endif
46
47 #include <stdio.h>
48 #include <string.h>
49
50 #include "fig2dev.h"
51 #include "object.h"
52
53 extern double rad2deg;
54
55 extern void
56 genlatex_start(F_compound *objects),
57 geneps_option(char opt, char *optarg),
58 genps_start(F_compound *objects),
59 genps_arc(F_arc *a),
60 genps_ellipse(F_ellipse *e),
61 genps_line(F_line *l),
62 genps_spline(F_spline *s),
63 genlatex_option(char opt, char *optarg),
64 genlatex_text(F_text *t),
65 genps_text(F_text *t);
66 extern int
67 genlatex_end(void),
68 genps_end(void);
69
70 extern void genpdf_option(char opt, char *optarg); /* genpdf.c */
71 extern void genpdf_start(F_compound *objects); /* genpdf.c */
72 extern int genpdf_end(void); /* genpdf.c */
73 extern void genps_grid(float major, float minor);
74
75 static char pstex_file[1000] = "";
76
77 void
genpstex_t_option(char opt,char * optarg)78 genpstex_t_option(char opt, char *optarg)
79 {
80 if (opt == 'p')
81 strcpy(pstex_file, optarg);
82 else
83 genlatex_option(opt, optarg);
84 }
85
86
87 void
genpstex_t_start(F_compound * objects)88 genpstex_t_start(F_compound *objects)
89 {
90 /* Put PostScript Image if any*/
91 if (pstex_file[0] != '\0') {
92 fprintf(tfp, "\\begin{picture}(0,0)%%\n");
93 /* newer includegraphics directive suggested by Stephen Harker 1/13/99 */
94 #ifdef LATEX2E_GRAPHICS
95 fprintf(tfp, "\\includegraphics{%s}%%\n",pstex_file);
96 #else
97 fprintf(tfp, "\\special{psfile=%s}%%\n",pstex_file);
98 #endif
99 fprintf(tfp, "\\end{picture}%%\n");
100 }
101 genlatex_start(objects);
102
103 }
104
105 void
genpstex_t_text(F_text * t)106 genpstex_t_text(F_text *t)
107 {
108 if (special_text(t))
109 genlatex_text(t);
110 }
111
112 void
genpstex_text(F_text * t)113 genpstex_text(F_text *t)
114 {
115 if (!special_text(t))
116 genps_text(t);
117 }
118
119 void
genpstex_option(char opt,char * optarg)120 genpstex_option(char opt, char *optarg)
121 {
122 if (opt != 'p')
123 genlatex_option(opt, optarg);
124 }
125
126 struct driver dev_pstex_t = {
127 genpstex_t_option,
128 genpstex_t_start,
129 gendev_nogrid,
130 (void (*)(F_arc *))gendev_null,
131 (void (*)(F_ellipse *))gendev_null,
132 (void (*)(F_line *))gendev_null,
133 (void (*)(F_spline *))gendev_null,
134 genpstex_t_text,
135 genlatex_end,
136 INCLUDE_TEXT
137 };
138
139 struct driver dev_pdftex_t = {
140 genpstex_t_option,
141 genpstex_t_start,
142 gendev_nogrid,
143 (void (*)(F_arc *))gendev_null,
144 (void (*)(F_ellipse *))gendev_null,
145 (void (*)(F_line *))gendev_null,
146 (void (*)(F_spline *))gendev_null,
147 genpstex_t_text,
148 genlatex_end,
149 INCLUDE_TEXT
150 };
151
152 struct driver dev_pstex = {
153 geneps_option, /* use eps so always exported in Portrait mode */
154 genps_start,
155 genps_grid,
156 genps_arc,
157 genps_ellipse,
158 genps_line,
159 genps_spline,
160 genpstex_text,
161 genps_end,
162 INCLUDE_TEXT
163 };
164
165 struct driver dev_pdftex = {
166 genpdf_option,
167 genpdf_start,
168 genps_grid,
169 genps_arc,
170 genps_ellipse,
171 genps_line,
172 genps_spline,
173 genpstex_text,
174 genpdf_end,
175 INCLUDE_TEXT
176 };
177