Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/visualization/OpenInventor/src/SbPainterPS.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /visualization/OpenInventor/src/SbPainterPS.cc (Version 11.3.0) and /visualization/OpenInventor/src/SbPainterPS.cc (Version 6.0.p1)


  1 //                                                  1 
  2 // *******************************************    
  3 // * License and Disclaimer                       
  4 // *                                              
  5 // * The  Geant4 software  is  copyright of th    
  6 // * the Geant4 Collaboration.  It is provided    
  7 // * conditions of the Geant4 Software License    
  8 // * LICENSE and available at  http://cern.ch/    
  9 // * include a list of copyright holders.         
 10 // *                                              
 11 // * Neither the authors of this software syst    
 12 // * institutes,nor the agencies providing fin    
 13 // * work  make  any representation or  warran    
 14 // * regarding  this  software system or assum    
 15 // * use.  Please see the license in the file     
 16 // * for the full disclaimer and the limitatio    
 17 // *                                              
 18 // * This  code  implementation is the result     
 19 // * technical work of the GEANT4 collaboratio    
 20 // * By using,  copying,  modifying or  distri    
 21 // * any work based  on the software)  you  ag    
 22 // * use  in  resulting  scientific  publicati    
 23 // * acceptance of all terms of the Geant4 Sof    
 24 // *******************************************    
 25 //                                                
 26 /*----------------------------HEPVis----------    
 27 /*                                                
 28 /* Node:             SbPainterPS                  
 29 /* Author:           Guy Barrand                  
 30 /*                                                
 31 /*--------------------------------------------    
 32 // this :                                         
 33 #include <HEPVis/SbPainterPS.h>                   
 34                                                   
 35 //#include <HEPVis/SbString.h>                    
 36 #define STRDUP(str)  ((str) != NULL ? (::strcp    
 37 #define STRDEL(str) {if((str)!=NULL) {::free(s    
 38                                                   
 39 //#define DEBUG                                   
 40 #include <stdlib.h>                               
 41 #include <string.h>                               
 42 #include <stdio.h>                                
 43 #include <stdarg.h>                               
 44 #include <time.h>                                 
 45 #include <locale.h>                               
 46                                                   
 47 #define METAFILE_DEFAULT "out.ps"                 
 48 #define METAFILE_SCALE 1.                         
 49                                                   
 50 static char* GetDate();                           
 51 static double ConvertRGB_ToGrey(double,double,    
 52 //////////////////////////////////////////////    
 53 SbPainterPS::SbPainterPS(                         
 54 )                                                 
 55 :fDeviceWidth((8.5-1.) * 72. * METAFILE_SCALE)    
 56 ,fDeviceHeight(11.     * 72. * METAFILE_SCALE)    
 57 ,fPageNumber(0)                                   
 58 ,fMarkerSize(2.)                                  
 59 ,fFile(NULL)                                      
 60 ,fFileName(NULL)                                  
 61 ,fGSave(0)                                        
 62 ,fBufferCount(0)                                  
 63 ,fBufferString(NULL)                              
 64 //////////////////////////////////////////////    
 65 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
 66 {                                                 
 67   fParams.shade = Color;                          
 68   fParams.portrait = 1;                           
 69   fParams.nbit = 2;                               
 70   fParams.doBack = 1;                             
 71   fParams.lineWidth = -1.;                        
 72   fBufferPointer[0] = '\0';                       
 73 #ifdef WIN32                                      
 74   ::setlocale(LC_NUMERIC,"USA");                  
 75 #endif                                            
 76 }                                                 
 77 //////////////////////////////////////////////    
 78 SbPainterPS::~SbPainterPS(                        
 79 )                                                 
 80 //////////////////////////////////////////////    
 81 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
 82 {                                                 
 83   if(fFile!=NULL) closeStream ();                 
 84   if(fBufferString!=NULL) ::free(fBufferString    
 85   fBufferString = NULL;                           
 86   if(fGSave!=0) {                                 
 87     ::printf("SbPainterPS : bad gsave/grestore    
 88   }                                               
 89 }                                                 
 90 //////////////////////////////////////////////    
 91 //////////////////////////////////////////////    
 92 //////////////////////////////////////////////    
 93 void SbPainterPS::beginTraversal (                
 94 )                                                 
 95 //////////////////////////////////////////////    
 96 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
 97 {                                                 
 98   if(fFile==NULL) openFileForWriting(NULL);       
 99   if(fFile==NULL) return;                         
100   putBeginPageInStream();                         
101   putPageScaleInStream((float)fWindowWidth,(fl    
102   putSaveStateInStream();                         
103 }                                                 
104 //////////////////////////////////////////////    
105 void SbPainterPS::endTraversal(                   
106 )                                                 
107 //////////////////////////////////////////////    
108 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
109 {                                                 
110   if(fFile==NULL) return;                         
111   putFrameInStream(0.0,0.0,0.0,(float)fWindowW    
112   putRestoreStateInStream();                      
113   putEndPageInStream();                           
114 }                                                 
115 //////////////////////////////////////////////    
116 void SbPainterPS::clearColorBuffer(               
117  float aRed                                       
118 ,float aGreen                                     
119 ,float aBlue                                      
120 )                                                 
121 //////////////////////////////////////////////    
122 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
123 {                                                 
124   if(fFile==NULL) return;                         
125   putBackgroundInStream(aRed,aGreen,aBlue,        
126                            (float)fWindowWidth    
127 }                                                 
128 /*                                                
129 //////////////////////////////////////////////    
130 void SbPainterPS::drawPrimitive (                 
131  SbPrimitiveType aType                            
132 ,int aPointn                                      
133 ,float* aXs                                       
134 ,float* aYs                                       
135 ,float* //aZs                                     
136 ,const SbPainterContext& aAtb                     
137 )                                                 
138 //////////////////////////////////////////////    
139 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
140 {                                                 
141   if(fFile==NULL) return;                         
142   switch(aType) {                                 
143   case SbPrimitivePoints:                         
144     drawMarkers(aPointn,                          
145                 aXs,aYs,                          
146                 aAtb.fRed,aAtb.fGreen,aAtb.fBl    
147                 aAtb.fMarkerStyle,aAtb.fMarker    
148     break;                                        
149   case SbPrimitiveLineStrip:                      
150   case SbPrimitiveLineLoop:                       
151     drawLines(aPointn,                            
152               aXs,aYs,                            
153               aAtb.fRed,aAtb.fGreen,aAtb.fBlue    
154               aAtb.fLineStyle,aAtb.fLineWidth)    
155     break;                                        
156   case SbPrimitivePolygon:                        
157     drawPolygon(aPointn,                          
158                 aXs,aYs,                          
159                 aAtb.fRed,aAtb.fGreen,aAtb.fBl    
160                 aAtb.fAreaStyle);                 
161     break;                                        
162   default:                                        
163     break;                                        
164   }                                               
165 }                                                 
166 //////////////////////////////////////////////    
167 void SbPainterPS::drawPolygon(                    
168  int aPointn                                      
169 ,float* aXs                                       
170 ,float* aYs                                       
171 ,float aRed                                       
172 ,float aGreen                                     
173 ,float aBlue                                      
174 ,const SbAreaStyle& //aStyle                      
175 )                                                 
176 //////////////////////////////////////////////    
177 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
178 {                                                 
179   if(fFile==NULL) return;                         
180   if(aPointn<=0) return;                          
181   putNewPathInStream();                           
182   putMoveInStream(aXs[0],aYs[0]);                 
183   for(int count=1;count<aPointn;count++) {        
184     putLineToInStream(aXs[count] - aXs[count-1    
185                       aYs[count] - aYs[count-1    
186   }                                               
187   if ( (aXs[0]==aXs[aPointn-1]) &&                
188        (aYs[0]==aYs[aPointn-1]) )                 
189     putClosePathInStream();                       
190   putRGB_InStream(aRed,aGreen,aBlue);             
191   putFillInStream();                              
192 }                                                 
193 //////////////////////////////////////////////    
194 void SbPainterPS::drawLines(                      
195  int aPointn                                      
196 ,float* aXs                                       
197 ,float* aYs                                       
198 ,float aRed                                       
199 ,float aGreen                                     
200 ,float aBlue                                      
201 ,const SbLineStyle& aStyle                        
202 ,int aWidth                                       
203 )                                                 
204 //////////////////////////////////////////////    
205 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
206 {                                                 
207   if(fFile==NULL) return;                         
208   if(aPointn<=0) return;                          
209   putMoveInStream(aXs[0],aYs[0]);                 
210   for(int count=1;count<aPointn;count++) {        
211     putLineToInStream(aXs[count] - aXs[count-1    
212                       aYs[count] - aYs[count-1    
213   }                                               
214   if ( (aXs[0]==aXs[aPointn-1]) &&                
215        (aYs[0]==aYs[aPointn-1]) )                 
216     putClosePathInStream();                       
217   putRGB_InStream(aRed,aGreen,aBlue);             
218   putLineWidthInStream(aWidth);                   
219   putCapInStream(1);                              
220   putLineStyleInStream(aStyle);                   
221   putStrokeInStream();                            
222 }                                                 
223 //////////////////////////////////////////////    
224 void SbPainterPS::drawMarkers (                   
225  int aPointn                                      
226 ,float* aXs                                       
227 ,float* aYs                                       
228 ,float aRed                                       
229 ,float aGreen                                     
230 ,float aBlue                                      
231 ,const SbMarkerStyle& aStyle                      
232 ,int aSize                                        
233 )                                                 
234 //////////////////////////////////////////////    
235 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
236 {                                                 
237   if(fFile==NULL) return;                         
238   float mark_size  = (float)(aSize <=0 ? 1. :     
239   mark_size *= 0.6F;                              
240   if(aStyle==SbMarkerCircleLine) {                
241     putNewPathInStream();                         
242     int icount = 1;                               
243     for(int count=0;count<aPointn;count++) {      
244       putCircleInStream(aXs[count],aYs[count],    
245 #define MAX_PATH_POINT 100                        
246       if(icount==MAX_PATH_POINT) {                
247         putRGB_InStream(aRed,aGreen,aBlue);       
248         putLineWidthInStream(1);                  
249         putCapInStream(1);                        
250         putStrokeInStream();                      
251         icount = 1;                               
252         if(count!=aPointn-1) putNewPathInStrea    
253       } else {                                    
254         icount++;                                 
255       }                                           
256     }                                             
257     putRGB_InStream(aRed,aGreen,aBlue);           
258     putLineWidthInStream(1);                      
259     putCapInStream(1);                            
260     putStrokeInStream();                          
261   } else {                                        
262     putNewPathInStream();                         
263     int icount = 1;                               
264     for(int count=0;count<aPointn;count++) {      
265       putMoveInStream(aXs[count],aYs[count]);     
266       putMarkerSizeInStream(mark_size);           
267       putMarkerStyleInStream(aStyle);             
268       if(icount==MAX_PATH_POINT) {                
269         putRGB_InStream(aRed,aGreen,aBlue);       
270         putLineWidthInStream(1);                  
271         putCapInStream(1);                        
272         putStrokeInStream();                      
273         icount = 1;                               
274         if(count!=aPointn-1) putNewPathInStrea    
275       } else {                                    
276         icount++;                                 
277       }                                           
278     }                                             
279     putRGB_InStream(aRed,aGreen,aBlue);           
280     putLineWidthInStream(1);                      
281     putCapInStream(1);                            
282     putStrokeInStream();                          
283   }                                               
284 }                                                 
285 */                                                
286 //////////////////////////////////////////////    
287 //////////////////////////////////////////////    
288 //////////////////////////////////////////////    
289 //////////////////////////////////////////////    
290 void SbPainterPS::setColorScheme(                 
291  int aShade                                       
292 )                                                 
293 //////////////////////////////////////////////    
294 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
295 {                                                 
296   fParams.shade = aShade;                         
297 }                                                 
298 //////////////////////////////////////////////    
299 void SbPainterPS::setOrientation(                 
300  int aPortrait                                    
301 )                                                 
302 //////////////////////////////////////////////    
303 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
304 {                                                 
305   fParams.portrait = aPortrait;                   
306 }                                                 
307 //////////////////////////////////////////////    
308 void SbPainterPS::setBackgroundDrawn(             
309  int aDoback                                      
310 )                                                 
311 //////////////////////////////////////////////    
312 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
313 {                                                 
314   fParams.doBack = aDoback;                       
315 }                                                 
316 //////////////////////////////////////////////    
317 void SbPainterPS::setBitsPerPixel(                
318  int aNbit                                        
319 )                                                 
320 //////////////////////////////////////////////    
321 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
322 {                                                 
323   if( (aNbit==2) || (aNbit==4) || (aNbit==8) )    
324     fParams.nbit = aNbit;                         
325   else                                            
326     fParams.nbit = 2;                             
327 }                                                 
328 //////////////////////////////////////////////    
329 void SbPainterPS::setLineWidth(                   
330  int aWidth                                       
331 )                                                 
332 //////////////////////////////////////////////    
333 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
334 {                                                 
335   fParams.lineWidth = (float)aWidth;              
336 }                                                 
337 //////////////////////////////////////////////    
338 //////////////////////////////////////////////    
339 //////////////////////////////////////////////    
340 void SbPainterPS::setFileName(                    
341  const char* aString                              
342 )                                                 
343 //////////////////////////////////////////////    
344 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
345 {                                                 
346   STRDEL(fFileName);                              
347   fFileName = STRDUP(aString);                    
348 }                                                 
349 //////////////////////////////////////////////    
350 const char* SbPainterPS::getFileName(             
351 ) const                                           
352 //////////////////////////////////////////////    
353 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
354 {                                                 
355   return fFileName;                               
356 }                                                 
357 //////////////////////////////////////////////    
358 void* SbPainterPS::getStream(                     
359 )                                                 
360 //////////////////////////////////////////////    
361 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
362 {                                                 
363   return fFile;                                   
364 }                                                 
365 //////////////////////////////////////////////    
366 void SbPainterPS::openFileForWriting(             
367  const char* aString                              
368 )                                                 
369 //////////////////////////////////////////////    
370 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
371 {                                                 
372   if(fFile!=NULL) closeStream ();                 
373   if( (aString==NULL) || (*aString=='\0') ) {     
374     if( (fFileName==NULL) || (*fFileName=='\0'    
375       fFile = ::fopen(METAFILE_DEFAULT,"wb");     
376       STRDEL(fFileName);                          
377       fFileName = STRDUP(METAFILE_DEFAULT);       
378     } else {                                      
379       fFile = ::fopen(fFileName,"wb");            
380     }                                             
381   } else {                                        
382     fFile = ::fopen(aString,"wb");                
383     STRDEL(fFileName);                            
384     fFileName = STRDUP(aString);                  
385   }                                               
386   if(fFile==NULL) return;                         
387                                                   
388   fBufferCount = 0;                               
389   fBufferPointer[METAFILE_RECORD_LENGTH] = '\0    
390   fPageNumber = 0;                                
391   // Header :                                     
392   printFLN   ("%%!PS-Adobe-2.0");                 
393   printFLN   ("%%%%Creator: HEPVis::SbPainterP    
394   printFLN("%%%%CreationDate: %s",GetDate());     
395   printFLN("%%%%Title: %s",fFileName);            
396   printFLN("%%%%Pages: (atend)");                 
397   printFLN("%%%%BoundingBox: 0 0 %d %d",          
398            (int)fDeviceWidth,(int)fDeviceHeigh    
399   printFLN("%%%%DocumentFonts: Courier-Bold");    
400   printFLN("%%%%DocumentPaperSizes: a4");         
401   printFLN("%%%%EndComments");                    
402   // PostScript :                                 
403   putSaveStateInStream      ();                   
404   // General :                                    
405   putInStreamF("/n {newpath} def ");              
406   putInStreamF("/cl {closepath} def ");           
407   putInStreamF("/s {stroke} def ");               
408   putInStreamF("/f {fill} def ");                 
409   // Move :                                       
410   putInStreamF("/m  {moveto} def ");              
411   putInStreamF("/rm {rmoveto} def ");             
412   putInStreamF("/rl {rlineto} def ");             
413   // Line :                                       
414   putInStreamF("/lc {setlinecap} def ");          
415   putInStreamF("/lw {setlinewidth} def ");        
416   putInStreamF("/rgb {setrgbcolor} def ");        
417   putInStreamF("/ss {[] 0 setdash} def ") ;       
418   putInStreamF("/sd {[12 6] 0 setdash} def ");    
419   putInStreamF("/so {[6 12] 0 setdash} def ");    
420   putInStreamF("/sdo {[18 12 6 12] 0 setdash}     
421   // Mark :                                       
422   fMarkerSize = 2.;                               
423   putInStreamF("/ms 2. def /msi .5 def ");        
424   putInStreamF("/cross {ms ms scale -1. -1. rm    
425   putInStreamF("2. 2. rl 0. -2. rm -2. 2. rl m    
426   putInStreamF("/plus  {ms ms scale -1. 0. rm     
427   putInStreamF("-1. 1. rm 0. -2. rl msi msi sc    
428   putInStreamF("/asterisk {ms ms scale -1. 0.     
429   putInStreamF("0. -2. rl 0. 1. rm -0.707 -0.7    
430   putInStreamF("0. -1.414 rm -1.414 1.414 rl m    
431   putInStreamF("/triangle {ms ms scale 0. 1. r    
432   putInStreamF("1.2 0. rl -0.6 1.5 rl msi msi     
433   // Text :                                       
434   putInStreamF("/sh {show} def ");                
435   putInStreamF("/df {/Courier-Bold findfont} d    
436   putInStreamF("/mf {makefont setfont} def ");    
437   printFLN("%%%%EndProlog");                      
438 }                                                 
439 //////////////////////////////////////////////    
440 void SbPainterPS::closeStream(                    
441 )                                                 
442 //////////////////////////////////////////////    
443 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
444 {                                                 
445   if(fFile==NULL) return;                         
446   putRestoreStateInStream    ();                  
447   printFLN("%%%%Trailer");                        
448   printFLN("%%%%Pages: %d",fPageNumber);          
449   printFLN("%%%%EOF");                            
450   if(fFile!=NULL) ::fclose(fFile);                
451   fFile = NULL;                                   
452   STRDEL(fFileName);                              
453   fFileName = NULL;                               
454 }                                                 
455 //////////////////////////////////////////////    
456 void SbPainterPS::putInStreamF(                   
457  const char* aFormat                              
458 ,...                                              
459 )                                                 
460 //////////////////////////////////////////////    
461 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
462 {                                                 
463   if(fFile==NULL) return;                         
464   va_list  args;                                  
465   va_start(args,aFormat);                         
466   printV(aFormat,args);                           
467   va_end(args);                                   
468   int length = (int)strlen(fBufferString);        
469   if(length>METAFILE_RECORD_LENGTH) {             
470     ::printf("SoPostScript::putInStreamF overf    
471     return;                                       
472   }                                               
473   int nlength = fBufferCount + length;            
474   if(nlength>METAFILE_RECORD_LENGTH) {            
475       fBufferPointer[fBufferCount] = '\0';        
476       if(::fprintf(fFile,"%s\n",(char*)fBuffer    
477         ::printf("SoPostScript::putInStreamF f    
478       }                                           
479       fBufferCount = 0;                           
480       nlength = length;                           
481     }                                             
482   unsigned char* pointer = fBufferPointer + fB    
483   ::strcpy((char*)pointer,fBufferString);         
484   fBufferCount = nlength;                         
485 }                                                 
486 //////////////////////////////////////////////    
487 void SbPainterPS::printFLN(                       
488  const char* aFormat                              
489 ,...                                              
490 )                                                 
491 //////////////////////////////////////////////    
492 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
493 {                                                 
494   if(fFile==NULL) return;                         
495   va_list args;                                   
496   va_start(args,aFormat);                         
497   printV(aFormat,args);                           
498   va_end(args);                                   
499 /* put buffer in file */                          
500   if(fBufferCount>0) {                            
501     fBufferPointer[fBufferCount] = '\0';          
502     if(::fprintf (fFile,"%s\n",(char*)fBufferP    
503       ::printf("SbPainterPS::printFLN fprintf     
504     }                                             
505     fBufferCount = 0;                             
506   }                                               
507 /* put comment in file */                         
508   if(::fprintf (fFile,"%s\n",fBufferString)<0)    
509     ::printf("SbPainterPS::printFLN fprintf er    
510   }                                               
511 }                                                 
512 //////////////////////////////////////////////    
513 void SbPainterPS::printV(                         
514  const char* This                                 
515 ,va_list aArgs                                    
516 )                                                 
517 //////////////////////////////////////////////    
518 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
519 {                                                 
520 #define MAX_STR    2048                           
521   if(fBufferString==NULL) {                       
522     fBufferString = (char*)::malloc(MAX_STR *     
523     if(fBufferString==NULL) return;               
524   }                                               
525   fBufferString[MAX_STR-1]  = '\0';               
526   ::vsnprintf(fBufferString,MAX_STR-1, This,aA    
527   if(fBufferString[MAX_STR-1]!='\0') {            
528     ::printf("SbPainterPS::printV overflow\n")    
529     fBufferString[0] = '\0';                      
530   }                                               
531 }                                                 
532 //////////////////////////////////////////////    
533 //////////////////////////////////////////////    
534 //////////////////////////////////////////////    
535 //////////////////////////////////////////////    
536 void SbPainterPS::putPageScaleInStream(           
537  float aWidth                                     
538 ,float aHeight                                    
539 )                                                 
540 //////////////////////////////////////////////    
541 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
542 {                                                 
543   if(aWidth <=0.) aWidth  = 100.;                 
544   if(aHeight<=0.) aHeight = 100.;                 
545                                                   
546   putScaleInStream (1./METAFILE_SCALE,1./METAF    
547   putTranslationInStream ((float)(fDeviceWidth    
548                           (float)(fDeviceHeigh    
549                                                   
550   float scale;                                    
551   if(fDeviceWidth<=fDeviceHeight)                 
552     scale = (aHeight<=aWidth ?                    
553              fDeviceWidth /aWidth  : fDeviceWi    
554   else                                            
555     scale = (aHeight<=aWidth ?                    
556              fDeviceHeight /aWidth : fDeviceHe    
557                                                   
558   float xtra,ytra;                                
559   if(fParams.portrait==1) {                       
560     xtra = (fDeviceWidth  - scale * aWidth)/2;    
561     ytra = (fDeviceHeight - scale * aHeight)/2    
562   } else {                                        
563     putTranslationInStream(fDeviceWidth,0.);      
564     putRotateInStream(90);                        
565     xtra = (fDeviceHeight  - scale * aWidth)/2    
566     ytra = (fDeviceWidth   - scale * aHeight)/    
567   }                                               
568   putTranslationInStream (xtra,ytra);             
569                                                   
570   putScaleInStream (scale,scale);                 
571 }                                                 
572 //////////////////////////////////////////////    
573 //////////////////////////////////////////////    
574 //////////////////////////////////////////////    
575 //////////////////////////////////////////////    
576 void SbPainterPS::putSaveStateInStream(           
577 )                                                 
578 //////////////////////////////////////////////    
579 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
580 {                                                 
581   putInStreamF("gsave ");                         
582   fGSave++;                                       
583 }                                                 
584 //////////////////////////////////////////////    
585 void SbPainterPS::putRestoreStateInStream(        
586 )                                                 
587 //////////////////////////////////////////////    
588 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
589 {                                                 
590   putInStreamF("grestore ");                      
591   fGSave--;                                       
592 }                                                 
593 //////////////////////////////////////////////    
594 void SbPainterPS::putTranslationInStream(         
595  float aX                                         
596 ,float aY                                         
597 )                                                 
598 //////////////////////////////////////////////    
599 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
600 {                                                 
601   putInStreamF("%.2f %.2f translate ",aX,aY);     
602 }                                                 
603 //////////////////////////////////////////////    
604 void SbPainterPS::putScaleInStream(               
605  float aX                                         
606 ,float aY                                         
607 )                                                 
608 //////////////////////////////////////////////    
609 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
610 {                                                 
611   putInStreamF("%.2f %.2f scale ",aX,aY);         
612 }                                                 
613 //////////////////////////////////////////////    
614 void SbPainterPS::putBeginPageInStream(           
615 )                                                 
616 //////////////////////////////////////////////    
617 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
618 {                                                 
619   fPageNumber++;                                  
620   printFLN("%%%%Page: %d %d",fPageNumber,fPage    
621   putSaveStateInStream();                         
622 }                                                 
623 //////////////////////////////////////////////    
624 void SbPainterPS::putEndPageInStream (            
625 )                                                 
626 //////////////////////////////////////////////    
627 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
628 {                                                 
629   putInStreamF("showpage ");                      
630   putRestoreStateInStream();                      
631 }                                                 
632 //////////////////////////////////////////////    
633 void SbPainterPS::putRGB_InStream (               
634  float aR                                         
635 ,float aG                                         
636 ,float aB                                         
637 )                                                 
638 //////////////////////////////////////////////    
639 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
640 {                                                 
641   if(fParams.shade==Color)                        
642     putInStreamF("%.2f %.2f %.2f rgb ",aR,aG,a    
643   else if(fParams.shade==Grey)                    
644     putInStreamF("%.2f setgray ",convertRGB_To    
645   else if(fParams.shade==BlackWhite)              
646     putInStreamF("0. setgray ",convertRGB_ToGr    
647 }                                                 
648 //////////////////////////////////////////////    
649 void SbPainterPS::putLineWidthInStream(           
650  int aWidth                                       
651 )                                                 
652 //////////////////////////////////////////////    
653 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
654 {                                                 
655   if(fParams.lineWidth<0.) {                      
656     if(aWidth==1) {                               
657       putInStreamF("%.1f lw ",0.5); // For a b    
658     } else {                                      
659       putInStreamF("%.1f lw ",(float)(aWidth))    
660     }                                             
661   } else {                                        
662     putInStreamF("%.1f lw ",fParams.lineWidth)    
663   }                                               
664 }                                                 
665 //////////////////////////////////////////////    
666 void SbPainterPS::putMarkerSizeInStream (         
667  float aSize                                      
668 )                                                 
669 //////////////////////////////////////////////    
670 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
671 {                                                 
672   if(aSize==fMarkerSize) return;                  
673   fMarkerSize = aSize;                            
674   putInStreamF("/ms %g def /msi %g def ",aSize    
675 }                                                 
676 /*                                                
677 //////////////////////////////////////////////    
678 void SbPainterPS::putMarkerStyleInStream (        
679  SbMarkerStyle aStyle                             
680 )                                                 
681 //////////////////////////////////////////////    
682 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
683 {                                                 
684   switch (aStyle) {                               
685   case SbMarkerPlus:                              
686     putInStreamF("plus ");                        
687     break;                                        
688   case SbMarkerAsterisk:                          
689   case SbMarkerStar:                              
690     putInStreamF("asterisk ");                    
691     break;                                        
692   case SbMarkerCross:                             
693     putInStreamF("cross ");                       
694     break;                                        
695   case SbMarkerTriangleUpLine:                    
696     putInStreamF("triangle ");                    
697     break;                                        
698   default:                                        
699     putLineToInStream(0.,0.);                     
700     break;                                        
701   }                                               
702 }                                                 
703 */                                                
704 //////////////////////////////////////////////    
705 void SbPainterPS::putBackgroundInStream (         
706  float aR                                         
707 ,float aG                                         
708 ,float aB                                         
709 ,float aWidth                                     
710 ,float aHeight                                    
711 )                                                 
712 //////////////////////////////////////////////    
713 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
714 {                                                 
715   putNewPathInStream();                           
716   putMoveInStream(0.,0.);                         
717   putLineToInStream(aWidth,0.);                   
718   putLineToInStream(0.,aHeight);                  
719   putLineToInStream(-aWidth,0.);                  
720   putLineToInStream(0.,-aHeight);                 
721   putClosePathInStream();                         
722   if(fParams.doBack==1) {                         
723     // Back :                                     
724     putSaveStateInStream();                       
725     putRGB_InStream(aR,aG,aB);                    
726     putFillInStream();                            
727     putRestoreStateInStream();                    
728   }                                               
729   // Clip :                                       
730   putInStreamF("clip ");                          
731 }                                                 
732 //////////////////////////////////////////////    
733 void SbPainterPS::putFrameInStream (              
734  float aR                                         
735 ,float aG                                         
736 ,float aB                                         
737 ,float aWidth                                     
738 ,float aHeight                                    
739 )                                                 
740 //////////////////////////////////////////////    
741 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
742 {                                                 
743   putNewPathInStream();                           
744   putMoveInStream(0.,0.);                         
745   putLineToInStream(aWidth,0.);                   
746   putLineToInStream(0.,aHeight);                  
747   putLineToInStream(-aWidth,0.);                  
748   putLineToInStream(0.,-aHeight);                 
749   putClosePathInStream();                         
750   putRGB_InStream(aR,aG,aB);                      
751   putLineWidthInStream(1);                        
752   putCapInStream(1);                              
753   putInStreamF("ss ");                            
754   putStrokeInStream();                            
755 }                                                 
756 //////////////////////////////////////////////    
757 float SbPainterPS::convertRGB_ToGrey (            
758  float aRed                                       
759 ,float aGreen                                     
760 ,float aBlue                                      
761 )                                                 
762 //////////////////////////////////////////////    
763 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
764 {                                                 
765   return (0.3F * aRed + 0.59F * aGreen + 0.11F    
766 }                                                 
767 //////////////////////////////////////////////    
768 void SbPainterPS::putRotateInStream(              
769  float aX                                         
770 )                                                 
771 //////////////////////////////////////////////    
772 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
773 {                                                 
774   putInStreamF("%.2f  rotate ",aX);               
775 }                                                 
776 //////////////////////////////////////////////    
777 void SbPainterPS::putNewPathInStream(             
778 )                                                 
779 //////////////////////////////////////////////    
780 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
781 {                                                 
782   putInStreamF("n ");                             
783 }                                                 
784 //////////////////////////////////////////////    
785 void SbPainterPS::putStrokeInStream(              
786 )                                                 
787 //////////////////////////////////////////////    
788 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
789 {                                                 
790   putInStreamF("s ");                             
791 }                                                 
792 //////////////////////////////////////////////    
793 void SbPainterPS::putFillInStream(                
794 )                                                 
795 //////////////////////////////////////////////    
796 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
797 {                                                 
798   putInStreamF("f ");                             
799 }                                                 
800 //////////////////////////////////////////////    
801 void SbPainterPS::putClosePathInStream(           
802 )                                                 
803 //////////////////////////////////////////////    
804 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
805 {                                                 
806   putInStreamF("cl ");                            
807 }                                                 
808 //////////////////////////////////////////////    
809 void SbPainterPS::putCapInStream(                 
810  int aX                                           
811 )                                                 
812 //////////////////////////////////////////////    
813 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
814 {                                                 
815   putInStreamF("%1d lc ",aX);                     
816 }                                                 
817 //////////////////////////////////////////////    
818 void SbPainterPS::putLineToInStream(              
819  float aX                                         
820 ,float aY                                         
821 )                                                 
822 //////////////////////////////////////////////    
823 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
824 {                                                 
825   putInStreamF ("%.2f %.2f rl ",aX,aY);           
826 }                                                 
827 //////////////////////////////////////////////    
828 void SbPainterPS::putMoveInStream(                
829  float aX                                         
830 ,float aY                                         
831 )                                                 
832 //////////////////////////////////////////////    
833 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
834 {                                                 
835   putInStreamF ("%.2f %.2f m ",aX,aY);            
836 }                                                 
837 //////////////////////////////////////////////    
838 void SbPainterPS::putCircleInStream(              
839  float aX                                         
840 ,float aY                                         
841 ,float aR                                         
842 )                                                 
843 //////////////////////////////////////////////    
844 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
845 {                                                 
846   putInStreamF("%.2f %.2f %.2f 0 360 arc s ",a    
847 }                                                 
848 /*                                                
849 //////////////////////////////////////////////    
850 void SbPainterPS::putLineStyleInStream(           
851  SbLineStyle aStyle                               
852 )                                                 
853 //////////////////////////////////////////////    
854 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
855 {                                                 
856   switch(aStyle) {                                
857   case SbLineSolid:putInStreamF("ss ") ;break;    
858   case SbLineDashed:putInStreamF("sd ") ;break    
859   case SbLineDotted:putInStreamF("so ") ;break    
860   case SbLineDashDotted:putInStreamF("sdo ");b    
861   }                                               
862 }                                                 
863 */                                                
864 //////////////////////////////////////////////    
865 //////////////////////////////////////////////    
866 /////// Image ////////////////////////////////    
867 //////////////////////////////////////////////    
868 //////////////////////////////////////////////    
869 void SbPainterPS::putImageInStream (              
870  unsigned int aWidth                              
871 ,unsigned int aHeight                             
872 ,GetRGB_Function aProc                            
873 )                                                 
874 //////////////////////////////////////////////    
875 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
876 {                                                 
877   if((aWidth<=0)||(aHeight<=0)) return;           
878   if(!aProc) return;                              
879                                                   
880   putSaveStateInStream      ();                   
881   putInStreamF     ("%d %d scale ", aWidth, aH    
882   int status = 1;                                 
883   int      nbhex;                                 
884   unsigned int row,col,col_max;                   
885   double   dr,dg,db;                              
886   typedef unsigned char Uchar;                    
887   Uchar    red,green,blue,b;                      
888   if(fParams.shade!=0) { /*grey*/                 
889     putInStreamF   ("/picstr %d string def ",a    
890     putInStreamF   ("%d %d %d ",aWidth,aHeight    
891     putInStreamF   ("[ %d 0 0 -%d 0 %d ] ",aWi    
892     putInStreamF   ("{ currentfile picstr read    
893     printFLN ("image " );                         
894     for ( row = 0; row < aHeight; row++ ){        
895       for ( col = 0; col < aWidth; col++){        
896         double    fgrey;                          
897         Uchar     grey;                           
898         status    = aProc(col,row,dr,dg,db)==0    
899         fgrey     = ConvertRGB_ToGrey(dr,dg,db    
900         grey      = (Uchar) ( 255. * fgrey);      
901         writeByte (grey);                         
902       }                                           
903     }                                             
904     nbhex     = aWidth * aHeight * 2;             
905     printFLN ("%%%% nbhex digit          :%d "    
906     printFLN ("%%%% nbhex/record_length  :%d "    
907     printFLN ("%%%% nbhex%%record_length :%d "    
908   }else if(fParams.nbit==2){                      
909     int       nbyte2;                             
910     nbyte2    = (aWidth   *  3)/4;                
911     nbyte2   /=3;                                 
912     nbyte2   *=3;                                 
913     col_max   = (nbyte2  *  4)/3;                 
914     /* 2 bit for r and g and b   */               
915     /* rgbs following each other */               
916     putInStreamF   ("/rgbstr %d string def ",n    
917     putInStreamF   ("%d %d %d ",col_max,aHeigh    
918     putInStreamF   ("[ %d 0 0 -%d 0 %d ] ",col    
919     putInStreamF   ("{ currentfile rgbstr read    
920     putInStreamF   ("false 3 " );                 
921     printFLN ("colorimage " );                    
922     for ( row = 0; row < aHeight; row++ ){        
923       for ( col = 0; col < col_max; col+=4){      
924         status  = aProc(col,row,dr,dg,db)==0 ?    
925         red     = (Uchar) ( 3. * dr);             
926         green   = (Uchar) ( 3. * dg);             
927         blue    = (Uchar) ( 3. * db);             
928         b       = red;                            
929         b       = (b<<2)+green;                   
930         b       = (b<<2)+blue;                    
931         status  = aProc(col+1,row,dr,dg,db)==0    
932         red     = (Uchar) ( 3. * dr);             
933         green   = (Uchar) ( 3. * dg);             
934         blue    = (Uchar) ( 3. * db);             
935         b     = (b<<2)+red;                       
936         writeByte (b);                            
937                                                   
938         b       = green;                          
939         b       = (b<<2)+blue;                    
940         status  = aProc(col+2,row,dr,dg,db)==0    
941         red     = (Uchar) ( 3. * dr);             
942         green   = (Uchar) ( 3. * dg);             
943         blue    = (Uchar) ( 3. * db);             
944         b     = (b<<2)+red;                       
945         b     = (b<<2)+green;                     
946         writeByte (b);                            
947                                                   
948         b       = blue;                           
949         status  = aProc(col+3,row,dr,dg,db)==0    
950         red     = (Uchar) ( 3. * dr);             
951         green   = (Uchar) ( 3. * dg);             
952         blue    = (Uchar) ( 3. * db);             
953         b     = (b<<2)+red;                       
954         b     = (b<<2)+green;                     
955         b     = (b<<2)+blue;                      
956         writeByte (b);                            
957       }                                           
958     }                                             
959   }else if(fParams.nbit==4){                      
960     int       nbyte4;                             
961     nbyte4    = (aWidth  * 3)/2;                  
962     nbyte4   /=3;                                 
963     nbyte4   *=3;                                 
964     col_max   = (nbyte4 * 2)/3;                   
965     /* 4 bit for r and g and b   */               
966     /* rgbs following each other */               
967     putInStreamF   ("/rgbstr %d string def ",n    
968     putInStreamF   ("%d %d %d ",col_max,aHeigh    
969     putInStreamF   ("[ %d 0 0 -%d 0 %d ] ",col    
970     putInStreamF   ("{ currentfile rgbstr read    
971     putInStreamF   ("false 3 " );                 
972     printFLN ("colorimage " );                    
973     for ( row = 0; row < aHeight; row++ ){        
974       for ( col = 0; col < col_max; col+=2){      
975         status  = aProc(col,row,dr,dg,db)==0 ?    
976         red     = (Uchar) ( 15. * dr);            
977         green   = (Uchar) ( 15. * dg);            
978         putInStreamF ("%x%x",red,green);          
979         blue    = (Uchar) ( 15. * db);            
980                                                   
981         status  = aProc(col+1,row,dr,dg,db)==0    
982         red     = (Uchar) ( 15. * dr);            
983         putInStreamF ("%x%x",blue,red);           
984         green   = (Uchar) ( 15. * dg);            
985         blue    = (Uchar) ( 15. * db);            
986         putInStreamF ("%x%x",green,blue);         
987       }                                           
988     }                                             
989   }else{                                          
990     int       nbyte8;                             
991     nbyte8    = aWidth   * 3;                     
992     /* 8 bit for r and g and b   */               
993     putInStreamF   ("/rgbstr %d string def ",n    
994     putInStreamF   ("%d %d %d ",aWidth,aHeight    
995     putInStreamF   ("[ %d 0 0 -%d 0 %d ] ",aWi    
996     putInStreamF   ("{ currentfile rgbstr read    
997     putInStreamF   ("false 3 " );                 
998     printFLN   ("colorimage " );                  
999     for ( row = 0; row < aHeight; row++ ){        
1000       for ( col = 0; col < aWidth; col++){       
1001         status     = aProc(col,row,dr,dg,db)=    
1002         red        = (Uchar) ( 255. * dr);       
1003         writeByte (red);                         
1004         green      = (Uchar) ( 255. * dg);       
1005         writeByte (green);                       
1006         blue       = (Uchar) ( 255. * db);       
1007         writeByte (blue);                        
1008       }                                          
1009     }                                            
1010   }                                              
1011   if(status==0)                                  
1012     ::printf("SbPainterPS::putImageInStream:     
1013   putRestoreStateInStream();                     
1014 }                                                
1015 /////////////////////////////////////////////    
1016 void SbPainterPS::writeByte (                    
1017  unsigned char a_byte                            
1018 )                                                
1019 /////////////////////////////////////////////    
1020 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
1021 {                                                
1022   unsigned char h = a_byte / 16;                 
1023   unsigned char l = a_byte % 16;                 
1024   putInStreamF ("%x%x",h,l);                     
1025 }                                                
1026 /////////////////////////////////////////////    
1027 /////////////////////////////////////////////    
1028 /////////////////////////////////////////////    
1029 char* GetDate (                                  
1030 )                                                
1031 /////////////////////////////////////////////    
1032 // Return local date.                            
1033 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
1034 {                                                
1035   time_t d;                                      
1036   time(&d);                                      
1037   char* string = ctime(&d);                      
1038   string[24] = '\0';                             
1039   return string;                                 
1040 }                                                
1041 /////////////////////////////////////////////    
1042 double ConvertRGB_ToGrey(                        
1043  double a_red                                    
1044 ,double a_green                                  
1045 ,double a_blue                                   
1046 )                                                
1047 /////////////////////////////////////////////    
1048 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
1049 {                                                
1050   return (0.30 * a_red + 0.59 * a_green + 0.1    
1051 }                                                
1052