Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches

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);
Ta->Range(0,0,1,1);
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.
auto *th1 = new TText(0.33,0.165,"Left adjusted");
th1->SetTextAlign(11); th1->SetTextSize(0.12);
th1->Draw();
auto *th2 = new TText(0.33,0.493,"Center adjusted");
th2->SetTextAlign(21); th2->SetTextSize(0.12);
th2->Draw();
auto *th3 = new TText(0.33,0.823,"Right adjusted");
th3->SetTextAlign(31); th3->SetTextSize(0.12);
th3->Draw();
// Vertical alignment.
auto *tv1 = new TText(0.66,0.165,"Bottom adjusted");
tv1->SetTextAlign(11); tv1->SetTextSize(0.12);
tv1->Draw();
auto *tv2 = new TText(0.66,0.493,"Center adjusted");
tv2->SetTextAlign(12); tv2->SetTextSize(0.12);
tv2->Draw();
auto *tv3 = new TText(0.66,0.823,"Top adjusted");
tv3->SetTextAlign(13); tv3->SetTextSize(0.12);
tv3->Draw();
}
@ kBlue
Definition Rtypes.h:66
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition TAttLine.h:42
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:40
The Canvas class.
Definition TCanvas.h:23
Use the TLine constructor to create a simple line.
Definition TLine.h:22
virtual TLine * DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Draw this line with new coordinates.
Definition TLine.cxx:103
Base class for several text objects.
Definition TText.h:22
auto * th3
Definition textalign.C:22
TLine lv
Definition textalign.C:5
auto * tv3
Definition textalign.C:35
auto * th2
Definition textalign.C:18
auto * tv1
Definition textalign.C:27
auto * tv2
Definition textalign.C:31
auto * th1
Definition textalign.C:14

Mnemonic constants are available:

@ kVAlignTop
Definition TAttText.h:54
@ kVAlignCenter
Definition TAttText.h:54
@ kHAlignLeft
Definition TAttText.h:53
@ kVAlignBottom
Definition TAttText.h:54
@ kHAlignCenter
Definition TAttText.h:53
@ kHAlignRight
Definition TAttText.h:53

They allow to write:

object->SetTextAlign(kHAlignLeft+kVAlignTop);

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);
Ta->Range(0,0,1,1);
l.DrawLine(0.1,0.1,0.9,0.1);
l.DrawLine(0.1,0.1,0.9,0.9);
m.DrawMarker(0.1,0.1);
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);
tt->SetTextAngle(45);
tt->Draw();
auto *t1 = new TLatex(0.3,0.18,"45^{o}");
t1->Draw();
}
#define a(i)
Definition RSha256.hxx:99
@ kRed
Definition Rtypes.h:66
Create an Arc.
Definition TArc.h:26
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition TAttFill.h:39
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:38
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:40
To draw Mathematical Formula.
Definition TLatex.h:18
Manages Markers.
Definition TMarker.h:22
virtual TMarker * DrawMarker(Double_t x, Double_t y)
Draw this marker with new coordinates.
Definition TMarker.cxx:208
TMarker m
Definition textangle.C:8
TLine l
Definition textangle.C:4
auto * tt
Definition textangle.C:16
auto * t1
Definition textangle.C:20

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 an opacity of 35% (i.e. a transparency of 65%). (The color kBlue itself is internally stored as fully opaque.)

text->SetTextColorAlpha(kBlue, 0.35);
Option_t Option_t TPoint TPoint const char text

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.

Alternatively, you can call at the top of your script gSytle->SetCanvasPreferGL();. Or if you prefer to activate GL for a single canvas c, then use c->SetSupportGL(true);.

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;
Option_t Option_t textsize
#define gPad

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
Option_t Option_t fontnumber

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 X11 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. These days TTF fonts are rendered fast enough and can be used in all cases.

How to use True Type Fonts

TTF fonts are used by default. They can be deactivated via the following line in the .rootrc file:

Unix.*.Root.UseTTFonts: false

List of the currently supported fonts

Font number TTF Names PostScript/PDF Names
1 : "Free Serif Italic" "Times-Italic"
2 : "Free Serif Bold" "Times-Bold"
3 : "Free Serif Bold Italic" "Times-BoldItalic"
4 : "Tex Gyre Regular" "Helvetica"
5 : "Tex Gyre Italic" "Helvetica-Oblique"
6 : "Tex Gyre Bold" "Helvetica-Bold"
7 : "Tex Gyre Bold Italic" "Helvetica-BoldOblique"
8 : "Free Mono" "Courier"
9 : "Free Mono Oblique" "Courier-Oblique"
10 : "Free Mono Bold" "Courier-Bold"
11 : "Free Mono Bold Oblique" "Courier-BoldOblique"
12 : "Symbol" "Symbol"
13 : "Free Serif" "Times-Roman"
14 : "Wingdings" "ZapfDingbats"
Interface to the freetype 2 library.
Definition TTF.h:53

The PostScript and PDF backends use the original PostScript-defined 13 fonts' styles forming four type families (Courier, Helvetica, Times, Symbol) as listed in the "Core Font Set" section of this page. These fonts are always available and do not need to be loaded in the PS or PDF files allowing to keep the files' sizes small.

On screen, text is rendered using free TTF fonts similar to the PDF ones. The corresponding font files are coming with the ROOT distribution in $ROOTSYS/fonts/Free*.

Definition at line 18 of file TAttText.h.

Public Member Functions

 TAttText ()
 AttText default constructor.
 
 TAttText (Int_t align, Float_t angle, Color_t color, Style_t font, Float_t tsize)
 AttText normal constructor.
 
virtual ~TAttText ()
 AttText destructor.
 
void Copy (TAttText &atttext) const
 Copy this text attributes to a new TAttText.
 
virtual Short_t GetTextAlign () const
 Return the text alignment.
 
virtual Float_t GetTextAngle () const
 Return the text angle.
 
virtual Color_t GetTextColor () const
 Return the text color.
 
virtual Font_t GetTextFont () const
 Return the text font.
 
virtual Float_t GetTextSize () const
 Return the text size.
 
virtual Float_t GetTextSizePercent (Float_t size)
 Return the text in percent of the pad size.
 
virtual TClassIsA () const
 
virtual void Modify ()
 Change current text attributes if necessary.
 
virtual void ResetAttText (Option_t *toption="")
 Reset this text attributes to default values.
 
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.
 
virtual void SetTextAlign (Short_t align=11)
 Set the text alignment.
 
virtual void SetTextAngle (Float_t tangle=0)
 Set the text angle.
 
virtual void SetTextAttributes ()
 Invoke the DialogCanvas Text attributes.
 
virtual void SetTextColor (Color_t tcolor=1)
 Set the text color.
 
virtual void SetTextColorAlpha (Color_t tcolor, Float_t talpha)
 Set a transparent text color.
 
virtual void SetTextFont (Font_t tfont=62)
 Set the text font.
 
virtual void SetTextSize (Float_t tsize=1)
 Set the text size.
 
virtual void SetTextSizePixels (Int_t npixels)
 Set the text size in pixel.
 
virtual void Streamer (TBuffer &)
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 

Static Public Member Functions

static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static const char * DeclFileName ()
 

Protected Attributes

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

#include <TAttText.h>

Inheritance diagram for TAttText:
[legend]

Constructor & Destructor Documentation

◆ TAttText() [1/2]

TAttText::TAttText ( )

AttText default constructor.

Default text attributes are taken from the current style.

Definition at line 257 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 275 of file TAttText.cxx.

◆ ~TAttText()

TAttText::~TAttText ( )
virtual

AttText destructor.

Definition at line 287 of file TAttText.cxx.

Member Function Documentation

◆ Class()

static TClass * TAttText::Class ( )
static
Returns
TClass describing this class

◆ Class_Name()

static const char * TAttText::Class_Name ( )
static
Returns
Name of this class

◆ Class_Version()

static constexpr Version_t TAttText::Class_Version ( )
inlinestaticconstexpr
Returns
Version of this class

Definition at line 50 of file TAttText.h.

◆ Copy()

void TAttText::Copy ( TAttText atttext) const

Copy this text attributes to a new TAttText.

Definition at line 294 of file TAttText.cxx.

◆ DeclFileName()

static const char * TAttText::DeclFileName ( )
inlinestatic
Returns
Name of the file containing the class declaration

Definition at line 50 of file TAttText.h.

◆ GetTextAlign()

virtual Short_t TAttText::GetTextAlign ( ) const
inlinevirtual

Return the text alignment.

Reimplemented in TGWin32VirtualXProxy, and TWebPadPainter.

Definition at line 32 of file TAttText.h.

◆ GetTextAngle()

virtual Float_t TAttText::GetTextAngle ( ) const
inlinevirtual

Return the text angle.

Reimplemented in TGWin32VirtualXProxy, and TWebPadPainter.

Definition at line 33 of file TAttText.h.

◆ GetTextColor()

virtual Color_t TAttText::GetTextColor ( ) const
inlinevirtual

Return the text color.

Reimplemented in TGWin32VirtualXProxy, and TWebPadPainter.

Definition at line 34 of file TAttText.h.

◆ GetTextFont()

virtual Font_t TAttText::GetTextFont ( ) const
inlinevirtual

Return the text font.

Reimplemented in TGWin32VirtualXProxy, and TWebPadPainter.

Definition at line 35 of file TAttText.h.

◆ GetTextSize()

virtual Float_t TAttText::GetTextSize ( ) const
inlinevirtual

Return the text size.

Reimplemented in TGWin32VirtualXProxy, and TWebPadPainter.

Definition at line 36 of file TAttText.h.

◆ GetTextSizePercent()

Float_t TAttText::GetTextSizePercent ( Float_t  size)
virtual

Return the text in percent of the pad size.

If the font precision is greater than 2, the text size returned is the size in pixel converted into percent of the pad size, otherwise the size returned is the same as the size given as input parameter.

Definition at line 310 of file TAttText.cxx.

◆ IsA()

◆ Modify()

void TAttText::Modify ( )
virtual

Change current text attributes if necessary.

Definition at line 329 of file TAttText.cxx.

◆ ResetAttText()

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

Reset this text attributes to default values.

Reimplemented in TGWin32VirtualXProxy.

Definition at line 361 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 
)
virtual

Save text attributes as C++ statement(s) on output stream out.

Definition at line 373 of file TAttText.cxx.

◆ SetTextAlign()

virtual void TAttText::SetTextAlign ( Short_t  align = 11)
inlinevirtual

Set the text alignment.

Reimplemented in TWebPadPainter, TVirtualX, TGQuartz, TGWin32, TGWin32VirtualXProxy, and TGX11.

Definition at line 42 of file TAttText.h.

◆ SetTextAngle()

virtual void TAttText::SetTextAngle ( Float_t  tangle = 0)
inlinevirtual

Set the text angle.

Reimplemented in TWebPadPainter, TGWin32VirtualXProxy, and TGraphNode.

Definition at line 43 of file TAttText.h.

◆ SetTextAttributes()

void TAttText::SetTextAttributes ( )
virtual

Invoke the DialogCanvas Text attributes.

Reimplemented in TGWin32VirtualXProxy.

Definition at line 400 of file TAttText.cxx.

◆ SetTextColor()

virtual void TAttText::SetTextColor ( Color_t  tcolor = 1)
inlinevirtual

Set the text color.

Reimplemented in TVirtualX, TGQuartz, TGWin32, TGX11, TPDF, TPostScript, TSVG, TTeXDump, TGWin32VirtualXProxy, and TWebPadPainter.

Definition at line 44 of file TAttText.h.

◆ SetTextColorAlpha()

void TAttText::SetTextColorAlpha ( Color_t  tcolor,
Float_t  talpha 
)
virtual

Set a transparent text color.

Parameters
tcolordefines the text color
talphadefines the percentage of opacity from 0. (fully transparent) to 1. (fully opaque).
Note
talpha is ignored (treated as 1) if the TCanvas has no GL support activated.

Definition at line 412 of file TAttText.cxx.

◆ SetTextFont()

virtual void TAttText::SetTextFont ( Font_t  tfont = 62)
inlinevirtual

Set the text font.

Reimplemented in TVirtualX, TGQuartz, TGWin32, TGX11, TGX11TTF, TGWin32VirtualXProxy, and TWebPadPainter.

Definition at line 46 of file TAttText.h.

◆ SetTextSize()

virtual void TAttText::SetTextSize ( Float_t  tsize = 1)
inlinevirtual

Set the text size.

Reimplemented in TVirtualX, TGQuartz, TGWin32, TGX11, TGX11TTF, TGWin32VirtualXProxy, and TWebPadPainter.

Definition at line 47 of file TAttText.h.

◆ SetTextSizePixels()

void TAttText::SetTextSizePixels ( Int_t  npixels)
virtual

Set the text size in pixel.

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, and TWebPadPainter.

Definition at line 423 of file TAttText.cxx.

◆ Streamer()

◆ StreamerNVirtual()

void TAttText::StreamerNVirtual ( TBuffer ClassDef_StreamerNVirtual_b)
inline

Definition at line 50 of file TAttText.h.

Member Data Documentation

◆ fTextAlign

Short_t TAttText::fTextAlign
protected

Text alignment.

Definition at line 23 of file TAttText.h.

◆ fTextAngle

Float_t TAttText::fTextAngle
protected

Text angle.

Definition at line 21 of file TAttText.h.

◆ fTextColor

Color_t TAttText::fTextColor
protected

Text color.

Definition at line 24 of file TAttText.h.

◆ fTextFont

Font_t TAttText::fTextFont
protected

Text font.

Definition at line 25 of file TAttText.h.

◆ fTextSize

Float_t TAttText::fTextSize
protected

Text size.

Definition at line 22 of file TAttText.h.

Libraries for TAttText:

The documentation for this class was generated from the following files: