Logo ROOT  
Reference Guide

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
auto *Ta = new TCanvas("Ta","Ta",0,0,500,200);
auto *lv = new TLine;
lv->SetLineStyle(3); lv->SetLineColor(kBlue);
// Horizontal alignment.
auto *th1 = new TText(0.33,0.165,"Left adjusted");
th1->SetTextAlign(11); th1->SetTextSize(0.12);
auto *th2 = new TText(0.33,0.493,"Center adjusted");
th2->SetTextAlign(21); th2->SetTextSize(0.12);
auto *th3 = new TText(0.33,0.823,"Right adjusted");
th3->SetTextAlign(31); th3->SetTextSize(0.12);
// Vertical alignment.
auto *tv1 = new TText(0.66,0.165,"Bottom adjusted");
tv1->SetTextAlign(11); tv1->SetTextSize(0.12);
auto *tv2 = new TText(0.66,0.493,"Center adjusted");
tv2->SetTextAlign(12); tv2->SetTextSize(0.12);
auto *tv3 = new TText(0.66,0.823,"Top adjusted");
tv3->SetTextAlign(13); tv3->SetTextSize(0.12);

Mnemonic constants are available:

They allow to write:


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:

auto *Ta = new TCanvas("Ta","Text angle",0,0,300,326);
auto *l = new TLine();
auto *m = new TMarker();
auto *a = new TArc();
a->SetLineColor(kBlue); a->SetLineStyle(3);
a->DrawArc(0.1, 0.1, 0.2, 0.,45.,"only");
auto *tt = new TText(0.1,0.1,"Text angle is 45 degrees");
tt->SetTextAlign(11); tt->SetTextSize(0.1);
auto *t1 = new TLatex(0.3,0.18,"45^{o}");

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.

Color transparency

SetTextColorAlpha(), allows to set a transparent color. In the following example the text color of the text text is set to blue with a transparency of 35%. The color kBlue itself remains fully opaque.

The transparency is available on all platforms when the flag OpenGL.CanvasPreferGL is set to 1 in $ROOTSYS/etc/system.rootrc, or on Mac with the Cocoa backend. On the file output it is visible with PDF, PNG, Gif, JPEG, SVG, TeX ... but not PostScript.

Text Size

If the text precision (see next paragraph) is smaller than 3, the text size (textsize) is a fraction of the current pad size. Therefore the same textsize value can generate text outputs with different absolute sizes in two different pads. The text size in pixels (charheight) is computed the following way:

pad_width = gPad->XtoPixel(gPad->GetX2());
pad_height = gPad->YtoPixel(gPad->GetY1());
if (pad_width < pad_height) charheight = textsize*pad_width;
else charheight = textsize*pad_height;

If the text precision is equal to 3, the text size doesn't depend on the pad's dimensions. A given textsize value always generates the same absolute size. The text size (charheight) is given in pixels:

charheight = textsize;

Note that to scale fonts to the same size as the old True Type package a scale factor of 0.93376068 is apply to the text size before drawing.

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 (TTF) 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 with the command:

If the TTF are in use the following line will appear at the beginning of the printout given by this command:

Unix.*.Root.UseTTFonts: true [Global]

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"
15 : Symbol italic (derived from Symbol)

The following picture shows how each font looks. The number on the left is the "text font code". In this picture precision 2 was selected.

Definition at line 18 of file TAttText.h.

Public Member Functions

 TAttText ()
 AttText default constructor. More...
 TAttText (Int_t align, Float_t angle, Color_t color, Style_t font, Float_t tsize)
 AttText normal constructor. More...
virtual ~TAttText ()
 AttText destructor. More...
void Copy (TAttText &atttext) const
 Copy this text attributes to a new TAttText. More...
virtual void Modify ()
 Change current text attributes if necessary. More...
virtual void ResetAttText (Option_t *toption="")
 Reset this text attributes to default values. More...
virtual void SaveTextAttributes (std::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. More...
virtual void SetTextAttributes ()
 Invoke the DialogCanvas Text attributes. More...
virtual void SetTextColorAlpha (Color_t tcolor, Float_t talpha)
 Set a transparent marker color. More...
virtual void SetTextSizePixels (Int_t npixels)
 Set the text size in pixels. More...

Protected Attributes

Short_t fTextAlign
 Text alignment. More...
Float_t fTextAngle
 Text angle. More...
Color_t fTextColor
 Text color. More...
Font_t fTextFont
 Text font. More...
Float_t fTextSize
 Text size. More...

#include <TAttText.h>

Inheritance diagram for TAttText:

Constructor & Destructor Documentation

◆ TAttText() [1/2]

TAttText::TAttText ( )

AttText default constructor.

Default text attributes are taken from the current style.

Definition at line 254 of file TAttText.cxx.

◆ TAttText() [2/2]

TAttText::TAttText ( Int_t  align,
Float_t  angle,
Color_t  color,
Style_t  font,
Float_t  tsize 

AttText normal constructor.

Text attributes are taken from the argument list.

Definition at line 272 of file TAttText.cxx.

◆ ~TAttText()

TAttText::~TAttText ( )

AttText destructor.

Definition at line 284 of file TAttText.cxx.

Member Function Documentation

◆ Copy()

void TAttText::Copy ( TAttText atttext) const

Copy this text attributes to a new TAttText.

Definition at line 291 of file TAttText.cxx.

◆ Modify()

void TAttText::Modify ( )

Change current text attributes if necessary.

Definition at line 303 of file TAttText.cxx.

◆ ResetAttText()

void TAttText::ResetAttText ( Option_t toption = "")

Reset this text attributes to default values.

Reimplemented in TGWin32VirtualXProxy.

Definition at line 332 of file TAttText.cxx.

◆ SaveTextAttributes()

void TAttText::SaveTextAttributes ( std::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.

Definition at line 344 of file TAttText.cxx.

◆ SetTextAttributes()

void TAttText::SetTextAttributes ( )

Invoke the DialogCanvas Text attributes.

Reimplemented in TGWin32VirtualXProxy.

Definition at line 372 of file TAttText.cxx.

◆ SetTextColorAlpha()

void TAttText::SetTextColorAlpha ( Color_t  tcolor,
Float_t  talpha 

Set a transparent marker color.

talpha defines the percentage of the color opacity from 0. (fully transparent) to 1. (fully opaque).

Definition at line 382 of file TAttText.cxx.

◆ SetTextSizePixels()

void TAttText::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 percent of the pad size.

Reimplemented in TGWin32VirtualXProxy.

Definition at line 393 of file TAttText.cxx.

Member Data Documentation

◆ fTextAlign

Short_t TAttText::fTextAlign

Text alignment.

Definition at line 29 of file TAttText.h.

◆ fTextAngle

Float_t TAttText::fTextAngle

Text angle.

Definition at line 27 of file TAttText.h.

◆ fTextColor

Color_t TAttText::fTextColor

Text color.

Definition at line 30 of file TAttText.h.

◆ fTextFont

Font_t TAttText::fTextFont

Text font.

Definition at line 31 of file TAttText.h.

◆ fTextSize

Float_t TAttText::fTextSize

Text size.

Definition at line 28 of file TAttText.h.

The documentation for this class was generated from the following files:
auto * l
Definition: textangle.C:4
auto * m
Definition: textangle.C:8
auto * tt
Definition: textangle.C:16
Definition: TArc.h:26
Definition: TLine.h:22
R__EXTERN TEnv * gEnv
Definition: TEnv.h:171
@ kVAlignBottom
Definition: TAttText.h:53
ROOT::R::TRInterface & r
Definition: Object.C:4
@ kVAlignTop
Definition: TAttText.h:53
Definition: TTF.h:53
auto * tv3
Definition: textalign.C:34
Definition: TLatex.h:18
@ kHAlignRight
Definition: TAttText.h:52
auto * tv2
Definition: textalign.C:30
TText * text
Definition: entrylist_figure1.C:10
@ kHAlignCenter
Definition: TAttText.h:52
auto * lv
Definition: textalign.C:5
auto * tv1
Definition: textalign.C:26
auto * a
Definition: textangle.C:12
@ kHAlignLeft
Definition: TAttText.h:52
@ kRed
Definition: Rtypes.h:66
@ kVAlignCenter
Definition: TAttText.h:53
Definition: TText.h:22
Definition: TCanvas.h:23
auto * t1
Definition: textangle.C:20
auto * th2
Definition: textalign.C:17
virtual void SetTextColorAlpha(Color_t tcolor, Float_t talpha)
Set a transparent marker color.
Definition: TAttText.cxx:382
auto * th1
Definition: textalign.C:13
@ kBlue
Definition: Rtypes.h:66
#define gPad
Definition: TVirtualPad.h:287
Definition: TMarker.h:22
auto * th3
Definition: textalign.C:21
virtual void Print(Option_t *option="") const
Print all resources or the global, user or local resources separately.
Definition: TEnv.cxx:557
Definition: CocoaGuiTypes.h:10