ROOT  6.06/09
Reference Guide
Public Member Functions | Protected Attributes | List of all members
TAttText Class Reference

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
{
TCanvas *Ta = new TCanvas("Ta","Ta",0,0,500,200);
Ta->Range(0,0,1,1);
TLine *lv = new TLine;
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;
}
TAttText_001.png

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:

TAttText_002.png

Mnemonic constants are available:

They allow to write:

object->SetTextAlign(kHAlignLeft+kVAlignTop);

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.

TAttText_003.png

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 flagOpenGL.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 ... 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:

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.

TAttText_004.png

Definition at line 32 of file TAttText.h.

Public Member Functions

 TAttText ()
 
 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 Short_t GetTextAlign () const
 
virtual Float_t GetTextAngle () const
 
virtual Color_t GetTextColor () const
 
virtual Font_t GetTextFont () const
 
virtual Float_t GetTextSize () const
 
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 SetTextAlign (Short_t align=11)
 
virtual void SetTextAngle (Float_t tangle=0)
 
virtual void SetTextColor (Color_t tcolor=1)
 
virtual void SetTextColorAlpha (Color_t tcolor, Float_t talpha)
 Set a transparent marker color. More...
 
virtual void SetTextFont (Font_t tfont=62)
 
virtual void SetTextSize (Float_t tsize=1)
 
virtual void SetTextSizePixels (Int_t npixels)
 Set the text size in pixels. More...
 

Protected Attributes

Float_t fTextAngle
 
Float_t fTextSize
 
Short_t fTextAlign
 
Color_t fTextColor
 
Font_t fTextFont
 

#include <TAttText.h>

+ Inheritance diagram for TAttText:

Constructor & Destructor Documentation

TAttText::TAttText ( )
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 ( )
virtual

AttText destructor.

Definition at line 284 of file TAttText.cxx.

Member Function Documentation

void TAttText::Copy ( TAttText atttext) const
virtual Short_t TAttText::GetTextAlign ( ) const
inlinevirtual
virtual Float_t TAttText::GetTextAngle ( ) const
inlinevirtual
virtual Color_t TAttText::GetTextColor ( ) const
inlinevirtual
virtual Font_t TAttText::GetTextFont ( ) const
inlinevirtual
virtual Float_t TAttText::GetTextSize ( ) const
inlinevirtual
void TAttText::Modify ( )
virtual
void TAttText::ResetAttText ( Option_t toption = "")
virtual

Reset this text attributes to default values.

Reimplemented in TGWin32VirtualXProxy.

Definition at line 332 of file TAttText.cxx.

Referenced by TStyle::Reset().

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
virtual void TAttText::SetTextAlign ( Short_t  align = 11)
inlinevirtual

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

Definition at line 55 of file TAttText.h.

Referenced by accents(), TPaveText::AddText(), alignment(), TLatex::Analyse(), bars(), box(), TDocLatexDirective::CreateLatex(), TMarker::DisplayMarkerTypes(), TGenerator::Draw(), TMVA::draw_input_labels(), TMVA::draw_network(), TGaxis::DrawAxis(), TPad::DrawClassObject(), TPad::DrawColorTable(), TMVA::DrawMLPoutputMovie(), TTreePlayer::DrawSelect(), drawtext(), TLatex::FirstParse(), fractions(), greekletters(), TInspectCanvas::InspectObject(), itbold(), kalman_do(), kerning(), mathsymbols(), TStyleManager::ModAttDateTextAlign(), TStyleManager::ModTextAlign(), TPaveStats::Paint(), TGraphNode::Paint(), TColorWheel::Paint(), TTreePerfStats::Paint(), TSpider::Paint(), TGaxis::PaintAxis(), TColorWheel::PaintCircle(), TColorWheel::PaintCircles(), TGLAxis::PaintGLAxisLabels(), TColorWheel::PaintGray(), TParallelCoordVar::PaintLabels(), TLatex::PaintLatex1(), TMathText::PaintMathText(), TButton::PaintModified(), TPaveLabel::PaintPaveLabel(), TGraphPolargram::PaintPolarDivisions(), TLegend::PaintPrimitives(), TPaveText::PaintPrimitives(), TColorWheel::PaintRectangles(), THistPainter::PaintStat(), THistPainter::PaintStat2(), THistPainter::PaintStat3(), TGraphPainter::PaintStats(), THistPainter::PaintText(), THistPainter::PaintTH2PolyText(), RooAbsPdf::paramOn(), TAttTextEditor::ProcessMessage(), TPaveText::ReadFile(), TMVA::regression_averagedevs(), TStyle::Reset(), roots(), TPaveText::SetAllWith(), TPad::SetAttTextPS(), TLegend::SetHeader(), TStyle::SetOptDate(), TGQuartz::SetTextAlign(), TGX11::SetTextAlign(), TGWin32::SetTextAlign(), TMemStatShow::Show(), slash(), splitline(), RooAbsData::statOn(), style(), subsupscript(), subsupscript2(), TImageDump::Text(), and TLegend::TLegend().

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

Invoke the DialogCanvas Text attributes.

Reimplemented in TGWin32VirtualXProxy.

Definition at line 372 of file TAttText.cxx.

Referenced by TLegend::EditEntryAttText(), and TPaveText::EditText().

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

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

Definition at line 57 of file TAttText.h.

Referenced by TPaveText::AddText(), TLatex::Analyse(), TMVA::boostcontrolplots(), TAttTextEditor::DoLiveAlpha(), TAttTextEditor::DoTextAlphaColor(), TPieEditor::DoTextChange(), TAttTextEditor::DoTextColor(), TGenerator::Draw(), TMVA::draw_input_labels(), TMVA::draw_layer_labels(), TMVA::draw_network(), TGaxis::DrawAxis(), TMVA::DrawCell(), TPad::DrawClassObject(), TPad::DrawColorTable(), TMVA::DrawMLPoutputMovie(), TMVA::StatDialogBDTReg::DrawNode(), TTreePlayer::DrawSelect(), TMVA::StatDialogBDTReg::DrawTree(), TMVA::StatDialogBDT::DrawTree(), TLatex::FirstParse(), TGaxis::ImportAxisAttributes(), TInspectCanvas::InspectObject(), kalman_do(), TStyleManager::ModAttDateTextColor(), TStyleManager::ModTextColor(), TPaveStats::Paint(), TGraphNode::Paint(), TColorWheel::Paint(), TPie::Paint(), TAxis3D::PaintAxis(), TGaxis::PaintAxis(), TColorWheel::PaintCircle(), TColorWheel::PaintCircles(), TGLAxis::PaintGLAxisLabels(), TGraphPainter::PaintGrapHist(), TGraphPainter::PaintGraphPolar(), TColorWheel::PaintGray(), TLatex::PaintLatex1(), TButton::PaintModified(), TPaveLabel::PaintPaveLabel(), TGraphPolargram::PaintPolarDivisions(), TLegend::PaintPrimitives(), TPaveText::PaintPrimitives(), TColorWheel::PaintRectangles(), THistPainter::PaintStat(), THistPainter::PaintStat2(), THistPainter::PaintStat3(), TGraphPainter::PaintStats(), THistPainter::PaintText(), THistPainter::PaintTH2PolyText(), THistPainter::PaintTitle(), TAttTextEditor::ProcessMessage(), TPaveText::ReadFile(), TPaveText::SetAllWith(), TPad::SetAttTextPS(), TLegend::SetHeader(), TGQuartz::SetTextColor(), TGX11::SetTextColor(), TGaxis::SetTitleColor(), TMemStatShow::Show(), TImageDump::Text(), TLegend::TLegend(), TPie::TPie(), TPaveStats::UseCurrentStyle(), TPaveText::UseCurrentStyle(), and TPad::UseCurrentStyle().

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

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.

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

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

Definition at line 59 of file TAttText.h.

Referenced by accents(), TPaveText::AddText(), alignment(), TLatex::Analyse(), bars(), TDocLatexDirective::CreateLatex(), TMarker::DisplayMarkerTypes(), TPieEditor::DoTextChange(), TGaxis::DrawAxis(), TPad::DrawClassObject(), TPad::DrawColorTable(), TTreePlayer::DrawSelect(), drawtext(), TLatex::FirstParse(), fractions(), TGaxis::ImportAxisAttributes(), TInspectCanvas::InspectObject(), itbold(), kerning(), TStyleManager::ModAttDateTextFont(), TStyleManager::ModAttDateTextSizeInPixels(), TStyleManager::ModTextFont(), TStyleManager::ModTextSizeInPixels(), TPaveStats::Paint(), TGraphNode::Paint(), TColorWheel::Paint(), TPie::Paint(), TAxis3D::PaintAxis(), TGaxis::PaintAxis(), TColorWheel::PaintCircles(), TGraphPainter::PaintGrapHist(), TGraphPainter::PaintGraphPolar(), TColorWheel::PaintGray(), TLatex::PaintLatex1(), TMathText::PaintMathText(), TButton::PaintModified(), TPaveLabel::PaintPaveLabel(), TGraphPolargram::PaintPolarDivisions(), TLegend::PaintPrimitives(), TPaveText::PaintPrimitives(), TColorWheel::PaintRectangles(), THistPainter::PaintStat(), THistPainter::PaintStat2(), THistPainter::PaintStat3(), TGraphPainter::PaintStats(), THistPainter::PaintText(), THistPainter::PaintTH2PolyText(), THistPainter::PaintTitle(), TAttTextEditor::ProcessMessage(), TPaveText::ReadFile(), roots(), TPaveText::SetAllWith(), TPad::SetAttTextPS(), TLegend::SetHeader(), TGQuartz::SetTextFont(), TGaxis::SetTitleFont(), slash(), splitline(), style(), subsupscript(), subsupscript2(), TImageDump::Text(), TPDF::Text(), TPostScript::Text(), TLegend::TLegend(), TPaveClass::TPaveClass(), TPie::TPie(), TPaveStats::UseCurrentStyle(), TPaveText::UseCurrentStyle(), and TPad::UseCurrentStyle().

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

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

Definition at line 60 of file TAttText.h.

Referenced by accents(), TPaveText::AddText(), alignment(), TLatex::Analyse(), bars(), TMVA::boostcontrolplots(), box(), TDialogCanvas::BuildStandardButtons(), TMVA::correlations(), TMVA::correlationsMultiClass(), TDocLatexDirective::CreateLatex(), TMarker::DisplayMarkerTypes(), TTextEditor::DoSize(), TPieEditor::DoTextChange(), TGenerator::Draw(), TMVA::draw_input_labels(), TMVA::draw_network(), TGaxis::DrawAxis(), TPad::DrawClassObject(), TPad::DrawColorTable(), TMVA::StatDialogMVAEffs::DrawHistograms(), TMVA::DrawMLPoutputMovie(), TTreePlayer::DrawSelect(), drawtext(), TText::ExecuteEvent(), TLatex::FirstParse(), fractions(), greekletters(), TInspectCanvas::InspectObject(), itbold(), kalman_do(), kerning(), mathsymbols(), TStyleManager::ModAttDateTextSize(), TStyleManager::ModAttDateTextSizeInPixels(), TStyleManager::ModTextSize(), TStyleManager::ModTextSizeInPixels(), TMVA::mvas(), TPaveStats::Paint(), TColorWheel::Paint(), TTreePerfStats::Paint(), TPie::Paint(), TSpider::Paint(), TGaxis::PaintAxis(), TColorWheel::PaintCircle(), TColorWheel::PaintCircles(), TClassTree::PaintClass(), TPad::PaintDate(), TGLAxis::PaintGLAxisLabels(), TGraphPainter::PaintGraphPolar(), TColorWheel::PaintGray(), TParallelCoordVar::PaintLabels(), TLatex::PaintLatex1(), TMathText::PaintMathText(), TButton::PaintModified(), TPaveLabel::PaintPaveLabel(), TLegend::PaintPrimitives(), TPaveText::PaintPrimitives(), TColorWheel::PaintRectangles(), THistPainter::PaintStat(), THistPainter::PaintStat2(), TGraphPainter::PaintStats(), THistPainter::PaintText(), THistPainter::PaintTH2PolyText(), THistPainter::PaintTitle(), RooAbsPdf::paramOn(), TAttTextEditor::ProcessMessage(), TPaveText::ReadFile(), TMVA::regression_averagedevs(), TStyle::Reset(), roots(), TPaveText::SetAllWith(), TPad::SetAttTextPS(), TLegend::SetHeader(), TGQuartz::SetTextSize(), TMemStatShow::Show(), slash(), splitline(), RooAbsData::statOn(), style(), subsupscript(), subsupscript2(), TImageDump::Text(), TPDF::Text(), TPostScript::Text(), TLegend::TLegend(), TPie::TPie(), TPaveStats::UseCurrentStyle(), TPaveText::UseCurrentStyle(), TMVA::variables(), and TMVA::variablesMultiClass().

void TAttText::SetTextSizePixels ( Int_t  npixels)
virtual

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

Short_t TAttText::fTextAlign
protected
Float_t TAttText::fTextAngle
protected
Color_t TAttText::fTextColor
protected
Font_t TAttText::fTextFont
protected
Float_t TAttText::fTextSize
protected

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