home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Graphics / Gnuplot / Source / term / nextfe.trm < prev    next >
Encoding:
Text File  |  1993-03-17  |  10.6 KB  |  377 lines

  1. /* GNUPLOT - nextfe.trm */
  2.  
  3. /* $Id: nextfe.trm,v 1.2 1993/03/18 04:44:47 davis Exp $ */
  4.  
  5. /*
  6.  * Copyright (C) 1990, 1992
  7.  *
  8.  * Permission to use, copy, and distribute this software and its
  9.  * documentation for any purpose with or without fee is hereby granted, 
  10.  * provided that the above copyright notice appear in all copies and 
  11.  * that both that copyright notice and this permission notice appear 
  12.  * in supporting documentation.
  13.  *
  14.  * Permission to modify the software is granted, but not the right to
  15.  * distribute the modified code.  Modifications are to be distributed 
  16.  * as patches to released version.
  17.  *  
  18.  * This software  is provided "as is" without express or implied warranty.
  19.  * 
  20.  * This file is included by ../term.c.
  21.  *
  22.  * This terminal driver supports:
  23.  *     postscript
  24.  *
  25.  * AUTHORS
  26.  *  Russell Lang (modified for the NeXTSTEP Front End by Robert Davis)
  27.  * 
  28.  * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
  29.  *
  30.  * The 'postscript' driver produces landscape output 10" wide and 7" high.  
  31.  * To change font to Times-Roman and font size to 20pts use 
  32.  * 'set term postscript "Times-Roman" 20'.
  33.  * To get a smaller (5" x 3.5") eps output use 'set term post eps'
  34.  * and make only one plot per file.  Font size for eps will be half
  35.  * the specified size.
  36.  */
  37.  
  38.  
  39. /* PostScript driver by Russell Lang, rjl@monu1.cc.monash.edu.au */
  40. /* Modified by Robert Davis, davis@ecn.purdue.edu, 71302,273@compuserve.com */
  41.  
  42. #import <streams/streams.h>
  43.  
  44. NXStream *EPSStream;
  45. TBOOLEAN nextfe_needsReset;
  46.  
  47. /* 
  48.  * The postscript driver by Russell Lang automatically halves the size 
  49.  * of EPS plots, as if you had done a "set size .5,.5".  This is 
  50.  * handy, since most EPS plots don't need to be page-sized, but it may 
  51.  * come as a suprise for folks not expecting it.  To turn it off, set 
  52.  * nextfe_halve to FALSE.
  53.  */
  54. TBOOLEAN nextfe_halve = TRUE;
  55.  
  56. char nextfe_font[MAX_ID_LEN+1] = "Helvetica" ;    /* name of font */
  57. int nextfe_fontsize = 14;            /* size of font in pts */
  58. TBOOLEAN nextfe_color = FALSE;
  59.  
  60. int nextfe_path_count=0;            /* count of lines in path */
  61. int nextfe_ang=0;                /* text angle */
  62. enum JUSTIFY nextfe_justify=LEFT;        /* text is flush left */
  63.  
  64. char *NEXTFE_header[] = {
  65. "/M {moveto} bind def\n",
  66. "/L {lineto} bind def\n",
  67. "/R {rmoveto} bind def\n",
  68. "/V {rlineto} bind def\n",
  69. "/vpt2 vpt 2 mul def\n",
  70. "/hpt2 hpt 2 mul def\n",
  71. /* flush left show */
  72. "/Lshow { currentpoint stroke M\n",
  73. "  0 vshift R show } def\n", 
  74. /* flush right show */
  75. "/Rshow { currentpoint stroke M\n",
  76. "  dup stringwidth pop neg vshift R show } def\n", 
  77. /* centred show */
  78. "/Cshow { currentpoint stroke M\n",
  79. "  dup stringwidth pop -2 div vshift R show } def\n", 
  80. /* Dash or Color Line */
  81. "/DL { Color {setrgbcolor [] 0 setdash pop}\n",
  82. " {pop pop pop 0 setdash} ifelse } def\n",
  83. /* Border Lines */
  84. "/BL { stroke gnulinewidth 2 mul setlinewidth } def\n",
  85. /* Axes Lines */
  86. "/AL { stroke gnulinewidth 2 div setlinewidth } def\n",
  87. /* Plot Lines */
  88. "/PL { stroke gnulinewidth setlinewidth } def\n",
  89. /* Line Types */
  90. "/LTb { BL [] 0 0 0 DL } def\n", /* border */
  91. "/LTa { AL [1 dl 2 dl] 0 setdash 0 0 0 setrgbcolor } def\n", /* axes */
  92. "/LT0 { PL [] 0 1 0 DL } def\n",
  93. "/LT1 { PL [4 dl 2 dl] 0 0 1 DL } def\n",
  94. "/LT2 { PL [2 dl 3 dl] 1 0 0 DL } def\n",
  95. "/LT3 { PL [1 dl 1.5 dl] 1 0 1 DL } def\n",
  96. "/LT4 { PL [5 dl 2 dl 1 dl 2 dl] 0 1 1 DL } def\n",
  97. "/LT5 { PL [4 dl 3 dl 1 dl 3 dl] 1 1 0 DL } def\n",
  98. "/LT6 { PL [2 dl 2 dl 2 dl 4 dl] 0 0 0 DL } def\n",
  99. "/LT7 { PL [2 dl 2 dl 2 dl 2 dl 2 dl 4 dl] 1 0.3 0 DL } def\n",
  100. "/LT8 { PL [2 dl 2 dl 2 dl 2 dl 2 dl 2 dl 2 dl 4 dl] 0.5 0.5 0.5 DL } def\n",
  101. "/P { stroke [] 0 setdash\n", /* Point */
  102. "  currentlinewidth 2 div sub M\n",
  103. "  0 currentlinewidth V stroke } def\n",
  104. "/D { stroke [] 0 setdash 2 copy vpt add M\n", /* Diamond */
  105. "  hpt neg vpt neg V hpt vpt neg V\n",
  106. "  hpt vpt V hpt neg vpt V closepath stroke\n",
  107. "  P } def\n",
  108. "/A { stroke [] 0 setdash vpt sub M 0 vpt2 V\n", /* Plus (Add) */
  109. "  currentpoint stroke M\n",
  110. "  hpt neg vpt neg R hpt2 0 V stroke\n",
  111. "  } def\n",
  112. "/B { stroke [] 0 setdash 2 copy exch hpt sub exch vpt add M\n", /* Box */
  113. "  0 vpt2 neg V hpt2 0 V 0 vpt2 V\n",
  114. "  hpt2 neg 0 V closepath stroke\n",
  115. "  P } def\n",
  116. "/C { stroke [] 0 setdash exch hpt sub exch vpt add M\n", /* Cross */
  117. "  hpt2 vpt2 neg V currentpoint stroke M\n",
  118. "  hpt2 neg 0 R hpt2 vpt2 V stroke } def\n",
  119. "/T { stroke [] 0 setdash 2 copy vpt 1.12 mul add M\n", /* Triangle */
  120. "  hpt neg vpt -1.62 mul V\n",
  121. "  hpt 2 mul 0 V\n",
  122. "  hpt neg vpt 1.62 mul V closepath stroke\n",
  123. "  P  } def\n",
  124. "/S { 2 copy A C} def\n", /* Star */
  125. NULL
  126. };
  127.  
  128. #define NEXTFE_XOFF    50    /* page offset in pts */
  129. #define NEXTFE_YOFF    50
  130.  
  131. #define NEXTFE_XMAX 7200
  132. #define NEXTFE_YMAX 5040
  133.  
  134. #define NEXTFE_XLAST (NEXTFE_XMAX - 1)
  135. #define NEXTFE_YLAST (NEXTFE_YMAX - 1)
  136.  
  137. #define NEXTFE_VTIC (NEXTFE_YMAX/80)
  138. #define NEXTFE_HTIC (NEXTFE_YMAX/80)
  139.  
  140. #define NEXTFE_SC (10)                /* scale is 1pt = 10 units */
  141. #define    NEXTFE_LW (0.5*NEXTFE_SC)        /* linewidth = 0.5 pts */
  142.  
  143. #define NEXTFE_VCHAR (14*NEXTFE_SC)    /* default is 14 point characters */
  144. #define NEXTFE_HCHAR (14*NEXTFE_SC*6/10)
  145.  
  146. int NEXTFE_pen_x, NEXTFE_pen_y;
  147. int NEXTFE_taken;
  148. int NEXTFE_linetype_last;
  149. TBOOLEAN NEXTFE_relative_ok;
  150.  
  151. NEXTFE_options()
  152. {
  153.     extern struct value *const_express();
  154.     extern double real();
  155.  
  156.     if (!END_OF_COMMAND && isstring(c_token)) {
  157.         quote_str(nextfe_font,c_token);
  158.         c_token++;
  159.     }
  160.  
  161.     if (!END_OF_COMMAND) {
  162.         /* We have font size specified */
  163.         struct value a;
  164.         nextfe_fontsize = (int)real(const_express(&a));
  165.         term_tbl[term].v_char = (unsigned int)(nextfe_fontsize*NEXTFE_SC);
  166.         term_tbl[term].h_char = (unsigned int)(nextfe_fontsize*NEXTFE_SC*6/10);
  167.     }
  168.  
  169. }
  170.  
  171.  
  172. NEXTFE_init()
  173. {
  174. struct termentry *t = &term_tbl[term];
  175. int i;
  176.     nextfe_needsReset = TRUE;
  177.  
  178.     NXPrintf(EPSStream,"%%!PS-Adobe-2.0 EPSF-2.0\n");
  179.     NXPrintf(EPSStream,"%%%%Creator: gnuplot\n");
  180.     NXPrintf(EPSStream,"%%%%DocumentFonts: %s\n", nextfe_font);
  181.     NXPrintf(EPSStream,"%%%%BoundingBox: %d %d ", NEXTFE_XOFF,NEXTFE_YOFF);
  182.  
  183.     /*
  184.      * The following calculates the size of the bounding box.  If 
  185.      * nextfe_halve is TRUE, the actual size of the entire plot, 
  186.      * including fonts, is halved.
  187.      */
  188.     NXPrintf(EPSStream,"%d %d\n", 
  189.     (int)(xsize * (nextfe_halve? 0.5: 1.0) * (NEXTFE_XMAX) / NEXTFE_SC
  190.           + 0.5 + NEXTFE_XOFF), 
  191.     (int)(ysize * (nextfe_halve? 0.5: 1.0) * (NEXTFE_YMAX) / NEXTFE_SC
  192.           + 0.5 + NEXTFE_YOFF));
  193.  
  194.     NXPrintf(EPSStream,"%%%%EndComments\n");
  195.     NXPrintf(EPSStream,"/gnudict 40 dict def\ngnudict begin\n");
  196.     NXPrintf(EPSStream,"/Color %s def\n",nextfe_color ? "true" : "false");
  197.     NXPrintf(EPSStream,"/gnulinewidth %.3f def\n",NEXTFE_LW);
  198.     NXPrintf(EPSStream,"/vshift %d def\n", (int)(t->v_char)/(-3));
  199.     NXPrintf(EPSStream,"/dl {%d mul} def\n",NEXTFE_SC); /* dash length */
  200.     NXPrintf(EPSStream,"/hpt %.1f def\n",NEXTFE_HTIC/2.0);
  201.     NXPrintf(EPSStream,"/vpt %.1f def\n",NEXTFE_VTIC/2.0);
  202.     for ( i=0; NEXTFE_header[i] != NULL; i++)
  203.         NXPrintf(EPSStream,"%s",NEXTFE_header[i]);
  204.     NXPrintf(EPSStream,"end\n");
  205.     NXPrintf(EPSStream,"%%%%EndProlog\n");
  206. }
  207.  
  208.  
  209. NEXTFE_graphics()
  210. {
  211.     struct termentry *t = &term_tbl[term];
  212.     NXPrintf(EPSStream,"gnudict begin\n");
  213.     NXPrintf(EPSStream,"gsave\n");
  214.     NXPrintf(EPSStream,"%d %d translate\n",NEXTFE_XOFF,NEXTFE_YOFF);
  215.  
  216.     /*
  217.      * The following scales the plot.  It halves the actual size
  218.      * of the plot if nextfe_halve is TRUE.
  219.      */    
  220.     NXPrintf(EPSStream,"%.3f %.3f scale\n", (nextfe_halve? 0.5: 1.0)
  221.          / NEXTFE_SC, (nextfe_halve? 0.5: 1.0) / NEXTFE_SC);
  222.     NXPrintf(EPSStream,"0 setgray\n");
  223.     NXPrintf(EPSStream,"/%s findfont %d ",nextfe_font, (t->v_char) );
  224.     NXPrintf(EPSStream,"scalefont setfont\n");
  225.     NXPrintf(EPSStream,"newpath\n");
  226.     nextfe_path_count = 0;
  227.  
  228.     NEXTFE_relative_ok = FALSE;
  229.     NEXTFE_pen_x = NEXTFE_pen_y = -4000;
  230.     NEXTFE_taken = 0;
  231.     NEXTFE_linetype_last = -1;
  232.  
  233. }
  234.  
  235.  
  236. NEXTFE_text()
  237. {
  238.     nextfe_path_count = 0;
  239.     NXPrintf(EPSStream,"stroke\ngrestore\nend\nshowpage\n");
  240. }
  241.  
  242.  
  243. NEXTFE_reset()
  244. {
  245.     if (nextfe_needsReset) {
  246.         NXPrintf(EPSStream,"%%%%Trailer\n");
  247.         NXFlush(EPSStream);
  248.         nextfe_needsReset = FALSE;
  249.     }
  250. }
  251.  
  252.  
  253. NEXTFE_linetype(linetype)
  254. int linetype;
  255. {
  256.     char *line = "ba012345678"; 
  257.  
  258.     linetype = (linetype % 9) + 2;
  259.     NEXTFE_relative_ok = FALSE;
  260.     if (NEXTFE_linetype_last == linetype) return;
  261.     NEXTFE_linetype_last = linetype;
  262.     NXPrintf(EPSStream,"LT%c\n", line[linetype]);
  263.     nextfe_path_count = 0;
  264. }
  265.  
  266.  
  267. NEXTFE_move(x,y)
  268. unsigned int x,y;
  269. {
  270.     int dx, dy;
  271.     char abso[20],rel[20];
  272.     dx = x - NEXTFE_pen_x;
  273.     dy = y - NEXTFE_pen_y;
  274.     /* can't cancel all null moves--need a move after stroking */
  275.     if (dx==0 && dy==0 && NEXTFE_relative_ok)
  276.     return;
  277.     sprintf(abso, "%d %d M\n", x, y);
  278.     sprintf(rel, "%d %d R\n", dx, dy);
  279.     if (strlen(rel) < strlen(abso) && NEXTFE_relative_ok){
  280.     NXPrintf(EPSStream, "%s",rel);
  281.     NEXTFE_taken++;
  282.     }else
  283.     NXPrintf(EPSStream, "%s",abso);
  284.     NEXTFE_relative_ok = TRUE;
  285.     nextfe_path_count += 1;
  286.     NEXTFE_pen_x = x;
  287.     NEXTFE_pen_y = y;
  288. }
  289.  
  290.  
  291. NEXTFE_vector(x,y)
  292. unsigned int x,y;
  293. {
  294.     int dx, dy;
  295.     char abso[20],rel[20];
  296.     dx = x - NEXTFE_pen_x;
  297.     dy = y - NEXTFE_pen_y;
  298.     if (dx==0 && dy==0) return;
  299.     sprintf(abso, "%d %d L\n", x, y);
  300.     sprintf(rel, "%d %d V\n", dx, dy);
  301.     if (strlen(rel) < strlen(abso) && NEXTFE_relative_ok){
  302.     NXPrintf (EPSStream, "%s", rel);
  303.     NEXTFE_taken++;
  304.     }else
  305.     NXPrintf (EPSStream, "%s", abso);
  306.     NEXTFE_relative_ok = TRUE;
  307.     nextfe_path_count += 1;
  308.     NEXTFE_pen_x = x;
  309.     NEXTFE_pen_y = y;
  310.     if (nextfe_path_count >= 400) {
  311.     NXPrintf (EPSStream, "currentpoint stroke M\n");
  312.     nextfe_path_count = 0;
  313.     }
  314. }
  315.  
  316.  
  317. NEXTFE_put_text(x,y,str)
  318. unsigned int x, y;
  319. char *str;
  320. {
  321.     char ch;
  322.     if (!strlen (str)) return;
  323.     NEXTFE_move(x,y);
  324.     if (nextfe_ang != 0)
  325.     NXPrintf(EPSStream,"currentpoint gsave translate %d rotate 0 0 M\n"
  326.             ,nextfe_ang*90);
  327.     NXPutc(EPSStream, '(');
  328.     ch = *str++;
  329.     while(ch!='\0') {
  330.     if ( (ch=='(') || (ch==')') || (ch=='\\') )
  331.         NXPutc(EPSStream,'\\');
  332.     NXPutc(EPSStream,ch);
  333.     ch = *str++;
  334.     }
  335.     switch(nextfe_justify) {
  336.     case LEFT : NXPrintf(EPSStream,") Lshow\n");
  337.     break;
  338.     case CENTRE : NXPrintf(EPSStream,") Cshow\n");
  339.     break;
  340.     case RIGHT : NXPrintf(EPSStream,") Rshow\n");
  341.     break;
  342.     }
  343.     if (nextfe_ang != 0)
  344.     NXPrintf(EPSStream,"grestore\n");
  345.     nextfe_path_count = 0;
  346.     NEXTFE_relative_ok = FALSE;
  347. }
  348.  
  349. int NEXTFE_text_angle(ang)
  350. int ang;
  351. {
  352.     nextfe_ang=ang;
  353.     return TRUE;
  354. }
  355.  
  356. int NEXTFE_justify_text(mode)
  357. enum JUSTIFY mode;
  358. {
  359.     nextfe_justify=mode;
  360.     return TRUE;
  361. }
  362.  
  363. /* postscript point routines */
  364. NEXTFE_point(x,y,number)
  365. int x,y;
  366. int number;
  367. {
  368. char *point = "PDABCTS";
  369.     number %= POINT_TYPES;
  370.      if (number < -1)
  371.         number = -1;        /* negative types are all 'dot' */
  372.     NXPrintf(EPSStream,"%d %d %c\n", x, y, point[number+1]);
  373.  
  374.     NEXTFE_relative_ok = 0;
  375.     nextfe_path_count = 0;
  376. }
  377.