home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume27 / transfig-2.1.8 / part06 < prev    next >
Text File  |  1993-10-05  |  56KB  |  1,980 lines

  1. Newsgroups: comp.sources.unix
  2. From: envbvs@epb12.lbl.gov (Brian V. Smith)
  3. Subject: v27i060: transfig-2.1.8 - a set of tools for creating TeX documents with graphics, Part06/07
  4. References: <1.749903574.10622@gw.home.vix.com>
  5. Sender: unix-sources-moderator@gw.home.vix.com
  6. Approved: vixie@gw.home.vix.com
  7.  
  8. Submitted-By: envbvs@epb12.lbl.gov (Brian V. Smith)
  9. Posting-Number: Volume 27, Issue 60
  10. Archive-Name: transfig-2.1.8/part06
  11.  
  12. #! /bin/sh
  13. # This is a shell archive.  Remove anything before this line, then unpack
  14. # it by saving it into a file and typing "sh file".  To overwrite existing
  15. # files, type "sh file -c".  You can also feed this as standard input via
  16. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  17. # will see the following message at the end:
  18. #        "End of archive 6 (of 7)."
  19. # Contents:  fig2dev/dev/genibmgl.c fig2dev/dev/genpictex.c
  20. # Wrapped by envbvs@epb12.lbl.gov.lbl.gov on Fri Oct  1 14:55:50 1993
  21. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  22. if test -f 'fig2dev/dev/genibmgl.c' -a "${1}" != "-c" ; then 
  23.   echo shar: Will not clobber existing file \"'fig2dev/dev/genibmgl.c'\"
  24. else
  25. echo shar: Extracting \"'fig2dev/dev/genibmgl.c'\" \(26109 characters\)
  26. sed "s/^X//" >'fig2dev/dev/genibmgl.c' <<'END_OF_FILE'
  27. X/*
  28. X * TransFig: Facility for Translating Fig code
  29. X * Copyright (c) 1985 Supoj Sutantavibul
  30. X * Copyright (c) 1991 Micah Beck
  31. X *
  32. X * Permission to use, copy, modify, distribute, and sell this software and its
  33. X * documentation for any purpose is hereby granted without fee, provided that
  34. X * the above copyright notice appear in all copies and that both that
  35. X * copyright notice and this permission notice appear in supporting
  36. X * documentation. The authors make no representations about the suitability 
  37. X * of this software for any purpose.  It is provided "as is" without express 
  38. X * or implied warranty.
  39. X *
  40. X * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  41. X * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  42. X * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  43. X * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  44. X * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  45. X * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  46. X * PERFORMANCE OF THIS SOFTWARE.
  47. X *
  48. X */
  49. X
  50. X/* 
  51. X *    genibmgl.c :    IBMGL driver for fig2dev
  52. X *            IBM 6180 Color Plotter with
  53. X *            IBM Graphics Enhancement Cartridge
  54. X *     Author E. Robert Tisdale, University of California, 1/92
  55. X *    (edwin@cs.ucla.edu)
  56. X *
  57. X *        adapted from:
  58. X *
  59. X *    genpictex.c :    PiCTeX driver for fig2dev
  60. X *
  61. X *     Author Micah Beck, Cornell University, 4/88
  62. X *    Color, rotated text and ISO-chars added by Herbert Bauer 11/91
  63. X*/
  64. X
  65. X#if defined(hpux) || defined(SYSV)
  66. X#include <sys/types.h>
  67. X#endif
  68. X#include <sys/file.h>
  69. X#ifdef SYSV
  70. X#include <string.h>
  71. X#else
  72. X#include <strings.h>
  73. X#endif
  74. X#include <stdio.h>
  75. X#include <math.h>
  76. X#include "object.h"
  77. X#include "fig2dev.h"
  78. X#include "pi.h"
  79. X
  80. X#define        FALSE            0
  81. X#define        TRUE            1
  82. X#define        FONTS             35
  83. X#define        COLORS             8
  84. X#define        PATTERNS         21
  85. X#define        DPR         180.0/M_PI    /*       degrees/radian    */
  86. X#define        DELTA         M_PI/36.0    /* radians        */
  87. X#define        DEFAULT_FONT_SIZE    11    /* points        */
  88. X#define        POINT_PER_INCH        72.27    /*      points/inch    */
  89. X#define        CMPP        254.0/7227.0    /*   centimeters/point    */
  90. X#define        UNITS_PER_INCH         1016.0    /* plotter units/inch    */
  91. X#define        HEIGHT             7650.0    /* plotter units    */
  92. X#define        ISO_A4            10900.0    /* plotter units    */
  93. X#define        ANSI_A            10300.0    /* plotter units    */
  94. X#define        SPEED_LIMIT        128.0    /* centimeters/second    */
  95. X
  96. X#ifdef IBMGEC
  97. Xstatic    int    ibmgec         = TRUE;
  98. X#else
  99. Xstatic    int    ibmgec         = FALSE;
  100. X#endif
  101. Xstatic    int    portrait     = FALSE;
  102. Xstatic    int    reflected     = FALSE;
  103. Xstatic    int    fonts         = FONTS;
  104. Xstatic    int    colors         = COLORS;
  105. Xstatic    int    patterns     = PATTERNS;
  106. Xstatic    int    line_color     = DEFAULT;
  107. Xstatic    int    line_style     = SOLID_LINE;
  108. Xstatic    int    fill_pattern     = DEFAULT;
  109. Xstatic    double    dash_length     = DEFAULT;    /* in pixels        */
  110. X#ifdef A4
  111. Xstatic    double    pagelength     = ISO_A4/UNITS_PER_INCH;
  112. X#else
  113. Xstatic    double    pagelength     = ANSI_A/UNITS_PER_INCH;
  114. X#endif
  115. Xstatic    double    pageheight     = HEIGHT/UNITS_PER_INCH;
  116. Xstatic    double    pen_speed     = SPEED_LIMIT;
  117. Xstatic    double    xz         =  0.0;    /* inches        */
  118. Xstatic    double    yz         =  0.0;    /* inches        */
  119. Xstatic    double    xl         =  0.0;    /* inches        */
  120. Xstatic    double    yl         =  0.0;    /* inches        */
  121. Xstatic    double    xu         = 32.25;    /* inches        */
  122. Xstatic    double    yu         = 32.25;    /* inches        */
  123. X
  124. Xstatic    int    pen_number[]     = { 1, 2, 3, 4, 5, 6, 7, 8, 1};
  125. Xstatic    double    pen_thickness[]     = {.3,.3,.3,.3,.3,.3,.3,.3,.3};
  126. X
  127. Xstatic    int    line_type[]     =
  128. X       {-1, 1, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6,-1,-1,-1,-1,-1,-1,-1,-1};
  129. Xstatic    double    line_space[]     =
  130. X       {.3,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.3,.3};
  131. Xstatic    int    fill_type[]     =
  132. X       { 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 1, 2};
  133. Xstatic    double    fill_space[]     =
  134. X       {.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1};
  135. Xstatic    double    fill_angle[]     =
  136. X       { 0, 0,-45,0,45,90,-45,0,45,90,-45,0,45,90,-45,0,45,90, 0, 0, 0, 0};
  137. X
  138. Xstatic    int    standard[]     = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  139. X         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  140. Xstatic    int    alternate[]     = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  141. X         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
  142. Xstatic    double    slant[]         = { 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10,
  143. X         0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0, 0};
  144. Xstatic    double    wide[]         = {.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,
  145. X        .6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6};
  146. Xstatic    double    high[]         = {.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,
  147. X        .8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8};
  148. X
  149. Xstatic void genibmgl_option(opt, optarg)
  150. Xchar opt, *optarg;
  151. X{
  152. X    switch (opt) {
  153. X
  154. X        case 'a':                /* paper size        */
  155. X#ifdef A4
  156. X        pagelength     = ANSI_A/UNITS_PER_INCH;
  157. X#else
  158. X        pagelength     = ISO_A4/UNITS_PER_INCH;
  159. X#endif
  160. X        break;
  161. X
  162. X        case 'c':                /* Graphics Enhancement    */
  163. X        ibmgec         = !ibmgec;    /* Cartridge emulation    */
  164. X        break;
  165. X
  166. X        case 'd':                /* position and window    */
  167. X        sscanf(optarg, "%lf,%lf,%lf,%lf", &xl,&yl,&xu,&yu);
  168. X                        /* inches        */
  169. X        break;
  170. X
  171. X        case 'f':                /* user's characters    */
  172. X        {
  173. X            FILE    *ffp;
  174. X            int        font;
  175. X            if ((ffp = fopen(optarg, "r")) == NULL)
  176. X            fprintf(stderr, "Couldn't open %s\n", optarg);
  177. X            else
  178. X            for (font = 0; font <= fonts; font++)
  179. X                fscanf(ffp, "%d%d%lf%lf%lf",
  180. X                &standard[font],    /* 0-4 6-9 30-39*/
  181. X                &alternate[font],    /* 0-4 6-9 30-39*/
  182. X                &slant[font],        /*   degrees    */
  183. X                &wide[font],        /*    ~1.0    */
  184. X                &high[font]);        /*    ~1.0    */
  185. X            fclose(ffp);
  186. X        }
  187. X        break;
  188. X
  189. X        case 'l':                /* user's fill patterns    */
  190. X        {
  191. X            FILE    *ffp;
  192. X            int        pattern;
  193. X            if ((ffp = fopen(optarg, "r")) == NULL)
  194. X            fprintf(stderr, "Couldn't open %s\n", optarg);
  195. X            else
  196. X            for (pattern = 1; pattern <= patterns; pattern++)
  197. X                fscanf(ffp, "%d%lf%d%lf%lf",
  198. X                &line_type[pattern],    /*    -1-6    */
  199. X                &line_space[pattern],    /*   inches    */
  200. X                &fill_type[pattern],    /*     1-5    */
  201. X                &fill_space[pattern],    /*   inches    */
  202. X                &fill_angle[pattern]);    /*   degrees    */
  203. X            fclose(ffp);
  204. X        }
  205. X        break;
  206. X
  207. X        case 'L':                /* language        */
  208. X        break;
  209. X
  210. X        case 'm':                /* magnify and offset    */
  211. X        sscanf(optarg, "%lf,%lf,%lf", &mag,&xz,&yz);
  212. X                        /* inches        */
  213. X        break;
  214. X
  215. X        case 'p':                /* user's colors    */
  216. X        {
  217. X            FILE    *ffp;
  218. X            int        color;
  219. X            if ((ffp = fopen(optarg, "r")) == NULL)
  220. X            fprintf(stderr, "Couldn't open %s\n", optarg);
  221. X            else
  222. X            for (color = 0; color <= colors; color++)
  223. X                fscanf(ffp, "%d%lf",
  224. X                &pen_number[color],    /*     1-8    */
  225. X                &pen_thickness[color]);    /* millimeters    */
  226. X            fclose(ffp);
  227. X        }
  228. X        break;
  229. X
  230. X        case 'P':                /* portrait mode    */
  231. X        portrait     = TRUE;
  232. X        break;
  233. X
  234. X        case 's':                /* set default font size */
  235. X        font_size     = atoi(optarg) ?
  236. X            atoi(optarg): DEFAULT_FONT_SIZE;
  237. X        break;
  238. X
  239. X        case 'S':                /* select pen velocity    */
  240. X        pen_speed     = atof(optarg);
  241. X        break;
  242. X
  243. X        case 'v':
  244. X        reflected     = TRUE;    /* mirror image        */
  245. X        break;
  246. X
  247. X        default:
  248. X        put_msg(Err_badarg, opt, "ibmgl");
  249. X        exit(1);
  250. X        break;
  251. X    }
  252. X}
  253. X
  254. Xstatic double        ppi;            /*     pixels/inch    */
  255. Xstatic double        cpi;            /*       cent/inch    */
  256. Xstatic double        cpp;            /*       cent/pixel    */
  257. Xstatic double        wcmpp     = CMPP;    /* centimeter/point    */
  258. Xstatic double        hcmpp     = CMPP;    /* centimeter/point    */
  259. Xstatic int        flipped     = FALSE;    /* flip Y coordinate    */
  260. X
  261. Xvoid genibmgl_start(objects)
  262. XF_compound    *objects;
  263. X{
  264. X    int     P1x, P1y, P2x, P2y;
  265. X    int     Xll, Yll, Xur, Yur;
  266. X    double    Xmin,Xmax,Ymin,Ymax;
  267. X    double    height, length;
  268. X
  269. X    if (fabs(mag) < 1.0/2048.0){
  270. X        fprintf(stderr, "|mag| < 1/2048\n");
  271. X        exit(1);
  272. X        }
  273. X
  274. X    if (xl < xu)
  275. X        if (0.0 < xu)
  276. X        if (xl < pagelength) {
  277. X            xl     = (0.0 < xl) ? xl: 0.0;
  278. X            xu     = (xu < pagelength) ? xu: pagelength;
  279. X            }
  280. X        else {
  281. X            fprintf(stderr, "xll >= %.2f\n", pagelength);
  282. X            exit(1);
  283. X            }
  284. X        else {
  285. X        fprintf(stderr, "xur <= 0.0\n");
  286. X        exit(1);
  287. X        }
  288. X    else {
  289. X        fprintf(stderr, "xur <= xll\n");
  290. X        exit(1);
  291. X        }
  292. X
  293. X    if (yl < yu)
  294. X        if (0.0 < yu)
  295. X        if (yl < pageheight) {
  296. X            yl     = (0.0 < yl) ? yl: 0.0;
  297. X            yu     = (yu < pageheight) ? yu: pageheight;
  298. X            }
  299. X        else {
  300. X            fprintf(stderr, "yll >= %.2f\n", pageheight);
  301. X            exit(1);
  302. X            }
  303. X        else {
  304. X        fprintf(stderr, "yur <= 0.0\n");
  305. X        exit(1);
  306. X        }
  307. X    else {
  308. X        fprintf(stderr, "yur <= yll\n");
  309. X        exit(1);
  310. X        }
  311. X
  312. X    ppi     = objects->nwcorner.x;
  313. X    cpi     = mag*100.0/sqrt((xu-xl)*(xu-xl) + (yu-yl)*(yu-yl));
  314. X    cpp     = cpi/ppi;
  315. X    if (objects->nwcorner.y == 2)
  316. X        flipped     = TRUE;
  317. X
  318. X    /* IBMGL start */
  319. X    fprintf(tfp, "IN;\n");            /* initialize plotter    */
  320. X
  321. X    if (portrait) {                /* portrait mode    */
  322. X        fprintf(tfp, "RO90;\n");        /* rotate 90 degrees    */
  323. X        Xll     = yl*UNITS_PER_INCH;
  324. X        Xur     = yu*UNITS_PER_INCH;
  325. X        Yll     = (pagelength - xu)*UNITS_PER_INCH;
  326. X        Yur     = (pagelength - xl)*UNITS_PER_INCH;
  327. X        length     = yu - yl;
  328. X        height     = xu - xl;
  329. X        P1x          = Xll;
  330. X        P2x         = Xur;
  331. X        if (reflected)            /* upside-down text    */
  332. X        hcmpp     = -hcmpp;
  333. X        if (reflected^flipped) {        /* reflected or flipped */
  334. X        P1y     = Yur;            /* but not both        */
  335. X        P2y     = Yll;
  336. X        }
  337. X        else {                /* normal        */
  338. X        P1y     = Yll;
  339. X        P2y     = Yur;
  340. X        }
  341. X        Xmin     =  xz;
  342. X        Xmax     =  xz + (yu - yl)/mag;
  343. X        Ymin     =  yz;
  344. X        Ymax     =  yz + (xu - xl)/mag;
  345. X        }
  346. X    else {                    /* landscape mode    */
  347. X        Xll     = xl*UNITS_PER_INCH;
  348. X        Yll     = yl*UNITS_PER_INCH;
  349. X        Yur     = yu*UNITS_PER_INCH;
  350. X        Xur     = xu*UNITS_PER_INCH;
  351. X        length     = xu - xl;
  352. X        height     = yu - yl;
  353. X        if (reflected) {            /* flipped   or not    */
  354. X        wcmpp     = -wcmpp;        /* backward text    */
  355. X        P1x     = Xur;
  356. X        P2x     = Xll;
  357. X        }
  358. X        else {                /* normal        */
  359. X        P1x     = Xll;
  360. X        P2x     = Xur;
  361. X        }
  362. X        if (flipped) {            /* reflected or not    */
  363. X        P1y     = Yur;
  364. X        P2y     = Yll;
  365. X        }
  366. X        else {
  367. X        P1y      = Yll;
  368. X        P2y      = Yur;
  369. X        }
  370. X        }
  371. X
  372. X    Xmin     = xz;
  373. X    Ymin     = yz;
  374. X    Xmax     = xz + length/mag;
  375. X    Ymax     = yz + height/mag;
  376. X
  377. X    fprintf(tfp, "IP%d,%d,%d,%d;\n",
  378. X        P1x, P1y, P2x, P2y);
  379. X    fprintf(tfp, "IW%d,%d,%d,%d;\n",
  380. X        Xll, Yll, Xur, Yur);
  381. X    fprintf(tfp, "SC%.4f,%.4f,%.4f,%.4f;\n",
  382. X        Xmin,Xmax,Ymin,Ymax);
  383. X    if (0.0 < pen_speed && pen_speed < SPEED_LIMIT)
  384. X        fprintf(tfp, "VS%.2f;\n", pen_speed);
  385. X}
  386. X
  387. Xstatic arc_tangent(x1, y1, x2, y2, direction, x, y)
  388. Xdouble    x1, y1, x2, y2, *x, *y;
  389. Xint    direction;
  390. X{
  391. X    if (direction) { /* counter clockwise  */
  392. X        *x = x2 - (y2 - y1);
  393. X        *y = y2 + (x2 - x1);
  394. X        }
  395. X    else {
  396. X        *x = x2 + (y2 - y1);
  397. X        *y = y2 - (x2 - x1);
  398. X        }
  399. X    }
  400. X
  401. X/*    draw arrow heading from (x1, y1) to (x2, y2)    */
  402. X
  403. Xstatic draw_arrow_head(x1, y1, x2, y2, arrowht, arrowwid)
  404. Xdouble    x1, y1, x2, y2, arrowht, arrowwid;
  405. X{
  406. X    double    x, y, xb, yb, dx, dy, l, sina, cosa;
  407. X    double    xc, yc, xd, yd;
  408. X    int style;
  409. X    double length;
  410. X
  411. X    dx     = x2 - x1;
  412. X    dy     = y1 - y2;
  413. X    l     = sqrt(dx*dx+dy*dy);
  414. X    sina     = dy/l;
  415. X    cosa     = dx/l;
  416. X    xb     = x2*cosa - y2*sina;
  417. X    yb     = x2*sina + y2*cosa;
  418. X    x     = xb - arrowht;
  419. X    y     = yb - arrowwid/2.0;
  420. X    xc     =  x*cosa + y*sina;
  421. X    yc     = -x*sina + y*cosa;
  422. X    y     = yb + arrowwid/2.0;
  423. X    xd     =  x*cosa + y*sina;
  424. X    yd     = -x*sina + y*cosa;
  425. X
  426. X    /* save line style and set to solid */
  427. X    style     = line_style;
  428. X    length     = dash_length;
  429. X    set_style(SOLID_LINE, 0.0);
  430. X
  431. X    fprintf(tfp, "PA%.4f,%.4f;PD%.4f,%.4f,%.4f,%.4f;PU\n",
  432. X        xc, yc, x2, y2, xd, yd);
  433. X
  434. X    /* restore line style */
  435. X    set_style(style, length);
  436. X    }
  437. X
  438. X/* 
  439. X * set_style - issue line style commands as appropriate
  440. X */
  441. Xstatic set_style(style, length)
  442. Xint    style;
  443. Xdouble    length;
  444. X{
  445. X    if (style == line_style)
  446. X        switch (line_style) {
  447. X        case SOLID_LINE:
  448. X            break;
  449. X
  450. X        case DASH_LINE:
  451. X            if (dash_length != length && length > 0.0) {
  452. X            dash_length  = length;
  453. X            fprintf(tfp, "LT2,%.4f;\n", dash_length*2.0*cpp);
  454. X            }
  455. X            break;
  456. X
  457. X        case DOTTED_LINE:
  458. X            if (dash_length != length && length > 0.0) {
  459. X            dash_length  = length;
  460. X            fprintf(tfp, "LT1,%.4f;\n", dash_length*2.0*cpp);
  461. X            }
  462. X            break;
  463. X        }
  464. X    else {
  465. X        line_style = style;
  466. X        switch (line_style) {
  467. X        case SOLID_LINE:
  468. X            fprintf(tfp, "LT;\n");
  469. X            break;
  470. X
  471. X        case DASH_LINE:
  472. X            if (dash_length != length && length > 0.0)
  473. X            dash_length  = length;
  474. X            if (dash_length > 0.0)
  475. X            fprintf(tfp, "LT2,%.4f;\n", dash_length*2.0*cpp);
  476. X            else
  477. X            fprintf(tfp, "LT2,-1.0;\n");
  478. X            break;
  479. X
  480. X        case DOTTED_LINE:
  481. X            if (dash_length != length && length > 0.0)
  482. X            dash_length  = length;
  483. X            if (dash_length > 0.0)
  484. X            fprintf(tfp, "LT1,%.4f;\n", dash_length*2.0*cpp);
  485. X            else
  486. X            fprintf(tfp, "LT1,-1.0;\n");
  487. X            break;
  488. X        }
  489. X        }
  490. X    }
  491. X
  492. X/* 
  493. X * set_width - issue line width commands as appropriate
  494. X */
  495. Xstatic set_width(w)
  496. Xint    w;
  497. X{
  498. Xstatic    int    line_width     = DEFAULT;    /* in pixels         */
  499. X    line_width  = w;
  500. X    }
  501. X
  502. X/* 
  503. X * set_color - issue line color commands as appropriate
  504. X */
  505. Xstatic set_color(color)
  506. Xint    color;
  507. X{
  508. Xstatic    int    number         = 0;    /* 1 <= number <= 8        */
  509. Xstatic    double    thickness     = 0.3;    /* pen thickness in millimeters    */
  510. X    if (line_color != color) {
  511. X        line_color  = color;
  512. X        color    = (colors + color)%colors;
  513. X        if (number != pen_number[color]) {
  514. X        number  = pen_number[color];
  515. X        fprintf(tfp, "SP%d;\n", pen_number[color]);
  516. X        }
  517. X        if (thickness != pen_thickness[color]) {
  518. X        thickness  = pen_thickness[color];
  519. X        fprintf(tfp, "PT%.4f;\n", pen_thickness[color]);
  520. X        }
  521. X        }
  522. X    }
  523. X
  524. Xstatic fill_polygon(pattern)
  525. Xint    pattern;
  526. X{
  527. X    if (1 < pattern && pattern <= patterns) {
  528. X        int        style;
  529. X        double    length;
  530. X        if (fill_pattern != pattern) {
  531. X        fill_pattern  = pattern;
  532. X        fprintf(tfp, "FT%d,%.4f,%.4f;", fill_type[pattern],
  533. X            fill_space[pattern],
  534. X            reflected ? -fill_angle[pattern]: fill_angle[pattern]);
  535. X        }
  536. X        /*    save line style */
  537. X        style     = line_style;
  538. X        length     = dash_length;
  539. X        fprintf(tfp, "LT%d,%.4f;FP;\n",
  540. X            line_type[pattern], line_space[pattern]*cpi);
  541. X        /* restore line style */
  542. X        line_style     = DEFAULT;
  543. X        dash_length     = DEFAULT;
  544. X        set_style(style, length);
  545. X        }
  546. X    }
  547. X    
  548. Xvoid arc(sx, sy, cx, cy, theta, delta)
  549. Xdouble    sx, sy, cx, cy, theta, delta;
  550. X{
  551. X    if (ibmgec)
  552. X        if (delta == M_PI/36.0)        /* 5 degrees        */
  553. X        fprintf(tfp, "AA%.4f,%.4f,%.4f;",
  554. X            cx, cy, theta*DPR);
  555. X        else
  556. X        fprintf(tfp, "AA%.4f,%.4f,%.4f,%.4f;",
  557. X            cx, cy, theta*DPR, delta*DPR);
  558. X    else {
  559. X        double    alpha;
  560. X        if (theta < 0.0)
  561. X        delta = -fabs(delta);
  562. X        else
  563. X        delta = fabs(delta);
  564. X        for (alpha = delta; fabs(alpha) < fabs(theta); alpha += delta) {
  565. X        fprintf(tfp, "PA%.4f,%.4f;\n",
  566. X                cx + (sx - cx)*cos(alpha) - (sy - cy)*sin(alpha),
  567. X                cy + (sy - cy)*cos(alpha) + (sx - cx)*sin(alpha));
  568. X        }
  569. X        fprintf(tfp, "PA%.4f,%.4f;\n",
  570. X                cx + (sx - cx)*cos(theta) - (sy - cy)*sin(theta),
  571. X                cy + (sy - cy)*cos(theta) + (sx - cx)*sin(theta));
  572. X        }
  573. X    }
  574. X
  575. Xvoid genibmgl_arc(a)
  576. XF_arc    *a;
  577. X{
  578. X    if (a->thickness != 0 ||
  579. X        ibmgec && 1 <= a->area_fill && a->area_fill <= patterns) {
  580. X        double    x, y;
  581. X        double    cx, cy, sx, sy, ex, ey;
  582. X        double    dx1, dy1, dx2, dy2, theta;
  583. X
  584. X        set_style(a->style, a->style_val);
  585. X        set_width(a->thickness);
  586. X        set_color(a->color);
  587. X
  588. X        cx         = a->center.x/ppi;
  589. X        cy         = a->center.y/ppi;
  590. X        sx         = a->point[0].x/ppi;
  591. X        sy         = a->point[0].y/ppi;
  592. X        ex         = a->point[2].x/ppi;
  593. X        ey         = a->point[2].y/ppi;
  594. X
  595. X        dx1         = sx - cx;
  596. X        dy1         = sy - cy;
  597. X        dx2         = ex - cx;
  598. X        dy2         = ey - cy;
  599. X        
  600. X        theta     = atan2(dy2, dx2) - atan2(dy1, dx1);
  601. X        if (a->direction^flipped) {
  602. X        if (theta < 0.0)
  603. X            theta    += 2.0*M_PI;
  604. X        }
  605. X        else {
  606. X        if (theta > 0.0)
  607. X            theta    -= 2.0*M_PI;
  608. X        }
  609. X
  610. X        if (a->thickness != 0 && a->back_arrow) {
  611. X        arc_tangent(cx, cy, sx, sy, a->direction^flipped, &x, &y);
  612. X        draw_arrow_head(x, y, sx, sy,
  613. X        a->back_arrow->ht/ppi, a->back_arrow->wid/ppi);
  614. X        }
  615. X
  616. X        fprintf(tfp, "PA%.4f,%.4f;PM;PD;", sx, sy);
  617. X        arc(sx, sy, cx, cy, theta, DELTA);
  618. X        fprintf(tfp, "PU;PM2;\n");
  619. X
  620. X        if (a->thickness != 0)
  621. X        fprintf(tfp, "EP;\n");
  622. X
  623. X        if (a->thickness != 0 && a->for_arrow) {
  624. X        arc_tangent(cx, cy, ex, ey, !a->direction^flipped, &x, &y);
  625. X        draw_arrow_head(x, y, ex, ey,
  626. X            a->for_arrow->ht/ppi, a->for_arrow->wid/ppi);
  627. X        }
  628. X
  629. X        if (1 < a->area_fill && a->area_fill <= patterns)
  630. X        fill_polygon(a->area_fill);
  631. X        }
  632. X    }
  633. X
  634. Xvoid genibmgl_ellipse(e)
  635. XF_ellipse    *e;
  636. X{
  637. X    if (e->thickness != 0 ||
  638. X        ibmgec && 1 <= e->area_fill && e->area_fill <= patterns) {
  639. X        int        j;
  640. X        double    alpha     = 0.0;
  641. X        double    angle;
  642. X        double    delta;
  643. X        double    x0, y0;
  644. X        double    a,  b;
  645. X        double    x,  y;
  646. X
  647. X        set_style(e->style, e->style_val);
  648. X        set_width(e->thickness);
  649. X        set_color(e->color);
  650. X
  651. X        a         = e->radiuses.x/ppi;
  652. X        b         = e->radiuses.y/ppi;
  653. X        x0         = e->center.x/ppi;
  654. X        y0         = e->center.y/ppi;
  655. X        angle     = (flipped ? -e->angle: e->angle);
  656. X        delta     = (flipped ? -DELTA: DELTA);
  657. X
  658. X        x         = x0 + cos(angle)*a;
  659. X        y         = y0 + sin(angle)*a;
  660. X        fprintf(tfp, "PA%.4f,%.4f;PM;PD;\n", x, y);
  661. X        for (j = 1; j <= 72; j++) { alpha     = j*delta;
  662. X        x     = x0 + cos(angle)*a*cos(alpha)
  663. X                 - sin(angle)*b*sin(alpha);
  664. X        y     = y0 + sin(angle)*a*cos(alpha)
  665. X                 + cos(angle)*b*sin(alpha);
  666. X        fprintf(tfp, "PA%.4f,%.4f;\n", x, y);
  667. X        }
  668. X        fprintf(tfp, "PU;PM2;\n");
  669. X
  670. X        if (e->thickness != 0)
  671. X        fprintf(tfp, "EP;\n");
  672. X
  673. X        if (1 < e->area_fill && e->area_fill <= patterns)
  674. X        fill_polygon((int)e->area_fill);
  675. X        }
  676. X    }
  677. X
  678. Xvoid swap(i, j)
  679. Xint    *i, *j;
  680. X{    int    t; t = *i; *i = *j; *j = t; }
  681. X
  682. Xvoid genibmgl_line(l)
  683. XF_line    *l;
  684. X{
  685. X    if (l->thickness != 0 ||
  686. X        ibmgec && 1 <= l->area_fill && l->area_fill <= patterns) {
  687. X        F_point    *p, *q;
  688. X
  689. X        set_style(l->style, l->style_val);
  690. X        set_width(l->thickness);
  691. X        set_color(l->color);
  692. X
  693. X        p     = l->points;
  694. X        q     = p->next;
  695. X
  696. X        switch (l->type) {
  697. X        case    T_POLYLINE:
  698. X        case    T_BOX:
  699. X        case    T_POLYGON:
  700. X            if (q == NULL)        /* A single point line */
  701. X            fprintf(tfp, "PA%.4f,%.4f;PD;PU;\n",
  702. X                p->x/ppi, p->y/ppi);
  703. X            else {
  704. X            if (l->thickness != 0 && l->back_arrow)
  705. X                draw_arrow_head(q->x/ppi, q->y/ppi,
  706. X                        p->x/ppi, p->y/ppi,
  707. X                    l->back_arrow->ht/ppi,
  708. X                    l->back_arrow->wid/ppi);
  709. X
  710. X            fprintf(tfp, "PA%.4f,%.4f;PM;PD%.4f,%.4f;\n",
  711. X                p->x/ppi, p->y/ppi,
  712. X                q->x/ppi, q->y/ppi);
  713. X            while (q->next != NULL) {
  714. X                p     = q;
  715. X                q     = q->next;
  716. X                fprintf(tfp, "PA%.4f,%.4f;\n",
  717. X                    q->x/ppi, q->y/ppi);
  718. X                }
  719. X            fprintf(tfp, "PU;PM2;\n");
  720. X
  721. X            if (l->thickness != 0)
  722. X                fprintf(tfp, "EP;\n");
  723. X
  724. X            if (l->thickness != 0 && l->for_arrow)
  725. X                    draw_arrow_head(p->x/ppi, p->y/ppi,
  726. X                    q->x/ppi, q->y/ppi,
  727. X                    l->for_arrow->ht/ppi,
  728. X                    l->for_arrow->wid/ppi);
  729. X
  730. X            if (1 < l->area_fill && l->area_fill <= patterns)
  731. X                fill_polygon((int)l->area_fill);
  732. X            }
  733. X            break;
  734. X
  735. X        case    T_ARC_BOX: {
  736. X            int        llx, lly, urx, ury;
  737. X            double     x0,  y0,  x1,  y1;
  738. X            double    dx, dy, angle;
  739. X
  740. X            llx     = urx    = p->x;
  741. X            lly     = ury    = p->y;
  742. X            while ((p = p->next) != NULL) {
  743. X            if (llx > p->x)
  744. X                llx = p->x;
  745. X            if (urx < p->x)
  746. X                urx = p->x;
  747. X            if (lly > p->y)
  748. X                lly = p->y;
  749. X            if (ury < p->y)
  750. X                ury = p->y;
  751. X            }
  752. X
  753. X            x0     = llx/ppi;
  754. X            x1     = urx/ppi;
  755. X            dx     = l->radius/ppi;
  756. X            if (flipped) {
  757. X            y0     = ury/ppi;
  758. X            y1     = lly/ppi;
  759. X            dy     = -dx;
  760. X            angle     = -M_PI/2.0;
  761. X            }
  762. X            else {
  763. X            y0     = lly/ppi;
  764. X            y1     = ury/ppi;
  765. X            dy     =  dx;
  766. X            angle     =  M_PI/2.0;
  767. X            }
  768. X
  769. X            fprintf(tfp, "PA%.4f,%.4f;PM;PD;\n",  x0, y0 + dy);
  770. X            arc(x0, y0 + dy, x0 + dx, y0 + dy, angle, DELTA);
  771. X            fprintf(tfp, "PA%.4f,%.4f;\n", x1 - dx, y0);
  772. X            arc(x1 - dx, y0, x1 - dx, y0 + dy, angle, DELTA);
  773. X            fprintf(tfp, "PA%.4f,%.4f;\n", x1, y1 - dy);
  774. X            arc(x1, y1 - dy, x1 - dx, y1 - dy, angle, DELTA);
  775. X            fprintf(tfp, "PA%.4f,%.4f;\n", x0 + dx, y1);
  776. X            arc(x0 + dx, y1, x0 + dx, y1 - dy, angle, DELTA);
  777. X            fprintf(tfp, "PA%.4f,%.4f;PU;PM2;\n", x0, y0 + dy);
  778. X
  779. X            if (l->thickness != 0)
  780. X            fprintf(tfp, "EP;\n");
  781. X
  782. X            if (1 < l->area_fill && l->area_fill <= patterns)
  783. X            fill_polygon((int)l->area_fill);
  784. X            }
  785. X            break;
  786. X
  787. X        case    T_EPS_BOX:
  788. X            break;
  789. X        }
  790. X        }
  791. X    }
  792. X
  793. X#define        THRESHOLD    .05    /* inch */
  794. X
  795. Xstatic bezier_spline(a0, b0, a1, b1, a2, b2, a3, b3)
  796. Xdouble    a0, b0, a1, b1, a2, b2, a3, b3;
  797. X{
  798. X    double    x0, y0, x3, y3;
  799. X    double    sx1, sy1, sx2, sy2, tx, ty, tx1, ty1, tx2, ty2, xmid, ymid;
  800. X
  801. X    x0 = a0; y0 = b0;
  802. X    x3 = a3; y3 = b3;
  803. X    if (fabs(x0 - x3) < THRESHOLD && fabs(y0 - y3) < THRESHOLD)
  804. X        fprintf(tfp, "PA%.4f,%.4f;\n", x3, y3);
  805. X
  806. X    else {
  807. X        tx   = (a1  + a2 )/2.0;    ty   = (b1  + b2 )/2.0;
  808. X        sx1  = (x0  + a1 )/2.0;    sy1  = (y0  + b1 )/2.0;
  809. X        sx2  = (sx1 + tx )/2.0;    sy2  = (sy1 + ty )/2.0;
  810. X        tx2  = (a2  + x3 )/2.0;    ty2  = (b2  + y3 )/2.0;
  811. X        tx1  = (tx2 + tx )/2.0;    ty1  = (ty2 + ty )/2.0;
  812. X        xmid = (sx2 + tx1)/2.0;    ymid = (sy2 + ty1)/2.0;
  813. X
  814. X        bezier_spline(x0, y0, sx1, sy1, sx2, sy2, xmid, ymid);
  815. X        bezier_spline(xmid, ymid, tx1, ty1, tx2, ty2, x3, y3);
  816. X        }
  817. X    }
  818. X
  819. Xstatic void genibmgl_itp_spline(s)
  820. XF_spline    *s;
  821. X{
  822. X    F_point        *p1, *p2;
  823. X    F_control    *cp1, *cp2;
  824. X    double        x1, x2, y1, y2;
  825. X
  826. X    p1 = s->points;
  827. X    cp1 = s->controls;
  828. X    x2 = p1->x/ppi; y2 = p1->y/ppi;
  829. X
  830. X    if (s->thickness != 0 && s->back_arrow)
  831. X        draw_arrow_head(cp1->rx/ppi, cp1->ry/ppi, x2, y2,
  832. X            s->back_arrow->ht/ppi, s->back_arrow->wid/ppi);
  833. X
  834. X    fprintf(tfp, "PA%.4f,%.4f;PD;\n", x2, y2);
  835. X    for (p2 = p1->next, cp2 = cp1->next; p2 != NULL;
  836. X        p1 = p2, cp1 = cp2, p2 = p2->next, cp2 = cp2->next) {
  837. X        x1     = x2;
  838. X        y1     = y2;
  839. X        x2     = p2->x/ppi;
  840. X        y2     = p2->y/ppi;
  841. X        bezier_spline(x1, y1, (double)cp1->rx/ppi, cp1->ry/ppi,
  842. X        (double)cp2->lx/ppi, cp2->ly/ppi, x2, y2);
  843. X        }
  844. X    fprintf(tfp, "PU;\n");
  845. X
  846. X    if (s->thickness != 0 && s->for_arrow)
  847. X        draw_arrow_head(cp1->lx/ppi, cp1->ly/ppi, x2, y2,
  848. X            s->for_arrow->ht/ppi, s->for_arrow->wid/ppi);
  849. X    }
  850. X
  851. Xstatic quadratic_spline(a1, b1, a2, b2, a3, b3, a4, b4)
  852. Xdouble    a1, b1, a2, b2, a3, b3, a4, b4;
  853. X{
  854. X    double    x1, y1, x4, y4;
  855. X    double    xmid, ymid;
  856. X
  857. X    x1     = a1; y1 = b1;
  858. X    x4     = a4; y4 = b4;
  859. X    xmid     = (a2 + a3)/2.0;
  860. X    ymid     = (b2 + b3)/2.0;
  861. X    if (fabs(x1 - xmid) < THRESHOLD && fabs(y1 - ymid) < THRESHOLD)
  862. X        fprintf(tfp, "PA%.4f,%.4f;\n", xmid, ymid);
  863. X    else {
  864. X        quadratic_spline(x1, y1, ((x1+a2)/2.0), ((y1+b2)/2.0),
  865. X        ((3.0*a2+a3)/4.0), ((3.0*b2+b3)/4.0), xmid, ymid);
  866. X        }
  867. X
  868. X    if (fabs(xmid - x4) < THRESHOLD && fabs(ymid - y4) < THRESHOLD)
  869. X        fprintf(tfp, "PA%.4f,%.4f;\n", x4, y4);
  870. X    else {
  871. X        quadratic_spline(xmid, ymid, ((a2+3.0*a3)/4.0), ((b2+3.0*b3)/4.0),
  872. X            ((a3+x4)/2.0), ((b3+y4)/2.0), x4, y4);
  873. X        }
  874. X    }
  875. X
  876. Xstatic void genibmgl_ctl_spline(s)
  877. XF_spline    *s;
  878. X{
  879. X    F_point    *p;
  880. X    double    cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4;
  881. X    double    x1, y1, x2, y2;
  882. X
  883. X    p     = s->points;
  884. X    x1     = p->x/ppi;
  885. X    y1     = p->y/ppi;
  886. X    p     = p->next;
  887. X    x2     = p->x/ppi;
  888. X    y2     = p->y/ppi;
  889. X    cx1     = (x1 + x2)/2.0;
  890. X    cy1     = (y1 + y2)/2.0;
  891. X    cx2     = (x1 + 3.0*x2)/4.0;
  892. X    cy2     = (y1 + 3.0*y2)/4.0;
  893. X
  894. X    if (closed_spline(s))
  895. X        fprintf(tfp, "PA%.4f,%.4f;PD;\n ", cx1, cy1);
  896. X    else {
  897. X        if (s->thickness != 0 && s->back_arrow)
  898. X        draw_arrow_head(cx1, cy1, x1, y1,
  899. X            s->back_arrow->ht/ppi, s->back_arrow->wid/ppi);
  900. X        fprintf(tfp, "PA%.4f,%.4f;PD%.4f,%.4f;\n",
  901. X            x1, y1, cx1, cy1);
  902. X        }
  903. X
  904. X    for (p = p->next; p != NULL; p = p->next) {
  905. X        x1     = x2;
  906. X        y1     = y2;
  907. X        x2     = p->x/ppi;
  908. X        y2     = p->y/ppi;
  909. X        cx3     = (3.0*x1 + x2)/4.0;
  910. X        cy3     = (3.0*y1 + y2)/4.0;
  911. X        cx4     = (x1 + x2)/2.0;
  912. X        cy4     = (y1 + y2)/2.0;
  913. X        quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4);
  914. X        cx1     = cx4;
  915. X        cy1     = cy4;
  916. X        cx2     = (x1 + 3.0*x2)/4.0;
  917. X        cy2     = (y1 + 3.0*y2)/4.0;
  918. X        }
  919. X    x1     = x2; 
  920. X    y1     = y2;
  921. X    p     = s->points->next;
  922. X    x2     = p->x/ppi;
  923. X    y2     = p->y/ppi;
  924. X    cx3     = (3.0*x1 + x2)/4.0;
  925. X    cy3     = (3.0*y1 + y2)/4.0;
  926. X    cx4     = (x1 + x2)/2.0;
  927. X    cy4     = (y1 + y2)/2.0;
  928. X    if (closed_spline(s)) {
  929. X        quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4);
  930. X        fprintf(tfp, "PU;\n");
  931. X        }
  932. X    else {
  933. X        fprintf(tfp, "PA%.4f,%.4f;PU;\n", x1, y1);
  934. X        if (s->thickness != 0 && s->for_arrow)
  935. X            draw_arrow_head(cx1, cy1, x1, y1,
  936. X            s->for_arrow->ht/ppi, s->for_arrow->wid/ppi);
  937. X        }
  938. X    }
  939. X
  940. Xvoid genibmgl_spline(s)
  941. XF_spline    *s;
  942. X{
  943. X    if (s->thickness != 0) {
  944. X        set_style(s->style, s->style_val);
  945. X        set_width(s->thickness);
  946. X        set_color(s->color);
  947. X
  948. X        if (int_spline(s))
  949. X        genibmgl_itp_spline(s);
  950. X        else
  951. X        genibmgl_ctl_spline(s);
  952. X
  953. X        }
  954. X    if (1 < s->area_fill && s->area_fill <= patterns)
  955. X        fprintf(stderr, "Spline area fill not implemented\n");
  956. X}
  957. X
  958. X#define    FONT(T) ((-1 < (T) && (T) < fonts) ? (T): fonts)
  959. Xvoid genibmgl_text(t)
  960. XF_text    *t;
  961. X{
  962. Xstatic    int    font     = DEFAULT;    /* font                */
  963. Xstatic    int    size     = DEFAULT;    /* font size        in points    */
  964. Xstatic    int    rigid     = 0;        /* rigid text            */
  965. Xstatic    int    cs     = 0;        /* standard  character set    */
  966. Xstatic    int    ca     = 0;        /* alternate character set    */
  967. Xstatic    double    theta     = 0.0;        /* character slant  in degrees    */
  968. Xstatic    double    angle     = 0.0;        /* label direction  in radians    */
  969. X    double    width;            /* character width  in centimeters */
  970. X    double    height;            /* character height in centimeters */
  971. X
  972. X    if (font != FONT(t->font)) {
  973. X        font  = FONT(t->font);
  974. X        if (cs != standard[font]) {
  975. X        cs  = standard[font];
  976. X        fprintf(tfp, "CS%d;", cs);
  977. X        }
  978. X        if (ca != alternate[font]) {
  979. X        ca  = alternate[font];
  980. X        fprintf(tfp, "CA%d;", ca);
  981. X        }
  982. X        if (theta != slant[font]) {
  983. X        theta  = slant[font];
  984. X        fprintf(tfp, "SL%.4f;", tan(theta*M_PI/180.0));
  985. X        }
  986. X        }
  987. X    if (size != t->size || rigid != t->flags&RIGID_TEXT) {
  988. X        size  = t->size ? t->size: font_size;
  989. X        rigid  = (t->flags&RIGID_TEXT);
  990. X        width     = size*wcmpp*wide[font];
  991. X        height     = size*hcmpp*high[font];
  992. X        rigid     = (t->flags&RIGID_TEXT);
  993. X        if (rigid)
  994. X        fprintf(tfp, "SI%.4f,%.4f;", width, height);
  995. X        else
  996. X        fprintf(tfp, "SI%.4f,%.4f;", width*mag, height*mag);
  997. X        }
  998. X    if (angle != t->angle) {
  999. X        angle  = t->angle;
  1000. X        fprintf(tfp, "DI%.4f,%.4f;",
  1001. X            cos(angle), sin(reflected ? -angle: angle));
  1002. X        }
  1003. X    set_color(t->color);
  1004. X
  1005. X    fprintf(tfp, "PA%.4f,%.4f;\n",
  1006. X        t->base_x/ppi, t->base_y/ppi);
  1007. X
  1008. X    switch (t->type) {
  1009. X        case DEFAULT:
  1010. X        case T_LEFT_JUSTIFIED:
  1011. X        break;
  1012. X        case T_CENTER_JUSTIFIED:
  1013. X        fprintf(tfp, "CP%.4f,0.0;", -(double)(strlen(t->cstring)/2.0));
  1014. X        break;
  1015. X        case T_RIGHT_JUSTIFIED:
  1016. X        fprintf(tfp, "CP%.4f,0.0;", -(double)(strlen(t->cstring)));
  1017. X        break;
  1018. X        default:
  1019. X        fprintf(stderr, "unknown text position type\n");
  1020. X        exit(1);
  1021. X        }    
  1022. X
  1023. X    fprintf(tfp, "LB%s\003\n", t->cstring);
  1024. X    }
  1025. X
  1026. Xvoid genibmgl_end()
  1027. X{
  1028. X    /* IBMGL ending */
  1029. X    fprintf(tfp, "PU;SP;IN;\n");
  1030. X}
  1031. X
  1032. Xstruct driver dev_ibmgl = {
  1033. X         genibmgl_option,
  1034. X    genibmgl_start,
  1035. X    genibmgl_arc,
  1036. X    genibmgl_ellipse,
  1037. X    genibmgl_line,
  1038. X    genibmgl_spline,
  1039. X    genibmgl_text,
  1040. X    genibmgl_end,
  1041. X    EXCLUDE_TEXT
  1042. X    };
  1043. END_OF_FILE
  1044. if test 26109 -ne `wc -c <'fig2dev/dev/genibmgl.c'`; then
  1045.     echo shar: \"'fig2dev/dev/genibmgl.c'\" unpacked with wrong size!
  1046. fi
  1047. # end of 'fig2dev/dev/genibmgl.c'
  1048. fi
  1049. if test -f 'fig2dev/dev/genpictex.c' -a "${1}" != "-c" ; then 
  1050.   echo shar: Will not clobber existing file \"'fig2dev/dev/genpictex.c'\"
  1051. else
  1052. echo shar: Extracting \"'fig2dev/dev/genpictex.c'\" \(25452 characters\)
  1053. sed "s/^X//" >'fig2dev/dev/genpictex.c' <<'END_OF_FILE'
  1054. X/*
  1055. X * TransFig: Facility for Translating Fig code
  1056. X * Copyright (c) 1985 Supoj Sutantavibul
  1057. X * Copyright (c) 1991 Micah Beck
  1058. X *
  1059. X * Permission to use, copy, modify, distribute, and sell this software and its
  1060. X * documentation for any purpose is hereby granted without fee, provided that
  1061. X * the above copyright notice appear in all copies and that both that
  1062. X * copyright notice and this permission notice appear in supporting
  1063. X * documentation. The authors make no representations about the suitability 
  1064. X * of this software for any purpose.  It is provided "as is" without express 
  1065. X * or implied warranty.
  1066. X *
  1067. X * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  1068. X * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  1069. X * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  1070. X * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  1071. X * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  1072. X * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  1073. X * PERFORMANCE OF THIS SOFTWARE.
  1074. X *
  1075. X */
  1076. X
  1077. X/* 
  1078. X *    genpictex.C : PiCTeX driver for fig2dev
  1079. X *
  1080. X *     Author Micah Beck, Cornell University, 4/88
  1081. X *    Color, rotated text and ISO-chars added by Herbert Bauer 11/91
  1082. X*/
  1083. X#if defined(hpux) || defined(SYSV)
  1084. X#include <sys/types.h>
  1085. X#endif
  1086. X#include <sys/file.h>
  1087. X#include <stdio.h>
  1088. X#include <math.h>
  1089. X#include "pi.h"
  1090. X#include "object.h"
  1091. X#include "fig2dev.h"
  1092. X#include "texfonts.h"
  1093. X
  1094. X#define UNIT "cm"       /* dip */
  1095. X#define CONVUNIT 2.54   /* dip */
  1096. X
  1097. X#ifndef fabs
  1098. Xextern double fabs();
  1099. X#endif
  1100. X#ifndef sin
  1101. Xextern double sin();
  1102. X#endif
  1103. X#ifndef cos
  1104. Xextern double cos();
  1105. X#endif
  1106. X#ifndef acos
  1107. Xextern double acos();
  1108. X#endif
  1109. Xextern char *ISOtoTeX[];
  1110. X
  1111. Xvoid genpictex_ctl_spline(), genpictex_itp_spline();
  1112. X
  1113. Xstatic int        coord_system;
  1114. Xstatic double        dash_length = -1;
  1115. Xstatic int        line_style = SOLID_LINE;
  1116. Xstatic char         *linethick = "1pt";
  1117. Xstatic char        *plotsymbol = "\\makebox(0,0)[l]{\\tencirc\\symbol{'160}}";
  1118. Xstatic int        cur_thickness = -1;
  1119. X
  1120. Xstatic void genpictex_option(opt, optarg)
  1121. Xchar opt, *optarg;
  1122. X{
  1123. X        int i;
  1124. X
  1125. X    switch (opt) {
  1126. X
  1127. X        case 'a':
  1128. X            fprintf(stderr, "warning: pictex option -a obsolete\n");
  1129. X            break;
  1130. X
  1131. X        case 'f':            /* set default text font */
  1132. X            for ( i = 1; i <= MAX_FONT; i++ )
  1133. X            if ( !strcmp(optarg, texfontnames[i]) ) break;
  1134. X
  1135. X            if ( i > MAX_FONT)
  1136. X            fprintf(stderr,
  1137. X            "warning: non-standard font name %s\n", optarg);
  1138. X        
  1139. X            texfontnames[0] = texfontnames[1] = optarg;
  1140. X            break;
  1141. X
  1142. X        case 'l':            /* set line thickness */
  1143. X            linethick = optarg;
  1144. X            break;
  1145. X
  1146. X        case 'p':            /* set plot symbol */
  1147. X            plotsymbol = optarg;
  1148. X            break;
  1149. X
  1150. X        case 's':
  1151. X            if (font_size <= 0 || font_size > MAXFONTSIZE) {
  1152. X            fprintf(stderr,
  1153. X                "warning: font size %d out of bounds\n", font_size);
  1154. X            }
  1155. X            break;
  1156. X
  1157. X        case 'm':
  1158. X        case 'L':
  1159. X            break;
  1160. X
  1161. X    default:
  1162. X        put_msg(Err_badarg, opt, "pictex");
  1163. X        exit(1);
  1164. X        break;
  1165. X    }
  1166. X}
  1167. X
  1168. X#define            TOP    10.5    /* top of page is 10.5 inch */
  1169. Xstatic double        ppi;
  1170. Xstatic int        CONV = 0;
  1171. X
  1172. Xstatic double convy(a)
  1173. Xdouble    a;
  1174. X{
  1175. X    return((double)(CONV ? TOP-a : a));
  1176. X}
  1177. X
  1178. Xvoid genpictex_start(objects)
  1179. XF_compound    *objects;
  1180. X{
  1181. X    texfontsizes[0] = texfontsizes[1] = TEXFONTSIZE(font_size);
  1182. X
  1183. X    coord_system = objects->nwcorner.y;
  1184. X    ppi = objects->nwcorner.x;
  1185. X    if (coord_system == 2) CONV = 1;
  1186. X
  1187. X    /* PiCTeX start */
  1188. X    fprintf(tfp, "\\font\\thinlinefont=cmr5\n");
  1189. X    define_setfigfont(tfp);
  1190. X    fprintf(tfp, "\\mbox{\\beginpicture\n");
  1191. X    fprintf(tfp, "\\setcoordinatesystem units <%6.3f%s,%6.3f%s>\n",
  1192. X            mag, UNIT, mag, UNIT);
  1193. X    fprintf(tfp, "\\unitlength=%6.3f%s\n", mag, UNIT);
  1194. X    fprintf(tfp, "\\linethickness=%s\n", linethick);
  1195. X    fprintf(tfp, "\\setplotsymbol ({%s})\n", plotsymbol);
  1196. X    fprintf(tfp, "\\setshadesymbol ({\\thinlinefont .})\n");
  1197. X    fprintf(tfp, "\\setlinear\n");
  1198. X}
  1199. X
  1200. Xvoid genpictex_end()
  1201. X{
  1202. X    /* PiCTeX ending */
  1203. X    fprintf(tfp, "\\linethickness=0pt\n");
  1204. X        fprintf(tfp, "\\putrectangle corners at %6.3f %6.3f and %6.3f %6.3f\n",
  1205. X        (llx/ppi)*CONVUNIT, (convy(lly/ppi))*CONVUNIT, (urx/ppi)*CONVUNIT, (convy(ury/ppi))*CONVUNIT);
  1206. X    fprintf(tfp, "\\endpicture}\n");
  1207. X}
  1208. X
  1209. Xstatic set_linewidth(w)
  1210. Xint    w;
  1211. X{
  1212. X/*    static int    cur_thickness = -1;*/
  1213. X
  1214. X/*    if (w == 0) return;*/
  1215. X/*    if (w != cur_thickness) {*/
  1216. X        if (!w) {
  1217. X        fprintf(tfp, "\\linethickness=0pt\n");
  1218. X        cur_thickness = 0;
  1219. X        }
  1220. X        else {
  1221. X        cur_thickness = round(w*mag);
  1222. X
  1223. X        if (!cur_thickness || cur_thickness == 1) {
  1224. X            cur_thickness = 1;
  1225. X            fprintf(tfp, "\\linethickness=%6.3fpt\n", 0.5*cur_thickness);
  1226. X            }
  1227. X        else {
  1228. X            fprintf(tfp, "\\linethickness=%dpt\n", cur_thickness-1);
  1229. X            }
  1230. X        }
  1231. X        switch (cur_thickness) {
  1232. X            case 0:
  1233. X                        fprintf(tfp, "\\setplotsymbol ({%s})\n", "\\thinlinefont \\ ");
  1234. X                break;
  1235. X            case 1:
  1236. X                        fprintf(tfp, "\\setplotsymbol ({%s})\n", "\\thinlinefont .");
  1237. X                break;
  1238. X            case 2:
  1239. X                        fprintf(tfp, "\\setplotsymbol ({%s})\n", "\\makebox(0,0)[l]{\\tencirc\\symbol{'160}}");
  1240. X                break;
  1241. X            case 3:
  1242. X                        fprintf(tfp, "\\setplotsymbol ({%s})\n", "\\makebox(0,0)[l]{\\tencirc\\symbol{'161}}");
  1243. X                break;
  1244. X            case 4:
  1245. X                        fprintf(tfp, "\\setplotsymbol ({%s})\n", "\\makebox(0,0)[l]{\\tencirc\\symbol{'162}}");
  1246. X                break;
  1247. X            case 5:
  1248. X                        fprintf(tfp, "\\setplotsymbol ({%s})\n", "\\makebox(0,0)[l]{\\tencirc\\symbol{'163}}");
  1249. X                break;
  1250. X            case 6:
  1251. X                        fprintf(tfp, "\\setplotsymbol ({%s})\n", "\\makebox(0,0)[l]{\\tencirc\\symbol{'164}}");
  1252. X                break;
  1253. X            case 7:
  1254. X                        fprintf(tfp, "\\setplotsymbol ({%s})\n", "\\makebox(0,0)[l]{\\tencirc\\symbol{'165}}");
  1255. X                break;
  1256. X            case 8:
  1257. X                        fprintf(tfp, "\\setplotsymbol ({%s})\n", "\\makebox(0,0)[l]{\\tencirc\\symbol{'166}}");
  1258. X                break;
  1259. X            case 9:
  1260. X                        fprintf(tfp, "\\setplotsymbol ({%s})\n", "\\makebox(0,0)[l]{\\tencirc\\symbol{'167}}");
  1261. X                break;
  1262. X            case 10:
  1263. X                        fprintf(tfp, "\\setplotsymbol ({%s})\n", "\\makebox(0,0)[l]{\\tencirc\\symbol{'170}}");
  1264. X                break;
  1265. X            case 11:
  1266. X                        fprintf(tfp, "\\setplotsymbol ({%s})\n", "\\makebox(0,0)[l]{\\tencirc\\symbol{'171}}");
  1267. X                break;
  1268. X            case 12:
  1269. X                        fprintf(tfp, "\\setplotsymbol ({%s})\n", "\\makebox(0,0)[l]{\\tencirc\\symbol{'172}}");
  1270. X                break;
  1271. X            case 13:
  1272. X                        fprintf(tfp, "\\setplotsymbol ({%s})\n", "\\makebox(0,0)[l]{\\tencirc\\symbol{'173}}");
  1273. X                break;
  1274. X            case 14:
  1275. X                        fprintf(tfp, "\\setplotsymbol ({%s})\n", "\\makebox(0,0)[l]{\\tencirc\\symbol{'174}}");
  1276. X                break;
  1277. X            case 15:
  1278. X                        fprintf(tfp, "\\setplotsymbol ({%s})\n", "\\makebox(0,0)[l]{\\tencirc\\symbol{'175}}");
  1279. X                break;
  1280. X            case 16:
  1281. X                        fprintf(tfp, "\\setplotsymbol ({%s})\n", "\\makebox(0,0)[l]{\\tencirc\\symbol{'176}}");
  1282. X                break;
  1283. X            default:
  1284. X                fprintf(tfp, "\\setplotsymbol ({%s})\n", "\\makebox(0,0)[l]{\\tencirc\\symbol{'176}}");
  1285. X                break;
  1286. X        }
  1287. X/* PIC  fprintf(tfp, "\"D't %.3fi'\"\n", 0.7 * cur_thickness);*/
  1288. X/*    }*/
  1289. X}
  1290. X
  1291. Xvoid genpictex_line(l)
  1292. XF_line    *l;
  1293. X{
  1294. X    F_point        *p, *q;
  1295. X    int        x, y, llx, lly, urx, ury;
  1296. X
  1297. X    fprintf(tfp, "%%\n%% Fig POLYLINE object\n%%\n");
  1298. X
  1299. X    if (l->type == T_ARC_BOX) { /* A box with rounded corners */
  1300. X      fprintf(stderr, "Arc box not implemented; substituting box.\n");
  1301. X      l->type = T_BOX;
  1302. X    }
  1303. X
  1304. X    set_linewidth(l->thickness);
  1305. X    set_style(l->style, l->style_val);
  1306. X    set_color(l->color);
  1307. X
  1308. X    p = l->points;
  1309. X    q = p->next;
  1310. X
  1311. X    if (q == NULL) { /* A single point line */
  1312. X        fprintf(tfp, "\\plot %6.3f %6.3f %6.3f %6.3f /\n",
  1313. X            (p->x/ppi)*CONVUNIT, (convy(p->y/ppi))*CONVUNIT, (p->x/ppi)*CONVUNIT, (convy(p->y/ppi))*CONVUNIT);
  1314. X        return;
  1315. X        }
  1316. X
  1317. X    if (l->type == T_BOX || l->type == T_ARC_BOX) /* A (rounded corner) box */
  1318. X    {
  1319. X        x = p->x; y=p->y;
  1320. X        llx =urx = x;
  1321. X        lly =ury = y;
  1322. X        while ( q!= NULL )
  1323. X        {
  1324. X        x = q->x; y=q->y;
  1325. X        if (x < llx) llx = x;
  1326. X        if (y < lly) lly = y;
  1327. X        if (x > urx) urx = x;
  1328. X        if (y > ury) ury = y;
  1329. X        q = q->next;
  1330. X        }
  1331. X        put_box (llx, lly, urx, ury, l);
  1332. X        return; 
  1333. X    }
  1334. X
  1335. X    if (l->back_arrow)
  1336. X        draw_arrow_head(q->x/ppi, convy(q->y/ppi), p->x/ppi,
  1337. X        convy(p->y/ppi), l->back_arrow->ht/ppi, l->back_arrow->wid/ppi);
  1338. X    set_style(l->style, l->style_val);
  1339. X
  1340. X    while (q->next != NULL) {
  1341. X
  1342. X        putline(p->x, p->y, (double) q->x, (double) q->y,
  1343. X            (q->next)->x, (q->next)->y, -1, -1, -1, -1);
  1344. X        p = q;
  1345. X        q = q->next;
  1346. X        }
  1347. X
  1348. X    putline(p->x, p->y, (double) q->x, (double) q->y, -1, -1,
  1349. X        l->points->x, l->points->y,
  1350. X        l->points->next->x,l->points->next->y);
  1351. X    if (l->for_arrow)
  1352. X        draw_arrow_head(p->x/ppi, convy(p->y/ppi), q->x/ppi,
  1353. X        convy(q->y/ppi), l->for_arrow->ht/ppi, l->for_arrow->wid/ppi);
  1354. X
  1355. X    if (l->area_fill && (int)l->area_fill != DEFAULT)
  1356. X        fprintf(stderr, "Line area fill not implemented\n");
  1357. X    reset_color(l->color);
  1358. X    }
  1359. X
  1360. X
  1361. X/*
  1362. X * draw box
  1363. X */
  1364. Xstatic put_box (llx, lly, urx, ury, l)
  1365. Xint    llx, lly, urx, ury;
  1366. XF_line    *l;
  1367. X{
  1368. X    int radius;
  1369. X
  1370. X    set_color(l->color);
  1371. X    if (l->type == T_BOX)
  1372. X    {
  1373. X       if (l->area_fill && l->area_fill == BLACK_FILL)
  1374. X       {
  1375. X           fprintf(tfp,"\\linethickness=%6.3f%s\n", 
  1376. X               ((convy(lly/ppi))-(convy(ury/ppi)))*CONVUNIT*mag, UNIT);
  1377. X           fprintf(tfp,"{\\setsolid"); 
  1378. X           fprintf(tfp,"\\putrule from %6.3f %6.3f to %6.3f %6.3f }%%\n",
  1379. X               (llx/ppi)*CONVUNIT,
  1380. X               ((convy(lly/ppi)+convy(ury/ppi))/2)*CONVUNIT,
  1381. X               (urx/ppi)*CONVUNIT,
  1382. X               ((convy(lly/ppi)+convy(ury/ppi))/2)*CONVUNIT);
  1383. X           fprintf(tfp,"\\linethickness=%dpt\n", l->thickness);
  1384. X       }
  1385. X       else if (l->area_fill && l->area_fill > 15)
  1386. X       {
  1387. X           fprintf(tfp,"\\setshadegrid span <1pt>\n");
  1388. X           fprintf(tfp,"\\shaderectangleson\n");
  1389. X       }
  1390. X       else if (l->area_fill && l->area_fill > 10)
  1391. X       {
  1392. X           fprintf(tfp,"\\setshadegrid span <2pt>\n");
  1393. X           fprintf(tfp,"\\shaderectangleson\n");
  1394. X       }
  1395. X       else if (l->area_fill && l->area_fill > 5)
  1396. X       {
  1397. X           fprintf(tfp,"\\setshadegrid span <4pt>\n");
  1398. X           fprintf(tfp,"\\shaderectangleson\n");
  1399. X       }
  1400. X       else if (l->area_fill && l->area_fill == WHITE_FILL)
  1401. X       {
  1402. X           fprintf(stderr,"WHITE_FILL not implemeted for boxes\n");
  1403. X       }
  1404. X
  1405. X       fprintf(tfp,"\\putrectangle corners at %6.3f %6.3f and %6.3f %6.3f\n",
  1406. X           (llx/ppi)*CONVUNIT, (convy(lly/ppi))*CONVUNIT,
  1407. X           (urx/ppi)*CONVUNIT, (convy(ury/ppi))*CONVUNIT);
  1408. X
  1409. X       if (l->area_fill
  1410. X        && l->area_fill != WHITE_FILL && l->area_fill != BLACK_FILL)
  1411. X       {
  1412. X           fprintf(tfp,"\\setshadegrid span <5pt>\n");
  1413. X           fprintf(tfp,"\\shaderectanglesoff\n");
  1414. X       }
  1415. X    }
  1416. X    else if (l->type == T_ARC_BOX)
  1417. X    {
  1418. X       radius = l->radius;
  1419. X
  1420. X       if (l->area_fill)
  1421. X       {
  1422. X           fprintf(stderr,"area fill not implemeted for rounded corner boxes\n");
  1423. X       }
  1424. X
  1425. X       fprintf(tfp,"\\putrule from %6.3f %6.3f to %6.3f %6.3f\n",
  1426. X           ((llx+radius)/ppi)*CONVUNIT, (convy(lly/ppi))*CONVUNIT,
  1427. X           ((urx-radius)/ppi)*CONVUNIT, (convy(lly/ppi))*CONVUNIT);
  1428. X       fprintf(tfp,"\\putrule from %6.3f %6.3f to %6.3f %6.3f\n",
  1429. X           (urx/ppi)*CONVUNIT, (convy((lly+radius)/ppi))*CONVUNIT,
  1430. X           (urx/ppi)*CONVUNIT, (convy((ury-radius)/ppi))*CONVUNIT);
  1431. X       fprintf(tfp,"\\putrule from %6.3f %6.3f to %6.3f %6.3f\n",
  1432. X           ((urx-radius)/ppi)*CONVUNIT, (convy(ury/ppi))*CONVUNIT,
  1433. X           ((llx+radius)/ppi)*CONVUNIT, (convy(ury/ppi))*CONVUNIT);
  1434. X       fprintf(tfp,"\\putrule from %6.3f %6.3f to %6.3f %6.3f\n",
  1435. X           (llx/ppi)*CONVUNIT, (convy((ury-radius)/ppi))*CONVUNIT,
  1436. X           (llx/ppi)*CONVUNIT, (convy((lly+radius)/ppi))*CONVUNIT);
  1437. X       fprintf(tfp,"\\circulararc -90 degrees from %6.3f %6.3f center at %6.3f %6.3f\n",
  1438. X           ((urx-radius)/ppi)*CONVUNIT, (convy(lly/ppi))*CONVUNIT,
  1439. X           ((urx-radius)/ppi)*CONVUNIT, (convy((lly+radius)/ppi))*CONVUNIT);
  1440. X       fprintf(tfp,"\\circulararc -90 degrees from %6.3f %6.3f center at %6.3f %6.3f\n",
  1441. X           (urx/ppi)*CONVUNIT, (convy((ury-radius)/ppi))*CONVUNIT,
  1442. X           ((urx-radius)/ppi)*CONVUNIT, (convy((ury-radius)/ppi))*CONVUNIT);
  1443. X       fprintf(tfp,"\\circulararc -90 degrees from %6.3f %6.3f center at %6.3f %6.3f\n",
  1444. X           ((llx+radius)/ppi)*CONVUNIT, (convy(ury/ppi))*CONVUNIT,
  1445. X           ((llx+radius)/ppi)*CONVUNIT, (convy((ury-radius)/ppi))*CONVUNIT);
  1446. X       fprintf(tfp,"\\circulararc -90 degrees from %6.3f %6.3f center at %6.3f %6.3f\n",
  1447. X           (llx/ppi)*CONVUNIT, (convy((lly+radius)/ppi))*CONVUNIT,
  1448. X           ((llx+radius)/ppi)*CONVUNIT, (convy((lly+radius)/ppi))*CONVUNIT);
  1449. X    }
  1450. X    reset_color(l->color);
  1451. X}
  1452. X
  1453. X
  1454. X
  1455. X
  1456. X
  1457. X
  1458. X
  1459. X
  1460. X
  1461. X/* 
  1462. X * set_style - issue style commands as appropriate
  1463. X */
  1464. Xstatic set_style(style, dash_len)
  1465. Xint style;
  1466. Xdouble dash_len;
  1467. X{
  1468. X    switch (style) {
  1469. X     case SOLID_LINE:
  1470. X        if (line_style == SOLID_LINE) break;
  1471. X        fprintf(tfp, "\\setsolid\n");
  1472. X        break;
  1473. X
  1474. X    case DASH_LINE:
  1475. X        if (line_style == DASH_LINE && dash_length == dash_len)
  1476. X        break;
  1477. X        fprintf(tfp, "\\setdashes <%7.4f%s>\n", (0.5*dash_len*(cur_thickness+1)/ppi)*CONVUNIT, UNIT);
  1478. X        break;
  1479. X
  1480. X    case DOTTED_LINE:
  1481. X        if (line_style == DOTTED_LINE)
  1482. X        break;
  1483. X        fprintf(tfp, "\\setdots <%7.4f%s>\n", (0.5*dash_len*(cur_thickness+1)/ppi)*CONVUNIT, UNIT);
  1484. X        break;
  1485. X        }
  1486. X
  1487. X    line_style = style;
  1488. X    dash_length = dash_len;
  1489. X    }
  1490. X
  1491. X/*
  1492. X * putline - use rules if possible
  1493. X */
  1494. Xstatic putline (start_x, start_y, end_x, end_y, next_x, next_y,
  1495. X                first_start_x, first_start_y, first_end_x, first_end_y)
  1496. Xint    start_x, start_y, next_x, next_y;
  1497. Xint    first_start_x, first_start_y, first_end_x, first_end_y;
  1498. Xdouble    end_x, end_y;
  1499. X{
  1500. X    if (line_style == SOLID_LINE &&
  1501. X        ((start_x == end_x) || (start_y == end_y))) {
  1502. X    if (next_x != -1) {
  1503. X        if (start_x == end_x && end_y == next_y) {
  1504. X        if (end_y > start_y)
  1505. X            end_y += 0.5*ppi*(cur_thickness-1)/72/mag;
  1506. X        else
  1507. X            end_y -= 0.5*ppi*(cur_thickness-1)/72/mag;
  1508. X        }
  1509. X        else if (start_y == end_y && end_x == next_x) {
  1510. X        if (end_x > start_x)
  1511. X            end_x += 0.5*ppi*(cur_thickness-1)/72/mag;
  1512. X        else
  1513. X            end_x -= 0.5*ppi*(cur_thickness-1)/72/mag;
  1514. X        }
  1515. X        }
  1516. X    else if (end_x == first_start_x && end_y == first_start_y) {
  1517. X        if (start_x == end_x && first_start_y == first_end_y) {
  1518. X        if (end_y > start_y)
  1519. X            end_y += 0.5*ppi*(cur_thickness-1)/72/mag;
  1520. X        else
  1521. X            end_y -= 0.5*ppi*(cur_thickness-1)/72/mag;
  1522. X        }
  1523. X        else if (start_y == end_y && first_start_x == first_end_x) {
  1524. X        if (end_x > start_x)
  1525. X            end_x += 0.5*ppi*(cur_thickness-1)/72/mag;
  1526. X        else
  1527. X            end_x -= 0.5*ppi*(cur_thickness-1)/72/mag;
  1528. X        }
  1529. X        }
  1530. X
  1531. X    fprintf(tfp, "\\putrule from %6.3f %6.3f to %6.3f %6.3f\n",
  1532. X        (start_x/ppi)*CONVUNIT, (convy(start_y/ppi))*CONVUNIT, (end_x/ppi)*CONVUNIT, (convy(end_y/ppi))*CONVUNIT);
  1533. X    }
  1534. X    else {
  1535. X    fprintf(tfp, "\\plot %6.3f %6.3f %6.3f %6.3f /\n",
  1536. X        (start_x/ppi)*CONVUNIT, (convy(start_y/ppi))*CONVUNIT, (end_x/ppi)*CONVUNIT, (convy(end_y/ppi))*CONVUNIT);
  1537. X    }
  1538. X}
  1539. X
  1540. X
  1541. Xvoid genpictex_spline(s)
  1542. XF_spline    *s;
  1543. X{
  1544. X    set_linewidth(s->thickness);
  1545. X    set_style(s->style, s->style_val);
  1546. X    set_color(s->color);
  1547. X
  1548. X    if (int_spline(s))
  1549. X        genpictex_itp_spline(s);
  1550. X    else
  1551. X        genpictex_ctl_spline(s);
  1552. X
  1553. X    if (s->area_fill && (int)s->area_fill != DEFAULT)
  1554. X        fprintf(stderr, "Spline area fill not implemented\n");
  1555. X    reset_color(s->color);
  1556. X}
  1557. X
  1558. X#define MAXBLACKDIAM 15 /* pt */
  1559. X
  1560. Xvoid genpictex_ellipse(e)
  1561. XF_ellipse    *e;
  1562. X{
  1563. X    fprintf(tfp, "%%\n%% Fig ELLIPSE\n%%\n");
  1564. X
  1565. X    set_linewidth(e->thickness);
  1566. X    set_style(e->style, e->style_val);
  1567. X    set_color(e->color);
  1568. X
  1569. X    if ((e->area_fill == BLACK_FILL) && (e->radiuses.x == e->radiuses.y)) {
  1570. X        if (mag*e->radiuses.x > 0.5*ppi/72*MAXBLACKDIAM)
  1571. X            fprintf(stderr, "Too big black filled circle substituted by a diameter of %dpt\n", MAXBLACKDIAM);
  1572. X         fprintf(tfp, "\\put{\\makebox(0,0)[l]{\\circle*{%6.3f}}} at %6.3f %6.3f\n",
  1573. X            (2*e->radiuses.x/ppi)*CONVUNIT,
  1574. X            ((e->center.x)/ppi)*CONVUNIT, (convy(e->center.y/ppi))*CONVUNIT);
  1575. X
  1576. X        }
  1577. X    else {
  1578. X
  1579. X        fprintf(tfp, "\\ellipticalarc axes ratio %6.3f:%-6.3f 360 degrees \n",
  1580. X            (e->radiuses.x/ppi)*CONVUNIT, (e->radiuses.y/ppi)*CONVUNIT);
  1581. X        fprintf(tfp, "\tfrom %6.3f %6.3f center at %6.3f %6.3f\n",
  1582. X            ((e->center.x+e->radiuses.x)/ppi)*CONVUNIT, (convy(e->center.y/ppi))*CONVUNIT,
  1583. X            (e->center.x/ppi)*CONVUNIT, (convy(e->center.y/ppi))*CONVUNIT);
  1584. X        if (e->area_fill && (int)e->area_fill != DEFAULT)
  1585. X            fprintf(stderr, "Ellipse area fill not implemented\n");
  1586. X        }
  1587. X    reset_color(e->color);
  1588. X    }
  1589. X
  1590. X#define            HT_OFFSET    (0.2 / 72.0)
  1591. X
  1592. Xvoid genpictex_text(t)
  1593. XF_text    *t;
  1594. X{
  1595. X    double    x, y;
  1596. X    char *tpos;
  1597. X    unsigned char *cp;
  1598. X
  1599. X        fprintf(tfp, "%%\n%% Fig TEXT object\n%%\n");
  1600. X
  1601. X    x = t->base_x/ppi;
  1602. X    y = convy(t->base_y/ppi);
  1603. X
  1604. X    switch (t->type) {
  1605. X
  1606. X        case T_LEFT_JUSTIFIED:
  1607. X        case DEFAULT:
  1608. X            tpos = "[lB]";
  1609. X        break;
  1610. X
  1611. X        case T_CENTER_JUSTIFIED:
  1612. X            tpos = "[B]";
  1613. X        break;
  1614. X
  1615. X        case T_RIGHT_JUSTIFIED:
  1616. X            tpos = "[rB]";
  1617. X        break;
  1618. X
  1619. X        default:
  1620. X        fprintf(stderr, "Text incorrectly positioned\n");
  1621. X        return;
  1622. X        }
  1623. X
  1624. X    unpsfont(t);
  1625. X        { int texsize;
  1626. X          double baselineskip;
  1627. X
  1628. X      texsize = TEXFONTMAG(t);
  1629. X      baselineskip = (texsize * 1.2);
  1630. X
  1631. X       fprintf(tfp, "\\put{\\SetFigFont{%d}{%.1f}{%s}",
  1632. X        texsize, baselineskip, TEXFONT(t->font));
  1633. X    }
  1634. X
  1635. X#ifdef DVIPS
  1636. X    if(t->angle && t->type == T_LEFT_JUSTIFIED)
  1637. X      fprintf(tfp, "\\special{ps:gsave currentpoint currentpoint translate\n-%.1f rotate neg exch neg exch translate}", t->angle*180/M_PI);
  1638. X#endif
  1639. X
  1640. X    set_color(t->color);
  1641. X
  1642. X    if (!special_text(t))
  1643. X
  1644. X        /* this loop escapes characters "$&%#_{}" */
  1645. X        /* and deleted characters "~^\" */
  1646. X        for(cp = (unsigned char*)t->cstring; *cp; cp++) {
  1647. X                  if (strchr("$&%#_{}", *cp)) (void)fputc('\\', tfp);
  1648. X                  if (strchr("~^\\", *cp))
  1649. X            fprintf(stderr,
  1650. X                "Bad character in text object '%c'\n" ,*cp);
  1651. X            else
  1652. X            (void)fputc(*cp, tfp);
  1653. X              }
  1654. X    else 
  1655. X        for(cp = (unsigned char*)t->cstring; *cp; cp++) {
  1656. X            if (*cp >= 0xa0)
  1657. X                 fprintf(tfp, "%s", ISOtoTeX[(int)*cp-0xa0]);
  1658. X        else
  1659. X            fputc(*cp, tfp);
  1660. X        }
  1661. X
  1662. X    reset_color(t->color);
  1663. X
  1664. X#ifdef DVIPS
  1665. X    if(t->angle)
  1666. X    {
  1667. X      if (t->type == T_LEFT_JUSTIFIED)
  1668. X           fprintf(tfp, "\\special{ps:currentpoint grestore moveto}");
  1669. X      else
  1670. X         fprintf(stderr, "Rotated Text only for left justified text\n");
  1671. X    }
  1672. X#endif
  1673. X     fprintf(tfp, "} %s at %6.3f %6.3f\n",
  1674. X        tpos, (x)*CONVUNIT, (y)*CONVUNIT);
  1675. X    }
  1676. X
  1677. Xvoid genpictex_arc(a)
  1678. XF_arc    *a;
  1679. X{
  1680. X    double        x, y;
  1681. X    double        cx, cy, sx, sy, ex, ey;
  1682. X    double        dx1, dy1, dx2, dy2, r1, r2, th1, th2, theta;
  1683. X
  1684. X        fprintf(tfp, "%%\n%% Fig CIRCULAR ARC object\n%%\n");
  1685. X
  1686. X    set_linewidth(a->thickness);
  1687. X    set_style(a->style, a->style_val);
  1688. X    set_color(a->color);
  1689. X
  1690. X    cx = a->center.x/ppi; cy = convy(a->center.y/ppi);
  1691. X    sx = a->point[0].x/ppi; sy = convy(a->point[0].y/ppi);
  1692. X    ex = a->point[2].x/ppi; ey = convy(a->point[2].y/ppi);
  1693. X
  1694. X    if (a->for_arrow) {
  1695. X        arc_tangent(cx, cy, ex, ey, a->direction, &x, &y);
  1696. X        draw_arrow_head(x, y, ex, ey,
  1697. X            a->for_arrow->ht/ppi, a->for_arrow->wid/ppi);
  1698. X        }
  1699. X    if (a->back_arrow) {
  1700. X        arc_tangent(cx, cy, sx, sy, !a->direction, &x, &y);
  1701. X        draw_arrow_head(x, y, sx, sy,
  1702. X            a->back_arrow->ht/ppi, a->back_arrow->wid/ppi);
  1703. X        }
  1704. X
  1705. X    dx1 = sx - cx;
  1706. X    dy1 = sy - cy;
  1707. X    dx2 = ex - cx;
  1708. X    dy2 = ey - cy;
  1709. X        
  1710. X    rtop(dx1, dy1, &r1, &th1);
  1711. X    rtop(dx2, dy2, &r2, &th2);
  1712. X    theta = th2 - th1;
  1713. X    if (theta > 0) theta -= 2*M_PI;
  1714. X
  1715. X/*    set_linewidth(a->thickness); */
  1716. X
  1717. X    if (a->direction)
  1718. X        fprintf(tfp, "\\circulararc %6.3f degrees from %6.3f %6.3f center at %6.3f %6.3f\n",
  1719. X            360+(180/M_PI * theta), (sx)*CONVUNIT, (sy)*CONVUNIT, (cx)*CONVUNIT, (cy)*CONVUNIT);
  1720. X    else
  1721. X        fprintf(tfp, "\\circulararc %6.3f degrees from %6.3f %6.3f center at %6.3f %6.3f\n",
  1722. X            -180/M_PI * theta, (ex)*CONVUNIT, (ey)*CONVUNIT, (cx)*CONVUNIT, (cy)*CONVUNIT);
  1723. X
  1724. X    if (a->area_fill && (int)a->area_fill != DEFAULT)
  1725. X        fprintf(stderr, "Arc area fill not implemented\n");
  1726. X    reset_color(a->color);
  1727. X    }
  1728. X
  1729. X
  1730. X
  1731. X/*
  1732. X * rtop - rectangular to polar conversion
  1733. X */
  1734. Xstatic rtop(x, y, r, th)
  1735. Xdouble x, y, *r, *th;
  1736. X{
  1737. X    *r = sqrt(x*x+y*y);
  1738. X    *th = acos(x/(*r));
  1739. X
  1740. X    if (y < 0) *th = 2*M_PI - *th;
  1741. X}
  1742. X
  1743. Xstatic arc_tangent(x1, y1, x2, y2, direction, x, y)
  1744. Xdouble    x1, y1, x2, y2, *x, *y;
  1745. Xint    direction;
  1746. X{
  1747. X    if (direction) { /* counter clockwise  */
  1748. X        *x = x2 + (y2 - y1);
  1749. X        *y = y2 - (x2 - x1);
  1750. X        }
  1751. X    else {
  1752. X        *x = x2 - (y2 - y1);
  1753. X        *y = y2 + (x2 - x1);
  1754. X        }
  1755. X    }
  1756. X
  1757. X/*    draw arrow heading from (x1, y1) to (x2, y2)    */
  1758. X
  1759. Xstatic draw_arrow_head(x1, y1, x2, y2, arrowht, arrowwid)
  1760. Xdouble    x1, y1, x2, y2, arrowht, arrowwid;
  1761. X{
  1762. X    double    x, y, xb, yb, dx, dy, l, sina, cosa;
  1763. X    double    xc, yc, xd, yd;
  1764. X    int style;
  1765. X    double dash;
  1766. X
  1767. X    dx = x2 - x1;  dy = y1 - y2;
  1768. X
  1769. X    if (!dx && !dy)
  1770. X        return ;
  1771. X
  1772. X    l = sqrt(dx*dx+dy*dy);
  1773. X    if (l == 0) {
  1774. X         return;
  1775. X    }
  1776. X    else {
  1777. X         sina = dy / l;  cosa = dx / l;
  1778. X    }
  1779. X    xb = x2*cosa - y2*sina;
  1780. X    yb = x2*sina + y2*cosa;
  1781. X    x = xb - arrowht;
  1782. X    y = yb - arrowwid / 2;
  1783. X    xc = x*cosa + y*sina;
  1784. X    yc = -x*sina + y*cosa;
  1785. X    y = yb + arrowwid / 2;
  1786. X    xd = x*cosa + y*sina;
  1787. X    yd = -x*sina + y*cosa;
  1788. X
  1789. X    /* save line style and set to solid */
  1790. X    style = line_style;
  1791. X    dash = dash_length;
  1792. X    set_style(SOLID_LINE, 0.0);
  1793. X
  1794. X        fprintf(tfp, "%%\n%% arrow head\n%%\n");
  1795. X
  1796. X    fprintf(tfp, "\\plot %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f /\n%%\n",
  1797. X        (xc)*CONVUNIT, (yc)*CONVUNIT, (x2)*CONVUNIT, (y2)*CONVUNIT, (xd)*CONVUNIT, (yd)*CONVUNIT);
  1798. X
  1799. X    /* restore line style */
  1800. X    set_style(style, dash);
  1801. X    }
  1802. X
  1803. X#define        THRESHOLD    .05    /* inch */
  1804. X
  1805. Xstatic quadratic_spline(a1, b1, a2, b2, a3, b3, a4, b4)
  1806. Xdouble    a1, b1, a2, b2, a3, b3, a4, b4;
  1807. X{
  1808. X    double    x1, y1, x4, y4;
  1809. X    double    xmid, ymid;
  1810. X
  1811. X    x1 = a1; y1 = b1;
  1812. X    x4 = a4; y4 = b4;
  1813. X    xmid = (a2 + a3) / 2;
  1814. X    ymid = (b2 + b3) / 2;
  1815. X    if (fabs(x1 - xmid) < THRESHOLD && fabs(y1 - ymid) < THRESHOLD)
  1816. X        fprintf(tfp, "\t%6.3f %6.3f\n", (xmid)*CONVUNIT, (ymid)*CONVUNIT);
  1817. X
  1818. X    else {
  1819. X        quadratic_spline(x1, y1, ((x1+a2)/2), ((y1+b2)/2),
  1820. X            ((3*a2+a3)/4), ((3*b2+b3)/4), xmid, ymid);
  1821. X        }
  1822. X
  1823. X    if (fabs(xmid - x4) < THRESHOLD && fabs(ymid - y4) < THRESHOLD)
  1824. X        fprintf(tfp, "\t%6.3f %6.3f\n", (x4)*CONVUNIT, (y4)*CONVUNIT);
  1825. X
  1826. X    else {
  1827. X        quadratic_spline(xmid, ymid, ((a2+3*a3)/4), ((b2+3*b3)/4),
  1828. X            ((a3+x4)/2), ((b3+y4)/2), x4, y4);
  1829. X        }
  1830. X    }
  1831. X
  1832. Xstatic void genpictex_ctl_spline(s)
  1833. XF_spline    *s;
  1834. X{
  1835. X    F_point    *p;
  1836. X    double    cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4;
  1837. X    double    x1, y1, x2, y2;
  1838. X
  1839. X        fprintf(tfp, "%%\n%% Fig CONTROL PT SPLINE\n%%\n");
  1840. X
  1841. X    p = s->points;
  1842. X    x1 = p->x/ppi;  y1 = convy(p->y/ppi);
  1843. X    p = p->next;
  1844. X    x2 = p->x/ppi;  y2 = convy(p->y/ppi);
  1845. X    cx1 = (x1 + x2) / 2;      cy1 = (y1 + y2) / 2;
  1846. X    cx2 = (x1 + 3 * x2) / 4;  cy2 = (y1 + 3 * y2) / 4;
  1847. X
  1848. X    if (closed_spline(s)) {
  1849. X        fprintf(tfp, "%% closed spline\n%%\n");
  1850. X        fprintf(tfp, "\\plot\t%6.3f %6.3f \n ", (cx1)*CONVUNIT, (cy1)*CONVUNIT);
  1851. X        }
  1852. X    else {
  1853. X        fprintf(tfp, "%% open spline\n%%\n");
  1854. X        if (s->back_arrow)
  1855. X            draw_arrow_head(cx1, cy1, x1, y1,
  1856. X            s->back_arrow->ht/ppi, s->back_arrow->wid/ppi);
  1857. X        fprintf(tfp, "\\plot\t%6.3f %6.3f %6.3f %6.3f\n ",
  1858. X        (x1)*CONVUNIT, (y1)*CONVUNIT, (cx1)*CONVUNIT, (cy1)*CONVUNIT);
  1859. X        }
  1860. X
  1861. X    for (p = p->next; p != NULL; p = p->next) {
  1862. X        x1 = x2;  y1 = y2;
  1863. X        x2 = p->x/ppi;  y2 = convy(p->y/ppi);
  1864. X        cx3 = (3 * x1 + x2) / 4;  cy3 = (3 * y1 + y2) / 4;
  1865. X        cx4 = (x1 + x2) / 2;      cy4 = (y1 + y2) / 2;
  1866. X        quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4);
  1867. X        cx1 = cx4;  cy1 = cy4;
  1868. X        cx2 = (x1 + 3 * x2) / 4;  cy2 = (y1 + 3 * y2) / 4;
  1869. X        }
  1870. X    x1 = x2;  y1 = y2;
  1871. X    p = s->points->next;
  1872. X    x2 = p->x/ppi;  y2 = convy(p->y/ppi);
  1873. X    cx3 = (3 * x1 + x2) / 4;  cy3 = (3 * y1 + y2) / 4;
  1874. X    cx4 = (x1 + x2) / 2;      cy4 = (y1 + y2) / 2;
  1875. X    if (closed_spline(s)) {
  1876. X        quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4);
  1877. X        fprintf(tfp, "\t/\n");
  1878. X        }
  1879. X    else {
  1880. X        fprintf(tfp, "\t /\n\\plot %6.3f %6.3f %6.3f %6.3f /\n",
  1881. X        (cx1)*CONVUNIT, (cy1)*CONVUNIT, (x1)*CONVUNIT, (y1)*CONVUNIT);
  1882. X        if (s->for_arrow)
  1883. X            draw_arrow_head(cx1, cy1, x1, y1,
  1884. X            s->for_arrow->ht/ppi, s->for_arrow->wid/ppi);
  1885. X        }
  1886. X
  1887. X    }
  1888. X
  1889. Xstatic void genpictex_itp_spline(s)
  1890. XF_spline    *s;
  1891. X{
  1892. X    F_point        *p1, *p2;
  1893. X    F_control    *cp1, *cp2;
  1894. X    double        x1, x2, y1, y2;
  1895. X
  1896. X        fprintf(tfp, "%%\n%% Fig INTERPOLATED PT SPLINE\n%%\n");
  1897. X
  1898. X    p1 = s->points;
  1899. X    cp1 = s->controls;
  1900. X    x2 = p1->x/ppi; y2 = convy(p1->y/ppi);
  1901. X
  1902. X    if (s->back_arrow)
  1903. X        draw_arrow_head(cp1->rx/ppi, convy(cp1->ry/ppi), x2, y2,
  1904. X        s->back_arrow->ht/ppi, s->back_arrow->wid/ppi);
  1905. X
  1906. X    fprintf(tfp, "\\plot %6.3f %6.3f ", (x2)*CONVUNIT, (y2)*CONVUNIT);
  1907. X    for (p2 = p1->next, cp2 = cp1->next; p2 != NULL;
  1908. X        p1 = p2, cp1 = cp2, p2 = p2->next, cp2 = cp2->next) {
  1909. X        x1 = x2; y1 = y2;
  1910. X        x2 = p2->x/ppi; y2 = convy(p2->y/ppi);
  1911. X        bezier_spline(x1, y1, (double)cp1->rx/ppi, convy(cp1->ry/ppi),
  1912. X        (double)cp2->lx/ppi, convy(cp2->ly/ppi), x2, y2);
  1913. X        }
  1914. X    fprintf(tfp, "\t/\n");
  1915. X
  1916. X    if (s->for_arrow)
  1917. X        draw_arrow_head(cp1->lx/ppi, convy(cp1->ly/ppi), x2, y2,
  1918. X        s->for_arrow->ht/ppi, s->for_arrow->wid/ppi);
  1919. X    }
  1920. X
  1921. Xstatic bezier_spline(a0, b0, a1, b1, a2, b2, a3, b3)
  1922. Xdouble    a0, b0, a1, b1, a2, b2, a3, b3;
  1923. X{
  1924. X    double    x0, y0, x3, y3;
  1925. X    double    sx1, sy1, sx2, sy2, tx, ty, tx1, ty1, tx2, ty2, xmid, ymid;
  1926. X
  1927. X    x0 = a0; y0 = b0;
  1928. X    x3 = a3; y3 = b3;
  1929. X    if (fabs(x0 - x3) < THRESHOLD && fabs(y0 - y3) < THRESHOLD)
  1930. X        fprintf(tfp, "\t%6.3f %6.3f\n", (x3)*CONVUNIT, (y3)*CONVUNIT);
  1931. X
  1932. X    else {
  1933. X        tx = (a1 + a2) / 2;        ty = (b1 + b2) / 2;
  1934. X        sx1 = (x0 + a1) / 2;    sy1 = (y0 + b1) / 2;
  1935. X        sx2 = (sx1 + tx) / 2;    sy2 = (sy1 + ty) / 2;
  1936. X        tx2 = (a2 + x3) / 2;    ty2 = (b2 + y3) / 2;
  1937. X        tx1 = (tx2 + tx) / 2;    ty1 = (ty2 + ty) / 2;
  1938. X        xmid = (sx2 + tx1) / 2;    ymid = (sy2 + ty1) / 2;
  1939. X
  1940. X        bezier_spline(x0, y0, sx1, sy1, sx2, sy2, xmid, ymid);
  1941. X        bezier_spline(xmid, ymid, tx1, ty1, tx2, ty2, x3, y3);
  1942. X        }
  1943. X    }
  1944. X
  1945. Xstruct driver dev_pictex = {
  1946. X         genpictex_option,
  1947. X    genpictex_start,
  1948. X    genpictex_arc,
  1949. X    genpictex_ellipse,
  1950. X    genpictex_line,
  1951. X    genpictex_spline,
  1952. X    genpictex_text,
  1953. X    genpictex_end,
  1954. X    EXCLUDE_TEXT
  1955. X};
  1956. X
  1957. END_OF_FILE
  1958. if test 25452 -ne `wc -c <'fig2dev/dev/genpictex.c'`; then
  1959.     echo shar: \"'fig2dev/dev/genpictex.c'\" unpacked with wrong size!
  1960. fi
  1961. # end of 'fig2dev/dev/genpictex.c'
  1962. fi
  1963. echo shar: End of archive 6 \(of 7\).
  1964. cp /dev/null ark6isdone
  1965. MISSING=""
  1966. for I in 1 2 3 4 5 6 7 ; do
  1967.     if test ! -f ark${I}isdone ; then
  1968.     MISSING="${MISSING} ${I}"
  1969.     fi
  1970. done
  1971. if test "${MISSING}" = "" ; then
  1972.     echo You have unpacked all 7 archives.
  1973.     rm -f ark[1-9]isdone
  1974. else
  1975.     echo You still need to unpack the following archives:
  1976.     echo "        " ${MISSING}
  1977. fi
  1978. ##  End of shell archive.
  1979. exit 0
  1980.