home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume27 / gnuplot3 / patch01 / term / ai.trm
Encoding:
Text File  |  1992-01-17  |  7.2 KB  |  345 lines

  1. /* GNUPLOT - ai.trm */
  2. /*
  3.  * Copyright (C) 1991   
  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.  *     aifm
  21.  *
  22.  * AUTHORS
  23.  *  Ray Ghanbari
  24.  * 
  25.  * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
  26.  *
  27.  * The 'aifm' driver produces files editable by Adobe Illustrator 3.0
  28.  * To change font to Courier and font size to 20pts use 
  29.  * 'set term aifm "Courier" 20'.
  30.  * To switch to color output use
  31.  * 'set term aifm color'.
  32.  */
  33.  
  34.  
  35. /* AIFM driver by Ray Ghanbari, ray@mtl.mit.edu, 
  36.  *    based on PostScript driver by Russell Lang, rjl@monu1.cc.monash.edu.au */
  37.  
  38. char ai_font[MAX_ID_LEN+1] = "Times-Roman" ; /* name of font */
  39. int ai_fontsize = 14;                     /* size of font in pts */
  40. BOOLEAN ai_color = FALSE;
  41. BOOLEAN ai_stroke = FALSE;
  42. int ai_page=0;            /* page count */
  43. int ai_path_count=0;     /* count of lines in path */
  44. int ai_ang=0;            /* text angle */
  45. enum JUSTIFY ai_justify=LEFT;    /* text is flush left */
  46.  
  47.  
  48. #define AI_XOFF    50    /* page offset in pts */
  49. #define AI_YOFF    50
  50.  
  51. #define AI_XMAX 5000
  52. #define AI_YMAX 3500
  53.  
  54. #define AI_XLAST (AI_XMAX - 1)
  55. #define AI_YLAST (AI_YMAX - 1)
  56.  
  57. #define AI_VTIC (AI_YMAX/80)
  58. #define AI_HTIC (AI_YMAX/80)
  59.  
  60. #define AI_SC (10.0)                /* scale is 1pt = 10 units */
  61. #define AI_LW (0.5*AI_SC)        /* linewidth = 0.5 pts */
  62.  
  63. #define AI_VCHAR (14*AI_SC)        /* default is 14 point characters */
  64. #define AI_HCHAR (14*AI_SC*6/10)
  65.  
  66.  
  67. AI_options()
  68. {
  69.     extern struct value *const_express();
  70.     extern double real();
  71.  
  72.     if (!END_OF_COMMAND) {
  73.         if (almost_equals(c_token,"d$efault")) {
  74.             ai_color=FALSE;
  75.             strcpy(ai_font,"Times-Roman");
  76.             ai_fontsize = 14;
  77.             c_token++;
  78.         }
  79.     }
  80.  
  81.     if (!END_OF_COMMAND) {
  82.         if (almost_equals(c_token,"m$onochrome")) {
  83.             ai_color=FALSE;
  84.             c_token++;
  85.         }
  86.         else if (almost_equals(c_token,"c$olor")) {
  87.             ai_color=TRUE;
  88.             c_token++;
  89.         }
  90.     }
  91.  
  92.     if (!END_OF_COMMAND && isstring(c_token)) {
  93.         quote_str(ai_font,c_token);
  94.         c_token++;
  95.     }
  96.  
  97.     if (!END_OF_COMMAND) {
  98.         /* We have font size specified */
  99.         struct value a;
  100.         ai_fontsize = (int)real(const_express(&a));
  101.         c_token++;
  102.         term_tbl[term].v_char = (unsigned int)(ai_fontsize*AI_SC);
  103.         term_tbl[term].h_char = (unsigned int)(ai_fontsize*AI_SC*6/10);
  104.     }
  105.  
  106.     sprintf(term_options,"%s \"%s\" %d",
  107.         ai_color ? "color" : "monochrome",ai_font,ai_fontsize);
  108. }
  109.  
  110.  
  111. AI_init()
  112. {
  113. struct termentry *t = &term_tbl[term];
  114. int i;
  115.     ai_page = 0;
  116.     fprintf(outfile,"%%!PS-Adobe-2.0 EPSF-1.2\n");
  117.     fprintf(outfile,"%%%%BoundingBox: %d %d %d %d\n", AI_XOFF,AI_YOFF,
  118.         (int)((AI_XMAX)/AI_SC+0.5+AI_XOFF), 
  119.         (int)((AI_YMAX)/AI_SC+0.5+AI_YOFF) );
  120.     fprintf(outfile,"%%%%Template:\n");
  121.     fprintf(outfile,"%%%%EndComments\n");
  122.     fprintf(outfile,"%%%%EndProlog\n");
  123. }
  124.  
  125.  
  126. AI_graphics()
  127. {
  128. struct termentry *t = &term_tbl[term];
  129.     ai_page++;
  130. /*    fprintf(outfile,"%%%%Page: %d %d\n",ai_page,ai_page);*/
  131.     fprintf(outfile,"0 G\n");
  132.     fprintf(outfile,"1 j\n");
  133.     fprintf(outfile,"1 J\n");
  134.     fprintf(outfile,"u\n");
  135.     ai_path_count = 0;
  136.     ai_stroke = FALSE;
  137. }
  138.  
  139.  
  140. AI_text()
  141. {
  142.     if (ai_stroke) {
  143.         fprintf(outfile,"S\n");
  144.         ai_stroke = FALSE;
  145.     }
  146.     fprintf(outfile,"U\n");
  147.     ai_path_count = 0;
  148. }
  149.  
  150.  
  151. AI_reset()
  152. {
  153.     fprintf(outfile,"%%%%Trailer\n");
  154. /*    fprintf(outfile,"%%%%Pages: %d\n",ai_page);*/
  155. }
  156.  
  157.  
  158. AI_linetype(linetype)
  159. int linetype;
  160. {
  161.     if (ai_stroke) {
  162.         fprintf(outfile,"S\n");
  163.         ai_stroke = FALSE;
  164.     }
  165.     switch(linetype) {
  166.         case -2 : fprintf(outfile,"%.2f w\n",AI_LW/AI_SC*2.0);
  167.                 if (ai_color) {
  168.                     fprintf(outfile,"0 0 0 1 K\n");
  169.                 }
  170.                 else {                
  171.                     fprintf(outfile,"[] 0 d\n");
  172.                 }
  173.                 break;
  174.                 
  175.         case -1 : fprintf(outfile,"%.2f w\n",AI_LW/AI_SC/2.0);
  176.                 if (ai_color) {
  177.                     fprintf(outfile,"0 0 0 1 K\n");
  178.                 }
  179.                 else {                
  180.                     fprintf(outfile,"[1 2] 0 d\n");
  181.                 }
  182.                 break;
  183.                 
  184.         case 0 :  fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  185.                 if (ai_color) {
  186.                     fprintf(outfile,"1 0 1 0 K\n");
  187.                 }
  188.                 else {                
  189.                     fprintf(outfile,"[] 0 d\n");
  190.                 }
  191.                 break;
  192.                 
  193.         case 1 :  fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  194.                 if (ai_color) {
  195.                     fprintf(outfile,"1 1 0 0 K\n");
  196.                 }
  197.                 else {                
  198.                     fprintf(outfile,"[4 2] 0 d\n");
  199.                 }
  200.                 break;
  201.                 
  202.         case 2 :  fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  203.                 if (ai_color) {
  204.                     fprintf(outfile,"0 1 1 0 K\n");
  205.                 }
  206.                 else {                
  207.                     fprintf(outfile,"[2 3] 0 d\n");
  208.                 }
  209.                 break;
  210.                 
  211.         case 3 :  fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  212.                 if (ai_color) {
  213.                     fprintf(outfile,"0 1 0 0 K\n");
  214.                 }
  215.                 else {                
  216.                     fprintf(outfile,"[1 1.5] 0 d\n");
  217.                 }
  218.                 break;
  219.                 
  220.         case 4 :  fprintf(outfile,"%f w\n",AI_LW/AI_SC);
  221.                 if (ai_color) {
  222.                     fprintf(outfile,"1 0 0 0 K\n");
  223.                 }
  224.                 else {                
  225.                     fprintf(outfile,"[5 2 1 2] 0 d\n");
  226.                 }
  227.                 break;
  228.                 
  229.         case 5 : fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  230.                 if (ai_color) {
  231.                     fprintf(outfile,"0 0 1 0 K\n");
  232.                 }
  233.                 else {                
  234.                     fprintf(outfile,"[4 3 1 3] 0 d\n");
  235.                 }
  236.                 break;
  237.                 
  238.         case 6 : fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  239.                 if (ai_color) {
  240.                     fprintf(outfile,"0 0 0 1 K\n");
  241.                 }
  242.                 else {                
  243.                     fprintf(outfile,"[2 2 2 4] 0 d\n");
  244.                 }
  245.                 break;
  246.                 
  247.         case 7 : fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  248.                 if (ai_color) {
  249.                     fprintf(outfile,"0 0.7 1 0 K\n");
  250.                 }
  251.                 else {                
  252.                     fprintf(outfile,"[2 2 2 2 2 4] 0 d\n");
  253.                 }
  254.                 break;
  255.                 
  256.         case 8 : fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  257.                 if (ai_color) {
  258.                     fprintf(outfile,"0.5 0.5 0.5 0 K\n");
  259.                 }
  260.                 else {                
  261.                     fprintf(outfile,"[2 2 2 2 2 2 2 4] 0 d\n");
  262.                 }
  263.                 break;
  264.         }
  265.                 
  266.     ai_path_count = 0;
  267. }
  268.  
  269.  
  270. AI_move(x,y)
  271. unsigned int x,y;
  272. {
  273.     if (ai_stroke) fprintf(outfile,"S\n");
  274.     fprintf(outfile,"%.2f %.2f m\n", x/AI_SC, y/AI_SC);
  275.     ai_path_count += 1;
  276.     ai_stroke = TRUE;
  277. }
  278.  
  279.  
  280. AI_vector(x,y)
  281. unsigned int x,y;
  282. {
  283.     fprintf(outfile,"%.2f %.2f l\n", x/AI_SC, y/AI_SC);
  284.     ai_path_count += 1;
  285.     ai_stroke = TRUE;
  286.     if (ai_path_count >= 400) {
  287.         fprintf(outfile,"S\n%.2f %.2f m\n",x/AI_SC,y/AI_SC);
  288.         ai_path_count = 0;
  289.     }
  290. }
  291.  
  292.  
  293. AI_put_text(x,y,str)
  294. unsigned int x, y;
  295. char *str;
  296. {
  297. char ch;
  298.     if (ai_stroke) {
  299.         fprintf(outfile,"S\n");
  300.         ai_stroke = FALSE;
  301.     }
  302.     switch(ai_justify) {
  303.         case LEFT :   fprintf(outfile,"/_%s %d 0 0 0 z\n",ai_font,ai_fontsize);
  304.             break;
  305.         case CENTRE : fprintf(outfile,"/_%s %d 0 0 1 z\n",ai_font,ai_fontsize);
  306.             break;
  307.         case RIGHT :  fprintf(outfile,"/_%s %d 0 0 2 z\n",ai_font,ai_fontsize);
  308.             break;
  309.     }
  310.     if (ai_ang==0) {
  311.         fprintf(outfile,"[ 1 0 0 1 %.2f %.2f] e\n",
  312.             x/AI_SC,y/AI_SC - ai_fontsize/3.0);
  313.     }
  314.     else {
  315.         fprintf(outfile,"[ 0 1 -1 0 %.2f %.2f] e\n",
  316.             x/AI_SC - ai_fontsize/3.0,y/AI_SC);
  317.     }
  318.         
  319.     putc('(',outfile);
  320.     ch = *str++;
  321.     while(ch!='\0') {
  322.         if ( (ch=='(') || (ch==')') || (ch=='\\') )
  323.             putc('\\',outfile);
  324.         putc(ch,outfile);
  325.         ch = *str++;
  326.     }
  327.     fprintf(outfile,") t\nT\n");
  328.     ai_path_count = 0;
  329. }
  330.  
  331. int AI_text_angle(ang)
  332. int ang;
  333. {
  334.     ai_ang=ang;
  335.     return TRUE;
  336. }
  337.  
  338. int AI_justify_text(mode)
  339. enum JUSTIFY mode;
  340. {
  341.     ai_justify=mode;
  342.     return TRUE;
  343. }
  344.  
  345.