Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TPadPainterPS.cxx
Go to the documentation of this file.
1// @(#)root/gl:$Id$
2// Author: Sergey Linev 04/03/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 <algorithm>
13#include <limits>
14#include <memory>
15#include <vector>
16
17#include "TPadPainterPS.h"
18#include "TVirtualPS.h"
19#include "TCanvas.h"
20#include "TPoint.h"
21#include "TError.h"
22#include "TImage.h"
23#include "TROOT.h"
24#include "TColor.h"
25#include "TMath.h"
26#include "TPad.h"
27
28/** \class TPadPainter
29\ingroup gpad
30
31Implement TVirtualPadPainter which abstracts painting operations.
32*/
33
34////////////////////////////////////////////////////////////////////////////////
35/// Consructor
36/// Assigns TVirtualPS instance which will be used by the painter
37
42
43/*
44Line/fill/etc. attributes can be set inside TPad, but not only where:
45many of them are set by base sub-objects of 2d primitives
46(2d primitives usually inherit TAttLine or TAttFill etc.). And these sub-objects
47call gVirtualPS->SetLineWidth ... etc. So, if I save some attributes in my painter,
48it will be mess - at any moment I do not know, where to take line attribute - from
49gVirtualX or from my own member. So! All attributed, _ALL_ go to gVirtualPS.
50At the same time attributes copy preserved in the painter -
51so actual value can be requested without asking of gVirtualPS instance
52*/
53
54
55////////////////////////////////////////////////////////////////////////////////
56/// Delegate to gVirtualPS.
57
59{
61 att.SetFillStyle(4000 + percent);
63}
64
65////////////////////////////////////////////////////////////////////////////////
66/// Provide fill attributes to gVirtualPS.
67
69{
71
72 auto fill = GetAttFillInternal(kTRUE);
73 fPS->SetFillColor(fill.GetFillColor());
74 fPS->SetFillStyle(fill.GetFillStyle());
75}
76
77////////////////////////////////////////////////////////////////////////////////
78/// Provide line attributes to gVirtualPS.
79
81{
83
84 fPS->SetLineColor(att.GetLineColor());
85 fPS->SetLineStyle(att.GetLineStyle());
86 fPS->SetLineWidth(att.GetLineWidth());
87}
88
89////////////////////////////////////////////////////////////////////////////////
90/// Provide marker attributes to gVirtualPS.
91
93{
95
96 fPS->SetMarkerColor(att.GetMarkerColor());
97 fPS->SetMarkerSize(att.GetMarkerSize());
98 fPS->SetMarkerStyle(att.GetMarkerStyle());
99}
100
101////////////////////////////////////////////////////////////////////////////////
102/// Provide text attributes to gVirtualPS.
103
105{
107
108 // TODO: in ROOT7 move text size handling directly to correspondent PS engine
109 // One not need to recalculate text size many time back and forth
110
111 Float_t tsize = 0.03;
112
113 if (fPad)
114 tsize = att.GetTextSizeRelative(*fPad);
115 else
116 Fatal("SetAttText", "Pad not set when invoke method");
117
118 fPS->SetTextAlign(att.GetTextAlign());
119 fPS->SetTextAngle(att.GetTextAngle());
120 fPS->SetTextColor(att.GetTextColor());
122 fPS->SetTextFont(att.GetTextFont());
123}
124
125
126////////////////////////////////////////////////////////////////////////////////
127/// Create a gVirtualX Pixmap - not implemented
128
133
134
135////////////////////////////////////////////////////////////////////////////////
136/// Clear the current gVirtualX window - noop for PS
137
141
142
143////////////////////////////////////////////////////////////////////////////////
144/// Copy a gVirtualX pixmap - not implemented
145
149
150
151////////////////////////////////////////////////////////////////////////////////
152/// Close the current gVirtualX pixmap - not implemented
153
157
158
159////////////////////////////////////////////////////////////////////////////////
160/// Select the window in which the graphics will go - not implemented
161
165
166
167////////////////////////////////////////////////////////////////////////////////
168/// Start new page on PS output
169
171{
172 fPS->NewPage();
173}
174
175
176
177////////////////////////////////////////////////////////////////////////////////
178///Noop, for non-gl pad TASImage calls gVirtualX->CopyArea.
179
180void TPadPainterPS::DrawPixels(const unsigned char * /*pixelData*/, UInt_t /*width*/, UInt_t /*height*/,
181 Int_t /*dstX*/, Int_t /*dstY*/, Bool_t /*enableAlphaBlending*/)
182{
183}
184
185
186////////////////////////////////////////////////////////////////////////////////
187/// Paint a simple line.
188
190{
191 if (GetAttLine().GetLineWidth() <= 0)
192 return;
193 Double_t x[2] = {x1, x2}, y[2] = {y1, y2};
194 fPS->DrawPS(2, x, y);
195}
196
197
198////////////////////////////////////////////////////////////////////////////////
199/// Paint a simple line in normalized coordinates.
200
202{
203 if (GetAttLine().GetLineWidth() <= 0)
204 return;
205
206 Double_t xw[2], yw[2];
207
208 xw[0] = (1 - u1) * fPad->GetX1() + u1 * fPad->GetX2();
209 xw[1] = (1 - u2) * fPad->GetX1() + u2 * fPad->GetX2();
210 yw[0] = (1 - v1) * fPad->GetY1() + v1 * fPad->GetY2();
211 yw[1] = (1 - v2) * fPad->GetY1() + v2 * fPad->GetY2();
212 fPS->DrawPS(2, xw, yw);
213}
214
215
216////////////////////////////////////////////////////////////////////////////////
217/// Paint a simple box.
218
220{
221 Int_t style0 = -1;
222
224 if (GetAttLine().GetLineWidth() <= 0)
225 return;
227 if (style0 > 0)
228 fPS->SetFillStyle(0);
229 } else if (fFullyTransparent)
230 return;
231
232 fPS->DrawBox(x1, y1, x2, y2);
233
234 if (style0 > 0)
236}
237
238////////////////////////////////////////////////////////////////////////////////
239/// Paint filled area.
240
242{
243 if (nPoints < 3) {
244 ::Error("TPadPainterPS::DrawFillArea", "invalid number of points %d", nPoints);
245 return;
246 }
247
248 if (!fFullyTransparent || (fPS->GetLineWidth() > 0))
249 fPS->DrawPS(-nPoints, const_cast<Double_t *>(xs), const_cast<Double_t *>(ys));
250}
251
252
253////////////////////////////////////////////////////////////////////////////////
254/// Paint filled area.
255
257{
258 if (nPoints < 3) {
259 ::Error("TPadPainterPS::DrawFillArea", "invalid number of points %d", nPoints);
260 return;
261 }
262
263 if (!fFullyTransparent || (fPS->GetLineWidth() > 0))
264 fPS->DrawPS(-nPoints, const_cast<Float_t *>(xs), const_cast<Float_t *>(ys));
265}
266
267////////////////////////////////////////////////////////////////////////////////
268/// Paint Polyline.
269
271{
272 if (GetAttLine().GetLineWidth() <= 0)
273 return;
274
275 if (n < 2) {
276 ::Error("TPadPainterPS::DrawPolyLine", "invalid number of points");
277 return;
278 }
279
280 fPS->DrawPS(n, const_cast<Double_t *>(xs), const_cast<Double_t *>(ys));
281}
282
283
284////////////////////////////////////////////////////////////////////////////////
285/// Paint polyline.
286
288{
289 if (GetAttLine().GetLineWidth() <= 0)
290 return;
291
292 if (n < 2) {
293 ::Error("TPadPainterPS::DrawPolyLine", "invalid number of points");
294 return;
295 }
296
297 fPS->DrawPS(n, const_cast<Float_t *>(xs), const_cast<Float_t *>(ys));
298}
299
300
301////////////////////////////////////////////////////////////////////////////////
302/// Paint polyline in normalized coordinates.
303
305{
306 if (GetAttLine().GetLineWidth() <= 0)
307 return;
308
309 if (n < 2) {
310 ::Error("TPadPainterPS::DrawPolyLineNDC", "invalid number of points %d", n);
311 return;
312 }
313
314 std::vector<Double_t> xw(n), yw(n);
315 for (Int_t i = 0; i < n; i++) {
316 xw[i] = (1 - u[i]) * fPad->GetX1() + u[i] * fPad->GetX2();
317 yw[i] = (1 - v[i]) * fPad->GetY1() + v[i] * fPad->GetY2();
318 }
319 fPS->DrawPS(n, xw.data(), yw.data());
320}
321
322////////////////////////////////////////////////////////////////////////////////
323/// Paint N segments on the pad
324
326{
327 if (GetAttLine().GetLineWidth() <= 0)
328 return;
329
330 if (n < 1) {
331 ::Error("TPadPainterPS::DrawSegments", "invalid number of segments %d", n);
332 return;
333 }
334
335 fPS->DrawSegments(n, x, y);
336}
337
338////////////////////////////////////////////////////////////////////////////////
339/// Paint N segments in normalized coordinates on the pad
340
342{
343 if (GetAttLine().GetLineWidth() <= 0)
344 return;
345
346 if (n < 1) {
347 ::Error("TPadPainterPS::DrawSegmentsNDC", "invalid number of segments %d", n);
348 return;
349 }
350 // recalculate values into normal coordiantes
351 for (Int_t i = 0; i < 2*n; i++) {
352 u[i] = (1 - u[i]) * fPad->GetX1() + u[i] * fPad->GetX2();
353 v[i] = (1 - v[i]) * fPad->GetY1() + v[i] * fPad->GetY2();
354 }
355 fPS->DrawSegments(n, u, v);
356}
357
358////////////////////////////////////////////////////////////////////////////////
359/// Paint polymarker.
360
362{
363 if (n < 1) {
364 ::Error("TPadPainterPS::DrawPolyMarker", "invalid number of points %d", n);
365 return;
366 }
367
368 fPS->DrawPolyMarker(n, const_cast<Double_t *>(x), const_cast<Double_t *>(y));
369}
370
371
372////////////////////////////////////////////////////////////////////////////////
373/// Paint polymarker.
374
376{
377 if (n < 1) {
378 ::Error("TPadPainterPS::DrawPolyMarker", "invalid number of points %d", n);
379 return;
380 }
381
382 fPS->DrawPolyMarker(n, const_cast<Float_t *>(x), const_cast<Float_t *>(y));
383}
384
385
386////////////////////////////////////////////////////////////////////////////////
387/// Paint text.
388
390{
391 fPS->Text(x, y, text);
392}
393
394
395////////////////////////////////////////////////////////////////////////////////
396/// Special version working with wchar_t and required by TMathText.
397
398void TPadPainterPS::DrawText(Double_t x, Double_t y, const wchar_t *text, ETextMode /* mode */)
399{
400 fPS->Text(x, y, text);
401}
402
403
404////////////////////////////////////////////////////////////////////////////////
405/// Drawint text with url link
406
407void TPadPainterPS::DrawTextUrl(Double_t x, Double_t y, const char *text, const char *url)
408{
409 fPS->TextUrl(x, y, text, url);
410}
411
412
413////////////////////////////////////////////////////////////////////////////////
414/// Paint text in normalized coordinates.
415
417{
418 Double_t x = (1 - u) * fPad->GetX1() + u * fPad->GetX2();
419 Double_t y = (1 - v) * fPad->GetY1() + v * fPad->GetY2();
420 fPS->Text(x, y, text);
421}
422
423
424////////////////////////////////////////////////////////////////////////////////
425/// Save the image displayed in the canvas pointed by "pad" into a binary file.
426
427void TPadPainterPS::SaveImage(TVirtualPad *, const char *, Int_t) const
428{
429}
430
431
432////////////////////////////////////////////////////////////////////////////////
433/// Paint text in normalized coordinates.
434
435void TPadPainterPS::DrawTextNDC(Double_t u, Double_t v, const wchar_t *text, ETextMode /* mode */)
436{
437 Double_t x = (1 - u) * fPad->GetX1() + u * fPad->GetX2();
438 Double_t y = (1 - v) * fPad->GetY1() + v * fPad->GetY2();
439 fPS->Text(x, y, text);
440}
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
void Fatal(const char *location, const char *msgfmt,...)
Use this function in case of a fatal error. It will abort the program.
Definition TError.cxx:267
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint percent
Option_t Option_t TPoint TPoint const char text
Option_t Option_t TPoint TPoint const char y1
Fill Area Attributes class.
Definition TAttFill.h:21
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition TAttFill.h:33
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:40
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition TAttFill.h:42
Line Attributes class.
Definition TAttLine.h:21
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition TAttLine.h:46
virtual Width_t GetLineWidth() const
Return the line width.
Definition TAttLine.h:38
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:47
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:44
Marker Attributes class.
Definition TAttMarker.h:21
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:41
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:43
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition TAttMarker.h:48
Text Attributes class.
Definition TAttText.h:21
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition TAttText.h:48
virtual void SetTextAngle(Float_t tangle=0)
Set the text angle.
Definition TAttText.h:49
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition TAttText.h:50
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition TAttText.h:52
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition TAttText.h:53
void SetAttFill(const TAttFill &att) override
Set fill attributes.
void SetAttText(const TAttText &att) override
Set text attributes.
const TAttFill & GetAttFill() const override
Width_t GetLineWidth() const override
Bool_t fFullyTransparent
if transformed fill attributes fully transparent
void SetAttMarker(const TAttMarker &att) override
Set marker attributes.
void SetAttLine(const TAttLine &att) override
Set line attributes.
TAttFill GetAttFillInternal(Bool_t with_transparency)
Returns fill attributes after modification Checks for special fill styles 4000 .
const TAttLine & GetAttLine() const override
Get line attributes.
void DrawPolyLineNDC(Int_t n, const Double_t *u, const Double_t *v) override
Paint polyline in normalized coordinates.
void DrawSegments(Int_t n, Double_t *x, Double_t *y) override
Paint N segments on the pad.
void ClearDrawable() override
Clear the current gVirtualX window - noop for PS.
void SetAttMarker(const TAttMarker &att) override
Provide marker attributes to gVirtualPS.
TVirtualPS * fPS
void DrawSegmentsNDC(Int_t n, Double_t *u, Double_t *v) override
Paint N segments in normalized coordinates on the pad.
void SetAttText(const TAttText &att) override
Provide text attributes to gVirtualPS.
void SaveImage(TVirtualPad *pad, const char *fileName, Int_t type) const override
Save the image displayed in the canvas pointed by "pad" into a binary file.
void DrawTextNDC(Double_t u, Double_t v, const char *text, ETextMode mode) override
Paint text in normalized coordinates.
void DrawLineNDC(Double_t u1, Double_t v1, Double_t u2, Double_t v2) override
Paint a simple line in normalized coordinates.
TPadPainterPS(TVirtualPS *ps)
Consructor Assigns TVirtualPS instance which will be used by the painter.
void NewPage() override
Start new page on PS output.
void DrawPixels(const unsigned char *pixelData, UInt_t width, UInt_t height, Int_t dstX, Int_t dstY, Bool_t enableAlphaBlending) override
Noop, for non-gl pad TASImage calls gVirtualX->CopyArea.
void DrawTextUrl(Double_t x, Double_t y, const char *text, const char *url) override
Drawint text with url link.
void SelectDrawable(Int_t device) override
Select the window in which the graphics will go - not implemented.
void DrawFillArea(Int_t n, const Double_t *x, const Double_t *y) override
Paint filled area.
void SetAttLine(const TAttLine &att) override
Provide line attributes to gVirtualPS.
void DrawPolyMarker(Int_t n, const Double_t *x, const Double_t *y) override
Paint polymarker.
void DrawText(Double_t x, Double_t y, const char *text, ETextMode mode) override
Paint text.
TVirtualPad * fPad
void SetOpacity(Int_t percent) override
Delegate to gVirtualPS.
void SetAttFill(const TAttFill &att) override
Provide fill attributes to gVirtualPS.
void DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2) override
Paint a simple line.
Int_t CreateDrawable(UInt_t w, UInt_t h) override
Create a gVirtualX Pixmap - not implemented.
void DestroyDrawable(Int_t device) override
Close the current gVirtualX pixmap - not implemented.
void DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, EBoxMode mode) override
Paint a simple box.
void CopyDrawable(Int_t device, Int_t px, Int_t py) override
Copy a gVirtualX pixmap - not implemented.
void DrawPolyLine(Int_t n, const Double_t *x, const Double_t *y) override
Paint Polyline.
TVirtualPS is an abstract interface to Postscript, PDF, SVG.
Definition TVirtualPS.h:30
virtual void Text(Double_t x, Double_t y, const char *string)=0
virtual void NewPage()=0
virtual void DrawPS(Int_t n, Float_t *xw, Float_t *yw)=0
virtual void DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2)=0
virtual void DrawPolyMarker(Int_t n, Float_t *x, Float_t *y)=0
virtual void DrawSegments(Int_t n, Double_t *xw, Double_t *yw)
Print N segments.
virtual void TextUrl(Double_t x, Double_t y, const char *string, const char *url)=0
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
virtual Double_t GetX2() const =0
virtual Double_t GetY1() const =0
virtual Double_t GetY2() const =0
virtual Double_t GetX1() const =0
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16