home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 500-599 / ff552.lzh / GNUPlot / gnuplot3.lzh / gnuplot / term / post.trm < prev    next >
Text File  |  1991-08-30  |  9KB  |  339 lines

  1. /* GNUPLOT - post.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.  *     postscript
  21.  *
  22.  * AUTHORS
  23.  *  Russell Lang
  24.  * 
  25.  * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
  26.  *
  27.  * The 'postscript' driver produces landscape output 10" wide and 7" high.  
  28.  * To get a smaller epsf output use 'set size 0.5,0.5', 
  29.  * 'set term postscript portrait', make only one plot per file
  30.  * and change the first line of the postscript file from
  31.  * '%!PS-Adobe-2.0' to '%!PS-Adobe-2.0 EPSF-2.0'
  32.  * To change font to Times-Roman and font size to 20pts use 
  33.  * 'set term postscript "Times-Roman" 20'.
  34.  */
  35.  
  36.  
  37. /* PostScript driver by Russell Lang, rjl@monu1.cc.monash.edu.au */
  38.  
  39. char ps_font[MAX_ID_LEN+1] = "Courier" ; /* name of font */
  40. int ps_fontsize = 14;                     /* size of font in pts */
  41. BOOLEAN ps_portrait = FALSE;                 /* vertical page */
  42. BOOLEAN ps_color = FALSE;
  43. int ps_page=0;            /* page count */
  44. int ps_path_count=0;     /* count of lines in path */
  45. int ps_ang=0;            /* text angle */
  46. enum JUSTIFY ps_justify=LEFT;    /* text is flush left */
  47.  
  48. char *PS_header[] = {
  49. "/vpt2 vpt 2 mul def\n",
  50. "/hpt2 hpt 2 mul def\n",
  51. /* flush left show */
  52. "/Lshow { currentpoint stroke moveto\n",
  53. "  0 vshift rmoveto show } def\n", 
  54. /* flush right show */
  55. "/Rshow { currentpoint stroke moveto\n",
  56. "  dup stringwidth pop neg vshift rmoveto show } def\n", 
  57. /* centred show */
  58. "/Cshow { currentpoint stroke moveto\n",
  59. "  dup stringwidth pop -2 div vshift rmoveto show } def\n", 
  60. /* Dash or Color Line */
  61. "/DL { Color {setrgbcolor [] 0 setdash pop}\n",
  62. " {pop pop pop 0 setdash} ifelse } def\n",
  63. /* Border Lines */
  64. "/BL { stroke gnulinewidth 2 mul setlinewidth } def\n",
  65. /* Axes Lines */
  66. "/AL { stroke gnulinewidth 2 div setlinewidth } def\n",
  67. /* Plot Lines */
  68. "/PL { stroke gnulinewidth setlinewidth } def\n",
  69. /* Line Types */
  70. "/LTb { BL [] 0 0 0 DL } def\n", /* border */
  71. "/LTa { AL [1 dl 2 dl] 0 setdash 0 0 0 setrgbcolor } def\n", /* axes */
  72. "/LT0 { PL [] 0 1 0 DL } def\n",
  73. "/LT1 { PL [4 dl 2 dl] 0 0 1 DL } def\n",
  74. "/LT2 { PL [2 dl 3 dl] 1 0 0 DL } def\n",
  75. "/LT3 { PL [1 dl 1.5 dl] 1 0 1 DL } def\n",
  76. "/LT4 { PL [5 dl 2 dl 1 dl 2 dl] 0 1 1 DL } def\n",
  77. "/LT5 { PL [4 dl 3 dl 1 dl 3 dl] 1 1 0 DL } def\n",
  78. "/LT6 { PL [2 dl 2 dl 2 dl 4 dl] 0 0 0 DL } def\n",
  79. "/LT7 { PL [2 dl 2 dl 2 dl 2 dl 2 dl 4 dl] 1 0.3 0 DL } def\n",
  80. "/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",
  81. "/M {moveto} def\n",
  82. "/L {lineto} def\n",
  83. "/P { stroke [] 0 setdash\n", /* Point */
  84. "  currentlinewidth 2 div sub moveto\n",
  85. "  0 currentlinewidth rlineto  stroke } def\n",
  86. "/D { stroke [] 0 setdash  2 copy  vpt add moveto\n", /* Diamond */
  87. "  hpt neg vpt neg rlineto  hpt vpt neg rlineto\n",
  88. "  hpt vpt rlineto  hpt neg vpt rlineto  closepath  stroke\n",
  89. "  P  } def\n",
  90. "/A { stroke [] 0 setdash  vpt sub moveto  0 vpt2 rlineto\n", /* Plus (Add) */
  91. "  currentpoint stroke moveto\n",
  92. "  hpt neg vpt neg rmoveto  hpt2 0 rlineto stroke\n",
  93. "  } def\n",
  94. "/B { stroke [] 0 setdash  2 copy  exch hpt sub exch vpt add moveto\n", /* Box */
  95. "  0 vpt2 neg rlineto  hpt2 0 rlineto  0 vpt2 rlineto\n",
  96. "  hpt2 neg 0 rlineto  closepath  stroke\n",
  97. "  P  } def\n",
  98. "/C { stroke [] 0 setdash  exch hpt sub exch vpt add moveto\n", /* Cross */
  99. "  hpt2 vpt2 neg rlineto  currentpoint  stroke  moveto\n",
  100. "  hpt2 neg 0 rmoveto  hpt2 vpt2 rlineto stroke  } def\n",
  101. "/T { stroke [] 0 setdash  2 copy  vpt 1.12 mul add moveto\n", /* Triangle */
  102. "  hpt neg vpt -1.62 mul rlineto\n",
  103. "  hpt 2 mul 0 rlineto\n",
  104. "  hpt neg vpt 1.62 mul rlineto  closepath  stroke\n",
  105. "  P  } def\n",
  106. "/S { 2 copy A C} def\n", /* Star */
  107. NULL
  108. };
  109.  
  110. #define PS_XOFF    50    /* page offset in pts */
  111. #define PS_YOFF    50
  112.  
  113. #define PS_XMAX 7200
  114. #define PS_YMAX 5040
  115.  
  116. #define PS_XLAST (PS_XMAX - 1)
  117. #define PS_YLAST (PS_YMAX - 1)
  118.  
  119. #define PS_VTIC (PS_YMAX/80)
  120. #define PS_HTIC (PS_YMAX/80)
  121.  
  122. #define PS_SC (10)                /* scale is 1pt = 10 units */
  123. #define    PS_LW (0.5*PS_SC)        /* linewidth = 0.5 pts */
  124.  
  125. #define PS_VCHAR (14*PS_SC)        /* default is 14 point characters */
  126. #define PS_HCHAR (14*PS_SC*6/10)
  127.  
  128.  
  129. PS_options()
  130. {
  131.     extern struct value *const_express();
  132.     extern double real();
  133.  
  134.     if (!END_OF_COMMAND) {
  135.         if (almost_equals(c_token,"p$ortrait")) {
  136.             ps_portrait=TRUE;
  137.             c_token++;
  138.         }
  139.         else if (almost_equals(c_token,"l$andscape")) {
  140.             ps_portrait=FALSE;
  141.             c_token++;
  142.         }
  143.         else if (almost_equals(c_token,"d$efault")) {
  144.             ps_portrait=FALSE;
  145.             ps_color=FALSE;
  146.             strcpy(ps_font,"Courier");
  147.             ps_fontsize = 14;
  148.             c_token++;
  149.         }
  150.     }
  151.  
  152.     if (!END_OF_COMMAND) {
  153.         if (almost_equals(c_token,"m$onochrome")) {
  154.             ps_color=FALSE;
  155.             c_token++;
  156.         }
  157.         else if (almost_equals(c_token,"c$olor")) {
  158.             ps_color=TRUE;
  159.             c_token++;
  160.         }
  161.     }
  162.  
  163.     if (!END_OF_COMMAND && isstring(c_token)) {
  164.         quote_str(ps_font,c_token);
  165.         c_token++;
  166.     }
  167.  
  168.     if (!END_OF_COMMAND) {
  169.         /* We have font size specified */
  170.         struct value a;
  171.         ps_fontsize = (int)real(const_express(&a));
  172.         c_token++;
  173.         term_tbl[term].v_char = (unsigned int)(ps_fontsize*PS_SC);
  174.         term_tbl[term].h_char = (unsigned int)(ps_fontsize*PS_SC*6/10);
  175.     }
  176.  
  177.     sprintf(term_options,"%s %s \"%s\" %d",
  178.         ps_portrait ? "portrait" : "landscape",
  179.         ps_color ? "color" : "monochrome",ps_font,ps_fontsize);
  180. }
  181.  
  182.  
  183. PS_init()
  184. {
  185. struct termentry *t = &term_tbl[term];
  186. int i;
  187.     ps_page = 0;
  188.     fprintf(outfile,"%%!PS-Adobe-2.0\n");
  189.     fprintf(outfile,"%%%%Creator: gnuplot\n");
  190.     fprintf(outfile,"%%%%DocumentFonts: %s\n", ps_font);
  191.     fprintf(outfile,"%%%%BoundingBox: %d %d ", PS_XOFF,PS_YOFF);
  192.     if (ps_portrait)
  193.         fprintf(outfile,"%d %d\n", 
  194.             (int)(xsize*(PS_XMAX)/PS_SC+0.5+PS_XOFF), 
  195.             (int)(ysize*(PS_YMAX)/PS_SC+0.5+PS_YOFF) );
  196.     else 
  197.         fprintf(outfile,"%d %d\n", 
  198.             (int)(ysize*(PS_YMAX)/PS_SC+0.5+PS_XOFF), 
  199.             (int)(xsize*(PS_XMAX)/PS_SC+0.5+PS_YOFF) );
  200.     fprintf(outfile,"%%%%Pages: (atend)\n");
  201.     fprintf(outfile,"%%%%EndComments\n");
  202.     fprintf(outfile,"/gnudict 40 dict def\ngnudict begin\n");
  203.     fprintf(outfile,"/Color %s def\n",ps_color ? "true" : "false");
  204.     fprintf(outfile,"/gnulinewidth %.3f def\n",PS_LW);
  205.     fprintf(outfile,"/vshift %d def\n", (int)(t->v_char)/(-3));
  206.     fprintf(outfile,"/dl {%d mul} def\n",PS_SC); /* dash length */
  207.     fprintf(outfile,"/hpt %.1f def\n",PS_HTIC/2.0);
  208.     fprintf(outfile,"/vpt %.1f def\n",PS_VTIC/2.0);
  209.     for ( i=0; PS_header[i] != NULL; i++)
  210.         fprintf(outfile,"%s",PS_header[i]);
  211.     fprintf(outfile,"end\n");
  212.     fprintf(outfile,"%%%%EndProlog\n");
  213. }
  214.  
  215.  
  216. PS_graphics()
  217. {
  218. struct termentry *t = &term_tbl[term];
  219.     ps_page++;
  220.     fprintf(outfile,"%%%%Page: %d %d\n",ps_page,ps_page);
  221.     fprintf(outfile,"gnudict begin\n");
  222.     fprintf(outfile,"gsave\n");
  223.     fprintf(outfile,"%d %d translate\n",PS_XOFF,PS_YOFF);
  224.     if (ps_portrait) {
  225.         fprintf(outfile,"%.3f %.3f scale\n", xsize/PS_SC, ysize/PS_SC);
  226.     }
  227.     else {
  228.         fprintf(outfile,"%.3f %.3f scale\n", ysize/PS_SC, xsize/PS_SC);
  229.         fprintf(outfile,"90 rotate\n0 %d translate\n", -PS_YMAX);
  230.     }
  231.     fprintf(outfile,"0 setgray\n");
  232.     fprintf(outfile,"/%s findfont %d ", ps_font, (t->v_char) );
  233.     fprintf(outfile,"scalefont setfont\n");
  234.     fprintf(outfile,"newpath\n");
  235.     ps_path_count = 0;
  236. }
  237.  
  238.  
  239. PS_text()
  240. {
  241.     ps_path_count = 0;
  242.     fprintf(outfile,"stroke\ngrestore\nend\nshowpage\n");
  243. }
  244.  
  245.  
  246. PS_reset()
  247. {
  248.     fprintf(outfile,"%%%%Trailer\n");
  249.     fprintf(outfile,"%%%%Pages: %d\n",ps_page);
  250. }
  251.  
  252.  
  253. PS_linetype(linetype)
  254. int linetype;
  255. {
  256. char *line = "ba012345678"; 
  257.     fprintf(outfile,"LT%c\n", line[(linetype%9)+2]);
  258.     ps_path_count = 0;
  259. }
  260.  
  261.  
  262. PS_move(x,y)
  263. unsigned int x,y;
  264. {
  265.     fprintf(outfile,"%d %d M\n", x, y);
  266.     ps_path_count += 1;
  267. }
  268.  
  269.  
  270. PS_vector(x,y)
  271. unsigned int x,y;
  272. {
  273.     fprintf(outfile,"%d %d L\n", x, y);
  274.     ps_path_count += 1;
  275.     if (ps_path_count >= 400) {
  276.         fprintf(outfile,"currentpoint stroke moveto\n");
  277.         ps_path_count = 0;
  278.     }
  279. }
  280.  
  281.  
  282. PS_put_text(x,y,str)
  283. unsigned int x, y;
  284. char *str;
  285. {
  286. char ch;
  287.     PS_move(x,y);
  288.     if (ps_ang != 0)
  289.         fprintf(outfile,"currentpoint gsave translate %d rotate 0 0 moveto\n"
  290.             ,ps_ang*90);
  291.     putc('(',outfile);
  292.     ch = *str++;
  293.     while(ch!='\0') {
  294.         if ( (ch=='(') || (ch==')') || (ch=='\\') )
  295.             putc('\\',outfile);
  296.         putc(ch,outfile);
  297.         ch = *str++;
  298.     }
  299.     switch(ps_justify) {
  300.         case LEFT : fprintf(outfile,") Lshow\n");
  301.             break;
  302.         case CENTRE : fprintf(outfile,") Cshow\n");
  303.             break;
  304.         case RIGHT : fprintf(outfile,") Rshow\n");
  305.             break;
  306.     }
  307.     if (ps_ang != 0)
  308.         fprintf(outfile,"grestore\n");
  309.     ps_path_count = 0;
  310. }
  311.  
  312. int PS_text_angle(ang)
  313. int ang;
  314. {
  315.     ps_ang=ang;
  316.     return TRUE;
  317. }
  318.  
  319. int PS_justify_text(mode)
  320. enum JUSTIFY mode;
  321. {
  322.     ps_justify=mode;
  323.     return TRUE;
  324. }
  325.  
  326. /* postscript point routines */
  327. PS_point(x,y,number)
  328. int x,y;
  329. int number;
  330. {
  331. char *point = "PDABCTS";
  332.     number %= POINT_TYPES;
  333.      if (number < -1)
  334.         number = -1;        /* negative types are all 'dot' */
  335.     fprintf(outfile,"%d %d %c\n", x, y, point[number+1]);
  336.     ps_path_count = 0;
  337. }
  338.  
  339.