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