home *** CD-ROM | disk | FTP | other *** search
/ CICA 1995 May / cica_0595_4.zip / cica_0595_4 / UTIL / GPT34SRC / TERM / TEXDRAW.TRM (.txt) < prev    next >
LaTeX Document  |  1993-05-11  |  8KB  |  213 lines

  1.  * $Id: texdraw.trm%v 3.38.2.125 1993/05/05 00:13:05 woo Exp woo $
  2. /* GNUPLOT - texdraw.trm */
  3.  * Copyright (C) 1990
  4.  * Permission to use, copy, and distribute this software and its
  5.  * documentation for any purpose with or without fee is hereby granted,
  6.  * provided that the above copyright notice appear in all copies and
  7.  * that both that copyright notice and this permission notice appear
  8.  * in supporting documentation.
  9.  * Permission to modify the software is granted, but not the right to
  10.  * distribute the modified code.  Modifications are to be distributed
  11.  * as patches to released version.
  12.  * This software  is provided "as is" without express or implied warranty.
  13.  * This file is included by ../term.c.
  14.  * This terminal driver supports:
  15.  *   The TEXDRAW macros for LaTeX.
  16.  * AUTHORS
  17.  *   Khun Yee Fung. Modified from eepic.trm.
  18.  *   clipper@csd.uwo.ca
  19.  *   January 20, 1992
  20.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  21.  *  This file contains the texdraw terminal driver, intended for use with the
  22.  *  texdraw macro package for LaTeX. This is an alternative to the
  23.  *  latex driver. You need texdraw.sty, and texdraw.tex in the texdraw package.
  24. #define TEXDRAW_PTS_PER_INCH (72.27)
  25. #define DOTS_PER_INCH (300)    /* resolution of printer we expect to use */
  26. #define TEXDRAW_UNIT (TEXDRAW_PTS_PER_INCH/DOTS_PER_INCH) /* dot size in pt */
  27. /* 5 inches wide by 3 inches high (default) */
  28. #define TEXDRAW_XMAX (5*DOTS_PER_INCH)
  29. #define TEXDRAW_YMAX (3*DOTS_PER_INCH)
  30. #define TEXDRAW_HTIC (5*DOTS_PER_INCH/72)    /* (5./TEXDRAW_UNIT) */
  31. #define TEXDRAW_VTIC (5*DOTS_PER_INCH/72)    /* (5./TEXDRAW_UNIT) */
  32. #define TEXDRAW_HCHAR (DOTS_PER_INCH*53/10/72)    /* (5.3/TEXDRAW_UNIT) */
  33. #define TEXDRAW_VCHAR (DOTS_PER_INCH*11/72)    /* (11./TEXDRAW_UNIT) */
  34. static unsigned int TEXDRAW_posx;
  35. static unsigned int TEXDRAW_posy;
  36. enum JUSTIFY TEXDRAW_justify = LEFT;
  37. enum JUSTIFY TEXDRAW_last_justify = LEFT;
  38. static int TEXDRAW_angle = 0;
  39. static float TEXDRAW_scalefactor = 0.2409;
  40. static double TEXDRAW_xscale = 1.0, TEXDRAW_yscale = 1.0;
  41. /* for DOTS point style */
  42. #define TEXDRAW_TINY_DOT "\\htext{$\\cdot$}"
  43. /* POINTS */
  44. #define TEXDRAW_POINT_TYPES 12    /* we supply more point types */
  45. static char GPFAR * GPFAR TEXDRAW_points[] =
  46.   "\\rmove(0 4)\\htext{$\\Diamond$}",
  47.   "\\htext{$+$}",
  48.   "\\rmove(0 4)\\htext{$\\Box$}",
  49.   "\\htext{$\\times$}",
  50.   "\\htext{$\\triangle$}",
  51.   "\\htext{$\\star$}",
  52.   "\\lcir f:9",
  53.   "\\lcir f:12",
  54.   "\\lcir f:16",
  55.   "\\fcir f:0.9 r:9",
  56.   "\\fcir f:0.9 r:12",
  57.   "\\fcir f:0.9 r:16"
  58. /* LINES */
  59. #define TEXDRAW_NUMLINES 5    /* number of linetypes below */
  60. static int TEXDRAW_lines[] =
  61.   4,        /* -2 border */
  62.   3,        /* -1 axes */
  63.   3,        /*  0 solid thin  */
  64.   4,        /*  1 solid thick */
  65.   6,        /*  2 solid Thick */
  66. static int TEXDRAW_last_type = 0; /* The line type selected most recently */
  67. static int TEXDRAW_type;    /* current line type */
  68. static TBOOLEAN TEXDRAW_inline = FALSE;    /* are we in the middle of a line */
  69. static void TEXDRAW_endline();    /* terminate any line in progress */
  70. static int TEXDRAW_linecount = 0;    /* number of points in line so far */
  71. #define TEXDRAW_LINEMAX 5    /* max value for linecount */
  72. TEXDRAW_init()
  73.   TEXDRAW_posx = TEXDRAW_posy = 0;
  74.   TEXDRAW_linetype(-1);
  75.   fprintf(outfile, "%% GNUPLOT: LaTeX using TEXDRAW macros\n");
  76. TEXDRAW_scale(xs, ys)
  77. double xs, ys;            /* scaling factors */
  78.   register struct termentry *t = &term_tbl[term];
  79.   /* we change the table for use in graphics.c */
  80.   t->xmax = (unsigned int) (TEXDRAW_XMAX * xs);
  81.   t->ymax = (unsigned int) (TEXDRAW_YMAX * ys);
  82.   TEXDRAW_xscale = xs;
  83.   TEXDRAW_yscale = ys;
  84.   return (TRUE);
  85. TEXDRAW_graphics()
  86. static char GPFAR tdg1[] = "\
  87. \\begin{texdraw}\n\
  88. \\normalsize\n\
  89. \\ifx\\pathDEFINED\\relax\\else\\let\\pathDEFINED\\relax\n\
  90.  \\def\\QtGfr{\\ifx (\\TGre \\let\\YhetT\\cpath\\else\\let\\YhetT\\relax\\fi\\YhetT}\n\
  91.  \\def\\path (#1 #2){\\move (#1 #2)\\futurelet\\TGre\\QtGfr}\n\
  92.  \\def\\cpath (#1 #2){\\lvec (#1 #2)\\futurelet\\TGre\\QtGfr}\n\
  93. \\fi\n\
  94. \\drawdim pt\n\
  95. \\setunitscale %2.2f\n\
  96. \\linewd %d\n\
  97. \\textref h:L v:C\n";
  98.   fprintf(outfile, tdg1, 
  99.     TEXDRAW_scalefactor,
  100.     TEXDRAW_lines[2]);
  101.   TEXDRAW_last_type = 0;
  102.   TEXDRAW_type = 0;
  103. TEXDRAW_text()
  104.   TEXDRAW_endline();
  105.   fprintf(outfile, "\\end{texdraw}\n");
  106. TEXDRAW_linetype(linetype)
  107. int linetype;
  108.   TEXDRAW_endline();
  109.   if (linetype >= TEXDRAW_NUMLINES - 2)
  110.     linetype %= (TEXDRAW_NUMLINES - 2);
  111.   TEXDRAW_type = linetype;
  112. TEXDRAW_move(x, y)
  113. unsigned int x, y;
  114.   TEXDRAW_endline();
  115.   TEXDRAW_posx = x;
  116.   TEXDRAW_posy = y;
  117. TEXDRAW_point(x, y, number)
  118. unsigned int x, y;
  119. int number;
  120.   TEXDRAW_move(x, y);
  121.   /* Print the character defined by 'number'; number < 0 means
  122.         to use a dot, otherwise one of the defined points. */
  123.   fprintf(outfile, "\\move (%d %d)\n",
  124.       (int)((double) x * TEXDRAW_xscale),
  125.       (int)((double) y * TEXDRAW_yscale));
  126.   if (TEXDRAW_last_justify != CENTRE) {
  127.     fprintf(outfile, "\\textref h:C v:C ");
  128.     TEXDRAW_last_justify = CENTRE;
  129.   fprintf(outfile, "%s\n",
  130.       (number < 0 ?
  131.        TEXDRAW_TINY_DOT :
  132.        TEXDRAW_points[number % TEXDRAW_POINT_TYPES]));
  133. TEXDRAW_vector(ux, uy)
  134. unsigned int ux, uy;
  135.   if (!TEXDRAW_inline) {
  136.     TEXDRAW_inline = TRUE;
  137.     /* Start a new line. This depends on line type */
  138.     if (TEXDRAW_type != TEXDRAW_last_type){
  139.       if (TEXDRAW_lines[TEXDRAW_type+2] != TEXDRAW_lines[TEXDRAW_last_type+2])
  140.     fprintf(outfile, "\\linewd %d\n", TEXDRAW_lines[TEXDRAW_type + 2]);
  141.       TEXDRAW_last_type = TEXDRAW_type;
  142.     }
  143.     fprintf(outfile, "\\path (%d %d)",
  144.         (int)((double) TEXDRAW_posx * TEXDRAW_xscale),
  145.         (int)((double) TEXDRAW_posy * TEXDRAW_yscale));
  146.     TEXDRAW_linecount = 1;
  147.   else {
  148.     /* Even though we are in middle of a path,
  149.      * we may want to start a new path command.
  150.      * If they are too long then latex will choke.
  151.      */
  152.     if (TEXDRAW_linecount++ >= TEXDRAW_LINEMAX) {
  153.       fprintf(outfile, "\n\\cpath ");
  154.       TEXDRAW_linecount = 1;
  155.     }
  156.   fprintf(outfile, "(%d %d)",
  157.       (int)((double) ux * TEXDRAW_xscale),
  158.       (int)((double) uy * TEXDRAW_yscale));
  159.   TEXDRAW_posx = ux;
  160.   TEXDRAW_posy = uy;
  161. static void TEXDRAW_endline()
  162.   if (TEXDRAW_inline) {
  163.     fprintf(outfile, "\n");
  164.     TEXDRAW_inline = FALSE;
  165. TEXDRAW_arrow(sx, sy, ex, ey, head)
  166. int sx, sy, ex, ey;
  167. TBOOLEAN head;
  168.   char text;
  169.   if (head)
  170.     text = 'a';
  171.   else
  172.     text = 'l';
  173.   fprintf(outfile, "\\move (%d %d)\\%cvec (%d %d)",
  174.       (int)((double) sx * TEXDRAW_xscale),
  175.       (int)((double) sy * TEXDRAW_yscale),
  176.       text,
  177.       (int)((double) ex * TEXDRAW_xscale),
  178.       (int)((double) ey * TEXDRAW_yscale));
  179.   TEXDRAW_posx = ex;
  180.   TEXDRAW_posy = ey;
  181. TEXDRAW_put_text(x, y, str)
  182. int x, y;            /* reference point of string */
  183. char str[];            /* the text */
  184.   char text;
  185.   TEXDRAW_endline();
  186.   fprintf(outfile, "\\move (%d %d)",
  187.       (int)((double) x * TEXDRAW_xscale),
  188.       (int)((double) y * TEXDRAW_yscale));
  189.   if (!TEXDRAW_angle)
  190.     text = 'h';
  191.   else
  192.     text = 'v';
  193.   if (TEXDRAW_last_justify != TEXDRAW_justify) {
  194.     TEXDRAW_last_justify = TEXDRAW_justify;
  195.     if (TEXDRAW_justify == LEFT)
  196.       fprintf(outfile, "\\textref h:L v:C ");
  197.     else if (TEXDRAW_justify == CENTRE)
  198.       fprintf(outfile, "\\textref h:C v:C ");
  199.     else if (TEXDRAW_justify == RIGHT)
  200.       fprintf(outfile, "\\textref h:R v:C ");
  201.   fprintf(outfile, "\\%ctext{%s}\n", text, str);
  202. int TEXDRAW_justify_text(mode)
  203. enum JUSTIFY mode;
  204.   TEXDRAW_justify = mode;
  205.   return (TRUE);
  206. int TEXDRAW_text_angle(angle)
  207. int angle;
  208.   TEXDRAW_angle = angle;
  209.   return (TRUE);
  210. TEXDRAW_reset()
  211.   TEXDRAW_endline();
  212.   TEXDRAW_posx = TEXDRAW_posy = 0;
  213.