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 TPadPainterPS
29\ingroup gpad
30
31TPadPainterPS is an attempt to abstract
32pad painting operation to the TVirtualPS interface.
33So using same API as for normal object drawing on interactive canvas,
34one also will be able to produce vector-based and binary images
35*/
36
37////////////////////////////////////////////////////////////////////////////////
38/// Consructor
39/// Assigns TVirtualPS instance which will be used by the painter
40
45
46/*
47Line/fill/etc. attributes can be set inside TPad, but not only where:
48many of them are set by base sub-objects of 2d primitives
49(2d primitives usually inherit TAttLine or TAttFill etc.). And these sub-objects
50call gVirtualPS->SetLineWidth ... etc. So, if I save some attributes in my painter,
51it will be mess - at any moment I do not know, where to take line attribute - from
52gVirtualX or from my own member. So! All attributed, _ALL_ go to gVirtualPS.
53At the same time attributes copy preserved in the painter -
54so actual value can be requested without asking of gVirtualPS instance
55*/
56
57
58////////////////////////////////////////////////////////////////////////////////
59/// Delegate to gVirtualPS.
60
62{
63 TAttFill att = GetAttFill();
64 att.SetFillStyle(4000 + percent);
65 SetAttFill(att);
66}
67
68////////////////////////////////////////////////////////////////////////////////
69/// Provide fill attributes to gVirtualPS.
70
72{
74
75 auto fill = GetAttFillInternal(kTRUE);
76 fPS->SetFillColor(fill.GetFillColor());
77 fPS->SetFillStyle(fill.GetFillStyle());
78}
79
80////////////////////////////////////////////////////////////////////////////////
81/// Provide line attributes to gVirtualPS.
82
91
92////////////////////////////////////////////////////////////////////////////////
93/// Provide marker attributes to gVirtualPS.
94
103
104////////////////////////////////////////////////////////////////////////////////
105/// Provide text attributes to gVirtualPS.
106
108{
110
111 // TODO: in ROOT7 move text size handling directly to correspondent PS engine
112 // One not need to recalculate text size many time back and forth
113
114 Float_t tsize = 0.03;
115
116 if (fPad)
117 tsize = att.GetTextSizeRelative(*fPad);
118 else
119 Fatal("SetAttText", "Pad not set when invoke method");
120
124 fPS->SetTextSize(tsize);
126}
127
128
129////////////////////////////////////////////////////////////////////////////////
130/// Create a gVirtualX Pixmap - not implemented
131
136
137
138////////////////////////////////////////////////////////////////////////////////
139/// Clear the current gVirtualX window - noop for PS
140
144
145
146////////////////////////////////////////////////////////////////////////////////
147/// Copy a gVirtualX pixmap - not implemented
148
152
153
154////////////////////////////////////////////////////////////////////////////////
155/// Close the current gVirtualX pixmap - not implemented
156
160
161
162////////////////////////////////////////////////////////////////////////////////
163/// Select the window in which the graphics will go - not implemented
164
168
169
170////////////////////////////////////////////////////////////////////////////////
171/// Start new page on PS output
172
174{
175 fPS->NewPage();
176}
177
178
179
180////////////////////////////////////////////////////////////////////////////////
181///Noop, for non-gl pad TASImage calls gVirtualX->CopyArea.
182
183void TPadPainterPS::DrawPixels(const unsigned char * /*pixelData*/, UInt_t /*width*/, UInt_t /*height*/,
184 Int_t /*dstX*/, Int_t /*dstY*/, Bool_t /*enableAlphaBlending*/)
185{
186}
187
188
189////////////////////////////////////////////////////////////////////////////////
190/// Paint a simple line.
191
193{
194 if (GetAttLine().GetLineWidth() <= 0)
195 return;
196 Double_t x[2] = {x1, x2}, y[2] = {y1, y2};
197 fPS->DrawPS(2, x, y);
198}
199
200
201////////////////////////////////////////////////////////////////////////////////
202/// Paint a simple line in normalized coordinates.
203
205{
206 if (GetAttLine().GetLineWidth() <= 0)
207 return;
208
209 Double_t xw[2], yw[2];
210
211 xw[0] = (1 - u1) * fPad->GetX1() + u1 * fPad->GetX2();
212 xw[1] = (1 - u2) * fPad->GetX1() + u2 * fPad->GetX2();
213 yw[0] = (1 - v1) * fPad->GetY1() + v1 * fPad->GetY2();
214 yw[1] = (1 - v2) * fPad->GetY1() + v2 * fPad->GetY2();
215 fPS->DrawPS(2, xw, yw);
216}
217
218
219////////////////////////////////////////////////////////////////////////////////
220/// Paint a simple box.
221
223{
224 Int_t style0 = -1;
225
227 if (GetAttLine().GetLineWidth() <= 0)
228 return;
229 style0 = fPS->GetFillStyle();
230 if (style0 > 0)
231 fPS->SetFillStyle(0);
232 } else if (fFullyTransparent)
233 return;
234
235 fPS->DrawBox(x1, y1, x2, y2);
236
237 if (style0 > 0)
238 fPS->SetFillStyle(style0);
239}
240
241////////////////////////////////////////////////////////////////////////////////
242/// Paint filled area.
243
244void TPadPainterPS::DrawFillArea(Int_t nPoints, const Double_t *xs, const Double_t *ys)
245{
246 if (nPoints < 3) {
247 ::Error("TPadPainterPS::DrawFillArea", "invalid number of points %d", nPoints);
248 return;
249 }
250
251 if (!fFullyTransparent || (fPS->GetLineWidth() > 0))
252 fPS->DrawPS(-nPoints, const_cast<Double_t *>(xs), const_cast<Double_t *>(ys));
253}
254
255
256////////////////////////////////////////////////////////////////////////////////
257/// Paint filled area.
258
259void TPadPainterPS::DrawFillArea(Int_t nPoints, const Float_t *xs, const Float_t *ys)
260{
261 if (nPoints < 3) {
262 ::Error("TPadPainterPS::DrawFillArea", "invalid number of points %d", nPoints);
263 return;
264 }
265
266 if (!fFullyTransparent || (fPS->GetLineWidth() > 0))
267 fPS->DrawPS(-nPoints, const_cast<Float_t *>(xs), const_cast<Float_t *>(ys));
268}
269
270////////////////////////////////////////////////////////////////////////////////
271/// Paint Polyline.
272
274{
275 if (GetAttLine().GetLineWidth() <= 0)
276 return;
277
278 if (n < 2) {
279 ::Error("TPadPainterPS::DrawPolyLine", "invalid number of points");
280 return;
281 }
282
283 fPS->DrawPS(n, const_cast<Double_t *>(xs), const_cast<Double_t *>(ys));
284}
285
286
287////////////////////////////////////////////////////////////////////////////////
288/// Paint polyline.
289
291{
292 if (GetAttLine().GetLineWidth() <= 0)
293 return;
294
295 if (n < 2) {
296 ::Error("TPadPainterPS::DrawPolyLine", "invalid number of points");
297 return;
298 }
299
300 fPS->DrawPS(n, const_cast<Float_t *>(xs), const_cast<Float_t *>(ys));
301}
302
303
304////////////////////////////////////////////////////////////////////////////////
305/// Paint polyline in normalized coordinates.
306
308{
309 if (GetAttLine().GetLineWidth() <= 0)
310 return;
311
312 if (n < 2) {
313 ::Error("TPadPainterPS::DrawPolyLineNDC", "invalid number of points %d", n);
314 return;
315 }
316
317 std::vector<Double_t> xw(n), yw(n);
318 for (Int_t i = 0; i < n; i++) {
319 xw[i] = (1 - u[i]) * fPad->GetX1() + u[i] * fPad->GetX2();
320 yw[i] = (1 - v[i]) * fPad->GetY1() + v[i] * fPad->GetY2();
321 }
322 fPS->DrawPS(n, xw.data(), yw.data());
323}
324
325////////////////////////////////////////////////////////////////////////////////
326/// Paint N segments on the pad
327
329{
330 if (GetAttLine().GetLineWidth() <= 0)
331 return;
332
333 if (n < 1) {
334 ::Error("TPadPainterPS::DrawSegments", "invalid number of segments %d", n);
335 return;
336 }
337
338 fPS->DrawSegments(n, x, y);
339}
340
341////////////////////////////////////////////////////////////////////////////////
342/// Paint N segments in normalized coordinates on the pad
343
345{
346 if (GetAttLine().GetLineWidth() <= 0)
347 return;
348
349 if (n < 1) {
350 ::Error("TPadPainterPS::DrawSegmentsNDC", "invalid number of segments %d", n);
351 return;
352 }
353 // recalculate values into normal coordiantes
354 for (Int_t i = 0; i < 2*n; i++) {
355 u[i] = (1 - u[i]) * fPad->GetX1() + u[i] * fPad->GetX2();
356 v[i] = (1 - v[i]) * fPad->GetY1() + v[i] * fPad->GetY2();
357 }
358 fPS->DrawSegments(n, u, v);
359}
360
361////////////////////////////////////////////////////////////////////////////////
362/// Paint polymarker.
363
365{
366 if (n < 1) {
367 ::Error("TPadPainterPS::DrawPolyMarker", "invalid number of points %d", n);
368 return;
369 }
370
371 fPS->DrawPolyMarker(n, const_cast<Double_t *>(x), const_cast<Double_t *>(y));
372}
373
374
375////////////////////////////////////////////////////////////////////////////////
376/// Paint polymarker.
377
379{
380 if (n < 1) {
381 ::Error("TPadPainterPS::DrawPolyMarker", "invalid number of points %d", n);
382 return;
383 }
384
385 fPS->DrawPolyMarker(n, const_cast<Float_t *>(x), const_cast<Float_t *>(y));
386}
387
388
389////////////////////////////////////////////////////////////////////////////////
390/// Paint text.
391
393{
394 fPS->Text(x, y, text);
395}
396
397
398////////////////////////////////////////////////////////////////////////////////
399/// Special version working with wchar_t and required by TMathText.
400
401void TPadPainterPS::DrawText(Double_t x, Double_t y, const wchar_t *text, ETextMode /* mode */)
402{
403 fPS->Text(x, y, text);
404}
405
406
407////////////////////////////////////////////////////////////////////////////////
408/// Drawint text with url link
409
410void TPadPainterPS::DrawTextUrl(Double_t x, Double_t y, const char *text, const char *url)
411{
412 fPS->TextUrl(x, y, text, url);
413}
414
415
416////////////////////////////////////////////////////////////////////////////////
417/// Paint text in normalized coordinates.
418
420{
421 Double_t x = (1 - u) * fPad->GetX1() + u * fPad->GetX2();
422 Double_t y = (1 - v) * fPad->GetY1() + v * fPad->GetY2();
423 fPS->Text(x, y, text);
424}
425
426
427////////////////////////////////////////////////////////////////////////////////
428/// Draw image on the PS output
429
431{
432 // transfer to absolute pixel coordiantes for PS
433 x += fPad->UtoAbsPixel(0);
434 y += fPad->VtoAbsPixel(1);
435
436 fPS->DrawImage(img, x, y, flags);
437}
438
439
440////////////////////////////////////////////////////////////////////////////////
441/// Save the image displayed in the canvas pointed by "pad" into a binary file.
442
443void TPadPainterPS::SaveImage(TVirtualPad *, const char *, Int_t) const
444{
445}
446
447
448////////////////////////////////////////////////////////////////////////////////
449/// Paint text in normalized coordinates.
450
451void TPadPainterPS::DrawTextNDC(Double_t u, Double_t v, const wchar_t *text, ETextMode /* mode */)
452{
453 Double_t x = (1 - u) * fPad->GetX1() + u * fPad->GetX2();
454 Double_t y = (1 - v) * fPad->GetY1() + v * fPad->GetY2();
455 fPS->Text(x, y, text);
456}
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:72
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
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 Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:36
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
virtual Style_t GetLineStyle() const
Return the line style.
Definition TAttLine.h:37
Marker Attributes class.
Definition TAttMarker.h:22
virtual Style_t GetMarkerStyle() const
Return the marker style.
Definition TAttMarker.h:35
virtual Color_t GetMarkerColor() const
Return the marker color.
Definition TAttMarker.h:34
virtual Size_t GetMarkerSize() const
Return the marker size.
Definition TAttMarker.h:36
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Text Attributes class.
Definition TAttText.h:21
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition TAttText.h:48
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 GetTextSizeRelative(TVirtualPad &pad) const
Return the text size in relative units.
Definition TAttText.cxx:333
virtual void SetTextAngle(Float_t tangle=0)
Set the text angle.
Definition TAttText.h:49
virtual Float_t GetTextAngle() const
Return the text angle.
Definition TAttText.h:36
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
An abstract interface to image processing library.
Definition TImage.h:30
void SetAttFill(const TAttFill &att) override
Set fill attributes.
void SetAttText(const TAttText &att) override
Set text attributes.
const TAttFill & GetAttFill() const override
Get fill attributes.
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 DrawImage(TImage *img, Int_t x, Int_t y, Int_t flags=0) override
Draw image on the PS output.
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:32
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 DrawImage(TImage *, Int_t, Int_t, Int_t=0)
Definition TVirtualPS.h:60
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:53
virtual Double_t GetX2() const =0
virtual Double_t GetY1() const =0
virtual Int_t UtoAbsPixel(Double_t u) const =0
virtual Int_t VtoAbsPixel(Double_t v) 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