home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / gnuplot-.5 / gnuplot- / gnuplot / term / pslatex.trm < prev    next >
Encoding:
Text File  |  1993-09-16  |  5.4 KB  |  242 lines

  1. /*
  2.  * $Id: pslatex.trm%v 3.50 1993/07/09 05:35:24 woo Exp $
  3.  */
  4.  
  5. /* GNUPLOT - pslatex.trm */
  6. /*
  7.  * Copyright (C) 1990 - 1993   
  8.  *
  9.  * Permission to use, copy, and distribute this software and its
  10.  * documentation for any purpose with or without fee is hereby granted, 
  11.  * provided that the above copyright notice appear in all copies and 
  12.  * that both that copyright notice and this permission notice appear 
  13.  * in supporting documentation.
  14.  *
  15.  * Permission to modify the software is granted, but not the right to
  16.  * distribute the modified code.  Modifications are to be distributed 
  17.  * as patches to released version.
  18.  *  
  19.  * This software  is provided "as is" without express or implied warranty.
  20.  * 
  21.  * This file is included by ../term.c.
  22.  *
  23.  * This terminal driver supports:
  24.  *     latex with embedded postscript
  25.  *
  26.  * AUTHORS
  27.  *  George Phillips
  28.  *  Russell Lang
  29.  *  David Kotz
  30.  * 
  31.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  32.  */
  33.  
  34. /* Driver by George Phillips */
  35.  
  36. #define PSLATEX_XMAX (5*720)
  37. #define PSLATEX_YMAX (3*720)
  38.  
  39. /* 10 pt char is about 10 pts high (say) */
  40. #define PSLATEX_VCHAR (100)
  41. /* 10 pt char is about 6 pts wide (say) */
  42. #define PSLATEX_HCHAR (60)
  43.  
  44. static int PSLATEX_angle;
  45. static int PSLATEX_justify;
  46. static int PSLATEX_rotate = TRUE;
  47.  
  48. struct text_command {
  49.     int x, y, angle, justify;
  50.     char* label;
  51.     struct text_command* next;
  52. };
  53.  
  54. static struct text_command* PSLATEX_labels;
  55.  
  56. PSLATEX_options()
  57. {
  58.     if (!END_OF_COMMAND) {
  59.     if (almost_equals(c_token, "d$efault")) {
  60.         ps_color = FALSE;
  61.         PSLATEX_rotate = TRUE;
  62.         c_token++;
  63.     }
  64.     }
  65.  
  66.     if (!END_OF_COMMAND) {
  67.     if (almost_equals(c_token, "c$olor")) {
  68.         ps_color = TRUE;
  69.         c_token++;
  70.     }
  71.     }
  72.  
  73.     if (!END_OF_COMMAND) {
  74.     if (almost_equals(c_token, "m$onochrome")) {
  75.         ps_color = FALSE;
  76.         c_token++;
  77.     }
  78.     }
  79.  
  80.     if (!END_OF_COMMAND) {
  81.     if (almost_equals(c_token, "r$otate")) {
  82.         PSLATEX_rotate = TRUE;
  83.         c_token++;
  84.     }
  85.     }
  86.  
  87.     if (!END_OF_COMMAND) {
  88.     if (almost_equals(c_token, "n$orotate")) {
  89.         PSLATEX_rotate = FALSE;
  90.         c_token++;
  91.     }
  92.     }
  93.  
  94.     sprintf(term_options, "%s %s", ps_color ? "color" : "monochrome",
  95.     PSLATEX_rotate ? "rotate" : "norotate");
  96. }
  97.  
  98. PSLATEX_init()
  99. {
  100.     /* reset PostScript driver variables */
  101.     ps_portrait = TRUE;
  102.     ps_eps = FALSE;
  103.     ps_color = FALSE;
  104.  
  105.     fprintf(outfile, "%% GNUPLOT: LaTeX picture with Postscript\n");
  106.     fprintf(outfile, "\\setlength{\\unitlength}{0.1bp}\n");
  107.     fprintf(outfile, "\\special{!\n");
  108.     PS_init();
  109.     fprintf(outfile, "}\n");
  110.  
  111.     PSLATEX_angle = 0;
  112.     PSLATEX_justify = 0;
  113.     PSLATEX_labels = 0;
  114. }
  115.  
  116. PSLATEX_scale(xs, ys)
  117. double xs, ys;
  118. {
  119.     register struct termentry *t = &term_tbl[term];
  120.  
  121.     t->xmax = (unsigned int)(PSLATEX_XMAX * xs);
  122.     t->ymax = (unsigned int)(PSLATEX_YMAX * ys);
  123.  
  124.     return TRUE;
  125. }
  126.  
  127. PSLATEX_graphics()
  128. {
  129.     struct termentry *t = &term_tbl[term];
  130.  
  131.     fprintf(outfile, "\\begin{picture}(%d,%d)(0,0)\n", t->xmax, t->ymax);
  132.  
  133.     fprintf(outfile, "\\special{\"\n");
  134.     PS_graphics();
  135.     /* thwart the translation done by PS_graphics() */
  136.     fprintf(outfile, "%f %f translate\n",
  137.         -PS_XOFF * (float)PS_SC, -PS_YOFF * (float)PS_SC);
  138.     PSLATEX_labels = (struct text_command *)NULL;
  139. }
  140.  
  141. PSLATEX_put_text(x, y, str)
  142. int x, y;
  143. char str[];
  144. {
  145.     struct text_command* tc;
  146.  
  147.     /* ignore empty strings */
  148.     if (str[0] == '\0')
  149.     return(0);
  150.     
  151.     tc = (struct text_command*)alloc(sizeof(struct text_command),"pslatex");
  152.     tc->x = x;
  153.     tc->y = y;
  154.     tc->label = (char *)alloc(strlen(str) + 1,"pslatex");
  155.     strcpy(tc->label, str);
  156.     tc->justify = PSLATEX_justify;
  157.     tc->angle = PSLATEX_angle;
  158.  
  159.     tc->next = PSLATEX_labels;
  160.     PSLATEX_labels = tc;
  161. }
  162.  
  163. PSLATEX_justify_text(mode)
  164. enum JUSTIFY mode;
  165. {
  166.     PSLATEX_justify = mode;
  167.     return TRUE;
  168. }
  169.  
  170. int PSLATEX_text_angle(angle)
  171. int angle;
  172. {
  173.     /* rotated text is put in a short stack, and optionally uses 
  174.      * postscript specials depending on PSLATEX_rotate */
  175.     PSLATEX_angle = angle;
  176.     return TRUE;
  177. }
  178.  
  179.  
  180. PSLATEX_reset()
  181. {
  182. }
  183.  
  184. PSLATEX_text()
  185. {
  186.     struct text_command* tc;
  187.  
  188.     PS_text();
  189.     fprintf(outfile, "}\n");
  190.  
  191.     for (tc = PSLATEX_labels; tc != (struct text_command*)NULL; tc = tc->next) {
  192.     fprintf(outfile, "\\put(%d,%d){", tc->x, tc->y);
  193.     switch (tc->angle) {
  194.     case 0:
  195.         switch (tc->justify) {
  196.         case LEFT:
  197.         fprintf(outfile, "\\makebox(0,0)[l]{%s}", tc->label);
  198.         break;
  199.         case CENTRE:
  200.         fprintf(outfile, "\\makebox(0,0){%s}", tc->label);
  201.         break;
  202.         case RIGHT:
  203.         fprintf(outfile, "\\makebox(0,0)[r]{%s}", tc->label);
  204.         break;
  205.         }
  206.         break;
  207.     case 1: /* put text in a short stack */
  208.         if (PSLATEX_rotate) {
  209.             fprintf(outfile, "%%\n\\special{ps: gsave currentpoint currentpoint translate\n");
  210.             fprintf(outfile, "270 rotate neg exch neg exch translate}%%\n");
  211.         }
  212.         switch (tc->justify) {
  213.         case LEFT:
  214.         fprintf(outfile, "\\makebox(0,0)[lb]{\\shortstack{%s}}",
  215.             tc->label);
  216.         break;
  217.         case CENTRE:
  218.         fprintf(outfile, "\\makebox(0,0)[b]{\\shortstack{%s}}",
  219.             tc->label);
  220.         break;
  221.         case RIGHT:
  222.         fprintf(outfile, "\\makebox(0,0)[lt]{\\shortstack{%s}}",
  223.             tc->label);
  224.         break;
  225.         }
  226.         if (PSLATEX_rotate) {
  227.             fprintf(outfile, "%%\n\\special{ps: currentpoint grestore moveto}%%\n");
  228.         }
  229.     }
  230.     fprintf(outfile, "}\n");
  231.     }
  232.  
  233.     while (PSLATEX_labels) {
  234.     tc = PSLATEX_labels->next;
  235.     free(PSLATEX_labels->label);
  236.     free(PSLATEX_labels);
  237.     PSLATEX_labels = tc;
  238.     }
  239.  
  240.     fprintf(outfile, "\\end{picture}\n");
  241. }
  242.