align = 10*HorizontalAlign + VerticalAlignFor horizontal alignment the following convention applies:
1=left adjusted, 2=centered, 3=right adjustedFor vertical alignment the following convention applies:
1=bottom adjusted, 2=centered, 3=top adjustedFor 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->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; }
{ 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; }
Mnemonic constants are available: <pre> kHAlignLeft = 10, kHAlignCenter = 20, kHAlignRight = 30, kVAlignBottom = 1, kVAlignCenter = 2, kVAlignTop = 3 </pre> They allow to write: <pre> object->SetTextAlign(kHAlignLeft+kVAlignTop); </pre>
text->SetTextColorAlpha(kBlue, 0.35);
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.
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 code = 10*fontnumber + precisionFont 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.
Unix.*.Root.UseTTFonts: trueIt is possible to check the TTF are in use in a Root session with the command:
gEnv->Print();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]
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)
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<=152; f+=10) { if (f!=142) drawtext(0.02,y, f,"ABCDEFGH abcdefgh 0123456789 @#$"); else drawtext(0.02,y, f,"ABCD efgh 01234 @#$"); y -= 0.065; } 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->SetTextSize(0.048); t->Draw(); }
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() |
void | Copy(TAttText& atttext) const |
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 TClass* | IsA() const |
virtual void | Modify() |
TAttText& | operator=(const TAttText&) |
virtual void | ResetAttText(Option_t* toption = "") |
virtual 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) |
virtual void | SetTextAlign(Short_t align = 11) |
virtual void | SetTextAngle(Float_t tangle = 0)MENU |
virtual void | SetTextAttributes()MENU |
virtual void | SetTextColor(Color_t tcolor = 1) |
virtual void | SetTextColorAlpha(Color_t tcolor, Float_t talpha) |
virtual void | SetTextFont(Font_t tfont = 62) |
virtual void | SetTextSize(Float_t tsize = 1) |
virtual void | SetTextSizePixels(Int_t npixels) |
virtual void | ShowMembers(TMemberInspector&) |
virtual void | Streamer(TBuffer&) |
void | StreamerNVirtual(TBuffer& ClassDef_StreamerNVirtual_b) |
AttText normal constructor. Text attributes are taken from the argument list.
Save text attributes as C++ statement(s) on output stream out.
Set a transparent marker color. talpha defines the percentage of the color opacity from 0. (fully transparent) to 1. (fully opaque).
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.