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 "TVirtualX.h"
20#include "TCanvas.h"
21#include "TPoint.h"
22#include "TError.h"
23#include "TImage.h"
24#include "TROOT.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/from gVirtualPS.
50*/
51
52
53////////////////////////////////////////////////////////////////////////////////
54/// Delegate to gVirtualPS.
55
60
61
62////////////////////////////////////////////////////////////////////////////////
63/// Delegate to gVirtualPS.
64
69
70
71////////////////////////////////////////////////////////////////////////////////
72/// Delegate to gVirtualPS.
73
78
79
80////////////////////////////////////////////////////////////////////////////////
81/// Delegate to gVirtualPS.
82
87
88
89////////////////////////////////////////////////////////////////////////////////
90/// Delegate to gVirtualPS.
91
96
97
98////////////////////////////////////////////////////////////////////////////////
99/// Delegate to gVirtualPS.
100
105
106
107////////////////////////////////////////////////////////////////////////////////
108/// Delegate to gVirtualPS.
109
111{
112 return fPS->GetFillColor();
113}
114
115
116////////////////////////////////////////////////////////////////////////////////
117/// Delegate to gVirtualPS.
118
120{
121 return fPS->GetFillStyle();
122}
123
124
125////////////////////////////////////////////////////////////////////////////////
126/// Delegate to gVirtualPS.
127
129{
130 //IsTransparent is implemented as inline function in TAttFill.
131 return fPS->IsTransparent();
132}
133
134
135////////////////////////////////////////////////////////////////////////////////
136/// Delegate to gVirtualPS.
137
142
143
144////////////////////////////////////////////////////////////////////////////////
145/// Delegate to gVirtualPS.
146
151
152
153////////////////////////////////////////////////////////////////////////////////
154/// Delegate to gVirtualPS.
155
160
161
162////////////////////////////////////////////////////////////////////////////////
163/// Delegate to gVirtualPS.
164
166{
167 return fPS->GetTextAlign();
168}
169
170
171////////////////////////////////////////////////////////////////////////////////
172/// Delegate to gVirtualPS.
173
175{
176 return fPS->GetTextAngle();
177}
178
179
180////////////////////////////////////////////////////////////////////////////////
181/// Delegate to gVirtualPS.
182
184{
185 return fPS->GetTextColor();
186}
187
188
189////////////////////////////////////////////////////////////////////////////////
190/// Delegate to gVirtualPS.
191
193{
194 return fPS->GetTextFont();
195}
196
197
198////////////////////////////////////////////////////////////////////////////////
199/// Delegate to gVirtualPS.
200
202{
203 return fPS->GetTextSize();
204}
205
206
207////////////////////////////////////////////////////////////////////////////////
208/// Delegate to gVirtualPS.
209
211{
212 // FIXME!!!
213 return 0;
214}
215
216
217////////////////////////////////////////////////////////////////////////////////
218/// Delegate to gVirtualPS.
219
221{
222 fPS->SetTextAlign(align);
223}
224
225
226////////////////////////////////////////////////////////////////////////////////
227/// Delegate to gVirtualPS.
228
233
234
235////////////////////////////////////////////////////////////////////////////////
236/// Delegate to gVirtualPS.
237
242
243
244////////////////////////////////////////////////////////////////////////////////
245/// Delegate to gVirtualPS.
246
251
252
253////////////////////////////////////////////////////////////////////////////////
254/// Delegate to gVirtualPS.
255
260
261
262////////////////////////////////////////////////////////////////////////////////
263/// Delegate to gVirtualPS.
264
269
270
271////////////////////////////////////////////////////////////////////////////////
272/// Delegate to gVirtualPS.
273
278
279
280////////////////////////////////////////////////////////////////////////////////
281/// Delegate to gVirtualPS.
282
287
288
289////////////////////////////////////////////////////////////////////////////////
290/// Delegate to gVirtualPS.
291
293{
294 return fPS->GetMarkerSize();
295}
296
297
298////////////////////////////////////////////////////////////////////////////////
299/// Delegate to gVirtualPS.
300
305
306
307////////////////////////////////////////////////////////////////////////////////
308/// Delegate to gVirtualPS.
309
314
315
316////////////////////////////////////////////////////////////////////////////////
317/// Delegate to gVirtualPS.
318
323
324
325////////////////////////////////////////////////////////////////////////////////
326/// Create a gVirtualX Pixmap - not implemented
327
332
333
334////////////////////////////////////////////////////////////////////////////////
335/// Clear the current gVirtualX window - noop for PS
336
340
341
342////////////////////////////////////////////////////////////////////////////////
343/// Copy a gVirtualX pixmap - not implemented
344
348
349
350////////////////////////////////////////////////////////////////////////////////
351/// Close the current gVirtualX pixmap - not implemented
352
356
357
358////////////////////////////////////////////////////////////////////////////////
359/// Select the window in which the graphics will go - not implemented
360
364
365
366////////////////////////////////////////////////////////////////////////////////
367/// Start new page on PS output
368
370{
371 fPS->NewPage();
372}
373
374
375
376////////////////////////////////////////////////////////////////////////////////
377///Noop, for non-gl pad TASImage calls gVirtualX->CopyArea.
378
379void TPadPainterPS::DrawPixels(const unsigned char * /*pixelData*/, UInt_t /*width*/, UInt_t /*height*/,
380 Int_t /*dstX*/, Int_t /*dstY*/, Bool_t /*enableAlphaBlending*/)
381{
382}
383
384
385////////////////////////////////////////////////////////////////////////////////
386/// Paint a simple line.
387
389{
390 if (GetLineWidth() <= 0)
391 return;
392 Double_t x[2] = {x1, x2}, y[2] = {y1, y2};
393 fPS->DrawPS(2, x, y);
394}
395
396
397////////////////////////////////////////////////////////////////////////////////
398/// Paint a simple line in normalized coordinates.
399
401{
402 if (GetLineWidth() <= 0)
403 return;
404
405 Double_t xw[2], yw[2];
406
407 xw[0] = (1 - u1) * fPad->GetX1() + u1 * fPad->GetX2();
408 xw[1] = (1 - u2) * fPad->GetX1() + u2 * fPad->GetX2();
409 yw[0] = (1 - v1) * fPad->GetY1() + v1 * fPad->GetY2();
410 yw[1] = (1 - v2) * fPad->GetY1() + v2 * fPad->GetY2();
411 fPS->DrawPS(2, xw, yw);
412}
413
414
415////////////////////////////////////////////////////////////////////////////////
416/// Paint a simple box.
417
419{
420 Int_t style0 = -1;
421
423 if (GetLineWidth() <= 0)
424 return;
426 if (style0 > 0)
427 fPS->SetFillStyle(0);
428 }
429
430 fPS->DrawBox(x1, y1, x2, y2);
431
432 if (style0 > 0)
434}
435
436////////////////////////////////////////////////////////////////////////////////
437/// Paint filled area.
438
440{
441 if (nPoints < 3) {
442 ::Error("TPadPainterPS::DrawFillArea", "invalid number of points %d", nPoints);
443 return;
444 }
445
446 fPS->DrawPS(-nPoints, const_cast<Double_t *>(xs), const_cast<Double_t *>(ys));
447}
448
449
450////////////////////////////////////////////////////////////////////////////////
451/// Paint filled area.
452
454{
455 if (nPoints < 3) {
456 ::Error("TPadPainterPS::DrawFillArea", "invalid number of points %d", nPoints);
457 return;
458 }
459
460 fPS->DrawPS(-nPoints, const_cast<Float_t *>(xs), const_cast<Float_t *>(ys));
461}
462
463////////////////////////////////////////////////////////////////////////////////
464/// Paint Polyline.
465
467{
468 if (GetLineWidth() <= 0)
469 return;
470
471 if (n < 2) {
472 ::Error("TPadPainterPS::DrawPolyLine", "invalid number of points");
473 return;
474 }
475
476 fPS->DrawPS(n, const_cast<Double_t *>(xs), const_cast<Double_t *>(ys));
477}
478
479
480////////////////////////////////////////////////////////////////////////////////
481/// Paint polyline.
482
484{
485 if (GetLineWidth() <= 0)
486 return;
487
488 if (n < 2) {
489 ::Error("TPadPainterPS::DrawPolyLine", "invalid number of points");
490 return;
491 }
492
493 fPS->DrawPS(n, const_cast<Float_t *>(xs), const_cast<Float_t *>(ys));
494}
495
496
497////////////////////////////////////////////////////////////////////////////////
498/// Paint polyline in normalized coordinates.
499
501{
502 if (GetLineWidth() <= 0)
503 return;
504
505 if (n < 2) {
506 ::Error("TPadPainterPS::DrawPolyLineNDC", "invalid number of points %d", n);
507 return;
508 }
509
510 std::vector<Double_t> xw(n), yw(n);
511 for (Int_t i = 0; i < n; i++) {
512 xw[i] = (1 - u[i]) * fPad->GetX1() + u[i] * fPad->GetX2();
513 yw[i] = (1 - v[i]) * fPad->GetY1() + v[i] * fPad->GetY2();
514 }
515 fPS->DrawPS(n, xw.data(), yw.data());
516}
517
518////////////////////////////////////////////////////////////////////////////////
519/// Paint N segments on the pad
520
522{
523 if (GetLineWidth() <= 0)
524 return;
525
526 if (n < 1) {
527 ::Error("TPadPainterPS::DrawSegments", "invalid number of segments %d", n);
528 return;
529 }
530
531 fPS->DrawSegments(n, x, y);
532}
533
534////////////////////////////////////////////////////////////////////////////////
535/// Paint N segments in normalized coordinates on the pad
536
538{
539 if (GetLineWidth() <= 0)
540 return;
541
542 if (n < 1) {
543 ::Error("TPadPainterPS::DrawSegmentsNDC", "invalid number of segments %d", n);
544 return;
545 }
546 // recalculate values into normal coordiantes
547 for (Int_t i = 0; i < 2*n; i++) {
548 u[i] = (1 - u[i]) * fPad->GetX1() + u[i] * fPad->GetX2();
549 v[i] = (1 - v[i]) * fPad->GetY1() + v[i] * fPad->GetY2();
550 }
551 fPS->DrawSegments(n, u, v);
552}
553
554////////////////////////////////////////////////////////////////////////////////
555/// Paint polymarker.
556
558{
559 if (n < 1) {
560 ::Error("TPadPainterPS::DrawPolyMarker", "invalid number of points %d", n);
561 return;
562 }
563
564 fPS->DrawPolyMarker(n, const_cast<Double_t *>(x), const_cast<Double_t *>(y));
565}
566
567
568////////////////////////////////////////////////////////////////////////////////
569/// Paint polymarker.
570
572{
573 if (n < 1) {
574 ::Error("TPadPainterPS::DrawPolyMarker", "invalid number of points %d", n);
575 return;
576 }
577
578 fPS->DrawPolyMarker(n, const_cast<Float_t *>(x), const_cast<Float_t *>(y));
579}
580
581
582////////////////////////////////////////////////////////////////////////////////
583/// Paint text.
584
586{
587 fPS->Text(x, y, text);
588}
589
590
591////////////////////////////////////////////////////////////////////////////////
592/// Special version working with wchar_t and required by TMathText.
593
594void TPadPainterPS::DrawText(Double_t x, Double_t y, const wchar_t *text, ETextMode /* mode */)
595{
596 fPS->Text(x, y, text);
597}
598
599
600////////////////////////////////////////////////////////////////////////////////
601/// Drawint text with url link
602
603void TPadPainterPS::DrawTextUrl(Double_t x, Double_t y, const char *text, const char *url)
604{
605 fPS->TextUrl(x, y, text, url);
606}
607
608
609////////////////////////////////////////////////////////////////////////////////
610/// Paint text in normalized coordinates.
611
613{
614 Double_t x = (1 - u) * fPad->GetX1() + u * fPad->GetX2();
615 Double_t y = (1 - v) * fPad->GetY1() + v * fPad->GetY2();
616 fPS->Text(x, y, text);
617}
618
619
620////////////////////////////////////////////////////////////////////////////////
621/// Save the image displayed in the canvas pointed by "pad" into a binary file.
622
623void TPadPainterPS::SaveImage(TVirtualPad *, const char *, Int_t) const
624{
625}
626
627
628////////////////////////////////////////////////////////////////////////////////
629/// Paint text in normalized coordinates.
630
631void TPadPainterPS::DrawTextNDC(Double_t u, Double_t v, const wchar_t *text, ETextMode /* mode */)
632{
633 Double_t x = (1 - u) * fPad->GetX1() + u * fPad->GetX2();
634 Double_t y = (1 - v) * fPad->GetY1() + v * fPad->GetY2();
635 fPS->Text(x, y, text);
636}
short Style_t
Style number (short)
Definition RtypesCore.h:96
short Color_t
Color number (short)
Definition RtypesCore.h:99
float Size_t
Attribute size (float)
Definition RtypesCore.h:103
short Width_t
Line width (short)
Definition RtypesCore.h:98
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
short Font_t
Font number (short)
Definition RtypesCore.h:95
short Short_t
Signed Short integer 2 bytes (short)
Definition RtypesCore.h:53
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
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
virtual Color_t GetFillColor() const
Return the fill area color.
Definition TAttFill.h:32
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 Bool_t IsTransparent() const
Definition TAttFill.h:49
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 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
virtual Style_t GetMarkerStyle() const
Return the marker style.
Definition TAttMarker.h:34
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:41
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 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
virtual Float_t GetTextSize() const
Return the text size.
Definition TAttText.h:39
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition TAttText.h:46
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 void SetTextAngle(Float_t tangle=0)
Set the text angle.
Definition TAttText.h:47
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:48
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition TAttText.h:50
virtual void SetTextSizePixels(Int_t npixels)
Set the text size in pixel.
Definition TAttText.cxx:433
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition TAttText.h:51
void DrawPolyLineNDC(Int_t n, const Double_t *u, const Double_t *v) override
Paint polyline in normalized coordinates.
Font_t GetTextFont() const override
Delegate to gVirtualPS.
Float_t GetTextSize() const override
Delegate to gVirtualPS.
Color_t GetTextColor() const override
Delegate to gVirtualPS.
Style_t GetMarkerStyle() const override
Delegate to gVirtualPS.
Style_t GetFillStyle() const override
Delegate to gVirtualPS.
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.
Color_t GetFillColor() const override
Delegate to gVirtualPS.
Color_t GetMarkerColor() const override
Delegate to gVirtualPS.
TVirtualPS * fPS
void SetTextSize(Float_t tsize) override
Delegate to gVirtualPS.
void DrawSegmentsNDC(Int_t n, Double_t *u, Double_t *v) override
Paint N segments in normalized coordinates on the pad.
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.
Style_t GetLineStyle() const override
Delegate to gVirtualPS.
void DrawTextNDC(Double_t u, Double_t v, const char *text, ETextMode mode) override
Paint text in normalized coordinates.
void SetMarkerStyle(Style_t mstyle) override
Delegate to gVirtualPS.
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 SetLineWidth(Width_t lwidth) override
Delegate to gVirtualPS.
void SetTextAlign(Short_t align) override
Delegate to gVirtualPS.
void SetMarkerSize(Size_t msize) override
Delegate to gVirtualPS.
void NewPage() override
Start new page on PS output.
Width_t GetLineWidth() const override
Delegate to gVirtualPS.
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 SetTextFont(Font_t tfont) override
Delegate to gVirtualPS.
void SetTextColor(Color_t tcolor) override
Delegate to gVirtualPS.
void SetMarkerColor(Color_t mcolor) override
Delegate to gVirtualPS.
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.
Float_t GetTextAngle() const override
Delegate to gVirtualPS.
void SetLineStyle(Style_t lstyle) override
Delegate to gVirtualPS.
void DrawFillArea(Int_t n, const Double_t *x, const Double_t *y) override
Paint filled area.
void DrawPolyMarker(Int_t n, const Double_t *x, const Double_t *y) override
Paint polymarker.
Float_t GetTextMagnitude() const override
Delegate to gVirtualPS.
void DrawText(Double_t x, Double_t y, const char *text, ETextMode mode) override
Paint text.
void SetLineColor(Color_t lcolor) override
Delegate to gVirtualPS.
TVirtualPad * fPad
Size_t GetMarkerSize() const override
Delegate to gVirtualPS.
Color_t GetLineColor() const override
Delegate to gVirtualPS.
void SetFillStyle(Style_t fstyle) override
Delegate to gVirtualPS.
void SetTextAngle(Float_t tangle) override
Delegate to gVirtualPS.
void SetOpacity(Int_t percent) override
Delegate to gVirtualPS.
void DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2) override
Paint a simple line.
void SetFillColor(Color_t fcolor) override
Delegate to gVirtualPS.
Short_t GetTextAlign() const override
Delegate to gVirtualPS.
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 SetTextSizePixels(Int_t npixels) override
Delegate to gVirtualPS.
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.
Bool_t IsTransparent() const override
Delegate to gVirtualPS.
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