Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TPadPainterBase.cxx
Go to the documentation of this file.
1// @(#)root/gpad:$Id$
2// Author: Sergey Linev 17/04/2026
3
4/*************************************************************************
5 * Copyright (C) 1995-2026, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "TPadPainterBase.h"
13#include "TColor.h"
14
15#include "TVirtualX.h"
16#include "TVirtualPad.h"
17#include "TMathBase.h"
18#include "TError.h"
19#include "TTFhandle.h"
20
21/** \class TPadPainterBase
22\ingroup gpad
23
24Extends TVirtualPadPainter interface to simplify work with graphical attributes
25
26Plus for now central place for TTF handling
27*/
28
29////////////////////////////////////////////////////////////////////////////////
30/// Returns fill attributes after modification
31/// Checks for special fill styles 4000 .. 4100
32
34{
35 Style_t style = GetAttFill().GetFillStyle();
36 Color_t color = GetAttFill().GetFillColor();
37
38 fFullyTransparent = (style == 4000) || (style == 0);
40 style = 0;
41 } else if ((style > 4000) && (style <= 4100)) {
42 if ((style < 4100) && with_transparency)
43 color = TColor::GetColorTransparent(color, (style - 4000) / 100.);
44 style = 1001;
45 }
46
47 return { color, style };
48}
49
50////////////////////////////////////////////////////////////////////////////////
51/// Returns text extend
52
54{
55 Bool_t res = kFALSE;
56
57 if (!HasTTFonts() && gVirtualX)
58 res = gVirtualX->GetTextExtentA(font, size, w, h, mess);
59
60 if (!res) {
62 ttf.SetTextFont(font);
63 ttf.SetTextSize(size * GetTTFScale());
64 ttf.GetTextExtent(w, h, mess);
65 }
66}
67
68////////////////////////////////////////////////////////////////////////////////
69/// Returns text extend
70
72{
73 Bool_t res = kFALSE;
74
75 if (!HasTTFonts() && gVirtualX)
76 res = gVirtualX->GetTextExtentA(font, size, w, h, mess);
77
78 if (!res) {
80 ttf.SetTextFont(font);
81 ttf.SetTextSize(size * GetTTFScale());
82 ttf.GetTextExtent(w, h, mess);
83 }
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// Returns text accent / descent
88
90{
91 Bool_t res = kFALSE;
92
93 if (!HasTTFonts() && gVirtualX) {
94 res = gVirtualX->GetFontAscentDescent(font, size, a, d, mess);
95 if (res & !a) {
96 UInt_t w = 0;
97 gVirtualX->GetTextExtentA(font, size, w, a, mess);
98 }
99 }
100
101 if (!res) {
103 ttf.SetTextFont(font);
104 ttf.SetTextSize(size * GetTTFScale());
105 UInt_t w, h;
106 ttf.GetTextExtent(w, h, mess);
107 a = ttf.GetBoxYMax();
108 d = TMath::Abs(ttf.GetBoxYMin());
109 }
110}
111
112////////////////////////////////////////////////////////////////////////////////
113/// Returns text accent / descent
114
116{
117 Bool_t res = kFALSE;
118
119 // special use case for MacOS - directly use TTF
120 if (!HasTTFonts() && !IsCocoa() && gVirtualX) {
121 res = gVirtualX->GetFontAscentDescent(font, size, a, d, "");
122 if (res & !a) {
123 UInt_t w = 0;
124 gVirtualX->GetTextExtentA(font, size, w, a, mess);
125 }
126 }
127
128 if (!res) {
130 ttf.SetTextFont(font);
131 ttf.SetTextSize(size * GetTTFScale());
132 UInt_t w, h;
133 ttf.GetTextExtent(w, h, mess);
134 a = ttf.GetBoxYMax();
135 d = TMath::Abs(ttf.GetBoxYMin());
136 }
137}
138
139////////////////////////////////////////////////////////////////////////////////
140/// Returns text advance
141
143{
144 if (!HasTTFonts() && gVirtualX) {
145 UInt_t a = 0, h;
146 if (gVirtualX->GetTextExtentA(font, size, a, h, mess))
147 return a;
148 }
149
151 ttf.SetTextFont(font);
152 ttf.SetTextSize(size * GetTTFScale());
153 ttf.SetKerning(kern);
154
155 UInt_t a = 0;
156 ttf.GetTextAdvance(a, mess);
157 return a;
158}
159
160////////////////////////////////////////////////////////////////////////////////
161/// Performs rendering of TTF glyphs on output device
162/// Can be implemented in derived classes instead of implementing
163/// 4 different signatures of DrawText
164
168
169////////////////////////////////////////////////////////////////////////////////
170/// Paint text.
171
173{
174 Int_t px = fPad->XtoPixel(x);
175 Int_t py = fPad->YtoPixel(y);
176 const TAttText &att = GetAttText();
177
178 if (HasTTFonts()) {
180 ttf.SetTextFont(att.GetTextFont());
181 ttf.SetTextSize(att.GetTextSizePixels(*fPad));
182 ttf.SetRotationMatrix(att.GetTextAngle());
183 ttf.PrepareString(text);
184 ttf.LayoutGlyphs();
185 if (ttf.ApplyAlignRotate(px, py, att.GetTextAlign(), fPad->GetPadWidth(), fPad->GetPadHeight()))
186 DrawTTFglyphs(px, py, ttf, mode);
187 } else if (fWinContext && gVirtualX) {
188 gVirtualX->DrawTextW(fWinContext, px, py, att.GetTextAngle(), GetTextMagnitude(), text,
190 }
191}
192
193////////////////////////////////////////////////////////////////////////////////
194/// Paint wtext.
195
197{
198 Int_t px = fPad->XtoPixel(x);
199 Int_t py = fPad->YtoPixel(y);
200 const TAttText &att = GetAttText();
201
202 if (HasTTFonts()) {
204 ttf.SetTextFont(att.GetTextFont());
205 ttf.SetTextSize(att.GetTextSizePixels(*fPad));
206 ttf.SetRotationMatrix(att.GetTextAngle());
207 ttf.PrepareString(text);
208 ttf.LayoutGlyphs();
209 if (ttf.ApplyAlignRotate(px, py, att.GetTextAlign(), fPad->GetPadWidth(), fPad->GetPadHeight()))
210 DrawTTFglyphs(px, py, ttf, mode);
211 } else if (fWinContext && gVirtualX) {
212 gVirtualX->DrawTextW(fWinContext, px, py, att.GetTextAngle(), GetTextMagnitude(), text,
214 }
215}
216
217////////////////////////////////////////////////////////////////////////////////
218/// Paint text at NDC coordinates.
219
221{
222 Int_t px = fPad->UtoPixel(u);
223 Int_t py = fPad->VtoPixel(v);
224 const TAttText &att = GetAttText();
225
226 if (HasTTFonts()) {
228 ttf.SetTextFont(att.GetTextFont());
229 ttf.SetTextSize(att.GetTextSizePixels(*fPad));
230 ttf.SetRotationMatrix(att.GetTextAngle());
231 ttf.PrepareString(text);
232 ttf.LayoutGlyphs();
233 if (ttf.ApplyAlignRotate(px, py, att.GetTextAlign(), fPad->GetPadWidth(), fPad->GetPadHeight()))
234 DrawTTFglyphs(px, py, ttf, mode);
235 } else if (fWinContext && gVirtualX) {
236 gVirtualX->DrawTextW(fWinContext, px, py, att.GetTextAngle(), GetTextMagnitude(), text,
238 }
239}
240
241////////////////////////////////////////////////////////////////////////////////
242/// Paint wtext at NDC coordinates.
243
245{
246 Int_t px = fPad->UtoPixel(u);
247 Int_t py = fPad->VtoPixel(v);
248 const TAttText &att = GetAttText();
249
250 if (HasTTFonts()) {
252 ttf.SetTextFont(att.GetTextFont());
253 ttf.SetTextSize(att.GetTextSizePixels(*fPad));
254 ttf.SetRotationMatrix(att.GetTextAngle());
255 ttf.PrepareString(text);
256 ttf.LayoutGlyphs();
257 if (ttf.ApplyAlignRotate(px, py, att.GetTextAlign(), fPad->GetPadWidth(), fPad->GetPadHeight()))
258 DrawTTFglyphs(px, py, ttf, mode);
259 } else if (fWinContext && gVirtualX) {
260 gVirtualX->DrawTextW(fWinContext, px, py, att.GetTextAngle(), GetTextMagnitude(), text,
262 }
263}
#define d(i)
Definition RSha256.hxx:102
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
short Style_t
Style number (short)
Definition RtypesCore.h:97
short Color_t
Color number (short)
Definition RtypesCore.h:100
short Font_t
Font number (short)
Definition RtypesCore.h:96
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t style
Option_t Option_t TPoint TPoint const char text
#define gVirtualX
Definition TVirtualX.h:379
Fill Area Attributes class.
Definition TAttFill.h:21
Text Attributes class.
Definition TAttText.h:21
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition TColor.cxx:2195
void DrawTextNDC(Double_t u, Double_t v, const char *text, ETextMode mode) override
Paint text at NDC coordinates.
void GetTextExtent(Font_t font, Double_t size, UInt_t &w, UInt_t &h, const char *mess) override
Returns text extend.
const TAttText & GetAttText() const override
Get text attributes.
UInt_t GetTextAdvance(Font_t font, Double_t size, const char *text, Bool_t kern) override
Returns text advance.
const TAttFill & GetAttFill() const override
Get fill attributes.
Bool_t fFullyTransparent
if transformed fill attributes fully transparent
Float_t GetTextMagnitude() const override
void DrawText(Double_t x, Double_t y, const char *text, ETextMode mode) override
Paint text.
WinContext_t fWinContext
virtual Double_t GetTTFScale() const
TVirtualPad * fPad
TAttFill GetAttFillInternal(Bool_t with_transparency)
Returns fill attributes after modification Checks for special fill styles 4000 .
void GetTextAscentDescent(Font_t font, Double_t size, UInt_t &a, UInt_t &d, const char *mess) override
Returns text accent / descent.
virtual void DrawTTFglyphs(Int_t x, Int_t y, TTFhandle &ttf, ETextMode mode)
Performs rendering of TTF glyphs on output device Can be implemented in derived classes instead of im...
Dynamic handle to work with freetype 2 library.
Definition TTFhandle.h:21
virtual Bool_t HasTTFonts() const
virtual Bool_t IsCocoa() const
virtual Int_t YtoPixel(Double_t y) const =0
virtual UInt_t GetPadWidth() const =0
virtual Int_t VtoPixel(Double_t v) const =0
virtual UInt_t GetPadHeight() const =0
virtual Int_t XtoPixel(Double_t x) const =0
virtual Int_t UtoPixel(Double_t u) const =0
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:122