// @(#)root/graf:$Id$
// Author: Nicolas Brun   07/08/98

/*************************************************************************
 * 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.             *
 *************************************************************************/
#ifndef ROOT_TLatex
#define ROOT_TLatex

#ifndef ROOT_Riosfwd
#include "Riosfwd.h"
#endif
#ifndef ROOT_TText
#include "TText.h"
#endif
#ifndef ROOT_TAttLine
#include "TAttLine.h"
#endif

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TLatex                                                               //
//                                                                      //
// The Latex-style text processor class                                 //
//                                                                      //
//////////////////////////////////////////////////////////////////////////


struct FormSize_t {
      Double_t fWidth, fOver, fUnder;
};

struct TextSpec_t {
   Double_t fAngle,fSize;
   Int_t    fColor,fFont;
};

// compute size of a portion of a formula
class TLatexFormSize {
private:
      Double_t fWidth, fOver, fUnder;
public:
      TLatexFormSize() : fWidth(0), fOver(0),fUnder(0) { } // constructeur par defaut
      TLatexFormSize(Double_t x, Double_t y1, Double_t y2) : fWidth(x), fOver(y1), fUnder(y2) { } // constructeur
      virtual ~TLatexFormSize() {} //destructeur
      TLatexFormSize(const TLatexFormSize& form)
         : fWidth(form.fWidth), fOver(form.fOver), fUnder(form.fUnder) { }

      // definition of operators + and +=
      TLatexFormSize operator+(TLatexFormSize f)
         { return TLatexFormSize(f.Width()+fWidth,TMath::Max(f.Over(),fOver),TMath::Max(f.Under(),fUnder)); }
      void operator+=(TLatexFormSize f)
         { fWidth += f.Width(); fOver = TMath::Max(fOver,f.Over()); fUnder = TMath::Max(fUnder,f.Under()); }

      inline void Set(Double_t x, Double_t y1, Double_t y2) { fWidth=x; fOver=y1; fUnder=y2; }
      TLatexFormSize AddOver(TLatexFormSize f)
         { return TLatexFormSize(f.Width()+fWidth,f.Height()+fOver,fUnder); }
      TLatexFormSize AddUnder(TLatexFormSize f)
         { return TLatexFormSize(f.Width()+fWidth,fOver,f.Height()+fUnder); }
      TLatexFormSize AddOver(TLatexFormSize f1, TLatexFormSize f2)
         { return TLatexFormSize(fWidth+TMath::Max(f1.Width(),f2.Width()),fOver+f1.Over(),fUnder+f2.Under()); }

      // return members
      inline Double_t Width()  const { return fWidth; }
      inline Double_t Over()   const { return fOver; }
      inline Double_t Under()  const { return fUnder; }
      inline Double_t Height() const { return fOver+fUnder; }
};

class TLatex : public TText, public TAttLine {

protected:
      Double_t      fFactorSize;      //!Relative size of subscripts and superscripts
      Double_t      fFactorPos;       //!Relative position of subscripts and superscripts
      Int_t         fLimitFactorSize; // lower bound for subscripts/superscripts size
      const Char_t *fError;           //!error code
      Bool_t        fShow;            //!is true during the second pass (Painting)
      FormSize_t   *fTabSize;         //!array of values for the different zones
      Double_t      fOriginSize;      // Font size of the starting font
      Int_t         fTabMax;          //!Maximum allocation for array fTabSize;
      Int_t         fPos;             //!Current position in array fTabSize;
      Bool_t        fItalic;          //!Currently inside #it operator

      TLatex& operator=(const TLatex&);

      //Text analysis and painting
      TLatexFormSize Analyse(Double_t x, Double_t y, TextSpec_t spec, const Char_t* t,Int_t length);
      TLatexFormSize Anal1(TextSpec_t spec, const Char_t* t,Int_t length);

      void DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2, TextSpec_t spec);
      void DrawCircle(Double_t x1, Double_t y1, Double_t r, TextSpec_t spec);
      void DrawParenthesis(Double_t x1, Double_t y1, Double_t r1, Double_t r2, Double_t phimin, Double_t phimax, TextSpec_t spec);

      TLatexFormSize FirstParse(Double_t angle, Double_t size, const Char_t *text);

      Int_t PaintLatex1(Double_t x, Double_t y, Double_t angle, Double_t size, const char *text);

      void Savefs(TLatexFormSize *fs);
      TLatexFormSize Readfs();

      Int_t CheckLatexSyntax(TString &text) ;

public:
      // TLatex status bits
      enum { kTextNDC = BIT(14) };

      TLatex();
      TLatex(Double_t x, Double_t y, const char *text);
      TLatex(const TLatex &text);
      virtual ~TLatex();
      void             Copy(TObject &text) const;

      TLatex          *DrawLatex(Double_t x, Double_t y, const char *text);
      TLatex          *DrawLatexNDC(Double_t x, Double_t y, const char *text);

      Double_t         GetHeight() const;
      Double_t         GetXsize();
      Double_t         GetYsize();
      void             GetBoundingBox(UInt_t &w, UInt_t &h, Bool_t angle = kFALSE);
      virtual void     Paint(Option_t *option="");
      virtual void     PaintLatex(Double_t x, Double_t y, Double_t angle, Double_t size, const char *text);

      virtual void     SavePrimitive(std::ostream &out, Option_t *option = "");
      virtual void     SetIndiceSize(Double_t factorSize);
      virtual void     SetLimitIndiceSize(Int_t limitFactorSize);

      ClassDef(TLatex,2)  //The Latex-style text processor class
};

#endif
 TLatex.h:1
 TLatex.h:2
 TLatex.h:3
 TLatex.h:4
 TLatex.h:5
 TLatex.h:6
 TLatex.h:7
 TLatex.h:8
 TLatex.h:9
 TLatex.h:10
 TLatex.h:11
 TLatex.h:12
 TLatex.h:13
 TLatex.h:14
 TLatex.h:15
 TLatex.h:16
 TLatex.h:17
 TLatex.h:18
 TLatex.h:19
 TLatex.h:20
 TLatex.h:21
 TLatex.h:22
 TLatex.h:23
 TLatex.h:24
 TLatex.h:25
 TLatex.h:26
 TLatex.h:27
 TLatex.h:28
 TLatex.h:29
 TLatex.h:30
 TLatex.h:31
 TLatex.h:32
 TLatex.h:33
 TLatex.h:34
 TLatex.h:35
 TLatex.h:36
 TLatex.h:37
 TLatex.h:38
 TLatex.h:39
 TLatex.h:40
 TLatex.h:41
 TLatex.h:42
 TLatex.h:43
 TLatex.h:44
 TLatex.h:45
 TLatex.h:46
 TLatex.h:47
 TLatex.h:48
 TLatex.h:49
 TLatex.h:50
 TLatex.h:51
 TLatex.h:52
 TLatex.h:53
 TLatex.h:54
 TLatex.h:55
 TLatex.h:56
 TLatex.h:57
 TLatex.h:58
 TLatex.h:59
 TLatex.h:60
 TLatex.h:61
 TLatex.h:62
 TLatex.h:63
 TLatex.h:64
 TLatex.h:65
 TLatex.h:66
 TLatex.h:67
 TLatex.h:68
 TLatex.h:69
 TLatex.h:70
 TLatex.h:71
 TLatex.h:72
 TLatex.h:73
 TLatex.h:74
 TLatex.h:75
 TLatex.h:76
 TLatex.h:77
 TLatex.h:78
 TLatex.h:79
 TLatex.h:80
 TLatex.h:81
 TLatex.h:82
 TLatex.h:83
 TLatex.h:84
 TLatex.h:85
 TLatex.h:86
 TLatex.h:87
 TLatex.h:88
 TLatex.h:89
 TLatex.h:90
 TLatex.h:91
 TLatex.h:92
 TLatex.h:93
 TLatex.h:94
 TLatex.h:95
 TLatex.h:96
 TLatex.h:97
 TLatex.h:98
 TLatex.h:99
 TLatex.h:100
 TLatex.h:101
 TLatex.h:102
 TLatex.h:103
 TLatex.h:104
 TLatex.h:105
 TLatex.h:106
 TLatex.h:107
 TLatex.h:108
 TLatex.h:109
 TLatex.h:110
 TLatex.h:111
 TLatex.h:112
 TLatex.h:113
 TLatex.h:114
 TLatex.h:115
 TLatex.h:116
 TLatex.h:117
 TLatex.h:118
 TLatex.h:119
 TLatex.h:120
 TLatex.h:121
 TLatex.h:122
 TLatex.h:123
 TLatex.h:124
 TLatex.h:125
 TLatex.h:126
 TLatex.h:127
 TLatex.h:128
 TLatex.h:129
 TLatex.h:130
 TLatex.h:131
 TLatex.h:132
 TLatex.h:133
 TLatex.h:134