-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathTPostScript.cxx
More file actions
3127 lines (2818 loc) · 104 KB
/
TPostScript.cxx
File metadata and controls
3127 lines (2818 loc) · 104 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// @(#)root/postscript:$Id$
// Author: Rene Brun, Olivier Couet, Pierre Juillot, Oleksandr Grebenyuk, Yue Shi Lai
/*************************************************************************
* Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
/** \class TPostScript
\ingroup PS
\brief Interface to PostScript.
To generate a Postscript (or encapsulated ps) file corresponding to
a single image in a canvas, you can:
- Select the <B>Print PostScript</B> item in the canvas <B>File</B> menu.
By default, a Postscript file with the name of the canvas.ps is generated.
- Click in the canvas area, near the edges, with the right mouse button
and select the <B>Print</B> item. You can select the name of the Postscript
file. If the file name is xxx.ps, you will generate a Postscript file named
xxx.ps. If the file name is xxx.eps, you generate an encapsulated Postscript
file instead.
- In your program (or macro), you can type:
~~~ {.cpp}
c1->Print("xxx.ps");
~~~
or:
~~~ {.cpp}
c1->Print("xxx.eps");
~~~
This will generate a file corresponding to the picture in the canvas
pointed by `c1`.
~~~ {.cpp}
pad1->Print("xxx.ps");
~~~
prints only the picture in the pad pointed by `pad1`.
The size of the Postscript picture, by default, is computed to keep the aspect
ratio of the picture on the screen, where the size along x is always 20cm. You
can set the size of the PostScript picture before generating the picture
with a command such as:
~~~ {.cpp}
TPostScript myps("myfile.ps",111)
myps.Range(xsize,ysize);
object->Draw();
myps.Close();
~~~
You can set the default paper size with:
~~~ {.cpp}
gStyle->SetPaperSize(xsize,ysize);
~~~
You can resume writing again in this file with `myps.Open();`.
Note that you may have several Postscript files opened simultaneously.
## Output type
The output type allows to define how the PostScript output will looks like.
It allows to define the page format (A4, Legal etc..), the orientation
(Portrait, Landscape) and the number of images (zones) per page.
The output type has the following form:
~~~ {.cpp}
[Format][Nx][Ny][Type]
~~~
Where:
- Format : Is an integer between 0 and 99 defining the page format:
~~~ {.cpp}
Format = 3 the paper is in the standard A3 format.
Format = n (1<n<98) is an An format.
Format = 4 and Format=0 are the same and define an A4 page.
The A0 format is selected by Format=99.
The US format Letter is selected by Format = 100.
The US format Legal is selected by Format = 200.
The US format Ledger is selected by Format = 300.
~~~
- Nx, Ny : Specify respectively the number of zones on the x and y axis.
Nx and Ny are integers between 1 and 9.
- Type : Can be equal to:
- 1 : Portrait mode with a small margin at the bottom of the page.
- 2 : Landscape mode with a small margin at the bottom of the page.
- 4 : Portrait mode with a large margin at the bottom of the page.
- 5 : Landscape mode with a large margin at the bottom of the page.
The large margin is useful for some PostScript printers (very often
for the colour printers) as they need more space to grip the paper
for mechanical reasons. Note that some PostScript colour printers
can also use the so called special A4 format permitting the full
usage of the A4 area; in this case larger margins are not necessary
and Type=1 or 2 can be used.
- 3 : Encapsulated PostScript. This Type permits the generation of files
which can be included in other documents, for example in LaTeX files.
## Making several pictures in the same Postscript file: case 1
The following macro is an example illustrating how to open a Postscript
file and draw several pictures. The generation of a new Postscript page
is automatic when `TCanvas::Clear` is called by `object->Draw()`.
~~~ {.cpp}
{
TFile f("hsimple.root");
TCanvas c1("c1","canvas",800,600);
// select postscript output type
// type = 111 portrait ps
// type = 112 landscape ps
// type = 113 eps
Int_t type = 111;
// create a postscript file and set the paper size
TPostScript ps("test.ps",type);
ps.Range(16,24); //set x,y of printed page
// draw 3 histograms from file hsimple.root on separate pages
hpx->Draw();
c1.Update(); //force drawing in a macro
hprof->Draw();
c1.Update();
hpx->Draw("lego1");
c1.Update();
ps.Close();
}
~~~
## Making several pictures in the same Postscript file: case 2
This example shows 2 pages. The canvas is divided.
`TPostScript::NewPage` must be called before starting a new
picture.`object->Draw` does not clear the canvas in this case
because we clear only the pads and not the main canvas.
Note that `c1->Update` must be called at the end of the first picture.
~~~ {.cpp}
{
TFile *f1 = new TFile("hsimple.root");
TCanvas *c1 = new TCanvas("c1");
TPostScript *ps = new TPostScript("file.ps",112);
c1->Divide(2,1);
// picture 1
ps->NewPage();
c1->cd(1);
hpx->Draw();
c1->cd(2);
hprof->Draw();
c1->Update();
// picture 2
ps->NewPage();
c1->cd(1);
hpxpy->Draw();
c1->cd(2);
ntuple->Draw("px");
c1->Update();
ps->Close();
// invoke Postscript viewer
gSystem->Exec("gs file.ps");
}
~~~
## Making several pictures in the same Postscript file: case 3
This is the recommended way. If the Postscript file name finishes with
"(", the file remains opened (it is not closed). If the Postscript file name
finishes with ")" and the file has been opened with "(", the file is closed.
Example:
~~~ {.cpp}
{
TCanvas c1("c1");
h1.Draw();
c1.Print("c1.ps("); // write canvas and keep the ps file open
h2.Draw();
c1.Print("c1.ps"); // canvas is added to "c1.ps"
h3.Draw();
c1.Print("c1.ps)"); // canvas is added to "c1.ps" and ps file is closed
}
~~~
The `TCanvas::Print("file.ps(")` mechanism is very useful, but it can
be a little inconvenient to have the action of opening/closing a file being
atomic with printing a page. Particularly if pages are being generated in some
loop one needs to detect the special cases of first and last page and then
munge the argument to Print() accordingly.
The "[" and "]" can be used instead of "(" and ")" as shown below.
Example:
~~~ {.cpp}
c1.Print("file.ps["); // No actual print, just open file.ps
for (int i=0; i<10; ++i) {
// fill canvas for context i
// ...
c1.Print("file.ps"); // Actually print canvas to the file
}
c1.Print("file.ps]"); // No actual print, just close the file
~~~
## Color Model
TPostScript support two color model RGB and CMYK. CMY and CMYK models are
subtractive color models unlike RGB which is an additive. They are mainly
used for printing purposes. CMY means Cyan Magenta Yellow to convert RGB
to CMY it is enough to do: C=1-R, M=1-G and Y=1-B. CMYK has one more
component K (black). The conversion from RGB to CMYK is:
~~~ {.cpp}
Double_t Black = TMath::Min(TMath::Min(1-Red,1-Green),1-Blue);
Double_t Cyan = (1-Red-Black)/(1-Black);
Double_t Magenta = (1-Green-Black)/(1-Black);
Double_t Yellow = (1-Blue-Black)/(1-Black);
~~~
CMYK add the black component which allows to have a better quality for black
printing. PostScript support the CMYK model.
To change the color model use `gStyle->SetColorModelPS(c)`.
- c = 0 means TPostScript will use RGB color model (default)
- c = 1 means TPostScript will use CMYK color model
*/
#ifdef WIN32
#pragma optimize("",off)
#endif
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cwchar>
#include <fstream>
#include "strlcpy.h"
#include "snprintf.h"
#include "Byteswap.h"
#include "TROOT.h"
#include "TDatime.h"
#include "TColor.h"
#include "TVirtualPad.h"
#include "TPoints.h"
#include "TPostScript.h"
#include "TStyle.h"
#include "TMath.h"
#include "TText.h"
#include "TSystem.h"
#include "TEnv.h"
#include "../../../graf2d/mathtext/inc/fontembed.h"
// to scale fonts to the same size as the old TT version
const Float_t kScale = 0.93376068;
// Array defining if a font must be embedded or not.
static Bool_t MustEmbed[32];
Int_t TPostScript::fgLineJoin = 0;
Int_t TPostScript::fgLineCap = 0;
////////////////////////////////////////////////////////////////////////////////
/// Default PostScript constructor
TPostScript::TPostScript() : TVirtualPS()
{
fStream = nullptr;
fType = 0;
gVirtualPS = this;
fBlue = 0.;
fBoundingBox = kFALSE;
fClear = kFALSE;
fClip = 0;
fClipStatus = kFALSE;
fDXC = 0.;
fDYC = 0.;
fFX = 0.;
fFY = 0.;
fGreen = 0.;
fIXzone = 0;
fIYzone = 0;
fLastCellBlue = 0;
fLastCellGreen = 0;
fLastCellRed = 0;
fLineScale = 0.;
fMarkerSizeCur = 0.;
fMaxLines = 0;
fMaxsize = 0;
fMode = 0;
fNBSameColorCell = 0;
fNXzone = 0;
fNYzone = 0;
fNbCellLine = 0;
fNbCellW = 0;
fNbinCT = 0;
fNpages = 0;
fRange = kFALSE;
fRed = 0.;
fSave = 0;
fWidth = 0.;
fStyle = 1;
fX1v = 0.;
fX1w = 0.;
fX2v = 0.;
fX2w = 0.;
fXC = 0.;
fXVP1 = 0.;
fXVP2 = 0.;
fXVS1 = 0.;
fXVS2 = 0.;
fXsize = 0.;
fY1v = 0.;
fY1w = 0.;
fY2v = 0.;
fY2w = 0.;
fYC = 0.;
fYVP1 = 0.;
fYVP2 = 0.;
fYVS1 = 0.;
fYVS2 = 0.;
fYsize = 0.;
fZone = kFALSE;
fFileName = "";
fFontEmbed = kFALSE;
Int_t i;
for (i=0; i<32; i++) fPatterns[i] = 0;
for (i=0; i<32; i++) MustEmbed[i] = kFALSE;
SetTitle("PS");
}
////////////////////////////////////////////////////////////////////////////////
/// Initialize the PostScript interface
///
/// - fname : PostScript file name
/// - wtype : PostScript workstation type
///
///
/// The possible workstation types are:
/// - 111 ps Portrait
/// - 112 ps Landscape
/// - 113 eps
TPostScript::TPostScript(const char *fname, Int_t wtype)
:TVirtualPS(fname, wtype)
{
fStream = nullptr;
SetTitle("PS");
Open(fname, wtype);
}
////////////////////////////////////////////////////////////////////////////////
/// Open a PostScript file
void TPostScript::Open(const char *fname, Int_t wtype)
{
if (fStream) {
Warning("Open", "postscript file already open");
return;
}
fMarkerSizeCur = 0;
fRed = -1;
fGreen = -1;
fBlue = -1;
fLenBuffer = 0;
fClip = 0;
fType = abs(wtype);
fClear = kTRUE;
fZone = kFALSE;
fSave = 0;
fFontEmbed = kFALSE;
SetLineJoin(gStyle->GetJoinLinePS());
SetLineCap(gStyle->GetCapLinePS());
SetLineScale(gStyle->GetLineScalePS());
gStyle->GetPaperSize(fXsize, fYsize);
fMode = fType%10;
Float_t xrange, yrange;
if (gPad) {
Double_t ww = gPad->GetWw();
Double_t wh = gPad->GetWh();
if (fType == 113) {
ww *= gPad->GetWNDC();
wh *= gPad->GetHNDC();
}
Double_t ratio = wh/ww;
if (fType == 112) {
xrange = fYsize;
yrange = xrange*ratio;
if (yrange > fXsize) { yrange = fXsize; xrange = yrange/ratio;}
} else {
xrange = fXsize;
yrange = fXsize*ratio;
if (yrange > fYsize) { yrange = fYsize; xrange = yrange/ratio;}
}
fXsize = xrange; fYsize = yrange;
}
// Open OS file
fFileName = fname;
fStream = new std::ofstream(fFileName.Data(),std::ios::out);
if (!fStream || gSystem->AccessPathName(fFileName.Data(),kWritePermission)) {
Error("Open", "Cannot open file: %s", fFileName.Data());
return;
}
gVirtualPS = this;
for (Int_t i=0;i<fSizBuffer;i++) fBuffer[i] = ' ';
if( fType == 113) {
fBoundingBox = kFALSE;
PrintStr("%!PS-Adobe-2.0 EPSF-2.0@");
} else {
fBoundingBox = kTRUE;
PrintStr("%!PS-Adobe-2.0@");
Initialize();
}
fClipStatus = kFALSE;
fRange = kFALSE;
// Set a default range
Range(fXsize, fYsize);
fPrinted = kFALSE;
if (fType == 113) NewPage();
}
////////////////////////////////////////////////////////////////////////////////
/// Default PostScript destructor
TPostScript::~TPostScript()
{
Close();
}
////////////////////////////////////////////////////////////////////////////////
/// Close a PostScript file
void TPostScript::Close(Option_t *)
{
if (!gVirtualPS) return;
if (!fStream) return;
if (gPad) gPad->Update();
if( fMode != 3) {
SaveRestore(-1);
if( fPrinted ) { PrintStr("showpage@"); SaveRestore(-1);}
PrintStr("@");
PrintStr("%%Trailer@");
PrintStr("%%Pages: ");
WriteInteger(fNpages);
PrintStr("@");
while (fSave > 0) { SaveRestore(-1); }
} else {
PrintStr("@");
while (fSave > 0) { SaveRestore(-1); }
PrintStr("showpage@");
PrintStr("end@");
}
PrintStr("@");
PrintStr("%%EOF@");
// Embed the fonts previously used by TMathText
if (!fFontEmbed) {
// Close the file fFileName
if (fStream) {
PrintStr("@");
fStream->close(); delete fStream; fStream = nullptr;
}
// Rename the file fFileName
TString tmpname = TString::Format("%s_tmp_%d",fFileName.Data(),gSystem->GetPid());
if (gSystem->Rename( fFileName.Data() , tmpname.Data())) {
Error("Close", "Cannot open temporary file: %s", tmpname.Data());
return;
}
// Reopen the file fFileName
fStream = new std::ofstream(fFileName.Data(),std::ios::out);
if (!fStream || gSystem->AccessPathName(fFileName.Data(),kWritePermission)) {
Error("Close", "Cannot open file: %s", fFileName.Data());
return;
}
// Embed the fonts at the right place
FILE *sg = fopen(tmpname.Data(),"r");
if (!sg) {
Error("Close", "Cannot open file: %s", tmpname.Data());
return;
}
char line[255];
while (fgets(line,255,sg)) {
if (strstr(line,"EndComments")) PrintStr("%%DocumentNeededResources: ProcSet (FontSetInit)@");
fStream->write(line,strlen(line));
if (!fFontEmbed && strstr(line,"m5")) {
FontEmbed();
PrintStr("@");
}
}
fclose(sg);
if (gSystem->Unlink(tmpname.Data())) return;
}
fFontEmbed = kFALSE;
// Close file stream
if (fStream) { fStream->close(); delete fStream; fStream = nullptr;}
gVirtualPS = nullptr;
}
////////////////////////////////////////////////////////////////////////////////
/// Activate an already open PostScript file
void TPostScript::On()
{
if (!fType) {
Error("On", "no postscript file open");
Off();
return;
}
gVirtualPS = this;
}
////////////////////////////////////////////////////////////////////////////////
/// Deactivate an already open PostScript file
void TPostScript::Off()
{
gVirtualPS = nullptr;
}
////////////////////////////////////////////////////////////////////////////////
/// Draw a Cell Array
///
/// Drawing a PostScript Cell Array is in fact done thanks to three
/// procedures: CellArrayBegin, CellArrayFill, and CellArrayEnd.
///
/// - CellArrayBegin: Initiate the Cell Array by writing the necessary
/// PostScript procedures and the initial values of the
/// required parameters. The input parameters are:
/// - W: number of boxes along the width.
/// - H: number of boxes along the height
/// - x1,x2,y1,y2: First box coordinates.
/// - CellArrayFill: Is called for each box of the Cell Array. The first
/// box is the top left one and the last box is the
/// bottom right one. The input parameters are the Red,
/// Green, and Blue components of the box colour. These
/// Levels are between 0 and 255.
/// - CellArrayEnd: Finishes the Cell Array.
///
/// PostScript cannot handle arrays larger than 65535. So the Cell Array
/// is drawn in several pieces.
void TPostScript::CellArrayBegin(Int_t W, Int_t /*H*/, Double_t x1, Double_t x2,
Double_t y1, Double_t y2)
{
Int_t ix1 = XtoPS(x1);
Int_t iy1 = YtoPS(y1);
Float_t wt = (288/2.54)*gPad->GetAbsWNDC()*
fXsize*((x2 - x1)/(gPad->GetX2()-gPad->GetX1()));
Float_t ht = (288/2.54)*gPad->GetAbsHNDC()*
fYsize*((y2 - y1)/(gPad->GetY2()-gPad->GetY1()));
fLastCellRed = 300;
fLastCellGreen = 300;
fLastCellBlue = 300;
fNBSameColorCell = 0;
fNbinCT = 0;
fNbCellW = W;
fNbCellLine = 0;
fMaxLines = 40000/(3*fNbCellW);
// Define some parameters
PrintStr("@/WT"); WriteReal(wt) ; PrintStr(" def"); // Cells width
PrintStr(" /HT"); WriteReal(ht) ; PrintStr(" def"); // Cells height
PrintStr(" /XS"); WriteInteger(ix1) ; PrintStr(" def"); // X start
PrintStr(" /YY"); WriteInteger(iy1) ; PrintStr(" def"); // Y start
PrintStr(" /NX"); WriteInteger(W) ; PrintStr(" def"); // Number of columns
PrintStr(" /NY"); WriteInteger(fMaxLines); PrintStr(" def"); // Number of lines
// This PS procedure draws one cell.
PrintStr(" /DrawCell ");
PrintStr( "{WT HT XX YY bf");
PrintStr( " /NBBD NBBD 1 add def");
PrintStr( " NBBD NBB eq {exit} if");
PrintStr( " /XX WT XX add def");
PrintStr( " IX NX eq ");
PrintStr( "{/YY YY HT sub def");
PrintStr( " /XX XS def");
PrintStr( " /IX 0 def} if");
PrintStr( " /IX IX 1 add def} def");
// This PS procedure draws fMaxLines line. It takes care of duplicated
// colors. Values "n" greater than 300 mean than the previous color
// should be duplicated n-300 times.
PrintStr(" /DrawCT ");
PrintStr( "{/NBB NX NY mul def");
PrintStr( " /XX XS def");
PrintStr( " /IX 1 def");
PrintStr( " /NBBD 0 def");
PrintStr( " /RC 0 def /GC 1 def /BC 2 def");
PrintStr( " 1 1 NBB ");
PrintStr( "{/NB CT RC get def");
PrintStr( " NB 301 ge ");
PrintStr( "{/NBL NB 300 sub def");
PrintStr( " 1 1 NBL ");
PrintStr( "{DrawCell}");
PrintStr( " for");
PrintStr( " /RC RC 1 add def");
PrintStr( " /GC RC 1 add def");
PrintStr( " /BC RC 2 add def}");
PrintStr( "{CT RC get 255 div CT GC get 255 div CT BC get 255 div setrgbcolor");
PrintStr( " DrawCell");
PrintStr( " /RC RC 3 add def");
PrintStr( " /GC GC 3 add def");
PrintStr( " /BC BC 3 add def} ifelse NBBD NBB eq {exit} if} for");
PrintStr( " /YY YY HT sub def clear} def");
PrintStr(" /CT [");
}
////////////////////////////////////////////////////////////////////////////////
/// Paint the Cell Array
void TPostScript::CellArrayFill(Int_t r, Int_t g, Int_t b)
{
if (fLastCellRed == r && fLastCellGreen == g && fLastCellBlue == b) {
fNBSameColorCell++;
} else {
if (fNBSameColorCell != 0 ) {
WriteInteger(fNBSameColorCell+300);
fNBSameColorCell = 0;
}
WriteInteger(r);
WriteInteger(g);
WriteInteger(b);
fLastCellRed = r;
fLastCellGreen = g;
fLastCellBlue = b;
}
fNbinCT++;
if (fNbinCT == fNbCellW) {
fNbCellLine++;
fNbinCT = 0;
}
if (fNbCellLine == fMaxLines) {
if (fNBSameColorCell != 0) WriteInteger(fNBSameColorCell+300);
PrintStr("] def DrawCT /CT [");
fNbCellLine = 0;
fLastCellRed = 300;
fLastCellGreen = 300;
fLastCellBlue = 300;
fNBSameColorCell = 0;
fNbinCT = 0;
}
}
////////////////////////////////////////////////////////////////////////////////
/// End the Cell Array painting
void TPostScript::CellArrayEnd()
{
if (fNBSameColorCell != 0 ) WriteInteger(fNBSameColorCell+300);
PrintStr("] def /NY");
WriteInteger(fNbCellLine);
PrintStr(" def DrawCT ");
}
////////////////////////////////////////////////////////////////////////////////
/// Define the markers
void TPostScript::DefineMarkers()
{
PrintStr("/mp {newpath /y exch def /x exch def} def@");
PrintStr("/side {[w .77 mul w .23 mul] .385 w mul sd w 0 l currentpoint t -144 r} def@");
PrintStr("/mr {mp x y w2 0 360 arc} def /m24 {mr s} def /m20 {mr f} def@");
PrintStr("/mb {mp x y w2 add m w2 neg 0 d 0 w neg d w 0 d 0 w d cl} def@");
PrintStr("/mt {mp x y w2 add m w2 neg w neg d w 0 d cl} def@");
PrintStr("/w4 {w 4 div} def@");
PrintStr("/w6 {w 6 div} def@");
PrintStr("/w8 {w 8 div} def@");
PrintStr("/m21 {mb f} def /m25 {mb s} def /m22 {mt f} def /m26{mt s} def@");
PrintStr("/m23 {mp x y w2 sub m w2 w d w neg 0 d cl f} def@");
PrintStr("/m27 {mp x y w2 add m w3 neg w2 neg d w3 w2 neg d w3 w2 d cl s} def@");
PrintStr("/m28 {mp x w2 sub y w2 sub w3 add m w3 0 d ");
PrintStr(" 0 w3 neg d w3 0 d 0 w3 d w3 0 d ");
PrintStr(" 0 w3 d w3 neg 0 d 0 w3 d w3 neg 0 d");
PrintStr(" 0 w3 neg d w3 neg 0 d cl s } def@");
PrintStr("/m29 {mp gsave x w2 sub y w2 add w3 sub m currentpoint t");
PrintStr(" 4 {side} repeat cl fill gr} def@");
PrintStr("/m30 {mp gsave x w2 sub y w2 add w3 sub m currentpoint t");
PrintStr(" 4 {side} repeat cl s gr} def@");
PrintStr("/m31 {mp x y w2 sub m 0 w d x w2 sub y m w 0 d");
PrintStr(" x w2 .707 mul sub y w2 .707 mul add m w 1.44 div w 1.44 div neg d x w2 .707 mul sub y w2 .707 mul");
PrintStr(" sub m w 1.44 div w 1.44 div d s} def@");
PrintStr("/m32 {mp x y w2 sub m w2 w d w neg 0 d cl s} def@");
PrintStr("/m33 {mp x y w2 add m w3 neg w2 neg d w3 w2 neg d w3 w2 d cl f} def@");
PrintStr("/m34 {mp x w2 sub y w2 sub w3 add m w3 0 d ");
PrintStr(" 0 w3 neg d w3 0 d 0 w3 d w3 0 d ");
PrintStr(" 0 w3 d w3 neg 0 d 0 w3 d w3 neg 0 d");
PrintStr(" 0 w3 neg d w3 neg 0 d cl f } def@");
PrintStr("/m35 {mp x y w2 add m w2 neg w2 neg d w2 w2 neg d w2 w2 d w2 neg w2 d");
PrintStr(" x y w2 sub m 0 w d x w2 sub y m w 0 d s} def@");
PrintStr("/m36 {mb x w2 sub y w2 add m w w neg d x w2 sub y w2 sub m w w d s} def@");
PrintStr("/m37 {mp x y m w4 neg w2 d w4 neg w2 neg d w2 0 d ");
PrintStr(" w4 neg w2 neg d w2 0 d w4 neg w2 d w2 0 d w4 neg w2 d w4 neg w2 neg d cl s} def@");
PrintStr("/m38 {mp x w4 sub y w2 add m w4 neg w4 neg d 0 w2 neg d w4 w4 neg d");
PrintStr(" w2 0 d w4 w4 d 0 w2 d w4 neg w4 d w2 neg 0 d");
PrintStr(" x y w2 sub m 0 w d x w2 sub y m w 0 d cl s} def@");
PrintStr("/m39 {mp x y m w4 neg w2 d w4 neg w2 neg d w2 0 d ");
PrintStr(" w4 neg w2 neg d w2 0 d w4 neg w2 d w2 0 d w4 neg w2 d w4 neg w2 neg d cl f} def@");
PrintStr("/m40 {mp x y m w4 w2 d w4 w4 neg d w2 neg w4 neg d w2 w4 neg d w4 neg w4 neg d");
PrintStr(" w4 neg w2 d w4 neg w2 neg d w4 neg w4 d w2 w4 d w2 neg w4 d w4 w4 d w4 w2 neg d cl s} def@");
PrintStr("/m41 {mp x y m w4 w2 d w4 w4 neg d w2 neg w4 neg d w2 w4 neg d w4 neg w4 neg d");
PrintStr(" w4 neg w2 d w4 neg w2 neg d w4 neg w4 d w2 w4 d w2 neg w4 d w4 w4 d w4 w2 neg d cl f} def@");
PrintStr("/m42 {mp x y w2 add m w8 neg w2 -3 4 div mul d w2 -3 4 div mul w8 neg d");
PrintStr(" w2 3 4 div mul w8 neg d w8 w2 -3 4 div mul d");
PrintStr(" w8 w2 3 4 div mul d w2 3 4 div mul w8 d");
PrintStr(" w2 -3 4 div mul w8 d w8 neg w2 3 4 div mul d cl s} def@");
PrintStr("/m43 {mp x y w2 add m w8 neg w2 -3 4 div mul d w2 -3 4 div mul w8 neg d");
PrintStr(" w2 3 4 div mul w8 neg d w8 w2 -3 4 div mul d");
PrintStr(" w8 w2 3 4 div mul d w2 3 4 div mul w8 d");
PrintStr(" w2 -3 4 div mul w8 d w8 neg w2 3 4 div mul d cl f} def@");
PrintStr("/m44 {mp x y m w6 neg w2 d w2 2 3 div mul 0 d w6 neg w2 neg d");
PrintStr(" w2 w6 d 0 w2 -2 3 div mul d w2 neg w6 d");
PrintStr(" w6 w2 neg d w2 -2 3 div mul 0 d w6 w2 d");
PrintStr(" w2 neg w6 neg d 0 w2 2 3 div mul d w2 w6 neg d cl s} def@");
PrintStr("/m45 {mp x y m w6 neg w2 d w2 2 3 div mul 0 d w6 neg w2 neg d");
PrintStr(" w2 w6 d 0 w2 -2 3 div mul d w2 neg w6 d");
PrintStr(" w6 w2 neg d w2 -2 3 div mul 0 d w6 w2 d");
PrintStr(" w2 neg w6 neg d 0 w2 2 3 div mul d w2 w6 neg d cl f} def@");
PrintStr("/m46 {mp x y w4 add m w4 neg w4 d w4 neg w4 neg d ");
PrintStr(" w4 w4 neg d w4 neg w4 neg d w4 w4 neg d w4 w4 d");
PrintStr(" w4 w4 neg d w4 w4 d w4 neg w4 d w4 w4 d w4 neg w4 d w4 neg w4 neg d cl s} def@");
PrintStr("/m47 {mp x y w4 add m w4 neg w4 d w4 neg w4 neg d");
PrintStr(" w4 w4 neg d w4 neg w4 neg d w4 w4 neg d w4 w4 d");
PrintStr(" w4 w4 neg d w4 w4 d w4 neg w4 d w4 w4 d w4 neg w4 d w4 neg w4 neg d cl f} def@");
PrintStr("/m48 {mp x y w4 add m w4 neg w4 d w4 neg w4 neg d w4 w4 neg d ");
PrintStr(" w4 neg w4 neg d w4 w4 neg d w4 w4 d w4 w4 neg d w4 w4 d");
PrintStr(" w4 neg w4 d w4 w4 d w4 neg w4 d w4 neg w4 neg d ");
PrintStr(" w4 w4 neg d w4 neg w4 neg d w4 neg w4 d w4 w4 d cl f} def@");
PrintStr("/m49 {mp x w2 sub w3 add y w2 sub w3 add m ");
PrintStr(" 0 w3 neg d w3 0 d 0 w3 d w3 0 d 0 w3 d w3 neg 0 d 0 w3 d w3 neg 0 d");
PrintStr(" 0 w3 neg d w3 neg 0 d 0 w3 neg d w3 0 d 0 w3 d w3 0 d 0 w3 neg d w3 neg 0 d cl f } def@");
PrintStr("/m2 {mp x y w2 sub m 0 w d x w2 sub y m w 0 d s} def@");
PrintStr("/m5 {mp x w2 .707 mul sub y w2 .707 mul sub m w 1.44 div w 1.44 div d x w2 .707 mul sub y w2 .707 mul add m w 1.44 div w 1.44 div neg d s} def@");
}
////////////////////////////////////////////////////////////////////////////////
/// Draw a Box
void TPostScript::DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
{
static Double_t x[4], y[4];
Int_t ix1 = XtoPS(x1);
Int_t ix2 = XtoPS(x2);
Int_t iy1 = YtoPS(y1);
Int_t iy2 = YtoPS(y2);
Int_t fillis = fFillStyle/1000;
Int_t fillsi = fFillStyle%1000;
if (fillis == 3 || fillis == 2) {
if (fillsi > 99) {
x[0] = x1; y[0] = y1;
x[1] = x2; y[1] = y1;
x[2] = x2; y[2] = y2;
x[3] = x1; y[3] = y2;
return;
}
if (fillsi > 0 && fillsi < 26) {
x[0] = x1; y[0] = y1;
x[1] = x2; y[1] = y1;
x[2] = x2; y[2] = y2;
x[3] = x1; y[3] = y2;
DrawPS(-4, &x[0], &y[0]);
}
if (fillsi == -3) {
SetColor(5);
WriteInteger(ix2 - ix1);
WriteInteger(iy2 - iy1);
WriteInteger(ix1);
WriteInteger(iy1);
PrintFast(3," bf");
}
}
if (fillis == 1) {
SetColor(fFillColor);
WriteInteger(ix2 - ix1);
WriteInteger(iy2 - iy1);
WriteInteger(ix1);
WriteInteger(iy1);
PrintFast(3," bf");
}
if (fillis == 0) {
if (fLineWidth<=0) return;
SetColor(fLineColor);
WriteInteger(ix2 - ix1);
WriteInteger(iy2 - iy1);
WriteInteger(ix1);
WriteInteger(iy1);
PrintFast(3," bl");
}
}
////////////////////////////////////////////////////////////////////////////////
/// Draw a Frame around a box
///
/// - mode = -1 box looks as it is behind the screen
/// - mode = 1 box looks as it is in front of the screen
/// - border is the border size in already precomputed PostScript units
/// - dark is the color for the dark part of the frame
/// - light is the color for the light part of the frame
void TPostScript::DrawFrame(Double_t xl, Double_t yl, Double_t xt, Double_t yt,
Int_t mode, Int_t border, Int_t dark, Int_t light)
{
static Int_t xps[7], yps[7];
Int_t i, ixd0, iyd0, idx, idy, ixdi, iydi, ix, iy;
// Draw top&left part of the box
if (mode == -1) SetColor(dark);
else SetColor(light);
Int_t bordPS = 4*border;
xps[0] = XtoPS(xl); yps[0] = YtoPS(yl);
xps[1] = xps[0] + bordPS; yps[1] = yps[0] + bordPS;
xps[2] = xps[1]; yps[2] = YtoPS(yt) - bordPS;
xps[3] = XtoPS(xt) - bordPS; yps[3] = yps[2];
xps[4] = XtoPS(xt); yps[4] = YtoPS(yt);
xps[5] = xps[0]; yps[5] = yps[4];
xps[6] = xps[0]; yps[6] = yps[0];
ixd0 = xps[0];
iyd0 = yps[0];
WriteInteger(ixd0);
WriteInteger(iyd0);
PrintFast(2," m");
idx = 0;
idy = 0;
for (i=1;i<7;i++) {
ixdi = xps[i];
iydi = yps[i];
ix = ixdi - ixd0;
iy = iydi - iyd0;
ixd0 = ixdi;
iyd0 = iydi;
if( ix && iy) {
if( idx ) { MovePS(idx,0); idx = 0; }
if( idy ) { MovePS(0,idy); idy = 0; }
MovePS(ix,iy);
continue;
}
if ( ix ) {
if( idy ) { MovePS(0,idy); idy = 0; }
if( !idx ) { idx = ix; continue;}
if( ix*idx > 0 ) idx += ix;
else { MovePS(idx,0); idx = ix; }
continue;
}
if( iy ) {
if( idx ) { MovePS(idx,0); idx = 0; }
if( !idy) { idy = iy; continue;}
if( iy*idy > 0 ) idy += iy;
else { MovePS(0,idy); idy = iy; }
}
}
if( idx ) MovePS(idx,0);
if( idy ) MovePS(0,idy);
PrintFast(2," f");
// Draw bottom&right part of the box
if (mode == -1) SetColor(light);
else SetColor(dark);
xps[0] = XtoPS(xl); yps[0] = YtoPS(yl);
xps[1] = xps[0] + bordPS; yps[1] = yps[0] + bordPS;
xps[2] = XtoPS(xt) - bordPS; yps[2] = yps[1];
xps[3] = xps[2]; yps[3] = YtoPS(yt) - bordPS;
xps[4] = XtoPS(xt); yps[4] = YtoPS(yt);
xps[5] = xps[4]; yps[5] = yps[0];
xps[6] = xps[0]; yps[6] = yps[0];
ixd0 = xps[0];
iyd0 = yps[0];
WriteInteger(ixd0);
WriteInteger(iyd0);
PrintFast(2," m");
idx = 0;
idy = 0;
for (i=1;i<7;i++) {
ixdi = xps[i];
iydi = yps[i];
ix = ixdi - ixd0;
iy = iydi - iyd0;
ixd0 = ixdi;
iyd0 = iydi;
if( ix && iy) {
if( idx ) { MovePS(idx,0); idx = 0; }
if( idy ) { MovePS(0,idy); idy = 0; }
MovePS(ix,iy);
continue;
}
if ( ix ) {
if( idy ) { MovePS(0,idy); idy = 0; }
if( !idx ) { idx = ix; continue;}
if( ix*idx > 0 ) idx += ix;
else { MovePS(idx,0); idx = ix; }
continue;
}
if( iy ) {
if( idx ) { MovePS(idx,0); idx = 0; }
if( !idy) { idy = iy; continue;}
if( iy*idy > 0 ) idy += iy;
else { MovePS(0,idy); idy = iy; }
}
}
if( idx ) MovePS(idx,0);
if( idy ) MovePS(0,idy);
PrintFast(2," f");
}
////////////////////////////////////////////////////////////////////////////////
/// Draw a PolyLine
///
/// Draw a polyline through the points xy.
/// - If nn=1 moves only to point x,y.
/// - If nn=0 the x,y are written in the PostScript file
/// according to the current transformation.
/// - If nn>0 the line is clipped as a line.
/// - If nn<0 the line is clipped as a fill area.
void TPostScript::DrawPolyLine(Int_t nn, TPoints *xy)
{
Int_t i, n, ixd0, iyd0, idx, idy, ixdi, iydi, ix, iy;
Style_t linestylesav = fLineStyle;
Width_t linewidthsav = fLineWidth;
if (nn > 0) {
if (fLineWidth<=0) return;
n = nn;
SetStyle(fLineStyle);
SetWidth(fLineWidth);
SetColor(Int_t(fLineColor));
} else {
n = -nn;
SetStyle(1);
SetWidth(1);
SetColor(Int_t(fLineColor));
}
ixd0 = XtoPS(xy[0].GetX());
iyd0 = YtoPS(xy[0].GetY());
WriteInteger(ixd0);
WriteInteger(iyd0);
if( n <= 1) {
if( n == 0) goto END;
PrintFast(2," m");
goto END;
}
PrintFast(2," m");
idx = 0;
idy = 0;
for (i=1;i<n;i++) {
ixdi = XtoPS(xy[i].GetX());
iydi = YtoPS(xy[i].GetY());
ix = ixdi - ixd0;
iy = iydi - iyd0;
ixd0 = ixdi;
iyd0 = iydi;
if( ix && iy) {
if( idx ) { MovePS(idx,0); idx = 0; }
if( idy ) { MovePS(0,idy); idy = 0; }
MovePS(ix,iy);
continue;
}
if ( ix ) {
if( idy ) { MovePS(0,idy); idy = 0; }
if( !idx ) { idx = ix; continue;}
if( ix*idx > 0 ) idx += ix;
else { MovePS(idx,0); idx = ix; }
continue;
}
if( iy ) {
if( idx ) { MovePS(idx,0); idx = 0; }
if( !idy) { idy = iy; continue;}
if( iy*idy > 0 ) idy += iy;
else { MovePS(0,idy); idy = iy; }
}
}
if( idx ) MovePS(idx,0);
if( idy ) MovePS(0,idy);
if (nn > 0 ) {