21 const Double_t kPI = TMath::Pi();
398 fLimitFactorSize = 3;
405 TLatex::TLatex(Double_t x, Double_t y,
const char *text)
417 fLimitFactorSize = 3;
431 TLatex::TLatex(
const TLatex &text) : TText(text), TAttLine(text)
442 fLimitFactorSize = 3;
443 ((TLatex&)text).Copy(*
this);
449 TLatex& TLatex::operator=(
const TLatex& lt)
452 TText::operator=(lt);
453 TAttLine::operator=(lt);
454 fFactorSize=lt.fFactorSize;
455 fFactorPos=lt.fFactorPos;
456 fLimitFactorSize=lt.fLimitFactorSize;
459 fTabSize=lt.fTabSize;
460 fOriginSize=lt.fOriginSize;
461 fTabSize=lt.fTabSize;
462 fTabSize=lt.fTabSize;
471 void TLatex::Copy(TObject &obj)
const
473 ((TLatex&)obj).fFactorSize = fFactorSize;
474 ((TLatex&)obj).fFactorPos = fFactorPos;
475 ((TLatex&)obj).fLimitFactorSize = fLimitFactorSize;
476 ((TLatex&)obj).fError = fError;
477 ((TLatex&)obj).fShow = fShow;
478 ((TLatex&)obj).fTabSize = 0;
479 ((TLatex&)obj).fOriginSize = fOriginSize;
480 ((TLatex&)obj).fTabMax = fTabMax;
481 ((TLatex&)obj).fPos = fPos;
482 ((TLatex&)obj).fItalic = fItalic;
484 TAttLine::Copy(((TAttLine&)obj));
490 TLatex::TLatexFormSize TLatex::Anal1(TextSpec_t spec,
const Char_t* t, Int_t length)
492 return Analyse(0,0,spec,t,length);
522 TLatex::TLatexFormSize TLatex::Analyse(Double_t x, Double_t y, TextSpec_t spec,
const Char_t* t, Int_t length)
524 const char *tab[] = {
"alpha",
"beta",
"chi",
"delta",
"varepsilon",
"phi",
"gamma",
"eta",
"iota",
"varphi",
"kappa",
"lambda",
525 "mu",
"nu",
"omicron",
"pi",
"theta",
"rho",
"sigma",
"tau",
"upsilon",
"varomega",
"omega",
"xi",
"psi",
"zeta",
526 "Alpha",
"Beta",
"Chi",
"Delta",
"Epsilon",
"Phi",
"Gamma",
"Eta",
"Iota",
"vartheta",
527 "Kappa",
"Lambda",
"Mu",
"Nu",
"Omicron",
"Pi",
"Theta",
"Rho",
"Sigma",
"Tau",
528 "Upsilon",
"varsigma",
"Omega",
"Xi",
"Psi",
"Zeta",
"varUpsilon",
"epsilon"};
530 const char *tab2[] = {
"leq",
"/",
"infty",
"voidb",
"club",
"diamond",
"heart",
531 "spade",
"leftrightarrow",
"leftarrow",
"uparrow",
"rightarrow",
532 "downarrow",
"circ",
"pm",
"doublequote",
"geq",
"times",
"propto",
533 "partial",
"bullet",
"divide",
"neq",
"equiv",
"approx",
"3dots",
534 "cbar",
"topbar",
"downleftarrow",
"aleph",
"Jgothic",
"Rgothic",
"voidn",
535 "otimes",
"oplus",
"oslash",
"cap",
"cup",
"supset",
"supseteq",
536 "notsubset",
"subset",
"subseteq",
"in",
"notin",
"angle",
"nabla",
537 "oright",
"ocopyright",
"trademark",
"prod",
"surd",
"upoint",
"corner",
"wedge",
538 "vee",
"Leftrightarrow",
"Leftarrow",
"Uparrow",
"Rightarrow",
539 "Downarrow",
"diamond",
"LT",
"void1",
"copyright",
"void3",
"sum",
540 "arctop",
"lbar",
"arcbottom",
"topbar",
"void8",
"bottombar",
"arcbar",
541 "ltbar",
"AA",
"aa",
"void06",
"GT",
"int",
"forall",
"exists" };
543 const char *tab3[] = {
"bar",
"vec",
"dot",
"hat",
"ddot",
"acute",
"grave",
"check",
"tilde",
"slash"};
545 if (fError != 0)
return TLatexFormSize(0,0,0);
547 Int_t nBlancDeb=0,nBlancFin=0,l_nBlancDeb=0,l_nBlancFin=0;
555 if (nBlancDeb==length)
return TLatexFormSize(0,0,0);
560 if (nBlancDeb==l_nBlancDeb && nBlancFin==l_nBlancFin) cont = kFALSE;
563 if (t[nBlancDeb]==
'{' && t[length-nBlancFin-1]==
'}') {
565 Bool_t sameBrackets = kTRUE;
566 for(i=nBlancDeb;i<length-nBlancFin;i++) {
567 if (t[i] ==
'{' && !(i>0 && t[i-1] ==
'@')) nBrackets++;
568 if (t[i] ==
'}' && t[i-1]!=
'@') nBrackets--;
569 if (nBrackets==0 && i<length-nBlancFin-2) {
579 if (nBlancDeb+nBlancFin==length)
return TLatexFormSize(0,0,0);
585 l_nBlancDeb = nBlancDeb;
586 l_nBlancFin = nBlancFin;
591 length -= nBlancFin+nBlancDeb;
593 Error(
"Analyse",
"It seems there is a syntax error in the TLatex string");
594 return TLatexFormSize(0,0,0);
596 Char_t* text =
new Char_t[length+1];
597 strncpy(text,t+nBlancDeb,length);
601 Double_t indiceSize = spec.fSize/fFactorSize;
602 if(indiceSize<fOriginSize/TMath::Exp(fLimitFactorSize*TMath::Log(fFactorSize))-0.001f)
603 indiceSize = spec.fSize;
605 TextSpec_t specNewSize = spec;
606 specNewSize.fSize = indiceSize;
615 Int_t opCurlyCurly = -1;
616 Int_t opSquareCurly = -1;
617 Int_t opCloseCurly = -2;
624 Int_t opSquareBracket = 0 ;
625 Int_t opBigCurly = 0 ;
628 Int_t abovePlace = 0 ;
636 Int_t opBackslash = 0;
637 Int_t opParallel = 0;
638 Int_t opSplitLine = -1;
645 Bool_t opFound = kFALSE;
646 Bool_t quote1 = kFALSE, quote2 = kFALSE ;
648 for(i=0;i<length;i++) {
650 case '\'' : quote1 = !quote1 ; break ;
651 case '"' : quote2 = !quote2 ; break ;
657 if (!(i>0 && text[i-1] ==
'@')) nBrackets++;
662 if (!(i>0 && text[i-1] ==
'@')) nBrackets--;
664 if (i<length-1)
if (text[i+1]==
'{' && opCurlyCurly==-1) opCurlyCurly=i;
666 if (text[i+1]!=
'{' && !(text[i+2]==
'{' && (text[i+1]==
'^' || text[i+1]==
'_'))
667 && opCloseCurly==-2) opCloseCurly=i;
669 else if (i<length-1) {
670 if (text[i+1]!=
'{' && opCloseCurly==-2) opCloseCurly=i;
672 else if (opCloseCurly==-2) opCloseCurly=i;
678 if (!(i>0 && text[i-1] ==
'@')) nCroch++;
683 if (!(i>0 && text[i-1] ==
'@')) nCroch--;
686 fError =
"Missing \"[\"";
688 return TLatexFormSize(0,0,0);
695 strncpy(buf,&text[i],2);
696 if (strncmp(buf,
"^{",2)==0) {
697 if (opPower==-1 && nBrackets==0 && nCroch==0) opPower=i;
700 strncpy(buf1,&text[i-4],4);
701 if (strncmp(buf1,
"#int",4)==0) {
703 if (i>4 && opCloseCurly==-2) opCloseCurly=i-5;
705 if (strncmp(buf1,
"#sum",4)==0) {
707 if (i>4 && opCloseCurly==-2) opCloseCurly=i-5;
711 if (strncmp(buf,
"_{",2)==0) {
712 if (opUnder==-1 && nBrackets==0 && nCroch==0) opUnder=i;
715 strncpy(buf2,&text[i-4],4);
716 if (strncmp(buf2,
"#int",4)==0) {
718 if (i>4 && opCloseCurly==-2) opCloseCurly=i-5;
720 if (strncmp(buf2,
"#sum",4)==0) {
722 if (i>4 && opCloseCurly==-2) opCloseCurly=i-5;
726 if (strncmp(buf,
"]{",2)==0)
727 if (opSquareCurly==-1 && nBrackets==0 && nCroch==0) opSquareCurly=i;
730 if (text[i]==
'\\' || (text[i]==
'#' && !opFound && nBrackets==0 && nCroch==0)) {
734 strncpy(buf,&text[i+1],10);
735 if (strncmp(buf,
"splitline{",10)==0) {
736 opSplitLine=i; opFound = kTRUE;
737 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
743 strncpy(buf,&text[i+1],9);
744 if (!opBackslash && strncmp(buf,
"backslash",9)==0) {
745 opBackslash=1; opFound = kTRUE;
746 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
752 strncpy(buf,&text[i+1],8);
753 if (!opParallel && strncmp(buf,
"parallel",8)==0) {
754 opParallel=1; opFound = kTRUE;
755 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
761 strncpy(buf,&text[i+1],6);
762 if (strncmp(buf,
"lower[",6)==0 || strncmp(buf,
"lower{",6)==0) {
763 opLower=i; opFound = kTRUE;
764 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
767 if (strncmp(buf,
"scale[",6)==0 || strncmp(buf,
"scale{",6)==0) {
768 opScale=i; opFound = kTRUE;
769 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
772 if (strncmp(buf,
"color[",6)==0 || strncmp(buf,
"color{",6)==0) {
773 opColor=i; opFound = kTRUE;
774 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
780 strncpy(buf,&text[i+1],5);
781 if (strncmp(buf,
"frac{",5)==0) {
782 opFrac=i; opFound = kTRUE;
783 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
786 if (strncmp(buf,
"sqrt{",5)==0 || strncmp(buf,
"sqrt[",5)==0) {
787 opSqrt=i; opFound = kTRUE;
788 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
791 if (strncmp(buf,
"font{",5)==0 || strncmp(buf,
"font[",5)==0) {
792 opFont=i; opFound = kTRUE;
793 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
796 if (strncmp(buf,
"kern[",5)==0 || strncmp(buf,
"kern{",5)==0) {
797 opKern=i; opFound = kTRUE;
798 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
801 if (!opMinus && strncmp(buf,
"minus",5)==0) {
802 opMinus=1; opFound = kTRUE;
803 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
806 if (strncmp(buf,
"mbox[",5)==0 || strncmp(buf,
"mbox{",5)==0) {
807 opMbox=i; opFound = kTRUE;
808 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
814 strncpy(buf,&text[i+1],4);
815 if (!opOdot && strncmp(buf,
"odot",4)==0) {
816 opOdot=1; opFound = kTRUE;
817 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
820 if (!opHbar && strncmp(buf,
"hbar",4)==0) {
821 opHbar=1; opFound = kTRUE;
822 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
825 if (!opPerp && strncmp(buf,
"perp",4)==0) {
826 opPerp=1; opFound = kTRUE;
827 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
830 if (!opPlus && strncmp(buf,
"plus",4)==0) {
831 opPlus=1; opFound = kTRUE;
832 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
838 strncpy(buf,&text[i+1],3);
840 if (strncmp(buf,
"[]{",3)==0) {
841 opSquareBracket=1; opFound = kTRUE;
842 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
845 if (strncmp(buf,
"{}{",3)==0 ) {
846 opBigCurly=1; opFound = kTRUE;
847 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
850 if (strncmp(buf,
"||{",3)==0) {
851 opAbs=1; opFound = kTRUE;
852 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
855 if (strncmp(buf,
"(){",3)==0) {
856 opParen=1; opFound = kTRUE;
857 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
860 if (!opBox && strncmp(buf,
"Box",3)==0) {
861 opBox=1; opFound = kTRUE;
862 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
865 if (strncmp(buf,
"bf[",3)==0 || strncmp(buf,
"bf{",3)==0) {
866 opBf=i; opFound = kTRUE;
867 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
870 if (strncmp(buf,
"it[",3)==0 || strncmp(buf,
"it{",3)==0) {
871 opIt=i; opFound = kTRUE;
872 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
878 strncpy(buf,&text[i+1],2);
879 if (!opMp && strncmp(buf,
"mp",2)==0) {
880 opMp=1; opFound = kTRUE;
881 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
886 if (!opFound && UInt_t(length)>i+strlen(tab[k])) {
887 if (strncmp(&text[i+1],tab[k],strlen(tab[k]))==0) {
890 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
895 if (!opFound && UInt_t(length)>i+strlen(tab3[k])) {
896 if (strncmp(&text[i+1],tab3[k],strlen(tab3[k]))==0) {
899 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
906 if ((opSpec==-1 || strlen(tab2[k])>lastsize) && UInt_t(length)>i+strlen(tab2[k])) {
907 if (strncmp(&text[i+1],tab2[k],strlen(tab2[k]))==0) {
908 lastsize = strlen(tab2[k]);
911 if (i>0 && opCloseCurly==-2) opCloseCurly=i-1;
921 TLatexFormSize result;
924 if (opCloseCurly>-1 && opCloseCurly<length-1) {
926 fs1 = Anal1(spec,text,opCloseCurly+1);
927 fs2 = Anal1(spec,text+opCloseCurly+1,length-opCloseCurly-1);
931 Analyse(x+fs1.Width(),y,spec,text+opCloseCurly+1,length-opCloseCurly-1);
932 Analyse(x,y,spec,text,opCloseCurly+1);
937 else if (opPower>-1 && opUnder>-1) {
938 min = TMath::Min(opPower,opUnder);
939 max = TMath::Max(opPower,opUnder);
940 Double_t xfpos = 0. ;
941 Double_t prop=1, propU=1;
942 switch (abovePlace) {
944 prop = .8 ; propU = 1.75 ;
947 prop = .9 ; propU = 1.75 ;
956 if (min >= 2 && strncmp(&text[min-2],
"{}",2)==0) {
959 snprintf(&text[ltext-2],length-(ltext-2),
"I ") ;
962 fs1 = Anal1(spec,text,ltext);
963 fs2 = Anal1(specNewSize,text+min+1,max-min-1);
964 fs3 = Anal1(specNewSize,text+max+1,length-max-1);
974 Double_t addW = fs1.Width()+xfpos, addH1, addH2;
975 if (opPower<opUnder) {
976 addH1 = -fs1.Over()*(fFactorPos)-fs2.Under();
977 addH2 = fs1.Under()+fs3.Over()*(fFactorPos);
979 addH1 = fs1.Under()+fs2.Over()*(fFactorPos);
980 addH2 = -fs1.Over()*(fFactorPos)-fs3.Under();
982 Analyse(x+addW,y+addH2,specNewSize,text+max+1,length-max-1);
983 Analyse(x+addW,y+addH1,specNewSize,text+min+1,max-min-1);
985 Double_t addW1, addW2, addH1, addH2;
986 Double_t m = TMath::Max(fs1.Width(),TMath::Max(fs2.Width(),fs3.Width()));
987 pos = (m-fs1.Width())/2;
988 if (opPower<opUnder) {
989 addH1 = -fs1.Over()*propU-fs2.Under();
990 addW1 = (m-fs2.Width())/2;
991 addH2 = fs1.Under()*prop+fs3.Over();
992 addW2 = (m-fs3.Width())/2;
994 addH1 = fs1.Under()*prop+fs2.Over();
995 addW1 = (m-fs2.Width())/2;
996 addH2 = -fs1.Over()*propU-fs3.Under();
997 addW2 = (m-fs3.Width())/2;
1000 Analyse(x+addW2,y+addH2,specNewSize,text+max+1,length-max-1);
1001 Analyse(x+addW1,y+addH1,specNewSize,text+min+1,max-min-1);
1004 if (min >= 2 && strncmp(&text[min-2],
"{}",2)==0) {
1005 snprintf(&text[min-2],length-(min-2),
" ") ;
1006 Analyse(x+pos,y,spec,text,min-1);
1008 Analyse(x+pos,y,spec,text,min);
1013 if (opPower<opUnder) {
1014 result.Set(fs1.Width()+xfpos+TMath::Max(fs2.Width(),fs3.Width()),
1015 fs1.Over()*fFactorPos+fs2.Height(),
1016 fs1.Under()+fs3.Height()-fs3.Over()*(1-fFactorPos));
1018 result.Set(fs1.Width()+xfpos+TMath::Max(fs2.Width(),fs3.Width()),
1019 fs1.Over()*fFactorPos+fs3.Height(),
1020 fs1.Under()+fs2.Height()-fs2.Over()*(1-fFactorPos));
1023 if (opPower<opUnder) {
1024 result.Set(TMath::Max(fs1.Width(),TMath::Max(fs2.Width(),fs3.Width())),
1025 fs1.Over()*propU+fs2.Height(),fs1.Under()*prop+fs3.Height());
1027 result.Set(TMath::Max(fs1.Width(),TMath::Max(fs2.Width(),fs3.Width())),
1028 fs1.Over()*propU+fs3.Height(),fs1.Under()*prop+fs2.Height());
1032 else if (opPower>-1) {
1034 Double_t xfpos = 0. ;
1035 switch (abovePlace) {
1037 prop = 1.75 ; break ;
1039 prop = 1.75; break ;
1043 Int_t ltext = opPower ;
1044 if (ltext >= 2 && strncmp(&text[ltext-2],
"{}",2)==0) {
1047 snprintf(&text[ltext-2],length-(ltext-2),
"I ") ;
1050 fs1 = Anal1(spec,text,ltext);
1051 fs2 = Anal1(specNewSize,text+opPower+1,length-opPower-1);
1059 Double_t over = fs1.Over();
1060 if (over <= 0) over = 1.5*fs2.Over();
1061 Analyse(x+fs1.Width()+xfpos,y-over*fFactorPos-fs2.Under(),specNewSize,text+opPower+1,length-opPower-1);
1064 if (fs2.Width()>fs1.Width())
1065 pos=Int_t((fs2.Width()-fs1.Width())/2);
1067 pos2=Int_t((fs1.Width()-fs2.Width())/2);
1069 Analyse(x+pos2,y-fs1.Over()*prop-fs2.Under(),specNewSize,text+opPower+1,length-opPower-1);
1071 if (opPower >= 2 && strncmp(&text[opPower-2],
"{}",2)==0) {
1072 snprintf(&text[opPower-2],length-(opPower-2),
" ") ;
1073 Analyse(x+pos,y,spec,text,opPower-1);
1075 Analyse(x+pos,y,spec,text,opPower);
1080 result.Set(fs1.Width()+xfpos+fs2.Width(),
1081 fs1.Over()*fFactorPos+fs2.Over(),fs1.Under());
1083 result.Set(TMath::Max(fs1.Width(),fs2.Width()),fs1.Over()*prop+fs2.Height(),fs1.Under());
1086 else if (opUnder>-1) {
1088 Double_t xfpos = 0.;
1089 Double_t fpos = fFactorPos ;
1092 Int_t ltext = opUnder ;
1093 if (ltext >= 2 && strncmp(&text[ltext-2],
"{}",2)==0) {
1096 snprintf(&text[ltext-2],length-(ltext-2),
"I ") ;
1099 fs1 = Anal1(spec,text,ltext);
1100 fs2 = Anal1(specNewSize,text+opUnder+1,length-opUnder-1);
1108 Analyse(x+fs1.Width()+xfpos,y+fs1.Under()+fs2.Over()*fpos,specNewSize,text+opUnder+1,length-opUnder-1);
1111 if (fs2.Width()>fs1.Width())
1112 pos=Int_t((fs2.Width()-fs1.Width())/2);
1114 pos2=Int_t((fs1.Width()-fs2.Width())/2);
1116 Analyse(x+pos2,y+fs1.Under()*prop+fs2.Over(),specNewSize,text+opUnder+1,length-opUnder-1);
1118 if (opUnder >= 2 && strncmp(&text[opUnder-2],
"{}",2)==0) {
1119 snprintf(&text[opUnder-2],length-(opUnder-2),
" ") ;
1120 Analyse(x+pos,y,spec,text,opUnder-1);
1122 Analyse(x+pos,y,spec,text,opUnder);
1126 result.Set(fs1.Width()+xfpos+fs2.Width(),fs1.Over(),
1127 fs1.Under()+fs2.Under()+fs2.Over()*fpos);
1129 result.Set(TMath::Max(fs1.Width(),fs2.Width()),fs1.Over(),fs1.Under()*prop+fs2.Height());
1132 Double_t square = GetHeight()*spec.fSize/2;
1134 fs1 = Anal1(spec,text+4,length-4);
1136 fs1 = Analyse(x+square,y,spec,text+4,length-4);
1137 Double_t adjust = GetHeight()*spec.fSize/20;
1138 Double_t x1 = x+adjust ;
1139 Double_t x2 = x-adjust+square ;
1141 Double_t y2 = y-square+adjust;
1142 DrawLine(x1,y1,x2,y1,spec);
1143 DrawLine(x2,y1,x2,y2,spec);
1144 DrawLine(x2,y2,x1,y2,spec);
1145 DrawLine(x1,y2,x1,y1,spec);
1147 result = fs1 + TLatexFormSize(square,square,0);
1150 Double_t square = GetHeight()*spec.fSize/2;
1152 fs1 = Anal1(spec,text+5,length-5);
1154 fs1 = Analyse(x+1.3*square,y,spec,text+5,length-5);
1155 Double_t adjust = GetHeight()*spec.fSize/20;
1156 Double_t r1 = 0.62*square;
1157 Double_t y1 = y-0.3*square-adjust;
1158 DrawCircle(x+0.6*square,y1,r1,spec) ;
1159 DrawCircle(x+0.6*square,y1,r1/100,spec) ;
1161 result = fs1 + TLatexFormSize(square,square,0);
1164 Double_t square = GetHeight()*spec.fSize/2;
1166 fs1 = Anal1(spec,text+5,length-5);
1168 fs1 = Analyse(x+square,y,spec,text+5,length-5);
1170 hbar.SetTextFont(12);
1171 hbar.SetTextColor(spec.fColor);
1172 hbar.SetTextSize(spec.fSize);
1173 hbar.SetTextAngle(fTextAngle);
1174 hbar.SetTextAlign(11);
1175 Double_t xOrigin = (Double_t)gPad->XtoAbsPixel(fX);
1176 Double_t yOrigin = (Double_t)gPad->YtoAbsPixel(fY);
1177 Double_t angle = kPI*spec.fAngle/180.;
1178 Double_t xx = gPad->AbsPixeltoX(Int_t((x-xOrigin)*TMath::Cos(angle)+(y-yOrigin)*TMath::Sin(angle)+xOrigin));
1179 Double_t yy = gPad->AbsPixeltoY(Int_t((x-xOrigin)*TMath::Sin(-angle)+(y-yOrigin)*TMath::Cos(angle)+yOrigin));
1180 hbar.PaintText(xx,yy,
"h");
1181 DrawLine(x,y-0.8*square,x+0.75*square,y-square,spec);
1183 result = fs1 + TLatexFormSize(square,square,0);
1186 Double_t square = GetHeight()*spec.fSize/2;
1188 fs1 = Anal1(spec,text+6,length-6);
1190 fs1 = Analyse(x+square,y,spec,text+6,length-6);
1192 minus.SetTextFont(122);
1193 minus.SetTextColor(spec.fColor);
1194 minus.SetTextSize(spec.fSize);
1195 minus.SetTextAngle(fTextAngle);
1196 minus.SetTextAlign(11);
1197 Double_t xOrigin = (Double_t)gPad->XtoAbsPixel(fX);
1198 Double_t yOrigin = (Double_t)gPad->YtoAbsPixel(fY);
1199 Double_t angle = kPI*spec.fAngle/180.;
1200 Double_t xx = gPad->AbsPixeltoX(Int_t((x-xOrigin)*TMath::Cos(angle)+(y-yOrigin)*TMath::Sin(angle)+xOrigin));
1201 Double_t yy = gPad->AbsPixeltoY(Int_t((x-xOrigin)*TMath::Sin(-angle)+(y-yOrigin)*TMath::Cos(angle)+yOrigin));
1202 minus.PaintText(xx,yy,
"-");
1204 result = fs1 + TLatexFormSize(square,square,0);
1207 Double_t square = GetHeight()*spec.fSize/2;
1209 fs1 = Anal1(spec,text+5,length-5);
1211 fs1 = Analyse(x+square,y,spec,text+5,length-5);
1213 plus.SetTextFont(122);
1214 plus.SetTextColor(spec.fColor);
1215 plus.SetTextSize(spec.fSize);
1216 plus.SetTextAngle(fTextAngle);
1217 plus.SetTextAlign(11);
1218 Double_t xOrigin = (Double_t)gPad->XtoAbsPixel(fX);
1219 Double_t yOrigin = (Double_t)gPad->YtoAbsPixel(fY);
1220 Double_t angle = kPI*spec.fAngle/180.;
1221 Double_t xx = gPad->AbsPixeltoX(Int_t((x-xOrigin)*TMath::Cos(angle)+(y-yOrigin)*TMath::Sin(angle)+xOrigin));
1222 Double_t yy = gPad->AbsPixeltoY(Int_t((x-xOrigin)*TMath::Sin(-angle)+(y-yOrigin)*TMath::Cos(angle)+yOrigin));
1223 plus.PaintText(xx,yy,
"+");
1225 result = fs1 + TLatexFormSize(square,square,0);
1228 Double_t square = GetHeight()*spec.fSize/2;
1230 fs1 = Anal1(spec,text+3,length-3);
1232 fs1 = Analyse(x+square,y,spec,text+3,length-3);
1234 mp.SetTextFont(122);
1235 mp.SetTextColor(spec.fColor);
1236 mp.SetTextSize(spec.fSize);
1237 mp.SetTextAngle(fTextAngle+180);
1238 mp.SetTextAlign(11);
1239 Double_t xOrigin = (Double_t)gPad->XtoAbsPixel(fX);
1240 Double_t yOrigin = (Double_t)gPad->YtoAbsPixel(fY);
1241 Double_t angle = kPI*spec.fAngle/180.;
1242 Double_t xx = gPad->AbsPixeltoX(Int_t((x+square-xOrigin)*TMath::Cos(angle)+(y-1.25*square-yOrigin)*TMath::Sin(angle)+xOrigin));
1243 Double_t yy = gPad->AbsPixeltoY(Int_t((x+square-xOrigin)*TMath::Sin(-angle)+(y-1.25*square-yOrigin)*TMath::Cos(angle)+yOrigin));
1244 mp.PaintText(xx,yy,
"\261");
1246 result = fs1 + TLatexFormSize(square,square,0);
1249 Double_t square = GetHeight()*spec.fSize/1.4;
1251 fs1 = Anal1(spec,text+5,length-5);
1253 fs1 = Analyse(x+0.5*square,y,spec,text+5,length-5);
1254 Double_t x0 = x + 0.50*square;
1255 Double_t x1 = x0 - 0.48*square;
1256 Double_t x2 = x0 + 0.48*square;
1257 Double_t y1 = y + 0.6*square;
1258 Double_t y2 = y1 - 1.3*square;
1259 DrawLine(x1,y1,x2,y1,spec);
1260 DrawLine(x0,y1,x0,y2,spec);
1264 else if (opBackslash) {
1265 Double_t square = GetHeight()*spec.fSize/2;
1267 fs1 = Anal1(spec,text+10,length-10);
1269 fs1 = Analyse(x+square,y,spec,text+10,length-10);
1271 bs.SetTextFont(GetTextFont());
1272 bs.SetTextColor(spec.fColor);
1273 bs.SetTextSize(spec.fSize);
1274 bs.SetTextAngle(fTextAngle);
1275 bs.SetTextAlign(11);
1276 Double_t xOrigin = (Double_t)gPad->XtoAbsPixel(fX);
1277 Double_t yOrigin = (Double_t)gPad->YtoAbsPixel(fY);
1278 Double_t angle = kPI*spec.fAngle/180.;
1279 Double_t xx = gPad->AbsPixeltoX(Int_t((x-xOrigin)*TMath::Cos(angle)+(y-yOrigin)*TMath::Sin(angle)+xOrigin));
1280 Double_t yy = gPad->AbsPixeltoY(Int_t((x-xOrigin)*TMath::Sin(-angle)+(y-yOrigin)*TMath::Cos(angle)+yOrigin));
1281 bs.PaintText(xx,yy,
"\\");
1283 result = fs1 + TLatexFormSize(square,square,0);
1285 else if (opParallel) {
1286 Double_t square = GetHeight()*spec.fSize/1.4;
1288 fs1 = Anal1(spec,text+9,length-9);
1290 fs1 = Analyse(x+0.5*square,y,spec,text+9,length-9);
1291 Double_t x1 = x + 0.15*square;
1292 Double_t x2 = x + 0.45*square;
1293 Double_t y1 = y + 0.3*square;
1294 Double_t y2 = y1- 1.3*square;
1295 DrawLine(x1,y1,x1,y2,spec);
1296 DrawLine(x2,y1,x2,y2,spec);
1298 result = fs1 + TLatexFormSize(square,square,0);
1300 else if (opGreek>-1) {
1301 TextSpec_t newSpec = spec;
1302 newSpec.fFont = fItalic ? 152 : 122;
1303 char letter = 97 + opGreek;
1304 Double_t yoffset = 0.;
1305 if (opGreek>25) letter -= 58;
1306 if (opGreek == 52) letter =
'\241';
1307 if (opGreek == 53) letter =
'\316';
1309 fs1 = Anal1(newSpec,&letter,1);
1310 fs2 = Anal1(spec,text+strlen(tab[opGreek])+1,length-strlen(tab[opGreek])-1);
1314 Analyse(x+fs1.Width(),y,spec,text+strlen(tab[opGreek])+1,length-strlen(tab[opGreek])-1);
1315 Analyse(x,y-yoffset,newSpec,&letter,1);
1317 fs1.AddOver(TLatexFormSize(0,yoffset,0)) ;
1321 else if (opSpec>-1) {
1322 TextSpec_t newSpec = spec;
1323 newSpec.fFont = fItalic ? 152 : 122;
1324 char letter =
'\243' + opSpec;
1325 if(opSpec == 75 || opSpec == 76) {
1326 newSpec.fFont = GetTextFont();
1327 if (gVirtualX->InheritsFrom(
"TGCocoa")) {
1328 if (opSpec == 75) letter =
'\201';
1329 if (opSpec == 76) letter =
'\214';
1331 if (opSpec == 75) letter =
'\305';
1332 if (opSpec == 76) letter =
'\345';
1335 if(opSpec == 80 || opSpec == 81) {
1336 if (opSpec == 80) letter =
'\042';
1337 if (opSpec == 81) letter =
'\044';
1339 Double_t props, propi;
1344 newSpec.fSize = spec.fSize*props;
1345 }
else if (opSpec==79) {
1346 newSpec.fSize = spec.fSize*propi;
1349 fs1 = Anal1(newSpec,&letter,1);
1350 if (opSpec == 79 || opSpec == 66)
1351 fs1.Set(fs1.Width(),fs1.Over()*0.45,fs1.Over()*0.45);
1353 fs2 = Anal1(spec,text+strlen(tab2[opSpec])+1,length-strlen(tab2[opSpec])-1);
1357 Analyse(x+fs1.Width(),y,spec,text+strlen(tab2[opSpec])+1,length-strlen(tab2[opSpec])-1);
1358 if (opSpec!=66 && opSpec!=79)
1359 Analyse(x,y,newSpec,&letter,1);
1361 Analyse(x,y+fs1.Under()/2.,newSpec,&letter,1);
1366 else if (opAbove>-1) {
1368 fs1 = Anal1(spec,text+strlen(tab3[opAbove])+1,length-strlen(tab3[opAbove])-1);
1372 Analyse(x,y,spec,text+strlen(tab3[opAbove])+1,length-strlen(tab3[opAbove])-1);
1373 Double_t sub = GetHeight()*spec.fSize/14;
1374 Double_t x1 , y1 , x2, y2, x3, x4;
1378 ypos = y-fs1.Over()-sub ;
1379 DrawLine(x,ypos,x+fs1.Width(),ypos,spec);
1383 y0 = y-sub-fs1.Over() ;
1384 y1 = y0-GetHeight()*spec.fSize/8 ;
1385 x1 = x+fs1.Width() ;
1386 DrawLine(x,y1,x1,y1,spec);
1387 DrawLine(x1,y1,x1-GetHeight()*spec.fSize/4,y0-GetHeight()*spec.fSize/4,spec);
1388 DrawLine(x1,y1,x1-GetHeight()*spec.fSize/4,y0,spec);
1391 x1 = x+fs1.Width()/2-3*sub/4 ;
1392 x2 = x+fs1.Width()/2+3*sub/4 ;
1393 y1 = y-sub-fs1.Over() ;
1394 DrawLine(x1,y1,x2,y1,spec);
1397 x2 = x+fs1.Width()/2 ;
1400 x1 = x2-fs1.Width()/3 ;
1401 x3 = x2+fs1.Width()/3 ;
1402 DrawLine(x1,y1,x2,y2,spec);
1403 DrawLine(x2,y2,x3,y1,spec);
1406 x1 = x+fs1.Width()/2-9*sub/4 ;
1407 x2 = x+fs1.Width()/2-3*sub/4 ;
1408 x3 = x+fs1.Width()/2+9*sub/4 ;
1409 x4 = x+fs1.Width()/2+3*sub/4 ;
1410 y1 = y-sub-fs1.Over() ;
1411 DrawLine(x1,y1,x2,y1,spec);
1412 DrawLine(x3,y1,x4,y1,spec);
1415 x1 = x+fs1.Width()/2;
1416 y1 = y +sub -fs1.Over() ;
1419 DrawLine(x1,y1,x2,y2,spec);
1422 x1 = x+fs1.Width()/2-sub;
1423 y1 = y-sub-fs1.Over() ;
1426 DrawLine(x1,y1,x2,y2,spec);
1429 x1 = x+fs1.Width()/2 ;
1432 y1 = y-sub-fs1.Over() ;
1433 DrawLine(x2,y-3*sub-fs1.Over(),x1,y1,spec);
1434 DrawLine(x3,y-3*sub-fs1.Over(),x1,y1,spec);
1437 x2 = x+fs1.Width()/2 ;
1438 y2 = y -fs1.Over() ;
1442 TVirtualPS *saveps = gVirtualPS;
1443 if (gVirtualPS) gVirtualPS = 0;
1445 if (gVirtualX->InheritsFrom(
"TGCocoa")) y2 -= 4.7*sub;
1446 Double_t sinang = TMath::Sin(spec.fAngle/180*kPI);
1447 Double_t cosang = TMath::Cos(spec.fAngle/180*kPI);
1448 Double_t xOrigin = (Double_t)gPad->XtoAbsPixel(fX);
1449 Double_t yOrigin = (Double_t)gPad->YtoAbsPixel(fY);
1450 Double_t xx = gPad->AbsPixeltoX(Int_t((x2-xOrigin)*cosang+(y2-yOrigin)*sinang+xOrigin));
1451 Double_t yy = gPad->AbsPixeltoY(Int_t((x2-xOrigin)*-sinang+(y2-yOrigin)*cosang+yOrigin));
1453 tilde.SetTextFont(fTextFont);
1454 tilde.SetTextColor(spec.fColor);
1455 tilde.SetTextSize(0.9*spec.fSize);
1456 tilde.SetTextAlign(22);
1457 tilde.SetTextAngle(fTextAngle);
1458 tilde.PaintText(xx,yy,
"~");
1460 gVirtualPS = saveps;
1461 if (!strstr(gVirtualPS->GetTitle(),
"IMG")) y22 -= 4*sub;
1462 xx = gPad->AbsPixeltoX(Int_t((x2-xOrigin)*cosang+(y22-yOrigin)*sinang+xOrigin));
1463 yy = gPad->AbsPixeltoY(Int_t((x2-xOrigin)*-sinang+(y22-yOrigin)*cosang+yOrigin));
1464 gVirtualPS->SetTextAlign(22);
1465 gVirtualPS->Text(xx, yy,
"~");
1470 x1 = x + 0.8*fs1.Width();
1471 y1 = y -fs1.Over() ;
1472 x2 = x + 0.3*fs1.Width();
1473 y2 = y1 + 1.2*fs1.Height();
1474 DrawLine(x1,y1,x2,y2,spec);
1479 if (opAbove==1) div=4;
1480 result.Set(fs1.Width(),fs1.Over()+GetHeight()*spec.fSize/div,fs1.Under());
1482 else if (opSquareBracket) {
1483 Double_t l = GetHeight()*spec.fSize/4;
1486 fs1 = Anal1(spec,text+3,length-3);
1490 Analyse(x+l2+l,y,spec,text+3,length-3);
1491 DrawLine(x+l2,y-fs1.Over(),x+l2,y+fs1.Under(),spec);
1492 DrawLine(x+l2,y-fs1.Over(),x+l2+l,y-fs1.Over(),spec);
1493 DrawLine(x+l2,y+fs1.Under(),x+l2+l,y+fs1.Under(),spec);
1494 DrawLine(x+l2+fs1.Width()+2*l,y-fs1.Over(),x+l2+fs1.Width()+2*l,y+fs1.Under(),spec);
1495 DrawLine(x+l2+fs1.Width()+2*l,y-fs1.Over(),x+l2+fs1.Width()+l,y-fs1.Over(),spec);
1496 DrawLine(x+l2+fs1.Width()+2*l,y+fs1.Under(),x+l2+fs1.Width()+l,y+fs1.Under(),spec);
1498 result.Set(fs1.Width()+3*l,fs1.Over(),fs1.Under());
1501 Double_t l = GetHeight()*spec.fSize/4;
1502 Double_t radius2,radius1 , dw, l2 = l/2 ;
1503 Double_t angle = 35 ;
1505 fs1 = Anal1(spec,text+3,length-3);
1507 radius2 = fs1.Height() ;
1508 radius1 = radius2 * 2 / 3;
1509 dw = radius1*(1 - TMath::Cos(kPI*angle/180)) ;
1512 radius2 = fs1.Height();
1513 radius1 = radius2 * 2 / 3;
1514 dw = radius1*(1 - TMath::Cos(kPI*angle/180)) ;
1515 Double_t x1 = x+l2+radius1 ;
1516 Double_t x2 = x+5*l2+2*dw+fs1.Width()-radius1 ;
1517 Double_t y1 = y - (fs1.Over() - fs1.Under())/2. ;
1518 DrawParenthesis(x1,y1,radius1,radius2,180-angle,180+angle,spec) ;
1519 DrawParenthesis(x2,y1,radius1,radius2,360-angle,360+angle,spec) ;
1520 Analyse(x+3*l2+dw,y,spec,text+3,length-3);
1523 result.Set(fs1.Width()+3*l+2*dw,fs1.Over(),fs1.Under());
1526 Double_t l = GetHeight()*spec.fSize/4;
1529 fs1 = Anal1(spec,text+3,length-3);
1533 Analyse(x+l2+l,y,spec,text+3,length-3);
1534 DrawLine(x+l2,y-fs1.Over(),x+l2,y+fs1.Under(),spec);
1535 DrawLine(x+l2+fs1.Width()+2*l,y-fs1.Over(),x+l2+fs1.Width()+2*l,y+fs1.Under(),spec);
1537 result.Set(fs1.Width()+3*l,fs1.Over(),fs1.Under());
1539 else if (opBigCurly) {
1540 Double_t l = GetHeight()*spec.fSize/4;
1545 fs1 = Anal1(spec,text+3,length-3);
1546 l8 = fs1.Height()/8 ;
1547 ltip = TMath::Min(l8,l) ;
1552 Double_t y2 = y + (fs1.Under()-fs1.Over())/2 ;
1553 l8 = fs1.Height()/8 ;
1554 ltip = TMath::Min(l8,l) ;
1556 Analyse(x+l+ltip+l2,y,spec,text+3,length-3);
1559 DrawLine(x+l2+ltip,y-fs1.Over(),x+l2+ltip,y2-ltip,spec);
1560 DrawLine(x+l2+ltip,y2+ltip,x+l2+ltip,y+fs1.Under(),spec);
1562 DrawLine(x+l2+ltip,y-fs1.Over(),x+l2+ltip+l,y-fs1.Over(),spec);
1563 DrawLine(x+l2+ltip,y+fs1.Under(),x+l2+ltip+l,y+fs1.Under(),spec);
1565 DrawLine(x+l2,y2,x+l2+ltip,y2-ltip,spec);
1566 DrawLine(x+l2,y2,x+l2+ltip,y2+ltip,spec);
1570 DrawLine(x+l2+ltip+fs1.Width()+2*l,y-fs1.Over(),x+l2+ltip+fs1.Width()+2*l,y2-ltip,spec);
1571 DrawLine(x+l2+ltip+fs1.Width()+2*l,y2+ltip,x+l2+ltip+fs1.Width()+2*l,y+fs1.Under(),spec);
1573 DrawLine(x+l2+fs1.Width()+l+ltip,y-fs1.Over(),x+l2+ltip+fs1.Width()+2*l,y-fs1.Over(),spec);
1574 DrawLine(x+l2+fs1.Width()+l+ltip,y+fs1.Under(),x+l2+ltip+fs1.Width()+2*l,y+fs1.Under(),spec);
1576 DrawLine(x+l2+ltip+2*l+fs1.Width(),y2-ltip,x+l2+2*l+2*ltip+fs1.Width(),y2,spec);
1577 DrawLine(x+l2+ltip+2*l+fs1.Width(),y2+ltip,x+l2+2*l+2*ltip+fs1.Width(),y2,spec);
1579 result.Set(fs1.Width()+3*l+2*ltip,fs1.Over(),fs1.Under()) ;;
1581 else if (opFrac>-1) {
1582 if (opCurlyCurly==-1) {
1584 fError =
"Missing denominator for #frac";
1585 return TLatexFormSize(0,0,0);
1587 Double_t height = GetHeight()*spec.fSize/8;
1589 fs1 = Anal1(spec,text+opFrac+6,opCurlyCurly-opFrac-6);
1590 fs2 = Anal1(spec,text+opCurlyCurly+2,length-opCurlyCurly-3);
1596 Double_t addW1,addW2;
1597 if (fs1.Width()<fs2.Width()) {
1598 addW1 = (fs2.Width()-fs1.Width())/2;
1602 addW2 = (fs1.Width()-fs2.Width())/2;
1604 Analyse(x+addW2,y+fs2.Over()-height,spec,text+opCurlyCurly+2,length-opCurlyCurly-3);
1605 Analyse(x+addW1,y-fs1.Under()-3*height,spec,text+opFrac+6,opCurlyCurly-opFrac-6);
1607 DrawLine(x,y-2*height,x+TMath::Max(fs1.Width(),fs2.Width()),y-2*height,spec);
1610 result.Set(TMath::Max(fs1.Width(),fs2.Width()),fs1.Height()+3*height,fs2.Height()-height);
1613 else if (opSplitLine>-1) {
1614 if (opCurlyCurly==-1) {
1616 fError =
"Missing second line for #splitline";
1617 return TLatexFormSize(0,0,0);
1619 Double_t height = GetHeight()*spec.fSize/8;
1621 fs1 = Anal1(spec,text+opSplitLine+11,opCurlyCurly-opSplitLine-11);
1622 fs2 = Anal1(spec,text+opCurlyCurly+2,length-opCurlyCurly-3);
1628 Analyse(x,y+fs2.Over()-height,spec,text+opCurlyCurly+2,length-opCurlyCurly-3);
1629 Analyse(x,y-fs1.Under()-3*height,spec,text+opSplitLine+11,opCurlyCurly-opSplitLine-11);
1632 result.Set(TMath::Max(fs1.Width(),fs2.Width()),fs1.Height()+3*height,fs2.Height()-height);
1635 else if (opSqrt>-1) {
1637 if (opSquareCurly>-1) {
1639 fs1 = Anal1(specNewSize,text+opSqrt+6,opSquareCurly-opSqrt-6);
1640 fs2 = Anal1(spec,text+opSquareCurly+1,length-opSquareCurly-1);
1643 result.Set(fs2.Width()+ GetHeight()*spec.fSize/10+TMath::Max(GetHeight()*spec.fSize/2,(Double_t)fs1.Width()),
1644 fs2.Over()+fs1.Height()+GetHeight()*spec.fSize/4,fs2.Under());
1646 fs1 = Anal1(spec,text+opSqrt+5,length-opSqrt-5);
1648 result.Set(fs1.Width()+GetHeight()*spec.fSize/2,fs1.Over()+GetHeight()*spec.fSize/4,fs1.Under());
1651 if (opSquareCurly>-1) {
1654 Double_t pas = TMath::Max(GetHeight()*spec.fSize/2,(Double_t)fs1.Width());
1655 Double_t pas2 = pas + GetHeight()*spec.fSize/10;
1656 Double_t y1 = y-fs2.Over() ;
1657 Double_t y2 = y+fs2.Under() ;
1658 Double_t y3 = y1-GetHeight()*spec.fSize/4;
1659 Analyse(x+pas2,y,spec,text+opSquareCurly+1,length-opSquareCurly-1);
1660 Analyse(x,y-fs2.Over()-fs1.Under(),specNewSize,text+opSqrt+6,opSquareCurly-opSqrt-6);
1661 DrawLine(x,y1,x+pas,y2,spec);
1662 DrawLine(x+pas,y2,x+pas,y3,spec);
1663 DrawLine(x+pas,y3,x+pas2+fs2.Width(),y3,spec);
1666 Double_t x1 = x+GetHeight()*spec.fSize*2/5 ;
1667 Double_t x2 = x+GetHeight()*spec.fSize/2+fs1.Width() ;
1668 Double_t y1 = y-fs1.Over() ;
1669 Double_t y2 = y+fs1.Under() ;
1670 Double_t y3 = y1-GetHeight()*spec.fSize/4;
1672 Analyse(x+GetHeight()*spec.fSize/2,y,spec,text+opSqrt+6,length-opSqrt-7);
1674 Short_t lineW = GetLineWidth();
1676 Double_t dx = (y2-y3)/8;
1678 GetTextAscentDescent(a, d, text);
1679 if (a>12) SetLineWidth(TMath::Max(2,(Int_t)(dx/2)));
1680 DrawLine(x1-2*dx,y1,x1-dx,y2,spec);
1681 if (a>12) SetLineWidth(TMath::Max(1,(Int_t)(dx/4)));
1682 DrawLine(x1-dx,y2,x1,y3,spec);
1683 DrawLine(x1,y3,x2,y3,spec);
1684 SetLineWidth(lineW);
1688 else if (opColor>-1) {
1689 if (opSquareCurly==-1) {
1691 fError =
"Missing color number. Syntax is #color[(Int_t)nb]{ ... }";
1692 return TLatexFormSize(0,0,0);
1694 TextSpec_t newSpec = spec;
1695 Char_t *nb =
new Char_t[opSquareCurly-opColor-6];
1696 strncpy(nb,text+opColor+7,opSquareCurly-opColor-7);
1697 nb[opSquareCurly-opColor-7] = 0;
1698 if (sscanf(nb,
"%d",&newSpec.fColor) < 1) {
1701 fError =
"Invalid color number. Syntax is #color[(Int_t)nb]{ ... }";
1702 return TLatexFormSize(0,0,0);
1706 result = Anal1(newSpec,text+opSquareCurly+1,length-opSquareCurly-1);
1708 Analyse(x,y,newSpec,text+opSquareCurly+1,length-opSquareCurly-1);
1711 else if (opFont>-1) {
1712 if (opSquareCurly==-1) {
1714 fError =
"Missing font number. Syntax is #font[nb]{ ... }";
1715 return TLatexFormSize(0,0,0);
1717 TextSpec_t newSpec = spec;
1718 Char_t *nb =
new Char_t[opSquareCurly-opFont-5];
1719 strncpy(nb,text+opFont+6,opSquareCurly-opFont-6);
1720 nb[opSquareCurly-opFont-6] = 0;
1721 if (sscanf(nb,
"%d",&newSpec.fFont) < 1) {
1724 fError =
"Invalid font number. Syntax is #font[(Int_t)nb]{ ... }";
1725 return TLatexFormSize(0,0,0);
1729 result = Anal1(newSpec,text+opSquareCurly+1,length-opSquareCurly-1);
1731 Analyse(x,y,newSpec,text+opSquareCurly+1,length-opSquareCurly-1);
1734 else if (opKern>-1) {
1735 if (opSquareCurly==-1) {
1737 fError =
"Missing horizontal shift number. Syntax is #kern[dx]{ ... }";
1738 return TLatexFormSize(0,0,0);
1740 Char_t *dxc =
new Char_t[opSquareCurly-opKern-5];
1741 strncpy(dxc,text+opKern+6,opSquareCurly-opKern-6);
1742 dxc[opSquareCurly-opKern-6] = 0;
1744 if (sscanf(dxc,
"%f",&dx) < 1) {
1747 fError =
"Invalid horizontal shift number. Syntax is #kern[(Float_t)dx]{ ... }";
1748 return TLatexFormSize(0,0,0);
1752 fs1 = Anal1(spec,text+opSquareCurly+1,length-opSquareCurly-1);
1754 Double_t ddx = dx * fs1.Width();
1755 result = TLatexFormSize(fs1.Width() + ddx, fs1.Over(), fs1.Under());
1758 Double_t ddx = dx * fs1.Width();
1759 Analyse(x + ddx,y,spec,text+opSquareCurly+1,length-opSquareCurly-1);
1762 else if (opLower>-1) {
1763 if (opSquareCurly==-1) {
1765 fError =
"Missing vertical shift number. Syntax is #lower[dy]{ ... }";
1766 return TLatexFormSize(0,0,0);
1768 Char_t *dyc =
new Char_t[opSquareCurly-opLower-6];
1769 strncpy(dyc,text+opLower+7,opSquareCurly-opLower-7);
1770 dyc[opSquareCurly-opLower-7] = 0;
1772 if (sscanf(dyc,
"%f",&dy) < 1) {
1775 fError =
"Invalid vertical shift number. Syntax is #lower[(Float_t)dy]{ ... }";
1776 return TLatexFormSize(0,0,0);
1780 fs1 = Anal1(spec,text+opSquareCurly+1,length-opSquareCurly-1);
1782 Double_t ddy = dy * (fs1.Over() + fs1.Under());
1783 result = TLatexFormSize(fs1.Width(), fs1.Over() + ddy, fs1.Under() + ddy);
1786 Double_t ddy = dy * (fs1.Over() + fs1.Under());
1787 Analyse(x,y + ddy,spec,text+opSquareCurly+1,length-opSquareCurly-1);
1790 else if (opScale>-1) {
1791 if (opSquareCurly==-1) {
1793 fError =
"Missing scale factor. Syntax is #scale[(Double_t)nb]{ ... }";
1794 return TLatexFormSize(0,0,0);
1796 TextSpec_t newSpec = spec;
1797 Char_t *nb =
new Char_t[opSquareCurly-opScale-6];
1798 strncpy(nb,text+opScale+7,opSquareCurly-opScale-7);
1799 nb[opSquareCurly-opScale-7] = 0;
1800 if (sscanf(nb,
"%lf",&newSpec.fSize) < 1) {
1803 fError =
"Invalid scale factor. Syntax is #factor[(Double_t)nb]{ ... }";
1804 return TLatexFormSize(0,0,0);
1806 newSpec.fSize *= spec.fSize;
1809 result = Anal1(newSpec,text+opSquareCurly+1,length-opSquareCurly-1);
1811 Analyse(x,y,newSpec,text+opSquareCurly+1,length-opSquareCurly-1);
1815 TextSpec_t newSpec = spec;
1816 Int_t lut[] = {3, 13, 1, 6, 7, 4, 5, 10, 11, 8, 9, 12, 2, 14, 15};
1817 Int_t fontId = (newSpec.fFont/10);
1818 if ((fontId >= 1) && (fontId <= (Int_t)(
sizeof(lut)/
sizeof(lut[0])))) fontId = lut[fontId-1];
1819 newSpec.fFont = fontId*10 + newSpec.fFont%10;
1821 fs1 = Anal1(newSpec,text+3,length-3);
1825 Analyse(x,y,newSpec,text+3,length-3);
1829 else if (opMbox>-1) {
1830 TextSpec_t newSpec = spec;
1832 fs1 = Anal1(newSpec,text+5,length-5);
1836 Analyse(x,y,newSpec,text+5,length-5);
1841 TextSpec_t newSpec = spec;
1842 Int_t lut[] = {13, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 15, 1, 14, 12};
1843 Int_t fontId = (newSpec.fFont/10);
1844 if ((fontId >= 1) && (fontId <= (Int_t)(
sizeof(lut)/
sizeof(lut[0])))) fontId = lut[fontId-1];
1845 newSpec.fFont = fontId*10 + newSpec.fFont%10;
1848 fs1 = Anal1(newSpec,text+3,length-3);
1852 Analyse(x,y,newSpec,text+3,length-3);
1858 SetTextSize(spec.fSize);
1859 SetTextAngle(spec.fAngle);
1860 SetTextColor(spec.fColor);
1861 SetTextFont(spec.fFont);
1866 Int_t leng = strlen(text) ;
1868 quote1 = quote2 = kFALSE ;
1870 for (i=0 ; i<leng ; i++) {
1872 case '\'' : quote1 = !quote1 ; break ;
1873 case '"' : quote2 = !quote2 ; break ;
1876 if (text[i] ==
'@') {
1878 if ( *(p+1) ==
'{' || *(p+1) ==
'}' || *(p+1) ==
'[' || *(p+1) ==
']') {
1890 Double_t xOrigin = (Double_t)gPad->XtoAbsPixel(fX);
1891 Double_t yOrigin = (Double_t)gPad->YtoAbsPixel(fY);
1892 Double_t angle = kPI*spec.fAngle/180.;
1893 Double_t xx = gPad->AbsPixeltoX(Int_t((x-xOrigin)*TMath::Cos(angle)+(y-yOrigin)*TMath::Sin(angle)+xOrigin));
1894 Double_t yy = gPad->AbsPixeltoY(Int_t((x-xOrigin)*TMath::Sin(-angle)+(y-yOrigin)*TMath::Cos(angle)+yOrigin));
1895 gPad->PaintText(xx,yy,text);
1897 GetTextExtent(w,h,text);
1900 GetTextAscentDescent(a, d, text);
1916 TLatex *TLatex::DrawLatex(Double_t x, Double_t y,
const char *text)
1918 TLatex *newtext =
new TLatex(x, y, text);
1919 TAttText::Copy(*newtext);
1920 newtext->SetBit(kCanDelete);
1921 if (TestBit(kTextNDC)) newtext->SetNDC();
1922 newtext->AppendPad();
1929 TLatex *TLatex::DrawLatexNDC(Double_t x, Double_t y,
const char *text)
1931 TLatex *newtext = DrawLatex(x, y, text);
1939 void TLatex::DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2, TextSpec_t spec)
1941 Double_t sinang = TMath::Sin(spec.fAngle/180*kPI);
1942 Double_t cosang = TMath::Cos(spec.fAngle/180*kPI);
1943 Double_t xOrigin = (Double_t)gPad->XtoAbsPixel(fX);
1944 Double_t yOrigin = (Double_t)gPad->YtoAbsPixel(fY);
1945 Double_t xx = gPad->AbsPixeltoX(Int_t((x1-xOrigin)*cosang+(y1-yOrigin)*sinang+xOrigin));
1946 Double_t yy = gPad->AbsPixeltoY(Int_t((x1-xOrigin)*-sinang+(y1-yOrigin)*cosang+yOrigin));
1948 Double_t xx2 = gPad->AbsPixeltoX(Int_t((x2-xOrigin)*cosang+(y2-yOrigin)*sinang+xOrigin));
1949 Double_t yy2 = gPad->AbsPixeltoY(Int_t((x2-xOrigin)*-sinang+(y2-yOrigin)*cosang+yOrigin));
1951 SetLineColor(spec.fColor);
1953 gPad->PaintLine(xx,yy,xx2,yy2);
1959 void TLatex::DrawCircle(Double_t x1, Double_t y1, Double_t r, TextSpec_t spec )
1962 Double_t sinang = TMath::Sin(spec.fAngle/180*kPI);
1963 Double_t cosang = TMath::Cos(spec.fAngle/180*kPI);
1964 Double_t xOrigin = (Double_t)gPad->XtoAbsPixel(fX);
1965 Double_t yOrigin = (Double_t)gPad->YtoAbsPixel(fY);
1967 const Int_t np = 40;
1968 Double_t dphi = 2*kPI/np;
1969 Double_t x[np+3], y[np+3];
1970 Double_t angle,dx,dy;
1972 SetLineColor(spec.fColor);
1975 for (Int_t i=0;i<=np;i++) {
1976 angle = Double_t(i)*dphi;
1977 dx = r*TMath::Cos(angle) +x1 -xOrigin;
1978 dy = r*TMath::Sin(angle) +y1 -yOrigin;
1979 x[i] = gPad->AbsPixeltoX(Int_t( dx*cosang+ dy*sinang +xOrigin));
1980 y[i] = gPad->AbsPixeltoY(Int_t(-dx*sinang+ dy*cosang +yOrigin));
1982 gPad->PaintPolyLine(np+1,x,y);
1988 void TLatex::DrawParenthesis(Double_t x1, Double_t y1, Double_t r1, Double_t r2,
1989 Double_t phimin, Double_t phimax, TextSpec_t spec )
1993 Double_t sinang = TMath::Sin(spec.fAngle/180*kPI);
1994 Double_t cosang = TMath::Cos(spec.fAngle/180*kPI);
1995 Double_t xOrigin = (Double_t)gPad->XtoAbsPixel(fX);
1996 Double_t yOrigin = (Double_t)gPad->YtoAbsPixel(fY);
1998 const Int_t np = 40;
1999 Double_t dphi = (phimax-phimin)*kPI/(180*np);
2000 Double_t x[np+3], y[np+3];
2001 Double_t angle,dx,dy ;
2003 SetLineColor(spec.fColor);
2006 for (Int_t i=0;i<=np;i++) {
2007 angle = phimin*kPI/180 + Double_t(i)*dphi;
2008 dx = r1*TMath::Cos(angle) +x1 -xOrigin;
2009 dy = r2*TMath::Sin(angle) +y1 -yOrigin;
2010 x[i] = gPad->AbsPixeltoX(Int_t( dx*cosang+dy*sinang +xOrigin));
2011 y[i] = gPad->AbsPixeltoY(Int_t(-dx*sinang+dy*cosang +yOrigin));
2013 gPad->PaintPolyLine(np+1,x,y);
2019 void TLatex::Paint(Option_t *)
2021 Double_t xsave = fX;
2022 Double_t ysave = fY;
2023 if (TestBit(kTextNDC)) {
2024 fX = gPad->GetX1() + xsave*(gPad->GetX2() - gPad->GetX1());
2025 fY = gPad->GetY1() + ysave*(gPad->GetY2() - gPad->GetY1());
2026 PaintLatex(fX,fY,GetTextAngle(),GetTextSize(),GetTitle());
2028 PaintLatex(gPad->XtoPad(fX),gPad->YtoPad(fY),GetTextAngle(),GetTextSize(),GetTitle());
2040 void TLatex::PaintLatex(Double_t x, Double_t y, Double_t angle, Double_t size,
const Char_t *text1)
2042 if (size<=0 || strlen(text1) <= 0)
return;
2046 TVirtualPS *saveps = gVirtualPS;
2049 if (gVirtualPS->InheritsFrom(
"TTeXDump")) {
2050 gVirtualPS->SetTextAngle(angle);
2052 if (t.Index(
"#")>=0 || t.Index(
"^")>=0 || t.Index(
"\\")>=0) {
2053 t.ReplaceAll(
"#LT",
"\\langle");
2054 t.ReplaceAll(
"#GT",
"\\rangle");
2055 t.ReplaceAll(
"#club",
"\\clubsuit");
2056 t.ReplaceAll(
"#spade",
"\\spadesuit");
2057 t.ReplaceAll(
"#heart",
"\\heartsuit");
2058 t.ReplaceAll(
"#diamond",
"\\diamondsuit");
2059 t.ReplaceAll(
"#voidn",
"\\wp");
2060 t.ReplaceAll(
"#voidb",
"f");
2061 t.ReplaceAll(
"#ocopyright",
"\\copyright");
2062 t.ReplaceAll(
"#trademark",
"TM");
2063 t.ReplaceAll(
"#void3",
"TM");
2064 t.ReplaceAll(
"#oright",
"R");
2065 t.ReplaceAll(
"#void1",
"R");
2066 t.ReplaceAll(
"#3dots",
"\\ldots");
2067 t.ReplaceAll(
"#lbar",
"\\mid");
2068 t.ReplaceAll(
"#bar",
"\\wwbar");
2069 t.ReplaceAll(
"#void8",
"\\mid");
2070 t.ReplaceAll(
"#divide",
"\\div");
2071 t.ReplaceAll(
"#Jgothic",
"\\Im");
2072 t.ReplaceAll(
"#Rgothic",
"\\Re");
2073 t.ReplaceAll(
"#doublequote",
"\"");
2074 t.ReplaceAll(
"#plus",
"+");
2075 t.ReplaceAll(
"#minus",
"-");
2076 t.ReplaceAll(
"#/",
"/");
2077 t.ReplaceAll(
"#upoint",
".");
2078 t.ReplaceAll(
"#aa",
"\\mbox{\\aa}");
2079 t.ReplaceAll(
"#AA",
"\\mbox{\\AA}");
2081 t.ReplaceAll(
"#omicron",
"o");
2082 t.ReplaceAll(
"#Alpha",
"A");
2083 t.ReplaceAll(
"#Beta",
"B");
2084 t.ReplaceAll(
"#Epsilon",
"E");
2085 t.ReplaceAll(
"#Zeta",
"Z");
2086 t.ReplaceAll(
"#Eta",
"H");
2087 t.ReplaceAll(
"#Iota",
"I");
2088 t.ReplaceAll(
"#Kappa",
"K");
2089 t.ReplaceAll(
"#Mu",
"M");
2090 t.ReplaceAll(
"#Nu",
"N");
2091 t.ReplaceAll(
"#Omicron",
"O");
2092 t.ReplaceAll(
"#Rho",
"P");
2093 t.ReplaceAll(
"#Tau",
"T");
2094 t.ReplaceAll(
"#Chi",
"X");
2095 t.ReplaceAll(
"#varomega",
"\\varpi");
2097 t.ReplaceAll(
"#varUpsilon",
"?");
2098 t.ReplaceAll(
"#corner",
"?");
2099 t.ReplaceAll(
"#ltbar",
"?");
2100 t.ReplaceAll(
"#bottombar",
"?");
2101 t.ReplaceAll(
"#notsubset",
"?");
2102 t.ReplaceAll(
"#arcbottom",
"?");
2103 t.ReplaceAll(
"#cbar",
"?");
2104 t.ReplaceAll(
"#arctop",
"?");
2105 t.ReplaceAll(
"#topbar",
"?");
2106 t.ReplaceAll(
"#arcbar",
"?");
2107 t.ReplaceAll(
"#downleftarrow",
"?");
2108 t.ReplaceAll(
"#splitline",
"\\genfrac{}{}{0pt}{}");
2110 t.ReplaceAll(
"#",
"\\");
2111 t.ReplaceAll(
"%",
"\\%");
2113 gVirtualPS->Text(x,y,t.Data());
2115 Bool_t saveb = gPad->IsBatch();
2116 gPad->SetBatch(kTRUE);
2117 if (!PaintLatex1( x, y, angle, size, text1)) {
2118 if (saveps) gVirtualPS = saveps;
2121 gPad->SetBatch(saveb);
2126 if (!gPad->IsBatch()) PaintLatex1( x, y, angle, size, text1);
2127 if (saveps) gVirtualPS = saveps;
2133 Int_t TLatex::PaintLatex1(Double_t x, Double_t y, Double_t angle, Double_t size,
const Char_t *text1)
2135 TString newText = text1;
2136 if( newText.Length() == 0)
return 0;
2137 newText.ReplaceAll(
"#hbox",
"#mbox");
2140 if (CheckLatexSyntax(newText)) {
2141 std::cout<<
"\n*ERROR<TLatex>: "<<fError<<std::endl;
2142 std::cout<<
"==> "<<text1<<std::endl;
2148 if (fTextFont%10 < 2) {
2149 if (gVirtualX) gVirtualX->SetTextAngle(angle);
2150 if (gVirtualPS) gVirtualPS->SetTextAngle(angle);
2151 gPad->PaintText(x,y,text1);
2155 Bool_t saveb = gPad->IsBatch();
2157 if (strstr(text1,
"\\")) {
2159 tm.SetTextAlign(GetTextAlign());
2160 tm.SetTextFont(GetTextFont());
2161 tm.PaintMathText(x, y, angle, size, text1);
2164 if (gVirtualPS->InheritsFrom(
"TPDF") ||
2165 gVirtualPS->InheritsFrom(
"TSVG")) {
2166 newText.ReplaceAll(
"\\",
"#");
2167 gPad->SetBatch(kTRUE);
2176 Double_t saveSize = size;
2177 Int_t saveFont = fTextFont;
2178 if (fTextFont%10 > 2) {
2179 UInt_t w = TMath::Abs(gPad->XtoAbsPixel(gPad->GetX2()) -
2180 gPad->XtoAbsPixel(gPad->GetX1()));
2181 UInt_t h = TMath::Abs(gPad->YtoAbsPixel(gPad->GetY2()) -
2182 gPad->YtoAbsPixel(gPad->GetY1()));
2187 SetTextFont(10*(saveFont/10) + 2);
2190 Int_t length = newText.Length() ;
2191 const Char_t *text = newText.Data() ;
2195 x = gPad->XtoAbsPixel(x);
2196 y = gPad->YtoAbsPixel(y);
2198 TLatexFormSize fs = FirstParse(angle,size,text);
2203 Short_t lineW = GetLineWidth();
2204 Int_t lineC = GetLineColor();
2207 spec.fAngle = angle;
2209 spec.fColor = GetTextColor();
2210 spec.fFont = GetTextFont();
2211 Short_t halign = fTextAlign/10;
2212 Short_t valign = fTextAlign - 10*halign;
2213 TextSpec_t newSpec = spec;
2215 std::cout<<
"*ERROR<TLatex>: "<<fError<<std::endl;
2216 std::cout<<
"==> "<<text<<std::endl;
2219 newSpec.fSize = size;
2222 case 0: y -= fs.Under() ;
break;
2224 case 2: y += fs.Height()*0.5-fs.Under(); y++;
break;
2225 case 3: y += fs.Over() ;
break;
2228 case 2: x -= fs.Width()/2 ;
break;
2229 case 3: x -= fs.Width() ;
break;
2231 Analyse(x,y,newSpec,text,length);
2234 gPad->SetBatch(saveb);
2235 SetTextSize(saveSize);
2236 SetTextAngle(angle);
2237 SetTextFont(saveFont);
2238 SetTextColor(spec.fColor);
2239 SetTextAlign(valign+10*halign);
2240 SetLineWidth(lineW);
2241 SetLineColor(lineC);
2243 if (fError != 0)
return 0;
2250 Int_t TLatex::CheckLatexSyntax(TString &text)
2252 const Char_t *kWord1[] = {
"{}^{",
"{}_{",
"^{",
"_{",
"#scale{",
"#color{",
"#font{",
"#sqrt{",
"#[]{",
"#{}{",
"#||{",
2253 "#bar{",
"#vec{",
"#dot{",
"#hat{",
"#ddot{",
"#acute{",
"#grave{",
"#check{",
"#tilde{",
"#slash{",
"#bf{",
"#it{",
"#mbox{",
2254 "\\scale{",
"\\color{",
"\\font{",
"\\sqrt{",
"\\[]{",
"\\{}{",
"\\||{",
"#(){",
"\\(){",
2255 "\\bar{",
"\\vec{",
"\\dot{",
"\\hat{",
"\\ddot{",
"\\acute{",
"\\grave{",
"\\check{",
"\\bf{",
"\\it{",
"\\mbox{"};
2256 const Char_t *kWord2[] = {
"#scale[",
"#color[",
"#font[",
"#sqrt[",
"#kern[",
"#lower[",
"\\scale[",
"\\color[",
"\\font[",
"\\sqrt[",
"\\kern[",
"\\lower["};
2257 const Char_t *kWord3[] = {
"#frac{",
"\\frac{",
"#splitline{",
"\\splitline{"};
2258 const Char_t *kLeft1[] = {
"#left[",
"\\left[",
"#left{",
"\\left{",
"#left|",
"\\left|",
"#left(",
"\\left("};
2259 const Char_t *kLeft2[] = {
"#[]{",
"#[]{",
"#{}{",
"#{}{",
"#||{",
"#||{",
"#(){",
"#(){"};
2260 const Char_t *kRight[] = {
"#right]",
"\\right]",
"#right}",
"\\right}",
"#right|",
"\\right|",
"#right)",
"\\right)"};
2261 const Int_t lkWord1[] = {4,4,2,2,7,7,6,6,4,4,4,5,5,5,5,6,7,7,7,7,7,4,4,6,7,7,6,6,4,4,4,4,4,5,5,5,5,6,7,7,7,4,4,6};
2262 const Int_t lkWord2[] = {7,7,6,6,6,7,7,7,6,6,6,7} ;
2263 const Int_t lkWord3[] = {6,6,11,11} ;
2264 Int_t nkWord1 = 44, nkWord2 = 12, nkWord3 = 4;
2266 Int_t nLeft1 , nRight , nOfLeft, nOfRight;
2270 nLeft1 = nRight = 8 ;
2271 nOfLeft = nOfRight = 0 ;
2273 Char_t buf[11] ;
for (i=0;i<11;i++) buf[i]=0;
2276 Int_t length = text.Length() ;
2278 Int_t nOfCurlyBracket, nOfKW1, nOfKW2, nOfKW3, nOfSquareCurly, nOfCurlyCurly ;
2279 Int_t nOfExtraCurly = 0 , nOfExtraSquare = 0;
2280 Int_t nOfSquareBracket = 0 ;
2282 Bool_t quote1 = kFALSE , quote2 = kFALSE;
2287 while (i < length) {
2290 strncpy(buf,&text[i],TMath::Min(7,length-i));
2292 for (k = 0 ; k < nLeft1 ; k++) {
2293 if (strncmp(buf,kLeft1[k],lLeft1)==0) {
2300 if (opFound) continue ;
2302 for(k=0;k<nRight;k++) {
2303 if (strncmp(buf,kRight[k],lRight)==0) {
2312 if (nOfLeft != nOfRight) {
2313 printf(
" nOfLeft = %d, nOfRight = %d\n",nOfLeft,nOfRight) ;
2315 fError =
"Operators \"#left\" and \"#right\" don't match !" ;
2319 for (k = 0 ; k < nLeft1 ; k++) {
2320 text.ReplaceAll(kLeft1[k],lLeft1,kLeft2[k],lLeft2) ;
2322 for (k = 0 ; k < nRight ; k++) {
2323 text.ReplaceAll(kRight[k],lRight,
"}",1) ;
2325 length = text.Length() ;
2327 i = nOfCurlyBracket = nOfKW1 = nOfKW2 = nOfKW3 = nOfSquareCurly = nOfCurlyCurly =0 ;
2330 case '"' : quote1 = !quote1 ; break ;
2331 case '\'': quote2 = !quote2 ; break ;
2335 strncpy(buf,&text[i],TMath::Min(11,length-i));
2338 for(k=0;k<nkWord1;k++) {
2339 if (strncmp(buf,kWord1[k],lkWord1[k])==0) {
2347 if (opFound) continue ;
2349 for(k=0;k<nkWord2;k++) {
2350 if (strncmp(buf,kWord2[k],lkWord2[k])==0) {
2358 if (opFound) continue ;
2360 for(k=0;k<nkWord3;k++) {
2361 if (strncmp(buf,kWord3[k],lkWord3[k])==0) {
2370 if (opFound) continue ;
2371 if (strncmp(buf,
"}{",2) == 0 && opFrac) {
2376 else if (strncmp(buf,
"]{",2) == 0 && nOfSquareBracket) {
2380 nOfSquareBracket-- ;
2382 else if (strncmp(buf,
"@{",2) == 0 || strncmp(buf,
"@}",2) == 0) {
2385 else if (strncmp(buf,
"@[",2) == 0 || strncmp(buf,
"@]",2) == 0) {
2388 else if (text[i] ==
']' ) {
2389 text.Insert(i,
"@") ;
2394 else if (text[i] ==
'[' ) {
2395 text.Insert(i,
"@") ;
2400 else if (text[i] ==
'{' ) {
2401 text.Insert(i,
"@") ;
2406 else if (text[i] ==
'}' ) {
2407 if ( nOfCurlyBracket) {
2411 text.Insert(i,
"@") ;
2422 if (nOfKW2 != nOfSquareCurly) {
2424 fError =
"Invalid number of \"]{\"" ;
2426 else if (nOfKW3 != nOfCurlyCurly) {
2428 fError =
"Error in syntax of \"#frac\"" ;
2430 else if (nOfCurlyBracket < 0) {
2432 fError =
"Missing \"{\"" ;
2434 else if (nOfCurlyBracket > 0) {
2436 fError =
"Missing \"}\"" ;
2438 else if (nOfSquareBracket < 0) {
2440 fError =
"Missing \"[\"" ;
2442 else if (nOfSquareBracket > 0) {
2444 fError =
"Missing \"]\"" ;
2454 TLatex::TLatexFormSize TLatex::FirstParse(Double_t angle, Double_t size,
const Char_t *text)
2458 fTabSize =
new FormSize_t[fTabMax];
2466 Short_t lineW = GetLineWidth();
2467 Int_t lineC = GetLineColor();
2470 spec.fAngle = angle;
2471 if (fTextFont%10 == 3) {
2472 Double_t hw = TMath::Max((Double_t)gPad->XtoPixel(gPad->GetX2()),
2473 (Double_t)gPad->YtoPixel(gPad->GetY1()));
2474 spec.fSize = size/hw;
2478 spec.fColor = GetTextColor();
2479 spec.fFont = GetTextFont();
2480 Short_t halign = fTextAlign/10;
2481 Short_t valign = fTextAlign - 10*halign;
2483 TLatexFormSize fs = Anal1(spec,text,strlen(text));
2486 SetTextAngle(angle);
2487 SetTextFont(spec.fFont);
2488 SetTextColor(spec.fColor);
2489 SetTextAlign(valign+10*halign);
2490 SetLineWidth(lineW);
2491 SetLineColor(lineC);
2498 Double_t TLatex::GetHeight()
const
2500 Double_t w = gPad->GetAbsWNDC()*Double_t(gPad->GetWw());
2501 Double_t h = gPad->GetAbsHNDC()*Double_t(gPad->GetWh());
2511 Double_t TLatex::GetXsize()
2513 if (!gPad)
return 0;
2514 TString newText = GetTitle();
2515 if( newText.Length() == 0)
return 0;
2518 if ( newText.Contains(
"\\") ) {
2519 TMathText tm(0., 0., newText.Data());
2520 return tm.GetXsize();
2524 if (CheckLatexSyntax(newText)) {
2525 std::cout<<
"\n*ERROR<TLatex>: "<<fError<<std::endl;
2526 std::cout<<
"==> "<<GetTitle()<<std::endl;
2531 const Char_t *text = newText.Data() ;
2532 Double_t angle_old = GetTextAngle();
2533 TLatexFormSize fs = FirstParse(0,GetTextSize(),text);
2534 SetTextAngle(angle_old);
2536 return TMath::Abs(gPad->AbsPixeltoX(Int_t(fs.Width())) - gPad->AbsPixeltoX(0));
2542 void TLatex::GetBoundingBox(UInt_t &w, UInt_t &h, Bool_t angle)
2545 TString newText = GetTitle();
2546 if( newText.Length() == 0)
return;
2549 if ( newText.Contains(
"\\") ) {
2550 TMathText tm(0., 0., newText.Data());
2551 tm.GetBoundingBox(w, h);
2556 if (CheckLatexSyntax(newText)) {
2557 std::cout<<
"\n*ERROR<TLatex>: "<<fError<<std::endl;
2558 std::cout<<
"==> "<<GetTitle()<<std::endl;
2564 Int_t cBoxX[4], cBoxY[4];
2566 if (TestBit(kTextNDC)) {
2567 ptx = gPad->UtoPixel(fX);
2568 pty = gPad->VtoPixel(fY);
2570 ptx = gPad->XtoAbsPixel(gPad->XtoPad(fX));
2571 pty = gPad->YtoAbsPixel(gPad->YtoPad(fY));
2573 GetControlBox(ptx, pty, fTextAngle, cBoxX, cBoxY);
2574 Int_t x1 = cBoxX[0];
2575 Int_t x2 = cBoxX[0];
2576 Int_t y1 = cBoxY[0];
2577 Int_t y2 = cBoxY[0];
2578 for (Int_t i=1; i<4; i++) {
2579 if (cBoxX[i] < x1) x1 = cBoxX[i];
2580 if (cBoxX[i] > x2) x2 = cBoxX[i];
2581 if (cBoxY[i] < y1) y1 = cBoxY[i];
2582 if (cBoxY[i] > y2) y2 = cBoxY[i];
2587 const Char_t *text = newText.Data() ;
2588 TLatexFormSize fs = FirstParse(GetTextAngle(),GetTextSize(),text);
2590 w = (UInt_t)fs.Width();
2591 h = (UInt_t)fs.Height();
2598 Double_t TLatex::GetYsize()
2600 if (!gPad)
return 0;
2601 TString newText = GetTitle();
2602 if( newText.Length() == 0)
return 0;
2605 if ( newText.Contains(
"\\") ) {
2606 TMathText tm(0., 0., newText.Data());
2607 return tm.GetYsize();
2611 if (CheckLatexSyntax(newText)) {
2612 std::cout<<
"\n*ERROR<TLatex>: "<<fError<<std::endl;
2613 std::cout<<
"==> "<<GetTitle()<<std::endl;
2618 const Char_t *text = newText.Data() ;
2619 Double_t angsav = fTextAngle;
2620 TLatexFormSize fs = FirstParse(0,GetTextSize(),text);
2621 fTextAngle = angsav;
2623 return TMath::Abs(gPad->AbsPixeltoY(Int_t(fs.Height())) - gPad->AbsPixeltoY(0));
2629 TLatex::TLatexFormSize TLatex::Readfs()
2632 TLatexFormSize result(fTabSize[fPos].fWidth,fTabSize[fPos].fOver,fTabSize[fPos].fUnder);
2639 void TLatex::Savefs(TLatex::TLatexFormSize *fs)
2641 fTabSize[fPos].fWidth = fs->Width();
2642 fTabSize[fPos].fOver = fs->Over();
2643 fTabSize[fPos].fUnder = fs->Under();
2645 if (fPos>=fTabMax) {
2647 FormSize_t *temp =
new FormSize_t[fTabMax+100];
2649 memcpy(temp,fTabSize,fTabMax*
sizeof(FormSize_t));
2661 void TLatex::SavePrimitive(std::ostream &out, Option_t * )
2665 if (gROOT->ClassSaved(TLatex::Class())) {
2671 TString s = GetTitle();
2673 s.ReplaceAll(
"\\",
"\\\\");
2674 s.ReplaceAll(
"\"",
"\\\"");
2675 out<<
" tex = new TLatex("<<fX<<
","<<fY<<
","<<quote<<s.Data()<<quote<<
");"<<std::endl;
2676 if (TestBit(kTextNDC)) out<<
"tex->SetNDC();"<<std::endl;
2678 SaveTextAttributes(out,
"tex",11,0,1,62,0.05);
2679 SaveLineAttributes(out,
"tex",1,1,1);
2681 out<<
" tex->Draw();"<<std::endl;
2687 void TLatex::SetIndiceSize(Double_t factorSize)
2689 fFactorSize = factorSize;
2695 void TLatex::SetLimitIndiceSize(Int_t limitFactorSize)
2697 fLimitFactorSize = limitFactorSize;