home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 334_01 / eepic.trm < prev    next >
Text File  |  1991-02-05  |  8KB  |  301 lines

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