2
* TransFig: Facility for Translating Fig code
3
* Copyright (c) 1991 by Micah Beck
4
* Parts Copyright (c) 1985-1988 by Supoj Sutanthavibul
5
* Parts Copyright (c) 1989-2002 by Brian V. Smith
7
* Any party obtaining a copy of these files is granted, free of charge, a
8
* full and unrestricted irrevocable, world-wide, paid up, royalty-free,
9
* nonexclusive right and license to deal in this software and
10
* documentation files (the "Software"), including without limitation the
11
* rights to use, copy, modify, merge, publish and/or distribute copies of
12
* the Software, and to permit persons who receive copies from any such
13
* party to do so, with the only requirement being that this copyright
14
* notice remain intact.
19
* genpstex.c : psTeX and psTeX_t drivers for fig2dev
21
* Author: Jose Alberto Fernandez R /Maryland CP 9/90
22
* It uses the LaTeX and PostScript drivers to generate
23
* LaTeX processed text for a Postscript figure.
25
* The pstex_t driver is like a latex driver that only translates
26
* text defined in the default font.
28
* The pstex driver is like a PostScript driver that translates
29
* everything except for text in the default font.
31
* The pdftex_t and pdftex are drivers for combined PDF/LaTeX.
33
* The option '-p file' added to the pstex_t translator specifies
34
* the name of the PostScript file to be called in the psfig macro.
35
* If not set or its value is null then no PS file will be inserted.
46
extern double rad2deg;
49
#define rint(a) floor((a)+0.5) /* close enough? */
53
#define rint(a) floor((a)+0.5) /* close enough? */
72
static char pstex_file[1000] = "";
73
static int iObjectsRead = 0;
74
static int iTextRead = 0;
75
static int iObjectsFileNumber = 0;
76
static int iStartDepth;
77
static int iLastDepth;
78
static FILE * ptCreateFile;
79
static char szFileName[1000];
81
static int iPdfOutputs = 0;
84
static double unitlength;
85
static double dash_mag = 1.0;
87
static int (*translate_coordinates)() = NULL;
88
static int (*translate_coordinates_d)() = NULL;
90
extern double unitlength;
91
extern double dash_mag;
93
extern int (*translate_coordinates)();
94
extern int (*translate_coordinates_d)();
98
#define SWAP(x,y) {tmp=x; x=y; y=tmp;}
99
#define TRANS(x,y) (*translate_coordinates)(&x,&y)
100
#define TRANS2(x1,y1,x2,y2) (*translate_coordinates)(&x1,&y1); \
101
(*translate_coordinates)(&x2,&y2)
102
#define TRANSD(x,y) (*translate_coordinates_d)(&x,&y)
104
static void genpstex_p_finalize_objects(int depth);
106
/*************************************************************************
107
*************************************************************************/
113
*yp = (double)(TOP - *yp -1);
129
*yp = (double)TOP - *yp -1.0;
132
/*************************************************************************
133
*************************************************************************/
134
void genpstex_p_option(opt, optarg)
139
strcpy(pstex_file, optarg);
142
genlatex_option(opt, optarg);
146
/*************************************************************************
147
*************************************************************************/
148
void genpstex_p_start(objects)
155
if (*pstex_file == '\0')
157
put_msg("Argument -p is mandatory to pstex_p.");
161
strncpy(szFileName, pstex_file, 900);
162
iLength = strlen(szFileName);
164
sprintf(szFileName + iLength, ".create");
165
ptCreateFile = fopen (szFileName, "wb");
169
put_msg("Couldn't open %s for writing", szFileName);
172
fstat(fileno(ptCreateFile), & tStat);
173
fchmod (fileno(ptCreateFile), tStat.st_mode | ((tStat.st_mode & (S_IRUSR | S_IRGRP | S_IROTH)) >> 2));
174
fprintf(ptCreateFile, "#!/bin/bash\n\n", szFileName);
176
fprintf(ptCreateFile, "while getopts \"r\" Option\n");
177
fprintf(ptCreateFile, "do\n");
178
fprintf(ptCreateFile, " case $Option in\n");
179
fprintf(ptCreateFile, " r) iOptRemove=1;;\n");
180
fprintf(ptCreateFile, " *) echo \"illegal option -$Option\"\n");
181
fprintf(ptCreateFile, " esac\n");
182
fprintf(ptCreateFile, "done\n");
183
fprintf(ptCreateFile, "shift $(($OPTIND - 1))\n");
185
texfontsizes[0] = texfontsizes[1] =
186
TEXFONTSIZE(font_size != 0.0? font_size : DEFAULT_FONT_SIZE);
188
unitlength = mag/ppi;
189
dash_mag /= unitlength*80.0;
191
translate_coordinates = translate2;
192
translate_coordinates_d = translate2_d;
194
TRANS2(llx, lly, urx, ury);
195
if (llx > urx) SWAP(llx, urx)
196
if (lly > ury) SWAP(lly, ury)
200
/* print any whole-figure comments prefixed with "%" */
201
if (objects->comments) {
203
print_comments("% ",objects->comments, "");
207
lUnitLength = (long) (round(4736286.72*unitlength));
208
fprintf(tfp, "\\setlength{\\unitlength}{%lisp}%%\n",
210
/* define the SetFigFont macro */
211
define_setfigfont(tfp);
213
sprintf(szFileName + iLength, ".size");
214
fprintf(ptCreateFile, "if [ \"$iOptRemove\" == \"\" ]; then\n");
216
fprintf(ptCreateFile, " echo \"\\setlength\\pdfpagewidth{%3.2fpt}\\setlength\\pdfpageheight{%3.2fpt}\" > %s\n",
217
(float) lUnitLength / 65536 * (urx - llx), (float) lUnitLength / 65536 * (ury - lly), szFileName);
219
fprintf(ptCreateFile, "echo -n\"\" > %s\n", szFileName);
220
fprintf(ptCreateFile, "else\n rm -f %s\nfi\n", szFileName);
223
/*************************************************************************
224
*************************************************************************/
225
void genpdftex_p_start(objects)
229
genpstex_p_start(objects);
233
/*************************************************************************
234
*************************************************************************/
239
fprintf(tfp, "\\end{picture}%%\n");
244
genpstex_p_finalize_objects(iLastDepth);
249
fprintf(tfp, "\\begin{picture}(%d,%d)\n", urx-llx, ury-lly);
250
fprintf(tfp, "\\end{picture}%%\n");
252
fclose(ptCreateFile);
259
/*************************************************************************
260
*************************************************************************/
261
void genpstex_p_finalize_objects(depth)
264
char szFileName[1000];
267
strncpy(szFileName, pstex_file, 900);
268
iLength = strlen(szFileName);
271
sprintf(szFileName + iLength, "%03d", iObjectsFileNumber++);
272
fprintf(ptCreateFile, "if [ \"$iOptRemove\" == \"\" ]; then\n");
275
fprintf(ptCreateFile, " %s -L pstex -D +%d:%d %s", prog, depth, iStartDepth, from, szFileName);
276
fprintf(ptCreateFile, " | epstopdf -f > %s.pdf\n", szFileName, szFileName);
279
fprintf(ptCreateFile, "%s -L pstex -D +%d:%d %s %s.eps\n", prog, depth, iStartDepth, from, szFileName);
280
fprintf(ptCreateFile, "else\n rm -f %s.", szFileName);
282
fprintf(ptCreateFile, "pdf");
284
fprintf(ptCreateFile, "eps");
285
fprintf(ptCreateFile, "\nfi\n");
287
fprintf(tfp, "\\begin{picture}(0,0)%%\n");
288
/* newer includegraphics directive suggested by Stephen Harker 1/13/99 */
289
#if defined(LATEX2E_GRAPHICS)
291
fprintf(tfp, "\\epsfig{file=%s.eps}%%\n",szFileName);
293
fprintf(tfp, "\\includegraphics{%s}%%\n",szFileName);
296
fprintf(tfp, "\\special{psfile=%s.eps}%%\n",szFileName);
298
fprintf(tfp, "\\end{picture}%%\n");
301
/*************************************************************************
302
*************************************************************************/
303
void genpstex_p_object(depth)
308
fprintf(tfp, "\\end{picture}%%\n");
311
if (iObjectsRead == 0)
320
void genpstex_p_arc(obj)
323
genpstex_p_object(obj->depth);
327
void genpstex_p_ellipse(obj)
330
genpstex_p_object(obj->depth);
333
void genpstex_p_line(obj)
336
genpstex_p_object(obj->depth);
339
void genpstex_p_spline(obj)
342
genpstex_p_object(obj->depth);
347
/*************************************************************************
348
*************************************************************************/
349
void genpstex_p_text(t)
353
if (!special_text(t))
354
genpstex_p_object(t->depth);
359
genpstex_p_finalize_objects(iLastDepth);
364
fprintf(tfp, "\\begin{picture}(0,0)(%d,%d)\n", llx, lly);
372
/*************************************************************************
373
*************************************************************************/
374
void genpstex_t_option(opt, optarg)
378
strcpy(pstex_file, optarg);
380
genlatex_option(opt, optarg);
384
void genpstex_t_start(objects)
387
/* Put PostScript Image if any*/
388
if (pstex_file[0] != '\0') {
389
fprintf(tfp, "\\begin{picture}(0,0)%%\n");
390
/* newer includegraphics directive suggested by Stephen Harker 1/13/99 */
391
#if defined(LATEX2E_GRAPHICS)
393
fprintf(tfp, "\\epsfig{file=%s}%%\n",pstex_file);
395
fprintf(tfp, "\\includegraphics{%s}%%\n",pstex_file);
398
fprintf(tfp, "\\special{psfile=%s}%%\n",pstex_file);
400
fprintf(tfp, "\\end{picture}%%\n");
402
genlatex_start(objects);
406
void genpstex_t_text(t)
410
if (!special_text(t))
412
else genlatex_text(t);
415
/*************************************************************************
416
*************************************************************************/
417
void genpstex_text(t)
421
if (!special_text(t))
426
void genpstex_option(opt, optarg)
430
genlatex_option(opt, optarg);
433
struct driver dev_pstex_p = {
446
struct driver dev_pdftex_p = {
459
struct driver dev_pstex_t = {
472
struct driver dev_pdftex_t = {
485
struct driver dev_pstex = {
486
geneps_option, /* use eps so always exported in Portrait mode */
498
extern void genpdf_option();
499
extern void genpdf_start();
500
extern int genpdf_end();
502
struct driver dev_pdftex = {