Logo ROOT   6.08/07
Reference Guide
TTeXDump.cxx
Go to the documentation of this file.
1 // @(#)root/postscript:$Id$
2 // Author: Olivier Couet
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifdef WIN32
13 #pragma optimize("",off)
14 #endif
15 
16 #include <stdlib.h>
17 #include <string.h>
18 #include <ctype.h>
19 
20 #include "Riostream.h"
21 #include "TROOT.h"
22 #include "TColor.h"
23 #include "TVirtualPad.h"
24 #include "TPoints.h"
25 #include "TTeXDump.h"
26 #include "TStyle.h"
27 #include "TMath.h"
28 #include "TObjString.h"
29 #include "TObjArray.h"
30 #include "TClass.h"
31 
33 
34 /** \class TTeXDump
35 \ingroup PS
36 
37 Interface to TeX.
38 
39 This class allow to generate <b>PGF/TikZ</b> vector graphics output
40 which can be included in TeX and LaTeX documents.
41 
42 PGF is a TeX macro package for generating graphics. It is platform
43 and format-independent and works together with the most important TeX
44 backend drivers, including pdftex and dvips. It comes with a
45 user-friendly syntax layer called TikZ.
46 
47 To generate a such file it is enough to do:
48 ~~~ {.cpp}
49  gStyle->SetPaperSize(10.,10.);
50  hpx->Draw();
51  gPad->Print("hpx.tex");
52 ~~~
53 
54 Then, the generated file (`hpx.tex`) can be included in a
55 LaTeX document (`simple.tex`) in the following way:
56 ~~~ {.cpp}
57 \documentclass{article}
58 \usepackage{tikz}
59 \usetikzlibrary{patterns}
60 \usetikzlibrary{plotmarks}
61 \title{A simple LaTeX example}
62 \date{July 2013}
63 \begin{document}
64 \maketitle
65 The following image as been generated using the TTeXDump class:
66 \par
67 \input{hpx.tex}
68 \end{document}
69 ~~~
70 
71 Note the three directives needed at the top of the LaTeX file:
72 ~~~ {.cpp}
73 \usepackage{tikz}
74 \usetikzlibrary{patterns}
75 \usetikzlibrary{plotmarks}
76 ~~~
77 
78 Then including the picture in the document is done with the
79 `\input` directive.
80 
81  The command `pdflatex simple.tex` will generate the
82 corresponding pdf file `simple.pdf`.
83 */
84 
85 ////////////////////////////////////////////////////////////////////////////////
86 /// Default TeX constructor
87 
89 {
90  fStream = 0;
91  fType = 0;
92  gVirtualPS = this;
93  fBoundingBox = kFALSE;
94  fRange = kFALSE;
95  fXsize = 0.;
96  fYsize = 0.;
97  fCurrentRed = -1.;
98  fCurrentGreen = -1.;
99  fCurrentBlue = -1.;
100  fCurrentAlpha = 1.;
101  fLineScale = 0.;
102 }
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 /// Initialize the TeX interface
106 ///
107 /// --fname : TeX file name
108 /// - wtype : TeX workstation type. Not used in the TeX driver. But as TTeXDump
109 /// inherits from TVirtualPS it should be kept. Anyway it is not
110 /// necessary to specify this parameter at creation time because it
111 /// has a default value (which is ignore in the TeX case).
112 
113 TTeXDump::TTeXDump(const char *fname, Int_t wtype) : TVirtualPS(fname, wtype)
114 {
115  fStream = 0;
116  fType = 0;
117  gVirtualPS = this;
119  fRange = kFALSE;
120  fXsize = 0.;
121  fYsize = 0.;
122  fCurrentRed = -1.;
123  fCurrentGreen = -1.;
124  fCurrentBlue = -1.;
125  fCurrentAlpha = 1.;
126  fLineScale = 0.;
127 
128  Open(fname, wtype);
129 }
130 
131 ////////////////////////////////////////////////////////////////////////////////
132 /// Open a TeX file
133 
134 void TTeXDump::Open(const char *fname, Int_t wtype)
135 {
136  if (fStream) {
137  Warning("Open", "TeX file already open");
138  return;
139  }
140 
142  fLenBuffer = 0;
143  fType = abs(wtype);
144 
146 
147  Float_t xrange, yrange;
148  if (gPad) {
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;
154  xrange = fXsize;
155  yrange = fXsize*ratio;
156  if (yrange > fYsize) { yrange = fYsize; xrange = yrange/ratio;}
157  fXsize = xrange; fYsize = yrange;
158  }
159 
160  // Open OS file
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;
165  }
166 
167  gVirtualPS = this;
168 
169  for (Int_t i=0;i<fSizBuffer;i++) fBuffer[i] = ' ';
170 
172  fRange = kFALSE;
173 
174  // Set a default range
175  Range(fXsize, fYsize);
176 
177  NewPage();
178 }
179 
180 ////////////////////////////////////////////////////////////////////////////////
181 /// Default TeX destructor
182 
184 {
185  Close();
186 }
187 
188 ////////////////////////////////////////////////////////////////////////////////
189 /// Close a TeX file
190 
192 {
193  if (!gVirtualPS) return;
194  if (!fStream) return;
195  if (gPad) gPad->Update();
196  PrintStr("@");
197  PrintStr("\\end{tikzpicture}@");
198 
199  // Close file stream
200  if (fStream) { fStream->close(); delete fStream; fStream = 0;}
201 
202  gVirtualPS = 0;
203 }
204 
205 ////////////////////////////////////////////////////////////////////////////////
206 /// Activate an already open TeX file
207 
209 {
210  // fType is used to know if the TeX file is open. Unlike TPostScript, TTeXDump
211  // has no "workstation type". In fact there is only one TeX type.
212 
213  if (!fType) {
214  Error("On", "no TeX file open");
215  Off();
216  return;
217  }
218  gVirtualPS = this;
219 }
220 
221 ////////////////////////////////////////////////////////////////////////////////
222 /// Deactivate an already open TeX file
223 
225 {
226  gVirtualPS = 0;
227 }
228 
229 ////////////////////////////////////////////////////////////////////////////////
230 /// Draw a Box
231 
233 {
234  Float_t x1c = XtoTeX(x1);
235  Float_t y1c = YtoTeX(y1);
236  Float_t x2c = XtoTeX(x2);
237  Float_t y2c = YtoTeX(y2);
238 
239  Int_t fillis = fFillStyle/1000;
240  Int_t fillsi = fFillStyle%1000;
241 
242  if (fillis==1) {
244  PrintStr("@");
245  PrintStr("\\draw [color=c, fill=c");
246  if (fCurrentAlpha != 1.) {
247  PrintStr(", fill opacity=");
249  }
250  PrintStr("] (");
251  WriteReal(x1c, kFALSE);
252  PrintFast(1,",");
253  WriteReal(y1c, kFALSE);
254  PrintStr(") rectangle (");
255  WriteReal(x2c, kFALSE);
256  PrintFast(1,",");
257  WriteReal(y2c, kFALSE);
258  PrintStr(");");
259  }
260  if (fillis>1 && fillis<4) {
262  PrintStr("@");
263  PrintStr("\\draw [pattern=");
264  switch (fillsi) {
265  case 1 :
266  PrintStr("crosshatch dots");
267  break;
268  case 2 :
269  case 3 :
270  PrintStr("dots");
271  break;
272  case 4 :
273  PrintStr("north east lines");
274  break;
275  case 5 :
276  PrintStr("north west lines");
277  break;
278  case 6 :
279  PrintStr("vertical lines");
280  break;
281  case 7 :
282  PrintStr("horizontal lines");
283  break;
284  case 10 :
285  PrintStr("bricks");
286  break;
287  case 13 :
288  PrintStr("crosshatch");
289  break;
290  }
291  PrintStr(", draw opacity=0, pattern color=c");
292  if (fCurrentAlpha != 1.) {
293  PrintStr(", fill opacity=");
295  }
296  PrintStr("] (");
297  WriteReal(x1c, kFALSE);
298  PrintFast(1,",");
299  WriteReal(y1c, kFALSE);
300  PrintStr(") rectangle (");
301  WriteReal(x2c, kFALSE);
302  PrintFast(1,",");
303  WriteReal(y2c, kFALSE);
304  PrintStr(");");
305  }
306  if (fillis == 0) {
307  if (fLineWidth<=0) return;
309  PrintStr("@");
310  PrintStr("\\draw [c");
311  PrintStr(",line width=");
313  if (fCurrentAlpha != 1.) {
314  PrintStr(", opacity=");
316  }
317  PrintStr("] (");
318  WriteReal(x1c, kFALSE);
319  PrintFast(1,",");
320  WriteReal(y1c, kFALSE);
321  PrintStr(") -- (");
322  WriteReal(x1c, kFALSE);
323  PrintFast(1,",");
324  WriteReal(y2c, kFALSE);
325  PrintStr(") -- (");
326  WriteReal(x2c, kFALSE);
327  PrintFast(1,",");
328  WriteReal(y2c, kFALSE);
329  PrintStr(") -- (");
330  WriteReal(x2c, kFALSE);
331  PrintFast(1,",");
332  WriteReal(y1c, kFALSE);
333  PrintStr(") -- (");
334  WriteReal(x1c, kFALSE);
335  PrintFast(1,",");
336  WriteReal(y1c, kFALSE);
337  PrintStr(");");
338  }
339 }
340 
341 ////////////////////////////////////////////////////////////////////////////////
342 /// Draw a Frame around a box
343 ///
344 /// mode = -1 the box looks as it is behind the screen
345 /// mode = 1 the box looks as it is in front of the screen
346 /// border is the border size in already pre-computed TeX units dark is the
347 /// color for the dark part of the frame light is the color for the light
348 /// part of the frame
349 
351  Int_t, Int_t, Int_t, Int_t)
352 {
353  Warning("DrawFrame", "not yet implemented");
354 }
355 
356 ////////////////////////////////////////////////////////////////////////////////
357 /// Draw a PolyLine
358 ///
359 /// Draw a polyline through the points xy.
360 /// - If NN=1 moves only to point x,y.
361 /// - If NN=0 the x,y are written in the TeX file
362 /// according to the current transformation.
363 /// - If NN>0 the line is clipped as a line.
364 /// - If NN<0 the line is clipped as a fill area.
365 
367 {
368  Warning("DrawPolyLine", "not yet implemented");
369 }
370 
371 ////////////////////////////////////////////////////////////////////////////////
372 /// Draw a PolyLine in NDC space
373 ///
374 /// Draw a polyline through the points xy.
375 /// - If NN=1 moves only to point x,y.
376 /// - If NN=0 the x,y are written in the TeX file
377 /// according to the current transformation.
378 /// - If NN>0 the line is clipped as a line.
379 /// - If NN<0 the line is clipped as a fill area.
380 
382 {
383  Warning("DrawPolyLineNDC", "not yet implemented");
384 }
385 
386 ////////////////////////////////////////////////////////////////////////////////
387 /// Paint PolyMarker
388 
390 {
391  Warning("DrawPolyMarker", "not yet implemented");
392 }
393 
394 ////////////////////////////////////////////////////////////////////////////////
395 /// Paint PolyMarker
396 
398 {
399  Float_t x, y;
400 
402 
403  PrintStr("@");
404  PrintStr("\\foreach \\P in {");
405 
406  x = XtoTeX(xw[0]);
407  y = YtoTeX(yw[0]);
408 
409  PrintStr("(");
410  WriteReal(x, kFALSE);
411  PrintFast(1,",");
412  WriteReal(y, kFALSE);
413  PrintStr(")");
414 
415  for (Int_t i=1;i<n;i++) {
416  x = XtoTeX(xw[i]);
417  y = YtoTeX(yw[i]);
418  PrintFast(3,", (");
419  WriteReal(x, kFALSE);
420  PrintFast(1,",");
421  WriteReal(y, kFALSE);
422  PrintFast(1,")");
423  }
424 
425  if (fMarkerStyle == 23 || fMarkerStyle == 32) {
426  PrintStr("}{\\draw[mark options={color=c,fill=c,rotate=180},mark size=");
427  } else {
428  PrintStr("}{\\draw[mark options={color=c,fill=c},mark size=");
429  }
430  PrintStr(Form("%fpt,mark=",8./3.33*fMarkerSize));
431  switch (fMarkerStyle) {
432  case 1 :
433  PrintStr("*");
434  PrintStr(",mark size=1pt");
435  break;
436  case 2 :
437  PrintStr("+");
438  break;
439  case 3 :
440  PrintStr("asterisk");
441  break;
442  case 4 :
443  PrintStr("o");
444  break;
445  case 5 :
446  PrintStr("x");
447  break;
448  case 20 :
449  PrintStr("*");
450  break;
451  case 21 :
452  PrintStr("square*");
453  break;
454  case 22 :
455  PrintStr("triangle*");
456  break;
457  case 23 :
458  PrintStr("triangle*");
459  break;
460  case 24 :
461  PrintStr("o");
462  break;
463  case 25 :
464  PrintStr("square");
465  break;
466  case 26 :
467  PrintStr("triangle");
468  break;
469  case 27 :
470  PrintStr("diamond");
471  break;
472  case 28 :
473  PrintStr("cross");
474  break;
475  case 29 :
476  PrintStr("newstar*");
477  break;
478  case 30 :
479  PrintStr("newstar");
480  break;
481  case 31 :
482  PrintStr("10-pointed star");
483  break;
484  case 32 :
485  PrintStr("triangle");
486  break;
487  case 33 :
488  PrintStr("diamond*");
489  break;
490  case 34 :
491  PrintStr("cross*");
492  break;
493  }
494  PrintStr("] plot coordinates {\\P};}");
495 }
496 
497 ////////////////////////////////////////////////////////////////////////////////
498 /// This function defines a path with xw and yw and draw it according the
499 /// value of nn:
500 ///
501 /// - If nn>0 a line is drawn.
502 /// - If nn<0 a closed polygon is drawn.
503 
505 {
506  Int_t n = TMath::Abs(nn);;
507  Float_t x, y;
508 
509  if( n <= 1) {
510  Error("DrawPS", "Two points are needed");
511  return;
512  }
513 
514  x = XtoTeX(xw[0]);
515  y = YtoTeX(yw[0]);
516 
517  Int_t fillis = fFillStyle/1000;
518  Int_t fillsi = fFillStyle%1000;
519 
520  if (nn>0) {
521  if (fLineWidth<=0) return;
523  PrintStr("@");
524  PrintStr("\\draw [c");
526  TString tikzSpec;
527  TString stripped = TString{spec.Strip(TString::kBoth)};
528  if (stripped.Length()) {
529  tikzSpec.Append(",dash pattern=");
530  Ssiz_t i{0}, j{0};
531  bool on{true}, iterate{true};
532 
533  while (iterate){
534  j = stripped.Index(" ", 1, i, TString::kExact);
535  if (j == kNPOS){
536  iterate = false;
537  j = stripped.Length();
538  }
539 
540  if (on) {
541  tikzSpec.Append("on ");
542  on = false;
543  } else {
544  tikzSpec.Append("off ");
545  on = true;
546  }
547  int num = TString{stripped(i, j - i)}.Atoi();
548  float pt = 0.2*num;
549  tikzSpec.Append(TString::Format("%.2fpt ", pt));
550  i = j + 1;
551  }
552  PrintStr(tikzSpec.Data());
553  }
554  PrintStr(",line width=");
556  } else {
558  if (fillis==1) {
559  PrintStr("@");
560  PrintStr("\\draw [c, fill=c");
561  } else if (fillis==0) {
562  PrintStr("@");
563  PrintStr("\\draw [c");
564  } else {
565  PrintStr("\\draw [pattern=");
566  switch (fillsi) {
567  case 1 :
568  PrintStr("crosshatch dots");
569  break;
570  case 2 :
571  case 3 :
572  PrintStr("dots");
573  break;
574  case 4 :
575  PrintStr("north east lines");
576  break;
577  case 5 :
578  PrintStr("north west lines");
579  break;
580  case 6 :
581  PrintStr("vertical lines");
582  break;
583  case 7 :
584  PrintStr("horizontal lines");
585  break;
586  case 10 :
587  PrintStr("bricks");
588  break;
589  case 13 :
590  PrintStr("crosshatch");
591  break;
592  }
593  PrintStr(", draw opacity=0, pattern color=c");
594  }
595  if (fCurrentAlpha != 1.) {
596  PrintStr(", fill opacity=");
598  }
599  }
600  PrintStr("] (");
601  WriteReal(x, kFALSE);
602  PrintFast(1,",");
603  WriteReal(y, kFALSE);
604  PrintStr(") -- ");
605 
606  for (Int_t i=1;i<n;i++) {
607  x = XtoTeX(xw[i]);
608  y = YtoTeX(yw[i]);
609  PrintFast(1,"(");
610  WriteReal(x, kFALSE);
611  PrintFast(1,",");
612  WriteReal(y, kFALSE);
613  PrintFast(1,")");
614  if (i<n-1) PrintStr(" -- ");
615  else PrintStr(";@");
616  }
617 }
618 
619 ////////////////////////////////////////////////////////////////////////////////
620 /// Start the TeX page. This function starts the tikzpicture environment
621 
623 {
624  // Compute pad conversion coefficients
625  if (gPad) {
626  Double_t ww = gPad->GetWw();
627  Double_t wh = gPad->GetWh();
628  fYsize = fXsize*wh/ww;
629  } else {
630  fYsize = 27;
631  }
632 
633  if(!fBoundingBox) {
634  PrintStr("\\begin{tikzpicture}@");
635  DefineMarkers();
637  }
638 }
639 
640 ////////////////////////////////////////////////////////////////////////////////
641 /// Set the range for the paper in centimetres
642 
643 void TTeXDump::Range(Float_t xsize, Float_t ysize)
644 {
645  fXsize = xsize;
646  fYsize = ysize;
647 
648  fRange = kTRUE;
649 }
650 
651 ////////////////////////////////////////////////////////////////////////////////
652 /// Set color index for fill areas
653 
655 {
656  fFillColor = cindex;
657  if (gStyle->GetFillColor() <= 0) cindex = 0;
658 }
659 
660 ////////////////////////////////////////////////////////////////////////////////
661 /// Set color index for lines
662 
664 {
665  fLineColor = cindex;
666 }
667 
668 ////////////////////////////////////////////////////////////////////////////////
669 /// Change the line style
670 ///
671 /// - linestyle = 2 dashed
672 /// - linestyle = 3 dotted
673 /// - linestyle = 4 dash-dotted
674 /// - linestyle = else solid (1 in is used most of the time)
675 
677 {
678  fLineStyle = linestyle;
679 }
680 
681 ////////////////////////////////////////////////////////////////////////////////
682 /// Set the lines width.
683 
685 {
686  fLineWidth = linewidth;
687 }
688 
689 ////////////////////////////////////////////////////////////////////////////////
690 /// Set size for markers.
691 
693 {
694  fMarkerSize = msize;
695 }
696 
697 ////////////////////////////////////////////////////////////////////////////////
698 /// Set color index for markers.
699 
701 {
702  fMarkerColor = cindex;
703 }
704 
705 ////////////////////////////////////////////////////////////////////////////////
706 /// Set color with its color index
707 
709 {
710  if (color < 0) color = 0;
711 
712  TColor *col = gROOT->GetColor(color);
713  if (col) SetColor(col->GetRed(), col->GetGreen(), col->GetBlue());
714  else SetColor(1., 1., 1.);
715  fCurrentAlpha = col->GetAlpha();
716 }
717 
718 ////////////////////////////////////////////////////////////////////////////////
719 /// Set color with its R G B components
720 ///
721 /// - r: % of red in [0,1]
722 /// - g: % of green in [0,1]
723 /// - b: % of blue in [0,1]
724 
726 {
727  if (fCurrentRed == r && fCurrentGreen == g && fCurrentBlue == b) return;
728 
729  fCurrentRed = r;
730  fCurrentGreen = g;
731  fCurrentBlue = b;
732  PrintStr("@");
733  PrintStr("\\definecolor{c}{rgb}{");
734  WriteReal(r, kFALSE);
735  PrintFast(1,",");
736  WriteReal(g, kFALSE);
737  PrintFast(1,",");
738  WriteReal(b, kFALSE);
739  PrintFast(2,"};");
740 }
741 
742 ////////////////////////////////////////////////////////////////////////////////
743 /// Set color index for text
744 
746 {
747  fTextColor = cindex;
748 }
749 
750 ////////////////////////////////////////////////////////////////////////////////
751 /// Draw text
752 ///
753 /// - xx: x position of the text
754 /// - yy: y position of the text
755 /// - chars: text to be drawn
756 
757 void TTeXDump::Text(Double_t x, Double_t y, const char *chars)
758 {
759  Double_t wh = (Double_t)gPad->XtoPixel(gPad->GetX2());
760  Double_t hh = (Double_t)gPad->YtoPixel(gPad->GetY1());
761  Float_t tsize, ftsize;
762  if (wh < hh) {
763  tsize = fTextSize*wh;
764  Int_t sizeTTF = (Int_t)(tsize+0.5);
765  ftsize = (sizeTTF*fXsize*gPad->GetAbsWNDC())/wh;
766  } else {
767  tsize = fTextSize*hh;
768  Int_t sizeTTF = (Int_t)(tsize+0.5);
769  ftsize = (sizeTTF*fYsize*gPad->GetAbsHNDC())/hh;
770  }
771  ftsize *= 2.22097;
772  if (ftsize <= 0) return;
773 
774  TString t(chars);
775  if (t.Index("\\")>=0 || t.Index("^{")>=0 || t.Index("_{")>=0) {
776  t.Prepend("$");
777  t.Append("$");
778  } else {
779  t.ReplaceAll("<","$<$");
780  t.ReplaceAll(">","$>$");
781  t.ReplaceAll("_","\\_");
782  }
783  t.ReplaceAll("&","\\&");
784  t.ReplaceAll("#","\\#");
785  t.ReplaceAll("%","\\%");
786 
787  Int_t txalh = fTextAlign/10;
788  if (txalh <1) txalh = 1; else if (txalh > 3) txalh = 3;
789  Int_t txalv = fTextAlign%10;
790  if (txalv <1) txalv = 1; else if (txalv > 3) txalv = 3;
792  PrintStr("@");
793  PrintStr("\\draw");
794  if (txalh!=2 || txalv!=2) {
795  PrintStr(" [anchor=");
796  if (txalv==1) PrintStr("base");
797  if (txalv==3) PrintStr("north");
798  if (txalh==1) PrintStr(" west");
799  if (txalh==3) PrintStr(" east");
800  PrintFast(1,"]");
801  }
802  PrintFast(2," (");
803  WriteReal(XtoTeX(x), kFALSE);
804  PrintFast(1,",");
805  WriteReal(YtoTeX(y), kFALSE);
806  PrintStr(") node[scale=");
807  WriteReal(ftsize, kFALSE);
808  PrintStr(", color=c, rotate=");
810  PrintFast(2,"]{");
811  PrintStr(t.Data());
812  PrintFast(2,"};");
813 }
814 
815 ////////////////////////////////////////////////////////////////////////////////
816 /// Write a string of characters in NDC
817 
818 void TTeXDump::TextNDC(Double_t u, Double_t v, const char *chars)
819 {
820  Double_t x = gPad->GetX1() + u*(gPad->GetX2() - gPad->GetX1());
821  Double_t y = gPad->GetY1() + v*(gPad->GetY2() - gPad->GetY1());
822  Text(x, y, chars);
823 }
824 
825 ////////////////////////////////////////////////////////////////////////////////
826 /// Convert U from NDC coordinate to TeX
827 
829 {
830  Double_t cm = fXsize*(gPad->GetAbsXlowNDC() + u*gPad->GetAbsWNDC());
831  return cm;
832 }
833 
834 ////////////////////////////////////////////////////////////////////////////////
835 /// Convert V from NDC coordinate to TeX
836 
838 {
839  Double_t cm = fYsize*(gPad->GetAbsYlowNDC() + v*gPad->GetAbsHNDC());
840  return cm;
841 }
842 
843 ////////////////////////////////////////////////////////////////////////////////
844 /// Convert X from world coordinate to TeX
845 
847 {
848  Double_t u = (x - gPad->GetX1())/(gPad->GetX2() - gPad->GetX1());
849  return UtoTeX(u);
850 }
851 
852 ////////////////////////////////////////////////////////////////////////////////
853 /// Convert Y from world coordinate to TeX
854 
856 {
857  Double_t v = (y - gPad->GetY1())/(gPad->GetY2() - gPad->GetY1());
858  return VtoTeX(v);
859 }
860 
861 ////////////////////////////////////////////////////////////////////////////////
862 /// Begin the Cell Array painting
863 
865  Double_t)
866 {
867  Warning("CellArrayBegin", "not yet implemented");
868 }
869 
870 ////////////////////////////////////////////////////////////////////////////////
871 /// Paint the Cell Array
872 
874 {
875  Warning("CellArrayFill", "not yet implemented");
876 }
877 
878 ////////////////////////////////////////////////////////////////////////////////
879 /// End the Cell Array painting
880 
882 {
883  Warning("CellArrayEnd", "not yet implemented");
884 }
885 
886 ////////////////////////////////////////////////////////////////////////////////
887 /// Not needed in TeX case
888 
890 {
891  Warning("DrawPS", "not yet implemented");
892 }
893 
894 ////////////////////////////////////////////////////////////////////////////////
895 /// add additional pgfplotmarks
896 
898 {
899  // open cross
900  PrintStr("\\pgfdeclareplotmark{cross} {@");
901  PrintStr("\\pgfpathmoveto{\\pgfpoint{-0.3\\pgfplotmarksize}{\\pgfplotmarksize}}@");
902  PrintStr("\\pgfpathlineto{\\pgfpoint{+0.3\\pgfplotmarksize}{\\pgfplotmarksize}}@");
903  PrintStr("\\pgfpathlineto{\\pgfpoint{+0.3\\pgfplotmarksize}{0.3\\pgfplotmarksize}}@");
904  PrintStr("\\pgfpathlineto{\\pgfpoint{+1\\pgfplotmarksize}{0.3\\pgfplotmarksize}}@");
905  PrintStr("\\pgfpathlineto{\\pgfpoint{+1\\pgfplotmarksize}{-0.3\\pgfplotmarksize}}@");
906  PrintStr("\\pgfpathlineto{\\pgfpoint{+0.3\\pgfplotmarksize}{-0.3\\pgfplotmarksize}}@");
907  PrintStr("\\pgfpathlineto{\\pgfpoint{+0.3\\pgfplotmarksize}{-1.\\pgfplotmarksize}}@");
908  PrintStr("\\pgfpathlineto{\\pgfpoint{-0.3\\pgfplotmarksize}{-1.\\pgfplotmarksize}}@");
909  PrintStr("\\pgfpathlineto{\\pgfpoint{-0.3\\pgfplotmarksize}{-0.3\\pgfplotmarksize}}@");
910  PrintStr("\\pgfpathlineto{\\pgfpoint{-1.\\pgfplotmarksize}{-0.3\\pgfplotmarksize}}@");
911  PrintStr("\\pgfpathlineto{\\pgfpoint{-1.\\pgfplotmarksize}{0.3\\pgfplotmarksize}}@");
912  PrintStr("\\pgfpathlineto{\\pgfpoint{-0.3\\pgfplotmarksize}{0.3\\pgfplotmarksize}}@");
913  PrintStr("\\pgfpathclose@");
914  PrintStr("\\pgfusepathqstroke@");
915  PrintStr("}@");
916 
917  // filled cross
918  PrintStr("\\pgfdeclareplotmark{cross*} {@");
919  PrintStr("\\pgfpathmoveto{\\pgfpoint{-0.3\\pgfplotmarksize}{\\pgfplotmarksize}}@");
920  PrintStr("\\pgfpathlineto{\\pgfpoint{+0.3\\pgfplotmarksize}{\\pgfplotmarksize}}@");
921  PrintStr("\\pgfpathlineto{\\pgfpoint{+0.3\\pgfplotmarksize}{0.3\\pgfplotmarksize}}@");
922  PrintStr("\\pgfpathlineto{\\pgfpoint{+1\\pgfplotmarksize}{0.3\\pgfplotmarksize}}@");
923  PrintStr("\\pgfpathlineto{\\pgfpoint{+1\\pgfplotmarksize}{-0.3\\pgfplotmarksize}}@");
924  PrintStr("\\pgfpathlineto{\\pgfpoint{+0.3\\pgfplotmarksize}{-0.3\\pgfplotmarksize}}@");
925  PrintStr("\\pgfpathlineto{\\pgfpoint{+0.3\\pgfplotmarksize}{-1.\\pgfplotmarksize}}@");
926  PrintStr("\\pgfpathlineto{\\pgfpoint{-0.3\\pgfplotmarksize}{-1.\\pgfplotmarksize}}@");
927  PrintStr("\\pgfpathlineto{\\pgfpoint{-0.3\\pgfplotmarksize}{-0.3\\pgfplotmarksize}}@");
928  PrintStr("\\pgfpathlineto{\\pgfpoint{-1.\\pgfplotmarksize}{-0.3\\pgfplotmarksize}}@");
929  PrintStr("\\pgfpathlineto{\\pgfpoint{-1.\\pgfplotmarksize}{0.3\\pgfplotmarksize}}@");
930  PrintStr("\\pgfpathlineto{\\pgfpoint{-0.3\\pgfplotmarksize}{0.3\\pgfplotmarksize}}@");
931  PrintStr("\\pgfpathclose@");
932  PrintStr("\\pgfusepathqfillstroke@");
933  PrintStr("}@");
934 
935  // open star
936  PrintStr("\\pgfdeclareplotmark{newstar} {@");
937  PrintStr("\\pgfpathmoveto{\\pgfqpoint{0pt}{\\pgfplotmarksize}}@");
938  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{44}{0.5\\pgfplotmarksize}}@");
939  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{18}{\\pgfplotmarksize}}@");
940  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{-20}{0.5\\pgfplotmarksize}}@");
941  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{-54}{\\pgfplotmarksize}}@");
942  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{-90}{0.5\\pgfplotmarksize}}@");
943  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{234}{\\pgfplotmarksize}}@");
944  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{198}{0.5\\pgfplotmarksize}}@");
945  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{162}{\\pgfplotmarksize}}@");
946  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{134}{0.5\\pgfplotmarksize}}@");
947  PrintStr("\\pgfpathclose@");
948  PrintStr("\\pgfusepathqstroke@");
949  PrintStr("}@");
950 
951  // filled star
952  PrintStr("\\pgfdeclareplotmark{newstar*} {@");
953  PrintStr("\\pgfpathmoveto{\\pgfqpoint{0pt}{\\pgfplotmarksize}}@");
954  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{44}{0.5\\pgfplotmarksize}}@");
955  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{18}{\\pgfplotmarksize}}@");
956  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{-20}{0.5\\pgfplotmarksize}}@");
957  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{-54}{\\pgfplotmarksize}}@");
958  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{-90}{0.5\\pgfplotmarksize}}@");
959  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{234}{\\pgfplotmarksize}}@");
960  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{198}{0.5\\pgfplotmarksize}}@");
961  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{162}{\\pgfplotmarksize}}@");
962  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{134}{0.5\\pgfplotmarksize}}@");
963  PrintStr("\\pgfpathclose@");
964  PrintStr("\\pgfusepathqfillstroke@");
965  PrintStr("}@");
966 }
void CellArrayBegin(Int_t W, Int_t H, Double_t x1, Double_t x2, Double_t y1, Double_t y2)
Begin the Cell Array painting.
Definition: TTeXDump.cxx:864
void Close(Option_t *opt="")
Close a TeX file.
Definition: TTeXDump.cxx:191
Float_t GetLineScalePS() const
Definition: TStyle.h:288
char * fBuffer
Definition: TVirtualPS.h:52
int iterate(rng_state_t *X)
Definition: mixmax.icc:34
void DrawPolyLine(Int_t n, TPoints *xy)
Draw a PolyLine.
Definition: TTeXDump.cxx:366
void SetMarkerSize(Size_t msize=1)
Set size for markers.
Definition: TTeXDump.cxx:692
Float_t GetRed() const
Definition: TColor.h:60
short Style_t
Definition: RtypesCore.h:76
Float_t fCurrentRed
Current Red component.
Definition: TTeXDump.h:30
float Float_t
Definition: RtypesCore.h:53
float Size_t
Definition: RtypesCore.h:83
const char Option_t
Definition: RtypesCore.h:62
void SetLineColor(Color_t cindex=1)
Set color index for lines.
Definition: TTeXDump.cxx:663
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
Float_t GetAlpha() const
Definition: TColor.h:66
R__EXTERN TStyle * gStyle
Definition: TStyle.h:418
void SetLineStyle(Style_t linestyle=1)
Change the line style.
Definition: TTeXDump.cxx:676
void GetPaperSize(Float_t &xsize, Float_t &ysize) const
Set paper size for PostScript output.
Definition: TStyle.cxx:810
Float_t UtoTeX(Double_t u)
Convert U from NDC coordinate to TeX.
Definition: TTeXDump.cxx:828
Size_t fMarkerSize
Marker size.
Definition: TAttMarker.h:29
Float_t fLineScale
Line width scale factor.
Definition: TTeXDump.h:34
void DrawPS(Int_t n, Float_t *xw, Float_t *yw)
Not needed in TeX case.
Definition: TTeXDump.cxx:889
void DefineMarkers()
add additional pgfplotmarks
Definition: TTeXDump.cxx:897
#define gROOT
Definition: TROOT.h:364
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:582
void Text(Double_t x, Double_t y, const char *string)
Draw text.
Definition: TTeXDump.cxx:757
Basic string class.
Definition: TString.h:137
virtual ~TTeXDump()
Default TeX destructor.
Definition: TTeXDump.cxx:183
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: Rtypes.h:92
Float_t fCurrentAlpha
Current Alpha value.
Definition: TTeXDump.h:33
Float_t VtoTeX(Double_t v)
Convert V from NDC coordinate to TeX.
Definition: TTeXDump.cxx:837
TString & Prepend(const char *cs)
Definition: TString.h:604
Float_t GetBlue() const
Definition: TColor.h:62
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
virtual void WriteReal(Float_t r, Bool_t space=kTRUE)
Write a Real number to the file.
Definition: TVirtualPS.cxx:185
Float_t fCurrentBlue
Current Blue component.
Definition: TTeXDump.h:32
static const double x2[5]
Double_t x[n]
Definition: legend1.C:17
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2335
virtual void PrintStr(const char *string="")
Output the string str in the output buffer.
Definition: TVirtualPS.cxx:72
Float_t GetGreen() const
Definition: TColor.h:61
TString & Append(const char *cs)
Definition: TString.h:492
Float_t fYsize
Page size along Y.
Definition: TTeXDump.h:26
Float_t XtoTeX(Double_t x)
Convert X from world coordinate to TeX.
Definition: TTeXDump.cxx:846
short Color_t
Definition: RtypesCore.h:79
Style_t fMarkerStyle
Marker style.
Definition: TAttMarker.h:28
void Off()
Deactivate an already open TeX file.
Definition: TTeXDump.cxx:224
Float_t fTextAngle
Text angle.
Definition: TAttText.h:27
TTeXDump()
Default TeX constructor.
Definition: TTeXDump.cxx:88
Style_t fLineStyle
Line style.
Definition: TAttLine.h:28
Float_t fXsize
Page size along X.
Definition: TTeXDump.h:25
void Open(const char *filename, Int_t type=-111)
Open a TeX file.
Definition: TTeXDump.cxx:134
TPaveText * pt
TRandom2 r(17)
Float_t fCurrentGreen
Current Green component.
Definition: TTeXDump.h:31
SVector< double, 2 > v
Definition: Dict.h:5
Bool_t fBoundingBox
True when the Tex header is printed.
Definition: TTeXDump.h:28
Int_t fSizBuffer
Definition: TVirtualPS.h:49
void SetFillColor(Color_t cindex=1)
Set color index for fill areas.
Definition: TTeXDump.cxx:654
const char * GetLineStyleString(Int_t i=1) const
Return line style string (used by PostScript).
Definition: TStyle.cxx:792
Color_t fLineColor
Line color.
Definition: TAttLine.h:27
Bool_t fRange
True when a range has been defined.
Definition: TTeXDump.h:29
void NewPage()
Start the TeX page. This function starts the tikzpicture environment.
Definition: TTeXDump.cxx:622
void On()
Activate an already open TeX file.
Definition: TTeXDump.cxx:208
Width_t fLineWidth
Line width.
Definition: TAttLine.h:29
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:925
char * Form(const char *fmt,...)
Float_t YtoTeX(Double_t y)
Convert Y from world coordinate to TeX.
Definition: TTeXDump.cxx:855
Ssiz_t Length() const
Definition: TString.h:390
void SetTextColor(Color_t cindex=1)
Set color index for text.
Definition: TTeXDump.cxx:745
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Definition: TString.cxx:1070
std::ofstream * fStream
Definition: TVirtualPS.h:51
short Width_t
Definition: RtypesCore.h:78
void SetLineScale(Float_t scale=1)
Definition: TTeXDump.h:68
PyObject * fType
int Ssiz_t
Definition: RtypesCore.h:63
2-D graphics point (world coordinates).
Definition: TPoints.h:21
Interface to TeX.
Definition: TTeXDump.h:22
void Range(Float_t xrange, Float_t yrange)
Set the range for the paper in centimetres.
Definition: TTeXDump.cxx:643
static const double x1[5]
#define ClassImp(name)
Definition: Rtypes.h:279
double Double_t
Definition: RtypesCore.h:55
virtual void PrintFast(Int_t nch, const char *string="")
Fast version of Print.
Definition: TVirtualPS.cxx:103
Double_t y[n]
Definition: legend1.C:17
virtual Color_t GetFillColor() const
Return the fill area color.
Definition: TAttFill.h:35
void TextNDC(Double_t u, Double_t v, const char *string)
Write a string of characters in NDC.
Definition: TTeXDump.cxx:818
The color creation and management class.
Definition: TColor.h:23
Float_t fTextSize
Text size.
Definition: TAttText.h:28
void SetLineWidth(Width_t linewidth=1)
Set the lines width.
Definition: TTeXDump.cxx:684
Int_t fLenBuffer
Definition: TVirtualPS.h:48
void SetColor(Int_t color=1)
Set color with its color index.
Definition: TTeXDump.cxx:708
void CellArrayEnd()
End the Cell Array painting.
Definition: TTeXDump.cxx:881
const Ssiz_t kNPOS
Definition: Rtypes.h:115
void CellArrayFill(Int_t r, Int_t g, Int_t b)
Paint the Cell Array.
Definition: TTeXDump.cxx:873
Color_t fFillColor
Fill area color.
Definition: TAttFill.h:27
void SetMarkerColor(Color_t cindex=1)
Set color index for markers.
Definition: TTeXDump.cxx:700
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
R__EXTERN TVirtualPS * gVirtualPS
Definition: TVirtualPS.h:91
void DrawPolyMarker(Int_t n, Float_t *x, Float_t *y)
Paint PolyMarker.
Definition: TTeXDump.cxx:389
#define gPad
Definition: TVirtualPad.h:289
Int_t Atoi() const
Return integer value of string.
Definition: TString.cxx:1965
void DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Draw a Box.
Definition: TTeXDump.cxx:232
TVirtualPS is an abstract interface to Postscript, PDF, SVG.
Definition: TVirtualPS.h:40
const int nn
const Bool_t kTRUE
Definition: Rtypes.h:91
Color_t fMarkerColor
Marker color.
Definition: TAttMarker.h:27
Color_t fTextColor
Text color.
Definition: TAttText.h:30
void 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)
Draw a Frame around a box.
Definition: TTeXDump.cxx:350
const Int_t n
Definition: legend1.C:16
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:911
Style_t fFillStyle
Fill area style.
Definition: TAttFill.h:28
Short_t fTextAlign
Text alignment.
Definition: TAttText.h:29
const char * Data() const
Definition: TString.h:349
void DrawPolyLineNDC(Int_t n, TPoints *uv)
Draw a PolyLine in NDC space.
Definition: TTeXDump.cxx:381
Int_t fType
Workstation type used to know if the Tex is open.
Definition: TTeXDump.h:27