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

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