class TAttText


Text Attributes class

This class is used (in general by secondary inheritance) by many other classes (graphics, histograms). It holds all the text attributes.

Text attributes

Text attributes are:

Text Alignment

The text alignment is an integer number (align) allowing to control the horizontal and vertical position of the text string with respect to the text position. The text alignment of any class inheriting from TAttText can be changed using the method SetTextAlign and retrieved using the method GetTextAlign.
   align = 10*HorizontalAlign + VerticalAlign
For Horizontal alignment the following convention applies:
   1=left adjusted, 2=centered, 3=right adjusted
For Vertical alignment the following convention applies:
   1=bottom adjusted, 2=centered, 3=top adjusted
For example:
   align = 11 = left adjusted and bottom adjusted
   align = 32 = right adjusted and vertically centered
output of MACRO_TAttText_1_Ta
{
   TCanvas *Ta = new TCanvas("Ta","Ta",0,0,500,200);
   Ta->Range(0,0,1,1);

   TLine *lv = new TLine;
   lv->SetLineStyle(3); lv->SetLineColor(kBlue);
   lv->DrawLine(0.33,0.0,0.33,1.0);
   lv->DrawLine(0.6,0.165,1.,0.165);
   lv->DrawLine(0.6,0.493,1.,0.493);
   lv->DrawLine(0.6,0.823,1.,0.823);

   // Horizontal alignment.
   TText *th1 = new TText(0.33,0.165,"Left adjusted");
   th1->SetTextAlign(11); th1->SetTextSize(0.12);
   th1->Draw();

   TText *th2 = new TText(0.33,0.493,"Center adjusted");
   th2->SetTextAlign(21); th2->SetTextSize(0.12);
   th2->Draw();

   TText *th3 = new TText(0.33,0.823,"Right adjusted");
   th3->SetTextAlign(31); th3->SetTextSize(0.12);
   th3->Draw();

   // Vertical alignment.
   TText *tv1 = new TText(0.66,0.165,"Bottom adjusted");
   tv1->SetTextAlign(11); tv1->SetTextSize(0.12);
   tv1->Draw();

   TText *tv2 = new TText(0.66,0.493,"Center adjusted");
   tv2->SetTextAlign(12); tv2->SetTextSize(0.12);
   tv2->Draw();
   
   TText *tv3 = new TText(0.66,0.823,"Top adjusted");
   tv3->SetTextAlign(13); tv3->SetTextSize(0.12);
   tv3->Draw();
   
   return Ta;
}

Text Angle

Text angle in degrees. The text angle of any class inheriting from TAttText can be changed using the method SetTextAngle and retrieved using the method GetTextAngle. The following picture shows the text angle:
output of MACRO_TAttText_3_Ta
{
   TCanvas *Ta = new TCanvas("Ta","Text angle",0,0,300,326);
   Ta->Range(0,0,1,1);
   TLine *l = new TLine();
   l->SetLineColor(kRed);
   l->DrawLine(0.1,0.1,0.9,0.1);
   l->DrawLine(0.1,0.1,0.9,0.9);
   TMarker *m = new TMarker();
   m->SetMarkerStyle(20);
   m->SetMarkerColor(kBlue);
   m->DrawMarker(0.1,0.1);
   TArc *a = new TArc();
   a->SetFillStyle(0);
   a->SetLineColor(kBlue); a->SetLineStyle(3);
   a->DrawArc(0.1, 0.1, 0.2, 0.,45.,"only");
   TText *tt = new TText(0.1,0.1,"Text angle is 45 degrees");
   tt->SetTextAlign(11); tt->SetTextSize(0.1);
   tt->SetTextAngle(45);
   tt->Draw();
   TLatex *t1 = new TLatex(0.3,0.18,"45^{o}");
   t1->Draw();
   return Ta;
}

Text Color

The text color is a color index (integer) pointing in the ROOT color table. The text color of any class inheriting from TAttText can be changed using the method SetTextColor and retrieved using the method GetTextColor. The following table shows the first 50 default colors.
output of MACRO_TAttText_5_c
{
   TCanvas *c = new TCanvas("c","Text colors",0,0,500,200);
   c.DrawColorTable();
   return c;
}

Text Size

If the text precision (see next paragraph) is smaller than 3, the text size is expressed in percentage of the current pad height. The textsize in pixels (say charheight) will be:
   charheight = textsize*canvas_height   if current pad is horizontal.
   charheight = textsize*canvas_width    if current pad is vertical.
If the text precision is equal to 3, the character size is given in pixel:
   charheight = number of pixels
The text size of any class inheriting from TAttText can be changed using the method SetTextSize and retrieved using the method GetTextSize.

Text Font and Precision

The text font code is combination of the font number and the precision.
   Text font code = 10*fontnumber + precision
Font numbers must be between 1 and 14.

The precision can be:
precision = 0 fast hardware fonts (steps in the size)
precision = 1 scalable and rotatable hardware fonts (see below)
precision = 2 scalable and rotatable hardware fonts
precision = 3 scalable and rotatable hardware fonts. Text size is given in pixels.

The text font and precision of any class inheriting from TAttText can be changed using the method SetTextFont and retrieved using the method GetTextFont.

Font quality and speed

When precision 0 is used, only the original non-scaled system fonts are used. The fonts have a minimum (4) and maximum (37) size in pixels. These fonts are fast and are of good quality. Their size varies with large steps and they cannot be rotated. Precision 1 and 2 fonts have a different behaviour depending if the True Type Fonts are used or not. If TTF are used, you always get very good quality scalable and rotatable fonts. However TTF are slow.

How to use True Type Fonts

One can activate the TTF by adding (or activating) the following line in the .rootrc file:
   Unix.*.Root.UseTTFonts:     true
It is possible to check the TTF are in use in a Root session. When the TTF is active, the following message is displayed at the start of the session:
   "FreeType Engine vX.X.X used to render TrueType fonts."
It is also possible to check it with the command gEnv->Print().

List of the currently supported fonts

   Font number         X11 Names             Win32/TTF Names
       1 :       times-medium-i-normal      "Times New Roman"
       2 :       times-bold-r-normal        "Times New Roman"
       3 :       times-bold-i-normal        "Times New Roman"
       4 :       helvetica-medium-r-normal  "Arial"
       5 :       helvetica-medium-o-normal  "Arial"
       6 :       helvetica-bold-r-normal    "Arial"
       7 :       helvetica-bold-o-normal    "Arial"
       8 :       courier-medium-r-normal    "Courier New"
       9 :       courier-medium-o-normal    "Courier New"
      10 :       courier-bold-r-normal      "Courier New"
      11 :       courier-bold-o-normal      "Courier New"
      12 :       symbol-medium-r-normal     "Symbol"
      13 :       times-medium-r-normal      "Times New Roman"
      14 :                                  "Wingdings"
The following picture shows how each font looks like. The number on the left is the "Text font code". In this picture precision 2 was selected.
output of MACRO_TAttText_7_Tf
TCanvas * fonts()
{
   TCanvas *Tf = new TCanvas("Tf", "Tf",0,0,500,700);
   Tf->Range(0,0,1,1);
   Tf->SetBorderSize(2);
   Tf->SetFrameFillColor(0);
                                                                                
   double y = 0.95;
   for (int f = 12; f<=142; f+=10) {
      if (f<142) drawtext(0.02,y, f,"ABCDFGF abcdefgh 0123456789 @#$");
      else drawtext(0.02,y, f,"ABCD efgh 01234 @#$");
      y- = 0.07;
   }
   return Tf;
}

void drawtext(double x, double y, int f, char *s)
{
   TLatex *t = new TLatex(x,y,Form("#font[41]{%d :} %s",f,s));
   t->SetTextFont(f);
   t->SetTextAlign(12);
   t->Draw();
}
 

Function Members (Methods)

public:
TAttText()
TAttText(const TAttText&)
TAttText(Int_t align, Float_t angle, Color_t color, Style_t font, Float_t tsize)
virtual~TAttText()
static TClass*Class()
voidCopy(TAttText& atttext) const
virtual Short_tGetTextAlign() const
virtual Float_tGetTextAngle() const
virtual Color_tGetTextColor() const
virtual Font_tGetTextFont() const
virtual Float_tGetTextSize() const
virtual TClass*IsA() const
virtual voidModify()
TAttText&operator=(const TAttText&)
virtual voidResetAttText(Option_t* toption = "")
virtual voidSaveTextAttributes(ostream& out, const char* name, Int_t alidef = 12, Float_t angdef = 0, Int_t coldef = 1, Int_t fondef = 61, Float_t sizdef = 1)
virtual voidSetTextAlign(Short_t align = 11)
virtual voidSetTextAngle(Float_t tangle = 0)MENU
virtual voidSetTextAttributes()MENU
virtual voidSetTextColor(Color_t tcolor = 1)
virtual voidSetTextFont(Font_t tfont = 62)
virtual voidSetTextSize(Float_t tsize = 1)
virtual voidSetTextSizePixels(Int_t npixels)
virtual voidShowMembers(TMemberInspector& insp, char* parent)
virtual voidStreamer(TBuffer& b)
voidStreamerNVirtual(TBuffer& b)

Data Members

protected:
Short_tfTextAlignText alignment
Float_tfTextAngleText angle
Color_tfTextColorText color index
Font_tfTextFontText font number
Float_tfTextSizeText size

Class Charts

Inheritance Inherited Members Includes Libraries
Class Charts

Function documentation

TAttText(const TAttText& )
 AttText default constructor.

 Default text attributes are taking from the current style.
TAttText(Int_t align, Float_t angle, Color_t color, Style_t font, Float_t tsize)
 AttText normal constructor.

 Text attributes are taking from the argument list.
~TAttText()
 AttText destructor.
void Copy(TAttText& atttext) const
 Copy this text attributes to a new TAttText.
void Modify()
 Change current text attributes if necessary.
void ResetAttText(Option_t* toption = "")
 Reset this text attributes to default values.
void SaveTextAttributes(ostream& out, const char* name, Int_t alidef = 12, Float_t angdef = 0, Int_t coldef = 1, Int_t fondef = 61, Float_t sizdef = 1)
 Save text attributes as C++ statement(s) on output stream out.
void SetTextAttributes()
 Invoke the DialogCanvas Text attributes.
void SetTextSizePixels(Int_t npixels)
 Set the text size in pixels.
 If the font precision is greater than 2, the text size is set to npixels,
 otherwise the text size is computed as a per cent of the pad size.
TAttText(const TAttText& )
Short_t GetTextAlign()
{return fTextAlign;}
Float_t GetTextAngle()
{return fTextAngle;}
Color_t GetTextColor()
{return fTextColor;}
Font_t GetTextFont()
{return fTextFont;}
Float_t GetTextSize()
{return fTextSize;}
void SetTextAlign(Short_t align = 11)
{ fTextAlign = align;}
void SetTextAngle(Float_t tangle = 0)
{ fTextAngle = tangle;}
void SetTextColor(Color_t tcolor = 1)
{ fTextColor = tcolor;}
void SetTextFont(Font_t tfont = 62)
{ fTextFont = tfont;}
void SetTextSize(Float_t tsize = 1)
{ fTextSize = tsize;}

Author: Rene Brun 12/12/94
Last change: root/base:$Id: TAttText.h 20877 2007-11-19 11:17:07Z rdm $
Last generated: 2008-06-25 08:34
Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.