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