home *** CD-ROM | disk | FTP | other *** search
/ CICA 1995 May / cica_0595_4.zip / cica_0595_4 / UTIL / GPT34SRC / TERM / EEPIC.TRM < prev    next >
Text File  |  1993-05-11  |  8KB  |  307 lines

  1. /*
  2.  * $Id: eepic.trm%v 3.38.2.125 1993/05/05 00:02:28 woo Exp woo $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - eepic.trm */
  7. /*
  8.  * Copyright (C) 1990 - 1993   
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted, 
  12.  * provided that the above copyright notice appear in all copies and 
  13.  * that both that copyright notice and this permission notice appear 
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed 
  18.  * as patches to released version.
  19.  *  
  20.  * This software  is provided "as is" without express or implied warranty.
  21.  * 
  22.  * This file is included by ../term.c.
  23.  *
  24.  * This terminal driver supports:
  25.  *   The EEPIC macros for LaTeX. 
  26.  *
  27.  * AUTHORS
  28.  *   David Kotz
  29.  *
  30.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  31.  * 
  32.  */
  33. /*
  34.  *  This file contains the eepic terminal driver, intended for use with the 
  35.  *  eepic.sty macro package for LaTeX. This is an alternative to the 
  36.  *  latex driver. You need eepic.sty, epic.sty, and a printer driver that
  37.  *  supports the tpic \specials.
  38.  *
  39.  * Although dotted and dashed lines are possible with EEPIC, and are
  40.  * tempting, they do not work well for high-sample-rate curves, mushing
  41.  * the dashes all together into a solid line. For now anyway, the EEPIC
  42.  * driver will have only solid lines. Anyone got a solution?
  43.  *
  44.  * LATEX must also be defined.
  45.  */
  46.  
  47. #define EEPIC_PTS_PER_INCH (72.27)
  48. #define DOTS_PER_INCH (300)    /* resolution of printer we expect to use */
  49. #define EEPIC_UNIT (EEPIC_PTS_PER_INCH/DOTS_PER_INCH) /* dot size in pt */
  50.  
  51. /* 5 inches wide by 3 inches high (default) */
  52. #define EEPIC_XMAX (5*DOTS_PER_INCH)  /* (EEPIC_PTS_PER_INCH/EEPIC_UNIT*5.0) */
  53. #define EEPIC_YMAX (3*DOTS_PER_INCH)  /* (EEPIC_PTS_PER_INCH/EEPIC_UNIT*3.0) */
  54.  
  55. #define EEPIC_HTIC (5*DOTS_PER_INCH/72)        /* (5./EEPIC_UNIT) */
  56. #define EEPIC_VTIC (5*DOTS_PER_INCH/72)        /* (5./EEPIC_UNIT) */
  57. #define EEPIC_HCHAR (DOTS_PER_INCH*53/10/72)    /* (5.3/EEPIC_UNIT) */
  58. #define EEPIC_VCHAR (DOTS_PER_INCH*11/72)    /* (11./EEPIC_UNIT) */
  59.  
  60. static unsigned int EEPIC_posx;
  61. static unsigned int EEPIC_posy;
  62. enum JUSTIFY eepic_justify=LEFT;
  63. static int eepic_angle=0;
  64.  
  65. /* for DOTS point style */
  66. #define EEPIC_TINY_DOT "\\rule{.1pt}{.1pt}"
  67.  
  68. /* POINTS */
  69. #define EEPIC_POINT_TYPES 12    /* we supply more point types */
  70. static char GPFAR * GPFAR EEPIC_points[] = {
  71.     "\\raisebox{-1.2pt}{\\makebox(0,0){$\\Diamond$}}",
  72.     "\\makebox(0,0){$+$}",
  73.     "\\raisebox{-1.2pt}{\\makebox(0,0){$\\Box$}}",
  74.     "\\makebox(0,0){$\\times$}",
  75.     "\\makebox(0,0){$\\triangle$}",
  76.     "\\makebox(0,0){$\\star$}",
  77.     "\\circle{12}", "\\circle{18}", "\\circle{24}",
  78.     "\\circle*{12}", "\\circle*{18}", "\\circle*{24}"
  79. };
  80.  
  81. /* LINES */
  82. #define EEPIC_NUMLINES 5        /* number of linetypes below */
  83. static char GPFAR * GPFAR EEPIC_lines[] = {
  84.     "\\thicklines \\path",            /* -2 border */
  85.     "\\thinlines \\drawline[-50]",        /* -1 axes */
  86.     "\\thinlines \\path",            /*  0 solid thin  */
  87.     "\\thicklines \\path",            /*  1 solid thick */
  88.     "\\Thicklines \\path",            /*  2 solid Thick */
  89. };
  90. /* These are other possibilities
  91.     "\\thinlines \\dottedline{30}",
  92.     "\\thinlines \\drawline[-30]",    
  93.     "\\thinlines \\dottedline{60}",
  94.     "\\thinlines \\drawline[-60]",    
  95.     "\\thinlines \\dashline[-10]{20}[6]"
  96. */
  97. static int EEPIC_type;        /* current line type */
  98. static TBOOLEAN EEPIC_inline = FALSE; /* are we in the middle of a line */
  99. static void EEPIC_endline();    /* terminate any line in progress */
  100. static int EEPIC_linecount = 0; /* number of points in line so far */
  101. #define EEPIC_LINEMAX 50        /* max value for linecount */
  102.  
  103. /* ARROWS */
  104. /* we use the same code as for LATEX */
  105. static void best_latex_arrow(); /* figure out the best arrow */
  106.  
  107. EEPIC_init()
  108. {
  109.     EEPIC_posx = EEPIC_posy = 0;
  110.     EEPIC_linetype(-1);
  111.     fprintf(outfile, "%% GNUPLOT: LaTeX picture using EEPIC macros\n");
  112.     fprintf(outfile, "\\setlength{\\unitlength}{%fpt}\n", EEPIC_UNIT);
  113. }
  114.  
  115.  
  116. EEPIC_scale(xs, ys)
  117.     double xs, ys;            /* scaling factors */
  118. {
  119.     register struct termentry *t = &term_tbl[term];
  120.  
  121.     /* we change the table for use in graphics.c and EEPIC_graphics */
  122.     t->xmax = (unsigned int)(EEPIC_XMAX * xs);
  123.     t->ymax = (unsigned int)(EEPIC_YMAX * ys);
  124.  
  125.     return(TRUE);
  126. }
  127.  
  128. EEPIC_graphics()
  129. {
  130.     register struct termentry *t = &term_tbl[term];
  131.  
  132.     fprintf(outfile, "\\begin{picture}(%d,%d)(0,0)\n", t->xmax, t->ymax);
  133.     fprintf(outfile, "\\tenrm\n");
  134. }
  135.  
  136.  
  137. EEPIC_text()
  138. {
  139.     EEPIC_endline();
  140.     fprintf(outfile, "\\end{picture}\n");
  141. }
  142.  
  143.  
  144. EEPIC_linetype(linetype)
  145.     int linetype;
  146. {
  147.     EEPIC_endline();
  148.  
  149.     if (linetype >= EEPIC_NUMLINES-2)
  150.      linetype %= (EEPIC_NUMLINES-2);
  151.  
  152.     EEPIC_type = linetype;
  153. }
  154.  
  155.  
  156.  
  157. EEPIC_move(x,y)
  158.     unsigned int x,y;
  159. {
  160.     EEPIC_endline();
  161.  
  162.     EEPIC_posx = x;
  163.     EEPIC_posy = y;
  164. }
  165.  
  166.  
  167. EEPIC_point(x,y, number)        /* version of line_and_point */
  168.     unsigned int x,y;
  169.     int number;                /* type of point */
  170. {
  171.     EEPIC_move(x,y);
  172.     
  173.     /* Print the character defined by 'number'; number < 0 means 
  174.       to use a dot, otherwise one of the defined points. */
  175.     fprintf(outfile, "\\put(%d,%d){%s}\n", x, y, 
  176.           (number < 0 ? EEPIC_TINY_DOT
  177.            : EEPIC_points[number % EEPIC_POINT_TYPES]));
  178. }
  179.  
  180.  
  181. EEPIC_vector(ux,uy)
  182.     unsigned int ux,uy;
  183. {
  184.     if (!EEPIC_inline) {
  185.        EEPIC_inline = TRUE;
  186.  
  187.        /* Start a new line. This depends on line type */
  188.        fprintf(outfile, "%s(%u,%u)", 
  189.              EEPIC_lines[EEPIC_type+2], 
  190.              EEPIC_posx, EEPIC_posy);
  191.        EEPIC_linecount = 1;
  192.     } else {
  193.        /* Even though we are in middle of a path, 
  194.         * we may want to start a new path command. 
  195.         * If they are too long then latex will choke.
  196.         */
  197.        if (EEPIC_linecount++ >= EEPIC_LINEMAX) {
  198.           fprintf(outfile, "\n");
  199.           fprintf(outfile, "%s(%u,%u)", 
  200.                 EEPIC_lines[EEPIC_type+2], 
  201.                 EEPIC_posx, EEPIC_posy);
  202.           EEPIC_linecount = 1;
  203.        }
  204.     }
  205.     fprintf(outfile, "(%u,%u)", ux,uy);
  206.     EEPIC_posx = ux;
  207.     EEPIC_posy = uy;
  208. }
  209.  
  210. static void
  211. EEPIC_endline()
  212. {
  213.     if (EEPIC_inline) {
  214.        fprintf(outfile, "\n");
  215.        EEPIC_inline = FALSE;
  216.     }
  217. }
  218.  
  219.  
  220. EEPIC_arrow(sx,sy, ex,ey, head)
  221.     int sx,sy, ex,ey;
  222.     TBOOLEAN head;
  223. {
  224.     best_latex_arrow(sx,sy, ex,ey, 2, head); /* call latex routine */
  225.  
  226.     EEPIC_posx = ex;
  227.     EEPIC_posy = ey;
  228. }
  229.  
  230.  
  231. EEPIC_put_text(x, y, str)
  232.     int x,y;                /* reference point of string */
  233.     char str[];            /* the text */
  234. {
  235.     EEPIC_endline();
  236.  
  237.     fprintf(outfile, "\\put(%d,%d)",x,y);
  238.     switch(eepic_angle) {  
  239.         case 0: {
  240.           switch(eepic_justify) {
  241.              case LEFT: {
  242.                 fprintf(outfile,
  243.                        "{\\makebox(0,0)[l]{%s}}\n", str);
  244.                 break;
  245.              }
  246.              case CENTRE: {
  247.                 fprintf(outfile,
  248.                        "{\\makebox(0,0){%s}}\n", str);
  249.                 break;
  250.              }
  251.              case RIGHT: {
  252.                 fprintf(outfile,
  253.                        "{\\makebox(0,0)[r]{%s}}\n", str);
  254.                 break;
  255.              }
  256.           }
  257.           break;
  258.        }
  259.        case 1: {            /* put text in a short stack */
  260.           switch(eepic_justify) {
  261.              case LEFT: {
  262.                 fprintf(outfile,
  263.                        "{\\makebox(0,0)[lb]{\\shortstack{%s}}}\n", str);
  264.                 break;
  265.              }
  266.              case CENTRE: {
  267.                 fprintf(outfile,
  268.                        "{\\makebox(0,0)[l]{\\shortstack{%s}}}\n", str);
  269.                 break;
  270.              }
  271.              case RIGHT: {
  272.                 fprintf(outfile,
  273.                        "{\\makebox(0,0)[lt]{\\shortstack{%s}}}\n", str);
  274.                 break;
  275.              }
  276.           }
  277.           break;
  278.        }    
  279.     }
  280. }
  281.  
  282.  
  283.  
  284. int EEPIC_justify_text(mode)
  285.     enum JUSTIFY mode;
  286. {
  287.     eepic_justify = mode;
  288.     return (TRUE);
  289. }
  290.  
  291. int EEPIC_text_angle(angle)
  292.     int angle;
  293. {
  294.     /* we can't really write text vertically, but this will 
  295.       put the ylabel centred at the left of the plot, and
  296.       then we'll make a \shortstack */
  297.     eepic_angle = angle;
  298.     return (TRUE);
  299. }
  300.  
  301. EEPIC_reset()
  302. {
  303.     EEPIC_endline();
  304.     EEPIC_posx = EEPIC_posy = 0;
  305. }
  306.  
  307.