~ubuntu-branches/ubuntu/quantal/transfig/quantal

« back to all changes in this revision

Viewing changes to .pc/28_fix_fig2dev_chmod.patch/fig2dev/dev/genpstex.c

  • Committer: Package Import Robot
  • Author(s): Roland Rosenfeld
  • Date: 2012-04-11 20:40:32 UTC
  • Revision ID: package-import@ubuntu.com-20120411204032-1w260cubi4ltzh9m
Tags: 1:3.2.5.d-3
* 28_fix_fig2dev_chmod: Add missing sys/stat.h prototype, which leads to
  an implicit declaration of fchmod(), which uses signed int while
  kFreeBSD expects unsigned int, which results in a wrong bitmap, which
  leads to a build failure.  Thanks to Steven Chamberlain for finding
  out what goes wrong here and providing a patch (Closes: #654767).
* Build-Depends on libpng-dev instead of libpng12-0-dev | libpng-dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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
 
6
 *
 
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.
 
15
 *
 
16
 */
 
17
 
 
18
/* 
 
19
 *      genpstex.c : psTeX and psTeX_t drivers for fig2dev
 
20
 *
 
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.
 
24
 *
 
25
 * The pstex_t driver is like a latex driver that only translates 
 
26
 * text defined in the default font.
 
27
 *
 
28
 * The pstex driver is like a PostScript driver that translates 
 
29
 * everything except for text in the default font.
 
30
 *
 
31
 * The pdftex_t and pdftex are drivers for combined PDF/LaTeX.
 
32
 *
 
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.
 
36
 *
 
37
 * Jose Alberto.
 
38
 */
 
39
 
 
40
#include "fig2dev.h"
 
41
#include "genps.h"
 
42
#include "genpdf.h"
 
43
#include "object.h"
 
44
#include "texfonts.h"
 
45
 
 
46
extern double rad2deg;
 
47
 
 
48
#ifdef hpux
 
49
#define rint(a) floor((a)+0.5)     /* close enough? */
 
50
#endif
 
51
 
 
52
#ifdef gould
 
53
#define rint(a) floor((a)+0.5)     /* close enough? */
 
54
#endif
 
55
 
 
56
extern void
 
57
        genlatex_start (),
 
58
        gendev_null (),
 
59
        geneps_option (),
 
60
        genps_start (),
 
61
        genps_arc (),
 
62
        genps_ellipse (),
 
63
        genps_line (),
 
64
        genps_spline (),
 
65
        genlatex_option (),
 
66
        genlatex_text (),
 
67
        genps_text ();
 
68
extern int
 
69
        genlatex_end (),
 
70
        genps_end ();
 
71
 
 
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];
 
80
static int    iLength;
 
81
static int    iPdfOutputs = 0;
 
82
 
 
83
#ifdef never
 
84
static double           unitlength;
 
85
static double           dash_mag = 1.0;
 
86
 
 
87
static int              (*translate_coordinates)() = NULL;
 
88
static int              (*translate_coordinates_d)() = NULL;
 
89
#else
 
90
extern double           unitlength;
 
91
extern double           dash_mag;
 
92
 
 
93
extern int              (*translate_coordinates)();
 
94
extern int              (*translate_coordinates_d)();
 
95
#endif
 
96
 
 
97
#define TOP             840
 
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)
 
103
 
 
104
static void genpstex_p_finalize_objects(int depth);
 
105
 
 
106
/*************************************************************************
 
107
 *************************************************************************/
 
108
static
 
109
translate2(xp, yp)
 
110
  int   *xp, *yp;
 
111
{
 
112
        *xp = *xp + 1;
 
113
        *yp = (double)(TOP - *yp -1);
 
114
        }
 
115
 
 
116
static
 
117
translate1_d(xp, yp)
 
118
  double        *xp, *yp;
 
119
{
 
120
        *xp = *xp + 1.0;
 
121
        *yp = *yp + 1.0;
 
122
        }
 
123
 
 
124
static
 
125
translate2_d(xp, yp)
 
126
  double        *xp, *yp;
 
127
{
 
128
        *xp = *xp + 1.0;
 
129
        *yp = (double)TOP - *yp -1.0;
 
130
        }
 
131
 
 
132
/*************************************************************************
 
133
 *************************************************************************/
 
134
void genpstex_p_option(opt, optarg)
 
135
char opt, *optarg;
 
136
{
 
137
       if (opt == 'p')
 
138
       {
 
139
           strcpy(pstex_file, optarg);
 
140
       }
 
141
       else
 
142
           genlatex_option(opt, optarg);
 
143
}
 
144
 
 
145
 
 
146
/*************************************************************************
 
147
 *************************************************************************/
 
148
void genpstex_p_start(objects)
 
149
  F_compound    *objects;
 
150
{
 
151
        int           tmp;
 
152
        struct stat   tStat;
 
153
        long          lUnitLength;
 
154
 
 
155
        if (*pstex_file == '\0')
 
156
        {
 
157
                put_msg("Argument -p is mandatory to pstex_p.");
 
158
                exit(1);
 
159
        }
 
160
 
 
161
        strncpy(szFileName, pstex_file, 900);
 
162
        iLength = strlen(szFileName);
 
163
 
 
164
        sprintf(szFileName + iLength, ".create");
 
165
        ptCreateFile = fopen (szFileName, "wb");
 
166
 
 
167
        if ( ! ptCreateFile)
 
168
        {
 
169
                put_msg("Couldn't open %s for writing", szFileName);
 
170
                exit(1);
 
171
        }
 
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);
 
175
 
 
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");
 
184
 
 
185
        texfontsizes[0] = texfontsizes[1] =
 
186
                TEXFONTSIZE(font_size != 0.0? font_size : DEFAULT_FONT_SIZE);
 
187
 
 
188
        unitlength = mag/ppi;
 
189
        dash_mag /= unitlength*80.0;
 
190
 
 
191
        translate_coordinates = translate2;
 
192
        translate_coordinates_d = translate2_d;
 
193
 
 
194
        TRANS2(llx, lly, urx, ury);
 
195
        if (llx > urx) SWAP(llx, urx)
 
196
        if (lly > ury) SWAP(lly, ury)
 
197
 
 
198
        /* LaTeX start */
 
199
 
 
200
        /* print any whole-figure comments prefixed with "%" */
 
201
        if (objects->comments) {
 
202
            fprintf(tfp,"%%\n");
 
203
            print_comments("% ",objects->comments, "");
 
204
            fprintf(tfp,"%%\n");
 
205
        }
 
206
 
 
207
        lUnitLength = (long) (round(4736286.72*unitlength));
 
208
        fprintf(tfp, "\\setlength{\\unitlength}{%lisp}%%\n",
 
209
                                lUnitLength);
 
210
        /* define the SetFigFont macro */
 
211
        define_setfigfont(tfp);
 
212
 
 
213
        sprintf(szFileName + iLength, ".size");
 
214
        fprintf(ptCreateFile, "if [ \"$iOptRemove\" == \"\" ]; then\n");
 
215
        if (iPdfOutputs)
 
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);
 
218
        else
 
219
                fprintf(ptCreateFile, "echo -n\"\" > %s\n", szFileName);
 
220
        fprintf(ptCreateFile, "else\n  rm -f %s\nfi\n", szFileName);
 
221
}
 
222
 
 
223
/*************************************************************************
 
224
 *************************************************************************/
 
225
void genpdftex_p_start(objects)
 
226
  F_compound    *objects;
 
227
{
 
228
        iPdfOutputs = 1;
 
229
        genpstex_p_start(objects);
 
230
}
 
231
 
 
232
 
 
233
/*************************************************************************
 
234
 *************************************************************************/
 
235
int genpstex_p_end()
 
236
{
 
237
        if (iTextRead)
 
238
        {
 
239
                fprintf(tfp, "\\end{picture}%%\n");
 
240
                iTextRead = 0;
 
241
        }
 
242
        if (iObjectsRead)
 
243
        {
 
244
                genpstex_p_finalize_objects(iLastDepth);
 
245
                iObjectsRead = 0;
 
246
        }
 
247
 
 
248
        /* LaTeX ending */
 
249
        fprintf(tfp, "\\begin{picture}(%d,%d)\n", urx-llx, ury-lly);
 
250
        fprintf(tfp, "\\end{picture}%%\n");
 
251
 
 
252
        fclose(ptCreateFile);
 
253
 
 
254
        /* all ok */
 
255
        return 0;
 
256
}
 
257
 
 
258
 
 
259
/*************************************************************************
 
260
 *************************************************************************/
 
261
void genpstex_p_finalize_objects(depth)
 
262
int depth;
 
263
{
 
264
        char    szFileName[1000];
 
265
        int     iLength;
 
266
 
 
267
        strncpy(szFileName, pstex_file, 900);
 
268
        iLength = strlen(szFileName);
 
269
 
 
270
 
 
271
        sprintf(szFileName + iLength, "%03d", iObjectsFileNumber++);
 
272
        fprintf(ptCreateFile, "if [ \"$iOptRemove\" == \"\" ]; then\n");
 
273
        if (iPdfOutputs)
 
274
        {
 
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);
 
277
        }
 
278
        else
 
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);
 
281
        if (iPdfOutputs)
 
282
                fprintf(ptCreateFile, "pdf");
 
283
        else
 
284
                fprintf(ptCreateFile, "eps");
 
285
        fprintf(ptCreateFile, "\nfi\n");
 
286
 
 
287
        fprintf(tfp, "\\begin{picture}(0,0)%%\n");
 
288
/* newer includegraphics directive suggested by Stephen Harker 1/13/99 */
 
289
#if defined(LATEX2E_GRAPHICS)
 
290
#  if defined(EPSFIG)
 
291
        fprintf(tfp, "\\epsfig{file=%s.eps}%%\n",szFileName);
 
292
#  else
 
293
        fprintf(tfp, "\\includegraphics{%s}%%\n",szFileName);
 
294
#  endif
 
295
#else
 
296
        fprintf(tfp, "\\special{psfile=%s.eps}%%\n",szFileName);
 
297
#endif
 
298
        fprintf(tfp, "\\end{picture}%%\n");
 
299
}
 
300
 
 
301
/*************************************************************************
 
302
 *************************************************************************/
 
303
void genpstex_p_object(depth)
 
304
int depth;
 
305
{
 
306
        if (iTextRead)
 
307
        {
 
308
                fprintf(tfp, "\\end{picture}%%\n");
 
309
                iTextRead = 0;
 
310
        }
 
311
        if (iObjectsRead == 0)
 
312
        {
 
313
                iStartDepth = depth;
 
314
                iObjectsRead = 1;
 
315
        }
 
316
        iLastDepth = depth;
 
317
 
 
318
}
 
319
 
 
320
void genpstex_p_arc(obj)
 
321
F_arc   *obj;
 
322
{
 
323
        genpstex_p_object(obj->depth);
 
324
}
 
325
 
 
326
 
 
327
void genpstex_p_ellipse(obj)
 
328
F_ellipse       *obj;
 
329
{
 
330
        genpstex_p_object(obj->depth);
 
331
}
 
332
 
 
333
void genpstex_p_line(obj)
 
334
F_line  *obj;
 
335
{
 
336
        genpstex_p_object(obj->depth);
 
337
}
 
338
 
 
339
void genpstex_p_spline(obj)
 
340
F_spline        *obj;
 
341
{
 
342
        genpstex_p_object(obj->depth);
 
343
}
 
344
 
 
345
 
 
346
 
 
347
/*************************************************************************
 
348
 *************************************************************************/
 
349
void genpstex_p_text(t)
 
350
F_text  *t;
 
351
{
 
352
 
 
353
        if (!special_text(t))
 
354
                genpstex_p_object(t->depth);
 
355
        else
 
356
        {
 
357
                if (iObjectsRead)
 
358
                {
 
359
                        genpstex_p_finalize_objects(iLastDepth);
 
360
                        iObjectsRead = 0;
 
361
                }
 
362
                if (iTextRead == 0)
 
363
                {
 
364
                        fprintf(tfp, "\\begin{picture}(0,0)(%d,%d)\n", llx, lly);
 
365
                        iTextRead = 1;
 
366
                }
 
367
                genlatex_text(t);
 
368
        }
 
369
 
 
370
}
 
371
 
 
372
/*************************************************************************
 
373
 *************************************************************************/
 
374
void genpstex_t_option(opt, optarg)
 
375
char opt, *optarg;
 
376
{
 
377
       if (opt == 'p') 
 
378
           strcpy(pstex_file, optarg);
 
379
       else
 
380
           genlatex_option(opt, optarg);
 
381
}
 
382
 
 
383
 
 
384
void genpstex_t_start(objects)
 
385
F_compound      *objects;
 
386
{
 
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)
 
392
#  if defined(EPSFIG)
 
393
                fprintf(tfp, "\\epsfig{file=%s}%%\n",pstex_file); 
 
394
#  else
 
395
                fprintf(tfp, "\\includegraphics{%s}%%\n",pstex_file);
 
396
#  endif
 
397
#else
 
398
                fprintf(tfp, "\\special{psfile=%s}%%\n",pstex_file);
 
399
#endif
 
400
                fprintf(tfp, "\\end{picture}%%\n");
 
401
        }
 
402
        genlatex_start(objects);
 
403
 
 
404
}
 
405
 
 
406
void genpstex_t_text(t)
 
407
F_text  *t;
 
408
{
 
409
 
 
410
        if (!special_text(t))
 
411
          gendev_null();
 
412
        else genlatex_text(t);
 
413
}
 
414
 
 
415
/*************************************************************************
 
416
 *************************************************************************/
 
417
void genpstex_text(t)
 
418
F_text  *t;
 
419
{
 
420
 
 
421
        if (!special_text(t))
 
422
          genps_text(t);
 
423
        else gendev_null();
 
424
}
 
425
 
 
426
void genpstex_option(opt, optarg)
 
427
char opt, *optarg;
 
428
{
 
429
       if (opt != 'p')
 
430
           genlatex_option(opt, optarg);
 
431
}
 
432
 
 
433
struct driver dev_pstex_p = {
 
434
        genpstex_p_option,
 
435
        genpstex_p_start,
 
436
        gendev_null,
 
437
        genpstex_p_arc,
 
438
        genpstex_p_ellipse,
 
439
        genpstex_p_line,
 
440
        genpstex_p_spline,
 
441
        genpstex_p_text,
 
442
        genpstex_p_end,
 
443
        INCLUDE_TEXT
 
444
};
 
445
 
 
446
struct driver dev_pdftex_p = {
 
447
        genpstex_p_option,
 
448
        genpdftex_p_start,
 
449
        gendev_null,
 
450
        genpstex_p_arc,
 
451
        genpstex_p_ellipse,
 
452
        genpstex_p_line,
 
453
        genpstex_p_spline,
 
454
        genpstex_p_text,
 
455
        genpstex_p_end,
 
456
        INCLUDE_TEXT
 
457
};
 
458
 
 
459
struct driver dev_pstex_t = {
 
460
        genpstex_t_option,
 
461
        genpstex_t_start,
 
462
        gendev_null,
 
463
        gendev_null,
 
464
        gendev_null,
 
465
        gendev_null,
 
466
        gendev_null,
 
467
        genpstex_t_text,
 
468
        genlatex_end,
 
469
        INCLUDE_TEXT
 
470
};
 
471
 
 
472
struct driver dev_pdftex_t = {
 
473
        genpstex_t_option,
 
474
        genpstex_t_start,
 
475
        gendev_null,
 
476
        gendev_null,
 
477
        gendev_null,
 
478
        gendev_null,
 
479
        gendev_null,
 
480
        genpstex_t_text,
 
481
        genlatex_end,
 
482
        INCLUDE_TEXT
 
483
};
 
484
 
 
485
struct driver dev_pstex = {
 
486
        geneps_option,  /* use eps so always exported in Portrait mode */
 
487
        genps_start,
 
488
        genps_grid,
 
489
        genps_arc,
 
490
        genps_ellipse,
 
491
        genps_line,
 
492
        genps_spline,
 
493
        genpstex_text,
 
494
        genps_end,
 
495
        INCLUDE_TEXT
 
496
};
 
497
 
 
498
extern void     genpdf_option();
 
499
extern void     genpdf_start();
 
500
extern int      genpdf_end();
 
501
 
 
502
struct driver dev_pdftex = {
 
503
        genpdf_option,
 
504
        genpdf_start,
 
505
        genps_grid,
 
506
        genps_arc,
 
507
        genps_ellipse,
 
508
        genps_line,
 
509
        genps_spline,
 
510
        genpstex_text,
 
511
        genpdf_end,
 
512
        INCLUDE_TEXT
 
513
};
 
514
 
 
515