Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TLatex.h
Go to the documentation of this file.
1 // @(#)root/graf:$Id$
2 // Author: Nicolas Brun 07/08/98
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 #ifndef ROOT_TLatex
12 #define ROOT_TLatex
13 
14 #include "TText.h"
15 #include "TAttLine.h"
16 
17 
18 class TLatex : public TText, public TAttLine {
19 protected:
20 
21 ////////////////////////////////////////////////////////////////////////////////
22 /// @brief TLatex helper struct holding the attributes of a piece of text.
23 
24  struct TextSpec_t {
25  Double_t fAngle,fSize;
26  Int_t fColor,fFont;
27  };
28 
29 ////////////////////////////////////////////////////////////////////////////////
30 /// @brief TLatex helper struct holding the dimensions of a piece of text.
31  struct FormSize_t {
32  Double_t fWidth, fOver, fUnder;
33  };
34 
35 ////////////////////////////////////////////////////////////////////////////////
36 /// @class TLatexFormSize
37 /// @brief TLatex helper class used to compute the size of a portion of a formula.
38 
39  class TLatexFormSize {
40  private:
41  Double_t fWidth{0}, fOver{0}, fUnder{0};
42 
43  public:
44  TLatexFormSize() = default;
45  TLatexFormSize(Double_t x, Double_t y1, Double_t y2) : fWidth(x), fOver(y1), fUnder(y2) { } // constructor
46 
47  // definition of operators + and +=
48  TLatexFormSize operator+(TLatexFormSize f)
49  { return TLatexFormSize(f.Width()+fWidth,TMath::Max(f.Over(),fOver),TMath::Max(f.Under(),fUnder)); }
50  void operator+=(TLatexFormSize f)
51  { fWidth += f.Width(); fOver = TMath::Max(fOver,f.Over()); fUnder = TMath::Max(fUnder,f.Under()); }
52 
53  inline void Set(Double_t x, Double_t y1, Double_t y2) { fWidth=x; fOver=y1; fUnder=y2; }
54  TLatexFormSize AddOver(TLatexFormSize f)
55  { return TLatexFormSize(f.Width()+fWidth,f.Height()+fOver,fUnder); }
56  TLatexFormSize AddUnder(TLatexFormSize f)
57  { return TLatexFormSize(f.Width()+fWidth,fOver,f.Height()+fUnder); }
58  TLatexFormSize AddOver(TLatexFormSize f1, TLatexFormSize f2)
59  { return TLatexFormSize(fWidth+TMath::Max(f1.Width(),f2.Width()),fOver+f1.Over(),fUnder+f2.Under()); }
60 
61  // return members
62  inline Double_t Width() const { return fWidth; }
63  inline Double_t Over() const { return fOver; }
64  inline Double_t Under() const { return fUnder; }
65  inline Double_t Height() const { return fOver+fUnder; }
66  };
67 
68  Double_t fFactorSize; ///<! Relative size of subscripts and superscripts
69  Double_t fFactorPos; ///<! Relative position of subscripts and superscripts
70  Int_t fLimitFactorSize; ///< lower bound for subscripts/superscripts size
71  const Char_t *fError; ///<! error code
72  Bool_t fShow; ///<! is true during the second pass (Painting)
73  FormSize_t *fTabSize; ///<! array of values for the different zones
74  Double_t fOriginSize; ///< Font size of the starting font
75  Int_t fTabMax; ///<! Maximum allocation for array fTabSize;
76  Int_t fPos; ///<! Current position in array fTabSize;
77  Bool_t fItalic; ///<! Currently inside italic operator
78 
79  TLatex& operator=(const TLatex&);
80 
81  //Text analysis and painting
82  TLatexFormSize Analyse(Double_t x, Double_t y, TextSpec_t spec, const Char_t* t,Int_t length);
83  TLatexFormSize Anal1(TextSpec_t spec, const Char_t* t,Int_t length);
84 
85  void DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2, TextSpec_t spec);
86  void DrawCircle(Double_t x1, Double_t y1, Double_t r, TextSpec_t spec);
87  void DrawParenthesis(Double_t x1, Double_t y1, Double_t r1, Double_t r2, Double_t phimin, Double_t phimax, TextSpec_t spec);
88 
89  TLatexFormSize FirstParse(Double_t angle, Double_t size, const Char_t *text);
90 
91  Int_t PaintLatex1(Double_t x, Double_t y, Double_t angle, Double_t size, const char *text);
92 
93  void Savefs(TLatexFormSize *fs);
94  TLatexFormSize Readfs();
95 
96  Int_t CheckLatexSyntax(TString &text) ;
97 
98 public:
99  // TLatex status bits
100  enum {
101  kTextNDC = BIT(14) ///< The text postion is in NDC coordinates
102  };
103 
104  TLatex();
105  TLatex(Double_t x, Double_t y, const char *text);
106  TLatex(const TLatex &text);
107  virtual ~TLatex();
108  void Copy(TObject &text) const;
109 
110  TLatex *DrawLatex(Double_t x, Double_t y, const char *text);
111  TLatex *DrawLatexNDC(Double_t x, Double_t y, const char *text);
112 
113  Double_t GetHeight() const;
114  Double_t GetXsize();
115  Double_t GetYsize();
116  void GetBoundingBox(UInt_t &w, UInt_t &h, Bool_t angle = kFALSE);
117  virtual void Paint(Option_t *option="");
118  virtual void PaintLatex(Double_t x, Double_t y, Double_t angle, Double_t size, const char *text);
119 
120  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
121  virtual void SetIndiceSize(Double_t factorSize);
122  virtual void SetLimitIndiceSize(Int_t limitFactorSize);
123 
124  ClassDef(TLatex,2) //The Latex-style text processor class
125 };
126 
127 #endif