00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00034
00035
00036 #include <locale.h>
00037 #include <libintl.h>
00038
00039
00040 #include "surface.h"
00041 #include "xsmmasks.h"
00042 #include "glbvars.h"
00043 #include "action_id.h"
00044 #include "epsfutils.h"
00045 #include "util.h"
00046 #include "unit.h"
00047
00051
00052 char *PSCode[]={
00053 "%%BeginSetup\n",
00054 "% Make Fonts ISO-Encoded, taken from xmgr\n",
00055 "mark\n",
00056 "/ISOLatin1Encoding\n",
00057 " 8#000 1 8#054 {StandardEncoding exch get} for\n",
00058 " /minus\n",
00059 " 8#056 1 8#217 {StandardEncoding exch get} for\n",
00060 " /dotlessi\n",
00061 " 8#301 1 8#317 {StandardEncoding exch get} for\n",
00062 " /space /exclamdown /cent /sterling /currency /yen /brokenbar /section\n",
00063 " /dieresis /copyright /ordfeminine /guillemotleft /logicalnot /hyphen\n",
00064 " /registered /macron /degree /plusminus /twosuperior /threesuperior /acute\n",
00065 " /mu /paragraph /periodcentered /cedilla /onesuperior /ordmasculine\n",
00066 " /guillemotright /onequarter /onehalf /threequarters /questiondown /Agrave\n",
00067 " /Aacute /Acircumflex /Atilde /Adieresis /Aring /AE /Ccedilla /Egrave /Eacute\n",
00068 " /Ecircumflex /Edieresis /Igrave /Iacute /Icircumflex /Idieresis /Eth /Ntilde\n",
00069 " /Ograve /Oacute /Ocircumflex /Otilde /Odieresis /multiply /Oslash /Ugrave\n",
00070 " /Uacute /Ucircumflex /Udieresis /Yacute /Thorn /germandbls /agrave /aacute\n",
00071 " /acircumflex /atilde /adieresis /aring /ae /ccedilla /egrave /eacute\n",
00072 " /ecircumflex /edieresis /igrave /iacute /icircumflex /idieresis /eth /ntilde\n",
00073 " /ograve /oacute /ocircumflex /otilde /odieresis /divide /oslash /ugrave\n",
00074 " /uacute /ucircumflex /udieresis /yacute /thorn /ydieresis\n",
00075 " /ISOLatin1Encoding where not {256 array astore def} if\n",
00076 " cleartomark\n",
00077 "\n",
00078 "/makeISOEncoded\n",
00079 "{ findfont /curfont exch def\n",
00080 " /newfont curfont maxlength dict def\n",
00081 " /ISOLatin1 (-ISOLatin1) def\n",
00082 " /curfontname curfont /FontName get dup length string cvs def\n",
00083 " /newfontname curfontname length ISOLatin1 length add string\n",
00084 " dup 0 curfontname putinterval\n",
00085 " dup curfontname length ISOLatin1 putinterval\n",
00086 " def\n",
00087 " curfont\n",
00088 " { exch dup /FID ne\n",
00089 " { dup /Encoding eq\n",
00090 " { exch pop ISOLatin1Encoding exch }\n",
00091 " if\n",
00092 " dup /FontName eq\n",
00093 " { exch pop newfontname exch }\n",
00094 " if\n",
00095 " exch newfont 3 1 roll put\n",
00096 " }\n",
00097 " { pop pop }\n",
00098 " ifelse\n",
00099 " }\n",
00100 " forall\n",
00101 " newfontname newfont definefont\n",
00102 "} def\n",
00103 "\n",
00104 "/Helvetica makeISOEncoded pop\n",
00105 "/Helvetica-Bold makeISOEncoded pop\n",
00106 "\n",
00107 "% by Dirk:\n",
00108 "% set raster frequency \n",
00109 "% Syntax: freq setfrequency \n",
00110 "/setfrequency \n",
00111 "{\n",
00112 " /setfreqoldscreen currentscreen 3 1 roll pop pop def\n",
00113 " 45 /setfreqoldscreen load setscreen\n",
00114 "} def\n\n",
00115 "\n",
00116 "%%EndSetup\n",
00117 "%ENDEMARKE"
00118 };
00119
00120
00121
00122
00123
00124
00128 EpsfTools::EpsfTools(int paper){
00129 imgdef = FALSE;
00130 font=NULL;
00131 PicNo = 0;
00132 papertyp = paper;
00133 SetAbbWidth();
00134 SetFontSize();
00135 NIcons();
00136 }
00137
00141 EpsfTools::~EpsfTools(){
00142 close();
00143 if(font) g_free(font);
00144 }
00145
00149 void EpsfTools::SetFontSize(double p){
00150 if(font) g_free(font);
00151 FontSize = p * Width/FIGNRMWIDTH;
00152 font = g_strdup_printf("/Helvetica-ISOLatin1 findfont %d scalefont setfont\n", (int)FontSize);
00153 }
00154
00167 int EpsfTools::open(char *name, int fullpage, int typ, int info){
00168 fname = name;
00169 Icf.open(fname, std::ios::out | std::ios::trunc);
00170 if(!Icf.good()){
00171 XSM_SHOW_ALERT(ERR_SORRY, ERR_FILEWRITE,fname,1);
00172 return (-1);
00173 }
00174 putheader(fullpage, typ, info);
00175 imgdef=FALSE;
00176 return 0;
00177 }
00178
00188 void EpsfTools::putheader(int fullpage, int typ, int info){
00189 int i;
00190 *EpsfBuffer=0;
00191 time_t t;
00192 time(&t);
00193 sprintf(EpsfBuffer,"%%!PS-Adobe-2.0 EPSF-2.0\n");
00194 sprintf(EpsfBuffer+strlen(EpsfBuffer),"%%%%Creator: [%s]\n", PACKAGE "-" VERSION);
00195 sprintf(EpsfBuffer+strlen(EpsfBuffer),"%%%%Title: %s\n",fname);
00196 sprintf(EpsfBuffer+strlen(EpsfBuffer),"%%%%CreationDate: %s", ctime (&t));
00197
00198 strcat(EpsfBuffer,"%%Pages: (atend)\n");
00199 strcat(EpsfBuffer,"%%Orientation: Portrait\n");
00200 if (papertyp == A4PAPER)
00201 strcat(EpsfBuffer,"%%DocumentPaperSizes: a4\n");
00202 else
00203 strcat(EpsfBuffer,"%%DocumentPaperSizes: letter\n");
00204 strcat(EpsfBuffer,"%%DocumentFonts: Helvetica-ISOLatin1\n");
00205 if((typ==ID_PRINTT_PLAIN || typ==ID_PRINTT_CIRC) && info==ID_PRINTI_NONE)
00206 sprintf(EpsfBuffer+strlen(EpsfBuffer),"%%%%BoundingBox: 100 150 500 550\n");
00207 else
00208 if(fullpage)
00209 sprintf(EpsfBuffer+strlen(EpsfBuffer),"%%%%BoundingBox: 50 0 %d %d\n",
00210 580, papertyp == A4PAPER ? 830:790);
00211 else
00212 sprintf(EpsfBuffer+strlen(EpsfBuffer),"%%%%BoundingBox: 47 47 %d %d\n", 553, 603);
00213 strcat(EpsfBuffer,"%%EndComments\n");
00214 i=0;
00215 while(strncmp(PSCode[i],"%ENDEMARKE",9))
00216 strcat(EpsfBuffer,PSCode[i++]);
00217
00218 Icf.write(EpsfBuffer, strlen(EpsfBuffer));
00219 }
00220
00229 void EpsfTools::makesize(int &Nx, int &Ny){
00230 if(Nx>Ny){
00231 Ny=Ny*400/Nx;
00232 Nx=400;
00233 if(Ny < 10) Ny=100;
00234 }else{
00235 Nx=Nx*400/Ny;
00236 Ny=400;
00237 if(Nx < 10) Nx=100;
00238 }
00239 }
00240
00248 void EpsfTools::tr2picorigin(int Nx, int Ny){
00249 strcat(EpsfBuffer,"% ->tr2picorigin\n");
00250 sprintf(EpsfBuffer+strlen(EpsfBuffer),"%d %d translate\n",50-Nx/2+200,50-Ny/2+200);
00251 strcat(EpsfBuffer,"% <-\n");
00252 }
00253
00258 void EpsfTools::putframe(){
00259 *EpsfBuffer=0;
00260 strcat(EpsfBuffer,"% ->putframe\n");
00261 strcat(EpsfBuffer,"gsave\n");
00262
00263 strcat(EpsfBuffer,"% lower left corner of picture\n");
00264 strcat(EpsfBuffer,"50 100 translate\n\n");
00265 strcat(EpsfBuffer,"0 -50 moveto\n");
00266 strcat(EpsfBuffer,"500 -50 lineto\n");
00267 strcat(EpsfBuffer,"500 500 lineto\n");
00268 strcat(EpsfBuffer,"0 500 lineto\n");
00269 strcat(EpsfBuffer,"0 -50 lineto\n closepath stroke\n");
00270
00271 strcat(EpsfBuffer,"grestore\n");
00272 Icf.write(EpsfBuffer, strlen(EpsfBuffer));
00273 }
00274
00282 void EpsfTools::putline(Scan *s, int x1, int y1, int x2, int y2){
00283
00284
00285
00286
00287 *EpsfBuffer=0;
00288 strcat(EpsfBuffer,"% ->putline\n");
00289 strcat(EpsfBuffer,"gsave\n");
00290 strcat(EpsfBuffer,"% draw a line\n");
00291 strcat(EpsfBuffer,"50 100 translate\n\n");
00292
00293 int Nx=s->mem2d->GetNx();
00294 int Ny=s->mem2d->GetNy();
00295 makesize(Nx, Ny);
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307 tr2picorigin(Nx, Ny);
00308
00309 double A,B,C;
00310
00311
00312 A=(s->data.s.x0)-(s->data.s.rx/2);
00313
00314 B=x2-A;
00315 C= B/(s->data.s.rx)*Nx;
00316 x2 = (int)C;
00317
00318 B=x1-A;
00319 C= B/(s->data.s.rx)*Nx;
00320 x1 = (int)C;
00321
00322
00323 A=(s->data.s.y0)-y2;
00324 B=A/(s->data.s.ry)*Ny;
00325 C=Ny-B;
00326 y2=(int)C - Ny/2 ;
00327
00328 A=(s->data.s.y0)-y1;
00329 B=A/(s->data.s.ry)*Ny;
00330 C=Ny-B;
00331 y1=(int)C - Ny/2;
00332
00333
00334 sprintf(EpsfBuffer+strlen(EpsfBuffer), "%d %d moveto\n", x1, y1);
00335 sprintf(EpsfBuffer+strlen(EpsfBuffer), "%d %d lineto\n stroke\n", x2, y2);
00336
00337 strcat(EpsfBuffer,"grestore\n");
00338 Icf.write(EpsfBuffer, strlen(EpsfBuffer));
00339 }
00340
00349 void EpsfTools::putcircle(Scan *s, int x1, int y1, int x2, int y2){
00350
00351
00352
00353
00354
00355 *EpsfBuffer=0;
00356 strcat(EpsfBuffer,"gsave\n");
00357 strcat(EpsfBuffer,"% draw a circle: putcircle()\n");
00358 strcat(EpsfBuffer,"50 100 translate\n\n");
00359
00360 int Nx=s->mem2d->GetNx();
00361 int Ny=s->mem2d->GetNy();
00362 makesize(Nx, Ny);
00363 tr2picorigin(Nx, Ny);
00364
00365 double A,B,C;
00366
00367
00368 A=(s->data.s.x0)-(s->data.s.rx/2);
00369
00370 B=x2-A;
00371 C= B/(s->data.s.rx)*Nx;
00372 x2 = (int)C;
00373
00374 B=x1-A;
00375 C= B/(s->data.s.rx)*Nx;
00376 x1 = (int)C;
00377
00378
00379 A=(s->data.s.y0)-y2;
00380 B=A/(s->data.s.ry)*Ny;
00381 C=Ny-B;
00382 y2=(int)C - Ny/2;
00383
00384 A=(s->data.s.y0)-y1;
00385 B=A/(s->data.s.ry)*Ny;
00386 C=Ny-B;
00387 y1=(int)C - Ny/2;
00388
00389
00390 A = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
00391
00392
00393
00394 sprintf(EpsfBuffer+strlen(EpsfBuffer), "newpath\n 0 0 moveto\n");
00395 sprintf(EpsfBuffer+strlen(EpsfBuffer), "%i 0 lineto \n %i %i lineto \n 0 %i lineto\n ", Nx, Nx, Ny, Ny);
00396 sprintf(EpsfBuffer+strlen(EpsfBuffer), "closepath \n clip\n");
00397
00398 sprintf(EpsfBuffer+strlen(EpsfBuffer), "newpath %i %i %f 0 360 arc\n stroke\n", x1, y1, A);
00399
00400 strcat(EpsfBuffer,"grestore\n");
00401 Icf.write(EpsfBuffer, strlen(EpsfBuffer));
00402 }
00403
00404
00405
00406
00407
00412 int EpsfTools::putticks(Scan *s, int OriginZero){
00413 int Nx=s->mem2d->GetNx();
00414 int Ny=s->mem2d->GetNy();
00415 int I,X,nSkX,nSkY;
00416 double l10;
00417 double Lab2X,Lab,dLab,MaxLab,LabW,Lab0;
00418 char sklprecX[10];
00419 char sklprecY[10];
00420 char strl[60];
00421
00422 makesize(Nx, Ny);
00423 if(Nx>Ny){
00424 nSkX=20; nSkY=Ny*20/Nx;
00425 if(nSkY==0) nSkY=1;
00426 }
00427 else{
00428 nSkY=20; nSkX=Nx*20/Ny;
00429 if(nSkX==0) nSkX=1;
00430 }
00431
00432 *EpsfBuffer=0;
00433 strcat(EpsfBuffer,"% ->putticks\n");
00434 strcat(EpsfBuffer,"gsave\n");
00435
00436 strcat(EpsfBuffer,"% lower left corner of picture\n");
00437 strcat(EpsfBuffer,"50 100 translate\n\n");
00438
00439 strcat(EpsfBuffer,"% size of image (on paper, in 1/72inch coords)\n");
00440
00441 tr2picorigin(Nx, Ny);
00442
00443 strcat(EpsfBuffer,font);
00444
00445 strcat(EpsfBuffer,"0 0 moveto\n");
00446 sprintf(EpsfBuffer+strlen(EpsfBuffer),"%d 0 lineto\n",Nx);
00447 sprintf(EpsfBuffer+strlen(EpsfBuffer),"%d %d lineto\n",Nx,Ny);
00448 sprintf(EpsfBuffer+strlen(EpsfBuffer),"0 %d lineto\n",Ny);
00449 strcat(EpsfBuffer,"0 0 lineto\n stroke\n");
00450
00451 if(OriginZero){
00452 Lab0=0.;
00453 MaxLab=s->data.Xunit->Base2Usr(s->data.s.rx);
00454 }else{
00455 Lab0=s->data.Xunit->Base2Usr(s->data.s.x0);
00456 MaxLab=s->data.Xunit->Base2Usr(s->data.s.rx+Lab0);
00457 }
00458
00459 std::ifstream labf;
00460 labf.open("/tmp/skloverride",std::ios::in);
00461 struct {
00462 int valid; int validSkl;
00463 double xmin,xmax,ymin,ymax;
00464 int xn,yn;
00465 char labx[40], laby[40], tit[40];
00466 } sklinfo;
00467 sklinfo.valid=0;
00468 sklinfo.validSkl=0;
00469 if(labf.good()){
00470 labf >> sklinfo.labx >> sklinfo.xmin >> sklinfo.xmax >> sklinfo.xn;
00471 labf >> sklinfo.laby >> sklinfo.ymin >> sklinfo.ymax >> sklinfo.yn;
00472 labf >> sklinfo.tit;
00473 labf.close();
00474
00475 XSM_DEBUG(DBG_L2, "Using Labinfo !" );
00476 XSM_DEBUG(DBG_L2, sklinfo.labx << " " << sklinfo.xmin << " " << sklinfo.xmax << " " << sklinfo.xn );
00477 XSM_DEBUG(DBG_L2, sklinfo.laby << " " << sklinfo.ymin << " " << sklinfo.ymax << " " << sklinfo.yn );
00478 nSkX = sklinfo.xn;
00479 nSkY = sklinfo.yn;
00480 Lab0 = sklinfo.xmin;
00481 MaxLab = sklinfo.xmax;
00482 sklinfo.valid=1;
00483 sklinfo.validSkl=1;
00484 }
00485
00486 labf.open("/tmp/TXYlabels",std::ios::in);
00487 if(labf.good()){
00488 labf >> sklinfo.tit;
00489 labf >> sklinfo.labx >> sklinfo.laby;
00490 sklinfo.valid=1;
00491 labf.close();
00492 }
00493
00494
00495
00496 strcpy(sklprecX,"6.2");
00497 strcpy(sklprecY,"6.2" );
00498
00499
00500 labf.open("/tmp/labprec");
00501 if(labf.good()){
00502 labf >> sklprecX;
00503 labf.close();
00504 strcpy(sklprecY,sklprecX);
00505 }
00506
00507 labf.open("/tmp/labprecX");
00508 if(labf.good()){
00509 labf >> sklprecX;
00510 labf.close();
00511 }
00512
00513 labf.open("/tmp/labprecY");
00514 if(labf.good()){
00515 labf >> sklprecY;
00516 labf.close();
00517 }
00518
00519 if(Lab0 < MaxLab){
00520 LabW = MaxLab-Lab0;
00521 dLab = AutoSkl(LabW/(double)nSkX);
00522 l10 = pow(10.,floor(log10(MaxLab)));
00523 if(l10 < 1000. && l10 > 0.01) l10=1.;
00524 if(dLab <= 0.) return(-1);
00525 Lab2X=(double)Nx/LabW;
00526 for(I=0, Lab=AutoNext(Lab0,dLab); Lab<MaxLab; Lab+=dLab, ++I){
00527 X=R2INT((Lab-Lab0)*Lab2X);
00528 if(I%5)
00529 sprintf(EpsfBuffer+strlen(EpsfBuffer),
00530 "%d 0 moveto %d -5 lineto %d %d moveto %d %d lineto stroke\n",
00531 X,X,X,Ny,X,Ny+5);
00532 else{
00533 sprintf(EpsfBuffer+strlen(EpsfBuffer),
00534 "%d 0 moveto %d -10 lineto %d %d moveto %d %d lineto stroke\n",
00535 X,X,X,Ny,X,Ny+10);
00536 sprintf(strl,"%cd -25 moveto (%c%sf) show\n",'%','%',sklprecX);
00537 sprintf(EpsfBuffer+strlen(EpsfBuffer),strl,X-3,Lab/l10);
00538 }
00539 }
00540 }
00541 else{
00542 LabW = Lab0-MaxLab;
00543 dLab = AutoSkl(LabW/(double)nSkX);
00544 l10 = pow(10.,floor(log10(MaxLab)));
00545 if(l10 < 1000. && l10 > 0.01) l10=1.;
00546 if(dLab <= 0.) return(-1);
00547 Lab2X=(double)Nx/LabW;
00548 for(I=0, Lab=AutoNext(MaxLab,dLab); Lab<Lab0; Lab+=dLab, ++I){
00549 X=Nx-R2INT((Lab-MaxLab)*Lab2X);
00550 if(I%5)
00551 sprintf(EpsfBuffer+strlen(EpsfBuffer),
00552 "%d 0 moveto %d -5 lineto %d %d moveto %d %d lineto stroke\n",
00553 X,X,X,Ny,X,Ny+5);
00554 else{
00555 sprintf(EpsfBuffer+strlen(EpsfBuffer),
00556 "%d 0 moveto %d -10 lineto %d %d moveto %d %d lineto stroke\n",
00557 X,X,X,Ny,X,Ny+10);
00558 sprintf(strl,"%cd -25 moveto (%c%sf) show\n",'%','%',sklprecX);
00559 sprintf(EpsfBuffer+strlen(EpsfBuffer),strl,X-3,Lab/l10);
00560 }
00561 }
00562 }
00563
00564 if(sklinfo.valid)
00565 sprintf(EpsfBuffer+strlen(EpsfBuffer),
00566 "150 -40 moveto (%s (*%g)) show\n",
00567 sklinfo.labx,l10);
00568 else
00569 sprintf(EpsfBuffer+strlen(EpsfBuffer),
00570 "150 -40 moveto (x %.0f %s) show\n",
00571 l10,s->data.Xunit->psSymbol());
00572
00573 if(OriginZero){
00574 Lab0=0.;
00575 MaxLab=s->data.Yunit->Base2Usr(s->data.s.ry);
00576 }else{
00577 Lab0=s->data.Yunit->Base2Usr(s->data.s.y0-s->data.s.ry);
00578 MaxLab=s->data.Yunit->Base2Usr(s->data.s.ry+Lab0);
00579 }
00580
00581 if(sklinfo.validSkl){
00582 Lab0 = sklinfo.ymin;
00583 MaxLab = sklinfo.ymax;
00584 }
00585
00586 if(Lab0 < MaxLab){
00587 LabW = MaxLab-Lab0;
00588 dLab = AutoSkl(LabW/(double)nSkY);
00589 l10 = pow(10.,floor(log10(MaxLab)));
00590 if(l10 < 1000. && l10 > 0.01) l10=1.;
00591 if(dLab <= 0.) return(-1);
00592 Lab2X=(double)Ny/LabW;
00593
00594 for(I=0, Lab=AutoNext(Lab0,dLab); Lab<MaxLab; Lab+=dLab, ++I){
00595 X=R2INT((Lab-Lab0)*Lab2X);
00596 if(I%5)
00597 sprintf(EpsfBuffer+strlen(EpsfBuffer),
00598 "0 %d moveto -5 %d lineto %d %d moveto %d %d lineto stroke\n",
00599 X,X,Nx,X,Nx+5,X);
00600 else{
00601 sprintf(EpsfBuffer+strlen(EpsfBuffer),
00602 "0 %d moveto -10 %d lineto %d %d moveto %d %d lineto stroke\n",
00603 X,X,Nx,X,Nx+10,X);
00604 sprintf(strl,"-40 %cd moveto (%c%sf) show\n",'%','%',sklprecY);
00605 sprintf(EpsfBuffer+strlen(EpsfBuffer),strl,X-4,Lab/l10);
00606 }
00607 }
00608 }
00609 else{
00610 LabW = Lab0-MaxLab;
00611 dLab = AutoSkl(LabW/(double)nSkY);
00612 l10 = pow(10.,floor(log10(MaxLab)));
00613 if(l10 < 1000. && l10 > 0.01) l10=1.;
00614 if(dLab <= 0.) return(-1);
00615 Lab2X=(double)Ny/LabW;
00616 for(I=0, Lab=AutoNext(MaxLab,dLab); Lab<Lab0; Lab+=dLab, ++I){
00617 X=Ny-R2INT((Lab-MaxLab)*Lab2X);
00618 if(I%5)
00619 sprintf(EpsfBuffer+strlen(EpsfBuffer),
00620 "0 %d moveto -5 %d lineto %d %d moveto %d %d lineto stroke\n",
00621 X,X,Nx,X,Nx+5,X);
00622 else{
00623 sprintf(EpsfBuffer+strlen(EpsfBuffer),
00624 "0 %d moveto -10 %d lineto %d %d moveto %d %d lineto stroke\n",
00625 X,X,Nx,X,Nx+10,X);
00626 sprintf(strl,"-40 %cd moveto (%c%sf) show\n",'%','%',sklprecY);
00627 sprintf(EpsfBuffer+strlen(EpsfBuffer),strl,X-4,Lab/l10);
00628 }
00629 }
00630 }
00631
00632 if(sklinfo.valid)
00633 sprintf(EpsfBuffer+strlen(EpsfBuffer),
00634 "-40 %d moveto (%s (*%g)) show\n",
00635 Ny+20,sklinfo.laby,l10);
00636 else
00637 sprintf(EpsfBuffer+strlen(EpsfBuffer),
00638 "-40 %d moveto (x %.0f %s) show\n",
00639 Ny+20,l10,s->data.Yunit->psSymbol());
00640 strcat(EpsfBuffer,"grestore\n");
00641 Icf.write(EpsfBuffer, strlen(EpsfBuffer));
00642
00643 return 0;
00644 }
00645
00646
00647 void EpsfTools::putbar(Scan *s){
00648 int Nx=s->mem2d->GetNx();
00649 int Ny=s->mem2d->GetNy();
00650 int I=0,X=0,nSkX=10;
00651 double l10, BarLen;
00652 double Lab2X,Lab,dLab,MaxLab;
00653 makesize(Nx, Ny);
00654
00655 *EpsfBuffer=0;
00656 strcat(EpsfBuffer,"% ->putbar\n");
00657 strcat(EpsfBuffer,"gsave\n");
00658 strcat(EpsfBuffer,"50 100 translate\n\n");
00659 tr2picorigin(Nx, Ny);
00660
00661 strcat(EpsfBuffer,"50 -30 translate\n\n");
00662
00663 strcat(EpsfBuffer,font);
00664
00665 BarLen = 1./3.;
00666 nSkX = 6;
00667 MaxLab=s->data.Xunit->Base2Usr(s->data.s.rx*BarLen);
00668 dLab = AutoSkl(MaxLab/(double)nSkX);
00669 l10 = pow(10.,floor(log10(MaxLab)));
00670 if(dLab > 0.){
00671 Lab2X=(double)Nx/MaxLab*BarLen;
00672
00673 strcat(EpsfBuffer,"3 setlinewidth\n");
00674 sprintf(EpsfBuffer+strlen(EpsfBuffer),
00675 "0 0 moveto %d 0 lineto closepath stroke\n",
00676 R2INT(MaxLab*Lab2X));
00677
00678 strcat(EpsfBuffer,"1 setlinewidth\n");
00679
00680 for(I=0, Lab=0.; Lab<MaxLab; Lab+=dLab, ++I){
00681 X=R2INT(Lab*Lab2X);
00682 if(I%2)
00683 sprintf(EpsfBuffer+strlen(EpsfBuffer),
00684 "%d 3 moveto %d -3 lineto closepath stroke\n", X, X);
00685 else{
00686 sprintf(EpsfBuffer+strlen(EpsfBuffer),
00687 "%d 5 moveto %d -5 lineto closepath stroke\n", X, X);
00688 sprintf(EpsfBuffer+strlen(EpsfBuffer),
00689 "%d -20 moveto (%4.2f) show\n",X-3,Lab/l10);
00690 }
00691 }
00692 sprintf(EpsfBuffer+strlen(EpsfBuffer),"%d -20 moveto (x %.0f %s) show\n",
00693 X+50, l10,s->data.Xunit->psSymbol());
00694 }
00695 strcat(EpsfBuffer,"grestore\n");
00696 Icf.write(EpsfBuffer, strlen(EpsfBuffer));
00697 }
00698
00699
00700 void EpsfTools::init(){
00701 *EpsfBuffer=0;
00702 strcat(EpsfBuffer,"% ->init\n");
00703 if (nPicPage > 0)
00704 if (!((PicNo)%nPicPage))
00705 sprintf(EpsfBuffer+strlen(EpsfBuffer),"%%%%Page: %d %d\n",
00706 1+PicNo/nPicPage, 1+PicNo/nPicPage);
00707
00708 Icf.write(EpsfBuffer, strlen(EpsfBuffer));
00709 }
00710
00711
00712 void EpsfTools::placeimage(){
00713 *EpsfBuffer=0;
00714 strcat(EpsfBuffer,"% ->placeimage\n");
00715
00716 if(nPicPage > 0 && MkTyp > 0){
00717 ++PicNo;
00718 double sfac = papertyp == A4PAPER? 0.46 : 0.44;
00719 strcat(EpsfBuffer,"gsave\n");
00720 sprintf(EpsfBuffer+strlen(EpsfBuffer),"%d %d translate\n",
00721 60+EPSF_XM*(((PicNo-1)%nPicPage)%(MkTyp*2))/(MkTyp*2),
00722 20+(papertyp == A4PAPER? EPSF_YM_A4:EPSF_YM_LETTER)*((MkTyp*3-1)-
00723 ((((PicNo-1)%nPicPage)
00724 /(MkTyp*2))%(MkTyp*3)))/(MkTyp*3));
00725 sprintf(EpsfBuffer+strlen(EpsfBuffer),"%d 100 div %d 100 div scale\n",
00726 (int)(100*sfac/(double)MkTyp),(int)(100*sfac/(double)MkTyp));
00727 }
00728 else{
00729 ++PicNo;
00730 strcat(EpsfBuffer,"gsave\n");
00731 if(Width != FIGNRMWIDTH){
00732 strcat(EpsfBuffer,"60 20 translate\n");
00733 sprintf(EpsfBuffer+strlen(EpsfBuffer),"%d 100 div %d 100 div scale\n",
00734 (int)(100*Width/FIGNRMWIDTH), (int)(100*Width/FIGNRMWIDTH));
00735 }
00736 }
00737
00738 strcat(EpsfBuffer,"%70 setfrequency\n\n");
00739
00740 Icf.write(EpsfBuffer, strlen(EpsfBuffer));
00741
00742 imgdef=TRUE;
00743 }
00744
00745
00746 void EpsfTools::endimage(){
00747 *EpsfBuffer=0;
00748 strcat(EpsfBuffer,"% ->endimage\n");
00749 strcat(EpsfBuffer,"grestore\n");
00750
00751 Icf.write(EpsfBuffer, strlen(EpsfBuffer));
00752 }
00753
00754
00755
00756 void EpsfTools::FootLine(Scan *s, int force){
00757 *EpsfBuffer=0;
00758 sprintf(EpsfBuffer,"%% ->FootLine, Pic %d/%d\n", PicNo, nPicPage);
00759 if(nPicPage > 0){
00760 if((!(PicNo%nPicPage)) || force){
00761 strcat(EpsfBuffer,"gsave\n");
00762 strcat(EpsfBuffer,"/Helvetica-ISOLatin1 findfont 10 scalefont setfont\n");
00763 strcat(EpsfBuffer,"150 23 moveto\n");
00764 sprintf(EpsfBuffer+strlen(EpsfBuffer),"(STM-Icons Page:%d Print-Date:",
00765 PicNo/nPicPage + (force ? 1:0));
00766
00767 strcat(EpsfBuffer," Data-Date:");
00768 sprintf(EpsfBuffer+strlen(EpsfBuffer),"%s",s->data.ui.dateofscan);
00769 strcat(EpsfBuffer,") show\n");
00770 strcat(EpsfBuffer,"grestore\n");
00771 strcat(EpsfBuffer,"showpage\n\n");
00772 }
00773 }
00774 Icf.write(EpsfBuffer, strlen(EpsfBuffer));
00775 }
00776
00777
00778
00779
00780 void EpsfTools::putimgdef(Mem2d *m, int y){
00781 int Nx=m->GetNx();
00782 int Ny=m->GetNy();
00783 static int yy;
00784 makesize(Nx, Ny);
00785
00786 *EpsfBuffer=0;
00787 if(y == -1){
00788 strcat(EpsfBuffer,"% ->putimagedef\n");
00789 strcat(EpsfBuffer,"50 100 translate\n\n");
00790 tr2picorigin(Nx, Ny);
00791
00792 strcat(EpsfBuffer,"% dimensions\n");
00793 sprintf(EpsfBuffer+strlen(EpsfBuffer),"/Breite %d def\n/Hoehe %d def\n\n",
00794 m->GetNx(), m->GetNy());
00795 strcat(EpsfBuffer,"% define string to hold a scanline's worth of data\n");
00796 strcat(EpsfBuffer,"/pix Breite string def\n\n");
00797 sprintf(EpsfBuffer+strlen(EpsfBuffer),"%d %d scale\n\n",Nx, Ny);
00798 strcat(EpsfBuffer,"Breite Hoehe 8\t\t% dimensions of data\n");
00799 strcat(EpsfBuffer,"[Breite 0 0 Hoehe neg 0 Hoehe]\t\t% mapping matrix\n");
00800 strcat(EpsfBuffer,"{currentfile pix readhexstring pop}\n");
00801 strcat(EpsfBuffer,"image\n\n\0\0");
00802 }else{
00803 if(y==0){
00804 strcat(EpsfBuffer,"% ->putimagedef, Start circ\n");
00805 strcat(EpsfBuffer,"50 100 translate\n\n");
00806 tr2picorigin(Nx, Ny);
00807 yy=0;
00808 }else{
00809 sprintf(EpsfBuffer+strlen(EpsfBuffer),"%d 100 div %d 100 div translate\n",
00810 (int)((double)Nx*100.*(.5-(double)y/2./m->GetNx())),
00811 (int)((double)Ny*100.*(yy++)/m->GetNy()));
00812 sprintf(EpsfBuffer+strlen(EpsfBuffer),"/Breite %d def\n/Hoehe 1 def\n", y);
00813 strcat(EpsfBuffer,"/pix Breite string def\n");
00814 sprintf(EpsfBuffer+strlen(EpsfBuffer),"%d 100 div %d 100 div scale\n\n",
00815 (int)(Nx*100.*y/m->GetNx()),
00816 (int)(Ny*100./m->GetNy()*1.01));
00817 strcat(EpsfBuffer,"Breite Hoehe 8\t\t% dimensions of data\n");
00818 strcat(EpsfBuffer,"[Breite 0 0 Hoehe neg 0 Hoehe]\t\t% mapping matrix\n");
00819 strcat(EpsfBuffer,"{currentfile pix readhexstring pop}\n");
00820 strcat(EpsfBuffer,"image\n\n\0\0");
00821 }
00822 }
00823
00824 Icf.write(EpsfBuffer, strlen(EpsfBuffer));
00825 }
00826
00827
00828 void EpsfTools::putgrey(Scan *s, Mem2d *m, int autoskl, int quick, int option){
00829 static char *HexTab = "0123456789ABCDEF";
00830 int PelWert;
00831 long i, j, k;
00832
00833
00834
00835
00836 m->SetDataRange(0, 0xff);
00837
00838 m->AutoDataSkl(NULL, NULL);
00839
00840 *EpsfBuffer=0;
00841 strcat(EpsfBuffer,"% ->putgrey\n");
00842
00843 if(option){
00844 double a2,b2,y;
00845 int nn;
00846 a2=m->GetNx()/2; a2*=a2;
00847 b2=m->GetNy()/2; b2*=b2;
00848 putimgdef(m, 0);
00849 for(i=0; i<m->GetNy(); i++){
00850 y = m->GetNy()/2.-i;
00851 nn=2*(int)rint(sqrt(a2*(1.-y*y/b2)));
00852
00853 if(nn>0){
00854 Icf << "gsave\n";
00855 putimgdef(m, nn);
00856 for(k=0, j=m->GetNx()/2-nn/2; nn--; j++){
00857 PelWert = m->GetDataVMode(j,i);
00858 EpsfBuffer[k++] = HexTab[(PelWert & 0xf0) >> 4];
00859 EpsfBuffer[k++] = HexTab[PelWert & 0x0f];
00860 if(k>72){
00861 EpsfBuffer[k++] = 0; strcat(EpsfBuffer,"\n\0");
00862 Icf.write(EpsfBuffer,k);
00863 k=0;
00864 }
00865 }
00866 EpsfBuffer[k++] = 0; strcat(EpsfBuffer,"\n\0");
00867 Icf.write(EpsfBuffer,k);
00868 Icf << "grestore\n";
00869 }
00870 }
00871 }else{
00872 putimgdef(m);
00873 for(i=0; i<m->GetNy(); i++){
00874 for(k=j=0; j<m->GetNx(); j++){
00875 PelWert = m->GetDataVMode(j,i);
00876 EpsfBuffer[k++] = HexTab[(PelWert & 0xf0) >> 4];
00877 EpsfBuffer[k++] = HexTab[PelWert & 0x0f];
00878 if(k>72){
00879 EpsfBuffer[k++] = 0; strcat(EpsfBuffer,"\n\0");
00880 Icf.write(EpsfBuffer,k);
00881 k=0;
00882 }
00883 }
00884 EpsfBuffer[k++] = 0; strcat(EpsfBuffer,"\n\0");
00885 Icf.write(EpsfBuffer,k);
00886 }
00887 }
00888 imgdef=FALSE;
00889 }
00890
00891
00892
00893
00894 void EpsfTools::putsize(Scan *s){
00895 XSM_DEBUG (DBG_L3, "PutSize");
00896 int i=0;
00897 gchar *su[20];
00898 gchar *comm = g_new(gchar, 82);
00899 strncpy(comm, s->data.ui.comment, 80); comm[81]=0;
00900 gchar *npix = g_strdup_printf (" [%d x %d]", s->data.s.nx, s->data.s.ny);
00901 gchar *gstr;
00902 gstr = g_strconcat("% ->putsize\n",
00903 "gsave\n",
00904 "% lower left corner\n",
00905 font,
00906 "150 585 moveto\n",
00907 "(Name: ", s->data.ui.name, " ) show\n",
00908 "60 85 moveto\n",
00909 "(", su[i++]=s->data.Xunit->UsrString(s->data.s.rx, UNIT_SM_PS),
00910 " x ", su[i++]=s->data.Yunit->UsrString(s->data.s.ry, UNIT_SM_PS),
00911 npix,
00912 " VRZ: ", su[i++]=s->data.Zunit->UsrString(s->data.display.vrange_z, UNIT_SM_PS),
00913 ") show\n",
00914 "60 70 moveto\n",
00915 "(dxy: ", su[i++]=s->data.Xunit->UsrString(s->data.s.dx, UNIT_SM_PS),
00916 " x ", su[i++]=s->data.Yunit->UsrString(s->data.s.dy, UNIT_SM_PS),
00917 ") show\n",
00918 "( ",
00919 " *** ",
00920
00921
00922
00923 ") show\n",
00924 "60 55 moveto\n",
00925 "(", comm, ") show\n",
00926 "grestore\n",
00927 NULL);
00928
00929 Icf.write (gstr, strlen (gstr));
00930 g_free (npix);
00931 g_free (gstr); while (i) g_free (su[--i]);
00932 g_free (comm);
00933 }
00934
00935
00936 void EpsfTools::putmore(Scan *s, char *Title){
00937 int psy=740;
00938 const int dpsy=15;
00939 const int pstx1=60;
00940 const int pstx2=pstx1+100;
00941
00942
00943
00944 int i=0;
00945 gchar *su[10];
00946 gchar *mv1, *mv2;
00947 gchar *gstr;
00948 XSM_DEBUG (DBG_L3, "PutMore");
00949 gstr = g_strconcat("% ->putmore\n",
00950 "gsave\n",
00951 font,
00952 "60 760 moveto\n (", Title ? Title : " ", ") show\n",
00953
00954 mv1=g_strdup_printf("%d %d moveto\n",pstx1,psy),
00955 "(Scan Name:) show ",
00956 mv2=g_strdup_printf("%d %d moveto\n",pstx2,psy),
00957 "(", s->data.ui.name, ", ", s->data.ui.originalname, ") show\n",
00958 NULL);
00959 XSM_DEBUG(DBG_L2, gstr );
00960 Icf.write(gstr, strlen(gstr)); g_free(gstr); g_free(mv1); g_free(mv2); psy-=dpsy;
00961
00962 gstr = g_strconcat(
00963 mv1=g_strdup_printf("%d %d moveto\n",pstx1,psy),
00964 "(Scan Type:) show ",
00965 mv2=g_strdup_printf("%d %d moveto\n",pstx2,psy),
00966 "(", s->data.ui.type, ") show\n",
00967 NULL);
00968 Icf.write(gstr, strlen(gstr)); g_free(gstr); g_free(mv1); g_free(mv2); psy-=dpsy;
00969
00970 gstr = g_strconcat(
00971 mv1=g_strdup_printf("%d %d moveto\n",pstx1,psy),
00972 "(Date of Scan:) show ",
00973 mv2=g_strdup_printf("%d %d moveto\n",pstx2,psy),
00974 "(", s->data.ui.dateofscan, ") show\n",
00975 NULL);
00976 Icf.write(gstr, strlen(gstr)); g_free(gstr); g_free(mv1); g_free(mv2); psy-=dpsy;
00977
00978 gstr = g_strconcat(
00979 mv1=g_strdup_printf("%d %d moveto\n",pstx1,psy),
00980 "(User:) show ",
00981 mv2=g_strdup_printf("%d %d moveto\n",pstx2,psy),
00982 "(", s->data.ui.user, "@", s->data.ui.host, ") show\n",
00983 NULL);
00984 Icf.write(gstr, strlen(gstr)); g_free(gstr); g_free(mv1); g_free(mv2); psy-=dpsy;
00985
00986 char hostname[256];
00987 gethostname(hostname, 256);
00988 time_t t;
00989 time(&t);
00990 gstr = g_strconcat(
00991 mv1=g_strdup_printf("%d %d moveto\n",pstx1,psy),
00992 "(Printed by:) show ",
00993 mv2=g_strdup_printf("%d %d moveto\n",pstx2,psy),
00994 "(", getlogin() ? getlogin():"???", "@", hostname, ", ", ctime(&t), ") show\n",
00995 NULL);
00996 Icf.write(gstr, strlen(gstr)); g_free(gstr); g_free(mv1); g_free(mv2); psy-=dpsy;
00997
00998 gstr = g_strconcat(
00999 mv1=g_strdup_printf("%d %d moveto\n",pstx1,psy),
01000 "(DSP Settings:) show ",
01001 mv2=g_strdup_printf("%d %d moveto\n",pstx2,psy),
01002 "(",
01003 " *** ",
01004
01005
01006
01007 ") show\n",
01008 NULL);
01009 Icf.write(gstr, strlen(gstr)); g_free(gstr); g_free(mv1); g_free(mv2); psy-=dpsy;
01010
01011
01012
01013
01014 while(i) g_free(su[--i]);
01015
01016 gstr = g_strconcat("% ->putmore\n",
01017 "grestore\n",
01018 NULL);
01019 Icf.write(gstr, strlen(gstr)); g_free(gstr);
01020 }
01021
01022 void EpsfTools::close(){
01023 gchar *pages;
01024 if(nPicPage > 0)
01025 pages = g_strdup_printf("%d",1+PicNo/nPicPage);
01026 else
01027 pages = g_strdup("1");
01028
01029 gchar *gstr
01030 = g_strconcat("% ->close\n",
01031 "showpage\n\n",
01032 "%%Trailer\n",
01033 "%%Pages: ", pages, "\n",
01034 "%%EOF\n",
01035 NULL);
01036
01037 Icf.write(gstr, strlen(gstr));
01038 Icf.close();
01039
01040 g_free(gstr);
01041 g_free(pages);
01042 }
01043
01044
01045
01046 void SPA_epsftools::putsize(Scan *s){
01047 XSM_DEBUG (DBG_L4, "PutSize");
01048 int i=0;
01049 gchar *su[10];
01050 gchar *comm = g_strdup_printf("%40s", s->data.ui.comment);
01051 gchar *gstr;
01052 gstr = g_strconcat("% ->putsize\n",
01053 "gsave\n",
01054 "% lower left corner\n",
01055 font,
01056 "60 85 moveto\n",
01057 "(", s->data.ui.name, " ) show\n",
01058 "(", su[i++]=s->data.Xunit->UsrString(s->data.s.rx, UNIT_SM_PS),
01059 " x ", su[i++]=s->data.Yunit->UsrString(s->data.s.ry, UNIT_SM_PS),
01060 ") show\n",
01061 "60 70 moveto\n",
01062
01063
01064
01065 "(",
01066 " *** ",
01067
01068
01069
01070
01071 ") show\n",
01072 "60 55 moveto\n",
01073 "(", comm, ") show\n",
01074 "grestore\n",
01075 NULL);
01076
01077 Icf.write(gstr, strlen(gstr));
01078 g_free(gstr); while(i) g_free(su[--i]);
01079 g_free(comm);
01080 }
01081
01082
01083 void SPA_epsftools::putmore(Scan *s, char *Title){
01084 int psy=740;
01085 const int dpsy=15;
01086 const int pstx1=60;
01087 const int pstx2=pstx1+100;
01088
01089
01090 gchar *comm = g_strdup_printf("%40s", s->data.ui.comment);
01091
01092 int i=0;
01093 gchar *su[10];
01094 gchar *mv1, *mv2;
01095 gchar *gstr;
01096 XSM_DEBUG (DBG_L4, "PutMore");
01097 gstr = g_strconcat("% ->putmore\n",
01098 "gsave\n",
01099 font,
01100 "60 760 moveto\n (", Title ? Title : " ", ") show\n",
01101
01102 mv1=g_strdup_printf("%d %d moveto\n",pstx1,psy),
01103 "(Scan Name:) show ",
01104 mv2=g_strdup_printf("%d %d moveto\n",pstx2,psy),
01105 "(", s->data.ui.name, ", ", s->data.ui.originalname, ") show\n",
01106 NULL);
01107 XSM_DEBUG(DBG_L2, gstr );
01108 Icf.write(gstr, strlen(gstr)); g_free(gstr); g_free(mv1); g_free(mv2); psy-=dpsy;
01109
01110 gstr = g_strconcat(
01111 mv1=g_strdup_printf("%d %d moveto\n",pstx1,psy),
01112 "(Scan Type:) show ",
01113 mv2=g_strdup_printf("%d %d moveto\n",pstx2,psy),
01114 "(", s->data.ui.type, ") show\n",
01115 NULL);
01116 Icf.write(gstr, strlen(gstr)); g_free(gstr); g_free(mv1); g_free(mv2); psy-=dpsy;
01117
01118 gstr = g_strconcat(
01119 mv1=g_strdup_printf("%d %d moveto\n",pstx1,psy),
01120 "(Date of Scan:) show ",
01121 mv2=g_strdup_printf("%d %d moveto\n",pstx2,psy),
01122 "(", s->data.ui.dateofscan, ") show\n",
01123 NULL);
01124 Icf.write(gstr, strlen(gstr)); g_free(gstr); g_free(mv1); g_free(mv2); psy-=dpsy;
01125
01126 gstr = g_strconcat(
01127 mv1=g_strdup_printf("%d %d moveto\n",pstx1,psy),
01128 "(User:) show ",
01129 mv2=g_strdup_printf("%d %d moveto\n",pstx2,psy),
01130 "(", s->data.ui.user, "@", s->data.ui.host, ") show\n",
01131 NULL);
01132 Icf.write(gstr, strlen(gstr)); g_free(gstr); g_free(mv1); g_free(mv2); psy-=dpsy;
01133
01134 char hostname[256];
01135 gethostname(hostname, 256);
01136 time_t t;
01137 time(&t);
01138 gstr = g_strconcat(
01139 mv1=g_strdup_printf("%d %d moveto\n",pstx1,psy),
01140 "(Printed by:) show ",
01141 mv2=g_strdup_printf("%d %d moveto\n",pstx2,psy),
01142 "(", getlogin() ? getlogin():"???", "@", hostname, ", ", ctime(&t), ") show\n",
01143 NULL);
01144 Icf.write(gstr, strlen(gstr)); g_free(gstr); g_free(mv1); g_free(mv2); psy-=dpsy;
01145
01146 gstr = g_strconcat(
01147 mv1=g_strdup_printf("%d %d moveto\n",pstx1,psy),
01148 "(DSP Settings:) show ",
01149 mv2=g_strdup_printf("%d %d moveto\n",pstx2,psy),
01150 "(",
01151 " *** ",
01152
01153
01154
01155 ") show\n",
01156 NULL);
01157 Icf.write(gstr, strlen(gstr)); g_free(gstr); g_free(mv1); g_free(mv2); psy-=dpsy;
01158
01159
01160
01161
01162 while(i) g_free(su[--i]);
01163
01164 gstr = g_strconcat("% ->putmore\n",
01165 "grestore\n",
01166 NULL);
01167 Icf.write(gstr, strlen(gstr)); g_free(gstr);
01168 g_free(comm);
01169 }
01170
01171