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{
60 TAttFill att = GetAttFill();
61 att.SetFillStyle(4000 + percent);
62 SetAttFill(att);
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());
121 fPS->SetTextSize(tsize);
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
223 if (mode == TVirtualPadPainter::kHollow) {
224 if (GetAttLine().GetLineWidth() <= 0)
225 return;
226 style0 = fPS->GetFillStyle();
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)
235 fPS->SetFillStyle(style0);
236}
237
238////////////////////////////////////////////////////////////////////////////////
239/// Paint filled area.
240
241void TPadPainterPS::DrawFillArea(Int_t nPoints, const Double_t *xs, const Double_t *ys)
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
256void TPadPainterPS::DrawFillArea(Int_t nPoints, const Float_t *xs, const Float_t *ys)
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}
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
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
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition TAttFill.h:42
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:36
virtual Width_t GetLineWidth() const
Return the line width.
Definition TAttLine.h:38
virtual Style_t GetLineStyle() const
Return the line style.
Definition TAttLine.h:37
virtual Style_t GetMarkerStyle() const
Return the marker style.
Definition TAttMarker.h:34
virtual Color_t GetMarkerColor() const
Return the marker color.
Definition TAttMarker.h:33
virtual Size_t GetMarkerSize() const
Return the marker size.
Definition TAttMarker.h:35
virtual Short_t GetTextAlign() const
Return the text alignment.
Definition TAttText.h:35
virtual Font_t GetTextFont() const
Return the text font.
Definition TAttText.h:38
virtual Color_t GetTextColor() const
Return the text color.
Definition TAttText.h:37
virtual Float_t GetTextAngle() const
Return the text angle.
Definition TAttText.h:36
virtual Float_t GetTextSizeRelative(TVirtualPad &pad) const
Return the text size in relative units.
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
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
TText * text
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16