13 #pragma optimize("",off)
88 TTeXDump::TTeXDump() : TVirtualPS()
93 fBoundingBox = kFALSE;
113 TTeXDump::TTeXDump(
const char *fname, Int_t wtype) : TVirtualPS(fname, wtype)
118 fBoundingBox = kFALSE;
134 void TTeXDump::Open(
const char *fname, Int_t wtype)
137 Warning(
"Open",
"TeX file already open");
141 SetLineScale(gStyle->GetLineScalePS());
145 gStyle->GetPaperSize(fXsize, fYsize);
147 Float_t xrange, yrange;
149 Double_t ww = gPad->GetWw();
150 Double_t wh = gPad->GetWh();
151 ww *= gPad->GetWNDC();
152 wh *= gPad->GetHNDC();
153 Double_t ratio = wh/ww;
155 yrange = fXsize*ratio;
156 if (yrange > fYsize) { yrange = fYsize; xrange = yrange/ratio;}
157 fXsize = xrange; fYsize = yrange;
161 fStream =
new std::ofstream(fname,std::ios::out);
162 if (fStream == 0 || !fStream->good()) {
163 printf(
"ERROR in TTeXDump::Open: Cannot open file:%s\n",fname);
164 if (fStream == 0)
return;
169 for (Int_t i=0;i<fSizBuffer;i++) fBuffer[i] =
' ';
171 fBoundingBox = kFALSE;
175 Range(fXsize, fYsize);
183 TTeXDump::~TTeXDump()
191 void TTeXDump::Close(Option_t *)
193 if (!gVirtualPS)
return;
194 if (!fStream)
return;
195 if (gPad) gPad->Update();
197 PrintStr(
"\\end{tikzpicture}@");
200 if (fStream) { fStream->close();
delete fStream; fStream = 0;}
214 Error(
"On",
"no TeX file open");
232 void TTeXDump::DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
234 Float_t x1c = XtoTeX(x1);
235 Float_t y1c = YtoTeX(y1);
236 Float_t x2c = XtoTeX(x2);
237 Float_t y2c = YtoTeX(y2);
239 Int_t fillis = fFillStyle/1000;
240 Int_t fillsi = fFillStyle%1000;
243 SetColor(fFillColor);
245 PrintStr(
"\\draw [color=c, fill=c");
246 if (fCurrentAlpha != 1.) {
247 PrintStr(
", fill opacity=");
248 WriteReal(fCurrentAlpha, kFALSE);
251 WriteReal(x1c, kFALSE);
253 WriteReal(y1c, kFALSE);
254 PrintStr(
") rectangle (");
255 WriteReal(x2c, kFALSE);
257 WriteReal(y2c, kFALSE);
260 if (fillis>1 && fillis<4) {
261 SetColor(fFillColor);
263 PrintStr(
"\\draw [pattern=");
266 PrintStr(
"crosshatch dots");
273 PrintStr(
"north east lines");
276 PrintStr(
"north west lines");
279 PrintStr(
"vertical lines");
282 PrintStr(
"horizontal lines");
288 PrintStr(
"crosshatch");
291 PrintStr(
", draw=none, pattern color=c");
292 if (fCurrentAlpha != 1.) {
293 PrintStr(
", fill opacity=");
294 WriteReal(fCurrentAlpha, kFALSE);
297 WriteReal(x1c, kFALSE);
299 WriteReal(y1c, kFALSE);
300 PrintStr(
") rectangle (");
301 WriteReal(x2c, kFALSE);
303 WriteReal(y2c, kFALSE);
307 if (fLineWidth<=0)
return;
308 SetColor(fLineColor);
310 PrintStr(
"\\draw [c");
311 PrintStr(
",line width=");
312 WriteReal(0.3*fLineScale*fLineWidth, kFALSE);
313 if (fCurrentAlpha != 1.) {
314 PrintStr(
", opacity=");
315 WriteReal(fCurrentAlpha, kFALSE);
318 WriteReal(x1c, kFALSE);
320 WriteReal(y1c, kFALSE);
322 WriteReal(x1c, kFALSE);
324 WriteReal(y2c, kFALSE);
326 WriteReal(x2c, kFALSE);
328 WriteReal(y2c, kFALSE);
330 WriteReal(x2c, kFALSE);
332 WriteReal(y1c, kFALSE);
334 WriteReal(x1c, kFALSE);
336 WriteReal(y1c, kFALSE);
350 void TTeXDump::DrawFrame(Double_t, Double_t, Double_t, Double_t,
351 Int_t, Int_t, Int_t, Int_t)
353 Warning(
"DrawFrame",
"not yet implemented");
366 void TTeXDump::DrawPolyLine(Int_t, TPoints *)
368 Warning(
"DrawPolyLine",
"not yet implemented");
381 void TTeXDump::DrawPolyLineNDC(Int_t, TPoints *)
383 Warning(
"DrawPolyLineNDC",
"not yet implemented");
389 void TTeXDump::DrawPolyMarker(Int_t, Float_t *, Float_t *)
391 Warning(
"DrawPolyMarker",
"not yet implemented");
397 void TTeXDump::DrawPolyMarker(Int_t n, Double_t *xw, Double_t *yw)
401 SetColor(fMarkerColor);
404 PrintStr(
"\\foreach \\P in {");
410 WriteReal(x, kFALSE);
412 WriteReal(y, kFALSE);
415 for (Int_t i=1;i<n;i++) {
419 WriteReal(x, kFALSE);
421 WriteReal(y, kFALSE);
425 PrintStr(
"}{\\draw[mark options={color=c,fill=c");
427 if (fCurrentAlpha != 1.) {
428 PrintStr(
",opacity=");
429 WriteReal(fCurrentAlpha, kFALSE);
432 if (fMarkerStyle == 23 || fMarkerStyle == 32) PrintStr(
",rotate=180");
434 PrintStr(Form(
"},mark size=%fpt,mark=",8./3.33*fMarkerSize));
435 switch (fMarkerStyle) {
438 PrintStr(
",mark size=1pt");
444 PrintStr(
"asterisk");
459 PrintStr(
"triangle*");
462 PrintStr(
"triangle*");
471 PrintStr(
"triangle");
480 PrintStr(
"newstar*");
486 PrintStr(
"10-pointed star");
489 PrintStr(
"triangle");
492 PrintStr(
"diamond*");
498 PrintStr(
"] plot coordinates {\\P};}");
508 void TTeXDump::DrawPS(Int_t nn, Double_t *xw, Double_t *yw)
510 Int_t n = TMath::Abs(nn);;
514 Error(
"DrawPS",
"Two points are needed");
521 Int_t fillis = fFillStyle/1000;
522 Int_t fillsi = fFillStyle%1000;
525 if (fLineWidth<=0)
return;
526 SetColor(fLineColor);
528 PrintStr(
"\\draw [c");
529 TString spec = gStyle->GetLineStyleString(fLineStyle);
531 TString stripped = TString{spec.Strip(TString::kBoth)};
532 if (stripped.Length()) {
533 tikzSpec.Append(
",dash pattern=");
535 bool on{
true}, iterate{
true};
538 j = stripped.Index(
" ", 1, i, TString::kExact);
541 j = stripped.Length();
545 tikzSpec.Append(
"on ");
548 tikzSpec.Append(
"off ");
551 int num = TString{stripped(i, j - i)}.Atoi();
553 tikzSpec.Append(TString::Format(
"%.2fpt ", pt));
556 PrintStr(tikzSpec.Data());
558 PrintStr(
",line width=");
559 WriteReal(0.3*fLineScale*fLineWidth, kFALSE);
560 if (fCurrentAlpha != 1.) {
561 PrintStr(
",opacity=");
562 WriteReal(fCurrentAlpha, kFALSE);
565 SetColor(fFillColor);
568 PrintStr(
"\\draw [c, fill=c");
569 }
else if (fillis==0) {
571 PrintStr(
"\\draw [c");
573 PrintStr(
"\\draw [pattern=");
576 PrintStr(
"crosshatch dots");
583 PrintStr(
"north east lines");
586 PrintStr(
"north west lines");
589 PrintStr(
"vertical lines");
592 PrintStr(
"horizontal lines");
598 PrintStr(
"crosshatch");
601 PrintStr(
", draw=none, pattern color=c");
603 if (fCurrentAlpha != 1.) {
604 PrintStr(
", fill opacity=");
605 WriteReal(fCurrentAlpha, kFALSE);
609 WriteReal(x, kFALSE);
611 WriteReal(y, kFALSE);
614 for (Int_t i=1;i<n;i++) {
618 WriteReal(x, kFALSE);
620 WriteReal(y, kFALSE);
622 if (i<n-1) PrintStr(
" -- ");
630 void TTeXDump::NewPage()
634 Double_t ww = gPad->GetWw();
635 Double_t wh = gPad->GetWh();
636 fYsize = fXsize*wh/ww;
642 PrintStr(
"\\begin{tikzpicture}@");
644 fBoundingBox = kTRUE;
651 void TTeXDump::Range(Float_t xsize, Float_t ysize)
662 void TTeXDump::SetFillColor( Color_t cindex )
665 if (gStyle->GetFillColor() <= 0) cindex = 0;
671 void TTeXDump::SetLineColor( Color_t cindex )
684 void TTeXDump::SetLineStyle(Style_t linestyle)
686 fLineStyle = linestyle;
692 void TTeXDump::SetLineWidth(Width_t linewidth)
694 fLineWidth = linewidth;
700 void TTeXDump::SetMarkerSize( Size_t msize)
708 void TTeXDump::SetMarkerColor( Color_t cindex)
710 fMarkerColor = cindex;
716 void TTeXDump::SetColor(Int_t color)
718 if (color < 0) color = 0;
719 TColor *col = gROOT->GetColor(color);
722 SetColor(col->GetRed(), col->GetGreen(), col->GetBlue());
723 fCurrentAlpha = col->GetAlpha();
725 SetColor(1., 1., 1.);
737 void TTeXDump::SetColor(Float_t r, Float_t g, Float_t b)
739 if (fCurrentRed == r && fCurrentGreen == g && fCurrentBlue == b)
return;
745 PrintStr(
"\\definecolor{c}{rgb}{");
746 WriteReal(r, kFALSE);
748 WriteReal(g, kFALSE);
750 WriteReal(b, kFALSE);
757 void TTeXDump::SetTextColor( Color_t cindex )
769 void TTeXDump::Text(Double_t x, Double_t y,
const char *chars)
771 Double_t wh = (Double_t)gPad->XtoPixel(gPad->GetX2());
772 Double_t hh = (Double_t)gPad->YtoPixel(gPad->GetY1());
773 Float_t tsize, ftsize;
775 tsize = fTextSize*wh;
776 Int_t sizeTTF = (Int_t)(tsize+0.5);
777 ftsize = (sizeTTF*fXsize*gPad->GetAbsWNDC())/wh;
779 tsize = fTextSize*hh;
780 Int_t sizeTTF = (Int_t)(tsize+0.5);
781 ftsize = (sizeTTF*fYsize*gPad->GetAbsHNDC())/hh;
784 if (ftsize <= 0)
return;
787 if (t.Index(
"\\")>=0 || t.Index(
"^{")>=0 || t.Index(
"_{")>=0) {
791 t.ReplaceAll(
"<",
"$<$");
792 t.ReplaceAll(
">",
"$>$");
793 t.ReplaceAll(
"_",
"\\_");
795 t.ReplaceAll(
"&",
"\\&");
796 t.ReplaceAll(
"#",
"\\#");
797 t.ReplaceAll(
"%",
"\\%");
799 Int_t txalh = fTextAlign/10;
800 if (txalh <1) txalh = 1;
else if (txalh > 3) txalh = 3;
801 Int_t txalv = fTextAlign%10;
802 if (txalv <1) txalv = 1;
else if (txalv > 3) txalv = 3;
803 SetColor(fTextColor);
806 if (txalh!=2 || txalv!=2) {
807 PrintStr(
" [anchor=");
808 if (txalv==1) PrintStr(
"base");
809 if (txalv==3) PrintStr(
"north");
810 if (txalh==1) PrintStr(
" west");
811 if (txalh==3) PrintStr(
" east");
815 WriteReal(XtoTeX(x), kFALSE);
817 WriteReal(YtoTeX(y), kFALSE);
818 PrintStr(
") node[scale=");
819 WriteReal(ftsize, kFALSE);
820 PrintStr(
", color=c");
821 if (fCurrentAlpha != 1.) {
822 PrintStr(
",opacity=");
823 WriteReal(fCurrentAlpha, kFALSE);
825 PrintStr(
", rotate=");
826 WriteReal(fTextAngle, kFALSE);
835 void TTeXDump::TextNDC(Double_t u, Double_t v,
const char *chars)
837 Double_t x = gPad->GetX1() + u*(gPad->GetX2() - gPad->GetX1());
838 Double_t y = gPad->GetY1() + v*(gPad->GetY2() - gPad->GetY1());
845 Float_t TTeXDump::UtoTeX(Double_t u)
847 Double_t cm = fXsize*(gPad->GetAbsXlowNDC() + u*gPad->GetAbsWNDC());
854 Float_t TTeXDump::VtoTeX(Double_t v)
856 Double_t cm = fYsize*(gPad->GetAbsYlowNDC() + v*gPad->GetAbsHNDC());
863 Float_t TTeXDump::XtoTeX(Double_t x)
865 Double_t u = (x - gPad->GetX1())/(gPad->GetX2() - gPad->GetX1());
872 Float_t TTeXDump::YtoTeX(Double_t y)
874 Double_t v = (y - gPad->GetY1())/(gPad->GetY2() - gPad->GetY1());
881 void TTeXDump::CellArrayBegin(Int_t, Int_t, Double_t, Double_t, Double_t,
884 Warning(
"CellArrayBegin",
"not yet implemented");
890 void TTeXDump::CellArrayFill(Int_t, Int_t, Int_t)
892 Warning(
"CellArrayFill",
"not yet implemented");
898 void TTeXDump::CellArrayEnd()
900 Warning(
"CellArrayEnd",
"not yet implemented");
906 void TTeXDump::DrawPS(Int_t, Float_t *, Float_t *)
908 Warning(
"DrawPS",
"not yet implemented");
914 void TTeXDump::DefineMarkers()
917 PrintStr(
"\\pgfdeclareplotmark{cross} {@");
918 PrintStr(
"\\pgfpathmoveto{\\pgfpoint{-0.3\\pgfplotmarksize}{\\pgfplotmarksize}}@");
919 PrintStr(
"\\pgfpathlineto{\\pgfpoint{+0.3\\pgfplotmarksize}{\\pgfplotmarksize}}@");
920 PrintStr(
"\\pgfpathlineto{\\pgfpoint{+0.3\\pgfplotmarksize}{0.3\\pgfplotmarksize}}@");
921 PrintStr(
"\\pgfpathlineto{\\pgfpoint{+1\\pgfplotmarksize}{0.3\\pgfplotmarksize}}@");
922 PrintStr(
"\\pgfpathlineto{\\pgfpoint{+1\\pgfplotmarksize}{-0.3\\pgfplotmarksize}}@");
923 PrintStr(
"\\pgfpathlineto{\\pgfpoint{+0.3\\pgfplotmarksize}{-0.3\\pgfplotmarksize}}@");
924 PrintStr(
"\\pgfpathlineto{\\pgfpoint{+0.3\\pgfplotmarksize}{-1.\\pgfplotmarksize}}@");
925 PrintStr(
"\\pgfpathlineto{\\pgfpoint{-0.3\\pgfplotmarksize}{-1.\\pgfplotmarksize}}@");
926 PrintStr(
"\\pgfpathlineto{\\pgfpoint{-0.3\\pgfplotmarksize}{-0.3\\pgfplotmarksize}}@");
927 PrintStr(
"\\pgfpathlineto{\\pgfpoint{-1.\\pgfplotmarksize}{-0.3\\pgfplotmarksize}}@");
928 PrintStr(
"\\pgfpathlineto{\\pgfpoint{-1.\\pgfplotmarksize}{0.3\\pgfplotmarksize}}@");
929 PrintStr(
"\\pgfpathlineto{\\pgfpoint{-0.3\\pgfplotmarksize}{0.3\\pgfplotmarksize}}@");
930 PrintStr(
"\\pgfpathclose@");
931 PrintStr(
"\\pgfusepathqstroke@");
935 PrintStr(
"\\pgfdeclareplotmark{cross*} {@");
936 PrintStr(
"\\pgfpathmoveto{\\pgfpoint{-0.3\\pgfplotmarksize}{\\pgfplotmarksize}}@");
937 PrintStr(
"\\pgfpathlineto{\\pgfpoint{+0.3\\pgfplotmarksize}{\\pgfplotmarksize}}@");
938 PrintStr(
"\\pgfpathlineto{\\pgfpoint{+0.3\\pgfplotmarksize}{0.3\\pgfplotmarksize}}@");
939 PrintStr(
"\\pgfpathlineto{\\pgfpoint{+1\\pgfplotmarksize}{0.3\\pgfplotmarksize}}@");
940 PrintStr(
"\\pgfpathlineto{\\pgfpoint{+1\\pgfplotmarksize}{-0.3\\pgfplotmarksize}}@");
941 PrintStr(
"\\pgfpathlineto{\\pgfpoint{+0.3\\pgfplotmarksize}{-0.3\\pgfplotmarksize}}@");
942 PrintStr(
"\\pgfpathlineto{\\pgfpoint{+0.3\\pgfplotmarksize}{-1.\\pgfplotmarksize}}@");
943 PrintStr(
"\\pgfpathlineto{\\pgfpoint{-0.3\\pgfplotmarksize}{-1.\\pgfplotmarksize}}@");
944 PrintStr(
"\\pgfpathlineto{\\pgfpoint{-0.3\\pgfplotmarksize}{-0.3\\pgfplotmarksize}}@");
945 PrintStr(
"\\pgfpathlineto{\\pgfpoint{-1.\\pgfplotmarksize}{-0.3\\pgfplotmarksize}}@");
946 PrintStr(
"\\pgfpathlineto{\\pgfpoint{-1.\\pgfplotmarksize}{0.3\\pgfplotmarksize}}@");
947 PrintStr(
"\\pgfpathlineto{\\pgfpoint{-0.3\\pgfplotmarksize}{0.3\\pgfplotmarksize}}@");
948 PrintStr(
"\\pgfpathclose@");
949 PrintStr(
"\\pgfusepathqfillstroke@");
953 PrintStr(
"\\pgfdeclareplotmark{newstar} {@");
954 PrintStr(
"\\pgfpathmoveto{\\pgfqpoint{0pt}{\\pgfplotmarksize}}@");
955 PrintStr(
"\\pgfpathlineto{\\pgfqpointpolar{44}{0.5\\pgfplotmarksize}}@");
956 PrintStr(
"\\pgfpathlineto{\\pgfqpointpolar{18}{\\pgfplotmarksize}}@");
957 PrintStr(
"\\pgfpathlineto{\\pgfqpointpolar{-20}{0.5\\pgfplotmarksize}}@");
958 PrintStr(
"\\pgfpathlineto{\\pgfqpointpolar{-54}{\\pgfplotmarksize}}@");
959 PrintStr(
"\\pgfpathlineto{\\pgfqpointpolar{-90}{0.5\\pgfplotmarksize}}@");
960 PrintStr(
"\\pgfpathlineto{\\pgfqpointpolar{234}{\\pgfplotmarksize}}@");
961 PrintStr(
"\\pgfpathlineto{\\pgfqpointpolar{198}{0.5\\pgfplotmarksize}}@");
962 PrintStr(
"\\pgfpathlineto{\\pgfqpointpolar{162}{\\pgfplotmarksize}}@");
963 PrintStr(
"\\pgfpathlineto{\\pgfqpointpolar{134}{0.5\\pgfplotmarksize}}@");
964 PrintStr(
"\\pgfpathclose@");
965 PrintStr(
"\\pgfusepathqstroke@");
969 PrintStr(
"\\pgfdeclareplotmark{newstar*} {@");
970 PrintStr(
"\\pgfpathmoveto{\\pgfqpoint{0pt}{\\pgfplotmarksize}}@");
971 PrintStr(
"\\pgfpathlineto{\\pgfqpointpolar{44}{0.5\\pgfplotmarksize}}@");
972 PrintStr(
"\\pgfpathlineto{\\pgfqpointpolar{18}{\\pgfplotmarksize}}@");
973 PrintStr(
"\\pgfpathlineto{\\pgfqpointpolar{-20}{0.5\\pgfplotmarksize}}@");
974 PrintStr(
"\\pgfpathlineto{\\pgfqpointpolar{-54}{\\pgfplotmarksize}}@");
975 PrintStr(
"\\pgfpathlineto{\\pgfqpointpolar{-90}{0.5\\pgfplotmarksize}}@");
976 PrintStr(
"\\pgfpathlineto{\\pgfqpointpolar{234}{\\pgfplotmarksize}}@");
977 PrintStr(
"\\pgfpathlineto{\\pgfqpointpolar{198}{0.5\\pgfplotmarksize}}@");
978 PrintStr(
"\\pgfpathlineto{\\pgfqpointpolar{162}{\\pgfplotmarksize}}@");
979 PrintStr(
"\\pgfpathlineto{\\pgfqpointpolar{134}{0.5\\pgfplotmarksize}}@");
980 PrintStr(
"\\pgfpathclose@");
981 PrintStr(
"\\pgfusepathqfillstroke@");