home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume11 / gnuplot2 / part11 < prev    next >
Encoding:
Text File  |  1990-03-25  |  42.8 KB  |  1,712 lines

  1. Newsgroups: comp.sources.misc
  2. organization: Pixar -- Marin County, California
  3. subject: v11i076: Gnuplot 2.0 - 11 of 14
  4. From: thaw@ucbvax.Berkeley.EDU@pixar.UUCP (Tom Williams)
  5. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  6.  
  7. Posting-number: Volume 11, Issue 76
  8. Submitted-by: thaw@ucbvax.Berkeley.EDU@pixar.UUCP (Tom Williams)
  9. Archive-name: gnuplot2/part11
  10.  
  11. This is gnuplot.sh11
  12.  
  13. --- CUT HERE ---
  14. #! /bin/sh
  15. echo x - term/imPcodes.h
  16. sed 's/^X//' >term/imPcodes.h <<'*-*-END-of-term/imPcodes.h-*-*'
  17. X/*
  18. X * Copyright (c) 1985 Regents of the University of California.
  19. X * All rights reserved.  The Berkeley software License Agreement
  20. X * specifies the terms and conditions for redistribution.
  21. X *
  22. X *    @(#)imPcodes.h    5.1 (Berkeley) 9/21/85
  23. X */
  24. X
  25. X#define    imP_SP    128
  26. X#define    imP_SP1    129
  27. X#define    imP_OLD_MMOVE    130
  28. X#define    imP_MPLUS    131
  29. X#define    imP_MMINUS    132
  30. X#define    imP_MMOVE    133
  31. X#define    imP_SMOVE    134
  32. X
  33. X#define    imP_SET_ABS_H    135
  34. X#define    imP_SET_REL_H    136
  35. X#define    imP_SET_ABS_V    137
  36. X#define    imP_SET_REL_V    138
  37. X
  38. X#define    imP_SRULE    192
  39. X#define    imP_BRULE    193
  40. X
  41. X#define    imP_SET_HPOS    195
  42. X#define    imP_SET_VPOS    196
  43. X#define    imP_CRLF    197
  44. X#define    imP_SGLY    198
  45. X#define    imP_BGLY    199
  46. X#define    imP_DELG    200
  47. X#define    imP_DELC    201
  48. X#define    imP_DELF    202
  49. X
  50. X#define    imP_SET_HV_SYSTEM    205
  51. X#define    imP_SET_ADV_DIRS    206
  52. X#define    imP_SET_FAMILY    207
  53. X#define    imP_SET_IL    208
  54. X#define    imP_SET_BOL    209
  55. X#define    imP_SET_SP    210
  56. X#define    imP_PUSH    211
  57. X#define    imP_POP    212
  58. X#define    imP_PAGE    213
  59. X#define    imP_SET_PUSH_MASK    214
  60. X#define    imP_ENDPAGE    219
  61. X
  62. X#define    imP_CREATE_FAMILY_TABLE    221
  63. X#define    imP_CREATE_MAP    222
  64. X
  65. X#define    imP_CREATE_PATH    230
  66. X#define    imP_SET_TEXTURE    231
  67. X#define    imP_SET_PEN    232
  68. X#define    imP_FILL_PATH    233
  69. X#define    imP_DRAW_PATH    234
  70. X#define    imP_BITMAP    235
  71. X#define    imP_SET_MAGN    236
  72. X
  73. X#define    imP_EOF    255
  74. X
  75. X
  76. *-*-END-of-term/imPcodes.h-*-*
  77. echo x - term/imagen.trm
  78. sed 's/^X//' >term/imagen.trm <<'*-*-END-of-term/imagen.trm-*-*'
  79. X/* GNUPLOT - imagen.trm */
  80. X/*
  81. X * Copyright (C) 1990   
  82. X *
  83. X * Permission to use, copy, and distribute this software and its
  84. X * documentation for any purpose with or without fee is hereby granted, 
  85. X * provided that the above copyright notice appear in all copies and 
  86. X * that both that copyright notice and this permission notice appear 
  87. X * in supporting documentation.
  88. X *
  89. X * Permission to modify the software is granted, but not the right to
  90. X * distribute the modified code.  Modifications are to be distributed 
  91. X * as patches to released version.
  92. X *  
  93. X * This software  is provided "as is" without express or implied warranty.
  94. X * 
  95. X * This file is included by ../term.c.
  96. X *
  97. X * This terminal driver supports:
  98. X *   Imagen laser printers
  99. X *
  100. X * AUTHORS
  101. X *   Paul E. McKenney, David Kotz
  102. X * 
  103. X * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
  104. X * 
  105. X */
  106. X
  107. X/*
  108. X * Original for direct Imagen output (but retaining many of the
  109. X * LaTeX extensions) by Paul E. McKenney, 1989.
  110. X * Further modified by David Kotz to fit into gnuplot 2.0.
  111. X * Information Science and Technology Division, SRI International,
  112. X * 333 Ravenswood Ave, Menlo Park, CA 94025.
  113. X * Mail to mckenney@sri.com.
  114. X */
  115. X
  116. X#include "imPcodes.h"
  117. X
  118. X#define IMAGEN_PTS_PER_INCH (300)
  119. X
  120. X#define IMAGEN_XMAX (10.0 * IMAGEN_PTS_PER_INCH) /* 10.0 inches */
  121. X#define IMAGEN_YMAX (7.5 * IMAGEN_PTS_PER_INCH) /* 7.5 inches */
  122. X
  123. X#define IMAGEN_FONTSIZE 12
  124. X
  125. X#define IMAGEN_HTIC (20)
  126. X#define IMAGEN_VTIC (20)
  127. X#define IMAGEN_VCHAR (IMAGEN_FONTSIZE*5)
  128. X#define IMAGEN_HCHAR (IMAGEN_VCHAR/2)
  129. X
  130. Xstatic int IMAGEN_orgx;        /* absolute-pixel-ORIgin of graph.    */
  131. Xstatic int IMAGEN_orgy;
  132. Xstatic int IMAGEN_posx;        /* current drawing position (lines).    */
  133. Xstatic int IMAGEN_posy;
  134. Xstatic int IMAGEN_inplot;
  135. Xstatic int IMAGEN_xmax;        /* width of graph in pixels.        */
  136. Xstatic int IMAGEN_ymax;        /* height of graph in pixels.        */
  137. Xstatic int IMAGEN_hchar;        /* Height of CHAR in current font.    */
  138. Xstatic int IMAGEN_wchar;        /* Width of CHAR in current font.    */
  139. Xstatic int IMAGEN_blofs;        /* BaseLine OFfSet from bounding box.    */
  140. Xstatic int IMAGEN_angle = -1;    /* 0 for horizontal text, 1 for vertical */
  141. Xstatic enum JUSTIFY IMAGEN_justify = LEFT; /* left/center/right */
  142. X
  143. Xstatic IMAGEN_seq_pos;        /* position in sequence */
  144. X
  145. Xstatic void IMAGEN_putwd();
  146. Xstatic void IMAGEN_createfamily();
  147. Xstatic void IMAGEN_setfont();
  148. Xstatic void IMAGEN_setpos();
  149. Xstatic char *IMAGEN_cvts();
  150. X
  151. XIMAGEN_init()
  152. X{
  153. X    char font[10];            /* font name */
  154. X
  155. X    IMAGEN_posx = IMAGEN_posy = 0;
  156. X
  157. X    IMAGEN_orgx = (11.0 * IMAGEN_PTS_PER_INCH - IMAGEN_XMAX) / 2;
  158. X    IMAGEN_orgy = (8.5 * IMAGEN_PTS_PER_INCH - IMAGEN_YMAX)/ 2;
  159. X
  160. X    fputs("@document(language impress)", outfile);
  161. X
  162. X    putc(imP_SET_HV_SYSTEM, outfile);
  163. X    putc((3<<3)|5, outfile);
  164. X
  165. X    sprintf(font, "cour%02d", IMAGEN_FONTSIZE);
  166. X    IMAGEN_createfamily(font, IMAGEN_FONTSIZE);
  167. X    IMAGEN_setfont(IMAGEN_FONTSIZE);
  168. X
  169. X    IMAGEN_text_angle(0);
  170. X
  171. X    putc(imP_SET_ABS_H, outfile);
  172. X    IMAGEN_putwd(0);
  173. X    putc(imP_SET_ABS_V, outfile);
  174. X    IMAGEN_putwd(0);
  175. X
  176. X    IMAGEN_linetype(-1);
  177. X}
  178. X
  179. XIMAGEN_graphics()
  180. X{
  181. X    static BOOLEAN first = TRUE;
  182. X
  183. X    if (!first)
  184. X     putc(imP_ENDPAGE, outfile);
  185. X    first = FALSE;
  186. X
  187. X    IMAGEN_move(0, 0);
  188. X}
  189. X
  190. XIMAGEN_text()
  191. X{
  192. X}
  193. X
  194. X
  195. XIMAGEN_linetype(linetype)
  196. Xint linetype;
  197. X{
  198. X    static int lastlinetype = -10;
  199. X
  200. X    if (linetype < 0)
  201. X     linetype = -linetype;
  202. X    else
  203. X     linetype *= 2;
  204. X
  205. X    if (lastlinetype == linetype)
  206. X     return;
  207. X
  208. X    lastlinetype = linetype;    /* now >= 0 */
  209. X
  210. X    putc(imP_SET_PEN, outfile);
  211. X    putc(linetype, outfile);
  212. X}
  213. X
  214. X
  215. XIMAGEN_move(x,y)
  216. X    unsigned int x,y;
  217. X{
  218. X    IMAGEN_posx = x;
  219. X    IMAGEN_posy = y;
  220. X}
  221. X
  222. XIMAGEN_vector(ux,uy)
  223. X    unsigned int ux,uy;
  224. X{
  225. X    /* Create path. */
  226. X
  227. X    putc(imP_CREATE_PATH, outfile);
  228. X    IMAGEN_putwd(2);
  229. X    IMAGEN_putwd(IMAGEN_posx + IMAGEN_orgx);
  230. X    IMAGEN_putwd(IMAGEN_posy + IMAGEN_orgy);
  231. X    IMAGEN_putwd(ux + IMAGEN_orgx);
  232. X    IMAGEN_putwd(uy + IMAGEN_orgy);
  233. X
  234. X    /* Draw path with black pen. */
  235. X
  236. X    putc(imP_DRAW_PATH, outfile);
  237. X    putc(15, outfile);
  238. X
  239. X    /* Set current position to end of line. */
  240. X
  241. X    IMAGEN_move(ux, uy);
  242. X}
  243. X
  244. Xstatic void
  245. XIMAGEN_setpos(ux, uy)
  246. X    int ux,uy;
  247. X{
  248. X    /* Set x and y position (for text), also set beginning-of-line. */
  249. X
  250. X    putc(imP_SET_ABS_H, outfile);
  251. X    IMAGEN_putwd(ux + IMAGEN_orgx);
  252. X    putc(imP_SET_ABS_V, outfile);
  253. X    IMAGEN_putwd(uy + IMAGEN_orgy);
  254. X    putc(imP_SET_BOL, outfile);
  255. X    if (IMAGEN_angle == 1)
  256. X     IMAGEN_putwd(uy + IMAGEN_orgx); /* vertical */
  257. X    else
  258. X     IMAGEN_putwd(ux + IMAGEN_orgx); /* horizontal */
  259. X}
  260. X
  261. XIMAGEN_text_angle(angle)
  262. X    int angle;
  263. X{
  264. X    if (IMAGEN_angle != angle) {
  265. X       IMAGEN_angle = angle;    /* record for later use */
  266. X       putc(imP_SET_ADV_DIRS, outfile);
  267. X       putc(angle == 0 ? 0 : 7, outfile); /* 0=>horiz : 7=>vert */
  268. X    }
  269. X
  270. X    return(TRUE);
  271. X}
  272. X
  273. XIMAGEN_justify_text(mode)
  274. X    enum JUSTIFY mode;
  275. X{
  276. X    IMAGEN_justify = mode;
  277. X    return(TRUE);
  278. X}
  279. X
  280. Xstatic char *
  281. XIMAGEN_cvts(str, width, height)
  282. X    char        *str;
  283. X    int        *width;
  284. X    int        *height;
  285. X{
  286. X    char        *cp1;
  287. X    char        *cp2;
  288. X    static char    *buf = NULL;
  289. X    int        h;
  290. X    int        maxw;
  291. X    int        w;
  292. X
  293. X    /* Free up old buffer, if there is one, get a new one.  Since    */
  294. X    /* all transformations shorten the string, get a buffer that is    */
  295. X    /* the same size as the input string.                */
  296. X
  297. X    if (buf != NULL)
  298. X     (void) free(buf);
  299. X    buf = (char *) alloc(strlen(str), "converted label string");
  300. X
  301. X    /* Do the transformations. */
  302. X
  303. X    cp1 = str;
  304. X    cp2 = buf;
  305. X    h = 1;
  306. X    maxw = 0;
  307. X    w = 0;
  308. X    while (*cp1 != NULL) {
  309. X       switch (*cp1) {
  310. X          case ' ' :        /* Space character. */
  311. X            *cp2++ = imP_SP;
  312. X            w++;
  313. X            break;
  314. X            
  315. X            case  '\\' :    /* Escape sequence. */
  316. X             if (*++cp1 == '\\') {
  317. X                /* Begin new line. */
  318. X                h++;
  319. X                if (w > maxw)
  320. X                  maxw = w;
  321. X                w = 0;
  322. X                *cp2++ = imP_CRLF;
  323. X                break;
  324. X             }
  325. X            
  326. X            /* Fall through to just copy next char out.    */
  327. X            
  328. X            default :
  329. X             *cp2++ = *cp1;
  330. X            w++;
  331. X            break;
  332. X        }
  333. X       cp1++;
  334. X    }
  335. X    
  336. X    *cp2 = '\0';
  337. X    if (w > maxw)
  338. X     maxw = w;
  339. X    
  340. X    if (height != NULL)
  341. X     *height = IMAGEN_angle ?
  342. X       IMAGEN_wchar * maxw :
  343. X        IMAGEN_hchar * h;
  344. X    if (width != NULL)
  345. X     *width = IMAGEN_angle ?
  346. X       IMAGEN_hchar * h :
  347. X        IMAGEN_wchar * maxw;
  348. X    return (buf);
  349. X}
  350. X
  351. XIMAGEN_put_text(x, y, str)
  352. X    int x,y;                /* reference point of string */
  353. X    char str[];            /* the text */
  354. X{
  355. X    char *cvstr;
  356. X    int height;
  357. X    int width;
  358. X    
  359. X    cvstr = IMAGEN_cvts(str, &width, &height);
  360. X
  361. X    switch (IMAGEN_justify) {
  362. X       case LEFT: break;
  363. X       case CENTRE: x -= width/2; break;
  364. X       case RIGHT: x -= width; break;
  365. X    }
  366. X
  367. X    if (IMAGEN_angle) {        /* vertical */
  368. X       x += IMAGEN_hchar;
  369. X       y -= height/2;
  370. X    } else                /* horizontal */
  371. X     y += height/2 - IMAGEN_hchar;
  372. X
  373. X    IMAGEN_setpos(x, y + IMAGEN_blofs);
  374. X    fputs(cvstr, outfile);
  375. X}
  376. X
  377. X
  378. XIMAGEN_reset()
  379. X{
  380. X    putc(imP_EOF, outfile);
  381. X}
  382. X
  383. Xstatic void
  384. XIMAGEN_putwd(w)
  385. X{
  386. X    putc(w>>8, outfile);
  387. X    putc(w, outfile);
  388. X}
  389. X
  390. Xstatic void
  391. XIMAGEN_createfamily(c, sz)
  392. X    char        *c;
  393. X    int        sz;
  394. X{
  395. X    putc(imP_CREATE_FAMILY_TABLE, outfile);
  396. X    putc(sz, outfile);
  397. X    putc(1, outfile);
  398. X    putc(0, outfile);
  399. X    fputs(c, outfile);
  400. X    putc(0, outfile);
  401. X}
  402. X
  403. Xstatic void
  404. XIMAGEN_setfont(sz) 
  405. X    int sz;
  406. X{
  407. X    IMAGEN_hchar = sz * 5;
  408. X    IMAGEN_wchar = IMAGEN_hchar / 2;
  409. X    IMAGEN_blofs = IMAGEN_hchar / 3;
  410. X    putc(imP_SET_FAMILY, outfile);
  411. X    putc(sz, outfile);
  412. X    putc(imP_SET_SP, outfile);
  413. X    IMAGEN_putwd(IMAGEN_wchar);
  414. X    putc(imP_SET_IL, outfile);
  415. X    IMAGEN_putwd(IMAGEN_hchar);
  416. X}
  417. *-*-END-of-term/imagen.trm-*-*
  418. echo x - term/object.h
  419. sed 's/^X//' >term/object.h <<'*-*-END-of-term/object.h-*-*'
  420. X/* 
  421. X *    FIG : Facility for Interactive Generation of figures
  422. X *
  423. X *    (c) copy right 1985 by Supoj Sutanthavibul (supoj@sally.utexas.edu)
  424. X *      January 1985.
  425. X *    1st revision : Aug 1985.
  426. X *    2nd revision : Feb 1988.
  427. X *
  428. X *    %W%    %G%
  429. X*/
  430. X#define                    DEFAULT            -1
  431. X
  432. Xtypedef        struct f_pattern {
  433. X            int            w, h;
  434. X            int            *p;
  435. X            }
  436. X        F_pattern;
  437. X
  438. Xtypedef        struct f_pen {
  439. X            int            x, y;
  440. X            int            *p;
  441. X            }
  442. X        F_pen;
  443. X
  444. Xtypedef        struct f_point {
  445. X            int            x, y;
  446. X            struct f_point        *next;
  447. X            }
  448. X        F_point;
  449. X
  450. Xtypedef        struct f_pos {
  451. X            int            x, y;
  452. X            }
  453. X        F_pos;
  454. X
  455. Xtypedef        struct f_arrow {
  456. X            int            type;
  457. X            int            style;
  458. X            float            thickness;
  459. X            float            wid;
  460. X            float            ht;
  461. X            }
  462. X        F_arrow;
  463. X
  464. Xtypedef        struct f_ellipse {
  465. X            int            type;
  466. X#define                    T_ELLIPSE_BY_RAD    1
  467. X#define                    T_ELLIPSE_BY_DIA    2
  468. X#define                    T_CIRCLE_BY_RAD        3
  469. X#define                    T_CIRCLE_BY_DIA        4
  470. X            int            style;
  471. X            int            thickness;
  472. X            int            color;
  473. X#define                    BLACK            0
  474. X            int            depth;
  475. X            int            direction;
  476. X            float            style_val;
  477. X            float            angle;
  478. X            struct f_pen        *pen;
  479. X            struct f_pattern    *area_fill;
  480. X#define                           UNFILLED    (F_pattern *)0
  481. X#define                           BLACK_FILL    (F_pattern *)1
  482. X#define                           DARK_GRAY_FILL    (F_pattern *)2
  483. X#define                           MED_GRAY_FILL    (F_pattern *)3
  484. X#define                           LIGHT_GRAY_FILL    (F_pattern *)4
  485. X#define                           WHITE_FILL    (F_pattern *)4
  486. X            struct f_pos        center;
  487. X            struct f_pos        radiuses;
  488. X            struct f_pos        start;
  489. X            struct f_pos        end;
  490. X            struct f_ellipse    *next;
  491. X            }
  492. X        F_ellipse;
  493. X
  494. Xtypedef        struct f_arc {
  495. X            int            type;
  496. X#define                    T_3_POINTS_ARC        1
  497. X            int            style;
  498. X            int            thickness;
  499. X            int            color;
  500. X            int            depth;
  501. X            struct f_pen        *pen;
  502. X            struct f_pattern    *area_fill;
  503. X            float            style_val;
  504. X            int            direction;
  505. X            struct f_arrow        *for_arrow;
  506. X            struct f_arrow        *back_arrow;
  507. X            struct {float x, y;}    center;
  508. X            struct f_pos        point[3];
  509. X            struct f_arc        *next;
  510. X            }
  511. X        F_arc;
  512. X
  513. Xtypedef        struct f_line {
  514. X            int            type;
  515. X#define                    T_POLYLINE    1
  516. X#define                    T_BOX        2
  517. X#define                    T_POLYGON    3
  518. X            int            style;
  519. X            int            thickness;
  520. X            int            color;
  521. X            int            depth;
  522. X            float            style_val;
  523. X            struct f_pen        *pen;
  524. X            struct f_pattern    *area_fill;
  525. X            struct f_arrow        *for_arrow;
  526. X            struct f_arrow        *back_arrow;
  527. X            struct f_point        *points;
  528. X            struct f_line        *next;
  529. X            }
  530. X        F_line;
  531. X
  532. Xtypedef        struct f_text {
  533. X            int            type;
  534. X#define                    T_LEFT_JUSTIFIED    0
  535. X#define                    T_CENTER_JUSTIFIED    1
  536. X#define                    T_RIGHT_JUSTIFIED    2
  537. X            int            font;
  538. X#define                    DEFAULT_FONT        0
  539. X#define                    ROMAN_FONT        1
  540. X#define                    BOLD_FONT        2
  541. X#define                    ITALIC_FONT        3
  542. X#define                    MODERN_FONT        4
  543. X#define                    TYPEWRITER_FONT        5
  544. X            int            size;    /* point size */
  545. X            int            color;
  546. X            int            depth;
  547. X            float            angle;    /* in radian */
  548. X            int            style;
  549. X#define                    PLAIN        1
  550. X#define                    ITALIC        2
  551. X#define                    BOLD        4
  552. X#define                    OUTLINE        8
  553. X#define                    SHADOW        16
  554. X            int            height;    /* pixels */
  555. X            int            length;    /* pixels */
  556. X            int            base_x;
  557. X            int            base_y;
  558. X            struct f_pen        *pen;
  559. X            char            *cstring;
  560. X            struct f_text        *next;
  561. X            }
  562. X        F_text;
  563. X
  564. Xtypedef        struct f_control {
  565. X            float            lx, ly, rx, ry;
  566. X            struct f_control    *next;
  567. X            }
  568. X        F_control;
  569. X
  570. X#define        int_spline(s)        (s->type & 0x2)
  571. X#define        normal_spline(s)    (!(s->type & 0x2))
  572. X#define        closed_spline(s)    (s->type & 0x1)
  573. X#define        open_spline(s)        (!(s->type & 0x1))
  574. X
  575. Xtypedef        struct f_spline {
  576. X            int            type;
  577. X#define                    T_OPEN_NORMAL        0
  578. X#define                    T_CLOSED_NORMAL        1
  579. X#define                    T_OPEN_INTERPOLATED    2
  580. X#define                    T_CLOSED_INTERPOLATED    3
  581. X            int            style;
  582. X            int            thickness;
  583. X            int            color;
  584. X            int            depth;
  585. X            float            style_val;
  586. X            struct f_pen        *pen;
  587. X            struct f_pattern    *area_fill;
  588. X            struct f_arrow        *for_arrow;
  589. X            struct f_arrow        *back_arrow;
  590. X            /*
  591. X            For T_OPEN_NORMAL and T_CLOSED_NORMAL points
  592. X            are control points while they are knots for
  593. X            T_OPEN_INTERPOLATED and T_CLOSED_INTERPOLTED
  594. X            whose control points are stored in controls.
  595. X            */
  596. X            struct f_point        *points;
  597. X            struct f_control    *controls;
  598. X            struct f_spline        *next;
  599. X            }
  600. X        F_spline;
  601. X
  602. Xtypedef        struct f_compound {
  603. X            struct f_pos        nwcorner;
  604. X            struct f_pos        secorner;
  605. X            struct f_line        *lines;
  606. X            struct f_ellipse    *ellipses;
  607. X            struct f_spline        *splines;
  608. X            struct f_text        *texts;
  609. X            struct f_arc        *arcs;
  610. X            struct f_compound    *compounds;
  611. X            struct f_compound    *next;
  612. X            }
  613. X        F_compound;
  614. X
  615. X#define        ARROW_SIZE        sizeof(struct f_arrow)
  616. X#define        POINT_SIZE        sizeof(struct f_point)
  617. X#define        CONTROL_SIZE        sizeof(struct f_control)
  618. X#define        ELLOBJ_SIZE        sizeof(struct f_ellipse)
  619. X#define        ARCOBJ_SIZE        sizeof(struct f_arc)
  620. X#define        LINOBJ_SIZE        sizeof(struct f_line)
  621. X#define        TEXOBJ_SIZE        sizeof(struct f_text)
  622. X#define        SPLOBJ_SIZE        sizeof(struct f_spline)
  623. X#define        COMOBJ_SIZE        sizeof(struct f_compound)
  624. X
  625. X/**********************  object codes  **********************/
  626. X
  627. X#define        O_ELLIPSE        1
  628. X#define        O_POLYLINE        2
  629. X#define        O_SPLINE        3
  630. X#define        O_TEXT            4
  631. X#define        O_ARC            5
  632. X#define        O_COMPOUND        6
  633. X#define        O_END_COMPOUND        -O_COMPOUND
  634. X#define        O_ALL_OBJECT        99
  635. X
  636. X/************  object styles (except for f_text)  ************/
  637. X
  638. X#define        SOLID_LINE        0
  639. X#define        DASH_LINE        1
  640. X#define        DOTTED_LINE        2
  641. X
  642. X#define        CLOSED_PATH        0
  643. X#define        OPEN_PATH        1
  644. *-*-END-of-term/object.h-*-*
  645. echo x - term/fig.trm
  646. sed 's/^X//' >term/fig.trm <<'*-*-END-of-term/fig.trm-*-*'
  647. X/* GNUPLOT - fig.trm */
  648. X/*
  649. X * Copyright (C) 1990   
  650. X *
  651. X * Permission to use, copy, and distribute this software and its
  652. X * documentation for any purpose with or without fee is hereby granted, 
  653. X * provided that the above copyright notice appear in all copies and 
  654. X * that both that copyright notice and this permission notice appear 
  655. X * in supporting documentation.
  656. X *
  657. X * Permission to modify the software is granted, but not the right to
  658. X * distribute the modified code.  Modifications are to be distributed 
  659. X * as patches to released version.
  660. X *  
  661. X * This software  is provided "as is" without express or implied warranty.
  662. X * 
  663. X * This file is included by ../term.c.
  664. X *
  665. X * This terminal driver supports:
  666. X *  Fig graphics language
  667. X *
  668. X * AUTHORS
  669. X *  Micah Beck, David Kotz
  670. X * 
  671. X * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
  672. X * 
  673. X */
  674. X
  675. X/*
  676. X * Original for Fig code output by Micah Beck, 1989
  677. X * Department of Computer Science, Cornell University
  678. X * Updated by David Kotz for gnuplot 2.0
  679. X */
  680. X#include "object.h"            /* from the TransFig distribution */
  681. X
  682. X#ifndef FIG_RES
  683. X/* Must be 80 for the Fig editor, but may be increased if used 
  684. X * only by TransFig filters.
  685. X * Represents resolution per inch.
  686. X */
  687. X#define FIG_RES        80
  688. X#endif
  689. X
  690. X#define FIG_COORD_SYS    2
  691. X
  692. X#define FIG_MAGIC    "#FIG 1.4-TFX"
  693. X#define FIG_HTIC    (5*FIG_RES/80)
  694. X#define FIG_VTIC    (5*FIG_RES/80)
  695. X#define FIG_HCHAR    (6*FIG_RES/80)
  696. X#define FIG_VCHAR    (12*FIG_RES/80)
  697. X
  698. X#define FIG_ARROW_WIDTH FIG_HTIC
  699. X#define FIG_ARROW_HEIGHT FIG_HTIC
  700. X
  701. Xstatic long FIG_xbase = FIG_RES/2;
  702. Xstatic long FIG_ybase = FIG_RES/2;
  703. X
  704. Xstatic long FIG_posx;
  705. Xstatic long FIG_posy;
  706. X/* 5 inches wide by 3 inches high */
  707. X#define FIG_XMAX (5 * FIG_RES)
  708. X#define FIG_YMAX (3 * FIG_RES)
  709. X
  710. Xstatic int FIG_type;        /* negative types use real lines */
  711. Xstatic float FIG_spacing;    /* length of dash or dot spacing */
  712. Xstatic int FIG_justify;        /* Fig justification T_*_JUSTIFIED */
  713. Xstatic float FIG_angle;        /* Fig text angle 0=horiz, Pi/2=vert */
  714. X
  715. X#define FIG_POINT_TYPES POINT_TYPES /* we use the same points */
  716. X
  717. XFIG_init()
  718. X{
  719. X    FIG_posx = FIG_posy = 0;
  720. X    FIG_linetype(-1);
  721. X    FIG_justify_text(LEFT);
  722. X    FIG_text_angle(0);
  723. X
  724. X    fprintf(outfile, "%s\n", FIG_MAGIC);
  725. X    fprintf(outfile, "%d %d\n", FIG_RES, FIG_COORD_SYS);
  726. X}
  727. X
  728. X
  729. XFIG_graphics()
  730. X{
  731. X    FIG_posx = FIG_posy = 0;
  732. X    /* there is no way to have separate pictures in a FIG file */
  733. X}
  734. X
  735. X
  736. XFIG_text()
  737. X{
  738. X    /* there is no way to have separate pictures in a FIG file */
  739. X}
  740. X
  741. X
  742. X/* Line types for FIG work like this:
  743. X *  -2 : solid (border)
  744. X *  -1 : dashed 4 (axes)
  745. X *   0 : solid (first curve)
  746. X *   1 : dotted 3
  747. X *   2 : dashed 3
  748. X *   3 : dotted 6
  749. X *   4 : dashed 6
  750. X *   ... ...
  751. X */
  752. X
  753. XFIG_linetype(linetype)
  754. X    int linetype;            /* expect linetype >= -2 */
  755. X{
  756. X    switch (linetype) {
  757. X       case 0:
  758. X       case -2: {
  759. X          FIG_type = 0;    /* solid line */
  760. X          FIG_spacing = 0.0;
  761. X          break;
  762. X       } 
  763. X       case -1: {
  764. X          FIG_type = 1;    /* dashed */
  765. X          FIG_spacing = 4.0; /* dash length */
  766. X          break;
  767. X       }
  768. X       default: {
  769. X          linetype = abs(linetype); /* shouldn't be negative anyway */
  770. X          /* now linetype >= 1 */
  771. X          FIG_type = linetype % 2 + 1; /* dotted, dashed, ... */
  772. X          FIG_spacing = (linetype+1) / 2 * 3;
  773. X          break;          
  774. X       }
  775. X    }
  776. X}
  777. X
  778. XFIG_move(x,y)
  779. X    unsigned int x,y;
  780. X{
  781. X    FIG_posx = x;
  782. X    FIG_posy = y;
  783. X}
  784. X
  785. XFIG_vector(ux,uy)
  786. X    unsigned int ux,uy;
  787. X{
  788. X        int x=ux, y=uy;
  789. X
  790. X      fprintf(outfile, "%d %d %d %d %d %d %d %d %6.3f  %d %d\n",
  791. X         O_POLYLINE, T_POLYLINE,
  792. X         FIG_type, 1, DEFAULT, DEFAULT, DEFAULT, DEFAULT, FIG_spacing,
  793. X         0, 0);
  794. X      fprintf(outfile, "%d %d %d %d 9999 9999\n",
  795. X         FIG_posx, FIG_YMAX-FIG_posy, x, FIG_YMAX-y);
  796. X
  797. X    FIG_posx = x;
  798. X        FIG_posy = y;
  799. X}
  800. X
  801. XFIG_arrow(sx, sy, ex, ey)
  802. X    int sx, sy;    /* start coord */
  803. X    int ex, ey;    /* end coord */
  804. X{
  805. X      fprintf(outfile, "%d %d %d %d %d %d %d %d %6.3f  %d %d\n",
  806. X         O_POLYLINE, T_POLYLINE,
  807. X         FIG_type, 1, DEFAULT, DEFAULT, DEFAULT, DEFAULT, FIG_spacing,
  808. X         1, 0);
  809. X    /* arrow line */
  810. X      fprintf(outfile, "%d %d %.3f %.3f %.3f\n",
  811. X         0, 0, 1.0, (float)FIG_ARROW_WIDTH, (float)FIG_ARROW_HEIGHT);
  812. X      fprintf(outfile, "%d %d %d %d 9999 9999\n",
  813. X         sx, FIG_YMAX-sy, ex, FIG_YMAX-ey);
  814. X
  815. X    FIG_posx = ex;
  816. X        FIG_posy = ey;
  817. X}
  818. X
  819. XFIG_put_text(x, y, str)
  820. X    int x, y;
  821. X    char *str;
  822. X{
  823. X    y = y - FIG_VCHAR/2;        /* assuming vertical center justified */
  824. X
  825. X    fprintf(outfile, "%d %d %d %d %d %d %d %6.3f %d %d %d %d %d %s\01\n",
  826. X          O_TEXT, FIG_justify,
  827. X          ROMAN_FONT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, FIG_angle,
  828. X          DEFAULT, 16, 8*strlen(str), x, FIG_YMAX-y, str);
  829. X}
  830. X
  831. Xint FIG_justify_text(mode)
  832. X    enum JUSTIFY mode;
  833. X{
  834. X    switch(mode) {
  835. X       case LEFT: FIG_justify = T_LEFT_JUSTIFIED; break;
  836. X       case CENTRE: FIG_justify = T_CENTER_JUSTIFIED; break;
  837. X       case RIGHT: FIG_justify = T_RIGHT_JUSTIFIED; break;
  838. X       /* shouldn't happen */
  839. X       default: FIG_justify = T_LEFT_JUSTIFIED; break;
  840. X    }
  841. X    return (TRUE);
  842. X}
  843. X
  844. Xint FIG_text_angle(angle)
  845. X    int angle;
  846. X{
  847. X    if (angle)
  848. X     FIG_angle = Pi / 2.0;    /* vertical is pi/2 radians */
  849. X    else
  850. X     FIG_angle = 0.0;        /* horizontal */
  851. X    return (TRUE);
  852. X}
  853. X
  854. XFIG_reset()
  855. X{
  856. X    FIG_posx = FIG_posy = 0;
  857. X}
  858. *-*-END-of-term/fig.trm-*-*
  859. echo x - term/latex.trm
  860. sed 's/^X//' >term/latex.trm <<'*-*-END-of-term/latex.trm-*-*'
  861. X/* GNUPLOT - latex.trm */
  862. X/*
  863. X * Copyright (C) 1990   
  864. X *
  865. X * Permission to use, copy, and distribute this software and its
  866. X * documentation for any purpose with or without fee is hereby granted, 
  867. X * provided that the above copyright notice appear in all copies and 
  868. X * that both that copyright notice and this permission notice appear 
  869. X * in supporting documentation.
  870. X *
  871. X * Permission to modify the software is granted, but not the right to
  872. X * distribute the modified code.  Modifications are to be distributed 
  873. X * as patches to released version.
  874. X *  
  875. X * This software  is provided "as is" without express or implied warranty.
  876. X * 
  877. X * This file is included by ../term.c.
  878. X *
  879. X * This terminal driver supports:
  880. X *   LaTeX pictures
  881. X *
  882. X * AUTHORS
  883. X *   David Kotz, Russell Lang
  884. X *
  885. X * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
  886. X * 
  887. X */
  888. X
  889. X/* modified to optimize use of \rule for long lines */
  890. X
  891. X/* the following LATEX driver has been modified by 
  892. X   Russell Lang, eln272v@monu1.cc.monash.oz from the
  893. X   GnuTeX 1.3 driver by David Kotz, dfk@cs.duke.edu
  894. X   And further extended by David Kotz  */
  895. X
  896. X
  897. X#define LATEX_PTS_PER_INCH (72.27)
  898. X#define DOTS_PER_INCH (300)    /* resolution of printer we expect to use */
  899. X#define LATEX_UNIT (LATEX_PTS_PER_INCH/DOTS_PER_INCH) /* dot size in pt */
  900. X
  901. X/* 5 inches wide by 3 inches high (default) */
  902. X#define LATEX_XMAX (unsigned int)(LATEX_PTS_PER_INCH/LATEX_UNIT*5.0)
  903. X#define LATEX_YMAX (unsigned int)(LATEX_PTS_PER_INCH/LATEX_UNIT*3.0)
  904. X
  905. X#define LATEX_HTIC (5./LATEX_UNIT)
  906. X#define LATEX_VTIC (5./LATEX_UNIT)
  907. X#define LATEX_HCHAR (5.3/LATEX_UNIT)
  908. X#define LATEX_VCHAR (11./LATEX_UNIT)
  909. X
  910. Xstatic int LATEX_posx;
  911. Xstatic int LATEX_posy;
  912. Xenum JUSTIFY latex_justify=LEFT;
  913. Xstatic int latex_angle=0;
  914. X
  915. X/* Default line-drawing character */
  916. X/* the definition of plotpoint varies with linetype */
  917. X#define LATEX_DOT "\\usebox{\\plotpoint}"
  918. X#define LATEX_TINY_DOT "\\rule{.1pt}{.1pt}" /* for dots plot style */
  919. X
  920. X/* POINTS */
  921. X#define LATEX_POINT_TYPES 12    /* we supply more point types */
  922. Xstatic char *LATEX_points[] = {
  923. X    "\\makebox(0,0){$\\Diamond$}",
  924. X    "\\makebox(0,0){$+$}",
  925. X    "\\makebox(0,0){$\\Box$}",
  926. X    "\\makebox(0,0){$\\times$}",
  927. X    "\\makebox(0,0){$\\triangle$}",
  928. X    "\\makebox(0,0){$\\star$}",
  929. X    "\\circle{12}", "\\circle{18}", "\\circle{24}",
  930. X    "\\circle*{12}", "\\circle*{18}", "\\circle*{24}"
  931. X};
  932. X
  933. X/* LINES */
  934. Xstatic int LATEX_type;        /* negative types use real lines */
  935. X#define LATEX_LINE_TYPES 6    /* number of line types below */
  936. X#define LATEX_THIN_LINE 0    /* the thinnest solid line type */
  937. Xstatic struct {
  938. X    float size;            /* size of dot, or thick of line in points */
  939. X    float dotspace;            /* inter-dot space in points; 0 for lines */
  940. X} LATEX_lines[] = {
  941. X    {.4, 0},                /* thin solid line */
  942. X    {1.0, 0},                /* thick solid line */
  943. X    {2.0, 0},                /* Thick solid line */
  944. X    {.4, 5},                /* dotted line */
  945. X    {.4, 10},                /* widely dotted line */
  946. X    {.4, 15}                /* really widely dotted line */
  947. X};
  948. X/* for drawing dotted and solid lines */
  949. Xstatic void LATEX_dot_line();
  950. Xstatic void LATEX_solid_line();
  951. Xstatic void LATEX_rule();
  952. X#define LATEX_flushrule() LATEX_rule(2, 0.,0.,0.,0.) /* flush old rule */
  953. Xstatic BOOLEAN LATEX_moved = TRUE;    /* pen is up after move */
  954. Xstatic float LATEX_dotsize;    /* size of LATEX_DOT in units */
  955. X
  956. X/* ARROWS */
  957. X/* the set of non-vertical/non-horizontal LaTeX vector slopes */
  958. X/* except negatives - they are handled specially */
  959. Xstatic struct vslope {
  960. X    int dx, dy;
  961. X} LATEX_slopes[] = {
  962. X    {1,1}, {1,2}, {1,3}, {1,4},
  963. X    {2,1}, {2,3},
  964. X    {3,1}, {3,2}, {3,4},
  965. X    {4,1}, {4,3},
  966. X    {0,0}                    /* terminator */
  967. X};
  968. Xstatic void best_latex_arrow(); /* figure out the best arrow */
  969. X
  970. XLATEX_init()
  971. X{
  972. X    LATEX_posx = LATEX_posy = 0;
  973. X    LATEX_linetype(-1);
  974. X    fprintf(outfile, "%% GNUPLOT: LaTeX picture\n");
  975. X    fprintf(outfile, "\\setlength{\\unitlength}{%fpt}\n", LATEX_UNIT);
  976. X}
  977. X
  978. X
  979. XLATEX_scale(xs, ys)
  980. X    float xs, ys;            /* scaling factors */
  981. X{
  982. X    register struct termentry *t = &term_tbl[term];
  983. X
  984. X    /* we change the table for use in graphics.c and LATEX_graphics */
  985. X    t->xmax = (unsigned int)(LATEX_XMAX * xs);
  986. X    t->ymax = (unsigned int)(LATEX_YMAX * ys);
  987. X
  988. X    return(TRUE);
  989. X}
  990. X
  991. XLATEX_graphics()
  992. X{
  993. X    register struct termentry *t = &term_tbl[term];
  994. X
  995. X    fprintf(outfile, "\\begin{picture}(%d,%d)(0,0)\n", t->xmax, t->ymax);
  996. X    fprintf(outfile, "\\tenrm\n");
  997. X    fprintf(outfile, 
  998. X          "\\ifx\\plotpoint\\undefined\\newsavebox{\\plotpoint}\\fi\n");
  999. X}
  1000. X
  1001. X
  1002. XLATEX_text()
  1003. X{
  1004. X    LATEX_flushrule();
  1005. X    fprintf(outfile, "\\end{picture}\n");
  1006. X}
  1007. X
  1008. X
  1009. XLATEX_linetype(linetype)
  1010. X    int linetype;
  1011. X{
  1012. X    if (linetype >= LATEX_LINE_TYPES)
  1013. X     linetype %= LATEX_LINE_TYPES;
  1014. X
  1015. X    LATEX_flushrule();
  1016. X
  1017. X    if (linetype >= 0 && 
  1018. X       LATEX_lines[linetype].size != LATEX_lines[LATEX_type].size) 
  1019. X     /* redefine \plotpoint */
  1020. X     fprintf(outfile, "\\sbox{\\plotpoint}{\\rule[%.3fpt]{%.3fpt}{%.3fpt}}\n",
  1021. X            -LATEX_lines[linetype].size/2,
  1022. X            LATEX_lines[linetype].size,
  1023. X            LATEX_lines[linetype].size);
  1024. X
  1025. X    LATEX_type = linetype;
  1026. X    LATEX_dotsize = LATEX_lines[linetype].size / LATEX_UNIT;
  1027. X    LATEX_moved = TRUE;            /* reset */
  1028. X}
  1029. X
  1030. X
  1031. XLATEX_move(x,y)
  1032. X    unsigned int x,y;
  1033. X{
  1034. X    LATEX_posx = x;
  1035. X    LATEX_posy = y;
  1036. X    LATEX_moved = TRUE;            /* reset */
  1037. X}
  1038. X
  1039. X
  1040. XLATEX_point(x,y, number)        /* version of line_and_point */
  1041. X    unsigned int x,y;
  1042. X    int number;                /* type of point */
  1043. X{
  1044. X    LATEX_move(x,y);
  1045. X    
  1046. X    /* Print the character defined by 'number'; number < 0 means 
  1047. X      to use a dot, otherwise one of the defined points. */
  1048. X    fprintf(outfile, "\\put(%d,%d){%s}\n", x, y, 
  1049. X          (number < 0 ? LATEX_TINY_DOT
  1050. X           : LATEX_points[number % LATEX_POINT_TYPES]));
  1051. X}
  1052. X
  1053. X
  1054. XLATEX_vector(ux,uy)
  1055. X    unsigned int ux,uy;
  1056. X{
  1057. X    /* Negative linestyles are straight lines for frame and axes. */
  1058. X    /* These are vertical and horizontal lines only. */
  1059. X    if (LATEX_type < 0) {
  1060. X       int x=ux, y=uy;
  1061. X       if (x == LATEX_posx) { /* vertical */
  1062. X          fprintf(outfile, "\\put(%d,%d){\\line(0,%d){%d}}\n",
  1063. X                LATEX_posx, LATEX_posy, 
  1064. X                sign(y - LATEX_posy), abs(y - LATEX_posy));
  1065. X       } else if (y == LATEX_posy) { /* horizontal */
  1066. X          fprintf(outfile, "\\put(%d,%d){\\line(%d,0){%d}}\n",
  1067. X                LATEX_posx, LATEX_posy, 
  1068. X                sign(x - LATEX_posx), abs(x - LATEX_posx));
  1069. X       }
  1070. X    } else {                /* drawing real curves */
  1071. X       if (LATEX_lines[LATEX_type].dotspace == 0.0)
  1072. X        LATEX_solid_line(LATEX_posx, (int)ux, LATEX_posy, (int)uy);
  1073. X       else
  1074. X        LATEX_dot_line(LATEX_posx, (int)ux, LATEX_posy, (int)uy);
  1075. X    }
  1076. X    LATEX_posx = ux;
  1077. X    LATEX_posy = uy;
  1078. X}
  1079. X
  1080. Xstatic void
  1081. XLATEX_solid_line(x1,x2, y1,y2)
  1082. X    int x1,x2, y1,y2;
  1083. X{
  1084. X    float slope;
  1085. X    int inc;
  1086. X    float next;
  1087. X    float x,y;
  1088. X    int code;                /* possibly combine with previous rule */
  1089. X
  1090. X    /* we draw a solid line using the thickness for this linetype */
  1091. X    /* we do it with lots of \\rules */
  1092. X
  1093. X    if (x1 == x2 && y1 == y2) { /* zero-length line - just a dot */
  1094. X       if (LATEX_moved) {
  1095. X          LATEX_flushrule();
  1096. X          /* plot a dot */
  1097. X          fprintf(outfile, "\\put(%u,%u){%s}\n", x1, y1, LATEX_DOT);
  1098. X       }
  1099. X    } else {
  1100. X       code = (LATEX_moved ? 0 : 1); /* no combine after move */
  1101. X       if (x1 == x2)        /* vertical line - special case */
  1102. X        LATEX_rule(code, (float)x1, (float)y1, LATEX_dotsize, (float)y2-y1);
  1103. X       else if (y1 == y2)    /* horizontal line - special case */
  1104. X        LATEX_rule(code, (float)x1, (float)y1, (float)x2-x1, LATEX_dotsize);
  1105. X       else {
  1106. X          slope = ((float)y2-y1)/((float)x2-x1);
  1107. X          if (abs(slope) <= 1.0) {
  1108. X             /* longer than high */
  1109. X             inc = sign(y2-y1);
  1110. X             for (x = x1, y = y1; (y2-y)*inc >= 0; y += inc) {
  1111. X                next = inc/slope + x;
  1112. X                if ((x2>x1 && next > x2) || (x2<x1 && next < x2)) {
  1113. X                    LATEX_rule(code, x,y, x2-x, LATEX_dotsize);
  1114. X                    break;
  1115. X                } else {
  1116. X                    LATEX_rule(code, x,y, next-x, LATEX_dotsize);
  1117. X                    x = next;
  1118. X                }
  1119. X                code = 0;
  1120. X             }
  1121. X          } else {
  1122. X             /* higher than long */
  1123. X             inc = sign(x2-x1);
  1124. X             for (x = x1, y = y1; (x2-x)*inc >= 0; x += inc) {
  1125. X                next = inc*slope + y;
  1126. X                if ((y2>y1 && next > y2) || (y2<y1 && next < y2)) {
  1127. X                    LATEX_rule(code, x,y, LATEX_dotsize, y2-y);
  1128. X                    break;
  1129. X                } else {
  1130. X                    LATEX_rule(code, x,y, LATEX_dotsize, next-y);
  1131. X                    y = next;
  1132. X                }
  1133. X                code = 0;
  1134. X             }
  1135. X          }
  1136. X       }
  1137. X    }
  1138. X    LATEX_moved = FALSE;
  1139. X}
  1140. X
  1141. X/* Draw a \rule. Width or height may be negative; we can correct.
  1142. X * The rule is never output immediately. The previous rule is output
  1143. X * as-is if code is 0, and the previous rule is
  1144. X * combined with the current rule (if possible) if code is 1.
  1145. X * The previous rule is output, and the new one ignored, if code is 2.
  1146. X */
  1147. Xstatic void
  1148. XLATEX_rule(code, x,y, width, height)
  1149. X    int code;                /* how do we treat this rule? */
  1150. X    float x, y;
  1151. X    float width;
  1152. X    float height;
  1153. X{  
  1154. X    static float lastx, lasty;
  1155. X    static float lastw, lasth;
  1156. X    static BOOLEAN valid = FALSE; /* is 'last' data valid? */
  1157. X    BOOLEAN combine = (code == 1);
  1158. X    BOOLEAN flush = (code == 2);
  1159. X
  1160. X    if (!flush)
  1161. X     if (width == 0 || height == 0)
  1162. X       return;            /* ignore this rule */
  1163. X
  1164. X    if (width < 0) {
  1165. X       x += width;
  1166. X       width = -width;
  1167. X    }
  1168. X    if (height < 0) {
  1169. X       y += height;
  1170. X       height = -height;
  1171. X    }
  1172. X
  1173. X    if (valid && combine) {
  1174. X       /* try to combine new rule with old rule */
  1175. X       if ((int)lastx == (int)x && lastw == width) { /* vertical rule */
  1176. X          lasth += height;
  1177. X          return;
  1178. X       } else if ((int)lasty == (int)y && lasth == height){ /* horiz rule */
  1179. X          lastw += width;
  1180. X          return;
  1181. X       }
  1182. X       /* oh well, output last and remember the new one */
  1183. X    }
  1184. X
  1185. X    if (valid)
  1186. X     /* if very small use canned dot */
  1187. X     if (lastw < LATEX_dotsize || lasth < LATEX_dotsize)
  1188. X       fprintf(outfile, "\\put(%d,%d){%s}\n",       
  1189. X             (int)lastx, (int)lasty, LATEX_DOT);
  1190. X     else
  1191. X       fprintf(outfile, "\\put(%d,%d){\\rule[%.3fpt]{%.3fpt}{%.3fpt}}\n",
  1192. X             (int)lastx, (int)lasty, -LATEX_dotsize*LATEX_UNIT/2,
  1193. X             lastw*LATEX_UNIT, lasth*LATEX_UNIT);
  1194. X    
  1195. X    if (flush) {
  1196. X       valid = FALSE;
  1197. X    } else {
  1198. X       lastx = x; lasty = y;
  1199. X       lastw = width; lasth = height;
  1200. X       valid = TRUE;
  1201. X    }
  1202. X}
  1203. X
  1204. Xstatic void
  1205. XLATEX_dot_line(x1,x2, y1,y2)
  1206. X    int x1,x2, y1,y2;
  1207. X{
  1208. X    static float LATEX_left;    /* fraction of space left after last dot */
  1209. X    extern double sqrt();
  1210. X
  1211. X    /* we draw a dotted line using the dot spacing for this linetype */
  1212. X
  1213. X    if (LATEX_moved)
  1214. X     LATEX_left = 1.0;        /* reset after a move */
  1215. X
  1216. X    /* zero-length line? */
  1217. X    if (x1 == x2 && y1 == y2) {
  1218. X       if (LATEX_moved)
  1219. X        /* plot a dot */
  1220. X        fprintf(outfile, "\\put(%u,%u){%s}\n", x1, y1, LATEX_DOT);
  1221. X    } else {
  1222. X       float dotspace = LATEX_lines[LATEX_type].dotspace / LATEX_UNIT;
  1223. X       float x,y;            /* current position */
  1224. X       float xinc, yinc;    /* increments */
  1225. X       float slope;        /* slope of line */
  1226. X       float lastx = -1;    /* last x point plotted */
  1227. X       float lasty = -1;    /* last y point plotted */
  1228. X
  1229. X       /* first, figure out increments for x and y */
  1230. X       if (x2 == x1) {
  1231. X          xinc = 0.0;
  1232. X          yinc = dotspace;
  1233. X       } else {
  1234. X          slope = ((float)y2-y1)/((float)x2-x1);
  1235. X          xinc = dotspace / sqrt(1 + slope*slope) * sign(x2-x1);
  1236. X          yinc = slope * xinc;
  1237. X       }
  1238. X
  1239. X       /* now draw the dotted line */
  1240. X       /* we take into account where we last placed a dot */
  1241. X       for (x=x1 + xinc*(1-LATEX_left), y=y1 + yinc*(1-LATEX_left);
  1242. X           (x2-x)*xinc >= 0 && (y2-y)*yinc >= 0; /* same sign or zero */
  1243. X           lastx = x, x += xinc, 
  1244. X           lasty = y, y += yinc)
  1245. X        fprintf(outfile, "\\put(%d,%d){%s}\n", (int)x, (int)y, LATEX_DOT);
  1246. X
  1247. X       /* how much is left over, as a fraction of dotspace? */
  1248. X       if (xinc != 0.0)            /* xinc must be nonzero */
  1249. X        if (lastx >= 0)
  1250. X          LATEX_left = abs(x2 - lastx) / xinc;
  1251. X        else
  1252. X          LATEX_left += abs(x2-x1) / xinc;
  1253. X       else
  1254. X        if (lasty >= 0)
  1255. X          LATEX_left = abs(y2 - lasty) / yinc;
  1256. X        else
  1257. X          LATEX_left += abs(y2-y1) / yinc;
  1258. X    }
  1259. X
  1260. X    LATEX_moved = FALSE;
  1261. X}
  1262. X
  1263. XLATEX_arrow(sx,sy, ex,ey)
  1264. X    int sx,sy, ex,ey;
  1265. X{
  1266. X    best_latex_arrow(sx,sy, ex,ey, 1);
  1267. X
  1268. X    LATEX_posx = ex;
  1269. X    LATEX_posy = ey;
  1270. X}
  1271. X
  1272. Xstatic void best_latex_arrow(sx,sy, ex,ey, who)
  1273. X    int sx,sy, ex,ey;        /* start and end points */
  1274. X    int who;                /* 1=LATEX, 2=EEPIC */
  1275. X{
  1276. X    int dx = ex - sx;
  1277. X    int dy = ey - sy;
  1278. X    int x, y;                /* points near sx,sy */
  1279. X    float m;                /* slope of line */
  1280. X    float arrowslope;        /* slope of arrow */
  1281. X    float minerror;            /* best-case error */
  1282. X    struct vslope *slope;    /* one of the slopes */
  1283. X    struct vslope *bestslope;    /* the slope with min error */
  1284. X    BOOLEAN horiz;            /* was it the horiz line that was best? */
  1285. X
  1286. X    /* We try to draw a real arrow (ie, \vector). If we can't get
  1287. X    * a slope that is close, we draw a bent arrow.
  1288. X    */
  1289. X
  1290. X    if (dx == 0) {
  1291. X       /* vertical arrow */
  1292. X       fprintf(outfile, "\\put(%d,%d){\\vector(0,%d){%d}}\n",
  1293. X             sx, sy, sign(ey-sy), abs(ey-sy));
  1294. X    } else if (dy == 0) {
  1295. X       /* horizontal arrow */
  1296. X       fprintf(outfile, "\\put(%d,%d){\\vector(%d,0){%d}}\n",
  1297. X             sx, sy, sign(ex-sx), abs(ex-sx));
  1298. X    } else {
  1299. X       /* Slanted arrow. We'll give it a try.
  1300. X        * we try to find the closest-slope arrowhead.
  1301. X        */
  1302. X       bestslope = NULL;
  1303. X       m = abs((float)dy/dx); /* the slope we want */
  1304. X       for (slope = LATEX_slopes; slope->dx != 0.0; slope++) {
  1305. X          /* find the slope of the arrow */
  1306. X          arrowslope = (float) slope->dy / slope->dx;
  1307. X          if (bestslope == NULL || abs(m-arrowslope) < minerror) {
  1308. X             minerror = abs(m-arrowslope);
  1309. X             bestslope = slope;
  1310. X          }
  1311. X       }
  1312. X
  1313. X       /* now we have the best slope arrow */
  1314. X       /* maybe it's exactly the right slope! */
  1315. X       if (minerror == 0.0)    /* unlikely but possible */
  1316. X        fprintf(outfile, "\\put(%d,%d){\\vector(%d,%d){%d}}\n",
  1317. X               sx, sy, 
  1318. X               bestslope->dx*sign(ex-sx), bestslope->dy*sign(ey-sy),
  1319. X               abs(ex-sx));
  1320. X       else {
  1321. X          /* we draw the line the usual way, with thin lines */
  1322. X          if (who == 1) {
  1323. X             LATEX_linetype(LATEX_THIN_LINE);
  1324. X             LATEX_solid_line(sx,ex,sy,ey);
  1325. X          }
  1326. X#ifdef EEPIC
  1327. X          else {
  1328. X             EEPIC_move(sx,sy);
  1329. X             EEPIC_vector(ex,ey);
  1330. X          }
  1331. X#endif /* EEPIC */
  1332. X          /* and then draw an arrowhead (a short vector) there */
  1333. X          fprintf(outfile, "\\put(%d,%d){\\vector(%d,%d){0}}\n",
  1334. X                ex, ey, 
  1335. X                bestslope->dx*sign(ex-sx), bestslope->dy*sign(ey-sy));
  1336. X       }
  1337. X    }
  1338. X}
  1339. X
  1340. X
  1341. XLATEX_put_text(x, y, str)
  1342. X    int x,y;                /* reference point of string */
  1343. X    char str[];            /* the text */
  1344. X{
  1345. X    /* ignore empty strings */
  1346. X    if (str[0] == '\0')
  1347. X     return;
  1348. X
  1349. X    fprintf(outfile, "\\put(%d,%d)",x,y);
  1350. X    switch(latex_angle) {  
  1351. X        case 0: {
  1352. X          switch(latex_justify) {
  1353. X             case LEFT: {
  1354. X                fprintf(outfile,
  1355. X                       "{\\makebox(0,0)[l]{%s}}\n", str);
  1356. X                break;
  1357. X             }
  1358. X             case CENTRE: {
  1359. X                fprintf(outfile,
  1360. X                       "{\\makebox(0,0){%s}}\n", str);
  1361. X                break;
  1362. X             }
  1363. X             case RIGHT: {
  1364. X                fprintf(outfile,
  1365. X                       "{\\makebox(0,0)[r]{%s}}\n", str);
  1366. X                break;
  1367. X             }
  1368. X          }
  1369. X          break;
  1370. X       }
  1371. X       case 1: {            /* put text in a short stack */
  1372. X          switch(latex_justify) {
  1373. X             case LEFT: {
  1374. X                fprintf(outfile,
  1375. X                       "{\\makebox(0,0)[lb]{\\shortstack{%s}}}\n", str);
  1376. X                break;
  1377. X             }
  1378. X             case CENTRE: {
  1379. X                fprintf(outfile,
  1380. X                       "{\\makebox(0,0)[l]{\\shortstack{%s}}}\n", str);
  1381. X                break;
  1382. X             }
  1383. X             case RIGHT: {
  1384. X                fprintf(outfile,
  1385. X                       "{\\makebox(0,0)[lt]{\\shortstack{%s}}}\n", str);
  1386. X                break;
  1387. X             }
  1388. X          }
  1389. X          break;
  1390. X       }    
  1391. X    }
  1392. X}
  1393. X
  1394. X
  1395. X
  1396. Xint LATEX_justify_text(mode)
  1397. X    enum JUSTIFY mode;
  1398. X{
  1399. X    latex_justify = mode;
  1400. X    return (TRUE);
  1401. X}
  1402. X
  1403. Xint LATEX_text_angle(angle)
  1404. X    int angle;
  1405. X{
  1406. X    /* we can't really write text vertically, but this will 
  1407. X      put the ylabel centred at the left of the plot, and
  1408. X      then we'll make a \shortstack */
  1409. X    latex_angle = angle;
  1410. X    return (TRUE);
  1411. X}
  1412. X
  1413. XLATEX_reset()
  1414. X{
  1415. X    LATEX_posx = LATEX_posy = 0;
  1416. X}
  1417. X
  1418. *-*-END-of-term/latex.trm-*-*
  1419. echo x - term/eepic.trm
  1420. sed 's/^X//' >term/eepic.trm <<'*-*-END-of-term/eepic.trm-*-*'
  1421. X/* GNUPLOT - eepic.trm */
  1422. X/*
  1423. X * Copyright (C) 1990   
  1424. X *
  1425. X * Permission to use, copy, and distribute this software and its
  1426. X * documentation for any purpose with or without fee is hereby granted, 
  1427. X * provided that the above copyright notice appear in all copies and 
  1428. X * that both that copyright notice and this permission notice appear 
  1429. X * in supporting documentation.
  1430. X *
  1431. X * Permission to modify the software is granted, but not the right to
  1432. X * distribute the modified code.  Modifications are to be distributed 
  1433. X * as patches to released version.
  1434. X *  
  1435. X * This software  is provided "as is" without express or implied warranty.
  1436. X * 
  1437. X * This file is included by ../term.c.
  1438. X *
  1439. X * This terminal driver supports:
  1440. X *   The EEPIC macros for LaTeX. 
  1441. X *
  1442. X * AUTHORS
  1443. X *   David Kotz
  1444. X *
  1445. X * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
  1446. X * 
  1447. X */
  1448. X/*
  1449. X *  This file contains the eepic terminal driver, intended for use with the 
  1450. X *  eepic.sty macro package for LaTeX. This is an alternative to the 
  1451. X *  latex driver. You need eepic.sty, epic.sty, and a printer driver that
  1452. X *  supports the tpic \specials.
  1453. X *
  1454. X * Although dotted and dashed lines are possible with EEPIC, and are
  1455. X * tempting, they do not work well for high-sample-rate curves, mushing
  1456. X * the dashes all together into a solid line. For now anyway, the EEPIC
  1457. X * driver will have only solid lines. Anyone got a solution?
  1458. X *
  1459. X * LATEX must also be defined.
  1460. X */
  1461. X
  1462. X#define EEPIC_PTS_PER_INCH (72.27)
  1463. X#define DOTS_PER_INCH (300)    /* resolution of printer we expect to use */
  1464. X#define EEPIC_UNIT (EEPIC_PTS_PER_INCH/DOTS_PER_INCH) /* dot size in pt */
  1465. X
  1466. X/* 5 inches wide by 3 inches high (default) */
  1467. X#define EEPIC_XMAX (unsigned int)(EEPIC_PTS_PER_INCH/EEPIC_UNIT*5.0)
  1468. X#define EEPIC_YMAX (unsigned int)(EEPIC_PTS_PER_INCH/EEPIC_UNIT*3.0)
  1469. X
  1470. X#define EEPIC_HTIC (5./EEPIC_UNIT)
  1471. X#define EEPIC_VTIC (5./EEPIC_UNIT)
  1472. X#define EEPIC_HCHAR (5.3/EEPIC_UNIT)
  1473. X#define EEPIC_VCHAR (11./EEPIC_UNIT)
  1474. X
  1475. Xstatic unsigned int EEPIC_posx;
  1476. Xstatic unsigned int EEPIC_posy;
  1477. Xenum JUSTIFY eepic_justify=LEFT;
  1478. Xstatic int eepic_angle=0;
  1479. X
  1480. X/* for DOTS point style */
  1481. X#define EEPIC_TINY_DOT "\\rule{.1pt}{.1pt}"
  1482. X
  1483. X/* POINTS */
  1484. X#define EEPIC_POINT_TYPES 12    /* we supply more point types */
  1485. Xstatic char *EEPIC_points[] = {
  1486. X    "\\makebox(0,0){$\\Diamond$}",
  1487. X    "\\makebox(0,0){$+$}",
  1488. X    "\\makebox(0,0){$\\Box$}",
  1489. X    "\\makebox(0,0){$\\times$}",
  1490. X    "\\makebox(0,0){$\\triangle$}",
  1491. X    "\\makebox(0,0){$\\star$}",
  1492. X    "\\circle{12}", "\\circle{18}", "\\circle{24}",
  1493. X    "\\circle*{12}", "\\circle*{18}", "\\circle*{24}"
  1494. X};
  1495. X
  1496. X/* LINES */
  1497. X#define EEPIC_NUMLINES 5        /* number of linetypes below */
  1498. Xstatic char *EEPIC_lines[] = {
  1499. X    "\\thicklines \\path",            /* -2 border */
  1500. X    "\\thinlines \\drawline[-50]",        /* -1 axes */
  1501. X    "\\thinlines \\path",            /*  0 solid thin  */
  1502. X    "\\thicklines \\path",            /*  1 solid thick */
  1503. X    "\\Thicklines \\path",            /*  2 solid Thick */
  1504. X};
  1505. X/* These are other possibilities
  1506. X    "\\thinlines \\dottedline{30}",
  1507. X    "\\thinlines \\drawline[-30]",    
  1508. X    "\\thinlines \\dottedline{60}",
  1509. X    "\\thinlines \\drawline[-60]",    
  1510. X    "\\thinlines \\dashline[-10]{20}[6]"
  1511. X*/
  1512. Xstatic int EEPIC_type;        /* current line type */
  1513. Xstatic BOOLEAN EEPIC_inline = FALSE; /* are we in the middle of a line */
  1514. Xstatic void EEPIC_endline();    /* terminate any line in progress */
  1515. X
  1516. X/* ARROWS */
  1517. X/* we use the same code as for LATEX */
  1518. Xstatic void best_latex_arrow(); /* figure out the best arrow */
  1519. X
  1520. XEEPIC_init()
  1521. X{
  1522. X    EEPIC_posx = EEPIC_posy = 0;
  1523. X    EEPIC_linetype(-1);
  1524. X    fprintf(outfile, "%% GNUPLOT: LaTeX picture using EEPIC macros\n");
  1525. X    fprintf(outfile, "\\setlength{\\unitlength}{%fpt}\n", EEPIC_UNIT);
  1526. X}
  1527. X
  1528. X
  1529. XEEPIC_scale(xs, ys)
  1530. X    float xs, ys;            /* scaling factors */
  1531. X{
  1532. X    register struct termentry *t = &term_tbl[term];
  1533. X
  1534. X    /* we change the table for use in graphics.c and EEPIC_graphics */
  1535. X    t->xmax = (unsigned int)(EEPIC_XMAX * xs);
  1536. X    t->ymax = (unsigned int)(EEPIC_YMAX * ys);
  1537. X
  1538. X    return(TRUE);
  1539. X}
  1540. X
  1541. XEEPIC_graphics()
  1542. X{
  1543. X    register struct termentry *t = &term_tbl[term];
  1544. X
  1545. X    fprintf(outfile, "\\begin{picture}(%d,%d)(0,0)\n", t->xmax, t->ymax);
  1546. X    fprintf(outfile, "\\tenrm\n");
  1547. X}
  1548. X
  1549. X
  1550. XEEPIC_text()
  1551. X{
  1552. X    EEPIC_endline();
  1553. X    fprintf(outfile, "\\end{picture}\n");
  1554. X}
  1555. X
  1556. X
  1557. XEEPIC_linetype(linetype)
  1558. X    int linetype;
  1559. X{
  1560. X    EEPIC_endline();
  1561. X
  1562. X    if (linetype >= EEPIC_NUMLINES-2)
  1563. X     linetype %= (EEPIC_NUMLINES-2);
  1564. X
  1565. X    EEPIC_type = linetype;
  1566. X}
  1567. X
  1568. X
  1569. X
  1570. XEEPIC_move(x,y)
  1571. X    unsigned int x,y;
  1572. X{
  1573. X    EEPIC_endline();
  1574. X
  1575. X    EEPIC_posx = x;
  1576. X    EEPIC_posy = y;
  1577. X}
  1578. X
  1579. X
  1580. XEEPIC_point(x,y, number)        /* version of line_and_point */
  1581. X    unsigned int x,y;
  1582. X    int number;                /* type of point */
  1583. X{
  1584. X    EEPIC_move(x,y);
  1585. X    
  1586. X    /* Print the character defined by 'number'; number < 0 means 
  1587. X      to use a dot, otherwise one of the defined points. */
  1588. X    fprintf(outfile, "\\put(%d,%d){%s}\n", x, y, 
  1589. X          (number < 0 ? EEPIC_TINY_DOT
  1590. X           : EEPIC_points[number % EEPIC_POINT_TYPES]));
  1591. X}
  1592. X
  1593. X
  1594. XEEPIC_vector(ux,uy)
  1595. X    unsigned int ux,uy;
  1596. X{
  1597. X    if (!EEPIC_inline) {
  1598. X       EEPIC_inline = TRUE;
  1599. X
  1600. X       /* Start a new line. This depends on line type */
  1601. X       fprintf(outfile, "%s(%u,%u)", 
  1602. X             EEPIC_lines[EEPIC_type+2], 
  1603. X             EEPIC_posx, EEPIC_posy);
  1604. X    }
  1605. X
  1606. X    /* add new point to line */
  1607. X    fprintf(outfile, "(%u,%u)", ux,uy);
  1608. X    EEPIC_posx = ux;
  1609. X    EEPIC_posy = uy;
  1610. X}
  1611. X
  1612. Xstatic void
  1613. XEEPIC_endline()
  1614. X{
  1615. X    if (EEPIC_inline) {
  1616. X       fprintf(outfile, "\n");
  1617. X       EEPIC_inline = FALSE;
  1618. X    }
  1619. X}
  1620. X
  1621. X
  1622. XEEPIC_arrow(sx,sy, ex,ey)
  1623. X    int sx,sy, ex,ey;
  1624. X{
  1625. X    best_latex_arrow(sx,sy, ex,ey, 2); /* call latex routine */
  1626. X
  1627. X    EEPIC_posx = ex;
  1628. X    EEPIC_posy = ey;
  1629. X}
  1630. X
  1631. X
  1632. XEEPIC_put_text(x, y, str)
  1633. X    int x,y;                /* reference point of string */
  1634. X    char str[];            /* the text */
  1635. X{
  1636. X    EEPIC_endline();
  1637. X
  1638. X    fprintf(outfile, "\\put(%d,%d)",x,y);
  1639. X    switch(eepic_angle) {  
  1640. X        case 0: {
  1641. X          switch(eepic_justify) {
  1642. X             case LEFT: {
  1643. X                fprintf(outfile,
  1644. X                       "{\\makebox(0,0)[l]{%s}}\n", str);
  1645. X                break;
  1646. X             }
  1647. X             case CENTRE: {
  1648. X                fprintf(outfile,
  1649. X                       "{\\makebox(0,0){%s}}\n", str);
  1650. X                break;
  1651. X             }
  1652. X             case RIGHT: {
  1653. X                fprintf(outfile,
  1654. X                       "{\\makebox(0,0)[r]{%s}}\n", str);
  1655. X                break;
  1656. X             }
  1657. X          }
  1658. X          break;
  1659. X       }
  1660. X       case 1: {            /* put text in a short stack */
  1661. X          switch(eepic_justify) {
  1662. X             case LEFT: {
  1663. X                fprintf(outfile,
  1664. X                       "{\\makebox(0,0)[lb]{\\shortstack{%s}}}\n", str);
  1665. X                break;
  1666. X             }
  1667. X             case CENTRE: {
  1668. X                fprintf(outfile,
  1669. X                       "{\\makebox(0,0)[l]{\\shortstack{%s}}}\n", str);
  1670. X                break;
  1671. X             }
  1672. X             case RIGHT: {
  1673. X                fprintf(outfile,
  1674. X                       "{\\makebox(0,0)[lt]{\\shortstack{%s}}}\n", str);
  1675. X                break;
  1676. X             }
  1677. X          }
  1678. X          break;
  1679. X       }    
  1680. X    }
  1681. X}
  1682. X
  1683. X
  1684. X
  1685. Xint EEPIC_justify_text(mode)
  1686. X    enum JUSTIFY mode;
  1687. X{
  1688. X    eepic_justify = mode;
  1689. X    return (TRUE);
  1690. X}
  1691. X
  1692. Xint EEPIC_text_angle(angle)
  1693. X    int angle;
  1694. X{
  1695. X    /* we can't really write text vertically, but this will 
  1696. X      put the ylabel centred at the left of the plot, and
  1697. X      then we'll make a \shortstack */
  1698. X    eepic_angle = angle;
  1699. X    return (TRUE);
  1700. X}
  1701. X
  1702. XEEPIC_reset()
  1703. X{
  1704. X    EEPIC_endline();
  1705. X    EEPIC_posx = EEPIC_posy = 0;
  1706. X}
  1707. X
  1708. *-*-END-of-term/eepic.trm-*-*
  1709. exit
  1710.  
  1711.  
  1712.