14ab303ccf2ff612feadf0ed5198f6633d0321ae
1 /************************************************************************
2 ************************************************************************
4 Copyright (C) 2003-2004 GRAME, Centre National de Creation Musicale
5 ---------------------------------------------------------------------
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 ************************************************************************
20 ************************************************************************/
29 #include "compatibility.hh"
34 static int gFileNum
= 0;
36 static char * addFileNum(const char* fname
)
42 // remove suffixes (.xxx.yyy)
43 for (i
=0; (fname
[i
] != 0) && (fname
[i
] != '.'); i
++) {
48 // add number and .ps suffix
49 snprintf(s
, 255, "%s-%d.ps", f
, ++gFileNum
);
50 //cerr << "file name " << s << endl;
54 PSDev::PSDev(const char* ficName
, double largeur
, double hauteur
)
56 if ((fic_repr
= fopen(addFileNum(ficName
),"w+")) == NULL
) {
57 //if ((fic_repr = fopen(ficName,"w+")) == NULL) {
58 cout
<<"Impossible de creer ou d'ouvrir "<<ficName
<<endl
;
64 fprintf(fic_repr
,"%%!PS-Adobe-3.0 \n");
65 //fprintf(fic_repr,"%%%%Pages: (atend) \n");
66 fprintf(fic_repr
,"%%%%BoundingBox: 0 0 450 %d\n",(int)floor((hauteur
*450/largeur
)+1));
68 fprintf(fic_repr
,"/unit {%f mul} def\n\n",450/largeur
);
69 fprintf(fic_repr
,"0 %f unit translate\n",hauteur
);
70 fprintf(fic_repr
,"1 -1 scale\n\n"); // postscript's origin = lower left corner (SVG:upper left)
71 fprintf(fic_repr
,"0.6 unit setlinewidth\n"); // lines' width
73 fprintf(fic_repr
,"/Times-Roman findfont %% Get the basic font for text\n");
74 //fprintf(fic_repr,"15 unit scalefont %% Scale the font to 15 units\n");
75 fprintf(fic_repr
,"10 unit scalefont %% Scale the font to 10 units\n");
76 fprintf(fic_repr
,"setfont %% Make it the current font\n\n");
81 fprintf(fic_repr
,"showpage\n"); //eject the page
85 void PSDev::rect(double x
,double y
,double l
,double h
, const char*, const char*)
87 fprintf(fic_repr
,"gsave\n");
88 fprintf(fic_repr
,"newpath\n");
89 //fprintf(fic_repr,"1.5 unit setlinewidth\n");
90 fprintf(fic_repr
,"1.0 unit setlinewidth\n");
91 fprintf(fic_repr
,"%f unit %f unit moveto\n",x
,y
);
92 fprintf(fic_repr
,"0 unit %f unit rlineto\n",h
);
93 fprintf(fic_repr
,"%f unit 0 unit rlineto\n",l
);
94 fprintf(fic_repr
,"0 unit %f unit rlineto\n",-h
);
95 fprintf(fic_repr
,"closepath\n");
96 fprintf(fic_repr
,"stroke\n");
97 fprintf(fic_repr
,"grestore\n");
100 void PSDev::triangle(double x
,double y
,double l
,double h
, const char*, const char*, bool leftright
)
102 fprintf(fic_repr
,"gsave\n");
103 fprintf(fic_repr
,"newpath\n");
104 //fprintf(fic_repr,"1.5 unit setlinewidth\n");
105 fprintf(fic_repr
,"1.0 unit setlinewidth\n");
106 fprintf(fic_repr
,"%f unit %f unit moveto\n",x
,y
);
107 fprintf(fic_repr
,"0 unit %f unit rlineto\n",h
);
108 fprintf(fic_repr
,"%f unit 0 unit rlineto\n",l
);
109 fprintf(fic_repr
,"0 unit %f unit rlineto\n",-h
);
110 fprintf(fic_repr
,"closepath\n");
111 fprintf(fic_repr
,"stroke\n");
112 fprintf(fic_repr
,"grestore\n");
115 void PSDev::rond(double x
,double y
,double rayon
)
117 fprintf(fic_repr
,"gsave\n");
118 fprintf(fic_repr
,"newpath\n");
119 fprintf(fic_repr
,"%f unit %f unit %f unit 0 360 arc\n",x
,y
,rayon
);
120 fprintf(fic_repr
,"fill\n");
121 fprintf(fic_repr
,"grestore\n");
124 void PSDev::fleche(double x
,double y
,double rotation
,int sens
)
128 fprintf(fic_repr
,"gsave\n");
129 fprintf(fic_repr
,"newpath\n");
130 fprintf(fic_repr
,"0.3 setgray\n");
131 fprintf(fic_repr
,"%f unit %f unit moveto\n",x
,y
);
132 fprintf(fic_repr
,"%f rotate\n",rotation
);
133 fprintf(fic_repr
,"%f unit %f unit rlineto\n",(double)-4,(double)-2);
134 fprintf(fic_repr
,"%f rotate\n",(double)-rotation
);
135 fprintf(fic_repr
,"%f unit %f unit moveto\n",x
,y
);
136 fprintf(fic_repr
,"%f rotate\n",rotation
);
137 fprintf(fic_repr
,"%f unit %f unit rlineto\n",(double)-4,(double)+2);
138 fprintf(fic_repr
,"closepath\n");
139 fprintf(fic_repr
,"stroke\n");
140 fprintf(fic_repr
,"grestore\n");
142 else //for the recursion
144 fprintf(fic_repr
,"gsave\n");
145 fprintf(fic_repr
,"newpath\n");
146 fprintf(fic_repr
,"0.3 setgray\n");
147 fprintf(fic_repr
,"%f unit %f unit moveto\n",x
,y
);
148 fprintf(fic_repr
,"%f rotate\n",rotation
);
149 fprintf(fic_repr
,"%f unit %f unit rlineto\n",(double)4,(double)-2);
150 fprintf(fic_repr
,"%f rotate\n",(double)-rotation
);
151 fprintf(fic_repr
,"%f unit %f unit moveto\n",x
,y
);
152 fprintf(fic_repr
,"%f rotate\n",rotation
);
153 fprintf(fic_repr
,"%f unit %f unit rlineto\n",(double)4,(double)+2);
154 fprintf(fic_repr
,"closepath\n");
155 fprintf(fic_repr
,"stroke\n");
156 fprintf(fic_repr
,"grestore\n");
160 void PSDev::carre(double x
,double y
,double cote
)
162 fprintf(fic_repr
,"gsave\n");
163 fprintf(fic_repr
,"newpath\n");
164 fprintf(fic_repr
,"0.3 setgray\n");
165 fprintf(fic_repr
,"%f unit %f unit moveto\n",x
-cote
/2,y
);
166 fprintf(fic_repr
,"0 unit %f unit rlineto\n",-cote
);
167 fprintf(fic_repr
,"%f unit 0 unit rlineto\n",cote
);
168 fprintf(fic_repr
,"0 unit %f unit rlineto\n",cote
);
169 fprintf(fic_repr
,"closepath\n");
170 fprintf(fic_repr
,"stroke\n");
171 fprintf(fic_repr
,"grestore\n");
174 void PSDev::trait(double x1
,double y1
,double x2
,double y2
)
176 fprintf(fic_repr
,"gsave\n");
177 fprintf(fic_repr
,"0.3 setgray\n");
178 fprintf(fic_repr
,"newpath\n");
179 fprintf(fic_repr
,"%f unit %f unit moveto\n",x1
,y1
);
180 fprintf(fic_repr
,"%f unit %f unit lineto\n",x2
,y2
);
181 fprintf(fic_repr
,"stroke\n");
182 fprintf(fic_repr
,"grestore\n");
185 void PSDev::dasharray(double x1
,double y1
,double x2
,double y2
)
187 fprintf(fic_repr
,"gsave\n");
188 fprintf(fic_repr
,"newpath\n");
189 fprintf(fic_repr
,"0.6 setgray\n");
190 fprintf(fic_repr
,"0.8 unit setlinewidth\n");
191 fprintf(fic_repr
,"%f unit %f unit moveto\n",x1
,y1
);
192 fprintf(fic_repr
,"%f unit %f unit lineto\n",x2
,y2
);
193 fprintf(fic_repr
,"stroke\n");
194 fprintf(fic_repr
,"grestore\n");
197 void PSDev::text(double x
,double y
,const char* nom
, const char* link
)
199 fprintf(fic_repr
,"newpath\n");
200 //fprintf(fic_repr,"%f unit %f unit moveto\n",(x-4)-(strlen(nom)-1)*3.8,y+2);
201 fprintf(fic_repr
,"%f unit %f unit moveto\n",(x
-0)-(strlen(nom
)-1)*3.8,y
+2);
202 fprintf(fic_repr
,"gsave\n");
203 fprintf(fic_repr
,"1 -1 scale\n\n");
204 fprintf(fic_repr
,"(%s) show\n",nom
);
205 fprintf(fic_repr
,"grestore\n");
208 void PSDev::label(double x
,double y
,const char* label
)
210 fprintf(fic_repr
,"gsave\n");
211 fprintf(fic_repr
,"/Times-Roman findfont %% Get the basic font for text\n");
212 fprintf(fic_repr
,"7 unit scalefont %% Scale the font to 10 points\n");
213 fprintf(fic_repr
,"setfont %% Make it the current font\n\n");
214 fprintf(fic_repr
,"newpath\n");
215 fprintf(fic_repr
,"%f unit %f unit moveto\n",(x
+2),y
+1.2);
216 fprintf(fic_repr
,"1 -1 scale\n");
217 fprintf(fic_repr
,"(%s) show\n",label
);
218 fprintf(fic_repr
,"grestore\n");
221 void PSDev::markSens(double x
,double y
,int sens
)
225 fprintf(fic_repr
,"newpath\n");
226 fprintf(fic_repr
,"%f unit %f unit moveto\n",x
,y
+4);
227 fprintf(fic_repr
,"%f unit %f unit rlineto\n",(double)4,(double)-4);
228 fprintf(fic_repr
,"closepath\n");
230 else //for the recursion
232 fprintf(fic_repr
,"newpath\n");
233 fprintf(fic_repr
,"%f unit %f unit moveto\n",x
,y
-4);
234 fprintf(fic_repr
,"%f unit %f unit rlineto\n",(double)-4,(double)4);
235 fprintf(fic_repr
,"closepath\n");
237 fprintf(fic_repr
,"stroke\n");
240 void PSDev::Error(const char* message
, const char* reason
,int nb_error
,double x
,double y
,double largeur
)
242 fprintf(fic_repr
,"gsave\n");
243 fprintf(fic_repr
,"/Times-Roman findfont %% Get the basic font for text\n");
244 fprintf(fic_repr
,"17 unit scalefont %% Scale the font to 10 points\n");
245 fprintf(fic_repr
,"setfont %% Make it the current font\n\n");
246 fprintf(fic_repr
,"newpath\n");
247 fprintf(fic_repr
,"%f unit %f unit moveto\n",(x
-8)-(strlen(message
)-1)*3.8,y
-10);
248 fprintf(fic_repr
,"1 -1 scale\n");
249 fprintf(fic_repr
,"(%s) show\n",message
);
250 fprintf(fic_repr
,"1 -1 scale\n");
251 fprintf(fic_repr
,"%f unit %f unit moveto\n",(x
-8)-(strlen(reason
)-1)*3.8,y
+10);
252 fprintf(fic_repr
,"1 -1 scale\n");
253 fprintf(fic_repr
,"(%s) show\n",reason
);
254 fprintf(fic_repr
,"grestore\n");