|
FAUST compiler
0.9.9.6b8
|
00001 /************************************************************************ 00002 ************************************************************************ 00003 FAUST compiler 00004 Copyright (C) 2003-2004 GRAME, Centre National de Creation Musicale 00005 --------------------------------------------------------------------- 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00019 ************************************************************************ 00020 ************************************************************************/ 00021 00022 00023 00024 // PSDev.cpp 00025 00026 #include "PSDev.h" 00027 #include "string.h" 00028 #include "math.h" 00029 #include "compatibility.hh" 00030 #include <iostream> 00031 00032 using namespace std; 00033 00034 static int gFileNum = 0; 00035 00036 static char * addFileNum(const char* fname) 00037 { 00038 char f[256]; 00039 char s[256]; 00040 int i; 00041 00042 // remove suffixes (.xxx.yyy) 00043 for (i=0; (fname[i] != 0) && (fname[i] != '.'); i++) { 00044 f[i] = fname[i]; 00045 } 00046 f[i] = 0; 00047 00048 // add number and .ps suffix 00049 snprintf(s, 255, "%s-%d.ps", f, ++gFileNum); 00050 //cerr << "file name " << s << endl; 00051 return strdup(s); 00052 } 00053 00054 PSDev::PSDev(const char* ficName, double largeur, double hauteur) 00055 { 00056 if ((fic_repr = fopen(addFileNum(ficName),"w+")) == NULL) { 00057 //if ((fic_repr = fopen(ficName,"w+")) == NULL) { 00058 cout<<"Impossible de creer ou d'ouvrir "<<ficName<<endl; 00059 } 00060 00061 if(largeur<hauteur) 00062 largeur=hauteur; 00063 00064 fprintf(fic_repr,"%%!PS-Adobe-3.0 \n"); 00065 //fprintf(fic_repr,"%%%%Pages: (atend) \n"); 00066 fprintf(fic_repr,"%%%%BoundingBox: 0 0 450 %d\n",(int)floor((hauteur*450/largeur)+1)); 00067 00068 fprintf(fic_repr,"/unit {%f mul} def\n\n",450/largeur); 00069 fprintf(fic_repr,"0 %f unit translate\n",hauteur); 00070 fprintf(fic_repr,"1 -1 scale\n\n"); // postscript's origin = lower left corner (SVG:upper left) 00071 fprintf(fic_repr,"0.6 unit setlinewidth\n"); // lines' width 00072 00073 fprintf(fic_repr,"/Times-Roman findfont %% Get the basic font for text\n"); 00074 //fprintf(fic_repr,"15 unit scalefont %% Scale the font to 15 units\n"); 00075 fprintf(fic_repr,"10 unit scalefont %% Scale the font to 10 units\n"); 00076 fprintf(fic_repr,"setfont %% Make it the current font\n\n"); 00077 } 00078 00079 PSDev::~PSDev() 00080 { 00081 fprintf(fic_repr,"showpage\n"); //eject the page 00082 fclose(fic_repr); 00083 } 00084 00085 void PSDev::rect(double x,double y,double l,double h, const char*, const char*) 00086 { 00087 fprintf(fic_repr,"gsave\n"); 00088 fprintf(fic_repr,"newpath\n"); 00089 //fprintf(fic_repr,"1.5 unit setlinewidth\n"); 00090 fprintf(fic_repr,"1.0 unit setlinewidth\n"); 00091 fprintf(fic_repr,"%f unit %f unit moveto\n",x,y); 00092 fprintf(fic_repr,"0 unit %f unit rlineto\n",h); 00093 fprintf(fic_repr,"%f unit 0 unit rlineto\n",l); 00094 fprintf(fic_repr,"0 unit %f unit rlineto\n",-h); 00095 fprintf(fic_repr,"closepath\n"); 00096 fprintf(fic_repr,"stroke\n"); 00097 fprintf(fic_repr,"grestore\n"); 00098 } 00099 00100 void PSDev::triangle(double x,double y,double l,double h, const char*, const char*, bool leftright) 00101 { 00102 fprintf(fic_repr,"gsave\n"); 00103 fprintf(fic_repr,"newpath\n"); 00104 //fprintf(fic_repr,"1.5 unit setlinewidth\n"); 00105 fprintf(fic_repr,"1.0 unit setlinewidth\n"); 00106 fprintf(fic_repr,"%f unit %f unit moveto\n",x,y); 00107 fprintf(fic_repr,"0 unit %f unit rlineto\n",h); 00108 fprintf(fic_repr,"%f unit 0 unit rlineto\n",l); 00109 fprintf(fic_repr,"0 unit %f unit rlineto\n",-h); 00110 fprintf(fic_repr,"closepath\n"); 00111 fprintf(fic_repr,"stroke\n"); 00112 fprintf(fic_repr,"grestore\n"); 00113 } 00114 00115 void PSDev::rond(double x,double y,double rayon) 00116 { 00117 fprintf(fic_repr,"gsave\n"); 00118 fprintf(fic_repr,"newpath\n"); 00119 fprintf(fic_repr,"%f unit %f unit %f unit 0 360 arc\n",x,y,rayon); 00120 fprintf(fic_repr,"fill\n"); 00121 fprintf(fic_repr,"grestore\n"); 00122 } 00123 00124 void PSDev::fleche(double x,double y,double rotation,int sens) 00125 { 00126 if(sens == 1) 00127 { 00128 fprintf(fic_repr,"gsave\n"); 00129 fprintf(fic_repr,"newpath\n"); 00130 fprintf(fic_repr,"0.3 setgray\n"); 00131 fprintf(fic_repr,"%f unit %f unit moveto\n",x,y); 00132 fprintf(fic_repr,"%f rotate\n",rotation); 00133 fprintf(fic_repr,"%f unit %f unit rlineto\n",(double)-4,(double)-2); 00134 fprintf(fic_repr,"%f rotate\n",(double)-rotation); 00135 fprintf(fic_repr,"%f unit %f unit moveto\n",x,y); 00136 fprintf(fic_repr,"%f rotate\n",rotation); 00137 fprintf(fic_repr,"%f unit %f unit rlineto\n",(double)-4,(double)+2); 00138 fprintf(fic_repr,"closepath\n"); 00139 fprintf(fic_repr,"stroke\n"); 00140 fprintf(fic_repr,"grestore\n"); 00141 } 00142 else //for the recursion 00143 { 00144 fprintf(fic_repr,"gsave\n"); 00145 fprintf(fic_repr,"newpath\n"); 00146 fprintf(fic_repr,"0.3 setgray\n"); 00147 fprintf(fic_repr,"%f unit %f unit moveto\n",x,y); 00148 fprintf(fic_repr,"%f rotate\n",rotation); 00149 fprintf(fic_repr,"%f unit %f unit rlineto\n",(double)4,(double)-2); 00150 fprintf(fic_repr,"%f rotate\n",(double)-rotation); 00151 fprintf(fic_repr,"%f unit %f unit moveto\n",x,y); 00152 fprintf(fic_repr,"%f rotate\n",rotation); 00153 fprintf(fic_repr,"%f unit %f unit rlineto\n",(double)4,(double)+2); 00154 fprintf(fic_repr,"closepath\n"); 00155 fprintf(fic_repr,"stroke\n"); 00156 fprintf(fic_repr,"grestore\n"); 00157 } 00158 } 00159 00160 void PSDev::carre(double x,double y,double cote) 00161 { 00162 fprintf(fic_repr,"gsave\n"); 00163 fprintf(fic_repr,"newpath\n"); 00164 fprintf(fic_repr,"0.3 setgray\n"); 00165 fprintf(fic_repr,"%f unit %f unit moveto\n",x-cote/2,y); 00166 fprintf(fic_repr,"0 unit %f unit rlineto\n",-cote); 00167 fprintf(fic_repr,"%f unit 0 unit rlineto\n",cote); 00168 fprintf(fic_repr,"0 unit %f unit rlineto\n",cote); 00169 fprintf(fic_repr,"closepath\n"); 00170 fprintf(fic_repr,"stroke\n"); 00171 fprintf(fic_repr,"grestore\n"); 00172 } 00173 00174 void PSDev::trait(double x1,double y1,double x2,double y2) 00175 { 00176 fprintf(fic_repr,"gsave\n"); 00177 fprintf(fic_repr,"0.3 setgray\n"); 00178 fprintf(fic_repr,"newpath\n"); 00179 fprintf(fic_repr,"%f unit %f unit moveto\n",x1,y1); 00180 fprintf(fic_repr,"%f unit %f unit lineto\n",x2,y2); 00181 fprintf(fic_repr,"stroke\n"); 00182 fprintf(fic_repr,"grestore\n"); 00183 } 00184 00185 void PSDev::dasharray(double x1,double y1,double x2,double y2) 00186 { 00187 fprintf(fic_repr,"gsave\n"); 00188 fprintf(fic_repr,"newpath\n"); 00189 fprintf(fic_repr,"0.6 setgray\n"); 00190 fprintf(fic_repr,"0.8 unit setlinewidth\n"); 00191 fprintf(fic_repr,"%f unit %f unit moveto\n",x1,y1); 00192 fprintf(fic_repr,"%f unit %f unit lineto\n",x2,y2); 00193 fprintf(fic_repr,"stroke\n"); 00194 fprintf(fic_repr,"grestore\n"); 00195 } 00196 00197 void PSDev::text(double x,double y,const char* nom, const char* link) 00198 { 00199 fprintf(fic_repr,"newpath\n"); 00200 //fprintf(fic_repr,"%f unit %f unit moveto\n",(x-4)-(strlen(nom)-1)*3.8,y+2); 00201 fprintf(fic_repr,"%f unit %f unit moveto\n",(x-0)-(strlen(nom)-1)*3.8,y+2); 00202 fprintf(fic_repr,"gsave\n"); 00203 fprintf(fic_repr,"1 -1 scale\n\n"); 00204 fprintf(fic_repr,"(%s) show\n",nom); 00205 fprintf(fic_repr,"grestore\n"); 00206 } 00207 00208 void PSDev::label(double x,double y,const char* label) 00209 { 00210 fprintf(fic_repr,"gsave\n"); 00211 fprintf(fic_repr,"/Times-Roman findfont %% Get the basic font for text\n"); 00212 fprintf(fic_repr,"7 unit scalefont %% Scale the font to 10 points\n"); 00213 fprintf(fic_repr,"setfont %% Make it the current font\n\n"); 00214 fprintf(fic_repr,"newpath\n"); 00215 fprintf(fic_repr,"%f unit %f unit moveto\n",(x+2),y+1.2); 00216 fprintf(fic_repr,"1 -1 scale\n"); 00217 fprintf(fic_repr,"(%s) show\n",label); 00218 fprintf(fic_repr,"grestore\n"); 00219 } 00220 00221 void PSDev::markSens(double x,double y,int sens) 00222 { 00223 if (sens==1) 00224 { 00225 fprintf(fic_repr,"newpath\n"); 00226 fprintf(fic_repr,"%f unit %f unit moveto\n",x,y+4); 00227 fprintf(fic_repr,"%f unit %f unit rlineto\n",(double)4,(double)-4); 00228 fprintf(fic_repr,"closepath\n"); 00229 } 00230 else //for the recursion 00231 { 00232 fprintf(fic_repr,"newpath\n"); 00233 fprintf(fic_repr,"%f unit %f unit moveto\n",x,y-4); 00234 fprintf(fic_repr,"%f unit %f unit rlineto\n",(double)-4,(double)4); 00235 fprintf(fic_repr,"closepath\n"); 00236 } 00237 fprintf(fic_repr,"stroke\n"); 00238 } 00239 00240 void PSDev::Error(const char* message, const char* reason,int nb_error,double x,double y,double largeur) 00241 { 00242 fprintf(fic_repr,"gsave\n"); 00243 fprintf(fic_repr,"/Times-Roman findfont %% Get the basic font for text\n"); 00244 fprintf(fic_repr,"17 unit scalefont %% Scale the font to 10 points\n"); 00245 fprintf(fic_repr,"setfont %% Make it the current font\n\n"); 00246 fprintf(fic_repr,"newpath\n"); 00247 fprintf(fic_repr,"%f unit %f unit moveto\n",(x-8)-(strlen(message)-1)*3.8,y-10); 00248 fprintf(fic_repr,"1 -1 scale\n"); 00249 fprintf(fic_repr,"(%s) show\n",message); 00250 fprintf(fic_repr,"1 -1 scale\n"); 00251 fprintf(fic_repr,"%f unit %f unit moveto\n",(x-8)-(strlen(reason)-1)*3.8,y+10); 00252 fprintf(fic_repr,"1 -1 scale\n"); 00253 fprintf(fic_repr,"(%s) show\n",reason); 00254 fprintf(fic_repr,"grestore\n"); 00255 00256 } 00257 00258
1.8.0